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

Make LogChannelBootstrapper not depend on suffixed storage_path()

Since the tenant storage path can now be grabbed using FilesystemTenancyBootstrapper::getBoundTenantStoragePath(), the log bootstrapper doesn't need to depend on the FSBootstrapper being enabled and storage_path() being suffixed.

Instead of adding a regression test, just delete FilesystemTenancyBootstrapper from the config settings in the log bootstrapper tests (and in tests that did use storage_path() in tenant context assertions, use explicitly "hardcoded" paths instead).
This commit is contained in:
lukinovec 2026-08-25 13:20:50 +02:00 committed by Samuel Stancl
parent ae88836c0b
commit 2ef1ea94ed
2 changed files with 30 additions and 77 deletions

View file

@ -21,11 +21,8 @@ use Stancl\Tenancy\Contracts\Tenant;
* Laravel's 'single' and 'daily' channels by default. To customize it,
* see the property's docblock.
*
* For the storage path channels to be scoped correctly:
* - this bootstrapper must run *after* FilesystemTenancyBootstrapper,
* since FilesystemTenancyBootstrapper adjusts storage_path() for the tenant
* - storage path suffixing has to be enabled (= config('tenancy.filesystem.suffix_storage_path')
* must be true), since the storage path suffix is what separates filesystem-based logs
* Note that since the tenant's storage path is resolved using FilesystemTenancyBootstrapper::getBoundTenantStoragePath(),
* which is a public static method, FilesystemTenancyBootstrapper does not have to be enabled.
*
* For logging channels that are not filesystem-based, see the $channelOverrides logic.
*
@ -40,14 +37,10 @@ class LogChannelBootstrapper implements TenancyBootstrapper
/**
* Logging channels whose path is built using storage_path() (e.g. Laravel's 'single' and 'daily').
*
* Channels included here will be configured to use tenant-specific storage paths
* created using storage_path() in the tenant context. Overrides in the $channelOverrides
* property take precedence over $storagePathChannels when a channel is included in both.
* Channels included here will be configured to use tenant-specific storage paths.
*
* Requires FilesystemTenancyBootstrapper to run before this bootstrapper,
* and storage path suffixing to be enabled.
*
* @see Stancl\Tenancy\Bootstrappers\FilesystemTenancyBootstrapper
* Overrides in the $channelOverrides property take precedence over
* $storagePathChannels when a channel is included in both.
*/
public static array $storagePathChannels = ['single', 'daily'];
@ -158,11 +151,12 @@ class LogChannelBootstrapper implements TenancyBootstrapper
// The tenant log will be located at e.g. "storage/tenant{$tenantKey}/logs/laravel.log".
$originalChannelPath = $this->config->get("logging.channels.{$channel}.path");
$centralStoragePath = FilesystemTenancyBootstrapper::getBoundCentralStoragePath();
$tenantStoragePath = FilesystemTenancyBootstrapper::getBoundTenantStoragePath($tenant);
// The tenant log will inherit the segment that follows the storage path from the central channel path config.
// For example, if a channel's path is configured to storage_path('logs/foo.log') (storage/logs/foo.log),
// the 'logs/foo.log' segment will be passed to storage_path() in the tenant context (storage/tenant123/logs/foo.log).
$this->config->set("logging.channels.{$channel}.path", storage_path(Str::after($originalChannelPath, $centralStoragePath)));
// the '/logs/foo.log' segment will be appended to the tenant storage path (so the log will be located at storage/tenant123/logs/foo.log).
$this->config->set("logging.channels.{$channel}.path", $tenantStoragePath . Str::after($originalChannelPath, $centralStoragePath));
}
}
}