Changeset View
Changeset View
Standalone View
Standalone View
branches/5.3.x/core/units/helpers/deployment_helper.php
Show All 15 Lines | |||||
class DeploymentHelper extends kHelper { | class DeploymentHelper extends kHelper { | ||||
/** | /** | ||||
* How many symbols from sql should be shown. | * How many symbols from sql should be shown. | ||||
*/ | */ | ||||
const SQL_TRIM_LENGTH = 120; | const SQL_TRIM_LENGTH = 120; | ||||
const STAGE_DB_MIGRATE = 'db-migrate'; | |||||
const STAGE_CACHE_RESET = 'cache-reset'; | |||||
/** | /** | ||||
* Name of module, that is processed right now. | * Name of module, that is processed right now. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
private $moduleName = ''; | private $moduleName = ''; | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* IP Address of script invoker. | * IP Address of script invoker. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
public $ip = ''; | public $ip = ''; | ||||
/** | /** | ||||
* Deployment stages to run. | |||||
* | |||||
* @var array | |||||
*/ | |||||
public $stages = array( | |||||
self::STAGE_DB_MIGRATE, | |||||
self::STAGE_CACHE_RESET, | |||||
); | |||||
/** | |||||
* Event, that triggered deployment. | * Event, that triggered deployment. | ||||
* | * | ||||
* @var kEvent | * @var kEvent | ||||
*/ | */ | ||||
private $_event; | private $_event; | ||||
/** | /** | ||||
* Field values for log record. | * Field values for log record. | ||||
Show All 12 Lines | |||||
kUtil::setResourceLimit(); | kUtil::setResourceLimit(); | ||||
$this->_event = new kEvent('adm:OnDummy'); | $this->_event = new kEvent('adm:OnDummy'); | ||||
$this->isCommandLine = isset($GLOBALS['argv']) && count($GLOBALS['argv']); | $this->isCommandLine = isset($GLOBALS['argv']) && count($GLOBALS['argv']); | ||||
if ( !$this->isCommandLine ) { | if ( !$this->isCommandLine ) { | ||||
$this->ip = $this->Application->getClientIp(); | $this->ip = $this->Application->getClientIp(); | ||||
} | } | ||||
elseif ( isset($GLOBALS['argv'][3]) ) { | else { | ||||
if ( isset($GLOBALS['argv'][3]) ) { | |||||
$this->ip = $GLOBALS['argv'][3]; | $this->ip = $GLOBALS['argv'][3]; | ||||
} | } | ||||
if ( isset($GLOBALS['argv'][4]) ) { | |||||
$new_stages = explode(',', $GLOBALS['argv'][4]); | |||||
$unknown_stages = array_diff($new_stages, $this->stages); | |||||
if ( $unknown_stages ) { | |||||
throw new InvalidArgumentException('Unknown deployment stages: ' . implode(', ', $unknown_stages)); | |||||
} | |||||
$this->stages = $new_stages; | |||||
} | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* Sets event, associated with deployment. | * Sets event, associated with deployment. | ||||
* | * | ||||
* @param kEvent $event Event. | * @param kEvent $event Event. | ||||
* | * | ||||
* @return void | * @return void | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
{ | { | ||||
if ( !$this->isCommandLine ) { | if ( !$this->isCommandLine ) { | ||||
echo '<pre style="font-size: 10pt; color: #BBB; background-color: black; border: 2px solid darkgreen; padding: 8px;">' . PHP_EOL; | echo '<pre style="font-size: 10pt; color: #BBB; background-color: black; border: 2px solid darkgreen; padding: 8px;">' . PHP_EOL; | ||||
} | } | ||||
$ret = true; | $ret = true; | ||||
$this->dryRun = $dry_run; | $this->dryRun = $dry_run; | ||||
if ( in_array(self::STAGE_DB_MIGRATE, $this->stages) ) { | |||||
foreach ( $this->Application->ModuleInfo as $module_name => $module_info ) { | foreach ( $this->Application->ModuleInfo as $module_name => $module_info ) { | ||||
$this->moduleName = $module_name; | $this->moduleName = $module_name; | ||||
if ( !file_exists($this->getModuleFile('project_upgrades.sql')) ) { | if ( !file_exists($this->getModuleFile('project_upgrades.sql')) ) { | ||||
continue; | continue; | ||||
} | } | ||||
$ret = $ret && $this->deploy($module_name); | $ret = $ret && $this->deploy($module_name); | ||||
} | } | ||||
} | |||||
if ( in_array(self::STAGE_CACHE_RESET, $this->stages) ) { | |||||
if ( $ret && !$this->dryRun ) { | if ( $ret && !$this->dryRun ) { | ||||
$this->resetCaches(); | $this->resetCaches(); | ||||
$this->refreshThemes(); | $this->refreshThemes(); | ||||
} | } | ||||
} | |||||
if ( !$this->isCommandLine ) { | if ( !$this->isCommandLine ) { | ||||
echo kUtil::escape($this->_runShellScript()); | echo kUtil::escape($this->_runShellScript()); | ||||
echo '</pre>' . PHP_EOL; | echo '</pre>' . PHP_EOL; | ||||
} | } | ||||
return $ret; | return $ret; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 516 Lines • ▼ Show 20 Line(s) | |||||
$text = kUtil::escape($text); | $text = kUtil::escape($text); | ||||
} | } | ||||
echo $text . ($new_line ? PHP_EOL : ''); | echo $text . ($new_line ? PHP_EOL : ''); | ||||
return $this; | return $this; | ||||
} | } | ||||
} | } | ||||
No newline at end of file |