Loading core/modules/path_alias/path_alias.post_update.php 0 → 100644 +16 −0 Original line number Diff line number Diff line <?php /** * @file * Post update functions for Path Alias. */ /** * Remove the path_alias__status index. */ function path_alias_post_update_drop_path_alias_status_index(): void { /** @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $update_manager */ $update_manager = \Drupal::service('entity.definition_update_manager'); $entity_type = $update_manager->getEntityType('path_alias'); $update_manager->updateEntityType($entity_type); } core/modules/path_alias/src/PathAliasStorageSchema.php +6 −1 Original line number Diff line number Diff line Loading @@ -15,12 +15,17 @@ class PathAliasStorageSchema extends SqlContentEntityStorageSchema { */ protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) { $schema = parent::getEntitySchema($entity_type, $reset); $base_table = $this->storage->getBaseTable(); $schema[$this->storage->getBaseTable()]['indexes'] += [ $schema[$base_table]['indexes'] += [ 'path_alias__alias_langcode_id_status' => ['alias', 'langcode', 'id', 'status'], 'path_alias__path_langcode_id_status' => ['path', 'langcode', 'id', 'status'], ]; // Unset the path_alias__status index as it is slower than the above // indexes and MySQL 5.7 chooses to use it even though it is suboptimal. unset($schema[$base_table]['indexes']['path_alias__status']); return $schema; } Loading core/modules/path_alias/tests/src/Functional/PathAliasUpdateTest.php 0 → 100644 +33 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\path_alias\Functional; use Drupal\FunctionalTests\Update\UpdatePathTestBase; /** * Tests update hooks the path_alias module. * * @group path_alias */ class PathAliasUpdateTest extends UpdatePathTestBase { /** * {@inheritdoc} */ protected function setDatabaseDumpFiles() { $this->databaseDumpFiles[] = __DIR__ . '/../../../../system/tests/fixtures/update/drupal-9.4.0.bare.standard.php.gz'; } /** * Tests path_alias_post_update_drop_path_alias_status_index. */ public function testPathAliasStatusIndexRemoved(): void { $schema = \Drupal::database()->schema(); $this->assertTrue($schema->indexExists('path_alias', 'path_alias__status')); $this->runUpdates(); $this->assertFalse($schema->indexExists('path_alias', 'path_alias__status')); } } core/modules/path_alias/tests/src/Kernel/PathAliasStorageSchemaTest.php 0 → 100644 +44 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\path_alias\Kernel; use Drupal\KernelTests\KernelTestBase; /** * Tests the path_alias storage schema. * * @coversDefaultClass \Drupal\path_alias\PathAliasStorageSchema * * @group path_alias */ class PathAliasStorageSchemaTest extends KernelTestBase { /** * {@inheritdoc} */ protected static $modules = ['path_alias']; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $this->installEntitySchema('path_alias'); } /** * Tests that the path_alias__status index is removed. * * @covers ::getEntitySchema */ public function testPathAliasStatusIndexRemoved(): void { $schema = \Drupal::database()->schema(); $table_name = 'path_alias'; $this->assertTrue($schema->indexExists($table_name, 'path_alias__alias_langcode_id_status')); $this->assertTrue($schema->indexExists($table_name, 'path_alias__path_langcode_id_status')); $this->assertFalse($schema->indexExists($table_name, 'path_alias__status')); } } Loading
core/modules/path_alias/path_alias.post_update.php 0 → 100644 +16 −0 Original line number Diff line number Diff line <?php /** * @file * Post update functions for Path Alias. */ /** * Remove the path_alias__status index. */ function path_alias_post_update_drop_path_alias_status_index(): void { /** @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $update_manager */ $update_manager = \Drupal::service('entity.definition_update_manager'); $entity_type = $update_manager->getEntityType('path_alias'); $update_manager->updateEntityType($entity_type); }
core/modules/path_alias/src/PathAliasStorageSchema.php +6 −1 Original line number Diff line number Diff line Loading @@ -15,12 +15,17 @@ class PathAliasStorageSchema extends SqlContentEntityStorageSchema { */ protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) { $schema = parent::getEntitySchema($entity_type, $reset); $base_table = $this->storage->getBaseTable(); $schema[$this->storage->getBaseTable()]['indexes'] += [ $schema[$base_table]['indexes'] += [ 'path_alias__alias_langcode_id_status' => ['alias', 'langcode', 'id', 'status'], 'path_alias__path_langcode_id_status' => ['path', 'langcode', 'id', 'status'], ]; // Unset the path_alias__status index as it is slower than the above // indexes and MySQL 5.7 chooses to use it even though it is suboptimal. unset($schema[$base_table]['indexes']['path_alias__status']); return $schema; } Loading
core/modules/path_alias/tests/src/Functional/PathAliasUpdateTest.php 0 → 100644 +33 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\path_alias\Functional; use Drupal\FunctionalTests\Update\UpdatePathTestBase; /** * Tests update hooks the path_alias module. * * @group path_alias */ class PathAliasUpdateTest extends UpdatePathTestBase { /** * {@inheritdoc} */ protected function setDatabaseDumpFiles() { $this->databaseDumpFiles[] = __DIR__ . '/../../../../system/tests/fixtures/update/drupal-9.4.0.bare.standard.php.gz'; } /** * Tests path_alias_post_update_drop_path_alias_status_index. */ public function testPathAliasStatusIndexRemoved(): void { $schema = \Drupal::database()->schema(); $this->assertTrue($schema->indexExists('path_alias', 'path_alias__status')); $this->runUpdates(); $this->assertFalse($schema->indexExists('path_alias', 'path_alias__status')); } }
core/modules/path_alias/tests/src/Kernel/PathAliasStorageSchemaTest.php 0 → 100644 +44 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\path_alias\Kernel; use Drupal\KernelTests\KernelTestBase; /** * Tests the path_alias storage schema. * * @coversDefaultClass \Drupal\path_alias\PathAliasStorageSchema * * @group path_alias */ class PathAliasStorageSchemaTest extends KernelTestBase { /** * {@inheritdoc} */ protected static $modules = ['path_alias']; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $this->installEntitySchema('path_alias'); } /** * Tests that the path_alias__status index is removed. * * @covers ::getEntitySchema */ public function testPathAliasStatusIndexRemoved(): void { $schema = \Drupal::database()->schema(); $table_name = 'path_alias'; $this->assertTrue($schema->indexExists($table_name, 'path_alias__alias_langcode_id_status')); $this->assertTrue($schema->indexExists($table_name, 'path_alias__path_langcode_id_status')); $this->assertFalse($schema->indexExists($table_name, 'path_alias__status')); } }