public function run()
 {
     if (\GR\Hash::fetch($this->opts, 'help')) {
         $this->print_help();
         return false;
     }
     return true;
 }
Esempio n. 2
0
 function __construct($settings = array())
 {
     if (!self::$error_handler_set) {
         error_reporting(E_ALL);
         self::$error_handler_set = TRUE;
         self::$original_error_handler = set_error_handler(array('MySQLConcentrator\\Server', 'error_handler'));
     }
     $this->log = new Log($this->log_file_name);
     $this->mysql_address = \GR\Hash::fetch($settings, 'host', $this->mysql_address);
     $this->mysql_port = \GR\Hash::fetch($settings, 'port', $this->mysql_port);
     $this->listen_port = \GR\Hash::fetch($settings, 'listen_port', $this->listen_port);
 }
 public function __construct($opts, $args)
 {
     parent::__construct($opts, $args);
     $input_file_name = \GR\Hash::fetch($args, 0);
     if (!$input_file_name && !$opts['help']) {
         throw new \Exception("This command takes one argument - the path to the file to be stripped.");
     }
     $this->input_file_name = $input_file_name;
     $this->output_file_name = NULL;
     if (isset($this->opts['output'])) {
         $this->output_file_name = $this->opts['output'];
     }
 }
 public function __construct($opts = false, $args = false)
 {
     parent::__construct($opts, $args);
     $this->directory = realpath(\GR\Hash::fetch($opts, 'directory', '.'));
     $this->site_info = new \GR\SiteInfo($this->directory);
     $process_user = posix_getpwuid(posix_geteuid());
     $this->user = \GR\Hash::fetch($opts, 'user', $process_user['name']);
     $this->group = \GR\Hash::fetch($opts, 'group', 'giantrabbit');
     $this->web_user = \GR\Hash::fetch($opts, 'web-user', 'www-data');
     // @todo figure out why the optionkit parser won't take multiple values here
     $addl_files = \GR\Hash::fetch($opts, 'additional-site-files');
     if ($addl_files) {
         trigger_error("set-perms cannot currently accept more than one value for --additional-site-files\n", E_USER_NOTICE);
         $this->site_info->web_writeable_paths = array_merge($this->site_info->web_writeable_paths, $addl_files);
     }
 }
 /**
  * There's some kind of incompatibility with running the PHPUnit through the GR\Shell object
  * and bootstrapping the testing database, so this command is currently not available until
  * that gets sorted out. Tests can be run from the test directory by typing 'phpunit .'
  */
 public function run()
 {
     $msg = "The unit-test command is currently unavailable. Please run `phpunit .` from the test directory instead\n";
     die($msg);
     // keep this line
     if (!parent::run()) {
         return false;
     }
     $this->load_databases();
     $option_string = $this->get_phpunit_options();
     chdir(PROJECT_ROOT . '/test');
     $path = \GR\Hash::fetch($this->args, 0, '.');
     $cmd = "phpunit {$option_string} {$path}";
     $streams = \GR\Shell::command($cmd, array('throw_exception_on_nonzero' => false));
     $rslt = $streams[0];
     echo $rslt;
     if (strpos($rslt, 'FAILURES!') !== false) {
         exit(1);
     }
     exit(0);
 }
Esempio n. 6
0
 /**
  * Class constructor for your command
  *
  * If you need to override the constructor, be sure 
  * to keep the call to the parent constructor in place.
  * The $opts and $args params are automatically given to the constructor
  * by the main GR object and they are stored to $this->opts. 
  * and $this->args respectively. These are associative array of the 
  * arguments passed via the command line.
  * 
  * Eg. `gr example -f -b bar-value arg1 arg2` will create $opts as 
  * Array [
  *   foo => 1
  *   bar => bar-value
  * ]
  * and $args as
  * Array [
  *   [0] => arg1,
  *   [1] => arg2
  * ]
  * See the option_kit method below for more info on how
  * to define your options
  */
 public function __construct($opts = false, $args = false)
 {
     parent::__construct($opts, $args);
     $pars = \GR\Hash::fetch($args, 0);
     $this->num_pars = (int) $pars ?: 4;
 }
 public function set_database_credentials()
 {
     $database_credentials = $this->site_info->database_credentials;
     $overridden_database_credentials = $database_credentials;
     $overridden_database_credentials['database'] = \GR\Hash::fetch($this->args, 0, $database_credentials['database']);
     foreach (array('username', 'password', 'host') as $option) {
         $overridden_database_credentials[$option] = \GR\Hash::fetch($this->opts, $option, $database_credentials[$option]);
     }
     $this->database_credentials = $overridden_database_credentials;
 }
