1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 14:54:03 +00:00

Make FilesystemTenancyBootstrapper compatible with Flysystem v3

Co-authored-by: George <jiri.zizka@funfirst.cz>
This commit is contained in:
Erik Gaal 2022-02-14 14:23:58 +01:00
parent 81ebe7c6f5
commit 2bece24b07
No known key found for this signature in database
GPG key ID: 8733B288F439A599
2 changed files with 12 additions and 39 deletions

View file

@ -54,23 +54,22 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
} }
// Storage facade // Storage facade
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) { Storage::forgetDisk($this->app['config']['tenancy.filesystem.disks']);
/** @var FilesystemAdapter $filesystemDisk */
$filesystemDisk = Storage::disk($disk);
$this->originalPaths['disks'][$disk] = $filesystemDisk->getAdapter()->getPathPrefix();
if ($root = str_replace( foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
$root = $this->app['config']->get("filesystems.disks.{$disk}.root");
$this->originalPaths['disks'][$disk] = $root;
if (!($root = str_replace(
'%storage_path%', '%storage_path%',
storage_path(), storage_path(),
$this->app['config']["tenancy.filesystem.root_override.{$disk}"] ?? '' $this->app['config']["tenancy.filesystem.root_override.{$disk}"] ?? ''
)) { ))) {
$filesystemDisk->getAdapter()->setPathPrefix($finalPrefix = $root); $root = "{$root}/{$suffix}";
} else {
$root = $this->app['config']["filesystems.disks.{$disk}.root"];
$filesystemDisk->getAdapter()->setPathPrefix($finalPrefix = $root . "/{$suffix}");
} }
$this->app['config']["filesystems.disks.{$disk}.root"] = $finalPrefix; $this->app['config']["filesystems.disks.{$disk}.root"] = $root;
} }
} }
@ -84,14 +83,9 @@ class FilesystemTenancyBootstrapper implements TenancyBootstrapper
$this->app['url']->setAssetRoot($this->app['config']['app.asset_url']); $this->app['url']->setAssetRoot($this->app['config']['app.asset_url']);
// Storage facade // Storage facade
Storage::forgetDisk($this->app['config']['tenancy.filesystem.disks']);
foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) { foreach ($this->app['config']['tenancy.filesystem.disks'] as $disk) {
/** @var FilesystemAdapter $filesystemDisk */ $this->app['config']["filesystems.disks.{$disk}.root"] = $this->originalPaths['disks'][$disk];
$filesystemDisk = Storage::disk($disk);
$root = $this->originalPaths['disks'][$disk];
$filesystemDisk->getAdapter()->setPathPrefix($root);
$this->app['config']["filesystems.disks.{$disk}.root"] = $root;
} }
} }
} }

View file

@ -187,27 +187,6 @@ class BootstrapperTest extends TestCase
// Check suffixing logic // Check suffixing logic
$new_storage_path = storage_path(); $new_storage_path = storage_path();
$this->assertEquals($old_storage_path . '/' . config('tenancy.filesystem.suffix_base') . tenant('id'), $new_storage_path); $this->assertEquals($old_storage_path . '/' . config('tenancy.filesystem.suffix_base') . tenant('id'), $new_storage_path);
foreach (config('tenancy.filesystem.disks') as $disk) {
$suffix = config('tenancy.filesystem.suffix_base') . tenant('id');
/** @var FilesystemAdapter $filesystemDisk */
$filesystemDisk = Storage::disk($disk);
$current_path_prefix = $filesystemDisk->getAdapter()->getPathPrefix();
if ($override = config("tenancy.filesystem.root_override.{$disk}")) {
$correct_path_prefix = str_replace('%storage_path%', storage_path(), $override);
} else {
if ($base = $old_storage_facade_roots[$disk]) {
$correct_path_prefix = $base . "/$suffix/";
} else {
$correct_path_prefix = "$suffix/";
}
}
$this->assertSame($correct_path_prefix, $current_path_prefix);
}
} }
// for queues see QueueTest // for queues see QueueTest