Commit 6c3e7da2 authored by catch's avatar catch

Issue #2226455 by quietone, ultimike, brockfanning: Migrated URL aliases not...

Issue #2226455 by quietone, ultimike, brockfanning: Migrated URL aliases not working until nodes are re-saved
parent 5d8ea5f8
......@@ -32353,7 +32353,7 @@
'pid' => '1',
'src' => 'node/1',
'dst' => 'alias-one',
'language' => 'en',
'language' => 'af',
))
->values(array(
'pid' => '2',
......@@ -32361,6 +32361,12 @@
'dst' => 'alias-two',
'language' => 'en',
))
->values(array(
'pid' => '3',
'src' => 'node/3',
'dst' => 'alias-three',
'language' => '',
))
->execute();
$connection->schema()->createTable('users', array(
......
......@@ -17,6 +17,9 @@ process:
source:
- constants/slash
- dst
langcode: language
langcode:
plugin: d6_url_alias_language
source:
- language
destination:
plugin: url_alias
<?php
/**
* @file
* Contains \Drupal\path\Plugin\migrate\process\d6\UrlAliasLanguage.
*/
namespace Drupal\path\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Drupal\Core\Language\LanguageInterface;
/**
* Url alias language code process.
*
* @MigrateProcessPlugin(
* id = "d6_url_alias_language"
* )
*/
class UrlAliasLanguage extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$language = reset($value);
$langcode = ($language === '') ? LanguageInterface::LANGCODE_NOT_SPECIFIED : $language;
return $langcode;
}
}
......@@ -32,27 +32,44 @@ protected function setUp() {
$this->executeMigration('d6_url_alias');
}
/**
* Assert a path.
*
* @param string pid
* The path id.
* @param array $conditions
* The path conditions.
* @param array $path
* The path.
*/
private function assertPath($pid, $conditions, $path) {
$this->assertTrue($path, "Path alias for " . $conditions['source'] . " successfully loaded.");
$this->assertIdentical($conditions['alias'], $path['alias']);
$this->assertIdentical($conditions['langcode'], $path['langcode']);
$this->assertIdentical($conditions['source'], $path['source']);
}
/**
* Test the url alias migration.
*/
public function testUrlAlias() {
$id_map = Migration::load('d6_url_alias')->getIdMap();
// Test that the field exists.
$conditions = array(
'source' => '/node/1',
'alias' => '/alias-one',
'langcode' => 'en',
'langcode' => 'af',
);
$path = \Drupal::service('path.alias_storage')->load($conditions);
$this->assertNotNull($path, "Path alias for node/1 successfully loaded.");
$this->assertPath('1', $conditions, $path);
$this->assertIdentical($id_map->lookupDestinationID(array($path['pid'])), array('1'), "Test IdMap");
$conditions = array(
'source' => '/node/2',
'alias' => '/alias-two',
'langcode' => 'en',
);
$path = \Drupal::service('path.alias_storage')->load($conditions);
$this->assertNotNull($path, "Path alias for node/2 successfully loaded.");
$this->assertPath('2', $conditions, $path);
// Test that we can re-import using the UrlAlias destination.
Database::getConnection('default', 'migrate')
......@@ -71,7 +88,16 @@ public function testUrlAlias() {
$this->executeMigration($migration);
$path = \Drupal::service('path.alias_storage')->load(array('pid' => $path['pid']));
$this->assertIdentical('/new-url-alias', $path['alias']);
$conditions['alias'] = '/new-url-alias';
$this->assertPath('2', $conditions, $path);
$conditions = array(
'source' => '/node/3',
'alias' => '/alias-three',
'langcode' => 'und',
);
$path = \Drupal::service('path.alias_storage')->load($conditions);
$this->assertPath('3', $conditions, $path);
}
}
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