Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / migrate_plus / migrate_example / migrate_example_setup / migrate_example_setup.install
1 <?php
2
3 /**
4  * @file
5  * Install file for migrate 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 itself is a pure
9  * migration module.
10  */
11
12 /**
13  * Implements hook_schema().
14  */
15 function migrate_example_setup_schema() {
16   $schema['migrate_example_beer_account'] = migrate_example_beer_schema_account();
17   $schema['migrate_example_beer_node'] = migrate_example_beer_schema_node();
18   $schema['migrate_example_beer_comment'] = migrate_example_beer_schema_comment();
19   $schema['migrate_example_beer_topic'] = migrate_example_beer_schema_topic();
20   $schema['migrate_example_beer_topic_node'] = migrate_example_beer_schema_topic_node();
21
22   return $schema;
23 }
24
25 /**
26  * Implements hook_install().
27  */
28 function migrate_example_setup_install() {
29   // Populate our tables.
30   migrate_example_beer_data_account();
31   migrate_example_beer_data_node();
32   migrate_example_beer_data_comment();
33   migrate_example_beer_data_topic();
34   migrate_example_beer_data_topic_node();
35 }
36
37 /**
38  * The hook_schema definition for node.
39  *
40  * @return array
41  *   The schema definition.
42  */
43 function migrate_example_beer_schema_node() {
44   return [
45     'description' => 'Beers of the world.',
46     'fields' => [
47       'bid'  => [
48         'type' => 'serial',
49         'not null' => TRUE,
50         'description' => 'Beer ID.',
51       ],
52       'name'  => [
53         'type' => 'varchar',
54         'length' => 255,
55         'not null' => TRUE,
56       ],
57       'body' => [
58         'type' => 'varchar',
59         'length' => 255,
60         'not null' => FALSE,
61         'description' => 'Full description of the beer.',
62       ],
63       'excerpt' => [
64         'type' => 'varchar',
65         'length' => 255,
66         'not null' => FALSE,
67         'description' => 'Abstract for this beer.',
68       ],
69       'countries' => [
70         'type' => 'varchar',
71         'length' => 255,
72         'not null' => FALSE,
73         'description' => 'Countries of origin. Multiple values, delimited by pipe',
74       ],
75       'aid' => [
76         'type' => 'int',
77         'not null' => FALSE,
78         'description' => 'Account Id of the author.',
79       ],
80       'image' => [
81         'type' => 'varchar',
82         'length' => 255,
83         'not null' => FALSE,
84         'description' => 'Image path',
85       ],
86       'image_alt' => [
87         'type' => 'varchar',
88         'length' => 255,
89         'not null' => FALSE,
90         'description' => 'Image ALT',
91       ],
92       'image_title' => [
93         'type' => 'varchar',
94         'length' => 255,
95         'not null' => FALSE,
96         'description' => 'Image title',
97       ],
98       'image_description' => [
99         'type' => 'varchar',
100         'length' => 255,
101         'not null' => FALSE,
102         'description' => 'Image description',
103       ],
104     ],
105     'primary key' => ['bid'],
106   ];
107 }
108
109 /**
110  * The hook_schema definition for topic.
111  *
112  * @return array
113  *   The schema definition.
114  */
115 function migrate_example_beer_schema_topic() {
116   return [
117     'description' => 'Categories',
118     'fields' => [
119       'style'  => [
120         'type' => 'varchar_ascii',
121         'length' => 255,
122         'not null' => TRUE,
123       ],
124       'details' => [
125         'type' => 'varchar',
126         'length' => 255,
127         'not null' => FALSE,
128       ],
129       'style_parent' => [
130         'type' => 'varchar',
131         'length' => 255,
132         'not null' => FALSE,
133         'description' => 'Parent topic, if any',
134       ],
135       'region' => [
136         'type' => 'varchar',
137         'length' => 255,
138         'not null' => FALSE,
139         'description' => 'Region first associated with this style',
140       ],
141       'hoppiness' => [
142         'type' => 'varchar',
143         'length' => 255,
144         'not null' => FALSE,
145         'description' => 'Relative hoppiness of the beer',
146       ],
147     ],
148     'primary key' => ['style'],
149   ];
150 }
151
152 /**
153  * The hook_schema definition for topic node.
154  *
155  * @return array
156  *   The schema definition.
157  */
158 function migrate_example_beer_schema_topic_node() {
159   return [
160     'description' => 'Beers topic pairs.',
161     'fields' => [
162       'bid'  => [
163         'type' => 'int',
164         'not null' => TRUE,
165         'description' => 'Beer ID.',
166       ],
167       'style'  => [
168         'type' => 'varchar_ascii',
169         'length' => 255,
170         'not null' => TRUE,
171         'description' => 'Topic name',
172       ],
173     ],
174     'primary key' => ['style', 'bid'],
175   ];
176 }
177
178 /**
179  * The hook_schema definition for comment.
180  *
181  * @return array
182  *   The schema definition.
183  */
184 function migrate_example_beer_schema_comment() {
185   return [
186     'description' => 'Beers comments.',
187     'fields' => [
188       'cid'  => [
189         'type' => 'serial',
190         'not null' => TRUE,
191         'description' => 'Comment ID.',
192       ],
193       'bid'  => [
194         'type' => 'int',
195         'not null' => TRUE,
196         'description' => 'Beer ID that is being commented upon',
197       ],
198       'cid_parent' => [
199         'type' => 'int',
200         'not null' => FALSE,
201         'description' => 'Parent comment ID in case of comment replies.',
202       ],
203       'subject' => [
204         'type' => 'varchar',
205         'length' => 255,
206         'not null' => FALSE,
207         'description' => 'Comment subject',
208       ],
209       'body' => [
210         'type' => 'varchar',
211         'length' => 255,
212         'not null' => FALSE,
213         'description' => 'Comment body',
214       ],
215       'name' => [
216         'type' => 'varchar',
217         'length' => 255,
218         'not null' => FALSE,
219         'description' => 'Comment name (if anon)',
220       ],
221       'mail' => [
222         'type' => 'varchar',
223         'length' => 255,
224         'not null' => FALSE,
225         'description' => 'Comment email (if anon)',
226       ],
227       'aid' => [
228         'type' => 'int',
229         'not null' => FALSE,
230         'description' => 'Account ID (if any).',
231       ],
232     ],
233     'primary key' => ['cid'],
234   ];
235 }
236
237 /**
238  * The hook_schema definition for account.
239  *
240  * @return array
241  *   The schema definition.
242  */
243 function migrate_example_beer_schema_account() {
244   return [
245     'description' => 'Beers accounts.',
246     'fields' => [
247       'aid'  => [
248         'type' => 'serial',
249         'not null' => TRUE,
250         'description' => 'Account ID',
251       ],
252       'status'  => [
253         'type' => 'int',
254         'not null' => TRUE,
255         'description' => 'Blocked_Allowed',
256       ],
257       'registered' => [
258         'type' => 'varchar',
259         'length' => 255,
260         'not null' => TRUE,
261         'description' => 'Registration date',
262       ],
263       'username' => [
264         'type' => 'varchar',
265         'length' => 255,
266         'not null' => FALSE,
267         'description' => 'Account name (for login)',
268       ],
269       'nickname' => [
270         'type' => 'varchar',
271         'length' => 255,
272         'not null' => FALSE,
273         'description' => 'Account name (for display)',
274       ],
275       'password' => [
276         'type' => 'varchar',
277         'length' => 255,
278         'not null' => FALSE,
279         'description' => 'Account password (raw)',
280       ],
281       'email' => [
282         'type' => 'varchar',
283         'length' => 255,
284         'not null' => FALSE,
285         'description' => 'Account email',
286       ],
287       'sex' => [
288         'type' => 'int',
289         'not null' => FALSE,
290         'description' => 'Gender (0 for male, 1 for female)',
291       ],
292       'beers' => [
293         'type' => 'varchar',
294         'length' => 255,
295         'not null' => FALSE,
296         'description' => 'Favorite Beers',
297       ],
298     ],
299     'primary key' => ['aid'],
300   ];
301 }
302
303 /**
304  * Populate node table.
305  */
306 function migrate_example_beer_data_node() {
307   $fields = [
308     'bid',
309     'name',
310     'body',
311     'excerpt',
312     'countries',
313     'aid',
314     'image',
315     'image_alt',
316     'image_title',
317     'image_description',
318   ];
319   $query = db_insert('migrate_example_beer_node')
320     ->fields($fields);
321   // Use high bid numbers to avoid overwriting an existing node id.
322   $data = [
323     // Comes with migrate_example project.
324     [
325       99999999,
326       'Heineken',
327       'Blab Blah Blah Green',
328       'Green',
329       'Netherlands|Belgium',
330       0,
331       'heineken.jpg',
332       'Heinekin alt',
333       'Heinekin title',
334       'Heinekin description',
335     ],
336     [
337       99999998,
338       'Miller Lite',
339       'We love Miller Brewing',
340       'Tasteless',
341       'USA|Canada',
342       1,
343       NULL,
344       NULL,
345       NULL,
346       NULL,
347     ],
348     [
349       99999997,
350       'Boddington',
351       'English occasionally get something right',
352       'A treat',
353       'United Kingdom',
354       1,
355       NULL,
356       NULL,
357       NULL,
358       NULL,
359     ],
360   ];
361   foreach ($data as $row) {
362     $query->values(array_combine($fields, $row));
363   }
364   $query->execute();
365 }
366
367 /**
368  * Populate account table.
369  *
370  * Note that alice has duplicate username. Exercises dedupe_entity plugin.
371  * TODO duplicate email also.
372  */
373 function migrate_example_beer_data_account() {
374   $fields = [
375     'status',
376     'registered',
377     'username',
378     'nickname',
379     'password',
380     'email',
381     'sex',
382     'beers',
383   ];
384   $query = db_insert('migrate_example_beer_account')
385     ->fields($fields);
386   $data = [
387     [
388       1,
389       '2010-03-30 10:31:05',
390       'alice',
391       'alice in beerland',
392       'alicepass',
393       'alice@example.com',
394       '1',
395       '99999999|99999998|99999997',
396     ],
397     [
398       1,
399       '2010-04-04 10:31:05',
400       'alice',
401       'alice in aleland',
402       'alicepass',
403       'alice2@example.com',
404       '1',
405       '99999999|99999998|99999997',
406     ],
407     [
408       0,
409       '2007-03-15 10:31:05',
410       'bob',
411       'rebob',
412       'bobpass',
413       'bob@example.com',
414       '0',
415       '99999999|99999997',
416     ],
417     [
418       1,
419       '2004-02-29 10:31:05',
420       'charlie',
421       'charlie chocolate',
422       'mykids',
423       'charlie@example.com',
424       '0',
425       '99999999|99999998',
426     ],
427   ];
428   foreach ($data as $row) {
429     $query->values(array_combine($fields, $row));
430   }
431   $query->execute();
432 }
433
434 /**
435  * Populate comment table.
436  */
437 function migrate_example_beer_data_comment() {
438   $fields = ['bid', 'cid_parent', 'subject', 'body', 'name', 'mail', 'aid'];
439   $query = db_insert('migrate_example_beer_comment')
440     ->fields($fields);
441   $data = [
442     [99999998, NULL, 'im first', 'full body', 'alice', 'alice@example.com', 0],
443     [99999998, NULL, 'im second', 'aromatic', 'alice', 'alice@example.com', 0],
444     [99999999, NULL, 'im parent', 'malty', 'alice', 'alice@example.com', 0],
445     [99999999, 1, 'im child', 'cold body', 'bob', NULL, 1],
446     [
447       99999999,
448       4,
449       'im grandchild',
450       'bitter body',
451       'charlie@example.com',
452       NULL,
453       1,
454     ],
455   ];
456   foreach ($data as $row) {
457     $query->values(array_combine($fields, $row));
458   }
459   $query->execute();
460 }
461
462 /**
463  * Populate topic table.
464  */
465 function migrate_example_beer_data_topic() {
466   $fields = ['style', 'details', 'style_parent', 'region', 'hoppiness'];
467   $query = db_insert('migrate_example_beer_topic')
468     ->fields($fields);
469   $data = [
470     ['ale', 'traditional', NULL, 'Medieval British Isles', 'Medium'],
471     ['red ale', 'colorful', 'ale', NULL, NULL],
472     [
473       'pilsner',
474       'refreshing',
475       NULL,
476       'Pilsen, Bohemia (now Czech Republic)',
477       'Low',
478     ],
479   ];
480   foreach ($data as $row) {
481     $query->values(array_combine($fields, $row));
482   }
483   $query->execute();
484 }
485
486 /**
487  * Populate topic node table.
488  */
489 function migrate_example_beer_data_topic_node() {
490   $fields = ['bid', 'style'];
491   $query = db_insert('migrate_example_beer_topic_node')
492     ->fields($fields);
493   $data = [
494     [99999999, 'pilsner'],
495     [99999999, 'red ale'],
496     [99999998, 'red ale'],
497   ];
498   foreach ($data as $row) {
499     $query->values(array_combine($fields, $row));
500   }
501   $query->execute();
502 }