mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-16 11:24:04 +00:00
Revert "Remove symlink-related jobs, instantiate and use actions"
This reverts commit 547440c887.
This commit is contained in:
parent
547440c887
commit
9eb035155d
9 changed files with 117 additions and 46 deletions
|
|
@ -12,33 +12,29 @@ use Stancl\Tenancy\Database\Models\Tenant;
|
|||
use Stancl\Tenancy\Events\CreatingStorageSymlink;
|
||||
use Stancl\Tenancy\Events\StorageSymlinkCreated;
|
||||
|
||||
class CreateStorageSymlinks
|
||||
class CreateStorageSymlinksAction
|
||||
{
|
||||
use DealsWithTenantSymlinks;
|
||||
|
||||
public function __construct(protected Tenant|Collection|LazyCollection $tenants, protected bool $relativeLink = false, protected bool $force = false)
|
||||
public static function handle(Tenant|Collection|LazyCollection $tenants, bool $relativeLink = false, bool $force = false): void
|
||||
{
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$tenants = $this->tenants instanceof Tenant ? collect([$this->tenants]) : $this->tenants;
|
||||
$tenants = $tenants instanceof Tenant ? collect([$tenants]) : $tenants;
|
||||
|
||||
/** @var Tenant $tenant */
|
||||
foreach ($tenants as $tenant) {
|
||||
foreach ($this->possibleTenantSymlinks($tenant) as $publicPath => $storagePath) {
|
||||
$this->createLink((string) $publicPath, (string) $storagePath, $tenant);
|
||||
foreach (static::possibleTenantSymlinks($tenant) as $publicPath => $storagePath) {
|
||||
static::createLink($publicPath, $storagePath, $tenant, $relativeLink, $force);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function createLink(string $publicPath, string $storagePath, Tenant $tenant): void
|
||||
protected static function createLink(string $publicPath, string $storagePath, Tenant $tenant, bool $relativeLink, bool $force): void
|
||||
{
|
||||
event(new CreatingStorageSymlink($tenant));
|
||||
|
||||
if ($this->symlinkExists($publicPath)) {
|
||||
if (static::symlinkExists($publicPath)) {
|
||||
// If $force isn't passed, don't overwrite the existing symlink
|
||||
throw_if(! $this->force, new Exception("The [$publicPath] link already exists."));
|
||||
throw_if(! $force, new Exception("The [$publicPath] link already exists."));
|
||||
|
||||
app()->make('files')->delete($publicPath);
|
||||
}
|
||||
|
|
@ -48,7 +44,7 @@ class CreateStorageSymlinks
|
|||
mkdir($storagePath, 0777, true);
|
||||
}
|
||||
|
||||
if ($this->relativeLink) {
|
||||
if ($relativeLink) {
|
||||
app()->make('files')->relativeLink($storagePath, $publicPath);
|
||||
} else {
|
||||
app()->make('files')->link($storagePath, $publicPath);
|
||||
|
|
@ -11,29 +11,25 @@ use Stancl\Tenancy\Database\Models\Tenant;
|
|||
use Stancl\Tenancy\Events\RemovingStorageSymlink;
|
||||
use Stancl\Tenancy\Events\StorageSymlinkRemoved;
|
||||
|
||||
class RemoveStorageSymlinks
|
||||
class RemoveStorageSymlinksAction
|
||||
{
|
||||
use DealsWithTenantSymlinks;
|
||||
|
||||
public function __construct(protected Tenant|Collection|LazyCollection $tenants)
|
||||
public static function handle(Tenant|Collection|LazyCollection $tenants): void
|
||||
{
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$tenants = $this->tenants instanceof Tenant ? collect([$this->tenants]) : $this->tenants;
|
||||
$tenants = $tenants instanceof Tenant ? collect([$tenants]) : $tenants;
|
||||
|
||||
/** @var Tenant $tenant */
|
||||
foreach ($tenants as $tenant) {
|
||||
foreach ($this->possibleTenantSymlinks($tenant) as $publicPath => $storagePath) {
|
||||
$this->removeLink((string) $publicPath, $tenant);
|
||||
foreach (static::possibleTenantSymlinks($tenant) as $publicPath => $storagePath) {
|
||||
static::removeLink($publicPath, $tenant);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function removeLink(string $publicPath, Tenant $tenant): void
|
||||
protected static function removeLink(string $publicPath, Tenant $tenant): void
|
||||
{
|
||||
if ($this->symlinkExists($publicPath)) {
|
||||
if (static::symlinkExists($publicPath)) {
|
||||
event(new RemovingStorageSymlink($tenant));
|
||||
|
||||
app()->make('files')->delete($publicPath);
|
||||
Loading…
Add table
Add a link
Reference in a new issue