Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion database_sanitize.install
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function database_sanitize_requirements($phase) {
return $requirements;
}

$db_tables = \Drupal::database()->query('show tables')->fetchCol();
$db_tables = \Drupal::service('database')->schema()->findTables('%');

$yml_tables = [];
foreach ($parsed_file['sanitize'] as $machine_name => $tables) {
Expand Down
2 changes: 1 addition & 1 deletion database_sanitize.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ services:
database_sanitize:
class: Drupal\database_sanitize\DatabaseSanitize
public: true
arguments: ['@logger.factory']
arguments: ['@logger.factory', '@database']
18 changes: 15 additions & 3 deletions src/DatabaseSanitize.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drupal\database_sanitize;

use Drupal\Component\Serialization\Json;
use Drupal\Core\Database\Connection;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use EdisonLabs\MergeYaml\MergeYaml;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -33,16 +34,26 @@ class DatabaseSanitize {
*/
protected $logger;

/**
* Database Service Object.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;

/**
* DatabaseSanitize constructor.
*
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger
* The LoggerChannelFactoryInterface object.
* @param \Drupal\Core\Database\Connection $database
* The database connection to be used.
*
* @throws \Exception
*/
public function __construct(LoggerChannelFactoryInterface $logger) {
public function __construct(LoggerChannelFactoryInterface $logger, Connection $database) {
$this->logger = $logger->get('database_sanitize');
$this->database = $database;

$locations = $this->getSourceLocations();
$output_dir = $this->getOutputDir();
Expand All @@ -55,7 +66,8 @@ public function __construct(LoggerChannelFactoryInterface $logger) {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('logger.factory')
$container->get('logger.factory'),
$container->get('database')
);
}

Expand Down Expand Up @@ -188,7 +200,7 @@ public function getUnspecifiedTables($yml_file_path = NULL) {
}

// Get a list of all tables on the database.
$db_tables = \Drupal::database()->query('show tables')->fetchCol();
$db_tables = $this->database->schema()->findTables('%');

if (empty($file_content)) {
return $db_tables;
Expand Down