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