예제 #1
0
 /**
  * List an organizations sites
  *
  * ## OPTIONS
  *
  * [--org=<org>]
  * : Organization name or Id
  *
  * [--add=<site>]
  * : Site to add to organization
  *
  * [--remove=<site>]
  * : Site to remove from organization
  *
  * @subcommand sites
  *
  */
 public function sites($args, $assoc_args)
 {
     $orgs = array();
     $user = new User();
     foreach ($user->organizations() as $id => $org) {
         $orgs[$id] = $org->name;
     }
     if (!isset($assoc_args['org']) or empty($assoc_args['org'])) {
         $selected_org = Terminus::menu($orgs, false, "Choose an organization");
     } else {
         $selected_org = $assoc_args['org'];
     }
     $org = new Organization($selected_org);
     if (isset($assoc_args['add'])) {
         $add = SiteFactory::instance(Input::site($assoc_args, 'add'));
         Terminus::confirm("Are you sure you want to add %s to %s ?", $assoc_args, array($add->getName(), $org->name));
         $org->addSite($add);
         Terminus::success("Added site!");
         return true;
     }
     if (isset($assoc_args['remove'])) {
         $remove = SiteFactory::instance(Input::site($assoc_args, 'remove'));
         Terminus::confirm("Are you sure you want to remove %s to %s ?", $assoc_args, array($remove->getName(), $org->name));
         $org->removeSite($remove);
         Terminus::success("Removed site!");
         return true;
     }
     $sites = $org->getSites();
     $data = array();
     foreach ($sites as $site) {
         $data[] = array('name' => $site->site->name, 'service level' => isset($site->site->service_level) ? $site->site->service_level : '', 'framework' => isset($site->site->framework) ? $site->site->framework : '', 'created' => date('Y-m-d H:i:s', $site->site->created));
     }
     $this->handleDisplay($data);
 }
예제 #2
0
 /**
  * List an organization's sites
  *
  * ## OPTIONS
  *
  * [--org=<id>]
  * : Organization id
  *
  * [--tag=<tag>]
  * : Tag name to filter sites list by
  *
  * [--add=<site>]
  * : Site to add to organization
  *
  * [--remove=<site>]
  * : Site to remove from organization
  *
  * @subcommand sites
  *
  */
 public function sites($args, $assoc_args)
 {
     $org_id = Input::orgid($assoc_args, 'org', null, array('allow_none' => false));
     $org = new Organization($org_id);
     if (isset($assoc_args['add'])) {
         $add = SiteFactory::instance(Input::sitename($assoc_args, 'add'));
         Terminus::confirm("Are you sure you want to add %s to %s ?", $assoc_args, array($add->getName(), $org->name));
         $org->addSite($add);
         Terminus::success("Added site!");
         return true;
     }
     if (isset($assoc_args['remove'])) {
         $remove = SiteFactory::instance(Input::sitename($assoc_args, 'remove'));
         Terminus::confirm("Are you sure you want to remove %s to %s ?", $assoc_args, array($remove->getName(), $org->name));
         $org->removeSite($remove);
         Terminus::success("Removed site!");
         return true;
     }
     $org->siteMemberships->fetch();
     $memberships = $org->siteMemberships->all();
     foreach ($memberships as $membership) {
         if (isset($assoc_args['tag']) && !in_array($assoc_args['tag'], $membership->get('tags'))) {
             continue;
         }
         $site = $membership->get('site');
         $data[] = array('name' => $site->name, 'id' => $site->id, 'service_level' => $site->service_level, 'framework' => $site->framework, 'created' => date('Y-m-d H:i:s', $site->created), 'tags' => $membership->get('tags'));
     }
     $this->handleDisplay($data);
 }
예제 #3
0
 protected function success_or_failure($r)
 {
     list($type, $msg) = $r;
     if ('success' == $type) {
         \Terminus::success($msg);
         $status = 0;
     } else {
         \Terminus::warning($msg);
         $status = 1;
     }
     return $status;
 }
