migrate_example.migrate.inc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. /**
  3. * @file
  4. * Because the name of this file is the module name plus '.migrate.inc', when
  5. * hook_migrate_api is invoked by the Migrate module this file is automatically
  6. * loaded - thus, you don't need to implement your hook in the .module file.
  7. */
  8. /*
  9. * You must implement hook_migrate_api(), setting the API level to 2, if you are
  10. * implementing any migration classes. If your migration application is static -
  11. * that is, you know at implementation time exactly what migrations must be
  12. * instantiated - then you should register your migrations here. If your
  13. * application is more dynamic (for example, if selections in the UI determine
  14. * exactly what migrations need to be instantiated), then you would register
  15. * your migrations using registerMigration() - see migrate_example_baseball for
  16. * more information.
  17. */
  18. function migrate_example_migrate_api() {
  19. // Usually field mappings are established by code in the migration constructor -
  20. // a call to addFieldMapping(). They may also be passed as arguments when
  21. // registering a migration - in this case, they are stored in the database
  22. // and override any mappings for the same field in the code. To do this,
  23. // construct the field mapping object and configure it similarly to when
  24. // you call addFieldMapping, and pass your mappings as an array below.
  25. $translate_mapping = new MigrateFieldMapping('translate', NULL);
  26. $translate_mapping->defaultValue(0);
  27. $ignore_mapping = new MigrateFieldMapping('migrate_example_beer_styles:ignore_case', NULL);
  28. $ignore_mapping->defaultValue(1);
  29. $api = array(
  30. // Required - tells the Migrate module that you are implementing version 2
  31. // of the Migrate API.
  32. 'api' => 2,
  33. // Migrations can be organized into groups. The key used here will be the
  34. // machine name of the group, which can be used in Drush:
  35. // drush migrate-import --group=wine
  36. // The title is a required argument which is displayed for the group in the
  37. // UI. You may also have additional arguments for any other data which is
  38. // common to all migrations in the group.
  39. 'groups' => array(
  40. 'beer' => array(
  41. 'title' => t('Beer Imports'),
  42. ),
  43. 'wine' => array(
  44. 'title' => t('Wine Imports'),
  45. ),
  46. ),
  47. // Here we register the individual migrations. The keys (BeerTerm, BeerUser,
  48. // etc.) are the machine names of the migrations, and the class_name
  49. // argument is required. The group_name is optional (defaulting to 'default')
  50. // but specifying it is a best practice.
  51. 'migrations' => array(
  52. 'BeerTerm' => array(
  53. 'class_name' => 'BeerTermMigration',
  54. 'group_name' => 'beer',
  55. ),
  56. 'BeerUser' => array(
  57. 'class_name' => 'BeerUserMigration',
  58. 'group_name' => 'beer',
  59. ),
  60. 'BeerNode' => array(
  61. 'class_name' => 'BeerNodeMigration',
  62. 'group_name' => 'beer',
  63. // You may optionally declare dependencies for your migration - other
  64. // migrations which should run first. In this case, terms assigned to our
  65. // nodes and the authors of the nodes should be migrated before the nodes
  66. // themselves.
  67. 'dependencies' => array(
  68. 'BeerTerm',
  69. 'BeerUser',
  70. ),
  71. // Here is where we add field mappings which may override those
  72. // specified in the group constructor.
  73. 'field_mappings' => array(
  74. $translate_mapping,
  75. $ignore_mapping,
  76. ),
  77. ),
  78. 'BeerComment' => array(
  79. 'class_name' => 'BeerCommentMigration',
  80. 'group_name' => 'beer',
  81. 'dependencies' => array(
  82. 'BeerUser',
  83. 'BeerNode',
  84. ),
  85. ),
  86. 'WinePrep' => array(
  87. 'class_name' => 'WinePrepMigration',
  88. 'group_name' => 'wine',
  89. ),
  90. 'WineVariety' => array(
  91. 'class_name' => 'WineVarietyMigration',
  92. 'group_name' => 'wine',
  93. ),
  94. 'WineRegion' => array(
  95. 'class_name' => 'WineRegionMigration',
  96. 'group_name' => 'wine',
  97. ),
  98. 'WineBestWith' => array(
  99. 'class_name' => 'WineBestWithMigration',
  100. 'group_name' => 'wine',
  101. ),
  102. 'WineFileCopy' => array(
  103. 'class_name' => 'WineFileCopyMigration',
  104. 'group_name' => 'wine',
  105. 'dependencies' => array('WinePrep'),
  106. ),
  107. 'WineFileBlob' => array(
  108. 'class_name' => 'WineFileBlobMigration',
  109. 'group_name' => 'wine',
  110. 'dependencies' => array('WinePrep'),
  111. ),
  112. 'WineRole' => array(
  113. 'class_name' => 'WineRoleMigration',
  114. 'group_name' => 'wine',
  115. // TIP: Regular dependencies, besides enforcing (in the absence of
  116. // --force) the run order of migrations, affect the sorting of
  117. // migrations on display. You can use soft dependencies to affect just
  118. // the display order when the migrations aren't technically required to
  119. // run in a certain order. In this case, we want the role migration to
  120. // appear after the file migrations.
  121. 'soft_dependencies' => array('WineFileCopy'),
  122. ),
  123. 'WineUser' => array(
  124. 'class_name' => 'WineUserMigration',
  125. 'group_name' => 'wine',
  126. 'dependencies' => array(
  127. 'WineFileCopy',
  128. 'WineRole',
  129. ),
  130. ),
  131. 'WineProducer' => array(
  132. 'class_name' => 'WineProducerMigration',
  133. 'group_name' => 'wine',
  134. 'dependencies' => array(
  135. 'WineRegion',
  136. 'WineUser',
  137. ),
  138. ),
  139. 'WineProducerXML' => array(
  140. 'class_name' => 'WineProducerXMLMigration',
  141. 'group_name' => 'wine',
  142. 'dependencies' => array(
  143. 'WineRegion',
  144. 'WineUser',
  145. ),
  146. ),
  147. 'WineProducerNamespaceXML' => array(
  148. 'class_name' => 'WineProducerNamespaceXMLMigration',
  149. 'group_name' => 'wine',
  150. 'dependencies' => array(
  151. 'WineRegion',
  152. 'WineUser',
  153. ),
  154. ),
  155. 'WineProducerMultiXML' => array(
  156. 'class_name' => 'WineProducerMultiXMLMigration',
  157. 'group_name' => 'wine',
  158. 'dependencies' => array(
  159. 'WineRegion',
  160. 'WineUser',
  161. ),
  162. ),
  163. 'WineProducerMultiNamespaceXML' => array(
  164. 'class_name' => 'WineProducerMultiNamespaceXMLMigration',
  165. 'group_name' => 'wine',
  166. 'dependencies' => array(
  167. 'WineRegion',
  168. 'WineUser',
  169. ),
  170. ),
  171. 'WineProducerXMLPull' => array(
  172. 'class_name' => 'WineProducerXMLPullMigration',
  173. 'group_name' => 'wine',
  174. 'dependencies' => array(
  175. 'WineRegion',
  176. 'WineUser',
  177. ),
  178. ),
  179. 'WineProducerNamespaceXMLPull' => array(
  180. 'class_name' => 'WineProducerNamespaceXMLPullMigration',
  181. 'group_name' => 'wine',
  182. 'dependencies' => array(
  183. 'WineRegion',
  184. 'WineUser',
  185. ),
  186. ),
  187. 'WineWine' => array(
  188. 'class_name' => 'WineWineMigration',
  189. 'group_name' => 'wine',
  190. 'dependencies' => array(
  191. 'WineRegion',
  192. 'WineVariety',
  193. 'WineBestWith',
  194. 'WineUser',
  195. 'WineProducer',
  196. ),
  197. ),
  198. 'WineComment' => array(
  199. 'class_name' => 'WineCommentMigration',
  200. 'group_name' => 'wine',
  201. 'dependencies' => array(
  202. 'WineUser',
  203. 'WineWine',
  204. ),
  205. ),
  206. 'WineTable' => array(
  207. 'class_name' => 'WineTableMigration',
  208. 'group_name' => 'wine',
  209. 'soft_dependencies' => array('WineComment'),
  210. ),
  211. 'WineFinish' => array(
  212. 'class_name' => 'WineFinishMigration',
  213. 'group_name' => 'wine',
  214. 'dependencies' => array('WineComment'),
  215. ),
  216. 'WineUpdates' => array(
  217. 'class_name' => 'WineUpdatesMigration',
  218. 'group_name' => 'wine',
  219. 'dependencies' => array('WineWine'),
  220. 'soft_dependencies' => array('WineFinish'),
  221. ),
  222. 'WineCommentUpdates' => array(
  223. 'class_name' => 'WineCommentUpdatesMigration',
  224. 'group_name' => 'wine',
  225. 'dependencies' => array('WineComment'),
  226. 'soft_dependencies' => array('WineUpdates'),
  227. ),
  228. 'WineVarietyUpdates' => array(
  229. 'class_name' => 'WineVarietyUpdatesMigration',
  230. 'group_name' => 'wine',
  231. 'dependencies' => array('WineVariety'),
  232. 'soft_dependencies' => array('WineUpdates'),
  233. ),
  234. 'WineUserUpdates' => array(
  235. 'class_name' => 'WineUserUpdatesMigration',
  236. 'group_name' => 'wine',
  237. 'dependencies' => array('WineUser'),
  238. 'soft_dependencies' => array('WineUpdates'),
  239. ),
  240. ),
  241. );
  242. return $api;
  243. }