migrate_example_advanced_setup.install 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. <?php
  2. use Drupal\user\RoleInterface;
  3. /**
  4. * @file
  5. * Set up source data and destination configuration for the migration example
  6. * module. We do this in a separate module so migrate_example_advanced itself is
  7. * a pure migration module.
  8. */
  9. /**
  10. * Implements hook_schema().
  11. */
  12. function migrate_example_advanced_setup_schema() {
  13. $schema['migrate_example_advanced_account'] = migrate_example_advanced_schema_account();
  14. $schema['migrate_example_advanced_account_updates'] = migrate_example_advanced_schema_account_updates();
  15. $schema['migrate_example_advanced_categories'] = migrate_example_advanced_schema_categories();
  16. $schema['migrate_example_advanced_vintages'] = migrate_example_advanced_schema_vintages();
  17. $schema['migrate_example_advanced_variety_updates'] = migrate_example_advanced_schema_variety_updates();
  18. $schema['migrate_example_wine'] = migrate_example_advanced_schema_wine();
  19. $schema['migrate_example_advanced_updates'] = migrate_example_advanced_schema_updates();
  20. $schema['migrate_example_advanced_producer'] = migrate_example_advanced_schema_producer();
  21. $schema['migrate_example_advanced_category_wine'] = migrate_example_advanced_schema_category_wine();
  22. $schema['migrate_example_advanced_category_producer'] = migrate_example_advanced_schema_category_producer();
  23. $schema['migrate_example_advanced_comment'] = migrate_example_advanced_schema_comment();
  24. $schema['migrate_example_advanced_comment_updates'] = migrate_example_advanced_schema_comment_updates();
  25. $schema['migrate_example_advanced_files'] = migrate_example_advanced_schema_files();
  26. $schema['migrate_example_advanced_blobs'] = migrate_example_advanced_schema_blobs();
  27. $schema['migrate_example_advanced_table_source'] = migrate_example_advanced_schema_table_source();
  28. $schema['migrate_example_advanced_table_dest'] = migrate_example_advanced_schema_table_dest();
  29. return $schema;
  30. }
  31. /**
  32. * Implements hook_install().
  33. */
  34. function migrate_example_advanced_setup_install() {
  35. // Populate our tables.
  36. migrate_example_advanced_data_account();
  37. migrate_example_advanced_data_account_updates();
  38. migrate_example_advanced_data_categories();
  39. migrate_example_advanced_data_vintages();
  40. migrate_example_advanced_data_variety_updates();
  41. migrate_example_advanced_data_wine();
  42. migrate_example_advanced_data_updates();
  43. migrate_example_advanced_data_producer();
  44. migrate_example_advanced_data_category_wine();
  45. migrate_example_advanced_data_category_producer();
  46. migrate_example_advanced_data_comment();
  47. migrate_example_advanced_data_comment_updates();
  48. migrate_example_advanced_data_files();
  49. migrate_example_advanced_data_blobs();
  50. migrate_example_advanced_data_table_source();
  51. }
  52. function migrate_example_advanced_schema_wine() {
  53. return [
  54. 'description' => 'Wines of the world',
  55. 'fields' => [
  56. 'wineid' => [
  57. 'type' => 'int',
  58. 'unsigned' => TRUE,
  59. 'not null' => TRUE,
  60. 'description' => 'Wine ID',
  61. ],
  62. 'name' => [
  63. 'type' => 'varchar',
  64. 'length' => 255,
  65. 'not null' => TRUE,
  66. ],
  67. 'body' => [
  68. 'type' => 'varchar',
  69. 'length' => 255,
  70. 'not null' => FALSE,
  71. 'description' => 'Full description of the wine.',
  72. ],
  73. 'excerpt' => [
  74. 'type' => 'varchar',
  75. 'length' => 255,
  76. 'not null' => FALSE,
  77. 'description' => 'Abstract for this wine.',
  78. ],
  79. 'accountid' => [
  80. 'type' => 'int',
  81. 'unsigned' => TRUE,
  82. 'not null' => FALSE,
  83. 'description' => 'ID of the author.',
  84. ],
  85. 'posted' => [
  86. 'type' => 'int',
  87. 'unsigned' => TRUE,
  88. 'not null' => TRUE,
  89. 'description' => 'Original creation date',
  90. ],
  91. 'last_changed' => [
  92. 'type' => 'int',
  93. 'unsigned' => TRUE,
  94. 'not null' => TRUE,
  95. 'description' => 'Last change date',
  96. ],
  97. 'variety' => [
  98. 'type' => 'int',
  99. 'unsigned' => TRUE,
  100. 'not null' => TRUE,
  101. 'description' => 'Wine variety',
  102. ],
  103. 'region' => [
  104. 'type' => 'int',
  105. 'unsigned' => TRUE,
  106. 'not null' => TRUE,
  107. 'description' => 'Wine region',
  108. ],
  109. 'rating' => [
  110. 'type' => 'int',
  111. 'unsigned' => TRUE,
  112. 'not null' => FALSE,
  113. 'description' => 'Rating (100-point scale)',
  114. ],
  115. ],
  116. 'primary key' => ['wineid'],
  117. ];
  118. }
  119. function migrate_example_advanced_schema_updates() {
  120. return array(
  121. 'description' => 'Updated wine ratings',
  122. 'fields' => [
  123. 'wineid' => [
  124. 'type' => 'int',
  125. 'unsigned' => TRUE,
  126. 'not null' => TRUE,
  127. 'description' => 'Wine ID',
  128. ],
  129. 'rating' => [
  130. 'type' => 'int',
  131. 'unsigned' => TRUE,
  132. 'not null' => FALSE,
  133. 'description' => 'Rating (100-point scale)',
  134. ],
  135. ],
  136. 'primary key' => ['wineid'],
  137. );
  138. }
  139. function migrate_example_advanced_schema_producer() {
  140. return array(
  141. 'description' => 'Wine producers of the world',
  142. 'fields' => array(
  143. 'producerid' => array(
  144. 'type' => 'int',
  145. 'unsigned' => TRUE,
  146. 'not null' => TRUE,
  147. 'description' => 'Producer ID',
  148. ),
  149. 'name' => array(
  150. 'type' => 'varchar',
  151. 'length' => 255,
  152. 'not null' => TRUE,
  153. ),
  154. 'body' => array(
  155. 'type' => 'varchar',
  156. 'length' => 255,
  157. 'not null' => FALSE,
  158. 'description' => 'Full description of the producer.',
  159. ),
  160. 'excerpt' => array(
  161. 'type' => 'varchar',
  162. 'length' => 255,
  163. 'not null' => FALSE,
  164. 'description' => 'Abstract for this producer.',
  165. ),
  166. 'accountid' => array(
  167. 'type' => 'int',
  168. 'unsigned' => TRUE,
  169. 'not null' => FALSE,
  170. 'description' => 'Account ID of the author.',
  171. ),
  172. ),
  173. 'primary key' => array('producerid'),
  174. );
  175. }
  176. function migrate_example_advanced_schema_categories() {
  177. return array(
  178. 'description' => 'Categories',
  179. 'fields' => array(
  180. 'categoryid' => array(
  181. 'type' => 'int',
  182. 'not null' => TRUE,
  183. 'unsigned' => TRUE,
  184. 'description' => 'Category ID',
  185. ),
  186. 'type' => array(
  187. 'type' => 'varchar',
  188. 'length' => 255,
  189. 'not null' => TRUE,
  190. 'description' => 'Type of category: variety, region, best_with',
  191. ),
  192. 'name' => array(
  193. 'type' => 'varchar',
  194. 'length' => 255,
  195. 'not null' => TRUE,
  196. ),
  197. 'details' => array(
  198. 'type' => 'varchar',
  199. 'length' => 255,
  200. 'not null' => FALSE,
  201. ),
  202. 'category_parent' => array(
  203. 'type' => 'int',
  204. 'unsigned' => TRUE,
  205. 'not null' => FALSE,
  206. 'description' => 'Parent category, if any',
  207. ),
  208. 'ordering' => array(
  209. 'type' => 'int',
  210. 'unsigned' => FALSE,
  211. 'not null' => FALSE,
  212. 'description' => 'Order in which to display categories',
  213. ),
  214. ),
  215. 'primary key' => array('categoryid'),
  216. );
  217. }
  218. function migrate_example_advanced_schema_vintages() {
  219. return array(
  220. 'description' => 'Wine vintages',
  221. 'fields' => array(
  222. 'wineid' => array(
  223. 'type' => 'int',
  224. 'not null' => TRUE,
  225. 'description' => 'Wine ID',
  226. ),
  227. 'vintage' => array(
  228. 'type' => 'int',
  229. 'unsigned' => TRUE,
  230. 'not null' => TRUE,
  231. 'description' => 'Vintage (year)',
  232. ),
  233. ),
  234. 'primary key' => array('wineid', 'vintage'),
  235. );
  236. }
  237. function migrate_example_advanced_schema_variety_updates() {
  238. return array(
  239. 'description' => 'Variety updates',
  240. 'fields' => array(
  241. 'categoryid' => array(
  242. 'type' => 'int',
  243. 'not null' => TRUE,
  244. 'unsigned' => TRUE,
  245. 'description' => 'Category ID',
  246. ),
  247. 'details' => array(
  248. 'type' => 'varchar',
  249. 'length' => 255,
  250. 'not null' => FALSE,
  251. ),
  252. ),
  253. 'primary key' => array('categoryid'),
  254. );
  255. }
  256. function migrate_example_advanced_schema_category_wine() {
  257. return array(
  258. 'description' => 'Wine category assignments',
  259. 'fields' => array(
  260. 'wineid' => array(
  261. 'type' => 'int',
  262. 'not null' => TRUE,
  263. 'description' => 'Wine ID',
  264. ),
  265. 'categoryid' => array(
  266. 'type' => 'int',
  267. 'unsigned' => TRUE,
  268. 'not null' => TRUE,
  269. 'description' => 'Category ID',
  270. ),
  271. ),
  272. 'primary key' => array('categoryid', 'wineid'),
  273. );
  274. }
  275. function migrate_example_advanced_schema_category_producer() {
  276. return array(
  277. 'description' => 'Producer category assignments',
  278. 'fields' => array(
  279. 'producerid' => array(
  280. 'type' => 'int',
  281. 'not null' => TRUE,
  282. 'description' => 'Producer ID',
  283. ),
  284. 'categoryid' => array(
  285. 'type' => 'int',
  286. 'unsigned' => TRUE,
  287. 'not null' => TRUE,
  288. 'description' => 'Category ID',
  289. ),
  290. ),
  291. 'primary key' => array('categoryid', 'producerid'),
  292. );
  293. }
  294. function migrate_example_advanced_schema_comment() {
  295. return array(
  296. 'description' => 'Wine comments',
  297. 'fields' => array(
  298. 'commentid' => array(
  299. 'type' => 'int',
  300. 'unsigned' => TRUE,
  301. 'not null' => TRUE,
  302. 'description' => 'Comment ID',
  303. ),
  304. 'wineid' => array(
  305. 'type' => 'int',
  306. 'unsigned' => TRUE,
  307. 'not null' => TRUE,
  308. 'description' => 'Wine ID that is being commented upon',
  309. ),
  310. 'comment_parent' => array(
  311. 'type' => 'int',
  312. 'unsigned' => TRUE,
  313. 'not null' => FALSE,
  314. 'description' => 'Parent comment ID in case of comment replies.',
  315. ),
  316. 'subject' => array(
  317. 'type' => 'varchar',
  318. 'length' => 255,
  319. 'not null' => FALSE,
  320. 'description' => 'Comment subject',
  321. ),
  322. 'body' => array(
  323. 'type' => 'varchar',
  324. 'length' => 255,
  325. 'not null' => FALSE,
  326. 'description' => 'Comment body',
  327. ),
  328. 'name' => array(
  329. 'type' => 'varchar',
  330. 'length' => 255,
  331. 'not null' => FALSE,
  332. 'description' => 'Comment name (if anon)',
  333. ),
  334. 'mail' => array(
  335. 'type' => 'varchar',
  336. 'length' => 255,
  337. 'not null' => FALSE,
  338. 'description' => 'Comment email (if anon)',
  339. ),
  340. 'accountid' => array(
  341. 'type' => 'int',
  342. 'unsigned' => TRUE,
  343. 'not null' => FALSE,
  344. 'description' => 'Account ID (if any).',
  345. ),
  346. 'commenthost' => array(
  347. 'type' => 'varchar',
  348. 'length' => 255,
  349. 'not null' => FALSE,
  350. 'description' => 'IP/domain of host posted from',
  351. ),
  352. 'userpage' => array(
  353. 'type' => 'varchar',
  354. 'length' => 255,
  355. 'not null' => FALSE,
  356. 'description' => 'User homepage',
  357. ),
  358. 'posted' => array(
  359. 'type' => 'int',
  360. 'unsigned' => TRUE,
  361. 'not null' => TRUE,
  362. 'description' => 'Date comment posted',
  363. ),
  364. 'lastchanged' => array(
  365. 'type' => 'int',
  366. 'unsigned' => TRUE,
  367. 'not null' => TRUE,
  368. 'description' => 'Date comment last changed',
  369. ),
  370. ),
  371. 'primary key' => array('commentid'),
  372. );
  373. }
  374. function migrate_example_advanced_schema_comment_updates() {
  375. return array(
  376. 'description' => 'Wine comment updates',
  377. 'fields' => array(
  378. 'commentid' => array(
  379. 'type' => 'int',
  380. 'unsigned' => TRUE,
  381. 'not null' => TRUE,
  382. 'description' => 'Comment ID',
  383. ),
  384. 'subject' => array(
  385. 'type' => 'varchar',
  386. 'length' => 255,
  387. 'not null' => FALSE,
  388. 'description' => 'Comment subject',
  389. ),
  390. ),
  391. 'primary key' => array('commentid'),
  392. );
  393. }
  394. function migrate_example_advanced_schema_account() {
  395. return array(
  396. 'description' => 'Wine accounts.',
  397. 'fields' => array(
  398. 'accountid' => array(
  399. 'type' => 'serial',
  400. 'not null' => TRUE,
  401. 'description' => 'Account ID',
  402. ),
  403. 'status' => array(
  404. 'type' => 'int',
  405. 'not null' => TRUE,
  406. 'description' => 'Blocked_Allowed',
  407. ),
  408. 'posted' => array(
  409. 'type' => 'varchar',
  410. 'length' => 255,
  411. 'not null' => TRUE,
  412. 'description' => 'Registration date',
  413. ),
  414. 'last_access' => array(
  415. 'type' => 'varchar',
  416. 'length' => 255,
  417. 'not null' => TRUE,
  418. 'description' => 'Last access date',
  419. ),
  420. 'last_login' => array(
  421. 'type' => 'varchar',
  422. 'length' => 255,
  423. 'not null' => TRUE,
  424. 'description' => 'Last login date',
  425. ),
  426. 'name' => array(
  427. 'type' => 'varchar',
  428. 'length' => 255,
  429. 'not null' => FALSE,
  430. 'description' => 'Account name (for login)',
  431. ),
  432. 'sex' => array(
  433. 'type' => 'char',
  434. 'length' => 1,
  435. 'not null' => FALSE,
  436. 'description' => 'Gender',
  437. ),
  438. 'password' => array(
  439. 'type' => 'varchar',
  440. 'length' => 255,
  441. 'not null' => FALSE,
  442. 'description' => 'Account password (raw)',
  443. ),
  444. 'mail' => array(
  445. 'type' => 'varchar',
  446. 'length' => 255,
  447. 'not null' => FALSE,
  448. 'description' => 'Account email',
  449. ),
  450. 'original_mail' => array(
  451. 'type' => 'varchar',
  452. 'length' => 255,
  453. 'not null' => FALSE,
  454. 'description' => 'Original account email',
  455. ),
  456. 'sig' => array(
  457. 'type' => 'varchar',
  458. 'length' => 255,
  459. 'not null' => TRUE,
  460. 'description' => 'Signature for comments',
  461. ),
  462. 'imageid' => array(
  463. 'type' => 'int',
  464. 'unsigned' => TRUE,
  465. 'not null' => FALSE,
  466. 'description' => 'Image ID',
  467. ),
  468. 'positions' => array(
  469. 'type' => 'varchar',
  470. 'length' => 255,
  471. 'not null' => FALSE,
  472. 'description' => 'Positions held',
  473. ),
  474. ),
  475. 'primary key' => array('accountid'),
  476. );
  477. }
  478. function migrate_example_advanced_schema_account_updates() {
  479. return array(
  480. 'description' => 'Wine account updates',
  481. 'fields' => array(
  482. 'accountid' => array(
  483. 'type' => 'serial',
  484. 'not null' => TRUE,
  485. 'description' => 'Account ID',
  486. ),
  487. 'sex' => array(
  488. 'type' => 'char',
  489. 'length' => 1,
  490. 'not null' => FALSE,
  491. 'description' => 'Gender',
  492. ),
  493. ),
  494. 'primary key' => array('accountid'),
  495. );
  496. }
  497. function migrate_example_advanced_schema_blobs() {
  498. return array(
  499. 'description' => 'Wine blobs to be migrated to file entities',
  500. 'fields' => array(
  501. 'imageid' => array(
  502. 'type' => 'int',
  503. 'unsigned' => TRUE,
  504. 'not null' => TRUE,
  505. 'description' => 'Image ID',
  506. ),
  507. 'imageblob' => array(
  508. 'type' => 'blob',
  509. 'size' => 'normal',
  510. 'description' => 'binary image data',
  511. ),
  512. ),
  513. 'primary key' => array('imageid'),
  514. );
  515. }
  516. function migrate_example_advanced_schema_files() {
  517. return array(
  518. 'description' => 'Wine and account files',
  519. 'fields' => array(
  520. 'imageid' => array(
  521. 'type' => 'int',
  522. 'unsigned' => TRUE,
  523. 'not null' => TRUE,
  524. 'description' => 'Image ID',
  525. ),
  526. 'url' => array(
  527. 'type' => 'varchar',
  528. 'length' => 255,
  529. 'not null' => TRUE,
  530. 'description' => 'Image URL',
  531. ),
  532. 'image_alt' => array(
  533. 'type' => 'varchar',
  534. 'length' => 255,
  535. 'not null' => FALSE,
  536. 'description' => 'Image alt',
  537. ),
  538. 'image_title' => array(
  539. 'type' => 'varchar',
  540. 'length' => 255,
  541. 'not null' => FALSE,
  542. 'description' => 'Image title',
  543. ),
  544. 'wineid' => array(
  545. 'type' => 'int',
  546. 'unsigned' => TRUE,
  547. 'not null' => FALSE,
  548. 'description' => 'Wine node this is associated with',
  549. ),
  550. ),
  551. 'primary key' => array('imageid'),
  552. );
  553. }
  554. function migrate_example_advanced_schema_table_source() {
  555. return array(
  556. 'description' => 'Source data to go into a custom Drupal table',
  557. 'fields' => array(
  558. 'fooid' => array(
  559. 'type' => 'int',
  560. 'unsigned' => TRUE,
  561. 'not null' => TRUE,
  562. 'description' => 'Primary key',
  563. ),
  564. 'field1' => array(
  565. 'type' => 'varchar',
  566. 'length' => 255,
  567. 'not null' => TRUE,
  568. 'description' => 'First field',
  569. ),
  570. 'field2' => array(
  571. 'type' => 'int',
  572. 'unsigned' => TRUE,
  573. 'not null' => TRUE,
  574. 'description' => 'Second field',
  575. ),
  576. ),
  577. 'primary key' => array('fooid'),
  578. );
  579. }
  580. function migrate_example_advanced_schema_table_dest() {
  581. return array(
  582. 'description' => 'Custom Drupal table to receive source data directly',
  583. 'fields' => array(
  584. 'recordid' => array(
  585. 'type' => 'serial',
  586. 'unsigned' => TRUE,
  587. 'not null' => TRUE,
  588. 'description' => 'Primary key',
  589. ),
  590. 'drupal_text' => array(
  591. 'type' => 'varchar',
  592. 'length' => 255,
  593. 'not null' => TRUE,
  594. 'description' => 'First field',
  595. ),
  596. 'drupal_int' => array(
  597. 'type' => 'int',
  598. 'unsigned' => TRUE,
  599. 'not null' => TRUE,
  600. 'description' => 'Second field',
  601. ),
  602. ),
  603. 'primary key' => array('recordid'),
  604. );
  605. }
  606. function migrate_example_advanced_data_wine() {
  607. $fields = array('wineid', 'name', 'body', 'excerpt', 'accountid',
  608. 'posted', 'last_changed', 'variety', 'region', 'rating');
  609. $query = db_insert('migrate_example_wine')
  610. ->fields($fields);
  611. $data = array(
  612. array(1, 'Montes Classic Cabernet Sauvignon', 'Intense ruby-red color', 'Great!', 9,
  613. strtotime('2010-01-02 03:04:05'), strtotime('2010-03-04 05:06:07'), 25, 17, 95),
  614. array(2, 'Archeo Ruggero di Tasso Nero d\'Avola', 'Lots of berry character', 'Pair with red sauced dishes', 3,
  615. strtotime('2010-09-03 18:23:58'), strtotime('2010-09-03 18:23:58'), 26, 2, 85),
  616. );
  617. foreach ($data as $row) {
  618. $query->values(array_combine($fields, $row));
  619. }
  620. $query->execute();
  621. }
  622. function migrate_example_advanced_data_updates() {
  623. $fields = array('wineid', 'rating');
  624. $query = db_insert('migrate_example_advanced_updates')
  625. ->fields($fields);
  626. $data = array(
  627. array(1, 93),
  628. array(2, NULL),
  629. );
  630. foreach ($data as $row) {
  631. $query->values(array_combine($fields, $row));
  632. }
  633. $query->execute();
  634. }
  635. function migrate_example_advanced_data_producer() {
  636. $fields = array('producerid', 'name', 'body', 'excerpt', 'accountid');
  637. $query = db_insert('migrate_example_advanced_producer')
  638. ->fields($fields);
  639. $data = array(
  640. array(1, 'Montes', 'Fine Chilean winery', 'Great!', 9),
  641. array(2, 'Archeo', 'Sicilia!', NULL, 3),
  642. );
  643. foreach ($data as $row) {
  644. $query->values(array_combine($fields, $row));
  645. }
  646. $query->execute();
  647. }
  648. function migrate_example_advanced_data_account() {
  649. $fields = array('accountid', 'status', 'posted', 'last_access', 'last_login',
  650. 'name', 'sex', 'password', 'mail', 'original_mail', 'sig', 'imageid', 'positions');
  651. $query = db_insert('migrate_example_advanced_account')
  652. ->fields($fields);
  653. $data = array(
  654. array(1, 1, '2010-03-30 10:31:05', '2010-04-30 18:25:24', '2010-04-30 14:01:02',
  655. 'darren', 'M', 'dpass', 'ddarren@example.com', 'darren@example.com',
  656. 'All about the Australians', NULL, '5'),
  657. array(3, 0, '2007-03-15 10:31:05', '2007-06-10 04:11:38', '2007-06-10 04:11:38',
  658. 'emily', 'F', 'insecure', 'emily@example.com', 'emily@example.com',
  659. 'Sommelier to the stars', NULL, '18'),
  660. array(9, 1, '2004-02-29 10:31:05', '2004-02-29 10:31:05', '2004-02-29 10:31:05',
  661. 'fonzie', NULL, 'bike', 'thefonz@example.com', 'arthur@example.com',
  662. 'Aaay!', 1, '5,18'),
  663. );
  664. foreach ($data as $row) {
  665. $query->values(array_combine($fields, $row));
  666. }
  667. $query->execute();
  668. }
  669. function migrate_example_advanced_data_account_updates() {
  670. $fields = array('accountid', 'sex');
  671. $query = db_insert('migrate_example_advanced_account_updates')
  672. ->fields($fields);
  673. $data = array(
  674. array(1, NULL),
  675. array(3, 'M'),
  676. array(9, 'F'),
  677. );
  678. foreach ($data as $row) {
  679. $query->values(array_combine($fields, $row));
  680. }
  681. $query->execute();
  682. }
  683. function migrate_example_advanced_data_comment() {
  684. $fields = array('commentid', 'wineid', 'comment_parent', 'subject', 'body',
  685. 'name', 'mail', 'accountid', 'commenthost', 'userpage', 'posted', 'lastchanged');
  686. $query = db_insert('migrate_example_advanced_comment')
  687. ->fields($fields);
  688. $data = array(
  689. array(1, 1, NULL, 'im first', 'Tasty', 'grace', 'grace@example.com', 0,
  690. '123.456.78.9', 'http:://grace.example.com/',
  691. strtotime('2010-01-02 03:04:05'), strtotime('2010-04-05 06:07:08')),
  692. array(2, 1, NULL, 'im second', 'Delicious', 'horace', 'horace@example.com', 0,
  693. 'example.com', NULL,
  694. strtotime('2010-02-02 03:04:05'), strtotime('2010-05-05 06:07:08')),
  695. array(3, 1, NULL, 'im parent', 'Don\'t care for it', 'irene', 'irene@example.com', 0,
  696. '254.0.2.5', 'http:://www.example.com/irene',
  697. strtotime('2010-03-02 03:04:05'), strtotime('2010-03-02 03:04:05')),
  698. array(4, 1, 3, 'im child', 'But it\'s so good!', 'emily', NULL, 3,
  699. '58.29.126.1', 'http:://www.wine.com/',
  700. strtotime('2010-01-02 03:04:05'), strtotime('2010-01-02 03:04:05')),
  701. array(5, 1, 4, 'im grandchild', 'Right on, Emily!', 'thefonz@example.com', NULL, 9,
  702. '123.456.78.9', NULL,
  703. strtotime('2010-06-02 03:04:05'), strtotime('2010-06-02 03:04:05')),
  704. );
  705. foreach ($data as $row) {
  706. $query->values(array_combine($fields, $row));
  707. }
  708. $query->execute();
  709. }
  710. function migrate_example_advanced_data_comment_updates() {
  711. $fields = array('commentid', 'subject');
  712. $query = db_insert('migrate_example_advanced_comment_updates')
  713. ->fields($fields);
  714. $data = array(
  715. array(1, 'I am first'),
  716. array(2, 'I am second'),
  717. array(3, 'I am parent'),
  718. array(4, ''),
  719. array(5, 'I am Spartacus'),
  720. );
  721. foreach ($data as $row) {
  722. $query->values(array_combine($fields, $row));
  723. }
  724. $query->execute();
  725. }
  726. function migrate_example_advanced_data_categories() {
  727. $fields = array('categoryid', 'type', 'name', 'category_parent', 'details', 'ordering');
  728. $query = db_insert('migrate_example_advanced_categories')
  729. ->fields($fields);
  730. $data = array(
  731. array(1, 'variety', 'White wine', NULL, 'White wines are generally simpler and sweeter than red', 3),
  732. array(3, 'variety', 'Red wine', NULL, 'Red wines are generally more complex and "dry" than white', 1),
  733. array(8, 'variety', 'Riesling', 1, 'Associated with Germany', 2),
  734. array(9, 'variety', 'Chardonnay', 1, 'One of the most popular whites', 1),
  735. array(13, 'variety', 'Merlot', 3, 'Very drinkable', 4),
  736. array(14, 'variety', 'Syrah', 3, 'A.k.a. shiraz', -3),
  737. array(25, 'variety', 'Cabernet Sauvignon', 3, 'A basic', -5),
  738. array(26, 'variety', "Nero d'Avola", 3, 'Sicilian specialty', 2),
  739. array(2, 'region', 'Italy', NULL, 'Largest producer of wine', 5),
  740. array(11, 'region', 'Tuscany', 2, NULL, 2),
  741. array(18, 'region', 'Chianti', 11, NULL, -1),
  742. array(19, 'region', 'Elba', 11, NULL, 5),
  743. array(4, 'region', 'France', NULL, 'C\'est bon', 6),
  744. array(5, 'region', 'Bordeaux', 4, NULL, 1),
  745. array(6, 'region', 'Barsac', 5, NULL, 3),
  746. array(7, 'region', 'Pomerol', 5, NULL, 2),
  747. array(16, 'region', 'Chile', NULL, NULL, 3),
  748. array(17, 'region', 'Colchagua Valley', 16, NULL, 1),
  749. array(20, 'region', 'California', NULL, NULL, 5),
  750. array(21, 'region', 'Redwood Valley', 20, NULL, 1),
  751. array(10, 'best_with', 'Beef', NULL, NULL, 5),
  752. array(12, 'best_with', 'Pork', NULL, NULL, -3),
  753. array(15, 'best_with', 'Chicken', NULL, NULL, -5),
  754. );
  755. foreach ($data as $row) {
  756. $query->values(array_combine($fields, $row));
  757. }
  758. $query->execute();
  759. }
  760. function migrate_example_advanced_data_vintages() {
  761. $fields = array('wineid', 'vintage');
  762. $query = db_insert('migrate_example_advanced_vintages')
  763. ->fields($fields);
  764. $data = array(
  765. array(1, 2006),
  766. array(1, 2007),
  767. array(2, 2001),
  768. );
  769. foreach ($data as $row) {
  770. $query->values(array_combine($fields, $row));
  771. }
  772. $query->execute();
  773. }
  774. function migrate_example_advanced_data_variety_updates() {
  775. $fields = array('categoryid', 'details');
  776. $query = db_insert('migrate_example_advanced_variety_updates')
  777. ->fields($fields);
  778. $data = array(
  779. array(1, 'White wines are simpler and sweeter than red'),
  780. array(3, 'Red wines are generally more complex and dry than white'),
  781. array(8, 'Usually associated with Germany'),
  782. array(9, NULL),
  783. array(13, 'Common, very drinakable'),
  784. array(14, 'AKA Shiraz'),
  785. array(25, 'Basic'),
  786. array(26, 'A specialty of Sicily'),
  787. );
  788. foreach ($data as $row) {
  789. $query->values(array_combine($fields, $row));
  790. }
  791. $query->execute();
  792. }
  793. function migrate_example_advanced_data_category_wine() {
  794. $fields = array('wineid', 'categoryid');
  795. $query = db_insert('migrate_example_advanced_category_wine')
  796. ->fields($fields);
  797. $data = array(
  798. array(1, 12),
  799. array(1, 15),
  800. array(2, 10),
  801. );
  802. foreach ($data as $row) {
  803. $query->values(array_combine($fields, $row));
  804. }
  805. $query->execute();
  806. }
  807. function migrate_example_advanced_data_category_producer() {
  808. $fields = array('producerid', 'categoryid');
  809. $query = db_insert('migrate_example_advanced_category_producer')
  810. ->fields($fields);
  811. $data = array(
  812. array(1, 17),
  813. );
  814. foreach ($data as $row) {
  815. $query->values(array_combine($fields, $row));
  816. }
  817. $query->execute();
  818. }
  819. function migrate_example_advanced_data_files() {
  820. $fields = array('imageid', 'url', 'image_alt', 'image_title', 'wineid');
  821. $query = db_insert('migrate_example_advanced_files')
  822. ->fields($fields);
  823. $data = array(
  824. array(1, 'http://placekitten.com/200/200', NULL, NULL, NULL),
  825. array(2, 'http://cyrve.com/files/penguin.jpeg', 'Penguin alt', 'Penguin title', 1),
  826. array(3, 'http://cyrve.com/files/rioja.jpeg', 'Rioja alt', 'Rioja title', 2),
  827. array(4, 'http://cyrve.com/files/boutisse_0.jpeg', 'Boutisse alt', 'Boutisse title', 2),
  828. );
  829. foreach ($data as $row) {
  830. $query->values(array_combine($fields, $row));
  831. }
  832. $query->execute();
  833. }
  834. function migrate_example_advanced_data_blobs() {
  835. $blob = file_get_contents('core/misc/druplicon.png');
  836. $fields = array('imageid', 'imageblob');
  837. $query = db_insert('migrate_example_advanced_blobs')
  838. ->fields($fields);
  839. $data = array(
  840. array(1, $blob),
  841. );
  842. foreach ($data as $row) {
  843. $query->values(array_combine($fields, $row));
  844. }
  845. $query->execute();
  846. }
  847. function migrate_example_advanced_data_table_source() {
  848. $fields = array('fooid', 'field1', 'field2');
  849. $query = db_insert('migrate_example_advanced_table_source')
  850. ->fields($fields);
  851. $data = array(
  852. array(3, 'Some sample data', 58),
  853. array(15, 'Whatever', 2),
  854. array(646, 'More sample data', 34989),
  855. );
  856. foreach ($data as $row) {
  857. $query->values(array_combine($fields, $row));
  858. }
  859. $query->execute();
  860. }