From 0c3431b079de38635212d90e302f7a38d07cb33b Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Tue, 6 Aug 2024 11:29:21 +0300 Subject: [PATCH 1/8] Bump up requirements and support Drupal 11 and Drush 13 --- composer.json | 8 ++++---- gdpr_dumper.info.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 85577e1..da7317e 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,10 @@ } ], "require": { - "php": "^7.4 || ^8.0", - "druidfi/gdpr-mysqldump": "^1.2.2", - "drush/drush": "^11.4", - "drupal/core-recommended": "^9 || ^10" + "php": "^8.1", + "druidfi/gdpr-mysqldump": "^1.2.6", + "drush/drush": "^12 || ^13", + "drupal/core-recommended": "^10 || ^11" }, "config": { "allow-plugins": { diff --git a/gdpr_dumper.info.yml b/gdpr_dumper.info.yml index 01d3167..38792dc 100644 --- a/gdpr_dumper.info.yml +++ b/gdpr_dumper.info.yml @@ -1,4 +1,4 @@ name: GDPR dumper description: 'A drop-in replacement for mysqldump that optionally sanitizes DB fields for better GDPR conformity.' type: module -core_version_requirement: ^9 || ^10 +core_version_requirement: ^10 || ^11 From fe176ae522581af6d1879213bf982b2b822cbce9 Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Thu, 8 Aug 2024 21:50:12 +0300 Subject: [PATCH 2/8] Update SqlCommands class to support Drush 13 --- src/Commands/SqlCommands.php | 50 +++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/src/Commands/SqlCommands.php b/src/Commands/SqlCommands.php index eceb4a6..475ab7d 100644 --- a/src/Commands/SqlCommands.php +++ b/src/Commands/SqlCommands.php @@ -2,43 +2,47 @@ namespace Drupal\gdpr_dumper\Commands; +use Consolidation\AnnotatedCommand\Input\StdinAwareInterface; +use Consolidation\AnnotatedCommand\Input\StdinAwareTrait; use Consolidation\OutputFormatters\StructuredData\PropertyList; use Drupal\gdpr_dumper\Sql\GdprSqlBase; -use Drush\Commands\sql\SqlCommands as SqlCommandsBase; +use Drush\Attributes as CLI; +use Drush\Boot\DrupalBootLevels; +use Drush\Commands\DrushCommands; +use Drush\Exec\ExecTrait; /** * Class SQlCommands * @package Drupal\gdpr_dumper\Commands */ -class SqlCommands extends SqlCommandsBase +class SqlCommands extends DrushCommands implements StdinAwareInterface { + use ExecTrait; + use StdinAwareTrait; + /** - * Exports a GDPR compliant Drupal DB as SQL using mysqldump or equivalent. + * Exports a GDPR-compliant Drupal DB as SQL using mysqldump or equivalent. * - * @command sql:dump-gdpr - * @aliases sql-dump-gdpr - * @optionset_sql - * @optionset_table_selection - * @option result-file Save to a file. The file should be relative to Drupal root. If --result-file is provided with the value 'auto', a date-based filename will be created under ~/drush-backups directory. - * @option create-db Omit DROP TABLE statements. Used by Postgres and Oracle only. - * @option data-only Dump data without statements to create any of the schema. - * @option ordered-dump Order by primary key and add line breaks for efficient diffs. Slows down the dump. Mysql only. - * @option gzip Compress the dump using the gzip program which must be in your $PATH. - * @option extra Add custom arguments/options when connecting to database (used internally to list tables). - * @option extra-dump Add custom arguments/options to the dumping of the database (e.g. mysqldump command). - * @usage drush sql:dump-gdpr --result-file=../18.sql - * Save SQL dump to the directory above Drupal root. - * @usage drush sql:dump-gdpr --skip-tables-key=common - * Skip standard tables. @throws \Exception - * @see example.drush.yml - * @usage drush sql:dump-gdpr --extra-dump=--no-data - * Pass extra option to mysqldump command. * @hidden-options create-db - * @bootstrap max configuration * * @notes * createdb is used by sql-sync, since including the DROP TABLE statements interfere with the import when the database is created. */ + #[CLI\Command(name: 'sql:dump-gdpr', aliases: ['sql-dump-gdpr'])] + #[CLI\Bootstrap(level: DrupalBootLevels::MAX, max_level: DrupalBootLevels::CONFIGURATION)] + #[CLI\OptionsetSql] + #[CLI\OptionsetTableSelection] + #[CLI\Option(name: 'result-file', description: "Save to a file. The file should be relative to Drupal root. If --result-file is provided with the value 'auto', a date-based filename will be created under ~/drush-backups directory.")] + #[CLI\Option(name: 'create-db', description: 'Omit DROP TABLE statements. Used by Postgres and Oracle only.')] + #[CLI\Option(name: 'data-only', description: 'Dump data without statements to create any of the schema.')] + #[CLI\Option(name: 'ordered-dump', description: 'Order by primary key and add line breaks for efficient diffs. Slows down the dump. Mysql only.')] + #[CLI\Option(name: 'gzip', description: 'Compress the dump using the gzip program which must be in your $PATH.')] + #[CLI\Option(name: 'extra', description: 'Add custom arguments/options when connecting to database (used internally to list tables).')] + #[CLI\Option(name: 'extra-dump', description: 'Add custom arguments/options to the dumping of the database (e.g. mysqldump command).')] + #[CLI\Usage(name: 'drush sql:dump-gdpr --result-file=../18.sql', description: 'Save SQL dump to the directory above Drupal root.')] + #[CLI\Usage(name: 'drush sql:dump-gdpr --skip-tables-key=common', description: 'Skip standard tables. See [Drush configuration](../../using-drush-configuration)')] + #[CLI\Usage(name: 'drush sql:dump-gdpr --extra-dump=--no-data', description: 'Pass extra option to mysqldump command.')] + #[CLI\FieldLabels(labels: ['path' => 'Path'])] public function dump($options = ['result-file' => self::REQ, 'create-db' => false, 'data-only' => false, 'ordered-dump' => false, 'gzip' => false, 'extra' => self::REQ, 'extra-dump' => self::REQ, 'format' => 'null']): PropertyList { // Create new GDPR-compliant dump of DB. @@ -55,5 +59,5 @@ public function dump($options = ['result-file' => self::REQ, 'create-db' => fals } return new PropertyList(['path' => $return]); - } + } } From 008b8bac76c19f8b6814ca0844987e2d2a810a14 Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Thu, 8 Aug 2024 21:56:29 +0300 Subject: [PATCH 3/8] Cleanup --- src/Commands/SqlCommands.php | 2 +- src/Commands/SqlSyncCommands.php | 58 -------------------------------- src/Sql/GdprSqlOracle.php | 15 --------- src/Sql/GdprSqlSqlite.php | 15 --------- src/Sql/GdprSqlSqlsrv.php | 15 --------- 5 files changed, 1 insertion(+), 104 deletions(-) delete mode 100644 src/Commands/SqlSyncCommands.php delete mode 100644 src/Sql/GdprSqlOracle.php delete mode 100644 src/Sql/GdprSqlSqlite.php delete mode 100644 src/Sql/GdprSqlSqlsrv.php diff --git a/src/Commands/SqlCommands.php b/src/Commands/SqlCommands.php index 475ab7d..8b2a97a 100644 --- a/src/Commands/SqlCommands.php +++ b/src/Commands/SqlCommands.php @@ -15,7 +15,7 @@ * Class SQlCommands * @package Drupal\gdpr_dumper\Commands */ -class SqlCommands extends DrushCommands implements StdinAwareInterface +final class SqlCommands extends DrushCommands implements StdinAwareInterface { use ExecTrait; use StdinAwareTrait; diff --git a/src/Commands/SqlSyncCommands.php b/src/Commands/SqlSyncCommands.php deleted file mode 100644 index eac7c42..0000000 --- a/src/Commands/SqlSyncCommands.php +++ /dev/null @@ -1,58 +0,0 @@ - true, - 'result-file' => $options['source-dump'] ?: 'auto', - ]; - if (!$options['no-dump']) { - $this->logger()->notice(dt('Starting to dump database on source.')); - $process = $this->processManager()->drush($sourceRecord, 'sql-dump-gdpr', [], $dump_options + ['format' => 'json']); - $process->mustRun(); - - if ($this->getConfig()->simulate()) { - $source_dump_path = '/simulated/path/to/dump.tgz'; - } else { - // First try a Drush 9.6+ return format. - $json = $process->getOutputAsJson(); - if (!empty($json['path'])) { - $source_dump_path = $json['path']; - } else { - // Next, try 9.5- format. - $return = drush_backend_parse_output($process->getOutput()); - if (!$return['error_status'] || !empty($return['object'])) { - $source_dump_path = $return['object']; - } - } - } - } else { - $source_dump_path = $options['source-dump']; - } - - if (empty($source_dump_path)) { - throw new \Exception(dt('The Drush sql:dump command did not report the path to the dump file.')); - } - return $source_dump_path; - } -} diff --git a/src/Sql/GdprSqlOracle.php b/src/Sql/GdprSqlOracle.php deleted file mode 100644 index f5f509e..0000000 --- a/src/Sql/GdprSqlOracle.php +++ /dev/null @@ -1,15 +0,0 @@ - Date: Fri, 9 Aug 2024 07:44:47 +0300 Subject: [PATCH 4/8] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 381b8d9..c120e80 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,13 @@ and can in principle dump any database that PDO supports. Require druidfi/gdpr-mysqldump with Composer: -``` +```console composer require druidfi/drush-gdpr-dumper ``` Enable the module in Drupal UI or with Drush: -``` +```console drush en gdpr_dumper ``` @@ -24,13 +24,13 @@ drush en gdpr_dumper If you want to create a sql dump on live servers for local purposes (as a developer, themer, ...), you should use following command: -``` +```console drush sql-dump-gdpr > dump.sql ``` instead of -``` +```console drush sql-dump > dump.sql ``` @@ -41,7 +41,7 @@ be GDPR compliant YO! In settings.php you can do the override configuration like this: -``` +```php $config['gdpr_dumper.settings']['gdpr_replacements'] = [ 'users_field_data' => [ // Table 'name' => [ // Field From b0b4fc50e586f0416b518f53083783d74d73aa00 Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Fri, 9 Aug 2024 07:45:42 +0300 Subject: [PATCH 5/8] Bump up constraints --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index da7317e..a6ccb5e 100644 --- a/composer.json +++ b/composer.json @@ -23,8 +23,8 @@ "require": { "php": "^8.1", "druidfi/gdpr-mysqldump": "^1.2.6", - "drush/drush": "^12 || ^13", - "drupal/core-recommended": "^10 || ^11" + "drush/drush": "^13", + "drupal/core-recommended": "^10.3 || ^11" }, "config": { "allow-plugins": { From 239de906a288db1baecbfe0b710c02a35d8a764d Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Fri, 9 Aug 2024 07:50:05 +0300 Subject: [PATCH 6/8] Cleanup drivers --- config/install/gdpr_dumper.settings.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/config/install/gdpr_dumper.settings.yml b/config/install/gdpr_dumper.settings.yml index 7a3faac..57a52f3 100644 --- a/config/install/gdpr_dumper.settings.yml +++ b/config/install/gdpr_dumper.settings.yml @@ -12,11 +12,5 @@ gdpr_replacements: drivers: mysql: dump_command: 'mysqldump' - oracle: - dump_command: 'mysqldump' pqsql: dump_command: 'pg_dump' - sqlite: - dump_command: 'dump' - sqlsrv: - dump_command: 'mysqldump' From f9c8df6fc18c1c1d5ec1838300c8abed8e44dfda Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Fri, 9 Aug 2024 07:54:40 +0300 Subject: [PATCH 7/8] Fix deprecation on DrupalFinder --- composer.json | 3 +++ src/Sql/GdprSqlTrait.php | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index a6ccb5e..9fd31ff 100644 --- a/composer.json +++ b/composer.json @@ -30,5 +30,8 @@ "allow-plugins": { "cweagans/composer-patches": true } + }, + "require-dev": { + "webflo/drupal-finder": "^1.3" } } diff --git a/src/Sql/GdprSqlTrait.php b/src/Sql/GdprSqlTrait.php index 511e2a3..d1e088c 100644 --- a/src/Sql/GdprSqlTrait.php +++ b/src/Sql/GdprSqlTrait.php @@ -2,7 +2,7 @@ namespace Drupal\gdpr_dumper\Sql; -use DrupalFinder\DrupalFinder; +use DrupalFinder\DrupalFinderComposerRuntime; /** * Trait GdprSqlTrait @@ -16,12 +16,12 @@ public function dumpCmd($table_selection): string { $cmd = parent::dumpCmd($table_selection); - $drupal_finder = new DrupalFinder(); - $drupal_finder->locateRoot(DRUPAL_ROOT); + $drupal_finder = new DrupalFinderComposerRuntime(); + $drupal_finder->getDrupalRoot(); $vendor_dir = $drupal_finder->getVendorDir(); if ($vendor_dir && isset($this->driverOptions['dump_command'])) { - // Replace default dump command with the GDPR compliant one. + // Replace default dump command with the GDPR-compliant one. $cmd = str_replace($this->driverOptions['dump_command'], $vendor_dir . '/bin/mysqldump', $cmd); } From a36fbae5d71b34372ef720a0156bdea2a05ca95b Mon Sep 17 00:00:00 2001 From: Marko Korhonen Date: Fri, 9 Aug 2024 07:55:21 +0300 Subject: [PATCH 8/8] Add return type --- src/Sql/GdprSqlTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sql/GdprSqlTrait.php b/src/Sql/GdprSqlTrait.php index d1e088c..5f3bf6c 100644 --- a/src/Sql/GdprSqlTrait.php +++ b/src/Sql/GdprSqlTrait.php @@ -33,7 +33,7 @@ public function getDriverOptions(): array return $this->driverOptions; } - public function setDriverOptions(array $options) + public function setDriverOptions(array $options): void { $this->driverOptions = $options; }