diff --git a/database_sanitize.install b/database_sanitize.install index 7c9a548..c89d9e5 100644 --- a/database_sanitize.install +++ b/database_sanitize.install @@ -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) { diff --git a/database_sanitize.services.yml b/database_sanitize.services.yml index cd8987c..a201ff8 100644 --- a/database_sanitize.services.yml +++ b/database_sanitize.services.yml @@ -2,4 +2,4 @@ services: database_sanitize: class: Drupal\database_sanitize\DatabaseSanitize public: true - arguments: ['@logger.factory'] + arguments: ['@logger.factory', '@database'] diff --git a/src/DatabaseSanitize.php b/src/DatabaseSanitize.php index d8449eb..97d0744 100644 --- a/src/DatabaseSanitize.php +++ b/src/DatabaseSanitize.php @@ -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; @@ -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(); @@ -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') ); } @@ -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;