mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-15 11:04:04 +00:00
Extract Link command logic into actions
This commit is contained in:
parent
fa783641f4
commit
2594b1960f
6 changed files with 182 additions and 110 deletions
42
src/RemoveStorageSymlinksAction.php
Normal file
42
src/RemoveStorageSymlinksAction.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Collection;
|
||||
use Stancl\Tenancy\Concerns\DealsWithTenantSymlinks;
|
||||
use Stancl\Tenancy\Database\Models\Tenant;
|
||||
use Stancl\Tenancy\Events\StorageSymlinkRemoved;
|
||||
use Stancl\Tenancy\Events\RemovingStorageSymlink;
|
||||
|
||||
class RemoveStorageSymlinksAction
|
||||
{
|
||||
use DealsWithTenantSymlinks;
|
||||
|
||||
public static function handle($tenants, Closure|null $afterLinkRemoval = null)
|
||||
{
|
||||
$tenants = $tenants instanceof Tenant ? collect([$tenants]) : $tenants;
|
||||
|
||||
/** @var Tenant $tenant */
|
||||
foreach ($tenants as $tenant) {
|
||||
foreach(static::possibleTenantSymlinks($tenant) as $publicPath => $storagePath) {
|
||||
static::removeLink($publicPath, $tenant, $afterLinkRemoval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function removeLink(string $publicPath, Tenant $tenant, Closure|null $afterLinkRemoval)
|
||||
{
|
||||
if (static::symlinkExists($publicPath)) {
|
||||
event(new RemovingStorageSymlink($tenant));
|
||||
|
||||
app()->make('files')->delete($publicPath);
|
||||
|
||||
event(new StorageSymlinkRemoved($tenant));
|
||||
|
||||
if ($afterLinkRemoval) {
|
||||
$afterLinkRemoval($publicPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue