You are here

protected function GdprSqlMysql::createRenameCommands in General Data Protection Regulation 8

Same name and namespace in other branches
  1. 8.2 modules/gdpr_dump/src/Sql/GdprSqlMysql.php \Drupal\gdpr_dump\Sql\GdprSqlMysql::createRenameCommands()
  2. 3.0.x modules/gdpr_dump/src/Sql/GdprSqlMysql.php \Drupal\gdpr_dump\Sql\GdprSqlMysql::createRenameCommands()

Create table renames according to the GDPR config.

Parameters

array $tableSelection: Supported keys: 'skip', 'structure', 'tables'.

Return value

string The command.

1 call to GdprSqlMysql::createRenameCommands()
GdprSqlMysql::dump in modules/gdpr_dump/src/Sql/GdprSqlMysql.php
Execute a SQL dump and return the path to the resulting dump file.

File

modules/gdpr_dump/src/Sql/GdprSqlMysql.php, line 97

Class

GdprSqlMysql
Class GdprSqlMysql.

Namespace

Drupal\gdpr_dump\Sql

Code

protected function createRenameCommands(array $tableSelection) {
  $skipTables = \array_merge($tableSelection['skip'], $tableSelection['structure']);
  $skipTables = \array_flip($skipTables);
  $skipTables += $this->tablesToSkip;
  $command = '';
  foreach (\array_keys($this->tablesToAnonymize) as $table) {
    if (\array_key_exists($table, $skipTables)) {

      // Don't try to rename a table if it is excluded.
      continue;
    }
    $clone = GdprSqlDump::GDPR_TABLE_PREFIX . $table;
    $rename = "RENAME TABLE \\`{$clone}\\` TO \\`{$table}\\`;";
    if (drush_get_context('DRUSH_VERBOSE') || drush_get_context('DRUSH_SIMULATE')) {
      drush_print("Adding rename command: '{$rename}'", 0, STDERR);
    }
    $command .= " ( echo \"{$rename}\" ); ";
  }
  return $command;
}