Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Provides migration from other Drupal sites.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Core\Database\DatabaseExceptionWrapper;
|
Chris@0
|
9 use Drupal\Core\Routing\RouteMatchInterface;
|
Chris@0
|
10 use Drupal\migrate\Exception\RequirementsException;
|
Chris@0
|
11 use Drupal\migrate\MigrateExecutable;
|
Chris@0
|
12 use Drupal\migrate\Plugin\RequirementsInterface;
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Implements hook_help().
|
Chris@0
|
16 */
|
Chris@0
|
17 function migrate_drupal_help($route_name, RouteMatchInterface $route_match) {
|
Chris@0
|
18 switch ($route_name) {
|
Chris@0
|
19 case 'help.page.migrate_drupal':
|
Chris@0
|
20 $output = '';
|
Chris@0
|
21 $output .= '<h3>' . t('About') . '</h3>';
|
Chris@0
|
22 $output .= '<p>' . t('The Migrate Drupal module provides a framework based on the <a href=":migrate">Migrate module</a> to facilitate migration from a Drupal (6, 7, or 8) site to your website. It does not provide a user interface. For more information, see the <a href=":migrate_drupal">online documentation for the Migrate Drupal module</a>.', [':migrate' => \Drupal::url('help.page', ['name' => 'migrate']), ':migrate_drupal' => 'https://www.drupal.org/documentation/modules/migrate_drupal']) . '</p>';
|
Chris@0
|
23 return $output;
|
Chris@0
|
24 }
|
Chris@0
|
25 }
|
Chris@0
|
26
|
Chris@0
|
27 /**
|
Chris@0
|
28 * Implements hook_migration_plugins_alter().
|
Chris@0
|
29 */
|
Chris@0
|
30 function migrate_drupal_migration_plugins_alter(&$definitions) {
|
Chris@0
|
31 // This is why the deriver can't do this: the 'd6_taxonomy_vocabulary'
|
Chris@0
|
32 // definition is not available to the deriver as it is running inside
|
Chris@0
|
33 // getDefinitions().
|
Chris@0
|
34 if (isset($definitions['d6_taxonomy_vocabulary'])) {
|
Chris@0
|
35 $vocabulary_migration_definition = [
|
Chris@0
|
36 'source' => [
|
Chris@0
|
37 'ignore_map' => TRUE,
|
Chris@0
|
38 'plugin' => 'd6_taxonomy_vocabulary',
|
Chris@0
|
39 ],
|
Chris@0
|
40 'destination' => [
|
Chris@0
|
41 'plugin' => 'null',
|
Chris@0
|
42 ],
|
Chris@0
|
43 'idMap' => [
|
Chris@0
|
44 'plugin' => 'null',
|
Chris@0
|
45 ],
|
Chris@0
|
46 ];
|
Chris@0
|
47 $vocabulary_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($vocabulary_migration_definition);
|
Chris@0
|
48
|
Chris@0
|
49 try {
|
Chris@0
|
50 $source_plugin = $vocabulary_migration->getSourcePlugin();
|
Chris@0
|
51 if ($source_plugin instanceof RequirementsInterface) {
|
Chris@0
|
52 $source_plugin->checkRequirements();
|
Chris@0
|
53 }
|
Chris@0
|
54 $executable = new MigrateExecutable($vocabulary_migration);
|
Chris@0
|
55 $process = ['vid' => $definitions['d6_taxonomy_vocabulary']['process']['vid']];
|
Chris@0
|
56 foreach ($source_plugin as $row) {
|
Chris@0
|
57 $executable->processRow($row, $process);
|
Chris@0
|
58 $source_vid = $row->getSourceProperty('vid');
|
Chris@0
|
59 $plugin_ids = ['d6_term_node:' . $source_vid, 'd6_term_node_revision:' . $source_vid];
|
Chris@0
|
60 foreach ($plugin_ids as $plugin_id) {
|
Chris@0
|
61 // Match the field name derivation in d6_vocabulary_field.yml.
|
Chris@0
|
62 $field_name = substr('field_' . $row->getDestinationProperty('vid'), 0, 32);
|
Chris@0
|
63
|
Chris@0
|
64 // The Forum module is expecting 'taxonomy_forums' as the field name
|
Chris@0
|
65 // for the forum nodes. The 'forum_vocabulary' source property is
|
Chris@0
|
66 // evaluated in Drupal\taxonomy\Plugin\migrate\source\d6\Vocabulary
|
Chris@0
|
67 // and is set to true if the vocabulary vid being migrated is the
|
Chris@0
|
68 // same as the one in the 'forum_nav_vocabulary' variable on the
|
Chris@0
|
69 // source site.
|
Chris@0
|
70 $destination_vid = $row->getSourceProperty('forum_vocabulary') ? 'taxonomy_forums' : $field_name;
|
Chris@0
|
71 $definitions[$plugin_id]['process'][$destination_vid] = 'tid';
|
Chris@0
|
72 }
|
Chris@0
|
73 }
|
Chris@0
|
74 }
|
Chris@0
|
75 catch (RequirementsException $e) {
|
Chris@0
|
76 // This code currently runs whenever the definitions are being loaded and
|
Chris@0
|
77 // if you have a Drupal 7 source site then the requirements will not be
|
Chris@0
|
78 // met for the d6_taxonomy_vocabulary migration.
|
Chris@0
|
79 }
|
Chris@0
|
80 catch (DatabaseExceptionWrapper $e) {
|
Chris@0
|
81 // When the definitions are loaded it is possible the tables will not
|
Chris@0
|
82 // exist.
|
Chris@0
|
83 }
|
Chris@0
|
84
|
Chris@0
|
85 }
|
Chris@0
|
86 }
|