예제 #4
0
 /**
  * List an organization's sites
  *
  * ## OPTIONS
  *
  * [--org=<id|name>]
  * : Organization UUID or name
  *
  * [--tag=<tag>]
  * : Tag name to filter sites list by
  *
  * [--add=<site>]
  * : Site to add to organization
  *
  * [--remove=<site>]
  * : Site to remove from organization
  *
  * @subcommand sites
  *
  */
 public function sites($args, $assoc_args)
 {
     $org_id = Input::orgid($assoc_args, 'org', null, array('allow_none' => false));
     $orgs = new UserOrganizationMemberships();
     $org = $orgs->get($org_id);
     $memberships = $org->site_memberships;
     if (isset($assoc_args['add'])) {
         $site = $this->sites->get(Input::sitename($assoc_args, 'add'));
         Terminus::confirm('Are you sure you want to add %s to %s ?', $assoc_args, array($site->get('name'), $org->get('name')));
         $memberships->addMember($site);
         Terminus::success('Added site!');
         return true;
     }
     if (isset($assoc_args['remove'])) {
         $site_id = $assoc_args['remove'];
         $member = $memberships->get($assoc_args['remove']);
         $site = $member->get('site');
         Terminus::confirm('Are you sure you want to remove %s from %s ?', $assoc_args, array($site->name, $org->get('name')));
         $member->removeMember();
         Terminus::success('Removed site!');
         return true;
     }
     $memberships = $org->getSites();
     foreach ($memberships as $membership) {
         if (isset($assoc_args['tag']) && !in_array($assoc_args['tag'], $membership->get('tags'))) {
             continue;
         }
         $site = $membership->get('site');
         $data_array = array('name' => null, 'id' => null, 'service_level' => null, 'framework' => null, 'created' => null, 'tags' => $membership->get('tags'));
         foreach ($data_array as $key => $value) {
             if ($value == null && isset($site->{$key})) {
                 $data_array[$key] = $site->{$key};
             }
         }
         $data_array['created'] = date('Y-m-dTH:i:s', $data_array['created']);
         $data[] = $data_array;
     }
     $this->outputter->outputRecordList($data);
 }
예제 #5
0
 /**
  * Outputs basic response success/failure messages
  *
  * @param [array] $response Array from response
  * @param [array] $messages Array of response strings
  *        [string] success  Displayed on success
  *        [string] failure  Displayed on error
  */
 protected function responseOutput($response, $messages = array())
 {
     $default_messages = array('success' => 'The operation has succeeded.', 'failure' => 'The operation was unsuccessful.');
     $messages = array_merge($default_messages, $messages);
     if ($response['status_code'] == 200) {
         Terminus::success($messages['success']);
     } else {
         Terminus::error($messages['failure']);
     }
 }
예제 #6
0
파일: sites.php 프로젝트: xwp/pantheon-cli
 /**
  * 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.');
     }
 }
예제 #7
0
파일: site.php 프로젝트: mikevanwinkle/cli
 /**
  * Complete wipe and reset a site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to use
  *
  * [--env=<env>]
  * : Specify environment, default = dev
  */
 public function wipe($args, $assoc_args)
 {
     try {
         $env = @$assoc_args['env'] ?: 'dev';
         $site = SiteFactory::instance(Input::site($assoc_args));
         $site_id = $site->getId();
         $env = Input::env($assoc_args, 'env');
         Terminus::line("Wiping %s %s", array($site_id, $env));
         $resp = $site->environment($env)->wipe();
         if ($resp) {
             $this->waitOnWorkflow('sites', $site_id, $resp['data']->id);
             Terminus::success("Successfully wiped %s -- %s", array($site->getName(), $env));
         }
     } catch (Exception $e) {
         Terminus::error("%s", array($e->getMessage()));
     }
 }
예제 #8
0
파일: site.php 프로젝트: skyywalk3rr/cli
 /**
  * Complete wipe and reset a site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to use
  *
  * [--env=<env>]
  * : Environment to be wiped
  */
 public function wipe($args, $assoc_args)
 {
     $site = SiteFactory::instance(Input::sitename($assoc_args));
     $environment_id = Input::env($assoc_args, 'env');
     Terminus::confirm(sprintf("Are you sure you want to wipe %s - %s?", $site->getName(), $environment_id));
     $workflow = $site->environment($environment_id)->wipe();
     $workflow->wait();
     Terminus::success(sprintf("Successfully wiped %s - %s", $site->getName(), $environment_id));
 }
