Last active
June 4, 2016 21:42
-
-
Save chx/faa36718ec7fe2a912e6e8c41955238e to your computer and use it in GitHub Desktop.
How to migrate node/user/etc aliases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
id: discussion_aliases | |
label: Discussion aliases | |
source: | |
plugin: d7_node | |
node_type: discussion | |
constants: | |
english: en | |
node: /node | |
empty: "" | |
process: | |
alias: | |
plugin: concat | |
delimiter: / | |
source: | |
- constants/empty | |
- path | |
langcode: constants/english | |
destination_nid: | |
- | |
plugin: migration | |
migration: community_discussions | |
source: nid | |
no_stub: true | |
- | |
plugin: skip_on_empty | |
method: row | |
source: | |
plugin: concat | |
delimiter: / | |
source: | |
- constants/node | |
- @destination_nid | |
destination: | |
plugin: url_alias |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drupal\migrate\Plugin\MigrateSourceInterface; | |
use Drupal\migrate\Plugin\MigrationInterface; | |
use Drupal\migrate\Row; | |
/** | |
* Implements hook_migrate_prepare_row(). | |
*/ | |
function sc_migrate_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) { | |
$args = [ | |
':language_none' => 'und', | |
]; | |
switch ($migration->id()) { | |
case 'discussion_aliases': | |
case 'announcement_aliases': | |
$args[':system'] = 'node/' . $row->getSourceProperty('nid'); | |
break; | |
case 'community_user_aliases': | |
$args[':system'] = 'user/' . $row->getSourceProperty('uid'); | |
break; | |
default: | |
return; | |
} | |
/** @var Drupal\migrate\Plugin\migrate\source\SqlBase $source */ | |
$row->setSourceProperty('path', $source->getDatabase() | |
->query('SELECT alias FROM {url_alias} WHERE source IN (:system) AND language = :language_none ORDER BY pid ASC', $args) | |
->fetchField()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment