Commit 9259e099 authored by catch's avatar catch
Browse files

Issue #3210913 by quietone, Wim Leers, paulocs: DbDumpCommand fails when data...

Issue #3210913 by quietone, Wim Leers, paulocs: DbDumpCommand fails when data type is not a mapped Drupal schema field name

(cherry picked from commit c2103890)
parent a4cf7243
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -334,7 +334,7 @@ protected function fieldTypeMap(Connection $connection, $type) {
   * @param string $type
   *   The MySQL field type.
   *
   * @return string
   * @return string|null
   *   The Drupal schema field size.
   */
  protected function fieldSizeMap(Connection $connection, $type) {
@@ -342,6 +342,11 @@ protected function fieldSizeMap(Connection $connection, $type) {
    $map = array_map('strtolower', $connection->schema()->getFieldTypeMap());
    $map = array_flip($map);

    // Do nothing if the field type is not defined.
    if (!isset($map[$type])) {
      return NULL;
    }

    $schema_type = explode(':', $map[$type])[0];
    // Only specify size on these types.
    if (in_array($schema_type, ['blob', 'float', 'int', 'text'])) {
+6 −0
Original line number Diff line number Diff line
@@ -36,6 +36,12 @@ protected function setUp(): void {
    /** @var \Drupal\Core\Database\Connection $connection */
    $connection = $this->container->get('database');
    $connection->insert('router')->fields(['name', 'path', 'pattern_outline'])->values(['test', 'test', 'test'])->execute();

    // Create a table with a field type not defined in
    // \Drupal\Core\Database\Schema::getFieldTypeMap.
    $table_name = $connection->tablePrefix() . 'foo';
    $sql = "create table if not exists `$table_name` (`test` datetime NOT NULL);";
    $connection->query($sql)->execute();
  }

  /**