Version 1
[yaffs-website] / web / modules / contrib / migrate_plus / migrate_example_advanced / migrate_example_advanced.install
1 <?php
2
3 /**
4  * @file
5  * Install, update and uninstall functions for the migrate_example_advanced module.
6  */
7
8 use Drupal\migrate_plus\Entity\Migration;
9
10 /**
11  * Implements hook_install().
12  */
13 function migrate_example_advanced_install() {
14   // We need the urls to be absolute for the XML source plugin to read them, but
15   // the static configuration files on disk can't know the server and port to
16   // use. So, in the .yml files we provide the REST resources relative to the
17   // site root and here rewrite them to fully-qualified paths.
18
19   /** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_role_xml_migration */
20   $wine_role_xml_migration = Migration::load('wine_role_xml');
21   if ($wine_role_xml_migration) {
22     $source = $wine_role_xml_migration->get('source');
23     $request = \Drupal::request();
24     $source['urls'] = 'http://' . $request->getHttpHost() . $source['urls'];
25     $wine_role_xml_migration->set('source', $source);
26     $wine_role_xml_migration->save();
27   }
28   /** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_role_json_migration */
29   $wine_role_json_migration = Migration::load('wine_role_json');
30   if ($wine_role_json_migration) {
31     $source = $wine_role_json_migration->get('source');
32     $request = \Drupal::request();
33     $source['urls'] = 'http://' . $request->getHttpHost() . $source['urls'];
34     $wine_role_json_migration->set('source', $source);
35     $wine_role_json_migration->save();
36   }
37   /** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_variety_multi_xml_migration */
38   $wine_variety_multi_xml_migration = Migration::load('wine_variety_multi_xml');
39   if ($wine_variety_multi_xml_migration) {
40     $source = $wine_variety_multi_xml_migration->get('source');
41     $request = \Drupal::request();
42     $urls = [];
43     foreach ($source['urls'] as $url) {
44       $urls[] = 'http://' . $request->getHttpHost() . $url;
45     }
46     $source['urls'] = $urls;
47     $wine_variety_multi_xml_migration->set('source', $source);
48     $wine_variety_multi_xml_migration->save();
49   }
50 }