Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump up requirements and support Drupal 11 and Drush 13 #6

Merged
merged 8 commits into from
Aug 9, 2024
Merged
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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
```

Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
}
],
"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": "^13",
"drupal/core-recommended": "^10.3 || ^11"
},
"config": {
"allow-plugins": {
"cweagans/composer-patches": true
}
},
"require-dev": {
"webflo/drupal-finder": "^1.3"
}
}
6 changes: 0 additions & 6 deletions config/install/gdpr_dumper.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion gdpr_dumper.info.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 27 additions & 23 deletions src/Commands/SqlCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
final 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 <info>$PATH</info>.')]
#[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. <info>mysqldump</info> 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 <info>mysqldump</info> 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.
Expand All @@ -55,5 +59,5 @@ public function dump($options = ['result-file' => self::REQ, 'create-db' => fals
}

return new PropertyList(['path' => $return]);
}
}
}
58 changes: 0 additions & 58 deletions src/Commands/SqlSyncCommands.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Sql/GdprSqlOracle.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Sql/GdprSqlSqlite.php

This file was deleted.

15 changes: 0 additions & 15 deletions src/Sql/GdprSqlSqlsrv.php

This file was deleted.

10 changes: 5 additions & 5 deletions src/Sql/GdprSqlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Drupal\gdpr_dumper\Sql;

use DrupalFinder\DrupalFinder;
use DrupalFinder\DrupalFinderComposerRuntime;

/**
* Trait GdprSqlTrait
Expand All @@ -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);
}

Expand All @@ -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;
}
Expand Down