You are here

protected function GdprSqlDump::createCloneQueryString in General Data Protection Regulation 3.0.x

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

Creates a query string for cloning.

Parameters

string $originalTable: The table name.

Return value

string|null The query string.

Throws

\Exception

1 call to GdprSqlDump::createCloneQueryString()
GdprSqlDump::createTableClones in modules/gdpr_dump/src/Service/GdprSqlDump.php
Creates table clones according to the config.

File

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

Class

GdprSqlDump
Class GdprSqlDump.

Namespace

Drupal\gdpr_dump\Service

Code

protected function createCloneQueryString($originalTable) {
  if (array_key_exists($originalTable, $this->tablesToSkip)) {

    // No need to clone tables that are excluded.
    return NULL;
  }
  $clonedTable = self::GDPR_TABLE_PREFIX . $originalTable;
  switch ($this->driver) {
    case 'mysql':
      return "CREATE TABLE IF NOT EXISTS `{$clonedTable}` LIKE `{$originalTable}`;";

    /* @todo
     * - These seem to be the same.
     * - Test both.
     */
    case 'pgsql':
    case 'sqlite':

      // Maybe get the original SQL of the table and apply that:
      // SELECT sql FROM sqlite_master WHERE type='table' AND name='mytable'.
      return "CREATE TABLE IF NOT EXISTS `{$clonedTable}` AS SELECT * FROM `{$originalTable}` WHERE 1=2;";

    // These require a contrib module.
    case 'oracle':

      // @see: https://www.drupal.org/project/oracle
      break;
    case 'sqlsrv':

      // @see: https://www.drupal.org/project/sqlsrv
      break;
  }
  throw new SqlException("Unsupported database driver detected, can't clone table {$originalTable} for GDPR.");
}