2011-11-23 01:17:06 -02:00
|
|
|
<?php
|
|
|
|
|
class Mage_Task_BuiltIn_Deployment_Rsync
|
|
|
|
|
extends Mage_Task_TaskAbstract
|
2012-02-05 00:42:54 -02:00
|
|
|
implements Mage_Task_Releases_BuiltIn
|
2011-11-23 01:17:06 -02:00
|
|
|
{
|
|
|
|
|
public function getName()
|
|
|
|
|
{
|
2012-01-01 15:46:05 -02:00
|
|
|
if ($this->_config->release('enabled', false) == true) {
|
|
|
|
|
return 'Rsync (with Releases) [built-in]';
|
2011-11-27 12:14:40 -02:00
|
|
|
} else {
|
2012-01-01 15:46:05 -02:00
|
|
|
return 'Rsync [built-in]';
|
2011-11-27 12:14:40 -02:00
|
|
|
}
|
2011-11-23 01:17:06 -02:00
|
|
|
}
|
|
|
|
|
|
2011-11-23 09:38:52 -02:00
|
|
|
public function run()
|
2011-11-23 01:17:06 -02:00
|
|
|
{
|
2011-11-26 23:02:47 -02:00
|
|
|
$excludes = array(
|
|
|
|
|
'.git',
|
|
|
|
|
'.svn',
|
|
|
|
|
'.mage',
|
|
|
|
|
'.gitignore'
|
2011-11-23 01:17:06 -02:00
|
|
|
);
|
2011-11-26 23:02:47 -02:00
|
|
|
|
|
|
|
|
// Look for User Excludes
|
2012-01-01 15:46:05 -02:00
|
|
|
$userExcludes = $this->_config->deployment('excludes', array());
|
2011-11-27 12:14:40 -02:00
|
|
|
|
|
|
|
|
// If we are working with releases
|
2012-01-01 15:46:05 -02:00
|
|
|
$deployToDirectory = $this->_config->deployment('to');
|
|
|
|
|
if ($this->_config->release('enabled', false) == true) {
|
|
|
|
|
$releasesDirectory = $this->_config->release('directory', 'releases');
|
2011-11-27 12:14:40 -02:00
|
|
|
|
2012-01-01 15:46:05 -02:00
|
|
|
$deployToDirectory = rtrim($this->_config->deployment('to'), '/')
|
|
|
|
|
. '/' . $releasesDirectory
|
|
|
|
|
. '/' . $this->_config->getReleaseId();
|
|
|
|
|
$this->_runRemoteCommand('mkdir -p ' . $releasesDirectory . '/' . $this->_config->getReleaseId());
|
2011-11-27 12:14:40 -02:00
|
|
|
}
|
2011-11-23 01:17:06 -02:00
|
|
|
|
|
|
|
|
$command = 'rsync -avz '
|
2012-02-15 18:45:59 -02:00
|
|
|
. '--rsh="ssh -p' . $this->_config->deployment('port', '22') . '" '
|
2011-11-27 11:05:06 -02:00
|
|
|
. $this->_excludes(array_merge($excludes, $userExcludes)) . ' '
|
2012-01-01 15:46:05 -02:00
|
|
|
. $this->_config->deployment('from') . ' '
|
|
|
|
|
. $this->_config->deployment('user') . '@' . $this->_config->getHost() . ':' . $deployToDirectory;
|
2011-11-23 01:17:06 -02:00
|
|
|
|
|
|
|
|
$result = $this->_runLocalCommand($command);
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
2011-11-26 23:02:47 -02:00
|
|
|
|
|
|
|
|
private function _excludes(Array $excludes)
|
|
|
|
|
{
|
|
|
|
|
$excludesRsync = '';
|
|
|
|
|
foreach ($excludes as $exclude) {
|
|
|
|
|
$excludesRsync .= ' --exclude ' . $exclude . ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$excludesRsync = trim($excludesRsync);
|
|
|
|
|
return $excludesRsync;
|
|
|
|
|
}
|
2011-11-23 01:17:06 -02:00
|
|
|
}
|