protected function GdprSqlDump::getInstance in General Data Protection Regulation 8
Same name and namespace in other branches
- 8.2 modules/gdpr_dump/src/Service/GdprSqlDump.php \Drupal\gdpr_dump\Service\GdprSqlDump::getInstance()
- 3.0.x modules/gdpr_dump/src/Service/GdprSqlDump.php \Drupal\gdpr_dump\Service\GdprSqlDump::getInstance()
Get a SqlBase instance according to dbSpecs.
Parameters
array $dbSpec: If known, specify a $dbSpec that the class can operate with.
Return value
\Drush\Sql\SqlBase The Sql instance.
Throws
\Drush\Sql\SqlException
See also
\drush_sql_get_class()
2 calls to GdprSqlDump::getInstance()
- GdprSqlDump::buildTablesToSkip in modules/
gdpr_dump/ src/ Service/ GdprSqlDump.php - Builds tablesToSkip array.
- GdprSqlDump::dump in modules/
gdpr_dump/ src/ Service/ GdprSqlDump.php - Dump command.
File
- modules/
gdpr_dump/ src/ Service/ GdprSqlDump.php, line 145
Class
- GdprSqlDump
- Class GdprSqlDump.
Namespace
Drupal\gdpr_dump\ServiceCode
protected function getInstance(array $dbSpec = NULL) {
$database = drush_get_option('database', 'default');
$target = drush_get_option('target', 'default');
// Try a few times to quickly get $dbSpec.
if (!empty($dbSpec)) {
if (!empty($dbSpec['driver'])) {
// Try loading our implementation first.
$instance = drush_get_class('\\Drupal\\gdpr_dump\\Sql\\GdprSql', [
$dbSpec,
], [
\ucfirst($dbSpec['driver']),
]);
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);
}
}
}
throw new SqlException('Unable to find a matching SQL Class. Drush cannot find your database connection details.');
}