mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 15:44:03 +00:00
Add deprecated listener versions of the storage jobs
Without this, updating Tenancy in existing projects would break TenancyServiceProvider. The logic of the deprecated versions is up-to-date with the changes made in the jobs up until now.
This commit is contained in:
parent
b7766ef76f
commit
97e856616c
2 changed files with 56 additions and 0 deletions
24
src/Listeners/CreateTenantStorage.php
Normal file
24
src/Listeners/CreateTenantStorage.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Listeners;
|
||||
|
||||
use Stancl\Tenancy\Events\Contracts\TenantEvent;
|
||||
|
||||
/**
|
||||
* @deprecated use Stancl\Tenancy\Jobs\CreateTenantStorage instead.
|
||||
*/
|
||||
class CreateTenantStorage
|
||||
{
|
||||
public function handle(TenantEvent $event): void
|
||||
{
|
||||
$storage_path = tenancy()->run($event->tenant, fn () => storage_path());
|
||||
$cache_path = "$storage_path/framework/cache";
|
||||
|
||||
if (! is_dir($cache_path)) {
|
||||
// Create the tenant's storage directory and /framework/cache within (used for e.g. real-time facades)
|
||||
mkdir($cache_path, 0750, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/Listeners/DeleteTenantStorage.php
Normal file
32
src/Listeners/DeleteTenantStorage.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Listeners;
|
||||
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Stancl\Tenancy\Events\Contracts\TenantEvent;
|
||||
|
||||
/**
|
||||
* @deprecated use Stancl\Tenancy\Jobs\DeleteTenantStorage instead.
|
||||
*/
|
||||
class DeleteTenantStorage
|
||||
{
|
||||
public function handle(TenantEvent $event): void
|
||||
{
|
||||
// Skip storage deletion if path suffixing is disabled
|
||||
if (config('tenancy.filesystem.suffix_storage_path') === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$centralPath = tenancy()->central(fn () => storage_path());
|
||||
$path = tenancy()->run($event->tenant, fn () => storage_path());
|
||||
|
||||
// Skip storage deletion if tenant's storage path is the same as central storage path
|
||||
$tenantPathIsCentral = realpath($path) === realpath($centralPath);
|
||||
|
||||
if (is_dir($path) && ! $tenantPathIsCentral) {
|
||||
File::deleteDirectory($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue