Skip to content

Commit

Permalink
(#4) Stop creating links from application path to version files and f…
Browse files Browse the repository at this point in the history
…olders
  • Loading branch information
mougrim authored Aug 10, 2023
1 parent 934476a commit 5898f07
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 48 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use LoggerInterface
- Extract TemplateHelper::processTemplateToFile() to TemplateShellHelper

### Removed
- Stop creating links from application path to version files and folders

## [v0.3.0]

### Changed
Expand Down
50 changes: 2 additions & 48 deletions app/Command/Deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
use function escapeshellarg;
use function fgets;
use function file_exists;
use function in_array;
use function realpath;
use function scandir;
use function strtr;
use function trim;
use const STDIN;
Expand Down Expand Up @@ -311,61 +309,17 @@ public function actionDeploy(bool $isSkipGit = false): void

public function actionSwitch(): void
{
$applicationPath = (string) $this->getParam('application-path');
$user = (string) $this->getParam('user');
$afterSwitchScripts = $this->getParam('after-switch-script');
$currentLink = (string) $this->getParam('current-link-path');
$versionPath = (string) $this->getParam('version-path');

$applicationFiles = scandir($applicationPath);

$versionFiles = scandir($versionPath);

foreach ([&$applicationFiles, &$versionFiles] as &$files) {
foreach ([".", "..", "versions"] as $excludeFile) {
$key = array_search($excludeFile, $files);
if ($key !== false) {
unset($files[$key]);
}
}
}

$this->logger->info("Create new links");
$linksCreated = false;
foreach ($versionFiles as $versionFile) {
if (!in_array($versionFile, $applicationFiles)) {
$this->shellHelper->sudo($user)->ln(
"{$applicationPath}/{$versionFile}",
"$currentLink/{$versionFile}"
);
$linksCreated = true;
}
}

if ($linksCreated === false) {
$this->logger->info("No new links found");
}


$this->logger->info("Switch version");
$this->shellHelper->sudo($user)->ln(
$currentLink,
$versionPath
link: $currentLink,
destination: $versionPath
);

$this->logger->info("Remove old links");
$linksRemoved = false;
foreach ($applicationFiles as $applicationFile) {
if (!in_array($applicationFile, $versionFiles)) {
$linksRemoved = true;
$this->shellHelper->sudo($user)->rm("{$applicationPath}/{$applicationFile}");
}
}

if ($linksRemoved === false) {
$this->logger->info("No links to remove found");
}

if ($afterSwitchScripts !== null) {
$this->logger->info("Run after switch scripts");
foreach ($afterSwitchScripts as $afterSwitchScript) {
Expand Down

0 comments on commit 5898f07

Please sign in to comment.