ReleaseTask::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 16
ccs 9
cts 9
cp 1
crap 2
rs 10
1
<?php
2
3
/*
4
 * This file is part of the Magallanes package.
5
 *
6
 * (c) Andrés Montañez <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mage\Task\BuiltIn\Deploy;
13
14
use Mage\Task\Exception\ErrorException;
15
use Mage\Task\ExecuteOnRollbackInterface;
16
use Symfony\Component\Process\Process;
17
use Mage\Task\AbstractTask;
18
19
/**
20
 * Release Task - Create the Symlink
21
 *
22
 * @author Andrés Montañez <[email protected]>
23
 */
24
class ReleaseTask extends AbstractTask implements ExecuteOnRollbackInterface
25
{
26 48
    public function getName(): string
27
    {
28 48
        return 'deploy/release';
29
    }
30
31 14
    public function getDescription(): string
32
    {
33 14
        return '[Release] Creating Symlink';
34
    }
35
36 14
    public function execute(): bool
37
    {
38 14
        if (!$this->runtime->getEnvOption('releases', false)) {
39 1
            throw new ErrorException('This task is only available with releases enabled', 40);
40
        }
41
42 13
        $hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
43 13
        $releaseId = $this->runtime->getReleaseId();
44
45 13
        $symlink = $this->runtime->getEnvOption('symlink', 'current');
46
47 13
        $cmdLinkRelease = sprintf('cd %s && ln -snf releases/%s %s', $hostPath, $releaseId, $symlink);
48
49
        /** @var Process $process */
50 13
        $process = $this->runtime->runRemoteCommand($cmdLinkRelease, false, 0);
51 13
        return $process->isSuccessful();
52
    }
53
}
54