/
CreateDirectoriesTask.php
74 lines (66 loc) · 2.61 KB
/
CreateDirectoriesTask.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace TYPO3\Deploy\Task;
/* *
* This script belongs to the FLOW3 package "TYPO3.Deploy". *
* *
* */
use \TYPO3\Deploy\Domain\Model\Node;
use \TYPO3\Deploy\Domain\Model\Application;
use \TYPO3\Deploy\Domain\Model\Deployment;
/**
* A task to create initial directories and the release directory for the current release
*
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*/
class CreateDirectoriesTask extends \TYPO3\Deploy\Domain\Model\Task {
/**
* @inject
* @var \TYPO3\Deploy\Domain\Service\ShellCommandService
*/
protected $shell;
/**
* Executes this task
*
* @param \TYPO3\Deploy\Domain\Model\Node $node
* @param \TYPO3\Deploy\Domain\Model\Application $application
* @param \TYPO3\Deploy\Domain\Model\Deployment $deployment
* @param array $options
* @return void
*/
public function execute(Node $node, Application $application, Deployment $deployment, array $options = array()) {
$deploymentPath = $application->getDeploymentPath();
$sharedPath = $application->getSharedPath();
$result = $this->shell->execute('test -d ' . $deploymentPath, $node, $deployment, TRUE);
if ($result === FALSE) {
throw new \Exception('Deployment directory "' . $deploymentPath . '" does not exist on ' . $node->getName(), 1311003253);
}
$this->shell->executeOrSimulate('mkdir -p ' . $deploymentPath . '/releases;mkdir -p ' . $sharedPath, $node, $deployment);
}
/**
* Simulate this task
*
* @param Node $node
* @param Application $application
* @param Deployment $deployment
* @param array $options
* @return void
*/
public function simulate(Node $node, Application $application, Deployment $deployment, array $options = array()) {
$this->execute($node, $application, $deployment, $options);
}
/**
* Rollback this task
*
* @param \TYPO3\Deploy\Domain\Model\Node $node
* @param \TYPO3\Deploy\Domain\Model\Application $application
* @param \TYPO3\Deploy\Domain\Model\Deployment $deployment
* @param array $options
* @return void
* @todo Make the removal of a failed release configurable, sometimes it's necessary to inspect a failed release
*/
public function rollback(Node $node, Application $application, Deployment $deployment, array $options = array()) {
$releasePath = $deployment->getApplicationReleasePath($application);
$this->shell->execute('rm -rf ' . $releasePath, $node, $deployment, TRUE);
}
}
?>