1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-09-20 13:34:04 +00:00

Stop requiring a root_override in possibleTenantSymlinks

The symlink target used to be built from the root_override template, so a disk without an entry there had nothing to resolve.
The symlink target is now the disk's tenant-context root, which the bootstrapper sets either way -- with a root_override it expands
the template, without one, it appends the suffix to the disk's own root. Disks that only have a url_override now get a working symlink
instead of being skipped while their URL was still overridden.

Skipping disks with a null url_override is now explicit. The root_override check used to cover that by accident, and without it str_replace() gets null and throws a TypeError.
This commit is contained in:
lukinovec 2026-08-19 15:15:14 +02:00 committed by Samuel Stancl
parent aad435da44
commit ae77c49985
2 changed files with 9 additions and 7 deletions

View file

@ -357,7 +357,7 @@ return [
* Use `php artisan tenants:link` to create a symbolic link from the tenant's storage to its public directory. * Use `php artisan tenants:link` to create a symbolic link from the tenant's storage to its public directory.
*/ */
'url_override' => [ 'url_override' => [
// Note that the local disk you add must exist in the tenancy.filesystem.root_override config // Note that the local disk you add must exist in the tenancy.filesystem.disks config
'public' => 'public-%tenant%', 'public' => 'public-%tenant%',
], ],

View file

@ -18,7 +18,9 @@ trait DealsWithTenantSymlinks
/** /**
* Get all possible tenant symlinks, existing or not (array of ['public path' => 'disk root']). * Get all possible tenant symlinks, existing or not (array of ['public path' => 'disk root']).
* *
* Tenants can have a symlink for each disk registered in the tenancy.filesystem.url_override config. * Tenants can have a symlink for each local disk that is listed
* in both tenancy.filesystem.disks and tenancy.filesystem.url_override.
*
* This is used for creating all possible tenant symlinks and removing all existing tenant symlinks. * This is used for creating all possible tenant symlinks and removing all existing tenant symlinks.
* The same disk root can be symlinked to multiple public paths, which is why the public path * The same disk root can be symlinked to multiple public paths, which is why the public path
* is the array key. * is the array key.
@ -29,7 +31,6 @@ trait DealsWithTenantSymlinks
{ {
$disks = config('filesystems.disks'); $disks = config('filesystems.disks');
$urlOverrides = config('tenancy.filesystem.url_override'); $urlOverrides = config('tenancy.filesystem.url_override');
$rootOverrides = config('tenancy.filesystem.root_override');
$tenantKey = $tenant->getTenantKey(); $tenantKey = $tenant->getTenantKey();
$tenantDisks = tenancy()->run($tenant, fn () => config('filesystems.disks')); $tenantDisks = tenancy()->run($tenant, fn () => config('filesystems.disks'));
@ -38,11 +39,12 @@ trait DealsWithTenantSymlinks
$symlinks = []; $symlinks = [];
foreach ($urlOverrides as $disk => $publicPath) { foreach ($urlOverrides as $disk => $publicPath) {
if (! isset($disks[$disk])) { if (! $publicPath) {
// The disk's URL is not overridden, same as in FilesystemTenancyBootstrapper::diskUrl()
continue; continue;
} }
if (! isset($rootOverrides[$disk])) { if (! isset($disks[$disk])) {
continue; continue;
} }
@ -51,8 +53,8 @@ trait DealsWithTenantSymlinks
} }
if (! in_array($disk, config('tenancy.filesystem.disks'), true)) { if (! in_array($disk, config('tenancy.filesystem.disks'), true)) {
// The bootstrapper only scopes disks listed in tenancy.filesystem.disks. Without that, // The bootstrapper only scopes disks listed in tenancy.filesystem.disks.
// the disk root stays central, and the symlink of every tenant would point to it. // Without that, the root stays central and the symlink of every tenant would point to it.
throw new Exception("Disk $disk is not tenant-aware. Add it to the tenancy.filesystem.disks config to make its root tenant-specific."); throw new Exception("Disk $disk is not tenant-aware. Add it to the tenancy.filesystem.disks config to make its root tenant-specific.");
} }