Exemplo n.º 1
0
 /**
  * Wait on workflow to complete
  */
 public function wait()
 {
     \Terminus::set_config('nocache', true);
     $tries = 0;
     while ($this->status('result') !== 'succeeded' and $tries < 100) {
         if ('failed' == $this->status('result') or 'aborted' == $this->status('result')) {
             if (isset($this->status->final_task) and !empty($this->status->final_task->messages)) {
                 foreach ($this->status->final_task->messages as $data => $message) {
                     \Terminus::error(sprintf('[%s] %s', $message->level, $message->message));
                     exit;
                 }
             } else {
                 \Terminus::error(PHP_EOL . "Couldn't complete jobs: '{$this->type}'" . PHP_EOL);
             }
         }
         sleep(3);
         $this->refresh();
         print ".";
         $tries++;
     }
     print PHP_EOL;
     if ("succeeded" === $this->status('result')) {
         return $this;
     }
     return false;
     unset($workflow);
 }
Exemplo n.º 2
0
<?php

/**
 * Bootstrap file for unit tests
 */
define('CLI_ROOT', dirname(__DIR__) . '/..');
define('TEST_DIR', dirname(__DIR__));
define('TERMINUS_CMD', 'php ' . CLI_ROOT . '/php/boot-fs.php');
putenv('CLI_TEST_MODE=1');
require_once CLI_ROOT . '/vendor/autoload.php';
require_once CLI_ROOT . '/php/boot-fs.php';
Terminus::set_config('nocache', true);
Terminus::set_config('debug', false);
use Terminus\Session;
// Set some dummy credentials
Session::setData(json_decode('{
  "user_uuid": "0ffec038-4410-43d0-a404-46997f672d7a",
  "session": "0ffec038-4410-43d0-a404-46997f672d7a%3A68486878-dd87-11e4-b243-bc764e1113b5%3AbQR2fyNMh5PQXN6F2Ewge",
  "session_expire_time": 1739299351,
  "email": "*****@*****.**"
}'));
\VCR\VCR::configure()->enableRequestMatchers(array('method', 'url', 'body'));
# Prevent API requests from being made in CI Environment
$ci_environment = getenv('CI');
if ($ci_environment) {
    \VCR\VCR::configure()->setMode('none');
}
Exemplo n.º 3
0
 /**
  * Waits and returns response from workflow.
  * @package Terminus
  * @version 2.0
  * @param $object_name string -- i.e. sites / users / organization
  * @param $object_id string -- coresponding id
  * @param $workflow_id string -- workflow to wait on
  *
  * @deprecated Use new WorkFlow() object instead
  * Example: $this->waitOnWorkflow( "sites", "68b99b50-8942-4c66-b7e3-22b67445f55d", "e4f7e832-5644-11e4-81d4-bc764e111d20");
  */
 protected function waitOnWorkflow($object_name, $object_id, $workflow_id)
 {
     print "Working .";
     Terminus::set_config('nocache', true);
     $workflow = self::request($object_name, $object_id, "workflows/{$workflow_id}", 'GET');
     $result = $workflow['data']->result;
     $desc = $workflow['data']->active_description;
     $type = $workflow['data']->type;
     $tries = 0;
     while (!isset($result) and $tries < 100) {
         if ('failed' == $result or 'aborted' == $result) {
             if (isset($workflow['data']->final_task) and !empty($workflow['data']->final_task->messages)) {
                 foreach ($workflow['data']->final_task->messages as $data => $message) {
                     sprintf('[%s] %s', $message->level, $message->message);
                 }
             } else {
                 Terminus::error(PHP_EOL . "Couldn't complete jobs: '{$type}'" . PHP_EOL);
             }
         }
         $workflow = self::request($object_name, $object_id, "workflows/{$workflow_id}", 'GET');
         $result = $workflow['data']->result;
         if (Terminus::get_config('debug')) {
             print_r($workflow);
         }
         sleep(3);
         print ".";
         $tries++;
     }
     print PHP_EOL;
     if ("succeeded" === $workflow['data']->result or "aborted" === $workflow['data']->result) {
         return $workflow['data'];
     }
     return false;
     unset($workflow);
 }
Exemplo n.º 4
0
 /**
  * Execute the login based on an existing session token
  *
  * @param $session_token string (required)
  * @return array
  */
 private function doLoginFromSessionToken($session_token)
 {
     $options = array('headers' => array('Content-type' => 'application/json'), 'cookies' => array('X-Pantheon-Session' => $session_token));
     # Temporarily disable the cache for this GET call
     Terminus::set_config('nocache', TRUE);
     $response = Terminus_Command::request('user', '', '', 'GET', $options);
     Terminus::set_config('nocache', FALSE);
     if (!$response or '200' != @$response['info']['http_code']) {
         \Terminus::error("[auth_error]: session token not valid");
     }
     // Prepare credentials for storage.
     $data = array('user_uuid' => $response['data']->id, 'session' => $session_token, 'session_expire_time' => 0, 'email' => $response['data']->email);
     // creates a session instance
     Session::instance()->setData($data);
     return $data;
 }