5 * Install file for migrate 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 itself is a pure
13 * Implements hook_schema().
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();
26 * Implements hook_install().
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();
38 * The hook_schema definition for node.
41 * The schema definition.
43 function migrate_example_beer_schema_node() {
45 'description' => 'Beers of the world.',
50 'description' => 'Beer ID.',
61 'description' => 'Full description of the beer.',
67 'description' => 'Abstract for this beer.',
73 'description' => 'Countries of origin. Multiple values, delimited by pipe',
78 'description' => 'Account Id of the author.',
84 'description' => 'Image path',
90 'description' => 'Image ALT',
96 'description' => 'Image title',
98 'image_description' => [
102 'description' => 'Image description',
105 'primary key' => ['bid'],
110 * The hook_schema definition for topic.
113 * The schema definition.
115 function migrate_example_beer_schema_topic() {
117 'description' => 'Categories',
120 'type' => 'varchar_ascii',
133 'description' => 'Parent topic, if any',
139 'description' => 'Region first associated with this style',
145 'description' => 'Relative hoppiness of the beer',
148 'primary key' => ['style'],
153 * The hook_schema definition for topic node.
156 * The schema definition.
158 function migrate_example_beer_schema_topic_node() {
160 'description' => 'Beers topic pairs.',
165 'description' => 'Beer ID.',
168 'type' => 'varchar_ascii',
171 'description' => 'Topic name',
174 'primary key' => ['style', 'bid'],
179 * The hook_schema definition for comment.
182 * The schema definition.
184 function migrate_example_beer_schema_comment() {
186 'description' => 'Beers comments.',
191 'description' => 'Comment ID.',
196 'description' => 'Beer ID that is being commented upon',
201 'description' => 'Parent comment ID in case of comment replies.',
207 'description' => 'Comment subject',
213 'description' => 'Comment body',
219 'description' => 'Comment name (if anon)',
225 'description' => 'Comment email (if anon)',
230 'description' => 'Account ID (if any).',
233 'primary key' => ['cid'],
238 * The hook_schema definition for account.
241 * The schema definition.
243 function migrate_example_beer_schema_account() {
245 'description' => 'Beers accounts.',
250 'description' => 'Account ID',
255 'description' => 'Blocked_Allowed',
261 'description' => 'Registration date',
267 'description' => 'Account name (for login)',
273 'description' => 'Account name (for display)',
279 'description' => 'Account password (raw)',
285 'description' => 'Account email',
290 'description' => 'Gender (0 for male, 1 for female)',
296 'description' => 'Favorite Beers',
299 'primary key' => ['aid'],
304 * Populate node table.
306 function migrate_example_beer_data_node() {
319 $query = db_insert('migrate_example_beer_node')
321 // Use high bid numbers to avoid overwriting an existing node id.
323 // Comes with migrate_example project.
327 'Blab Blah Blah Green',
329 'Netherlands|Belgium',
334 'Heinekin description',
339 'We love Miller Brewing',
351 'English occasionally get something right',
361 foreach ($data as $row) {
362 $query->values(array_combine($fields, $row));
368 * Populate account table.
370 * Note that alice has duplicate username. Exercises dedupe_entity plugin.
371 * TODO duplicate email also.
373 function migrate_example_beer_data_account() {
384 $query = db_insert('migrate_example_beer_account')
389 '2010-03-30 10:31:05',
395 '99999999|99999998|99999997',
399 '2010-04-04 10:31:05',
403 'alice2@example.com',
405 '99999999|99999998|99999997',
409 '2007-03-15 10:31:05',
419 '2004-02-29 10:31:05',
423 'charlie@example.com',
428 foreach ($data as $row) {
429 $query->values(array_combine($fields, $row));
435 * Populate comment table.
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')
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],
451 'charlie@example.com',
456 foreach ($data as $row) {
457 $query->values(array_combine($fields, $row));
463 * Populate topic table.
465 function migrate_example_beer_data_topic() {
466 $fields = ['style', 'details', 'style_parent', 'region', 'hoppiness'];
467 $query = db_insert('migrate_example_beer_topic')
470 ['ale', 'traditional', NULL, 'Medieval British Isles', 'Medium'],
471 ['red ale', 'colorful', 'ale', NULL, NULL],
476 'Pilsen, Bohemia (now Czech Republic)',
480 foreach ($data as $row) {
481 $query->values(array_combine($fields, $row));
487 * Populate topic node table.
489 function migrate_example_beer_data_topic_node() {
490 $fields = ['bid', 'style'];
491 $query = db_insert('migrate_example_beer_topic_node')
494 [99999999, 'pilsner'],
495 [99999999, 'red ale'],
496 [99999998, 'red ale'],
498 foreach ($data as $row) {
499 $query->values(array_combine($fields, $row));