예제 #9
0
파일: site.php 프로젝트: newtoid/cli
 /**
  * Complete wipe and reset a site
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to use
  *
  * [--env=<env>]
  * : Environment to be wiped
  */
 public function wipe($args, $assoc_args)
 {
     $site = $this->sites->get(Input::sitename($assoc_args));
     $env = $site->environments->get(Input::env($assoc_args, 'env'));
     Terminus::confirm(sprintf('Are you sure you want to wipe %s - %s?', $site->get('name'), $env->get('id')));
     $workflow = $env->wipe();
     $workflow->wait();
     Terminus::success(sprintf('Successfully wiped %s - %s', $site->get('name'), $env->get('id')));
 }
예제 #10
0
파일: sites.php 프로젝트: mikevanwinkle/cli
 /**
  * Delete a site from pantheon
  *
  * ## OPTIONS
  * --site=<site>
  * : Id of the site you want to delete
  *
  * [--all]
  * : Just kidding ... we won't let you do that.
  *
  * [--force]
  * : to skip the confirmations
  *
  */
 function delete($args, $assoc_args)
 {
     $site_to_delete = SiteFactory::instance(@$assoc_args['site']);
     if (!$site_to_delete) {
         foreach (SiteFactory::instance() as $id => $site) {
             $site->id = $id;
             $sites[] = $site;
             $menu[] = $site->information->name;
         }
         $index = Terminus::menu($menu, null, "Select a site to delete");
         $site_to_delete = $sites[$index];
     }
     if (!isset($assoc_args['force']) and !Terminus::get_config('yes')) {
         // if the force option isn't used we'll ask you some annoying questions
         Terminus::confirm(sprintf("Are you sure you want to delete %s?", $site_to_delete->information->name));
         Terminus::confirm("Are you really sure?");
     }
     Terminus::line(sprintf("Deleting %s ...", $site_to_delete->information->name));
     $response = \Terminus_Command::request('sites', $site_to_delete->id, '', 'DELETE');
     Terminus::success("Deleted %s!", $site_to_delete->information->name);
 }
예제 #11
0
 /**
  * Update a meta field.
  *
  * ## OPTIONS
  *
  * <id>
  * : The ID of the object.
  *
  * <key>
  * : The name of the meta field to update.
  *
  * [<value>]
  * : The new value. If ommited, the value is read from STDIN.
  *
  * [--format=<format>]
  * : The serialization format for the value. Default is plaintext.
  *
  * @alias set
  */
 public function update($args, $assoc_args)
 {
     list($object_id, $meta_key) = $args;
     $meta_value = \Terminus::get_value_from_arg_or_stdin($args, 2);
     $meta_value = \Terminus::read_value($meta_value, $assoc_args);
     $success = \update_metadata($this->meta_type, $object_id, $meta_key, $meta_value);
     if ($success) {
         \Terminus::success("Updated custom field.");
     } else {
         \Terminus::error("Failed to update custom field.");
     }
 }
예제 #12
0
파일: site.php 프로젝트: reynoldsalec/cli
 /**
  * Delete a site from pantheon
  *
  * ## OPTIONS
  * [--site=<site>]
  * : ID of the site you want to delete
  *
  * [--force]
  * : to skip the confirmations
  */
 function delete($args, $assoc_args)
 {
     $sitename = Input::sitename($assoc_args);
     $site_id = $this->sitesCache->findID($sitename);
     $site_to_delete = new Site($site_id);
     if (!isset($assoc_args['force']) and !Terminus::get_config('yes')) {
         // if the force option isn't used we'll ask you some annoying questions
         Terminus::confirm(sprintf("Are you sure you want to delete %s?", $site_to_delete->information->name));
         Terminus::confirm("Are you really sure?");
     }
     Terminus::line(sprintf("Deleting %s ...", $site_to_delete->information->name));
     $response = \Terminus_Command::request('sites', $site_to_delete->id, '', 'DELETE');
     $this->sitesCache->remove($sitename);
     Terminus::success("Deleted %s!", $sitename);
 }