Пример #1
0
 public function invalid_positionals($args)
 {
     $positionals = $this->query_spec(array('type' => 'positional'));
     for ($i = 0; $i < count($args); $i++) {
         if (!isset($positionals[$i]['token'])) {
             continue;
         }
         $token = preg_replace('#\\[?\\<([a-zA-Z].*)\\>\\]?.*#s', '$1', $positionals[$i]['token']);
         if ("commands" == trim($token) || "email" == trim($token)) {
             // we exit here because the wp and drush commands need to not have validation running since their commands are dependent on their respective code bases.
             return false;
         }
         $regex = "#^({$token})\$#s";
         if (\Terminus::get_config('debug')) {
             Logger::coloredOutput("<Y>Positional match {$regex}</Y>");
         }
         if (!preg_match($regex, $args[$i])) {
             return $args[$i];
         }
     }
     return false;
 }
Пример #2
0
 /**
  * Outputs basic workflow success/failure messages
  *
  * @param [Workflow] $workflow Workflow to output message about
  * @return [void]
  */
 protected function workflowOutput($workflow)
 {
     if ($workflow->get('result') == 'succeeded') {
         Logger::coloredOutput('%2<K>' . $workflow->get('active_description') . '</K>');
     } else {
         $final_task = $workflow->get('final_task');
         Logger::redline($final_task->reason);
     }
 }
Пример #3
0
 /**
  * Create a new site
  *
  * ## OPTIONS
  *
  * [--product=<productid>]
  * : Specify the product to create
  *
  * [--name=<name>]
  * : (deprecated) use --site instead
  *
  * [--site=<site>]
  * : Name of the site to create (machine-readable)
  *
  * [--label=<label>]
  * : Label for the site
  *
  * [--org=<org>]
  * : UUID of organization to add this site to; or "None"
  *
  * [--import=<url>]
  * : A url to import a valid archive from
  */
 public function create($args, $assoc_args)
 {
     $sites = SiteFactory::instance();
     // setup data
     $data = array();
     $data['label'] = Input::string($assoc_args, 'label', "Human readable label for the site");
     $slug = Utils\sanitize_name($data['label']);
     // this ugly logic is temporarily if to handle the deprecated --name flag and preserve backward compatibility. it can be removed in the next major release.
     if (array_key_exists('name', $assoc_args)) {
         $data['site_name'] = $assoc_args['name'];
     } elseif (array_key_exists('site', $assoc_args)) {
         $data['site_name'] = $assoc_args['site'];
     } else {
         $data['site_name'] = Input::string($assoc_args, 'site', "Machine name of the site; used as part of the default URL [ if left blank will be {$slug}]", $slug);
     }
     if ($orgid = Input::orgid($assoc_args, 'org', false)) {
         $data['organization_id'] = $orgid;
     }
     if (!isset($assoc_args['import'])) {
         $product = Input::product($assoc_args, 'product');
         $data['deploy_product'] = array('product_id' => $product['id']);
         Terminus::line(sprintf("Creating new %s installation ... ", $product['longname']));
     }
     $params = array('body' => json_encode($data), 'headers' => array('Content-type' => 'application/json'));
     // run the workflow
     $workflow = Workflow::createWorkflow('create_site', 'users', new User());
     $workflow->setMethod('POST');
     $workflow->setParams($data);
     $workflow->start();
     $workflow->refresh();
     $details = $workflow->status();
     $site_id = $details->final_task->site_id;
     if ($details->result !== 'failed' and $details->result !== 'aborted') {
         Terminus\Loggers\Regular::coloredOutput('%G' . vsprintf('New "site" %s now building with "UUID" %s', array($data['site_name'], $site_id)));
     }
     $workflow->wait();
     Terminus::success("Pow! You created a new site!");
     $this->cache->flush(null, 'session');
     if (isset($assoc_args['import'])) {
         Terminus::launch_self('site', array('import'), array('url' => $assoc_args['import'], 'site' => $data['site_name'], 'element' => 'all', 'nocache' => True));
     }
     return true;
 }
Пример #4
0
 /**
  * Print and save drush aliases
  *
  * ## OPTIONS
  *
  * [--print]
  * : print aliases to screen
  *
  * [--location=<location>]
  * : specify the location of the alias file, default it ~/.drush/pantheon.drushrc.php
  *
  */
 public function aliases($args, $assoc_args)
 {
     $user = new User();
     $print = Input::optional('print', $assoc_args, false);
     $json = \Terminus::get_config('json');
     $location = Input::optional('location', $assoc_args, getenv("HOME") . '/.drush/pantheon.aliases.drushrc.php');
     $message = "Pantheon aliases updated.";
     if (!file_exists($location)) {
         $message = "Pantheon aliases created.";
     }
     $content = $user->getAliases();
     $h = fopen($location, 'w+');
     fwrite($h, $content);
     fclose($h);
     chmod($location, 0777);
     Logger::coloredOutput("%2%K{$message}%n");
     if ($json) {
         include $location;
         print \Terminus\Utils\json_dump($aliases);
     } elseif ($print) {
         print $content;
     }
 }
