You are here

protected function GdprDumpGdprSqlMysql::createRenameCommands in General Data Protection Regulation 7

Create table renames according to the GDPR config.

Parameters

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

Return value

string The command.

1 call to GdprDumpGdprSqlMysql::createRenameCommands()
GdprDumpGdprSqlMysql::dump in modules/gdpr_dump/inc/GdprDumpGdprSqlMysql.inc
Execute a SQL dump and return the path to the resulting dump file.

File

modules/gdpr_dump/inc/GdprDumpGdprSqlMysql.inc, line 58

Class

GdprDumpGdprSqlMysql
Class GdprDumpGdprSqlMysql.

Code

protected function createRenameCommands(array $tableSelection) {

  // @todo: Dep.inj.

  /** @var array $gdprOptions */
  $gdprOptions = variable_get('gdpr_dump_table_map', []);
  $emptyTables = variable_get('gdpr_dump_empty_tables', []);
  $sensitiveDataTables = \array_keys($gdprOptions);
  $skipTables = \array_merge($tableSelection['skip'], $tableSelection['structure']);
  $skipTables = \array_flip($skipTables);
  $skipTables = $skipTables + $emptyTables;
  $command = '';
  foreach ($sensitiveDataTables as $table) {
    if (\array_key_exists($table, $skipTables)) {

      // Don't try to rename a table if it is excluded.
      continue;
    }
    $clone = GdprDumpGdprSqlDump::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;
}