You are here

protected function GdprSqlDump::createTableClones in General Data Protection Regulation 8.2

Same name and namespace in other branches
  1. 8 modules/gdpr_dump/src/Service/GdprSqlDump.php \Drupal\gdpr_dump\Service\GdprSqlDump::createTableClones()
  2. 3.0.x modules/gdpr_dump/src/Service/GdprSqlDump.php \Drupal\gdpr_dump\Service\GdprSqlDump::createTableClones()

Creates table clones according to the config.

Throws

\Drupal\Core\Database\TransactionNoActiveException

\Drupal\Core\Database\TransactionCommitFailedException

\InvalidArgumentException

\Drupal\Core\Database\IntegrityConstraintViolationException

\Drupal\Core\Database\DatabaseExceptionWrapper

\Exception

1 call to GdprSqlDump::createTableClones()
GdprSqlDump::prepare in modules/gdpr_dump/src/Service/GdprSqlDump.php
Prepare the database for the dump.

File

modules/gdpr_dump/src/Service/GdprSqlDump.php, line 195

Class

GdprSqlDump
Class GdprSqlDump.

Namespace

Drupal\gdpr_dump\Service

Code

protected function createTableClones() {
  $tables = array_keys($this->tablesToAnonymize);
  $transaction = $this->database
    ->startTransaction('gdpr_clone_tables');
  foreach ($tables as $table) {
    $queryString = $this
      ->createCloneQueryString($table);
    if (NULL === $queryString) {

      // @todo: Notify?
      continue;
    }
    try {
      if (Drush::verbose() || Drush::service('config')
        ->simulate()) {
        Drush::output()
          ->writeln("Executing: '{$queryString}'");
      }
      $query = $this->database
        ->query($queryString);
      $query
        ->execute();
    } catch (Exception $e) {
      Drush::service('logger')
        ->error("Error while cloning the '{$table}'' table.");
      $transaction
        ->rollBack();
    }
  }
  $this->database
    ->popTransaction($transaction
    ->name());
}