Unverified Commit 5b7419e8 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3106205 by jrglasgow, plopesc, jonathan1055, smustgrave, edmund.dunn,...

Issue #3106205 by jrglasgow, plopesc, jonathan1055, smustgrave, edmund.dunn, heddn, narendra.rajwar27, jamiehollern, joshua1234511, murilohp, jacob.embree, mayurjadhav, raman.b, voviko, sonnykt, catch, kristen pol, dspachos, longwave, fmb, quietone, xjm, larowlan, devad: Length of menu_tree.url and menu_tree.route_param_key are too short (255 characters)

(cherry picked from commit 35044e45)
parent 8fc8778c
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1222,7 +1222,7 @@ protected static function schemaDefinition() {
        'route_param_key' => [
          'description' => 'An encoded string of route parameters for loading by route.',
          'type' => 'varchar',
          'length' => 255,
          'length' => 2048,
        ],
        'route_parameters' => [
          'description' => 'Serialized array of route parameters of this menu link.',
@@ -1234,7 +1234,7 @@ protected static function schemaDefinition() {
        'url' => [
          'description' => 'The external path this link points to (when not using a route).',
          'type' => 'varchar',
          'length' => 255,
          'length' => 2048,
          'not null' => TRUE,
          'default' => '',
        ],
+22 −0
Original line number Diff line number Diff line
@@ -1722,3 +1722,25 @@ function _system_advisories_requirements(array &$requirements): void {
    }
  }
}

/**
 * Update length of menu_tree fields url and route_param_key from 255 to 2048.
 */
function system_update_11001(): void {
  $schema = \Drupal::database()->schema();
  $spec = [
    'description' => 'The external path this link points to (when not using a route).',
    'type' => 'varchar',
    'length' => 2048,
    'not null' => TRUE,
    'default' => '',
  ];
  $schema->changeField('menu_tree', 'url', 'url', $spec);

  $spec = [
    'description' => 'An encoded string of route parameters for loading by route.',
    'type' => 'varchar',
    'length' => 2048,
  ];
  $schema->changeField('menu_tree', 'route_param_key', 'route_param_key', $spec);
}
+72 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\system\Functional\Update;

use Drupal\Core\Database\Connection;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;

/**
 * Tests update of menu tree storage fields.
 *
 * @group system
 */
class MenuTreeStorageSchemaUpdateTest extends UpdatePathTestBase {

  /**
   * The database.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected Connection $connection;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    /** @var \Drupal\Core\Database\Connection $connection */
    $this->connection = \Drupal::service('database');
  }

  /**
   * {@inheritdoc}
   */
  protected function setDatabaseDumpFiles(): void {
    $this->databaseDumpFiles = [
      // Start with a bare installation of Drupal 10.3.0.
      DRUPAL_ROOT . '/core/modules/system/tests/fixtures/update/drupal-10.3.0.bare.standard.php.gz',
    ];
  }

  /**
   * Tests DB behavior after update.
   */
  public function testSchemaLengthAfterUpdate(): void {
    if (\Drupal::service('database')->databaseType() == 'sqlite') {
      $this->markTestSkipped("This test does not support the SQLite database driver.");
    }

    $results = $this->connection->query('SELECT CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = :menu AND COLUMN_NAME IN ( :column_names[] )', [
      ':menu' => $this->connection->schema()->prefixNonTable('menu_tree'),
      ':column_names[]' => ['route_param_key', 'url'],
    ])->fetchCol();
    $this->assertNotEmpty($results);
    foreach ($results as $result) {
      self::assertEquals(255, $result);
    }

    $this->runUpdates();

    $results = $this->connection->query('SELECT CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = :menu AND COLUMN_NAME IN ( :column_names[] )', [
      ':menu' => $this->connection->schema()->prefixNonTable('menu_tree'),
      ':column_names[]' => ['route_param_key', 'url'],
    ])->fetchCol();
    $this->assertNotEmpty($results);
    foreach ($results as $result) {
      self::assertEquals(2048, $result);
    }
  }

}