You are here

protected function GdprDumpGdprSqlDump::getInstance in General Data Protection Regulation 7

Get a SqlBase instance according to dbSpecs.

2 calls to GdprDumpGdprSqlDump::getInstance()
GdprDumpGdprSqlDump::buildSkipTables in modules/gdpr_dump/inc/GdprDumpGdprSqlDump.inc
Builds skipTables array.
GdprDumpGdprSqlDump::dump in modules/gdpr_dump/inc/GdprDumpGdprSqlDump.inc
Dump command.

File

modules/gdpr_dump/inc/GdprDumpGdprSqlDump.inc, line 72

Class

GdprDumpGdprSqlDump
Class GdprDumpGdprSqlDump.

Code

protected function getInstance(array $dbSpec = NULL) {
  $database = drush_get_option('database', 'default');
  $target = drush_get_option('target', 'default');
  if (!empty($dbSpec)) {
    if (!empty($dbSpec['driver'])) {

      // Try loading our implementation first.
      $className = 'GdprDumpGdprSql' . ucfirst($dbSpec['driver']);
      module_load_include('inc', 'gdpr_dump', 'inc/' . $className);
      $instance = drush_get_class($className, [
        $dbSpec,
      ]);
      if (!empty($instance)) {
        return $instance;
      }
    }
  }
  elseif ($url = drush_get_option('db-url')) {
    $url = \is_array($url) ? $url[$database] : $url;
    $dbSpec = drush_convert_db_from_db_url($url);
    $dbSpec['db_prefix'] = drush_get_option('db-prefix');
    return $this
      ->getInstance($dbSpec);
  }
  elseif (($databases = drush_get_option('databases')) && \array_key_exists($database, $databases) && \array_key_exists($target, $databases[$database])) {
    $dbSpec = $databases[$database][$target];
    return $this
      ->getInstance($dbSpec);
  }
  else {

    // No parameter or options provided. Determine $dbSpec ourselves.

    /** @var \Drush\Sql\SqlVersion $sqlVersion */
    if ($sqlVersion = drush_sql_get_version()) {
      if ($dbSpec = $sqlVersion
        ->get_db_spec()) {
        return $this
          ->getInstance($dbSpec);
      }
    }
  }
}