Ejemplo n.º 1
0
 public function removeSite(Site $site)
 {
     $workflow = new Workflow('remove_organization_site_membership', 'organizations', $this);
     $workflow->setParams(array('site_id' => $site->getId()));
     $workflow->setMethod("POST");
     $workflow->start();
     $workflow->wait();
     return $workflow;
 }
Ejemplo n.º 2
0
 public function removeSite(Site $site)
 {
     $workflow = $this->workflows->create('remove_organization_site_membership', array('params' => array('site_id' => $site->getId())));
     $workflow->wait();
     return $workflow;
 }
Ejemplo n.º 3
0
 /**
  * Retrieve information about the site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : name of the site to work with
  *
  * [--field=<field>]
  * : field to return
  *
  * ## EXAMPLES
  *
  */
 public function info($args, $assoc_args)
 {
     $sitename = Input::site($assoc_args);
     $site_id = SitesCache::find($sitename);
     $site = new Site($site_id);
     $site->fetch();
     # Fetch environment data for sftp/git connection info
     $site->environmentsCollection->fetch();
     if (isset($assoc_args['field'])) {
         $field = $assoc_args['field'];
         Terminus::line($site->info($field));
     } else {
         $this->handleDisplay($site->info(), $args);
     }
 }
Ejemplo n.º 4
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.');
     }
 }
Ejemplo n.º 5
0
 /**
  * Create a new site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Name of the site to create (machine-readable)
  *
  * [--name=<name>]
  * : (deprecated) use --site instead
  *
  * [--label=<label>]
  * : Label for the site
  *
  * [--product=<productid>]
  * : Specify the upstream product to use
  *
  * [--import=<url>]
  * : A url to import a valid archive
  *
  * [--org=<org>]
  * : UUID of organization into which to add this site
  *
  */
 public function create($args, $assoc_args)
 {
     $options = array();
     $options['label'] = Input::string($assoc_args, 'label', "Human readable label for the site");
     $suggested_name = Utils\sanitize_name($options['label']);
     if (array_key_exists('name', $assoc_args)) {
         // Deprecated but kept for backwards compatibility
         $options['name'] = $assoc_args['name'];
     } elseif (array_key_exists('site', $assoc_args)) {
         $options['name'] = $assoc_args['site'];
     } else {
         $options['name'] = Input::string($assoc_args, 'site', "Machine name of the site; used as part of the default URL (if left blank will be {$suggested_name})", $suggested_name);
     }
     if ($org_id = Input::orgid($assoc_args, 'org', false)) {
         $options['organization_id'] = $org_id;
     }
     if (!isset($assoc_args['import'])) {
         $product = Input::product($assoc_args, 'product');
         $options['product_id'] = $product['id'];
         Terminus::line(sprintf("Creating new %s installation ... ", $product['longname']));
     }
     $workflow = Site::create($options);
     $workflow->wait();
     Terminus::success("Pow! You created a new site!");
     // Add Name->ID mapping to SitesCache
     $site_id = $workflow->status()->final_task->site_id;
     $sites_cache = new Terminus\SitesCache();
     $sites_cache->add(array($options['name'] => $site_id));
     if (isset($assoc_args['import'])) {
         sleep(10);
         //To stop erroenous site-DNE errors
         Terminus::launch_self('site', array('import'), array('url' => $assoc_args['import'], 'site' => $options['name'], 'element' => 'all'));
     } else {
         Terminus::launch_self('site', array('info'), array('site' => $options['name']));
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Retrieve information about the site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : name of the site to work with
  *
  * [--field=<field>]
  * : field to return
  *
  * ## EXAMPLES
  *
  */
 public function info($args, $assoc_args)
 {
     $sitename = Input::site($assoc_args);
     $site = Site::createFromName($sitename);
     if (isset($assoc_args['field'])) {
         $field = $assoc_args['field'];
         Terminus::line($site->info($field));
     } else {
         $this->handleDisplay($site->info(), $args);
     }
 }