Пример #5
0
 /**
  * Get or set team members
  *
  * ## OPTIONS
  *
  * <list|add-member|remove-member>
  * : i.e. add or remove
  *
  * [--site=<site>]
  * : Site to check
  *
  * [--member=<email>]
  * : Email of the member to add. Member will receive an invite
  *
  * @subcommand team
  */
 public function team($args, $assoc_args)
 {
     $action = array_shift($args) ?: 'list';
     $site = SiteFactory::instance(Input::site($assoc_args));
     $data = array();
     switch ($action) {
         case 'add-member':
             $team = $site->teamAddMember($assoc_args['member']);
             Logger::coloredOutput("%2<K>Team member added!</K>");
             break;
         case 'remove-member':
             $team = $site->teamRemoveMember($assoc_args['member']);
             Logger::coloredOutput("%2<K>Team member removed!</K>");
             break;
         case 'list':
         case 'default':
             $team = $site->team();
             foreach ($team as $uuid => $user) {
                 $data[] = array('First' => $user->profile->firstname, 'Last' => $user->profile->lastname, 'Email' => $user->email, 'UUID' => $uuid);
             }
             ksort($data);
             break;
     }
     if (!empty($data)) {
         $this->handleDisplay($data);
     }
 }
Пример #6
0
 /**
  * Get or set service level
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to check
  *
  * [--set=<value>]
  * : new service level to set
  *
  * @subcommand service-level
  */
 public function service_level($args, $assoc_args)
 {
     $site = SiteFactory::instance(Input::sitename($assoc_args));
     $info = $site->info('service_level');
     if (isset($assoc_args['set'])) {
         $set = $assoc_args['set'];
         $data = $site->updateServiceLevel($set);
         Logger::coloredOutput("%2<K>Service level has been updated to '{$set}'%n");
     }
     Logger::coloredOutput("%2<K>Service level is '{$info}'%n");
     return true;
 }
Пример #7
0
 /**
  * Print and save drush aliases
  *
  * ## OPTIONS
  *
  * [--print]
  * : print aliases to screen
  *
  * [--location=<location>]
  * : Specify the the full path, including the filename, to the alias file you wish to create.
  *   Without this option a default of '~/.drush/pantheon.drushrc.php' will be used.
  *
  */
 public function aliases($args, $assoc_args)
 {
     $user = new User(new stdClass(), array());
     $print = Input::optional('print', $assoc_args, false);
     $json = \Terminus::get_config('json');
     $location = Input::optional('location', $assoc_args, getenv("HOME") . '/.drush/pantheon.aliases.drushrc.php');
     // Cannot provide just a directory
     if (is_dir($location)) {
         \Terminus::error("Please provide a full path with filename, e.g. %s/pantheon.aliases.drushrc.php", $location);
         exit(1);
     }
     $file_exists = file_exists($location);
     // Create the directory if it doesn't yet exist
     $dirname = dirname($location);
     if (!is_dir($dirname)) {
         mkdir($dirname, 0700, true);
     }
     $content = $user->getAliases();
     $h = fopen($location, 'w+');
     fwrite($h, $content);
     fclose($h);
     chmod($location, 0700);
     $message = $file_exists ? 'Pantheon aliases updated' : 'Pantheon aliases created';
     Logger::coloredOutput("%2%K{$message}%n");
     if ($json) {
         include $location;
         print \Terminus\Utils\json_dump($aliases);
     } elseif ($print) {
         print $content;
     }
 }
Пример #8
0
 /**
  * Get or set service level
  *
  * ## OPTIONS
  *
  * [--site=<site>]
  * : Site to check
  *
  * [--set=<value>]
  * : new service level to set
  *
  * @subcommand service-level
  */
 public function service_level($args, $assoc_args)
 {
     $site = $this->sites->get(Input::sitename($assoc_args));
     $info = $site->get('service_level');
     if (isset($assoc_args['set'])) {
         $set = $assoc_args['set'];
         $data = $site->updateServiceLevel($set);
         Logger::coloredOutput("%2<K>Service level has been updated to '{$set}'%n");
     } else {
         Logger::coloredOutput("%2<K>Service level is '{$info}'%n");
     }
 }