Skip to content

Commit

Permalink
Merge 721173d into 5ad1da5
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed Mar 9, 2020
2 parents 5ad1da5 + 721173d commit c31b440
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/Task/CreateDirectoriesTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,32 @@ class CreateDirectoriesTask extends Task implements ShellCommandServiceAwareInte

public function execute(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$deploymentPath = $application->getDeploymentPath();
$sharedPath = $application->getSharedPath();
$releasesPath = $application->getReleasesPath();
$releaseIdentifier = $deployment->getReleaseIdentifier();
$releasePath = $deployment->getApplicationReleasePath($application);
$result = $this->shell->execute('test -d ' . $deploymentPath, $node, $deployment, true);
$result = $this->shell->execute(sprintf('test -d %s', $application->getDeploymentPath()), $node, $deployment, true);
if ($result === false) {
throw new TaskExecutionException('Deployment directory "' . $deploymentPath . '" does not exist on node ' . $node->getName(), 1311003253);
throw new TaskExecutionException('Deployment directory "'.$application->getDeploymentPath().'" does not exist on node '.$node->getName(), 1311003253);
}
$commands = [
'mkdir -p ' . $releasesPath,
'mkdir -p ' . $sharedPath,
'mkdir -p ' . $releasePath,
'cd ' . $releasesPath . ';ln -snf ./' . $releaseIdentifier . ' next'
sprintf('mkdir -p %s', $application->getReleasesPath()),
sprintf('mkdir -p %s', $application->getSharedPath()),
sprintf('mkdir -p %s', $deployment->getApplicationReleasePath($application)),
sprintf('cd %s;ln -snf ./%s next', $application->getReleasesPath(), $deployment->getReleaseIdentifier())
];
$this->shell->executeOrSimulate($commands, $node, $deployment);
}

/**
* @codeCoverageIgnore
*/
public function simulate(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$this->execute($node, $application, $deployment, $options);
}

public function rollback(Node $node, Application $application, Deployment $deployment, array $options = [])
{
$releasesPath = $application->getReleasesPath();
$releasePath = $deployment->getApplicationReleasePath($application);
$commands = [
'rm ' . $releasesPath . '/next',
'rm -rf ' . $releasePath
sprintf('rm %s/next', $application->getReleasesPath()),
sprintf('rm -rf %s', $deployment->getApplicationReleasePath($application))
];
$this->shell->execute($commands, $node, $deployment, true);
}
Expand Down
48 changes: 48 additions & 0 deletions tests/Unit/Task/CreateDirectoriesTaskTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace TYPO3\Surf\tests\Unit\Task;

/*
* This file is part of TYPO3 Surf.
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

use TYPO3\Surf\Domain\Model\Task;
use TYPO3\Surf\Task\CreateDirectoriesTask;
use PHPUnit\Framework\TestCase;

class CreateDirectoriesTaskTest extends BaseTaskTest
{

/**
* @test
*/
public function executeSuccessfully(): void
{
$this->task->execute($this->node, $this->application, $this->deployment);
$this->assertCommandExecuted(sprintf('mkdir -p %s', $this->application->getReleasesPath()));
$this->assertCommandExecuted(sprintf('mkdir -p %s', $this->application->getSharedPath()));
$this->assertCommandExecuted(sprintf('mkdir -p %s', $this->deployment->getApplicationReleasePath($this->application)));
$this->assertCommandExecuted(sprintf('cd %s;ln -snf ./%s next', $this->application->getReleasesPath(), $this->deployment->getReleaseIdentifier()));
}

/**
* @test
*/
public function rollbackSuccessfully(): void
{
$this->task->rollback($this->node, $this->application, $this->deployment);
$this->assertCommandExecuted(sprintf('rm %s/next', $this->application->getReleasesPath()));
$this->assertCommandExecuted(sprintf('rm -rf %s', $this->deployment->getApplicationReleasePath($this->application)));
}

/**
* @return CreateDirectoriesTask
*/
protected function createTask()
{
return new CreateDirectoriesTask();
}
}

0 comments on commit c31b440

Please sign in to comment.