Commit df594822 authored by catch's avatar catch
Browse files

Issue #3389202 by mondrake, andypost, daffie:...

Issue #3389202 by mondrake, andypost, daffie: migrate\Plugin\migrate\id_map\Sql assumes a PDO db driver
parent c3ff5768
Loading
Loading
Loading
Loading
Loading
+12 −0
Changes for core/lib/Drupal/Core/Database/Exception/SchemaTableColumnSizeTooLargeException.php: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Database\Exception;

use Drupal\Core\Database\DatabaseException;
use Drupal\Core\Database\SchemaException;

/**
 * Exception thrown if a column size is too large on table creation.
 */
class SchemaTableColumnSizeTooLargeException extends SchemaException implements DatabaseException {
}
+12 −0
Changes for core/lib/Drupal/Core/Database/Exception/SchemaTableKeyTooLargeException.php: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Database\Exception;

use Drupal\Core\Database\DatabaseException;
use Drupal\Core\Database\SchemaException;

/**
 * Exception thrown if a key is too large.
 */
class SchemaTableKeyTooLargeException extends SchemaException implements DatabaseException {
}
+3 −4
Changes for core/modules/migrate/src/Plugin/migrate/id_map/Sql.php: 3 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

use Drupal\Core\Database\DatabaseException;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Database\Exception\SchemaTableKeyTooLargeException;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
@@ -424,13 +425,11 @@ protected function ensureTables() {
            ->createTable($this->mapTableName, $schema);
          break;
        }
        catch (DatabaseException $e) {
          $pdo_exception = $e->getPrevious();
          $mysql_index_error = $pdo_exception instanceof \PDOException && $pdo_exception->getCode() === '42000' && $pdo_exception->errorInfo[1] === 1071;
        catch (SchemaTableKeyTooLargeException $e) {
          $chunk_size--;
          // Rethrow the exception if the source IDs can not be in smaller
          // groups.
          if (!$mysql_index_error || $chunk_size <= 0) {
          if ($chunk_size <= 0) {
            throw $e;
          }
        }
+2 −3
Changes for core/modules/migrate/tests/src/Kernel/Plugin/id_map/SqlTest.php: 2 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
namespace Drupal\Tests\migrate\Kernel\Plugin\id_map;

use Drupal\Core\Database\Database;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Database\Exception\SchemaTableColumnSizeTooLargeException;
use Drupal\Tests\migrate\Kernel\MigrateTestBase;
use Drupal\Tests\migrate\Unit\TestSqlIdMap;
use Drupal\migrate\MigrateException;
@@ -151,8 +151,7 @@ public function testFailEnsureTables($ids) {
    // Use local id map plugin to force an error.
    $map = new SqlIdMapTest($this->database, [], 'test', [], $migration, $this->eventDispatcher, $this->migrationPluginManager);

    $this->expectException(DatabaseExceptionWrapper::class);
    $this->expectExceptionMessage("Syntax error or access violation: 1074 Column length too big for column 'sourceid1' (max = 16383); use BLOB or TEXT instead:");
    $this->expectException(SchemaTableColumnSizeTooLargeException::class);
    $map->ensureTables();
  }

+10 −0
Changes for core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Database\ExceptionHandler as BaseExceptionHandler;
use Drupal\Core\Database\Exception\SchemaTableColumnSizeTooLargeException;
use Drupal\Core\Database\Exception\SchemaTableKeyTooLargeException;
use Drupal\Core\Database\IntegrityConstraintViolationException;
use Drupal\Core\Database\StatementInterface;

@@ -43,6 +45,14 @@ public function handleExecutionException(\Exception $exception, StatementInterfa
        throw new IntegrityConstraintViolationException($message, $code, $exception);
      }

      if ($exception->getCode() === '42000') {
        match ($exception->errorInfo[1]) {
          1071 => throw new SchemaTableKeyTooLargeException($message, $code, $exception),
          1074 => throw new SchemaTableColumnSizeTooLargeException($message, $code, $exception),
          default => throw new DatabaseExceptionWrapper($message, 0, $exception),
        };
      }

      throw new DatabaseExceptionWrapper($message, 0, $exception);
    }

Loading