migrate_example_advanced.install 2.0 KB

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