Commit 7f81be33 authored by catch's avatar catch

Issue #2827644 by maxocub, phenaproxima: Fix path alias migration of translated nodes [D6]

parent c779a82a
......@@ -44405,6 +44405,30 @@
'dst' => 'alias-three',
'language' => '',
))
->values(array(
'pid' => '4',
'src' => 'node/10',
'dst' => 'the-real-mccoy',
'language' => 'en',
))
->values(array(
'pid' => '5',
'src' => 'node/11',
'dst' => 'le-vrai-mccoy',
'language' => 'fr',
))
->values(array(
'pid' => '6',
'src' => 'node/12',
'dst' => 'abantu-zulu',
'language' => 'zu',
))
->values(array(
'pid' => '7',
'src' => 'node/13',
'dst' => 'the-zulu-people',
'language' => 'en',
))
->execute();
$connection->schema()->createTable('users', array(
......@@ -20,5 +20,17 @@ process:
langcode:
plugin: d6_url_alias_language
source: language
node_translation:
-
plugin: explode
source: src
delimiter: /
-
plugin: extract
index:
- 1
-
plugin: migration
migration: d6_node_translation
destination:
plugin: url_alias
......@@ -59,13 +59,21 @@ public static function create(ContainerInterface $container, array $configuratio
* {@inheritdoc}
*/
public function import(Row $row, array $old_destination_id_values = array()) {
$source = $row->getDestinationProperty('source');
$alias = $row->getDestinationProperty('alias');
$langcode = $row->getDestinationProperty('langcode');
$pid = $old_destination_id_values ? $old_destination_id_values[0] : NULL;
$path = $this->aliasStorage->save(
$row->getDestinationProperty('source'),
$row->getDestinationProperty('alias'),
$row->getDestinationProperty('langcode'),
$old_destination_id_values ? $old_destination_id_values[0] : NULL
);
// Check if this alias is for a node and if that node is a translation.
if (preg_match('/^\/node\/\d+$/', $source) && $row->hasDestinationProperty('node_translation')) {
// Replace the alias source with the translation source path.
$node_translation = $row->getDestinationProperty('node_translation');
$source = '/node/' . $node_translation[0];
$langcode = $node_translation[1];
}
$path = $this->aliasStorage->save($source, $alias, $langcode, $pid);
return array($path['pid']);
}
......
......@@ -16,14 +16,26 @@ class MigrateUrlAliasTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('path');
public static $modules = ['language', 'content_translation', 'path'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_url_alias');
$this->installEntitySchema('node');
$this->installConfig(['node']);
$this->installSchema('node', ['node_access']);
$this->migrateUsers(FALSE);
$this->migrateFields();
$this->executeMigrations([
'language',
'd6_node_settings',
'd6_node',
'd6_node_translation',
'd6_url_alias',
]);
}
/**
......@@ -93,4 +105,33 @@ public function testUrlAlias() {
$this->assertPath('3', $conditions, $path);
}
/**
* Test the URL alias migration with translated nodes.
*/
public function testUrlAliasWithTranslatedNodes() {
$alias_storage = $this->container->get('path.alias_storage');
// Alias for the 'The Real McCoy' node in English.
$path = $alias_storage->load(['alias' => '/the-real-mccoy']);
$this->assertSame('/node/10', $path['source']);
$this->assertSame('en', $path['langcode']);
// Alias for the 'The Real McCoy' French translation,
// which should now point to node/10 instead of node/11.
$path = $alias_storage->load(['alias' => '/le-vrai-mccoy']);
$this->assertSame('/node/10', $path['source']);
$this->assertSame('fr', $path['langcode']);
// Alias for the 'Abantu zulu' node in Zulu.
$path = $alias_storage->load(['alias' => '/abantu-zulu']);
$this->assertSame('/node/12', $path['source']);
$this->assertSame('zu', $path['langcode']);
// Alias for the 'Abantu zulu' English translation,
// which should now point to node/12 instead of node/13.
$path = $alias_storage->load(['alias' => '/the-zulu-people']);
$this->assertSame('/node/12', $path['source']);
$this->assertSame('en', $path['langcode']);
}
}
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