2 use Drupal\user\RoleInterface;
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.
12 * Implements hook_schema().
14 function migrate_example_advanced_setup_schema() {
15 $schema['migrate_example_advanced_account'] = migrate_example_advanced_schema_account();
16 $schema['migrate_example_advanced_account_updates'] = migrate_example_advanced_schema_account_updates();
17 $schema['migrate_example_advanced_categories'] = migrate_example_advanced_schema_categories();
18 $schema['migrate_example_advanced_vintages'] = migrate_example_advanced_schema_vintages();
19 $schema['migrate_example_advanced_variety_updates'] = migrate_example_advanced_schema_variety_updates();
20 $schema['migrate_example_wine'] = migrate_example_advanced_schema_wine();
21 $schema['migrate_example_advanced_updates'] = migrate_example_advanced_schema_updates();
22 $schema['migrate_example_advanced_producer'] = migrate_example_advanced_schema_producer();
23 $schema['migrate_example_advanced_category_wine'] = migrate_example_advanced_schema_category_wine();
24 $schema['migrate_example_advanced_category_producer'] = migrate_example_advanced_schema_category_producer();
25 $schema['migrate_example_advanced_comment'] = migrate_example_advanced_schema_comment();
26 $schema['migrate_example_advanced_comment_updates'] = migrate_example_advanced_schema_comment_updates();
27 $schema['migrate_example_advanced_files'] = migrate_example_advanced_schema_files();
28 $schema['migrate_example_advanced_blobs'] = migrate_example_advanced_schema_blobs();
29 $schema['migrate_example_advanced_table_source'] = migrate_example_advanced_schema_table_source();
30 $schema['migrate_example_advanced_table_dest'] = migrate_example_advanced_schema_table_dest();
36 * Implements hook_install().
38 function migrate_example_advanced_setup_install() {
39 // Populate our tables.
40 migrate_example_advanced_data_account();
41 migrate_example_advanced_data_account_updates();
42 migrate_example_advanced_data_categories();
43 migrate_example_advanced_data_vintages();
44 migrate_example_advanced_data_variety_updates();
45 migrate_example_advanced_data_wine();
46 migrate_example_advanced_data_updates();
47 migrate_example_advanced_data_producer();
48 migrate_example_advanced_data_category_wine();
49 migrate_example_advanced_data_category_producer();
50 migrate_example_advanced_data_comment();
51 migrate_example_advanced_data_comment_updates();
52 migrate_example_advanced_data_files();
53 migrate_example_advanced_data_blobs();
54 migrate_example_advanced_data_table_source();
57 function migrate_example_advanced_schema_wine() {
59 'description' => 'Wines of the world',
65 'description' => 'Wine ID',
76 'description' => 'Full description of the wine.',
82 'description' => 'Abstract for this wine.',
88 'description' => 'ID of the author.',
94 'description' => 'Original creation date',
100 'description' => 'Last change date',
106 'description' => 'Wine variety',
112 'description' => 'Wine region',
118 'description' => 'Rating (100-point scale)',
121 'primary key' => ['wineid'],
125 function migrate_example_advanced_schema_updates() {
127 'description' => 'Updated wine ratings',
133 'description' => 'Wine ID',
139 'description' => 'Rating (100-point scale)',
142 'primary key' => ['wineid'],
146 function migrate_example_advanced_schema_producer() {
148 'description' => 'Wine producers of the world',
150 'producerid' => array(
154 'description' => 'Producer ID',
165 'description' => 'Full description of the producer.',
171 'description' => 'Abstract for this producer.',
173 'accountid' => array(
177 'description' => 'Account ID of the author.',
180 'primary key' => array('producerid'),
184 function migrate_example_advanced_schema_categories() {
186 'description' => 'Categories',
188 'categoryid' => array(
192 'description' => 'Category ID',
198 'description' => 'Type of category: variety, region, best_with',
210 'category_parent' => array(
214 'description' => 'Parent category, if any',
220 'description' => 'Order in which to display categories',
223 'primary key' => array('categoryid'),
227 function migrate_example_advanced_schema_vintages() {
229 'description' => 'Wine vintages',
234 'description' => 'Wine ID',
240 'description' => 'Vintage (year)',
243 'primary key' => array('wineid', 'vintage'),
247 function migrate_example_advanced_schema_variety_updates() {
249 'description' => 'Variety updates',
251 'categoryid' => array(
255 'description' => 'Category ID',
263 'primary key' => array('categoryid'),
267 function migrate_example_advanced_schema_category_wine() {
269 'description' => 'Wine category assignments',
274 'description' => 'Wine ID',
276 'categoryid' => array(
280 'description' => 'Category ID',
283 'primary key' => array('categoryid', 'wineid'),
287 function migrate_example_advanced_schema_category_producer() {
289 'description' => 'Producer category assignments',
291 'producerid' => array(
294 'description' => 'Producer ID',
296 'categoryid' => array(
300 'description' => 'Category ID',
303 'primary key' => array('categoryid', 'producerid'),
307 function migrate_example_advanced_schema_comment() {
309 'description' => 'Wine comments',
311 'commentid' => array(
315 'description' => 'Comment ID',
321 'description' => 'Wine ID that is being commented upon',
323 'comment_parent' => array(
327 'description' => 'Parent comment ID in case of comment replies.',
333 'description' => 'Comment subject',
339 'description' => 'Comment body',
345 'description' => 'Comment name (if anon)',
351 'description' => 'Comment email (if anon)',
353 'accountid' => array(
357 'description' => 'Account ID (if any).',
359 'commenthost' => array(
363 'description' => 'IP/domain of host posted from',
369 'description' => 'User homepage',
375 'description' => 'Date comment posted',
377 'lastchanged' => array(
381 'description' => 'Date comment last changed',
384 'primary key' => array('commentid'),
388 function migrate_example_advanced_schema_comment_updates() {
390 'description' => 'Wine comment updates',
392 'commentid' => array(
396 'description' => 'Comment ID',
402 'description' => 'Comment subject',
405 'primary key' => array('commentid'),
409 function migrate_example_advanced_schema_account() {
411 'description' => 'Wine accounts.',
413 'accountid' => array(
416 'description' => 'Account ID',
421 'description' => 'Blocked_Allowed',
427 'description' => 'Registration date',
429 'last_access' => array(
433 'description' => 'Last access date',
435 'last_login' => array(
439 'description' => 'Last login date',
445 'description' => 'Account name (for login)',
451 'description' => 'Gender',
457 'description' => 'Account password (raw)',
463 'description' => 'Account email',
465 'original_mail' => array(
469 'description' => 'Original account email',
475 'description' => 'Signature for comments',
481 'description' => 'Image ID',
483 'positions' => array(
487 'description' => 'Positions held',
490 'primary key' => array('accountid'),
494 function migrate_example_advanced_schema_account_updates() {
496 'description' => 'Wine account updates',
498 'accountid' => array(
501 'description' => 'Account ID',
507 'description' => 'Gender',
510 'primary key' => array('accountid'),
514 function migrate_example_advanced_schema_blobs() {
516 'description' => 'Wine blobs to be migrated to file entities',
522 'description' => 'Image ID',
524 'imageblob' => array(
527 'description' => 'binary image data',
530 'primary key' => array('imageid'),
534 function migrate_example_advanced_schema_files() {
536 'description' => 'Wine and account files',
542 'description' => 'Image ID',
548 'description' => 'Image URL',
550 'image_alt' => array(
554 'description' => 'Image alt',
556 'image_title' => array(
560 'description' => 'Image title',
566 'description' => 'Wine node this is associated with',
569 'primary key' => array('imageid'),
573 function migrate_example_advanced_schema_table_source() {
575 'description' => 'Source data to go into a custom Drupal table',
581 'description' => 'Primary key',
587 'description' => 'First field',
593 'description' => 'Second field',
596 'primary key' => array('fooid'),
600 function migrate_example_advanced_schema_table_dest() {
602 'description' => 'Custom Drupal table to receive source data directly',
608 'description' => 'Primary key',
610 'drupal_text' => array(
614 'description' => 'First field',
616 'drupal_int' => array(
620 'description' => 'Second field',
623 'primary key' => array('recordid'),
627 function migrate_example_advanced_data_wine() {
628 $fields = array('wineid', 'name', 'body', 'excerpt', 'accountid',
629 'posted', 'last_changed', 'variety', 'region', 'rating');
630 $query = db_insert('migrate_example_wine')
633 array(1, 'Montes Classic Cabernet Sauvignon', 'Intense ruby-red color', 'Great!', 9,
634 strtotime('2010-01-02 03:04:05'), strtotime('2010-03-04 05:06:07'), 25, 17, 95),
635 array(2, 'Archeo Ruggero di Tasso Nero d\'Avola', 'Lots of berry character', 'Pair with red sauced dishes', 3,
636 strtotime('2010-09-03 18:23:58'), strtotime('2010-09-03 18:23:58'), 26, 2, 85),
638 foreach ($data as $row) {
639 $query->values(array_combine($fields, $row));
644 function migrate_example_advanced_data_updates() {
645 $fields = array('wineid', 'rating');
646 $query = db_insert('migrate_example_advanced_updates')
652 foreach ($data as $row) {
653 $query->values(array_combine($fields, $row));
658 function migrate_example_advanced_data_producer() {
659 $fields = array('producerid', 'name', 'body', 'excerpt', 'accountid');
660 $query = db_insert('migrate_example_advanced_producer')
663 array(1, 'Montes', 'Fine Chilean winery', 'Great!', 9),
664 array(2, 'Archeo', 'Sicilia!', NULL, 3),
666 foreach ($data as $row) {
667 $query->values(array_combine($fields, $row));
672 function migrate_example_advanced_data_account() {
673 $fields = array('accountid', 'status', 'posted', 'last_access', 'last_login',
674 'name', 'sex', 'password', 'mail', 'original_mail', 'sig', 'imageid', 'positions');
675 $query = db_insert('migrate_example_advanced_account')
678 array(1, 1, '2010-03-30 10:31:05', '2010-04-30 18:25:24', '2010-04-30 14:01:02',
679 'darren', 'M', 'dpass', 'ddarren@example.com', 'darren@example.com',
680 'All about the Australians', NULL, '5'),
681 array(3, 0, '2007-03-15 10:31:05', '2007-06-10 04:11:38', '2007-06-10 04:11:38',
682 'emily', 'F', 'insecure', 'emily@example.com', 'emily@example.com',
683 'Sommelier to the stars', NULL, '18'),
684 array(9, 1, '2004-02-29 10:31:05', '2004-02-29 10:31:05', '2004-02-29 10:31:05',
685 'fonzie', NULL, 'bike', 'thefonz@example.com', 'arthur@example.com',
688 foreach ($data as $row) {
689 $query->values(array_combine($fields, $row));
694 function migrate_example_advanced_data_account_updates() {
695 $fields = array('accountid', 'sex');
696 $query = db_insert('migrate_example_advanced_account_updates')
703 foreach ($data as $row) {
704 $query->values(array_combine($fields, $row));
709 function migrate_example_advanced_data_comment() {
710 $fields = array('commentid', 'wineid', 'comment_parent', 'subject', 'body',
711 'name', 'mail', 'accountid', 'commenthost', 'userpage', 'posted', 'lastchanged');
712 $query = db_insert('migrate_example_advanced_comment')
715 array(1, 1, NULL, 'im first', 'Tasty', 'grace', 'grace@example.com', 0,
716 '123.456.78.9', 'http:://grace.example.com/',
717 strtotime('2010-01-02 03:04:05'), strtotime('2010-04-05 06:07:08')),
718 array(2, 1, NULL, 'im second', 'Delicious', 'horace', 'horace@example.com', 0,
720 strtotime('2010-02-02 03:04:05'), strtotime('2010-05-05 06:07:08')),
721 array(3, 1, NULL, 'im parent', 'Don\'t care for it', 'irene', 'irene@example.com', 0,
722 '254.0.2.5', 'http:://www.example.com/irene',
723 strtotime('2010-03-02 03:04:05'), strtotime('2010-03-02 03:04:05')),
724 array(4, 1, 3, 'im child', 'But it\'s so good!', 'emily', NULL, 3,
725 '58.29.126.1', 'http:://www.wine.com/',
726 strtotime('2010-01-02 03:04:05'), strtotime('2010-01-02 03:04:05')),
727 array(5, 1, 4, 'im grandchild', 'Right on, Emily!', 'thefonz@example.com', NULL, 9,
728 '123.456.78.9', NULL,
729 strtotime('2010-06-02 03:04:05'), strtotime('2010-06-02 03:04:05')),
731 foreach ($data as $row) {
732 $query->values(array_combine($fields, $row));
737 function migrate_example_advanced_data_comment_updates() {
738 $fields = array('commentid', 'subject');
739 $query = db_insert('migrate_example_advanced_comment_updates')
742 array(1, 'I am first'),
743 array(2, 'I am second'),
744 array(3, 'I am parent'),
746 array(5, 'I am Spartacus'),
748 foreach ($data as $row) {
749 $query->values(array_combine($fields, $row));
754 function migrate_example_advanced_data_categories() {
755 $fields = array('categoryid', 'type', 'name', 'category_parent', 'details', 'ordering');
756 $query = db_insert('migrate_example_advanced_categories')
759 array(1, 'variety', 'White wine', NULL, 'White wines are generally simpler and sweeter than red', 3),
760 array(3, 'variety', 'Red wine', NULL, 'Red wines are generally more complex and "dry" than white', 1),
761 array(8, 'variety', 'Riesling', 1, 'Associated with Germany', 2),
762 array(9, 'variety', 'Chardonnay', 1, 'One of the most popular whites', 1),
763 array(13, 'variety', 'Merlot', 3, 'Very drinkable', 4),
764 array(14, 'variety', 'Syrah', 3, 'A.k.a. shiraz', -3),
765 array(25, 'variety', 'Cabernet Sauvignon', 3, 'A basic', -5),
766 array(26, 'variety', "Nero d'Avola", 3, 'Sicilian specialty', 2),
767 array(2, 'region', 'Italy', NULL, 'Largest producer of wine', 5),
768 array(11, 'region', 'Tuscany', 2, NULL, 2),
769 array(18, 'region', 'Chianti', 11, NULL, -1),
770 array(19, 'region', 'Elba', 11, NULL, 5),
771 array(4, 'region', 'France', NULL, 'C\'est bon', 6),
772 array(5, 'region', 'Bordeaux', 4, NULL, 1),
773 array(6, 'region', 'Barsac', 5, NULL, 3),
774 array(7, 'region', 'Pomerol', 5, NULL, 2),
775 array(16, 'region', 'Chile', NULL, NULL, 3),
776 array(17, 'region', 'Colchagua Valley', 16, NULL, 1),
777 array(20, 'region', 'California', NULL, NULL, 5),
778 array(21, 'region', 'Redwood Valley', 20, NULL, 1),
779 array(10, 'best_with', 'Beef', NULL, NULL, 5),
780 array(12, 'best_with', 'Pork', NULL, NULL, -3),
781 array(15, 'best_with', 'Chicken', NULL, NULL, -5),
783 foreach ($data as $row) {
784 $query->values(array_combine($fields, $row));
789 function migrate_example_advanced_data_vintages() {
790 $fields = array('wineid', 'vintage');
791 $query = db_insert('migrate_example_advanced_vintages')
798 foreach ($data as $row) {
799 $query->values(array_combine($fields, $row));
804 function migrate_example_advanced_data_variety_updates() {
805 $fields = array('categoryid', 'details');
806 $query = db_insert('migrate_example_advanced_variety_updates')
809 array(1, 'White wines are simpler and sweeter than red'),
810 array(3, 'Red wines are generally more complex and dry than white'),
811 array(8, 'Usually associated with Germany'),
813 array(13, 'Common, very drinakable'),
814 array(14, 'AKA Shiraz'),
816 array(26, 'A specialty of Sicily'),
818 foreach ($data as $row) {
819 $query->values(array_combine($fields, $row));
824 function migrate_example_advanced_data_category_wine() {
825 $fields = array('wineid', 'categoryid');
826 $query = db_insert('migrate_example_advanced_category_wine')
833 foreach ($data as $row) {
834 $query->values(array_combine($fields, $row));
839 function migrate_example_advanced_data_category_producer() {
840 $fields = array('producerid', 'categoryid');
841 $query = db_insert('migrate_example_advanced_category_producer')
846 foreach ($data as $row) {
847 $query->values(array_combine($fields, $row));
852 function migrate_example_advanced_data_files() {
853 $fields = array('imageid', 'url', 'image_alt', 'image_title', 'wineid');
854 $query = db_insert('migrate_example_advanced_files')
857 array(1, 'http://placekitten.com/200/200', NULL, NULL, NULL),
858 array(2, 'http://cyrve.com/files/penguin.jpeg', 'Penguin alt', 'Penguin title', 1),
859 array(3, 'http://cyrve.com/files/rioja.jpeg', 'Rioja alt', 'Rioja title', 2),
860 array(4, 'http://cyrve.com/files/boutisse_0.jpeg', 'Boutisse alt', 'Boutisse title', 2),
862 foreach ($data as $row) {
863 $query->values(array_combine($fields, $row));
868 function migrate_example_advanced_data_blobs() {
869 $blob = file_get_contents('core/misc/druplicon.png');
870 $fields = array('imageid', 'imageblob');
871 $query = db_insert('migrate_example_advanced_blobs')
876 foreach ($data as $row) {
877 $query->values(array_combine($fields, $row));
882 function migrate_example_advanced_data_table_source() {
883 $fields = array('fooid', 'field1', 'field2');
884 $query = db_insert('migrate_example_advanced_table_source')
887 array(3, 'Some sample data', 58),
888 array(15, 'Whatever', 2),
889 array(646, 'More sample data', 34989),
891 foreach ($data as $row) {
892 $query->values(array_combine($fields, $row));