2011-11-23 04:17:06 +01:00
|
|
|
<?php
|
|
|
|
abstract class Mage_Task_TaskAbstract
|
|
|
|
{
|
2011-11-23 12:38:52 +01:00
|
|
|
protected $_config = null;
|
2012-01-04 02:25:42 +01:00
|
|
|
protected $_inRollback = false;
|
2011-11-23 12:38:52 +01:00
|
|
|
|
2011-11-23 04:17:06 +01:00
|
|
|
public abstract function getName();
|
|
|
|
|
2011-11-23 12:38:52 +01:00
|
|
|
public abstract function run();
|
|
|
|
|
2012-01-04 02:25:42 +01:00
|
|
|
public final function __construct(Mage_Config $config, $inRollback = false)
|
2011-11-23 12:38:52 +01:00
|
|
|
{
|
|
|
|
$this->_config = $config;
|
2012-01-04 02:25:42 +01:00
|
|
|
$this->_inRollback = $inRollback;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function inRollback()
|
|
|
|
{
|
|
|
|
return $this->_inRollback;
|
2011-11-23 12:38:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
}
|
2011-11-23 04:17:06 +01:00
|
|
|
|
2012-01-01 16:36:41 +01:00
|
|
|
protected final function _runLocalCommand($command, &$output = null)
|
2011-11-23 04:17:06 +01:00
|
|
|
{
|
2012-01-01 16:36:41 +01:00
|
|
|
return Mage_Console::executeCommand($command, $output);
|
2011-11-23 04:17:06 +01:00
|
|
|
}
|
|
|
|
|
2012-01-01 16:36:41 +01:00
|
|
|
protected final function _runRemoteCommand($command, &$output = null)
|
2011-11-23 04:17:06 +01:00
|
|
|
{
|
2012-02-04 19:31:42 +01:00
|
|
|
if ($this->_config->release('enabled', false) == true) {
|
|
|
|
if ($this instanceOf Mage_Task_Releases_BuiltIn) {
|
|
|
|
$releasesDirectory = '';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$releasesDirectory = '/'
|
|
|
|
. $this->_config->release('directory', 'releases')
|
|
|
|
. '/'
|
|
|
|
. $this->_config->getReleaseId();
|
|
|
|
}
|
|
|
|
|
2012-02-04 18:48:15 +01:00
|
|
|
} else {
|
|
|
|
$releasesDirectory = '';
|
|
|
|
}
|
|
|
|
|
2012-02-15 21:45:59 +01:00
|
|
|
$localCommand = 'ssh -p ' . $this->_config->deployment('port', '22') . ' '
|
|
|
|
. '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '
|
2012-01-01 18:46:05 +01:00
|
|
|
. $this->_config->deployment('user') . '@' . $this->_config->getHost() . ' '
|
2012-02-04 18:48:15 +01:00
|
|
|
. '"cd ' . rtrim($this->_config->deployment('to'), '/') . $releasesDirectory . ' && '
|
2011-11-23 12:38:52 +01:00
|
|
|
. $command . '"';
|
|
|
|
|
2012-01-01 16:36:41 +01:00
|
|
|
return $this->_runLocalCommand($localCommand, $output);
|
2011-11-23 04:17:06 +01:00
|
|
|
}
|
|
|
|
}
|