mirror of
https://github.com/archtechx/tenancy.git
synced 2026-09-20 15:14:03 +00:00
Add symlink support for prefixed disks
Disk prefixes are no longer ignored by tenants:link. possibleTenantSymlinks() now appends them to both the public path and the disk root. CreateStorageSymlinksAction now creates parent directories for the symlinks in the public/ directory (e.g. for a disk with 'abc/def' prefix, the 'abc/def' subdirectory will be created inside public/<url_override>). RemoveStorageSymlinksAction removes the directories that CreateStorageSymlinksAction creates for the symlinks.
This commit is contained in:
parent
9673464128
commit
b2b8d50edb
4 changed files with 144 additions and 2 deletions
|
|
@ -47,6 +47,12 @@ class CreateStorageSymlinksAction
|
|||
mkdir($storagePath, 0777, true);
|
||||
}
|
||||
|
||||
// The public path of a prefixed disk includes the prefix,
|
||||
// and its parent directories may not exist yet.
|
||||
if (! is_dir($publicParent = dirname($publicPath))) {
|
||||
mkdir($publicParent, 0777, true);
|
||||
}
|
||||
|
||||
if ($relativeLink) {
|
||||
app()->make('files')->relativeLink($storagePath, $publicPath);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -32,12 +32,24 @@ class RemoveStorageSymlinksAction
|
|||
|
||||
protected function removeLink(string $publicPath, Tenant $tenant): void
|
||||
{
|
||||
$files = app()->make('files');
|
||||
|
||||
if ($this->symlinkExists($publicPath)) {
|
||||
event(new RemovingStorageSymlink($tenant));
|
||||
|
||||
app()->make('files')->delete($publicPath);
|
||||
$files->delete($publicPath);
|
||||
|
||||
event(new StorageSymlinkRemoved($tenant));
|
||||
}
|
||||
|
||||
// Remove the directories CreateStorageSymlinksAction created for the symlink
|
||||
// until a non-empty one is reached.
|
||||
$directory = dirname($publicPath);
|
||||
|
||||
while ($directory !== public_path() && $files->isEmptyDirectory($directory)) {
|
||||
$files->deleteDirectory($directory);
|
||||
|
||||
$directory = dirname($directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,8 +58,16 @@ trait DealsWithTenantSymlinks
|
|||
}
|
||||
|
||||
$publicPath = str_replace('%tenant%', (string) $tenantKey, $publicPath);
|
||||
$diskRoot = $tenantDisks[$disk]['root'];
|
||||
|
||||
$symlinks[public_path($publicPath)] = $tenantDisks[$disk]['root'];
|
||||
if ($prefix = trim($disks[$disk]['prefix'] ?? '', '/\\')) {
|
||||
$diskRoot = rtrim($diskRoot, '/\\') . DIRECTORY_SEPARATOR . $prefix;
|
||||
|
||||
// Storage::url() appends the disk's prefix to the url, so the prefix has to be in the public path as well
|
||||
$publicPath .= DIRECTORY_SEPARATOR . $prefix;
|
||||
}
|
||||
|
||||
$symlinks[public_path($publicPath)] = $diskRoot;
|
||||
}
|
||||
|
||||
return $symlinks;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue