Unverified Commit 39578f45 authored by alexpott's avatar alexpott

Issue #3006086 by amateescu, Wim Leers, alexpott, jibran, andypost, dawehner,...

Issue #3006086 by amateescu, Wim Leers, alexpott, jibran, andypost, dawehner, catch, Berdir: update.php should not process path aliases
parent cd6c6710
......@@ -32,6 +32,16 @@ public function alter(ContainerBuilder $container) {
$definition = $container->getDefinition('library.discovery.collector');
$argument = new Reference('cache.null');
$definition->replaceArgument(0, $argument);
// Prevent the alias-based path processor, which requires a path_alias db
// table, from being registered to the path processor manager. We do this by
// removing the tags that the compiler pass looks for. This means the url
// generator can safely be used during the database update process.
if ($container->hasDefinition('path_processor_alias')) {
$container->getDefinition('path_processor_alias')
->clearTag('path_processor_inbound')
->clearTag('path_processor_outbound');
}
}
}
......@@ -6,6 +6,27 @@
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Url;
use Drupal\Component\Render\FormattableMarkup;
/**
* Implements hook_requirements().
*/
function update_test_schema_requirements($phase) {
$requirements = [];
if ($phase === 'runtime') {
$requirements['path_alias_test'] = [
'title' => 'Path alias test',
'value' => 'Check a path alias for the admin page',
'severity' => REQUIREMENT_INFO,
'description' => new FormattableMarkup('Visit <a href=":link">the structure page</a> to do many useful things.', [
':link' => Url::fromRoute('system.admin_structure')->toString(),
]),
];
}
return $requirements;
}
/**
* Implements hook_schema().
......@@ -50,3 +71,18 @@ function update_test_schema_update_8001() {
}
}
if ($schema_version >= 8002) {
/**
* Schema version 8002.
*/
function update_test_schema_update_8002() {
// Return a message that contains a system path with an alias.
// @see \Drupal\FunctionalTests\Update\UpdatePathTestBaseTest::testPathAliasProcessing()
return new FormattableMarkup('Visit <a href=":link">the structure page</a> to do many useful things.', [
':link' => Url::fromRoute('system.admin_structure')->toString(),
]);
}
}
......@@ -160,8 +160,10 @@ protected function setUp() {
// Set the update url. This must be set here rather than in
// self::__construct() or the old URL generator will leak additional test
// sites.
$this->updateUrl = Url::fromRoute('system.db_update');
// sites. Additionally, we need to prevent the path alias processor from
// running because we might not have a working alias system before running
// the updates.
$this->updateUrl = Url::fromRoute('system.db_update', [], ['path_processing' => FALSE]);
$this->setupBaseUrl();
......
......@@ -98,4 +98,37 @@ public function testUpdateHookN() {
$this->assertTrue($connection->schema()->indexExists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
}
/**
* Tests that path aliases are not processed during database updates.
*/
public function testPathAliasProcessing() {
// Add a path alias for the '/admin' system path.
$database = \Drupal::database();
$database->insert('url_alias')
->fields(['source', 'alias', 'langcode'])
->values([
'source' => '/admin/structure',
'alias' => '/admin-structure-alias',
'langcode' => 'und',
])
->execute();
// Increment the schema version.
\Drupal::state()->set('update_test_schema_version', 8002);
$this->runUpdates();
// Check that the alias defined earlier is not used during the update
// process.
$this->assertSession()->linkByHrefExists('/admin/structure');
$this->assertSession()->linkByHrefNotExists('/admin-structure-alias');
$account = $this->createUser(['administer site configuration', 'access administration pages', 'access site reports']);
$this->drupalLogin($account);
// Go to the status report page and check that the alias is used.
$this->drupalGet('admin/reports/status');
$this->assertSession()->linkByHrefNotExists('/admin/structure');
$this->assertSession()->linkByHrefExists('/admin-structure-alias');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment