migrate_example_advanced.install 1.96 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Install, update and uninstall functions for migrate_example_advanced module.
6 7
 */

8
use Drupal\migrate_plus\Entity\Migration;
9 10 11

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