migrate_example_advanced_setup.install 25 KB

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