Ejemplo n.º 1
0
 /** 
  * Runs the command with the opts and args defined in the constructor
  * 
  * This is the meat of your command. Keep the call to 
  * parent::run(), but replace everything else with 
  * your own content
  *
  * See the function option_kit() below for how to define
  * and use the command-line parameters for your command
  */
 public function run()
 {
     // keep this line
     if (!parent::run()) {
         return false;
     }
     $this->link_git_hooks();
     $this->update_git_repo();
 }
 public function run()
 {
     if (!parent::run()) {
         return FALSE;
     }
     $this->site_info = new \GR\SiteInfo($this->root);
     $this->site_info->get_database_connection();
     $this->bootstrap_s3();
     $contents = $this->get_bucket_contents();
     $db_array = array();
     $files_array = array();
     if (empty($contents)) {
         $this->exit_with_message("Nothing found in bucket. Check your credentials and bucket name.");
     }
     foreach ($contents as $file) {
         if (substr($file['Key'], -9) == '.mysql.gz') {
             $db_array[$file['LastModified']] = $file['Key'];
         }
         if (substr($file['Key'], -7) == '.tar.gz') {
             $files_array[$file['LastModified']] = $file['Key'];
         }
     }
     ksort($db_array);
     ksort($files_array);
     $db_latest = array_pop($db_array);
     $files_latest = array_pop($files_array);
     $should_restore_db_latest = false;
     if ($db_latest) {
         $db_prompt = "Restore DB from file {$db_latest}?";
         $should_restore_db_latest = \GR\Hash::fetch($this->opts, 'no-prompts') ? true : $this->confirm($db_prompt);
     } else {
         $this->print_line("No database backup found. Looking for files that match *.mysql.gz");
     }
     $should_restore_files_latest = false;
     if ($files_latest && !\GR\Hash::fetch($this->opts, 'exclude-files')) {
         $files_prompt = "Restore files from tarball {$files_latest}? This will remove everything that's currently in sites/default/files";
         $should_restore_files_latest = \GR\Hash::fetch($this->opts, 'no-prompts') ? true : $this->confirm($files_prompt);
     }
     if ($should_restore_db_latest) {
         $this->restore_database($db_latest);
     }
     if ($should_restore_files_latest) {
         $this->restore_files($files_latest);
     }
 }
Ejemplo n.º 3
0
 /** 
  * Runs the command with the opts and args defined in the constructor
  * 
  * This is the meat of your command. Keep the call to 
  * parent::run(), but replace everything else with 
  * your own content
  *
  * See the function option_kit() below for how to define
  * and use the command-line parameters for your command
  */
 public function run()
 {
     // keep this line
     if (!parent::run()) {
         return false;
     }
     $paramString = "paras={$this->num_pars}&type=hipster-centric&html=false";
     $url = "http://hipsterjesus.com/api/?{$paramString}";
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $resp = curl_exec($ch);
     curl_close($ch);
     $rslt = json_decode($resp);
     $text = str_replace("\n", "\n\n", $rslt->text);
     echo $text;
     echo "\n";
 }
 /**
  * Runs the command with the opts and args defined in the constructor
  *
  * This is the meat of your command. Keep the call to
  * parent::run(), but replace everything else with
  * your own content
  *
  * See the function option_kit() below for how to define
  * and use the command-line parameters for your command
  */
 public function run()
 {
     // keep this line
     if (!parent::run()) {
         return FALSE;
     }
     $this->validate_arguments();
     $this->verify_database_with_user();
     if (!isset($this->no_backup) || !$this->no_backup) {
         $this->backup_database();
     } else {
         $this->print_line("* Skipping database backup...");
     }
     $this->print_line("* Connecting to database {$this->database_credentials['database']} as user {$this->database_credentials['username']}@{$this->database_credentials['host']}");
     $this->site_info->get_database_connection($this->database_credentials);
     $this->anonymize_database();
     $this->print_line("\nThe database was successfully anonymized.");
 }
Ejemplo n.º 5
0
 public function run()
 {
     if (!parent::run()) {
         return false;
     }
     if (empty($this->site_info->root_path) || $this->site_info->environment !== 'drupal') {
         throw new \Exception("Unable to determine the Drupal root directory. Make sure you are running this command inside a Drupal website's root directory.");
     }
     $env = new \GR\ServerEnv($this->site_info->root_path);
     $env->requireApacheConfFile();
     $env->setEnvVars();
     if (getenv("APP_ENV") === FALSE) {
         throw new \Exception("No APP_ENV environment variable is set for this site.");
     }
     if (getenv("APP_NAME") === FALSE) {
         throw new \Exception("No APP_NAME environment variable is set for this site.");
     }
     $args = implode(' ', $this->args);
     $command = "drush {$args}";
     passthru($command);
 }
