5 * Install setup for the migration example module.
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.
13 * Implements hook_schema().
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();
37 * Implements hook_install().
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();
59 * The hook_schema definition for wine.
62 * The schema definition.
64 function migrate_example_advanced_schema_wine() {
66 'description' => 'Wines of the world',
72 'description' => 'Wine ID',
83 'description' => 'Full description of the wine.',
89 'description' => 'Abstract for this wine.',
95 'description' => 'ID of the author.',
101 'description' => 'Original creation date',
107 'description' => 'Last change date',
113 'description' => 'Wine variety',
119 'description' => 'Wine region',
125 'description' => 'Rating (100-point scale)',
128 'primary key' => ['wineid'],
133 * The hook_schema definition for updates.
136 * The schema definition.
138 function migrate_example_advanced_schema_updates() {
140 'description' => 'Updated wine ratings',
146 'description' => 'Wine ID',
152 'description' => 'Rating (100-point scale)',
155 'primary key' => ['wineid'],
160 * The hook_schema definition for producer.
163 * The schema definition.
165 function migrate_example_advanced_schema_producer() {
167 'description' => 'Wine producers of the world',
173 'description' => 'Producer ID',
184 'description' => 'Full description of the producer.',
190 'description' => 'Abstract for this producer.',
196 'description' => 'Account ID of the author.',
199 'primary key' => ['producerid'],
204 * The hook_schema definition for categories.
207 * The schema definition.
209 function migrate_example_advanced_schema_categories() {
211 'description' => 'Categories',
217 'description' => 'Category ID',
223 'description' => 'Type of category: variety, region, best_with',
235 'category_parent' => [
239 'description' => 'Parent category, if any',
245 'description' => 'Order in which to display categories',
248 'primary key' => ['categoryid'],
253 * The hook_schema definition for vintages.
256 * The schema definition.
258 function migrate_example_advanced_schema_vintages() {
260 'description' => 'Wine vintages',
265 'description' => 'Wine ID',
271 'description' => 'Vintage (year)',
274 'primary key' => ['wineid', 'vintage'],
279 * The hook_schema definition for variety updates.
282 * The schema definition.
284 function migrate_example_advanced_schema_variety_updates() {
286 'description' => 'Variety updates',
292 'description' => 'Category ID',
300 'primary key' => ['categoryid'],
305 * The hook_schema definition for category wine.
308 * The schema definition.
310 function migrate_example_advanced_schema_category_wine() {
312 'description' => 'Wine category assignments',
317 'description' => 'Wine ID',
323 'description' => 'Category ID',
326 'primary key' => ['categoryid', 'wineid'],
331 * The hook_schema definition for category producer.
334 * The schema definition.
336 function migrate_example_advanced_schema_category_producer() {
338 'description' => 'Producer category assignments',
343 'description' => 'Producer ID',
349 'description' => 'Category ID',
352 'primary key' => ['categoryid', 'producerid'],
357 * The hook_schema definition for comment.
360 * The schema definition.
362 function migrate_example_advanced_schema_comment() {
364 'description' => 'Wine comments',
370 'description' => 'Comment ID',
376 'description' => 'Wine ID that is being commented upon',
378 'comment_parent' => [
382 'description' => 'Parent comment ID in case of comment replies.',
388 'description' => 'Comment subject',
394 'description' => 'Comment body',
400 'description' => 'Comment name (if anon)',
406 'description' => 'Comment email (if anon)',
412 'description' => 'Account ID (if any).',
418 'description' => 'IP/domain of host posted from',
424 'description' => 'User homepage',
430 'description' => 'Date comment posted',
436 'description' => 'Date comment last changed',
439 'primary key' => ['commentid'],
444 * The hook_schema definition for comment updates.
447 * The schema definition.
449 function migrate_example_advanced_schema_comment_updates() {
451 'description' => 'Wine comment updates',
457 'description' => 'Comment ID',
463 'description' => 'Comment subject',
466 'primary key' => ['commentid'],
471 * The hook_schema definition for account.
474 * The schema definition.
476 function migrate_example_advanced_schema_account() {
478 'description' => 'Wine accounts.',
483 'description' => 'Account ID',
488 'description' => 'Blocked_Allowed',
494 'description' => 'Registration date',
500 'description' => 'Last access date',
506 'description' => 'Last login date',
512 'description' => 'Account name (for login)',
518 'description' => 'Gender',
524 'description' => 'Account password (raw)',
530 'description' => 'Account email',
536 'description' => 'Original account email',
542 'description' => 'Signature for comments',
548 'description' => 'Image ID',
554 'description' => 'Positions held',
557 'primary key' => ['accountid'],
562 * The hook_schema definition for account updates.
565 * The schema definition.
567 function migrate_example_advanced_schema_account_updates() {
569 'description' => 'Wine account updates',
574 'description' => 'Account ID',
580 'description' => 'Gender',
583 'primary key' => ['accountid'],
588 * The hook_schema definition for blobs.
591 * The schema definition.
593 function migrate_example_advanced_schema_blobs() {
595 'description' => 'Wine blobs to be migrated to file entities',
601 'description' => 'Image ID',
606 'description' => 'binary image data',
609 'primary key' => ['imageid'],
614 * The hook_schema definition for files.
617 * The schema definition.
619 function migrate_example_advanced_schema_files() {
621 'description' => 'Wine and account files',
627 'description' => 'Image ID',
633 'description' => 'Image URL',
639 'description' => 'Image alt',
645 'description' => 'Image title',
651 'description' => 'Wine node this is associated with',
654 'primary key' => ['imageid'],
659 * The hook_schema definition for table source.
662 * The schema definition.
664 function migrate_example_advanced_schema_table_source() {
666 'description' => 'Source data to go into a custom Drupal table',
672 'description' => 'Primary key',
678 'description' => 'First field',
684 'description' => 'Second field',
687 'primary key' => ['fooid'],
692 * The hook_schema definition for table destination.
695 * The schema definition.
697 function migrate_example_advanced_schema_table_dest() {
699 'description' => 'Custom Drupal table to receive source data directly',
705 'description' => 'Primary key',
711 'description' => 'First field',
717 'description' => 'Second field',
720 'primary key' => ['recordid'],
725 * Populate wine table.
727 function migrate_example_advanced_data_wine() {
740 $query = db_insert('migrate_example_wine')
745 'Montes Classic Cabernet Sauvignon',
746 'Intense ruby-red color',
749 strtotime('2010-01-02 03:04:05'),
750 strtotime('2010-03-04 05:06:07'),
757 'Archeo Ruggero di Tasso Nero d\'Avola',
758 'Lots of berry character',
759 'Pair with red sauced dishes',
761 strtotime('2010-09-03 18:23:58'),
762 strtotime('2010-09-03 18:23:58'),
768 foreach ($data as $row) {
769 $query->values(array_combine($fields, $row));
775 * Populate updates table.
777 function migrate_example_advanced_data_updates() {
778 $fields = ['wineid', 'rating'];
779 $query = db_insert('migrate_example_advanced_updates')
785 foreach ($data as $row) {
786 $query->values(array_combine($fields, $row));
792 * Populate producer table.
794 function migrate_example_advanced_data_producer() {
795 $fields = ['producerid', 'name', 'body', 'excerpt', 'accountid'];
796 $query = db_insert('migrate_example_advanced_producer')
799 [1, 'Montes', 'Fine Chilean winery', 'Great!', 9],
800 [2, 'Archeo', 'Sicilia!', NULL, 3],
802 foreach ($data as $row) {
803 $query->values(array_combine($fields, $row));
809 * Populate account table.
811 function migrate_example_advanced_data_account() {
827 $query = db_insert('migrate_example_advanced_account')
833 '2010-03-30 10:31:05',
834 '2010-04-30 18:25:24',
835 '2010-04-30 14:01:02',
839 'ddarren@example.com',
840 'darren@example.com',
841 'All about the Australians',
848 '2007-03-15 10:31:05',
849 '2007-06-10 04:11:38',
850 '2007-06-10 04:11:38',
856 'Sommelier to the stars',
863 '2004-02-29 10:31:05',
864 '2004-02-29 10:31:05',
865 '2004-02-29 10:31:05',
869 'thefonz@example.com',
870 'arthur@example.com',
876 foreach ($data as $row) {
877 $query->values(array_combine($fields, $row));
883 * Populate account updates table.
885 function migrate_example_advanced_data_account_updates() {
886 $fields = ['accountid', 'sex'];
887 $query = db_insert('migrate_example_advanced_account_updates')
894 foreach ($data as $row) {
895 $query->values(array_combine($fields, $row));
901 * Populate comment table.
903 function migrate_example_advanced_data_comment() {
918 $query = db_insert('migrate_example_advanced_comment')
931 'http:://grace.example.com/',
932 strtotime('2010-01-02 03:04:05'),
933 strtotime('2010-04-05 06:07:08'),
942 'horace@example.com',
946 strtotime('2010-02-02 03:04:05'),
947 strtotime('2010-05-05 06:07:08'),
954 'Don\'t care for it',
959 'http:://www.example.com/irene',
960 strtotime('2010-03-02 03:04:05'),
961 strtotime('2010-03-02 03:04:05'),
968 'But it\'s so good!',
973 'http:://www.wine.com/',
974 strtotime('2010-01-02 03:04:05'),
975 strtotime('2010-01-02 03:04:05'),
983 'thefonz@example.com',
988 strtotime('2010-06-02 03:04:05'),
989 strtotime('2010-06-02 03:04:05'),
992 foreach ($data as $row) {
993 $query->values(array_combine($fields, $row));
999 * Populate comment updates table.
1001 function migrate_example_advanced_data_comment_updates() {
1002 $fields = ['commentid', 'subject'];
1003 $query = db_insert('migrate_example_advanced_comment_updates')
1010 [5, 'I am Spartacus'],
1012 foreach ($data as $row) {
1013 $query->values(array_combine($fields, $row));
1019 * Populate categories table.
1021 function migrate_example_advanced_data_categories() {
1030 $query = db_insert('migrate_example_advanced_categories')
1038 'White wines are generally simpler and sweeter than red',
1046 'Red wines are generally more complex and "dry" than white',
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],
1071 foreach ($data as $row) {
1072 $query->values(array_combine($fields, $row));
1078 * Populate vintages table.
1080 function migrate_example_advanced_data_vintages() {
1081 $fields = ['wineid', 'vintage'];
1082 $query = db_insert('migrate_example_advanced_vintages')
1089 foreach ($data as $row) {
1090 $query->values(array_combine($fields, $row));
1096 * Populate variety updates table.
1098 function migrate_example_advanced_data_variety_updates() {
1099 $fields = ['categoryid', 'details'];
1100 $query = db_insert('migrate_example_advanced_variety_updates')
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'],
1107 [13, 'Common, very drinakable'],
1110 [26, 'A specialty of Sicily'],
1112 foreach ($data as $row) {
1113 $query->values(array_combine($fields, $row));
1119 * Populate category wine table.
1121 function migrate_example_advanced_data_category_wine() {
1122 $fields = ['wineid', 'categoryid'];
1123 $query = db_insert('migrate_example_advanced_category_wine')
1130 foreach ($data as $row) {
1131 $query->values(array_combine($fields, $row));
1137 * Populate category producer table.
1139 function migrate_example_advanced_data_category_producer() {
1140 $fields = ['producerid', 'categoryid'];
1141 $query = db_insert('migrate_example_advanced_category_producer')
1146 foreach ($data as $row) {
1147 $query->values(array_combine($fields, $row));
1153 * Populate files table.
1155 function migrate_example_advanced_data_files() {
1156 $fields = ['imageid', 'url', 'image_alt', 'image_title', 'wineid'];
1157 $query = db_insert('migrate_example_advanced_files')
1162 'http://placekitten.com/200/200',
1169 'http://cyrve.com/files/penguin.jpeg',
1174 [3, 'http://cyrve.com/files/rioja.jpeg', 'Rioja alt', 'Rioja title', 2],
1177 'http://cyrve.com/files/boutisse_0.jpeg',
1183 foreach ($data as $row) {
1184 $query->values(array_combine($fields, $row));
1190 * Populate blobs table.
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')
1200 foreach ($data as $row) {
1201 $query->values(array_combine($fields, $row));
1207 * Populate table source table.
1209 function migrate_example_advanced_data_table_source() {
1210 $fields = ['fooid', 'field1', 'field2'];
1211 $query = db_insert('migrate_example_advanced_table_source')
1214 [3, 'Some sample data', 58],
1215 [15, 'Whatever', 2],
1216 [646, 'More sample data', 34989],
1218 foreach ($data as $row) {
1219 $query->values(array_combine($fields, $row));