Skip to content

Commit

Permalink
Slim down SymlinkStorageTask and let the public/storage symlink be ge…
Browse files Browse the repository at this point in the history
…nerated by its own Task
  • Loading branch information
simonschaufi committed Jun 29, 2020
1 parent 2546bc9 commit 84722f9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
3 changes: 0 additions & 3 deletions src/Application/Laravel.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ public function __construct($name = 'Laravel')
parent::__construct($name);
$this->options = array_merge($this->options, [
'webDirectory' => 'public',
'directories' => [
'storage'
],
'rsyncExcludes' => [
'.git',
'*.example',
Expand Down
20 changes: 3 additions & 17 deletions src/Task/Laravel/SymlinkStorageTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,13 @@ public function execute(Node $node, Application $application, Deployment $deploy
$applicationReleasePath = $deployment->getApplicationReleasePath($application);
$diffPath = substr($applicationReleasePath, strlen($deploymentPath));

$webDirectory = isset($options['webDirectory']) ? trim($options['webDirectory'], '\\/') : '';
$relativeDataPath = $relativeDataPathFromWeb = str_repeat('../', substr_count(trim($diffPath, '/'), '/') + 1) . 'shared';
if ($webDirectory !== '') {
$relativeDataPathFromWeb = str_repeat('../', substr_count(trim($webDirectory, '/'), '/') + 1) . $relativeDataPath;
}
$absoluteWebDirectory = rtrim("$targetReleasePath/$webDirectory", '/');
$relativeDataPath = str_repeat('../', substr_count(trim($diffPath, '/'), '/') + 1) . 'shared';
$absoluteProjectRootDirectory = rtrim($targetReleasePath, '/');
$commands = [
'cd ' . escapeshellarg($targetReleasePath),
sprintf('{ [ -d %1$s ] || mkdir -p %1$s ; }', escapeshellarg("{$relativeDataPath}/storage")),
sprintf('ln -sf %1$s %2$s', escapeshellarg("{$relativeDataPathFromWeb}/storage"), escapeshellarg("{$absoluteWebDirectory}/storage"))
sprintf('ln -sf %1$s %2$s', escapeshellarg("{$relativeDataPath}/storage"), escapeshellarg("{$absoluteProjectRootDirectory}/storage"))
];
if (isset($options['directories']) && is_array($options['directories'])) {
foreach ($options['directories'] as $directory) {
$directory = trim($directory, '\\/');
$targetDirectory = Files::concatenatePaths([$relativeDataPath, $directory]);
$commands[] = sprintf('{ [ -d %1$s ] || mkdir -p %1$s ; }', escapeshellarg($targetDirectory));
$commands[] = 'ln -sf ' . escapeshellarg(
str_repeat('../', substr_count(trim($directory, '/'), '/')) . $targetDirectory
) . ' ' . escapeshellarg($directory);
}
}
$this->shell->executeOrSimulate($commands, $node, $deployment);
}

Expand Down

0 comments on commit 84722f9

Please sign in to comment.