Skip to content

Commit

Permalink
Revised ActivateAction::run
Browse files Browse the repository at this point in the history
Granulated the setup of the static directory and symlink to avoid using recursive directory creation.
  • Loading branch information
mcaskill committed Dec 15, 2017
1 parent 0065eae commit 80e64f2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 25 additions & 7 deletions src/Charcoal/Admin/Action/System/StaticWebsite/ActivateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,45 @@ class ActivateAction extends AdminAction
*/
public function run(RequestInterface $request, ResponseInterface $response)
{
$baseCache = $this->basePath.'cache/static';
if (!file_exists($baseCache)) {
$ret = mkdir($baseCache, null, true);
$cachePath = $this->basePath.'cache';
// Ensure 'cache' directory exists
if (!file_exists($cachePath)) {
$ret = mkdir($cachePath);
if ($ret === false) {
$this->setSuccess(false);
return $response->withStatus(500);
}
}
$staticLink = $this->basePath.'www/static';

$staticPath = $cachePath.'/static';
// Ensure 'cache/static' directory exists
if (!file_exists($staticPath)) {
$ret = mkdir($staticPath);
if ($ret === false) {
$this->setSuccess(false);
return $response->withStatus(500);
}
}

$publicPath = $this->basePath.'www';
$staticLink = $publicPath.'/static';
// Ensure 'www/static' directory does NOT exist
if (file_exists($staticLink)) {
$this->setSuccess(false);
return $response->withStatus(409);
}
if (!file_exists(dirname($staticLink))) {
$ret = mkdir(dirname($staticLink));

// Ensure 'www' directory exists
if (!file_exists($publicPath)) {
$ret = mkdir($publicPath);
if ($ret === false) {
$this->setSuccess(false);
return $response->withStatus(500);
}
}
$ret = symlink($baseCache, $staticLink);

// Create a symbolic link from 'www/static' to 'cache/static'
$ret = symlink($staticPath, $staticLink);
if ($ret === false) {
$this->setSuccess(false);
return $response->withStatus(500);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ class DeactivateAction extends AdminAction
public function run(RequestInterface $request, ResponseInterface $response)
{
unset($request);

$staticLink = $this->basePath.'www/static';
if (!file_exists($staticLink)) {
$this->setSuccess(false);
return $response->withStatus(409);
}

$ret = unlink($staticLink);
if ($ret === false) {
$this->setSuccess(false);
Expand Down

0 comments on commit 80e64f2

Please sign in to comment.