migrate.api.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @file
  4. * Documentation for hooks defined by Migrate.
  5. */
  6. /**
  7. * Registers your module as an implementor of Migrate-based classes and provides
  8. * default configuration for migration processes.
  9. *
  10. * @return
  11. * An associative array with the following keys (of which only 'api' is
  12. * required):
  13. * - api: Always 2 for any module implementing the Migrate 2 API.
  14. * - groups: An associative array, keyed by group machine name, defining one
  15. * or more migration groups. Each value is an associative array - the 'title'
  16. * key defines a user-visible name for the group; any other values are
  17. * passed as arguments to all migrations in the group.
  18. * - migrations: An associative array, keyed by migration machine name,
  19. * defining one or more migrations. Each value is an associative array - any
  20. * keys other than the following are passed as arguments to the migration
  21. * constructor:
  22. * - class_name (required): The name of the class implementing the migration.
  23. * - group_name: The machine name of the group containing the migration.
  24. * - disable_hooks: An associative array, keyed by hook name, listing hook
  25. * implementations to be disabled during migration. Each value is an
  26. * array of module names whose implementations of the hook in the key is
  27. * to be disabled.
  28. * - destination handlers: An array of classes implementing destination
  29. * handlers.
  30. * - field handlers: An array of classes implementing field handlers.
  31. * - wizard classes: An array of classes that provide Migrate UI wizards.
  32. * - wizard extenders: An array of classes that extend Migrate UI wizards.
  33. * Keys are the wizard classes, values are arrays of extender classes.
  34. *
  35. * See system_hook_info() for all hook groups defined by Drupal core.
  36. *
  37. * @see hook_migrate_api_alter().
  38. */
  39. function hook_migrate_api() {
  40. $api = array(
  41. 'api' => 2,
  42. 'groups' => array(
  43. 'legacy' => array(
  44. 'title' => t('Import from legacy system'),
  45. // Default format for all content migrations
  46. 'default_format' => 'filtered_html',
  47. ),
  48. ),
  49. 'migrations' => array(
  50. 'ExampleUser' => array(
  51. 'class_name' => 'ExampleUserMigration',
  52. 'group_name' => 'legacy',
  53. 'default_role' => 'member', // Added to constructor $arguments
  54. ),
  55. 'ExampleNode' => array(
  56. 'class_name' => 'ExampleNodeMigration',
  57. 'group_name' => 'legacy',
  58. 'default_uid' => 1, // Added to constructor $arguments
  59. 'disable_hooks' => array(
  60. // Improve migration performance, and prevent accidental emails.
  61. 'node_insert' => array(
  62. 'expensive_module',
  63. 'email_notification_module',
  64. ),
  65. 'node_update' => array(
  66. 'expensive_module',
  67. 'email_notification_module',
  68. ),
  69. ),
  70. ),
  71. ),
  72. );
  73. return $api;
  74. }
  75. /**
  76. * Alter information from all implementations of hook_migrate_api().
  77. *
  78. * @param array $info
  79. * An array of results from hook_migrate_api(), keyed by module name.
  80. *
  81. * @see hook_migrate_api().
  82. */
  83. function hook_migrate_api_alter(array &$info) {
  84. // Override the class for another module's migration - say, to add some
  85. // additional preprocessing in prepareRow().
  86. if (isset($info['MODULE_NAME']['migrations']['ExampleNode'])) {
  87. $info['MODULE_NAME']['migrations']['ExampleNode']['class_name'] = 'MyBetterExampleNodeMigration';
  88. }
  89. }
  90. /**
  91. * Provides text to be displayed at the top of the dashboard page (migrate_ui).
  92. *
  93. * @return
  94. * Translated text for display on the dashboard page.
  95. */
  96. function hook_migrate_overview() {
  97. return t('<p>Listed below are all the migration processes defined for migration
  98. of our old site to Drupal. Open issues applying to specific migrations
  99. can be viewed by clicking the migration name. Also, details on how each
  100. migration will behave when incrementally migrated are provided.</p>
  101. <p><a href="http://issuetracker.example.com/?project=migration&status=open">Open migration tickets</a></p>');
  102. }