public function testOutputOption() { chdir($this->misc_root); @unlink('fix-definer-different-output.sql'); $cmd = "gr fix-definer --output fix-definer-different-output.sql fix-definer.sql"; \GR\Shell::command($cmd); $this->assertFileExists('fix-definer-different-output.sql'); }
public function load_databases() { echo "Reading config...\n"; $config = json_decode(file_get_contents(PROJECT_ROOT . "/test/config.json")); if (empty($config)) { $err = "\nYou are missing or have misconfigured your config.json file, "; $err .= "which specifies your testing databases. Please see config.example.json "; $err .= "for example usage\n\n"; die($err); } echo "Loading Drupal DB...\n"; $cnf = $config->databases->drupal; $cmd = "mysql -u {$cnf->username} -p{$cnf->password} {$cnf->database} < ./files/sql/drupal.sql"; $s = \GR\Shell::command($cmd); echo $s[0]; echo " ...done.\n\n"; }
protected function backup_database() { if (isset($this->backup_to)) { $backup_to = realpath($this->backup_to); if (is_dir($this->backup_to)) { $backup_location = $this->backup_to . "/" . $this->database_credentials['database'] . "_" . date("U") . ".sql"; } else { $backup_location = $this->backup_to; } } else { $backup_location = $this->get_tmp_backup_location(); } $this->print_line("* Backing up database {$this->database_credentials['database']} to {$backup_location}"); $cmd = "mysqldump -u {$this->database_credentials['username']} -p{$this->database_credentials['password']} -h {$this->database_credentials['host']} {$this->database_credentials['database']} > {$backup_location}"; $streams = \GR\Shell::command($cmd); $this->print_line($streams[0]); }
public function set_perms($user_name, $group_name, $path) { $opts = array('print_command' => true); if (file_exists($path)) { \GR\Shell::command("chown -R {$user_name}:{$group_name} {$path}", $opts); if (is_dir($path)) { \GR\Shell::command("find {$path} -type d -print0 | xargs -0 chmod 2775", $opts); if ($this->directory_contains_files($path)) { $command = "find {$path} -type f -print0 | xargs -0 chmod 0664"; \GR\Shell::command("find {$path} -type f -print0 | xargs -0 chmod 0664", $opts); } } else { \GR\Shell::command("chmod 0664 {$path}", $opts); } } }
echo "* Reading config...\n"; $config = json_decode(file_get_contents("./config.json")); if (empty($config)) { $err = "\nYou are missing or have misconfigured your config.json file, "; $err .= "\nwhich specifies your testing databases. Please see config.example.json "; $err .= "\nfor example usage\n\n"; $err .= "If this is not a development environment, you may disregard this message.\n\n"; die($err); } else { write_config_files($config); } if (!getenv("GR_SKIP_DB")) { echo "* Loading Drupal DB..."; $cnf = $config->databases->drupal; $cmd = "mysql -u {$cnf->username} -p{$cnf->password} {$cnf->database} < ./files/sql/drupal.sql"; $s = \GR\Shell::command($cmd); echo $s[0]; echo "done.\n\n"; } else { echo "* Skipping DB Setup...\n\n"; } function write_config_files($config) { // Wordpress $db = $config->databases->wordpress; $config_tpl = TEST_ROOT . '/files/wordpress/wp-config.template.php'; $config_file = TEST_ROOT . '/files/wordpress/wp-config.php'; $config_contents = file_get_contents($config_tpl); $config_contents = str_ireplace('{{hostname}}', $db->hostname, $config_contents); $config_contents = str_ireplace('{{database}}', $db->database, $config_contents); $config_contents = str_ireplace('{{username}}', $db->username, $config_contents);
public function restore_files($files_tarball) { $this->print_line(" Downloading tarball..."); $bucket = $this->opts['bucket']; $tmp_dir = sys_get_temp_dir(); $timestamp = date("U"); $files_dest = str_replace('/', '_', $files_tarball); $tmp_dest = "{$tmp_dir}/{$timestamp}_{$files_dest}"; $object = $this->s3->GetObject(array('Bucket' => $bucket, 'Key' => $files_tarball, 'SaveAs' => $tmp_dest)); $this->print_line(" Deleting contents of sites/default/files..."); \GR\Shell::command("rm -rf sites/default/files"); $tmp_extracted_dest = "{$tmp_dest}_extracted"; if (!is_dir($tmp_extracted_dest)) { $result = mkdir($tmp_extracted_dest); if ($result === FALSE) { throw new Exception("Error opening '{$tmp_extracted_dest}': " . print_r(error_get_last(), TRUE)); } } $this->print_line(" Unzipping to {$tmp_extracted_dest}"); $cmd = "tar -xvf {$tmp_dest} -C {$tmp_extracted_dest}"; \GR\Shell::command($cmd, array('throw_exception_on_nonzero' => true)); $files_path = $this->find_files_path($tmp_extracted_dest); \GR\Shell::command("mv --no-target-directory {$files_path} {$this->site_info->root_path}/sites/default/files"); $this->print_line('Files successfully restored from backup.'); $this->print_line("\nYou may need to run `gr set-perms`"); $this->print_line(''); }
protected function update_git_repo() { chdir($this->app_root); $this->print_line(''); $this->print_line('* Checking out master...'); $streams = \GR\Shell::command("git checkout master"); echo $streams[0]; $this->print_line(''); $this->print_line('* Performing git pull...'); $streams = \GR\Shell::command("git pull"); echo $streams[0]; }