Esempio n. 8
0
 static function command($command, $options = array())
 {
     $options['throw_exception_on_nonzero'] = Hash::fetch($options, 'throw_exception_on_nonzero', TRUE);
     $options['print_command'] = Hash::fetch($options, 'print_command', FALSE);
     $options['input'] = Hash::fetch($options, 'input', NULL);
     if ($options['print_command']) {
         print "{$command}\n";
     }
     $descriptors_spec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
     $process = proc_open($command, $descriptors_spec, $pipes);
     if ($process === FALSE) {
         throw new Exception("Unable to proc_open({$command}).");
     }
     stream_set_blocking($pipes[1], FALSE);
     if ($options['input']) {
         fwrite($pipes[0], $options['input']);
         fclose($pipes[0]);
     }
     $stdout_data = '';
     $stderr_data = '';
     $stdout_done = FALSE;
     $stderr_done = FALSE;
     while (!$stdout_done && !$stderr_done) {
         $read_streams = array($pipes[1], $pipes[2]);
         $write_streams = null;
         $exceptions = null;
         $result = stream_select($read_streams, $write_streams, $exceptions, 5);
         if ($result === FALSE) {
             throw new Exception("Error running stream_select on pipe.");
         }
         if ($result > 0) {
             foreach ($read_streams as $read_stream) {
                 if ($read_stream == $pipes[1]) {
                     $result = fgets($read_stream);
                     if ($result === FALSE) {
                         if (!feof($read_stream)) {
                             throw new Exception("Error reading from proc_open({$command}) stderr stream.");
                         } else {
                             $stdout_done = TRUE;
                         }
                     } else {
                         $stdout_data .= $result;
                     }
                 } elseif ($read_stream == $pipes[2]) {
                     $result = fgets($read_stream);
                     if ($result === FALSE) {
                         if (!feof($read_stream)) {
                             throw new Exception("Error reading from proc_open({$command}) stderr stream.");
                         } else {
                             $stderr_done = TRUE;
                         }
                     } else {
                         $stderr_data .= $result;
                     }
                 }
             }
         } else {
             break;
         }
     }
     fclose($pipes[1]);
     fclose($pipes[2]);
     $return_value = proc_close($process);
     if ($return_value != 0 && $options['throw_exception_on_nonzero']) {
         throw new Exception("Error running '{$command}'. Non-zero return value ({$return_value})\nstdout:\n{$stdout_data}\nstderr\n{$stderr_data}");
     }
     return array($stdout_data, $stderr_data);
 }
 public function restore_database($db_dump)
 {
     $this->print_line("  Downloading DB Dump...");
     $bucket = $this->opts['bucket'];
     $tmp_dir = sys_get_temp_dir();
     $timestamp = date("U");
     $db_dest = str_replace('/', '_', $db_dump);
     $dest = "{$tmp_dir}/{$timestamp}_{$db_dest}";
     $object = $this->s3->getObject(array('Bucket' => $bucket, 'Key' => $db_dump, 'SaveAs' => $dest));
     $should_fix_definer = !\GR\Hash::fetch($this->opts, 'no-fix-definer');
     $import_me = $dest;
     if ($should_fix_definer) {
         $this->print_line("  Stripping DEFINER clauses from DB dump...");
         $import_me = preg_replace("/\\.mysql.gz\$/", ".stripped.mysql.gz", $dest);
         \GR\Shell::command("gr fix-definer --output '{$import_me}' '{$dest}'");
         if (!is_file($import_me)) {
             $this->exit_with_message("Error stripping definer");
         }
     }
     $this->print_line("  Loading DB Dump...");
     $creds = $this->site_info->database_credentials;
     $sql_import = "gunzip -c {$import_me} | mysql -u {$creds['username']} -p{$creds['password']} -h{$creds['host']} {$creds['database']}";
     \GR\Shell::command($sql_import);
     if (!isset($this->opts['keep-schedules']) || !$this->opts['keep-schedules']) {
         $this->print_line("  Disabling Backup and Migrate Schedules...");
         $this->disable_backup_migrate_schedules();
     }
     $this->print_line('Database successfully restored from backup.');
     $this->print_line('');
 }