1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-06 17:44:04 +00:00
tenancy/src/Jobs/CreateTenantStorage.php
lukinovec bf42a12894 Change tenant storage listeners into jobs
Also move the commented jobs to the JobPipelines and update FilesystemTenancyBootstrapperTest accordingly.
2026-03-26 15:34:04 +01:00

39 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Stancl\Tenancy\Contracts\Tenant;
/**
* Can be used to manually create framework directories in the tenant storage when storage_path() is scoped.
*
* Useful when using real-time facades which use the framework/cache directory.
*
* Generally not needed anymore as the directory is also created by the FilesystemTenancyBootstrapper.
*/
class CreateTenantStorage implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(
public Tenant $tenant,
) {}
public function handle(): void
{
$storage_path = tenancy()->run($this->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);
}
}
}