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
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();
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();
29 function migrate_example_beer_schema_node() {
31 'description' => 'Beers of the world.',
36 'description' => 'Beer ID.',
47 'description' => 'Full description of the beer.',
53 'description' => 'Abstract for this beer.',
59 'description' => 'Countries of origin. Multiple values, delimited by pipe',
64 'description' => 'Account Id of the author.',
70 'description' => 'Image path',
76 'description' => 'Image ALT',
78 'image_title' => array(
82 'description' => 'Image title',
84 'image_description' => array(
88 'description' => 'Image description',
91 'primary key' => array('bid'),
95 function migrate_example_beer_schema_topic() {
97 'description' => 'Categories',
100 'type' => 'varchar_ascii',
109 'style_parent' => array(
113 'description' => 'Parent topic, if any',
119 'description' => 'Region first associated with this style',
121 'hoppiness' => array(
125 'description' => 'Relative hoppiness of the beer',
128 'primary key' => array('style'),
132 function migrate_example_beer_schema_topic_node() {
134 'description' => 'Beers topic pairs.',
139 'description' => 'Beer ID.',
142 'type' => 'varchar_ascii',
145 'description' => 'Topic name',
148 'primary key' => array('style', 'bid'),
152 function migrate_example_beer_schema_comment() {
154 'description' => 'Beers comments.',
159 'description' => 'Comment ID.',
164 'description' => 'Beer ID that is being commented upon',
166 'cid_parent' => array(
169 'description' => 'Parent comment ID in case of comment replies.',
175 'description' => 'Comment subject',
181 'description' => 'Comment body',
187 'description' => 'Comment name (if anon)',
193 'description' => 'Comment email (if anon)',
198 'description' => 'Account ID (if any).',
201 'primary key' => array('cid'),
205 function migrate_example_beer_schema_account() {
207 'description' => 'Beers accounts.',
212 'description' => 'Account ID',
217 'description' => 'Blocked_Allowed',
219 'registered' => array(
223 'description' => 'Registration date',
229 'description' => 'Account name (for login)',
235 'description' => 'Account name (for display)',
241 'description' => 'Account password (raw)',
247 'description' => 'Account email',
252 'description' => 'Gender (0 for male, 1 for female)',
258 'description' => 'Favorite Beers',
261 'primary key' => array('aid'),
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')
270 // Use high bid numbers to avoid overwriting an existing node id.
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),
276 foreach ($data as $row) {
277 $query->values(array_combine($fields, $row));
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')
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'),
294 foreach ($data as $row) {
295 $query->values(array_combine($fields, $row));
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')
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),
311 foreach ($data as $row) {
312 $query->values(array_combine($fields, $row));
317 function migrate_example_beer_data_topic() {
318 $fields = array('style', 'details', 'style_parent', 'region', 'hoppiness');
319 $query = db_insert('migrate_example_beer_topic')
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'),
326 foreach ($data as $row) {
327 $query->values(array_combine($fields, $row));
332 function migrate_example_beer_data_topic_node() {
333 $fields = array('bid', 'style');
334 $query = db_insert('migrate_example_beer_topic_node')
337 array(99999999, 'pilsner'),
338 array(99999999, 'red ale'),
339 array(99999998, 'red ale'),
341 foreach ($data as $row) {
342 $query->values(array_combine($fields, $row));