mirror of https://github.com/hauke68/Magallanes
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.3 KiB
75 lines
2.3 KiB
13 years ago
|
<?php
|
||
11 years ago
|
/*
|
||
|
* This file is part of the Magallanes package.
|
||
|
*
|
||
|
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||
|
*
|
||
|
* For the full copyright and license information, please view the LICENSE
|
||
|
* file that was distributed with this source code.
|
||
|
*/
|
||
|
|
||
11 years ago
|
namespace Mage\Task\BuiltIn\Deployment;
|
||
|
|
||
|
use Mage\Task\AbstractTask;
|
||
|
use Mage\Task\Releases\IsReleaseAware;
|
||
|
use Mage\Task\Releases\SkipOnOverride;
|
||
|
|
||
|
use Exception;
|
||
|
|
||
|
/**
|
||
|
* Task for Releasing a Deploy
|
||
|
*
|
||
|
* @author Andrés Montañez <andres@andresmontanez.com>
|
||
|
*/
|
||
|
class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
|
||
13 years ago
|
{
|
||
11 years ago
|
/**
|
||
|
* (non-PHPdoc)
|
||
|
* @see \Mage\Task\AbstractTask::getName()
|
||
|
*/
|
||
13 years ago
|
public function getName()
|
||
|
{
|
||
|
return 'Releasing [built-in]';
|
||
|
}
|
||
|
|
||
11 years ago
|
/**
|
||
|
* Releases a Deployment: points the current symbolic link to the release directory
|
||
|
* @see \Mage\Task\AbstractTask::run()
|
||
|
*/
|
||
13 years ago
|
public function run()
|
||
|
{
|
||
13 years ago
|
if ($this->getConfig()->release('enabled', false) == true) {
|
||
|
$releasesDirectory = $this->getConfig()->release('directory', 'releases');
|
||
|
$symlink = $this->getConfig()->release('symlink', 'current');
|
||
13 years ago
|
|
||
13 years ago
|
if (substr($symlink, 0, 1) == '/') {
|
||
13 years ago
|
$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
|
||
13 years ago
|
}
|
||
|
|
||
13 years ago
|
$currentCopy = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
|
||
13 years ago
|
|
||
11 years ago
|
// Fetch the user and group from base directory; defaults usergroup to 33:33
|
||
13 years ago
|
$userGroup = '33:33';
|
||
11 years ago
|
$resultFetch = $this->runCommandRemote('ls -ld . | awk \'{print \$3":"\$4}\'', $userGroup);
|
||
13 years ago
|
|
||
13 years ago
|
// Remove symlink if exists; create new symlink and change owners
|
||
13 years ago
|
$command = 'rm -f ' . $symlink
|
||
13 years ago
|
. ' ; '
|
||
13 years ago
|
. 'ln -sf ' . $currentCopy . ' ' . $symlink
|
||
|
. ' && '
|
||
13 years ago
|
. 'chown -h ' . $userGroup . ' ' . $symlink
|
||
|
. ' && '
|
||
13 years ago
|
. 'chown -R ' . $userGroup . ' ' . $currentCopy;
|
||
11 years ago
|
$result = $this->runCommandRemote($command);
|
||
|
|
||
|
// Set Directory Releases to same owner
|
||
|
$result = $this->runCommandRemote('chown ' . $userGroup . ' ' . $releasesDirectory);
|
||
13 years ago
|
|
||
13 years ago
|
return $result;
|
||
13 years ago
|
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|