Commit b42b41ac authored by webchick's avatar webchick

Issue #2504513 by quietone, phenaproxima, mikeryan: Migrate URL aliases

parent 560db5b3
......@@ -280,7 +280,7 @@ public function load() {
'name' => 'path',
'type' => 'module',
'owner' => '',
'status' => '0',
'status' => '1',
'throttle' => '0',
'bootstrap' => '0',
'schema_version' => '-1',
......@@ -939,4 +939,4 @@ public function load() {
}
}
#67a0176adb132bf6a171a703fa411e49
#05805c5d8ae80ed61f9abeb67143ec6f
......@@ -6,7 +6,6 @@ source:
plugin: d6_url_alias
constants:
slash: '/'
process:
source:
plugin: concat
......
id: d7_url_alias
label: URL aliases
migration_tags:
- Drupal 7
source:
plugin: d7_url_alias
constants:
slash: '/'
process:
source:
plugin: concat
source:
- constants/slash
- source
alias:
plugin: concat
source:
- constants/slash
- alias
langcode: language
destination:
plugin: url_alias
<?php
/**
* @file
* Contains \Drupal\path\Plugin\migrate\source\UrlAliasBase.
*/
namespace Drupal\path\Plugin\migrate\source;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Base class for the url_alias source plugins.
*/
abstract class UrlAliasBase extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('url_alias', 'ua')->fields('ua');
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'pid' => $this->t('The numeric identifier of the path alias.'),
'language' => $this->t('The language code of the url alias.'),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['pid']['type'] = 'integer';
return $ids;
}
}
......@@ -7,46 +7,26 @@
namespace Drupal\path\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
use Drupal\path\Plugin\migrate\source\UrlAliasBase;
/**
* Drupal 6 url aliases source from database.
* URL aliases source from database.
*
* @MigrateSource(
* id = "d6_url_alias"
* id = "d6_url_alias",
* source_provider = "path"
* )
*/
class UrlAlias extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('url_alias', 'ua')
->fields('ua', array('pid', 'src', 'dst', 'language'));
$query->orderBy('pid');
return $query;
}
class UrlAlias extends UrlAliasBase {
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'pid' => $this->t('The numeric identifier of the path alias.'),
'src' => $this->t('The internal path.'),
'dst' => $this->t('The user set path alias.'),
'language' => $this->t('The language code of the url alias.'),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['pid']['type'] = 'integer';
return $ids;
$fields = parent::fields();
$fields['src'] = $this->t('The internal system path.');
$fields['dst'] = $this->t('The path alias.');
return $fields;
}
}
<?php
/**
* @file
* Contains \Drupal\path\Plugin\migrate\source\d7\UrlAlias.
*/
namespace Drupal\path\Plugin\migrate\source\d7;
use Drupal\path\Plugin\migrate\source\UrlAliasBase;
/**
* URL aliases source from database.
*
* @MigrateSource(
* id = "d7_url_alias",
* source_provider = "path"
* )
*/
class UrlAlias extends UrlAliasBase {
/**
* {@inheritdoc}
*/
public function fields() {
$fields = parent::fields();
$fields['source'] = $this->t('The internal system path.');
$fields['alias'] = $this->t('The path alias.');
return $fields;
}
}
<?php
/**
* @file
* Contains \Drupal\path\Tests\Migrate\d7\MigrateUrlAliasTest.
*/
namespace Drupal\path\Tests\Migrate\d7;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Tests URL alias migration.
*
* @group path
*/
class MigrateUrlAliasTest extends MigrateDrupal7TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['path'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', ['url_alias']);
$this->executeMigration('d7_url_alias');
}
/**
* Test the URL alias migration.
*/
public function testUrlAlias() {
$path = \Drupal::service('path.alias_storage')->load([
'source' => '/taxonomy/term/4',
'alias' => '/term33',
'langcode' => 'und',
]);
$this->assertIdentical('/taxonomy/term/4', $path['source']);
$this->assertIdentical('/term33', $path['alias']);
$this->assertIdentical('und', $path['langcode']);
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\path\Unit\Migrate\UrlAliasTestBase.
*/
namespace Drupal\Tests\path\Unit\Migrate;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Base class for url_alias source tests.
*/
abstract class UrlAliasTestBase extends MigrateSqlSourceTestCase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->databaseContents['url_alias'] = $this->expectedResults;
parent::setUp();
}
}
......@@ -7,14 +7,14 @@
namespace Drupal\Tests\path\Unit\Migrate\d6;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
use Drupal\Tests\path\Unit\Migrate\UrlAliasTestBase;
/**
* Tests the D6 url alias migrations.
* Tests the d6_url_alias source plugin.
*
* @group path
*/
class UrlAliasTest extends MigrateSqlSourceTestCase {
class UrlAliasTest extends UrlAliasTestBase {
const PLUGIN_CLASS = 'Drupal\path\Plugin\migrate\source\d6\UrlAlias';
......@@ -41,14 +41,4 @@ class UrlAliasTest extends MigrateSqlSourceTestCase {
),
);
/**
* {@inheritdoc}
*/
protected function setUp() {
foreach ($this->expectedResults as $row) {
$this->databaseContents['url_alias'][] = $row;
}
parent::setUp();
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\path\Unit\Migrate\d7\UrlAliasTest.
*/
namespace Drupal\Tests\path\Unit\Migrate\d7;
use Drupal\Tests\path\Unit\Migrate\UrlAliasTestBase;
/**
* Tests the d7_url_alias source plugin.
*
* @group path
*/
class UrlAliasTest extends UrlAliasTestBase {
const PLUGIN_CLASS = 'Drupal\path\Plugin\migrate\source\d7\UrlAlias';
protected $migrationConfiguration = array(
'id' => 'test',
'source' => array(
'plugin' => 'd7_url_alias',
),
);
protected $expectedResults = array(
array(
'pid' => 1,
'source' => 'node/1',
'alias' => 'test-article',
'language' => 'en',
),
array(
'pid' => 2,
'source' => 'node/2',
'alias' => 'another-alias',
'language' => 'en',
),
);
}
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