Ejemplo n.º 6
0
 /**
  * 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);
 }
Ejemplo n.º 7
0
 /** 
  * Runs the command with the opts and args defined in the constructor
  * 
  * This is the meat of your command. Keep the call to 
  * parent::run(), but replace everything else with 
  * your own content
  *
  * See the function option_kit() below for how to define
  * and use the command-line parameters for your command
  */
 public function run()
 {
     // keep this line
     if (!parent::run()) {
         return false;
     }
     // remove everything from here to the end of this    ---------------------++
     // function and replace with your own content                             //
     echo "Passed options: ";
     //
     if (empty($this->opts)) {
         //
         echo "none\n\n";
     } else {
         //
         print_r($this->opts);
         //
         echo "\n";
         //
     }
     //
     //
     echo "Passed arguments: ";
     //
     if (empty($this->args)) {
         //
         echo "none\n\n";
     } else {
         //
         print_r($this->args);
         //
         echo "\n";
         //
     }
     //
     //
     echo "\nType `gr example -h` for usage and available options.\n\n";
     //
     //------------------------------------------------------------------------++
 }
Ejemplo n.º 8
0
 /** 
  * Runs the command with the opts and args defined in the constructor
  * 
  * This is the meat of your command. Keep the call to 
  * parent::run(), but replace everything else with 
  * your own content
  *
  * See the function option_kit() below for how to define
  * and use the command-line parameters for your command
  */
 public function run()
 {
     if (!parent::run()) {
         return false;
     }
     if (!$this->user || !$this->group) {
         $this->print_usage();
         exit;
     }
     $opts = array('print_command' => true);
     $this->set_perms($this->user, $this->group, $this->directory);
     foreach ($this->site_info->web_writeable_paths as $path) {
         $this->set_perms($this->web_user, $this->web_user, $path);
     }
     $this->apply_exception_rules();
 }
Ejemplo n.º 9
0
 /** 
  * Runs the command with the opts and args defined in the constructor
  * 
  * This is the meat of your command. Keep the call to 
  * parent::run(), but replace everything else with 
  * your own content
  *
  * See the function option_kit() below for how to define
  * and use the command-line parameters for your command
  */
 public function run()
 {
     // keep this line
     if (!parent::run()) {
         return false;
     }
     $dir_name = NULL;
     $base_file_name = NULL;
     $extension = NULL;
     $use_gzip = FALSE;
     foreach (static::$expected_extensions as $expected_extension) {
         $regex = str_replace('.', '\\.', $expected_extension);
         if (preg_match("/{$regex}\$/", $this->input_file_name)) {
             $base_name = basename($this->input_file_name, $expected_extension);
             $dir_name = dirname($this->input_file_name);
             $extension = $expected_extension;
             break;
         }
     }
     if ($base_name === NULL) {
         $base_name = basename($this->input_file_name);
         $dir_name = dirname($this->input_file_name);
     }
     if (preg_match("/.*\\.gz\$/", $extension)) {
         $use_gzip = TRUE;
     }
     if ($this->output_file_name == NULL) {
         $this->output_file_name = "{$base_name}-definer-fixed{$extension}";
     }
     if ($use_gzip) {
         $this->input_file = gzopen($this->input_file_name, 'r');
         if ($this->input_file === FALSE) {
             $this->throw_last_error("Error opening input file {$this->input_file_name}");
         }
         $this->output_file = gzopen($this->output_file_name, 'w');
         if ($this->output_file === FALSE) {
             $this->throw_last_error("Error openeing output file {$this->output_file_name}");
         }
     } else {
         $this->input_file = fopen($this->input_file_name, 'r');
         if ($this->input_file === FALSE) {
             $this->throw_last_error("Error opening input file {$this->input_file_name}");
         }
         $this->output_file = fopen($this->output_file_name, 'w');
         if ($this->output_file === FALSE) {
             $this->throw_last_error("Error opening output file {$this->output_file_name}");
         }
     }
     $this->file_get_contents_by_line(65536, $this, function ($line, $iteration, $fix_definer) {
         $regex = '/\\/\\*[^*]*DEFINER=[^*]*\\*\\//';
         $result = fwrite($fix_definer->output_file, preg_replace($regex, '', $line));
         if ($result === FALSE) {
             $this->throw_last_error("Error writing to output file {$fix_definer->output_file_name}");
         }
     });
     if ($use_gzip) {
         $result = gzclose($this->input_file);
         if ($result === FALSE) {
             $this->throw_last_error("Error closing input file {$this->input_file_name}");
         }
         $result = gzclose($this->output_file);
         if ($result === FALSE) {
             $this->throw_last_error("Error closing input file {$this->input_file_name}");
         }
     } else {
         $result = fclose($this->input_file);
         if ($result === FALSE) {
             $this->throw_last_error("Error closing input file {$this->input_file_name}");
         }
         $result = fclose($this->output_file);
         if ($result === FALSE) {
             $this->throw_last_error("Error closing input file {$this->input_file_name}");
         }
     }
 }