/** * Update alls dev sites with an available upstream update. * * ## OPTIONS * * [--report] * : If set output will contain list of sites and whether they are up-to-date * * [--upstream=<upstream>] * : Specify a specific upstream to check for updating. * * [--no-updatedb] * : Use flag to skip running update.php after the update has applied * * [--xoption=<theirs|ours>] * : Corresponds to git's -X option, set to 'theirs' by default -- https://www.kernel.org/pub/software/scm/git/docs/git-merge.html * * @subcommand mass-update */ public function mass_update($args, $assoc_args) { $sites = SiteFactory::instance(); $env = 'dev'; $upstream = Input::optional('upstream', $assoc_args, false); $data = array(); $report = Input::optional('report', $assoc_args, false); $confirm = Input::optional('confirm', $assoc_args, false); // Start status messages. if ($upstream) { Terminus::line('Looking for sites using ' . $upstream . '.'); } foreach ($sites as $site) { $updates = $site->getUpstreamUpdates(); if (!isset($updates->behind)) { // No updates, go back to start. continue; } // Check for upstream argument and site upstream URL match. $siteUpstream = $site->info('upstream'); if ($upstream and isset($siteUpstream->url)) { if ($siteUpstream->url != $upstream) { // Uptream doesn't match, go back to start. continue; } } if ($updates->behind > 0) { $data[$site->getName()] = array('site' => $site->getName(), 'status' => "Needs update"); $noupdatedb = Input::optional($assoc_args, 'updatedb', false); $update = $noupdatedb ? false : true; $xoption = Input::optional($assoc_args, 'xoption', 'theirs'); if (!$report) { $confirmed = Input::yesno("Apply upstream updatefs to %s ( run update.php:%s, xoption:%s ) ", array($site->getName(), var_export($update, 1), var_export($xoption, 1))); if (!$confirmed) { continue; } // Suer says No, go back to start. // Backup the DB so the client can restore if something goes wrong. Terminus::line('Backing up ' . $site->getName() . '.'); $backup = $site->environment('dev')->createBackup(array('element' => 'all')); // Only continue if the backup was successful. if ($backup) { Terminus::success("Backup of " . $site->getName() . " created."); Terminus::line('Updating ' . $site->getName() . '.'); // Apply the update, failure here would trigger a guzzle exception so no need to validate success. $response = $site->applyUpstreamUpdates($env, $update, $xoption); $data[$site->getName()]['status'] = 'Updated'; Terminus::success($site->getName() . ' is updated.'); } else { $data[$site->getName()]['status'] = 'Backup failed'; Terminus::error('There was a problem backing up ' . $site->getName() . '. Update aborted.'); } } } else { if (isset($assoc_args['report'])) { $data[$site->getName()] = array('site' => $site->getName(), 'status' => "Up to date"); } } } if (!empty($data)) { sort($data); $this->handleDisplay($data); } else { Terminus::line('No sites in need up updating.'); } }
/** * Update alls dev sites with an available upstream update. * * ## OPTIONS * * [--report] * : If set output will contain list of sites and whether they are up-to-date * * [--upstream=<upstream>] * : Specify a specific upstream to check for updating. * * [--no-updatedb] * : Use flag to skip running update.php after the update has applied * * [--xoption=<theirs|ours>] * : Corresponds to git's -X option, set to 'theirs' by default -- https://www.kernel.org/pub/software/scm/git/docs/git-merge.html * * [--tag=<tag>] * : Tag to filter by * * [--org=<id>] * : Only necessary if using --tag. Organization which has tagged the site thusly * * [--cached] * : Set to prevent rebuilding of sites cache * * @subcommand mass-update */ public function mass_update($args, $assoc_args) { // Ensure the sitesCache is up to date if (!isset($assoc_args['cached'])) { $this->sites->rebuildCache(); } $upstream = Input::optional('upstream', $assoc_args, false); $data = array(); $report = Input::optional('report', $assoc_args, false); $confirm = Input::optional('confirm', $assoc_args, false); $tag = Input::optional('tag', $assoc_args, false); $org = ''; if ($tag) { $org = Input::orgid($assoc_args, 'org'); } $sites = $this->sites->filterAllByTag($tag, $org); // Start status messages. if ($upstream) { $this->log()->info('Looking for sites using ' . $upstream . '.'); } foreach ($sites as $site) { $site->fetch(); $updates = $site->getUpstreamUpdates(); if (!isset($updates->behind)) { // No updates, go back to start. continue; } // Check for upstream argument and site upstream URL match. $siteUpstream = $site->info('upstream'); if ($upstream and isset($siteUpstream->url)) { if ($siteUpstream->url != $upstream) { // Uptream doesn't match, go back to start. continue; } } if ($updates->behind > 0) { $data[$site->get('name')] = array('site' => $site->get('name'), 'status' => "Needs update"); $env = $site->environments->get('dev'); if ($env->getConnectionMode() == 'sftp') { $this->log()->warning('{site} has available updates, but is in SFTP mode. Switch to Git mode to apply updates.', array('site' => $site->get('name'))); $data[$site->get('name')] = array('site' => $site->get('name'), 'status' => "Needs update - switch to Git mode"); continue; } $updatedb = !Input::optional($assoc_args, 'updatedb', false); $xoption = Input::optional($assoc_args, 'xoption', 'theirs'); if (!$report) { $confirmed = Input::yesno("Apply upstream updates to %s ( run update.php:%s, xoption:%s ) ", array($site->get('name'), var_export($updatedb, 1), var_export($xoption, 1))); if (!$confirmed) { continue; } // User says No, go back to start. // Backup the DB so the client can restore if something goes wrong. $this->log()->info('Backing up ' . $site->get('name') . '.'); $backup = $env->createBackup(array('element' => 'all')); // Only continue if the backup was successful. if ($backup) { $this->log()->info("Backup of " . $site->get('name') . " created."); $this->log()->info('Updating ' . $site->get('name') . '.'); // Apply the update, failure here would trigger a guzzle exception so no need to validate success. $response = $site->applyUpstreamUpdates($env->get('id'), $updatedb, $xoption); $data[$site->get('name')]['status'] = 'Updated'; $this->log()->info($site->get('name') . ' is updated.'); } else { $data[$site->get('name')]['status'] = 'Backup failed'; $this->log()->error('There was a problem backing up ' . $site->get('name') . '. Update aborted.'); } } } else { if (isset($assoc_args['report'])) { $data[$site->get('name')] = array('site' => $site->get('name'), 'status' => "Up to date"); } } } if (!empty($data)) { sort($data); $this->output()->outputRecordList($data); } else { $this->log()->info('No sites in need of updating.'); } }