Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / migrate_plus / migrate_example_advanced / migrate_example_advanced_setup / migrate_example_advanced_setup.install
1 <?php
2
3 /**
4  * @file
5  * Install setup for the migration example module.
6  *
7  * Set up source data and destination configuration for the migration example
8  * module. We do this in a separate module so migrate_example_advanced itself is
9  * a pure migration module.
10  */
11
12 /**
13  * Implements hook_schema().
14  */
15 function migrate_example_advanced_setup_schema() {
16   $schema['migrate_example_advanced_account'] = migrate_example_advanced_schema_account();
17   $schema['migrate_example_advanced_account_updates'] = migrate_example_advanced_schema_account_updates();
18   $schema['migrate_example_advanced_categories'] = migrate_example_advanced_schema_categories();
19   $schema['migrate_example_advanced_vintages'] = migrate_example_advanced_schema_vintages();
20   $schema['migrate_example_advanced_variety_updates'] = migrate_example_advanced_schema_variety_updates();
21   $schema['migrate_example_wine'] = migrate_example_advanced_schema_wine();
22   $schema['migrate_example_advanced_updates'] = migrate_example_advanced_schema_updates();
23   $schema['migrate_example_advanced_producer'] = migrate_example_advanced_schema_producer();
24   $schema['migrate_example_advanced_category_wine'] = migrate_example_advanced_schema_category_wine();
25   $schema['migrate_example_advanced_category_producer'] = migrate_example_advanced_schema_category_producer();
26   $schema['migrate_example_advanced_comment'] = migrate_example_advanced_schema_comment();
27   $schema['migrate_example_advanced_comment_updates'] = migrate_example_advanced_schema_comment_updates();
28   $schema['migrate_example_advanced_files'] = migrate_example_advanced_schema_files();
29   $schema['migrate_example_advanced_blobs'] = migrate_example_advanced_schema_blobs();
30   $schema['migrate_example_advanced_table_source'] = migrate_example_advanced_schema_table_source();
31   $schema['migrate_example_advanced_table_dest'] = migrate_example_advanced_schema_table_dest();
32
33   return $schema;
34 }
35
36 /**
37  * Implements hook_install().
38  */
39 function migrate_example_advanced_setup_install() {
40   // Populate our tables.
41   migrate_example_advanced_data_account();
42   migrate_example_advanced_data_account_updates();
43   migrate_example_advanced_data_categories();
44   migrate_example_advanced_data_vintages();
45   migrate_example_advanced_data_variety_updates();
46   migrate_example_advanced_data_wine();
47   migrate_example_advanced_data_updates();
48   migrate_example_advanced_data_producer();
49   migrate_example_advanced_data_category_wine();
50   migrate_example_advanced_data_category_producer();
51   migrate_example_advanced_data_comment();
52   migrate_example_advanced_data_comment_updates();
53   migrate_example_advanced_data_files();
54   migrate_example_advanced_data_blobs();
55   migrate_example_advanced_data_table_source();
56 }
57
58 /**
59  * The hook_schema definition for wine.
60  *
61  * @return array
62  *   The schema definition.
63  */
64 function migrate_example_advanced_schema_wine() {
65   return [
66     'description' => 'Wines of the world',
67     'fields' => [
68       'wineid'  => [
69         'type' => 'int',
70         'unsigned' => TRUE,
71         'not null' => TRUE,
72         'description' => 'Wine ID',
73       ],
74       'name'  => [
75         'type' => 'varchar',
76         'length' => 255,
77         'not null' => TRUE,
78       ],
79       'body' => [
80         'type' => 'varchar',
81         'length' => 255,
82         'not null' => FALSE,
83         'description' => 'Full description of the wine.',
84       ],
85       'excerpt' => [
86         'type' => 'varchar',
87         'length' => 255,
88         'not null' => FALSE,
89         'description' => 'Abstract for this wine.',
90       ],
91       'accountid' => [
92         'type' => 'int',
93         'unsigned' => TRUE,
94         'not null' => FALSE,
95         'description' => 'ID of the author.',
96       ],
97       'posted' => [
98         'type' => 'int',
99         'unsigned' => TRUE,
100         'not null' => TRUE,
101         'description' => 'Original creation date',
102       ],
103       'last_changed' => [
104         'type' => 'int',
105         'unsigned' => TRUE,
106         'not null' => TRUE,
107         'description' => 'Last change date',
108       ],
109       'variety' => [
110         'type' => 'int',
111         'unsigned' => TRUE,
112         'not null' => TRUE,
113         'description' => 'Wine variety',
114       ],
115       'region' => [
116         'type' => 'int',
117         'unsigned' => TRUE,
118         'not null' => TRUE,
119         'description' => 'Wine region',
120       ],
121       'rating' => [
122         'type' => 'int',
123         'unsigned' => TRUE,
124         'not null' => FALSE,
125         'description' => 'Rating (100-point scale)',
126       ],
127     ],
128     'primary key' => ['wineid'],
129   ];
130 }
131
132 /**
133  * The hook_schema definition for updates.
134  *
135  * @return array
136  *   The schema definition.
137  */
138 function migrate_example_advanced_schema_updates() {
139   return [
140     'description' => 'Updated wine ratings',
141     'fields' => [
142       'wineid'  => [
143         'type' => 'int',
144         'unsigned' => TRUE,
145         'not null' => TRUE,
146         'description' => 'Wine ID',
147       ],
148       'rating' => [
149         'type' => 'int',
150         'unsigned' => TRUE,
151         'not null' => FALSE,
152         'description' => 'Rating (100-point scale)',
153       ],
154     ],
155     'primary key' => ['wineid'],
156   ];
157 }
158
159 /**
160  * The hook_schema definition for producer.
161  *
162  * @return array
163  *   The schema definition.
164  */
165 function migrate_example_advanced_schema_producer() {
166   return [
167     'description' => 'Wine producers of the world',
168     'fields' => [
169       'producerid'  => [
170         'type' => 'int',
171         'unsigned' => TRUE,
172         'not null' => TRUE,
173         'description' => 'Producer ID',
174       ],
175       'name'  => [
176         'type' => 'varchar',
177         'length' => 255,
178         'not null' => TRUE,
179       ],
180       'body' => [
181         'type' => 'varchar',
182         'length' => 255,
183         'not null' => FALSE,
184         'description' => 'Full description of the producer.',
185       ],
186       'excerpt' => [
187         'type' => 'varchar',
188         'length' => 255,
189         'not null' => FALSE,
190         'description' => 'Abstract for this producer.',
191       ],
192       'accountid' => [
193         'type' => 'int',
194         'unsigned' => TRUE,
195         'not null' => FALSE,
196         'description' => 'Account ID of the author.',
197       ],
198     ],
199     'primary key' => ['producerid'],
200   ];
201 }
202
203 /**
204  * The hook_schema definition for categories.
205  *
206  * @return array
207  *   The schema definition.
208  */
209 function migrate_example_advanced_schema_categories() {
210   return [
211     'description' => 'Categories',
212     'fields' => [
213       'categoryid' => [
214         'type' => 'int',
215         'not null' => TRUE,
216         'unsigned' => TRUE,
217         'description' => 'Category ID',
218       ],
219       'type' => [
220         'type' => 'varchar',
221         'length' => 255,
222         'not null' => TRUE,
223         'description' => 'Type of category: variety, region, best_with',
224       ],
225       'name'  => [
226         'type' => 'varchar',
227         'length' => 255,
228         'not null' => TRUE,
229       ],
230       'details' => [
231         'type' => 'varchar',
232         'length' => 255,
233         'not null' => FALSE,
234       ],
235       'category_parent' => [
236         'type' => 'int',
237         'unsigned' => TRUE,
238         'not null' => FALSE,
239         'description' => 'Parent category, if any',
240       ],
241       'ordering' => [
242         'type' => 'int',
243         'unsigned' => FALSE,
244         'not null' => FALSE,
245         'description' => 'Order in which to display categories',
246       ],
247     ],
248     'primary key' => ['categoryid'],
249   ];
250 }
251
252 /**
253  * The hook_schema definition for vintages.
254  *
255  * @return array
256  *   The schema definition.
257  */
258 function migrate_example_advanced_schema_vintages() {
259   return [
260     'description' => 'Wine vintages',
261     'fields' => [
262       'wineid'  => [
263         'type' => 'int',
264         'not null' => TRUE,
265         'description' => 'Wine ID',
266       ],
267       'vintage'  => [
268         'type' => 'int',
269         'unsigned' => TRUE,
270         'not null' => TRUE,
271         'description' => 'Vintage (year)',
272       ],
273     ],
274     'primary key' => ['wineid', 'vintage'],
275   ];
276 }
277
278 /**
279  * The hook_schema definition for variety updates.
280  *
281  * @return array
282  *   The schema definition.
283  */
284 function migrate_example_advanced_schema_variety_updates() {
285   return [
286     'description' => 'Variety updates',
287     'fields' => [
288       'categoryid' => [
289         'type' => 'int',
290         'not null' => TRUE,
291         'unsigned' => TRUE,
292         'description' => 'Category ID',
293       ],
294       'details' => [
295         'type' => 'varchar',
296         'length' => 255,
297         'not null' => FALSE,
298       ],
299     ],
300     'primary key' => ['categoryid'],
301   ];
302 }
303
304 /**
305  * The hook_schema definition for category wine.
306  *
307  * @return array
308  *   The schema definition.
309  */
310 function migrate_example_advanced_schema_category_wine() {
311   return [
312     'description' => 'Wine category assignments',
313     'fields' => [
314       'wineid'  => [
315         'type' => 'int',
316         'not null' => TRUE,
317         'description' => 'Wine ID',
318       ],
319       'categoryid'  => [
320         'type' => 'int',
321         'unsigned' => TRUE,
322         'not null' => TRUE,
323         'description' => 'Category ID',
324       ],
325     ],
326     'primary key' => ['categoryid', 'wineid'],
327   ];
328 }
329
330 /**
331  * The hook_schema definition for category producer.
332  *
333  * @return array
334  *   The schema definition.
335  */
336 function migrate_example_advanced_schema_category_producer() {
337   return [
338     'description' => 'Producer category assignments',
339     'fields' => [
340       'producerid'  => [
341         'type' => 'int',
342         'not null' => TRUE,
343         'description' => 'Producer ID',
344       ],
345       'categoryid'  => [
346         'type' => 'int',
347         'unsigned' => TRUE,
348         'not null' => TRUE,
349         'description' => 'Category ID',
350       ],
351     ],
352     'primary key' => ['categoryid', 'producerid'],
353   ];
354 }
355
356 /**
357  * The hook_schema definition for comment.
358  *
359  * @return array
360  *   The schema definition.
361  */
362 function migrate_example_advanced_schema_comment() {
363   return [
364     'description' => 'Wine comments',
365     'fields' => [
366       'commentid'  => [
367         'type' => 'int',
368         'unsigned' => TRUE,
369         'not null' => TRUE,
370         'description' => 'Comment ID',
371       ],
372       'wineid'  => [
373         'type' => 'int',
374         'unsigned' => TRUE,
375         'not null' => TRUE,
376         'description' => 'Wine ID that is being commented upon',
377       ],
378       'comment_parent' => [
379         'type' => 'int',
380         'unsigned' => TRUE,
381         'not null' => FALSE,
382         'description' => 'Parent comment ID in case of comment replies.',
383       ],
384       'subject' => [
385         'type' => 'varchar',
386         'length' => 255,
387         'not null' => FALSE,
388         'description' => 'Comment subject',
389       ],
390       'body' => [
391         'type' => 'varchar',
392         'length' => 255,
393         'not null' => FALSE,
394         'description' => 'Comment body',
395       ],
396       'name' => [
397         'type' => 'varchar',
398         'length' => 255,
399         'not null' => FALSE,
400         'description' => 'Comment name (if anon)',
401       ],
402       'mail' => [
403         'type' => 'varchar',
404         'length' => 255,
405         'not null' => FALSE,
406         'description' => 'Comment email (if anon)',
407       ],
408       'accountid' => [
409         'type' => 'int',
410         'unsigned' => TRUE,
411         'not null' => FALSE,
412         'description' => 'Account ID (if any).',
413       ],
414       'commenthost' => [
415         'type' => 'varchar',
416         'length' => 255,
417         'not null' => FALSE,
418         'description' => 'IP/domain of host posted from',
419       ],
420       'userpage' => [
421         'type' => 'varchar',
422         'length' => 255,
423         'not null' => FALSE,
424         'description' => 'User homepage',
425       ],
426       'posted' => [
427         'type' => 'int',
428         'unsigned' => TRUE,
429         'not null' => TRUE,
430         'description' => 'Date comment posted',
431       ],
432       'lastchanged' => [
433         'type' => 'int',
434         'unsigned' => TRUE,
435         'not null' => TRUE,
436         'description' => 'Date comment last changed',
437       ],
438     ],
439     'primary key' => ['commentid'],
440   ];
441 }
442
443 /**
444  * The hook_schema definition for comment updates.
445  *
446  * @return array
447  *   The schema definition.
448  */
449 function migrate_example_advanced_schema_comment_updates() {
450   return [
451     'description' => 'Wine comment updates',
452     'fields' => [
453       'commentid'  => [
454         'type' => 'int',
455         'unsigned' => TRUE,
456         'not null' => TRUE,
457         'description' => 'Comment ID',
458       ],
459       'subject' => [
460         'type' => 'varchar',
461         'length' => 255,
462         'not null' => FALSE,
463         'description' => 'Comment subject',
464       ],
465     ],
466     'primary key' => ['commentid'],
467   ];
468 }
469
470 /**
471  * The hook_schema definition for account.
472  *
473  * @return array
474  *   The schema definition.
475  */
476 function migrate_example_advanced_schema_account() {
477   return [
478     'description' => 'Wine accounts.',
479     'fields' => [
480       'accountid'  => [
481         'type' => 'serial',
482         'not null' => TRUE,
483         'description' => 'Account ID',
484       ],
485       'status'  => [
486         'type' => 'int',
487         'not null' => TRUE,
488         'description' => 'Blocked_Allowed',
489       ],
490       'posted' => [
491         'type' => 'varchar',
492         'length' => 255,
493         'not null' => TRUE,
494         'description' => 'Registration date',
495       ],
496       'last_access' => [
497         'type' => 'varchar',
498         'length' => 255,
499         'not null' => TRUE,
500         'description' => 'Last access date',
501       ],
502       'last_login' => [
503         'type' => 'varchar',
504         'length' => 255,
505         'not null' => TRUE,
506         'description' => 'Last login date',
507       ],
508       'name' => [
509         'type' => 'varchar',
510         'length' => 255,
511         'not null' => FALSE,
512         'description' => 'Account name (for login)',
513       ],
514       'sex' => [
515         'type' => 'char',
516         'length' => 1,
517         'not null' => FALSE,
518         'description' => 'Gender',
519       ],
520       'password' => [
521         'type' => 'varchar',
522         'length' => 255,
523         'not null' => FALSE,
524         'description' => 'Account password (raw)',
525       ],
526       'mail' => [
527         'type' => 'varchar',
528         'length' => 255,
529         'not null' => FALSE,
530         'description' => 'Account email',
531       ],
532       'original_mail' => [
533         'type' => 'varchar',
534         'length' => 255,
535         'not null' => FALSE,
536         'description' => 'Original account email',
537       ],
538       'sig' => [
539         'type' => 'varchar',
540         'length' => 255,
541         'not null' => TRUE,
542         'description' => 'Signature for comments',
543       ],
544       'imageid'  => [
545         'type' => 'int',
546         'unsigned' => TRUE,
547         'not null' => FALSE,
548         'description' => 'Image ID',
549       ],
550       'positions' => [
551         'type' => 'varchar',
552         'length' => 255,
553         'not null' => FALSE,
554         'description' => 'Positions held',
555       ],
556     ],
557     'primary key' => ['accountid'],
558   ];
559 }
560
561 /**
562  * The hook_schema definition for account updates.
563  *
564  * @return array
565  *   The schema definition.
566  */
567 function migrate_example_advanced_schema_account_updates() {
568   return [
569     'description' => 'Wine account updates',
570     'fields' => [
571       'accountid'  => [
572         'type' => 'serial',
573         'not null' => TRUE,
574         'description' => 'Account ID',
575       ],
576       'sex' => [
577         'type' => 'char',
578         'length' => 1,
579         'not null' => FALSE,
580         'description' => 'Gender',
581       ],
582     ],
583     'primary key' => ['accountid'],
584   ];
585 }
586
587 /**
588  * The hook_schema definition for blobs.
589  *
590  * @return array
591  *   The schema definition.
592  */
593 function migrate_example_advanced_schema_blobs() {
594   return [
595     'description' => 'Wine blobs to be migrated to file entities',
596     'fields' => [
597       'imageid'  => [
598         'type' => 'int',
599         'unsigned' => TRUE,
600         'not null' => TRUE,
601         'description' => 'Image ID',
602       ],
603       'imageblob' => [
604         'type' => 'blob',
605         'size' => 'normal',
606         'description' => 'binary image data',
607       ],
608     ],
609     'primary key' => ['imageid'],
610   ];
611 }
612
613 /**
614  * The hook_schema definition for files.
615  *
616  * @return array
617  *   The schema definition.
618  */
619 function migrate_example_advanced_schema_files() {
620   return [
621     'description' => 'Wine and account files',
622     'fields' => [
623       'imageid'  => [
624         'type' => 'int',
625         'unsigned' => TRUE,
626         'not null' => TRUE,
627         'description' => 'Image ID',
628       ],
629       'url'  => [
630         'type' => 'varchar',
631         'length' => 255,
632         'not null' => TRUE,
633         'description' => 'Image URL',
634       ],
635       'image_alt'  => [
636         'type' => 'varchar',
637         'length' => 255,
638         'not null' => FALSE,
639         'description' => 'Image alt',
640       ],
641       'image_title'  => [
642         'type' => 'varchar',
643         'length' => 255,
644         'not null' => FALSE,
645         'description' => 'Image title',
646       ],
647       'wineid'  => [
648         'type' => 'int',
649         'unsigned' => TRUE,
650         'not null' => FALSE,
651         'description' => 'Wine node this is associated with',
652       ],
653     ],
654     'primary key' => ['imageid'],
655   ];
656 }
657
658 /**
659  * The hook_schema definition for table source.
660  *
661  * @return array
662  *   The schema definition.
663  */
664 function migrate_example_advanced_schema_table_source() {
665   return [
666     'description' => 'Source data to go into a custom Drupal table',
667     'fields' => [
668       'fooid'  => [
669         'type' => 'int',
670         'unsigned' => TRUE,
671         'not null' => TRUE,
672         'description' => 'Primary key',
673       ],
674       'field1'  => [
675         'type' => 'varchar',
676         'length' => 255,
677         'not null' => TRUE,
678         'description' => 'First field',
679       ],
680       'field2'  => [
681         'type' => 'int',
682         'unsigned' => TRUE,
683         'not null' => TRUE,
684         'description' => 'Second field',
685       ],
686     ],
687     'primary key' => ['fooid'],
688   ];
689 }
690
691 /**
692  * The hook_schema definition for table destination.
693  *
694  * @return array
695  *   The schema definition.
696  */
697 function migrate_example_advanced_schema_table_dest() {
698   return [
699     'description' => 'Custom Drupal table to receive source data directly',
700     'fields' => [
701       'recordid'  => [
702         'type' => 'serial',
703         'unsigned' => TRUE,
704         'not null' => TRUE,
705         'description' => 'Primary key',
706       ],
707       'drupal_text'  => [
708         'type' => 'varchar',
709         'length' => 255,
710         'not null' => TRUE,
711         'description' => 'First field',
712       ],
713       'drupal_int'  => [
714         'type' => 'int',
715         'unsigned' => TRUE,
716         'not null' => TRUE,
717         'description' => 'Second field',
718       ],
719     ],
720     'primary key' => ['recordid'],
721   ];
722 }
723
724 /**
725  * Populate wine table.
726  */
727 function migrate_example_advanced_data_wine() {
728   $fields = [
729     'wineid',
730     'name',
731     'body',
732     'excerpt',
733     'accountid',
734     'posted',
735     'last_changed',
736     'variety',
737     'region',
738     'rating',
739   ];
740   $query = db_insert('migrate_example_wine')
741     ->fields($fields);
742   $data = [
743     [
744       1,
745       'Montes Classic Cabernet Sauvignon',
746       'Intense ruby-red color',
747       'Great!',
748       9,
749       strtotime('2010-01-02 03:04:05'),
750       strtotime('2010-03-04 05:06:07'),
751       25,
752       17,
753       95,
754     ],
755     [
756       2,
757       'Archeo Ruggero di Tasso Nero d\'Avola',
758       'Lots of berry character',
759       'Pair with red sauced dishes',
760       3,
761       strtotime('2010-09-03 18:23:58'),
762       strtotime('2010-09-03 18:23:58'),
763       26,
764       2,
765       85,
766     ],
767   ];
768   foreach ($data as $row) {
769     $query->values(array_combine($fields, $row));
770   }
771   $query->execute();
772 }
773
774 /**
775  * Populate updates table.
776  */
777 function migrate_example_advanced_data_updates() {
778   $fields = ['wineid', 'rating'];
779   $query = db_insert('migrate_example_advanced_updates')
780     ->fields($fields);
781   $data = [
782     [1, 93],
783     [2, NULL],
784   ];
785   foreach ($data as $row) {
786     $query->values(array_combine($fields, $row));
787   }
788   $query->execute();
789 }
790
791 /**
792  * Populate producer table.
793  */
794 function migrate_example_advanced_data_producer() {
795   $fields = ['producerid', 'name', 'body', 'excerpt', 'accountid'];
796   $query = db_insert('migrate_example_advanced_producer')
797     ->fields($fields);
798   $data = [
799     [1, 'Montes', 'Fine Chilean winery', 'Great!', 9],
800     [2, 'Archeo', 'Sicilia!', NULL, 3],
801   ];
802   foreach ($data as $row) {
803     $query->values(array_combine($fields, $row));
804   }
805   $query->execute();
806 }
807
808 /**
809  * Populate account table.
810  */
811 function migrate_example_advanced_data_account() {
812   $fields = [
813     'accountid',
814     'status',
815     'posted',
816     'last_access',
817     'last_login',
818     'name',
819     'sex',
820     'password',
821     'mail',
822     'original_mail',
823     'sig',
824     'imageid',
825     'positions',
826   ];
827   $query = db_insert('migrate_example_advanced_account')
828     ->fields($fields);
829   $data = [
830     [
831       1,
832       1,
833       '2010-03-30 10:31:05',
834       '2010-04-30 18:25:24',
835       '2010-04-30 14:01:02',
836       'darren',
837       'M',
838       'dpass',
839       'ddarren@example.com',
840       'darren@example.com',
841       'All about the Australians',
842       NULL,
843       '5',
844     ],
845     [
846       3,
847       0,
848       '2007-03-15 10:31:05',
849       '2007-06-10 04:11:38',
850       '2007-06-10 04:11:38',
851       'emily',
852       'F',
853       'insecure',
854       'emily@example.com',
855       'emily@example.com',
856       'Sommelier to the stars',
857       NULL,
858       '18',
859     ],
860     [
861       9,
862       1,
863       '2004-02-29 10:31:05',
864       '2004-02-29 10:31:05',
865       '2004-02-29 10:31:05',
866       'fonzie',
867       NULL,
868       'bike',
869       'thefonz@example.com',
870       'arthur@example.com',
871       'Aaay!',
872       1,
873       '5,18',
874     ],
875   ];
876   foreach ($data as $row) {
877     $query->values(array_combine($fields, $row));
878   }
879   $query->execute();
880 }
881
882 /**
883  * Populate account updates table.
884  */
885 function migrate_example_advanced_data_account_updates() {
886   $fields = ['accountid', 'sex'];
887   $query = db_insert('migrate_example_advanced_account_updates')
888     ->fields($fields);
889   $data = [
890     [1, NULL],
891     [3, 'M'],
892     [9, 'F'],
893   ];
894   foreach ($data as $row) {
895     $query->values(array_combine($fields, $row));
896   }
897   $query->execute();
898 }
899
900 /**
901  * Populate comment table.
902  */
903 function migrate_example_advanced_data_comment() {
904   $fields = [
905     'commentid',
906     'wineid',
907     'comment_parent',
908     'subject',
909     'body',
910     'name',
911     'mail',
912     'accountid',
913     'commenthost',
914     'userpage',
915     'posted',
916     'lastchanged',
917   ];
918   $query = db_insert('migrate_example_advanced_comment')
919     ->fields($fields);
920   $data = [
921     [
922       1,
923       1,
924       NULL,
925       'im first',
926       'Tasty',
927       'grace',
928       'grace@example.com',
929       0,
930       '123.456.78.9',
931       'http:://grace.example.com/',
932       strtotime('2010-01-02 03:04:05'),
933       strtotime('2010-04-05 06:07:08'),
934     ],
935     [
936       2,
937       1,
938       NULL,
939       'im second',
940       'Delicious',
941       'horace',
942       'horace@example.com',
943       0,
944       'example.com',
945       NULL,
946       strtotime('2010-02-02 03:04:05'),
947       strtotime('2010-05-05 06:07:08'),
948     ],
949     [
950       3,
951       1,
952       NULL,
953       'im parent',
954       'Don\'t care for it',
955       'irene',
956       'irene@example.com',
957       0,
958       '254.0.2.5',
959       'http:://www.example.com/irene',
960       strtotime('2010-03-02 03:04:05'),
961       strtotime('2010-03-02 03:04:05'),
962     ],
963     [
964       4,
965       1,
966       3,
967       'im child',
968       'But it\'s so good!',
969       'emily',
970       NULL,
971       3,
972       '58.29.126.1',
973       'http:://www.wine.com/',
974       strtotime('2010-01-02 03:04:05'),
975       strtotime('2010-01-02 03:04:05'),
976     ],
977     [
978       5,
979       1,
980       4,
981       'im grandchild',
982       'Right on, Emily!',
983       'thefonz@example.com',
984       NULL,
985       9,
986       '123.456.78.9',
987       NULL,
988       strtotime('2010-06-02 03:04:05'),
989       strtotime('2010-06-02 03:04:05'),
990     ],
991   ];
992   foreach ($data as $row) {
993     $query->values(array_combine($fields, $row));
994   }
995   $query->execute();
996 }
997
998 /**
999  * Populate comment updates table.
1000  */
1001 function migrate_example_advanced_data_comment_updates() {
1002   $fields = ['commentid', 'subject'];
1003   $query = db_insert('migrate_example_advanced_comment_updates')
1004     ->fields($fields);
1005   $data = [
1006     [1, 'I am first'],
1007     [2, 'I am second'],
1008     [3, 'I am parent'],
1009     [4, ''],
1010     [5, 'I am Spartacus'],
1011   ];
1012   foreach ($data as $row) {
1013     $query->values(array_combine($fields, $row));
1014   }
1015   $query->execute();
1016 }
1017
1018 /**
1019  * Populate categories table.
1020  */
1021 function migrate_example_advanced_data_categories() {
1022   $fields = [
1023     'categoryid',
1024     'type',
1025     'name',
1026     'category_parent',
1027     'details',
1028     'ordering',
1029   ];
1030   $query = db_insert('migrate_example_advanced_categories')
1031     ->fields($fields);
1032   $data = [
1033     [
1034       1,
1035       'variety',
1036       'White wine',
1037       NULL,
1038       'White wines are generally simpler and sweeter than red',
1039       3,
1040     ],
1041     [
1042       3,
1043       'variety',
1044       'Red wine',
1045       NULL,
1046       'Red wines are generally more complex and "dry" than white',
1047       1,
1048     ],
1049     [8, 'variety', 'Riesling', 1, 'Associated with Germany', 2],
1050     [9, 'variety', 'Chardonnay', 1, 'One of the most popular whites', 1],
1051     [13, 'variety', 'Merlot', 3, 'Very drinkable', 4],
1052     [14, 'variety', 'Syrah', 3, 'A.k.a. shiraz', -3],
1053     [25, 'variety', 'Cabernet Sauvignon', 3, 'A basic', -5],
1054     [26, 'variety', "Nero d'Avola", 3, 'Sicilian specialty', 2],
1055     [2, 'region', 'Italy', NULL, 'Largest producer of wine', 5],
1056     [11, 'region', 'Tuscany', 2, NULL, 2],
1057     [18, 'region', 'Chianti', 11, NULL, -1],
1058     [19, 'region', 'Elba', 11, NULL, 5],
1059     [4, 'region', 'France', NULL, 'C\'est bon', 6],
1060     [5, 'region', 'Bordeaux', 4, NULL, 1],
1061     [6, 'region', 'Barsac', 5, NULL, 3],
1062     [7, 'region', 'Pomerol', 5, NULL, 2],
1063     [16, 'region', 'Chile', NULL, NULL, 3],
1064     [17, 'region', 'Colchagua Valley', 16, NULL, 1],
1065     [20, 'region', 'California', NULL, NULL, 5],
1066     [21, 'region', 'Redwood Valley', 20, NULL, 1],
1067     [10, 'best_with', 'Beef', NULL, NULL, 5],
1068     [12, 'best_with', 'Pork', NULL, NULL, -3],
1069     [15, 'best_with', 'Chicken', NULL, NULL, -5],
1070   ];
1071   foreach ($data as $row) {
1072     $query->values(array_combine($fields, $row));
1073   }
1074   $query->execute();
1075 }
1076
1077 /**
1078  * Populate vintages table.
1079  */
1080 function migrate_example_advanced_data_vintages() {
1081   $fields = ['wineid', 'vintage'];
1082   $query = db_insert('migrate_example_advanced_vintages')
1083     ->fields($fields);
1084   $data = [
1085     [1, 2006],
1086     [1, 2007],
1087     [2, 2001],
1088   ];
1089   foreach ($data as $row) {
1090     $query->values(array_combine($fields, $row));
1091   }
1092   $query->execute();
1093 }
1094
1095 /**
1096  * Populate variety updates table.
1097  */
1098 function migrate_example_advanced_data_variety_updates() {
1099   $fields = ['categoryid', 'details'];
1100   $query = db_insert('migrate_example_advanced_variety_updates')
1101     ->fields($fields);
1102   $data = [
1103     [1, 'White wines are simpler and sweeter than red'],
1104     [3, 'Red wines are generally more complex and dry than white'],
1105     [8, 'Usually associated with Germany'],
1106     [9, NULL],
1107     [13, 'Common, very drinakable'],
1108     [14, 'AKA Shiraz'],
1109     [25, 'Basic'],
1110     [26, 'A specialty of Sicily'],
1111   ];
1112   foreach ($data as $row) {
1113     $query->values(array_combine($fields, $row));
1114   }
1115   $query->execute();
1116 }
1117
1118 /**
1119  * Populate category wine table.
1120  */
1121 function migrate_example_advanced_data_category_wine() {
1122   $fields = ['wineid', 'categoryid'];
1123   $query = db_insert('migrate_example_advanced_category_wine')
1124     ->fields($fields);
1125   $data = [
1126     [1, 12],
1127     [1, 15],
1128     [2, 10],
1129   ];
1130   foreach ($data as $row) {
1131     $query->values(array_combine($fields, $row));
1132   }
1133   $query->execute();
1134 }
1135
1136 /**
1137  * Populate category producer table.
1138  */
1139 function migrate_example_advanced_data_category_producer() {
1140   $fields = ['producerid', 'categoryid'];
1141   $query = db_insert('migrate_example_advanced_category_producer')
1142     ->fields($fields);
1143   $data = [
1144     [1, 17],
1145   ];
1146   foreach ($data as $row) {
1147     $query->values(array_combine($fields, $row));
1148   }
1149   $query->execute();
1150 }
1151
1152 /**
1153  * Populate files table.
1154  */
1155 function migrate_example_advanced_data_files() {
1156   $fields = ['imageid', 'url', 'image_alt', 'image_title', 'wineid'];
1157   $query = db_insert('migrate_example_advanced_files')
1158     ->fields($fields);
1159   $data = [
1160     [
1161       1,
1162       'http://placekitten.com/200/200',
1163       NULL,
1164       NULL,
1165       NULL,
1166     ],
1167     [
1168       2,
1169       'http://cyrve.com/files/penguin.jpeg',
1170       'Penguin alt',
1171       'Penguin title',
1172       1,
1173     ],
1174     [3, 'http://cyrve.com/files/rioja.jpeg', 'Rioja alt', 'Rioja title', 2],
1175     [
1176       4,
1177       'http://cyrve.com/files/boutisse_0.jpeg',
1178       'Boutisse alt',
1179       'Boutisse title',
1180       2,
1181     ],
1182   ];
1183   foreach ($data as $row) {
1184     $query->values(array_combine($fields, $row));
1185   }
1186   $query->execute();
1187 }
1188
1189 /**
1190  * Populate blobs table.
1191  */
1192 function migrate_example_advanced_data_blobs() {
1193   $blob = file_get_contents('core/misc/druplicon.png');
1194   $fields = ['imageid', 'imageblob'];
1195   $query = db_insert('migrate_example_advanced_blobs')
1196     ->fields($fields);
1197   $data = [
1198     [1, $blob],
1199   ];
1200   foreach ($data as $row) {
1201     $query->values(array_combine($fields, $row));
1202   }
1203   $query->execute();
1204 }
1205
1206 /**
1207  * Populate table source table.
1208  */
1209 function migrate_example_advanced_data_table_source() {
1210   $fields = ['fooid', 'field1', 'field2'];
1211   $query = db_insert('migrate_example_advanced_table_source')
1212     ->fields($fields);
1213   $data = [
1214     [3, 'Some sample data', 58],
1215     [15, 'Whatever', 2],
1216     [646, 'More sample data', 34989],
1217   ];
1218   foreach ($data as $row) {
1219     $query->values(array_combine($fields, $row));
1220   }
1221   $query->execute();
1222 }