Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / migrate_drupal / migrate_drupal.module
1 <?php
2
3 /**
4  * @file
5  * Provides migration from other Drupal sites.
6  */
7
8 use Drupal\Core\Database\DatabaseExceptionWrapper;
9 use Drupal\Core\Routing\RouteMatchInterface;
10 use Drupal\migrate\Exception\RequirementsException;
11 use Drupal\migrate\MigrateExecutable;
12 use Drupal\migrate\MigrateMessage;
13 use Drupal\migrate\Plugin\RequirementsInterface;
14
15 /**
16  * Implements hook_help().
17  */
18 function migrate_drupal_help($route_name, RouteMatchInterface $route_match) {
19   switch ($route_name) {
20     case 'help.page.migrate_drupal':
21       $output = '';
22       $output .= '<h3>' . t('About') . '</h3>';
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' => \Drupal::url('help.page', ['name' => 'migrate']), ':migrate_drupal' => 'https://www.drupal.org/documentation/modules/migrate_drupal']) . '</p>';
24       return $output;
25   }
26 }
27
28 /**
29  * Implements hook_migration_plugins_alter().
30  */
31 function migrate_drupal_migration_plugins_alter(&$definitions) {
32   // This is why the deriver can't do this: the 'd6_taxonomy_vocabulary'
33   // definition is not available to the deriver as it is running inside
34   // getDefinitions().
35   if (isset($definitions['d6_taxonomy_vocabulary'])) {
36     $vocabulary_migration_definition = [
37       'source' => [
38         'ignore_map' => TRUE,
39         'plugin' => 'd6_taxonomy_vocabulary',
40       ],
41       'destination' => [
42         'plugin' => 'null',
43       ],
44     ];
45     $vocabulary_migration = \Drupal::service('plugin.manager.migration')->createStubMigration($vocabulary_migration_definition);
46
47     try {
48       $source_plugin = $vocabulary_migration->getSourcePlugin();
49       if ($source_plugin instanceof RequirementsInterface) {
50         $source_plugin->checkRequirements();
51       }
52       $executable = new MigrateExecutable($vocabulary_migration, new MigrateMessage());
53       $process = ['vid' => $definitions['d6_taxonomy_vocabulary']['process']['vid']];
54       foreach ($source_plugin as $row) {
55         $executable->processRow($row, $process);
56         $source_vid = $row->getSourceProperty('vid');
57         $plugin_ids = ['d6_term_node:' . $source_vid, 'd6_term_node_revision:' . $source_vid];
58         foreach ($plugin_ids as $plugin_id) {
59           if (isset($definitions[$plugin_id])) {
60             $definitions[$plugin_id]['process'][$row->getDestinationProperty('vid')] = 'tid';
61           }
62         }
63       }
64     }
65     catch (RequirementsException $e) {
66       // This code currently runs whenever the definitions are being loaded and
67       // if you have a Drupal 7 source site then the requirements will not be
68       // met for the d6_taxonomy_vocabulary migration.
69     }
70     catch (DatabaseExceptionWrapper $e) {
71       // When the definitions are loaded it is possible the tables will not
72       // exist.
73     }
74
75   }
76 }