Код: Выделить всё
<?php
// Security key
$key = 'go6qyKw2tvDxbpG7Ss';
if (!isset($_GET['key']) || $_GET['key'] !== $key) {
die;
}
// "/var/www/site/frontend/web/../../" => "/var/www/site"
$root_dir = rtrim(realpath(__DIR__ . '/../../'), '\\/');
// run git pull
$commands = array(
'cd "' . $root_dir . '"',
'git fetch --all',
'git reset --hard origin/master',
'git pull origin master'
);
$git_result = shell_exec(implode(' && ', $commands));
$php_command_tpl = '/usr/bin/php -q {file} &> /dev/null &';
// apply migrations & re-initialize application enviroment
$migrate_command = str_replace('{file}', '"' . $root_dir . '/yii" migrate/up --interactive=0', $php_command_tpl);
$init_command = str_replace('{file}', '"' . $root_dir . '/init" --env=Production --overwrite=All', $php_command_tpl);
$migrate_result = false;
$init_result = false;
// if changes exists
if (stripos($git_result, 'Already up-to-date') === false) {
$migrate_result = shell_exec($migrate_command);
$init_result = shell_exec($init_command);
}
Если вручную в консоли ввести эти две команды(копировал из var_dump ручного запуска этого хука), то они работают.