a8bda30881f34784107489dd90c10b89ddba1d3e
[yaffs-website] / web / modules / contrib / migrate_plus / migrate_example / migrate_example_setup / migrate_example_setup.install
1 <?php
2
3 /**
4  * @file
5  * Set up source data and destination configuration for the migration example
6  * module. We do this in a separate module so migrate_example itself is a pure
7  * migration module.
8  */
9
10 function migrate_example_setup_schema() {
11   $schema['migrate_example_beer_account'] = migrate_example_beer_schema_account();
12   $schema['migrate_example_beer_node'] = migrate_example_beer_schema_node();
13   $schema['migrate_example_beer_comment'] = migrate_example_beer_schema_comment();
14   $schema['migrate_example_beer_topic'] = migrate_example_beer_schema_topic();
15   $schema['migrate_example_beer_topic_node'] = migrate_example_beer_schema_topic_node();
16
17   return $schema;
18 }
19
20 function migrate_example_setup_install() {
21   // Populate our tables.
22   migrate_example_beer_data_account();
23   migrate_example_beer_data_node();
24   migrate_example_beer_data_comment();
25   migrate_example_beer_data_topic();
26   migrate_example_beer_data_topic_node();
27 }
28
29 function migrate_example_beer_schema_node() {
30   return array(
31     'description' => 'Beers of the world.',
32     'fields' => array(
33       'bid'  => array(
34         'type' => 'serial',
35         'not null' => TRUE,
36         'description' => 'Beer ID.',
37       ),
38       'name'  => array(
39         'type' => 'varchar',
40         'length' => 255,
41         'not null' => TRUE,
42       ),
43       'body' => array(
44         'type' => 'varchar',
45         'length' => 255,
46         'not null' => FALSE,
47         'description' => 'Full description of the beer.',
48       ),
49       'excerpt' => array(
50         'type' => 'varchar',
51         'length' => 255,
52         'not null' => FALSE,
53         'description' => 'Abstract for this beer.',
54       ),
55       'countries' => array(
56         'type' => 'varchar',
57         'length' => 255,
58         'not null' => FALSE,
59         'description' => 'Countries of origin. Multiple values, delimited by pipe',
60       ),
61       'aid' => array(
62         'type' => 'int',
63         'not null' => FALSE,
64         'description' => 'Account Id of the author.',
65       ),
66       'image' => array(
67         'type' => 'varchar',
68         'length' => 255,
69         'not null' => FALSE,
70         'description' => 'Image path',
71       ),
72       'image_alt' => array(
73         'type' => 'varchar',
74         'length' => 255,
75         'not null' => FALSE,
76         'description' => 'Image ALT',
77       ),
78       'image_title' => array(
79         'type' => 'varchar',
80         'length' => 255,
81         'not null' => FALSE,
82         'description' => 'Image title',
83       ),
84       'image_description' => array(
85         'type' => 'varchar',
86         'length' => 255,
87         'not null' => FALSE,
88         'description' => 'Image description',
89       ),
90     ),
91     'primary key' => array('bid'),
92   );
93 }
94
95 function migrate_example_beer_schema_topic() {
96   return array(
97     'description' => 'Categories',
98     'fields' => array(
99       'style'  => array(
100         'type' => 'varchar_ascii',
101         'length' => 255,
102         'not null' => TRUE,
103       ),
104       'details' => array(
105         'type' => 'varchar',
106         'length' => 255,
107         'not null' => FALSE,
108       ),
109       'style_parent' => array(
110         'type' => 'varchar',
111         'length' => 255,
112         'not null' => FALSE,
113         'description' => 'Parent topic, if any',
114       ),
115       'region' => array(
116         'type' => 'varchar',
117         'length' => 255,
118         'not null' => FALSE,
119         'description' => 'Region first associated with this style',
120       ),
121       'hoppiness' => array(
122         'type' => 'varchar',
123         'length' => 255,
124         'not null' => FALSE,
125         'description' => 'Relative hoppiness of the beer',
126       ),
127     ),
128     'primary key' => array('style'),
129   );
130 }
131
132 function migrate_example_beer_schema_topic_node() {
133   return array(
134     'description' => 'Beers topic pairs.',
135     'fields' => array(
136       'bid'  => array(
137         'type' => 'int',
138         'not null' => TRUE,
139         'description' => 'Beer ID.',
140       ),
141       'style'  => array(
142         'type' => 'varchar_ascii',
143         'length' => 255,
144         'not null' => TRUE,
145         'description' => 'Topic name',
146       ),
147     ),
148     'primary key' => array('style', 'bid'),
149   );
150 }
151
152 function migrate_example_beer_schema_comment() {
153   return array(
154     'description' => 'Beers comments.',
155     'fields' => array(
156       'cid'  => array(
157         'type' => 'serial',
158         'not null' => TRUE,
159         'description' => 'Comment ID.',
160       ),
161       'bid'  => array(
162         'type' => 'int',
163         'not null' => TRUE,
164         'description' => 'Beer ID that is being commented upon',
165       ),
166       'cid_parent' => array(
167         'type' => 'int',
168         'not null' => FALSE,
169         'description' => 'Parent comment ID in case of comment replies.',
170       ),
171       'subject' => array(
172         'type' => 'varchar',
173         'length' => 255,
174         'not null' => FALSE,
175         'description' => 'Comment subject',
176       ),
177       'body' => array(
178         'type' => 'varchar',
179         'length' => 255,
180         'not null' => FALSE,
181         'description' => 'Comment body',
182       ),
183       'name' => array(
184         'type' => 'varchar',
185         'length' => 255,
186         'not null' => FALSE,
187         'description' => 'Comment name (if anon)',
188       ),
189       'mail' => array(
190         'type' => 'varchar',
191         'length' => 255,
192         'not null' => FALSE,
193         'description' => 'Comment email (if anon)',
194       ),
195       'aid' => array(
196         'type' => 'int',
197         'not null' => FALSE,
198         'description' => 'Account ID (if any).',
199       ),
200     ),
201     'primary key' => array('cid'),
202   );
203 }
204
205 function migrate_example_beer_schema_account() {
206   return array(
207     'description' => 'Beers accounts.',
208     'fields' => array(
209       'aid'  => array(
210         'type' => 'serial',
211         'not null' => TRUE,
212         'description' => 'Account ID',
213       ),
214       'status'  => array(
215         'type' => 'int',
216         'not null' => TRUE,
217         'description' => 'Blocked_Allowed',
218       ),
219       'registered' => array(
220         'type' => 'varchar',
221         'length' => 255,
222         'not null' => TRUE,
223         'description' => 'Registration date',
224       ),
225       'username' => array(
226         'type' => 'varchar',
227         'length' => 255,
228         'not null' => FALSE,
229         'description' => 'Account name (for login)',
230       ),
231       'nickname' => array(
232         'type' => 'varchar',
233         'length' => 255,
234         'not null' => FALSE,
235         'description' => 'Account name (for display)',
236       ),
237       'password' => array(
238         'type' => 'varchar',
239         'length' => 255,
240         'not null' => FALSE,
241         'description' => 'Account password (raw)',
242       ),
243       'email' => array(
244         'type' => 'varchar',
245         'length' => 255,
246         'not null' => FALSE,
247         'description' => 'Account email',
248       ),
249       'sex' => array(
250         'type' => 'int',
251         'not null' => FALSE,
252         'description' => 'Gender (0 for male, 1 for female)',
253       ),
254       'beers' => array(
255         'type' => 'varchar',
256         'length' => 255,
257         'not null' => FALSE,
258         'description' => 'Favorite Beers',
259       ),
260     ),
261     'primary key' => array('aid'),
262   );
263 }
264
265 function migrate_example_beer_data_node() {
266   $fields = array('bid', 'name', 'body', 'excerpt', 'countries', 'aid', 'image',
267     'image_alt', 'image_title', 'image_description');
268   $query = db_insert('migrate_example_beer_node')
269            ->fields($fields);
270   // Use high bid numbers to avoid overwriting an existing node id.
271   $data = array(
272     array(99999999, 'Heineken', 'Blab Blah Blah Green', 'Green', 'Netherlands|Belgium', 0, 'heineken.jpg', 'Heinekin alt', 'Heinekin title', 'Heinekin description'), // comes with migrate_example project.
273     array(99999998, 'Miller Lite', 'We love Miller Brewing', 'Tasteless', 'USA|Canada', 1, NULL, NULL, NULL, NULL),
274     array(99999997, 'Boddington', 'English occasionally get something right', 'A treat', 'United Kingdom', 1, NULL, NULL, NULL, NULL),
275   );
276   foreach ($data as $row) {
277     $query->values(array_combine($fields, $row));
278   }
279   $query->execute();
280 }
281
282 // Note that alice has duplicate username. Exercises dedupe_entity plugin.
283 // @TODO duplicate email also.
284 function migrate_example_beer_data_account() {
285   $fields = array('status', 'registered', 'username', 'nickname', 'password', 'email', 'sex', 'beers');
286   $query = db_insert('migrate_example_beer_account')
287     ->fields($fields);
288   $data = array(
289     array(1, '2010-03-30 10:31:05', 'alice', 'alice in beerland', 'alicepass', 'alice@example.com', '1', '99999999|99999998|99999997'),
290     array(1, '2010-04-04 10:31:05', 'alice', 'alice in aleland', 'alicepass', 'alice2@example.com', '1', '99999999|99999998|99999997'),
291     array(0, '2007-03-15 10:31:05', 'bob', 'rebob', 'bobpass', 'bob@example.com', '0', '99999999|99999997'),
292     array(1, '2004-02-29 10:31:05', 'charlie', 'charlie chocolate', 'mykids', 'charlie@example.com', '0', '99999999|99999998'),
293   );
294   foreach ($data as $row) {
295     $query->values(array_combine($fields, $row));
296   }
297   $query->execute();
298 }
299
300 function migrate_example_beer_data_comment() {
301   $fields = array('bid', 'cid_parent', 'subject', 'body', 'name', 'mail', 'aid');
302   $query = db_insert('migrate_example_beer_comment')
303     ->fields($fields);
304   $data = array(
305     array(99999998, NULL, 'im first', 'full body', 'alice', 'alice@example.com', 0),
306     array(99999998, NULL, 'im second', 'aromatic', 'alice', 'alice@example.com', 0),
307     array(99999999, NULL, 'im parent', 'malty', 'alice', 'alice@example.com', 0),
308     array(99999999, 1, 'im child', 'cold body', 'bob', NULL, 1),
309     array(99999999, 4, 'im grandchild', 'bitter body', 'charlie@example.com', NULL, 1),
310   );
311   foreach ($data as $row) {
312     $query->values(array_combine($fields, $row));
313   }
314   $query->execute();
315 }
316
317 function migrate_example_beer_data_topic() {
318   $fields = array('style', 'details', 'style_parent', 'region', 'hoppiness');
319   $query = db_insert('migrate_example_beer_topic')
320     ->fields($fields);
321   $data = array(
322     array('ale', 'traditional', NULL, 'Medieval British Isles', 'Medium'),
323     array('red ale', 'colorful', 'ale', NULL, NULL),
324     array('pilsner', 'refreshing', NULL, 'Pilsen, Bohemia (now Czech Republic)', 'Low'),
325   );
326   foreach ($data as $row) {
327     $query->values(array_combine($fields, $row));
328   }
329   $query->execute();
330 }
331
332 function migrate_example_beer_data_topic_node() {
333   $fields = array('bid', 'style');
334   $query = db_insert('migrate_example_beer_topic_node')
335     ->fields($fields);
336   $data = array(
337     array(99999999, 'pilsner'),
338     array(99999999, 'red ale'),
339     array(99999998, 'red ale'),
340   );
341   foreach ($data as $row) {
342     $query->values(array_combine($fields, $row));
343   }
344   $query->execute();
345 }