Ejemplo n.º 1
0
 /**
  * Run the configured migrations.
  */
 public function import()
 {
     $log = new DrushLogMigrateMessage();
     foreach ($this->migrationList as $migration_id) {
         /** @var MigrationInterface $migration */
         $migration = Migration::load($migration_id);
         drush_print(dt('Upgrading !migration', ['!migration' => $migration_id]));
         $executable = new MigrateExecutable($migration, $log);
         // drush_op() provides --simulate support.
         drush_op([$executable, 'import']);
     }
 }
Ejemplo n.º 2
0
 public function revoke_permissions($perms)
 {
     return drush_op('user_role_revoke_permissions', $this->rid, $perms);
 }
Ejemplo n.º 3
0
 /**
  * Execute a SQL query.
  *
  * Note: This is an API function. Try to avoid using drush_get_option() and instead
  * pass params in. If you don't want to query results to print during --debug then
  * provide a $result_file whose value can be drush_bit_bucket().
  *
  * @param string $query
  *   The SQL to be executed. Should be NULL if $input_file is provided.
  * @param string $input_file
  *   A path to a file containing the SQL to be executed.
  * @param string $result_file
  *   A path to save query results to. Can be drush_bit_bucket() if desired.
  *
  * @return
  *   TRUE on success, FALSE on failure
  */
 public function query($query, $input_file = NULL, $result_file = '')
 {
     $input_file_original = $input_file;
     if ($input_file && drush_file_is_tarball($input_file)) {
         if (drush_shell_exec('gunzip %s', $input_file)) {
             $input_file = trim($input_file, '.gz');
         } else {
             return drush_set_error(dt('Failed to gunzip input file.'));
         }
     }
     // Save $query to a tmp file if needed. We will redirect it in.
     if (!$input_file) {
         $query = $this->query_prefix($query);
         $query = $this->query_format($query);
         $input_file = drush_save_data_to_temp_file($query);
     }
     $parts = array($this->command(), $this->creds(), $this->silent(), drush_get_option('extra', $this->query_extra), $this->query_file, drush_escapeshellarg($input_file));
     $exec = implode(' ', $parts);
     if ($result_file) {
         $exec .= ' > ' . drush_escapeshellarg($result_file);
     }
     // In --verbose mode, drush_shell_exec() will show the call to mysql/psql/sqlite,
     // but the sql query itself is stored in a temp file and not displayed.
     // We show the query when --debug is used and this function created the temp file.
     if ((drush_get_context('DRUSH_DEBUG') || drush_get_context('DRUSH_SIMULATE')) && empty($input_file_original)) {
         drush_log('sql-query: ' . $query, LogLevel::NOTICE);
     }
     $success = drush_shell_exec($exec);
     if ($success && drush_get_option('file-delete')) {
         drush_op('drush_delete_dir', $input_file);
     }
     return $success;
 }
 /**
  * Rolls back the configured migrations.
  */
 public function rollback()
 {
     static::$messages = new DrushLogMigrateMessage();
     $query = \Drupal::entityQuery('migration');
     $names = $query->execute();
     // Order the migrations according to their dependencies.
     /** @var MigrationInterface[] $migrations */
     $migrations = \Drupal::entityManager()->getStorage('migration')->loadMultiple($names);
     // Assume we want all those tagged 'Drupal %'.
     foreach ($migrations as $migration_id => $migration) {
         $keep = FALSE;
         $tags = $migration->get('migration_tags');
         foreach ($tags as $tag) {
             if (strpos($tag, 'Drupal ') === 0) {
                 $keep = TRUE;
                 break;
             }
         }
         if (!$keep) {
             unset($migrations[$migration_id]);
         }
     }
     // Roll back in reverse order.
     $this->migrationList = array_reverse($migrations);
     foreach ($this->migrationList as $migration_id => $migration) {
         drush_print(dt('Rolling back @migration', ['@migration' => $migration_id]));
         $executable = new MigrateExecutable($migration, static::$messages);
         // drush_op() provides --simulate support.
         drush_op([$executable, 'rollback']);
         $migration->delete();
     }
 }
Ejemplo n.º 5
0
 function updatePerms()
 {
     $new_perms = implode(", ", $this->perms);
     drush_op('db_query', "UPDATE {permission} SET perm = '%s' WHERE rid= %d", $new_perms, $this->rid);
 }
Ejemplo n.º 6
0
 /**
  * Execute a single migration.
  *
  * @param \Drupal\migrate\Entity\Migration $migration
  *   The migration to run.
  *
  * @return \Drupal\migrate_tools\MigrateExecutable
  *   The migration executable.
  */
 protected function executeMigration($migration)
 {
     drush_log('Running ' . $migration->id(), 'ok');
     $executable = new MigrateExecutable($migration, $this->log);
     // drush_op() provides --simulate support.
     drush_op(array($executable, 'import'));
     return $executable;
 }
Ejemplo n.º 7
0
 public function moveFile($source, $target)
 {
     if (!drush_op('rename', $source, $target)) {
         throw new FileSystemCouldNotMoveFile($source, $target);
     }
     drush_log(dt('Moved the settings.php file to !target.', array('!target' => $target)), 'success');
     return TRUE;
 }