You are here

function migrate_example_advanced_install in Migrate Plus 8.5

Same name and namespace in other branches
  1. 8 migrate_example_advanced/migrate_example_advanced.install \migrate_example_advanced_install()
  2. 8.2 migrate_example_advanced/migrate_example_advanced.install \migrate_example_advanced_install()
  3. 8.3 migrate_example_advanced/migrate_example_advanced.install \migrate_example_advanced_install()
  4. 8.4 migrate_example_advanced/migrate_example_advanced.install \migrate_example_advanced_install()

Implements hook_install().

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.

File

migrate_example_advanced/migrate_example_advanced.install, line 18
Install, update and uninstall functions for migrate_example_advanced module.

Code

function migrate_example_advanced_install() {

  /** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_role_xml_migration */
  $wine_role_xml_migration = Migration::load('wine_role_xml');
  if ($wine_role_xml_migration) {
    $source = $wine_role_xml_migration
      ->get('source');
    $request = \Drupal::request();
    $urls = [];
    foreach ($source['urls'] as $url) {
      $urls[] = 'http://' . $request
        ->getHttpHost() . $url;
    }
    $source['urls'] = $urls;
    $wine_role_xml_migration
      ->set('source', $source);
    $wine_role_xml_migration
      ->save();
  }

  /** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_role_json_migration */
  $wine_role_json_migration = Migration::load('wine_role_json');
  if ($wine_role_json_migration) {
    $source = $wine_role_json_migration
      ->get('source');
    $request = \Drupal::request();
    $urls = [];
    foreach ($source['urls'] as $url) {
      $urls[] = 'http://' . $request
        ->getHttpHost() . $url;
    }
    $source['urls'] = $urls;
    $wine_role_json_migration
      ->set('source', $source);
    $wine_role_json_migration
      ->save();
  }

  /** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_variety_multi_xml_migration */
  $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();
  }
}