Scalr\Upgrade\UpgradeHandler::run PHP Method

run() public method

Runs upgrade process
public run ( ) : boolean
return boolean Returns true if all updates completed successfully, false otherwise
    public function run()
    {
        if (!self::checkPid()) {
            $this->console->warning("Cannot start a new process because another one has already been started.");
            return false;
        }
        register_shutdown_function('Scalr\\Upgrade\\UpgradeHandler::removePid');
        //Loads updates
        $successful = $this->loadUpdates();
        if (isset($this->opt->cmd) && $this->opt->cmd == self::CMD_RUN_SPECIFIC) {
            $pending = [];
            if (!isset($this->updates[$this->opt->uuid])) {
                $this->console->warning("Could not find specified update %s", $this->opt->uuid);
                exit(1);
            }
            $pending[] = $this->updates[$this->opt->uuid];
        } else {
            $dt = new \DateTime($this->getLastDate(), new \DateTimeZone('UTC'));
            $pending = $this->updates->getPendingUpdates($dt->getTimestamp());
        }
        if (count($pending) == 0) {
            $this->console->out('Scalr is up-to-date');
            return $successful;
        }
        $this->console->success('Starting Scalr upgrade');
        //Applies updates
        foreach ($pending as $update) {
            $update->console->interactive = $this->console->interactive;
            $successful = $this->applyUpdate($update) && $successful;
        }
        $this->console->success('Done');
        return $successful;
    }

Usage Example

Example #1
0
if (isset($opt['n']) || isset($opt['new'])) {
    $template = UpgradeHandler::getPathToUpdates() . '/Template.php';
    if (!is_readable($template)) {
        $console->error('Could not open template file for reading ' . $template);
        exit;
    }
    $released = gmdate('YmdHis');
    $pathname = UpgradeHandler::getPathToUpdates() . '/Update' . $released . '.php';
    $tpl = PhpTemplate::load($template, array('upd_released' => $released, 'upd_uuid' => \Scalr::GenerateUID()));
    if ($console->confirm("Are you sure you want to create a new upgrade class?")) {
        if (file_put_contents($pathname, $tpl) === false) {
            $console->error('Could not write to file "%s"', $pathname);
            exit;
        }
        $console->success('Upgrade class "%s" has been successfully created.', realpath($pathname));
    }
    exit;
}
if (isset($opt['force'])) {
    UpgradeHandler::removePid();
}
$upgrade = new UpgradeHandler($options);
if (!$upgrade->run()) {
    exit(1);
}
$scalrInfo = Scalr::getContainer()->version();
try {
    Scalr::getDb()->Execute("\n        REPLACE `scalr_hosts`\n        SET `host` = ?, `version` = ?, `edition` = ?, `git_commit` = ?, `git_commit_added` = ?\n    ", [php_uname("n"), $scalrInfo['version'], $scalrInfo['edition'], empty($scalrInfo['gitRevision']) ? null : $scalrInfo['gitRevision'], empty($scalrInfo['gitDate']) || ($gts = strtotime($scalrInfo['gitDate'])) === false ? null : date("Y-m-d H:i:s", $gts)]);
} catch (Exception $e) {
    Scalr::logException($e);
}
All Usage Examples Of Scalr\Upgrade\UpgradeHandler::run