Ejemplo n.º 1
0
 /**
  * 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_cache = $this->sitesCache->all();
     $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_cache as $site_cache) {
         $site = new Site($site_cache['id']);
         $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 updates to %s ( run update.php:%s, xoption:%s ) ", array($site->getName(), var_export($update, 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.
                 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.');
     }
 }