This repository has been archived by the owner on May 2, 2018. It is now read-only.
forked from vejlebib/migrate_ding1_ding2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.inc
1026 lines (899 loc) · 47.2 KB
/
node.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Common mappings for the Drupal 6 node migrations.
*/
abstract class DingNodeMigration extends DrupalNode6Migration {
public function __construct(array $arguments) {
$common_arguments = array(
'source_connection' => 'legacy',
'source_version' => 6,
'user_migration' => 'DingUser',
);
parent::__construct($arguments + $common_arguments);
// With migrate_ui enabled, migration pages will indicate people involved in
// the particular migration, with their role and contact info. We default the
// list in the shared class; it can be overridden for specific migrations.
$this->team = array(
new MigrateTeamMember('Ewan Andreasen', '[email protected]', t('Webdeveloper (Ding1 -> Ding2 Migration)')),
);
$this->addFieldMapping('field_legacy_nid', 'nid')
->description('We have a common field to save the D6 nid');
// Unmapped source fields - EXAMPLE
//$this->addUnmigratedSources(array('vid', 'tnid', 'translate', 'teaser', 'format'));
// Unmapped destination fields - EXAMPLE
//$this->addUnmigratedDestinations(array('log', 'tnid', 'translate', 'body:summary', 'body:format', 'body:language', 'comment'))
}
// function to create ting objects with relations to the node
public function createDingNodeTingRefs($node, $row) {
if (isset($row->field_ting_refs) && count($row->field_ting_refs) > 0) {
$refs = '';
$agency = variable_get('ting_agency', FALSE);
foreach ($row->field_ting_refs as $ref) {
if ($ref) {
// Convert data well 2 references to data well 3 references.
if ($agency && preg_match('/^(\d{6}):(\w+)$/', $ref, $matches)) {
$ref = ding_provider_build_entity_id($matches[2], $matches[1]);
}
// Save a ting object entity
$tid = migrate_ding1_ding2_add_ting_object($ref);
// Create relation
if ($tid) {
$rel_ent = ting_reference_create_relation('node', $node->nid, $tid);
// Append to logging string
$refs .= $ref . ', ';
}
}
}
$refs = rtrim($refs, ', ');
// Logging
if ($refs != '') {
watchdog('migrate_ding1_ding2', 'Created Ting object reference(s) (%refs) with relation(s) on item (%title - D7 nid %d7nid)', array('%refs' => $refs, '%title'=>$node->title, '%d7nid'=>$node->nid), WATCHDOG_INFO);
}
}
}
/**
* Function to replace IMG-tags in body text with Media tokens
*
* @param $row
*
* @return modified body text
*/
public function img2mediatoken($row) {
$file_directory_path = variable_get('migrate_ding1_ding2_file_directory_path', 'sites/default/files');
// Regex pattern that matches img tags containg /sites/default/files/ in src attribute,
// and also returns a matching group with the content of src-string after ../sites/default/files/
$regexp = '/<img.*src\s*=\s*[\"\'].*\/' . preg_quote($file_directory_path, '/') . '\/([^"\']+)[\"\'][^>]+>/i';
// Returns an array of arrays with
// first element = full img tag,
// 2nd element = filepath after "../sites/default/files/"
preg_match_all($regexp, $row->body, $img_tags, PREG_SET_ORDER);
// Return if no IMG tags were found
if (empty($img_tags)) {
return $row->body;
}
// create new array with the keys being the filepaths to lookup in legacy db and the values being tag content
foreach ($img_tags as $img_tag) {
$img_file_tag[$file_directory_path . '/' . $img_tag[1]] = array(
'tag_html' => $img_tag[0],
'legacy_filepath' => $file_directory_path . '/' . $img_tag[1],
);
}
// Check if src exists among the files in the SOURCE and get their fid from source db
$legacy_files_result = Database::getConnection('default', 'legacy')
->select('files', 'f')
->fields('f', array('fid', 'filepath'))
->condition('filepath', array_keys($img_file_tag), 'IN')
->execute();
$legacy_fids = array();
foreach ($legacy_files_result as $legacy_row) {
// append old fid to our $img_file_tag array
$img_file_tag[$legacy_row->filepath]['legacy_fid'] = $legacy_row->fid;
// Get and append new fid to array
$new_fid = $new_fid_query = db_select('migrate_map_dingfile', 'mmf')
->fields('mmf', array('destid1'))
->condition('sourceid1', $legacy_row->fid)
->execute()
->fetchField();
if ($new_fid) {
// append new fid to array
$img_file_tag[$legacy_row->filepath]['new_fid'] = $new_fid;
// Build new media tokens and append to array
$img_file_tag[$legacy_row->filepath]['new_fid_token'] = '[[{"fid":"' . $new_fid . '","view_mode":"default","fields":{"format":"default","field_file_image_alt_text[und][0][value]":"","field_file_image_title_text[und][0][value]":""},"type":"media","attributes":{"alt":"","title":"","class":"media-element file-default"}}]]';
}
}
// Replace img-tags with media tokens in body text
$replace_count = 0;
foreach ($img_file_tag as $img_item) {
$row->body = str_replace($img_item['tag_html'], $img_item['new_fid_token'], $row->body);
$replace_count++;
}
if ($replace_count > 0) {
// Logging
watchdog('migrate_ding1_ding2', 'Found and replaced %count IMG-tags with media tokens on item (title: %title)', array('%count' => $replace_count, '%title'=>$row->title), WATCHDOG_INFO);
}
return $row->body;
}
}
class DingLibraryMigration extends DingNodeMigration {
public function __construct($arguments) {
$arguments = array(
'description' => t('Migration of Libraries from Ding1/D6'),
'machine_name' => 'DingLibrary',
'group_name' => 'ding1_group',
'source_type' => 'library',
'destination_type' => 'ding_library',
'dependencies' => array('DingUser','DingFile'),
);
// Add to sourceFields before calling parent constructor.
// See http://www.acquia.com/blog/drupal-drupal-data-migration-part-2-architecture
$this->sourceFields['list_image_title'] = t('Title text extracted from field_list_image_data');
$this->sourceFields['image_title'] = t('Title text extracted from field_image_data');
parent::__construct($arguments);
$this->addFieldMapping('field_ding_library_body', 'body');
$this->addFieldMapping('field_ding_library_body:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_library_body:format')
->defaultValue('ding_wysiwyg');
$this->addFieldMapping('field_ding_library_lead', 'teaser');
$this->addFieldMapping('field_ding_library_lead:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_library_mail', 'field_email');
$this->addFieldMapping('group_group')
->defaultValue('1');
// Phone and fax comes from location_phone table and is drawn in via the modified query
$this->addFieldMapping('field_ding_library_phone_number', 'phone');
$this->addFieldMapping('field_ding_library_phone_number:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_library_fax_number', 'fax');
$this->addFieldMapping('field_ding_library_fax_number:language')
->defaultValue('und');
// library slug comes from ding_library table and is drawn in via the modified query
$this->addFieldMapping('field_ding_library_slug', 'slug');
$this->addFieldMapping('field_ding_library_slug:language')
->defaultValue('und');
// Map the list image field to the new list image field, base this on the DingFile migration
// to map the files to the imported files table.
$this->addFieldMapping('field_ding_library_list_image', 'field_list_image')
->sourceMigration('DingFile');
$this->addFieldMapping('field_ding_library_list_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_ding_library_list_image:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_library_list_image:preserve_files')
->defaultValue(TRUE);
$this->addFieldMapping('field_ding_library_list_image:alt', 'field_list_image:alt');
$this->addFieldMapping('field_ding_library_list_image:title', 'list_image_title');
$this->addFieldMapping(NULL, 'field_list_image:data')
->description(t('Split this into list_image_title for D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_list_image:list');
// Map the image field to the new title image field, base this on the DingFile migration
// to map the files to the imported files table.
$this->addFieldMapping('field_ding_library_title_image', 'field_image')
->sourceMigration('DingFile');
$this->addFieldMapping('field_ding_library_title_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_ding_library_title_image:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_library_title_image:preserve_files')
->defaultValue(TRUE);
$this->addFieldMapping('field_ding_library_title_image:alt', 'field_image:alt');
$this->addFieldMapping('field_ding_library_title_image:title', 'image_title');
$this->addFieldMapping(NULL, 'field_image:data')
->description(t('Split this into image_title for D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_image:list');
// Map to addressfield. See https://drupal.org/node/1996546.
$this->addFieldMapping('field_ding_library_addresse', 'country');
$this->addFieldMapping('field_ding_library_addresse:thoroughfare', 'street');
$this->addFieldMapping('field_ding_library_addresse:premise', 'additional');
$this->addFieldMapping('field_ding_library_addresse:locality', 'city');
$this->addFieldMapping('field_ding_library_addresse:administrative_area', 'province');
$this->addFieldMapping('field_ding_library_addresse:postal_code', 'postal_code');
$this->addFieldMapping('field_ding_library_addresse:name_line', 'name');
// Map to geofield.
$this->addFieldMapping('field_ding_library_geocode')
->defaultValue('point');
$this->addFieldMapping('field_ding_library_geocode:geo_type')
->defaultValue('point');
$this->addFieldMapping('field_ding_library_geocode:lat', 'latitude');
$this->addFieldMapping('field_ding_library_geocode:top', 'latitude');
$this->addFieldMapping('field_ding_library_geocode:bottom', 'latitude');
$this->addFieldMapping('field_ding_library_geocode:lon', 'longitude');
$this->addFieldMapping('field_ding_library_geocode:left', 'longitude');
$this->addFieldMapping('field_ding_library_geocode:right', 'longitude');
$this->addFieldMapping(NULL, 'lid')
->issueGroup(t('DNM'));
// The opening_hours field in Ding2/D7 will be handled by migrating the opening_hours table of the module opening_hours
$this->addFieldMapping('field_ding_library_opening_hours')
->description(t('Initially empty strings - field is populated by use of the site'))
->defaultValue('');
$this->addFieldMapping('field_ding_library_opening_hours:language')
->defaultValue('und');
// library links
$this->addFieldMapping('field_ding_library_links', 'field_links');
$this->addFieldMapping('field_ding_library_links:title', 'field_links:title');
$this->addFieldMapping('field_ding_library_links:attributes', 'field_links:attributes');
$this->addFieldMapping('field_ding_library_links:language')
->defaultValue('und');
// Unmapped source fields
$this->addFieldMapping(NULL, 'field_content_images')
->description(t('content images are not mapped to Ding2/D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_content_images:list')
->description(t('content images are not mapped to Ding2/D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_content_images:alt')
->description(t('content images are not mapped to Ding2/D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, '2')
->description(t('Ding2 does not employ the Tags taxonomy (taxonomy "2") for library nodes'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_pc_booking_method')
->description(t('Ding2/D7 does not employ pc booking'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_pc_booking_url')
->description(t('Ding2/D7 does not employ pc booking'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_feature_ref')
->description(t('Ding2/D7 does not employ feature nodes'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'revision')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'log')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'revision_uid')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:week_start')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:week_end')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:sun_open')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:sun_close')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:mon_open')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:mon_close')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:tue_open')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:tue_close')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:wed_open')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:wed_close')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:thu_open')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:thu_close')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:fri_open')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:fri_close')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:sat_open')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_opening_hours:sat_close')
->description(t('Ding2/D7 uses the opening_hours module instead of office_hours module. Handled by separate migration of the opening_hours table'))
->issueGroup(t('DNM'));
// Unmapped destination fields
$this->addUnmigratedDestinations(array(
'field_ding_library_addresse:sub_administrative_area',
'field_ding_library_addresse:dependent_locality',
'field_ding_library_addresse:sub_premise',
'field_ding_library_addresse:organisation_name',
'field_ding_library_addresse:first_name',
'field_ding_library_addresse:last_name',
'field_ding_library_addresse:data',
'field_ding_library_geocode:srid',
'field_ding_library_geocode:accuracy',
'field_ding_library_geocode:source',
'og_group_ref',
));
}
public function prepareRow($row) {
// Always include this snippet, in case our parent class decides to ignore the row
if (parent::prepareRow($row) === FALSE) {
return FALSE;
}
// Get values from serialized data and populate the source fields defined in our constructor
$list_image_data = unserialize($row->field_list_image_data);
$row->list_image_alt = $list_image_data['alt'];
$row->list_image_title = $list_image_data['title'];
$image_data = unserialize($row->field_image_data);
$row->image_alt = $image_data['alt'];
$row->image_title = $image_data['title'];
// Make country code uppercase
$row->country = strtoupper($row->country);
// Replace img-tags found in body with the corresponding media tokens
$row->body = parent::img2mediatoken($row);
}
// Modify the query to include location data
// For more info, see:
// http://www.acquia.com/blog/drupal-drupal-data-migration-part-2-architecture as well as
// http://www.grasmash.com/article/migrate-classes-location-cck-address-field
protected function query() {
$query = parent::query();
$query->leftJoin('location_instance', 'li', 'n.nid=li.nid AND n.vid = li.vid');
$query->addField('li', 'lid');
$query->leftJoin('location', 'l', 'li.lid=l.lid');
$query->addField('l', 'name');
$query->addField('l', 'street');
$query->addField('l', 'additional');
$query->addField('l', 'city');
$query->addField('l', 'province');
$query->addField('l', 'postal_code');
$query->addField('l', 'country');
$query->addField('l', 'latitude');
$query->addField('l', 'longitude');
$query->leftJoin('location_phone', 'lp', 'lp.lid=l.lid');
$query->addField('lp', 'phone');
$query->leftJoin('location_fax', 'lf', 'lf.lid=l.lid');
$query->addField('lf', 'fax');
$query->leftJoin('panels_subsites_slugs', 'pss', 'n.nid=pss.nid');
$query->addField('pss', 'slug');
return $query;
}
}
class DingCampaignMigration extends DingNodeMigration {
public function __construct($arguments) {
$arguments = array(
'description' => t('Migration of Campaigns from Ding1/D6'),
'machine_name' => 'DingCampaign',
'group_name' => 'ding1_group',
'source_type' => 'campaign',
'destination_type' => 'ding_campaign',
'dependencies' => array('DingUser', 'DingFile'),
);
// Add to sourceFields before calling parent constructor.
// See http://www.acquia.com/blog/drupal-drupal-data-migration-part-2-architecture
$this->sourceFields['campaign_image_alt'] = t('Alt text extracted from field_campaign_image_data');
$this->sourceFields['campaign_image_title'] = t('Title text extracted from field_campaign_image_data');
parent::__construct($arguments);
$this->addFieldMapping('field_camp_text_full', 'body')
->description(t('body is mapped to both field_camp_text_full and field_camp_text_plain'));
$this->addFieldMapping('field_camp_text_plain', 'body')
->description(t('body is mapped to both field_camp_text_full and field_camp_text_plain'));
$this->addFieldMapping('field_camp_link', 'field_campaign_link');
$this->addFieldMapping('field_camp_image:alt', 'campaign_image_alt');
$this->addFieldMapping('field_camp_image:title', 'campaign_image_title');
$this->addFieldMapping(NULL, 'field_campaign_image:data')
->description(t('Split this into campaign_image_alt and campaign_image_title for D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, '2')
->description(t('Ding2 does not employ the Tags taxonomy (taxonomy "2") for campaigns'));
$this->addFieldMapping(NULL, 'field_campaign_link:title')
->description(t('Ding2 does not have title data on the campaign links'));
$this->addFieldMapping(NULL, 'field_campaign_link:attributes')
->description(t('Ding2 does not have attribute data on the campaign links'));
$this->addFieldMapping('field_camp_weight', 'campaign_weight');
$this->addFieldMapping('field_camp_settings', 'campaign_type')
->description(t('Handled in prepareRow of DingCampaignMigration'));
$this->addFieldMapping('field_camp_link:language')
->defaultValue('und');
$this->addFieldMapping('field_camp_text_full:language')
->defaultValue('und');
$this->addFieldMapping('field_camp_text_plain:language')
->defaultValue('und');
$this->addFieldMapping('field_camp_text_full:format')
->defaultValue('ding_wysiwyg');
$this->addFieldMapping(NULL, 'field_campaign_image:list');
// Map the image field to the new image field, base this on the Files migration
// to map the files to the imported files table.
$this->addFieldMapping('field_camp_image', 'field_campaign_image')
->sourceMigration('DingFile');
$this->addFieldMapping('field_camp_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_camp_image:language')
->defaultValue('und');
$this->addFieldMapping('field_camp_image:preserve_files')
->defaultValue(TRUE);
// Unmapped source fields
$this->addFieldMapping(NULL, 'revision')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'log')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'revision_uid')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
}
public function prepareRow($row) {
// Always include this snippet, in case our parent class decides to ignore the row
if (parent::prepareRow($row) === FALSE) {
return FALSE;
}
// Get values from serialized data and populate the source fields defined in our constructor
$campaign_image_data = unserialize($row->field_campaign_image_data);
$row->campaign_image_alt = $campaign_image_data['alt'];
$row->campaign_image_title = $campaign_image_data['title'];
// Modify text in campaign_type
$row->campaign_type = str_replace('-only', '', $row->campaign_type);
}
// Modify the query to include ding_campaign data
protected function query() {
$query = parent::query();
$query->leftJoin('ding_campaign', 'dc', 'n.nid=dc.nid AND n.vid = dc.vid');
$query->addField('dc', 'campaign_weight');
$query->addField('dc', 'campaign_type');
return $query;
}
}
class DingPageMigration extends DingNodeMigration {
public function __construct($arguments) {
$arguments = array(
'description' => t('Migration of Pages from Ding1/D6'),
'machine_name' => 'DingPage',
'group_name' => 'ding1_group',
'source_type' => 'page',
'destination_type' => 'ding_page',
'dependencies' => array('DingUser','DingTagsTerm', 'DingLibrary', 'DingFile'),
);
// Add to sourceFields before calling parent constructor.
// See http://www.acquia.com/blog/drupal-drupal-data-migration-part-2-architecture
$this->sourceFields['list_image_title'] = t('Title text extracted from field_list_image_data');
parent::__construct($arguments);
$this->addFieldMapping('field_ding_page_body', 'body');
$this->addFieldMapping('field_ding_page_body:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_page_body:format')
->defaultValue('ding_wysiwyg');
$this->addFieldMapping('field_ding_page_lead', 'field_teaser');
$this->addFieldMapping('field_ding_page_lead:language')
->defaultValue('und');
// Files mapping
$this->addFieldMapping('field_ding_page_files', 'field_file_attachments')
->sourceMigration('DingFile');
$this->addFieldMapping('field_ding_page_files:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_ding_page_files:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_page_files:preserve_files')
->defaultValue(TRUE);
// Mapping remaining page file fields
$this->addFieldMapping('field_ding_page_files:description', 'field_file_attachments:description');
// Map the list image field to the new list image field, base this on the DingFile migration
// to map the files to the imported files table.
$this->addFieldMapping('field_ding_page_list_image', 'field_list_image')
->sourceMigration('DingFile');
$this->addFieldMapping('field_ding_page_list_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_ding_page_list_image:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_page_list_image:preserve_files')
->defaultValue(TRUE);
// Mapping remaining list image fields
$this->addFieldMapping('field_ding_page_list_image:alt', 'field_list_image:alt');
$this->addFieldMapping('field_ding_page_list_image:title', 'list_image_title');
$this->addFieldMapping(NULL, 'field_list_image:data')
->description(t('Split this into list_image_title for D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_list_image:list');
// ting references
$this->addFieldMapping(NULL, 'field_ting_refs')
->description(t('Handled in complete function'));
$this->addFieldMapping(NULL, 'field_ting_refs:ting_ref_type')
->description(t('Not mapped - Ding2 does not employ ref types'));
$this->addFieldMapping(NULL, 'field_ting_refs:description')
->description(t('Not mapped - Ding2 does not employ descriptions on ting refs.'));
// Tags term mapping
$this->addFieldMapping('field_ding_page_tags', '2')
->sourceMigration('DingTagsTerm');
$this->addFieldMapping('field_ding_page_tags:source_type')
->defaultValue('tid');
$this->addFieldMapping('field_ding_page_tags:create_term')
->defaultValue(TRUE);
$this->addFieldMapping('field_ding_page_tags:ignore_case')
->defaultValue(TRUE);
// Unmapped source fields
$this->addFieldMapping(NULL, 'revision')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'log')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'revision_uid')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_content_images')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_content_images:list')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_content_images:alt')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_file_attachments:list')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_library_ref')
->description(t('Not mapped - Ding2 does not relate pages to libraries'))
->issueGroup(t('DNM'));
// Unmapped destination fields
$this->addUnmigratedDestinations(array(
'field_ding_page_title_image',
'field_ding_page_title_image:file_class',
'field_ding_page_title_image:language',
'field_ding_page_title_image:alt',
'field_ding_page_title_image:title',
'field_ding_page_title_image:destination_dir',
'field_ding_page_title_image:destination_file',
'field_ding_page_title_image:file_replace',
'field_ding_page_title_image:preserve_files',
'field_ding_page_title_image:source_dir',
'field_ding_page_title_image:urlencode',
'field_ding_page_files:display',
'ding_page_group_ref',
'field_ding_page_materials',
));
}
public function prepareRow($row) {
// Always include this snippet, in case our parent class decides to ignore the row
if (parent::prepareRow($row) === FALSE) {
return FALSE;
}
// Get values from serialized data and populate the source fields defined in our constructor
// file attachments
$file_attachments_data = unserialize($row->field_file_attachments_data);
$row->file_attachments_description = $file_attachments_data['description'];
// list images
$list_image_data = unserialize($row->field_list_image_data);
$row->list_image_alt = $list_image_data['alt'];
$row->list_image_title = $list_image_data['title'];
// Replace img-tags found in body with the corresponding media tokens
$row->body = parent::img2mediatoken($row);
}
public function complete($node, stdClass $row) {
// Create Ting objects and relation to it for each item i field_ting_refs
// We perform this in complete() function since we need the nid on the news node just created
parent::createDingNodeTingRefs($node, $row);
}
}
class DingNewsMigration extends DingNodeMigration {
public function __construct($arguments) {
$arguments = array(
'description' => t('Migration of Blogposts/News from Ding1/D6'),
'machine_name' => 'DingNews',
'group_name' => 'ding1_group',
'source_type' => 'article',
'destination_type' => 'ding_news',
'dependencies' => array('DingUser','DingNewsCategoryTerm','DingTagsTerm','DingFile','DingLibrary'),
);
// Add to sourceFields before calling parent constructor.
// See http://www.acquia.com/blog/drupal-drupal-data-migration-part-2-architecture
$this->sourceFields['list_image_title'] = t('Title text extracted from field_list_image_data');
parent::__construct($arguments);
$this->addFieldMapping('field_ding_news_body', 'body');
$this->addFieldMapping('field_ding_news_body:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_news_body:format')
->defaultValue('ding_wysiwyg');
$this->addFieldMapping('field_ding_news_lead', 'field_teaser');
$this->addFieldMapping('field_ding_news_lead:language')
->defaultValue('und');
$this->addFieldMapping('og_group_ref', 'field_library_ref')
->sourceMigration('DingLibrary');
// Files mapping
$this->addFieldMapping('field_ding_news_files', 'field_file_attachments')
->sourceMigration('DingFile');
$this->addFieldMapping('field_ding_news_files:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_ding_news_files:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_news_files:preserve_files')
->defaultValue(TRUE);
// Mapping remaining news file fields
$this->addFieldMapping('field_ding_news_files:description', 'field_file_attachments:description');
// Map the list image field to the new list image field, base this on the DingFile migration
// to map the files to the imported files table.
$this->addFieldMapping('field_ding_news_list_image', 'field_list_image')
->sourceMigration('DingFile');
$this->addFieldMapping('field_ding_news_list_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_ding_news_list_image:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_news_list_image:preserve_files')
->defaultValue(TRUE);
// Mapping remaining list image fields
$this->addFieldMapping('field_ding_news_list_image:alt', 'field_list_image:alt');
$this->addFieldMapping('field_ding_news_list_image:title', 'list_image_title');
$this->addFieldMapping(NULL, 'field_list_image:list');
// ting references
$this->addFieldMapping(NULL, 'field_ting_refs')
->description(t('Handled in complete function'));
$this->addFieldMapping(NULL, 'field_ting_refs:ting_ref_type')
->description(t('Not mapped - Ding2 does not employ ref types'));
$this->addFieldMapping(NULL, 'field_ting_refs:description')
->description(t('Not mapped - Ding2 does not employ descriptions on ting refs.'));
// News Category term mapping
$this->addFieldMapping('field_ding_news_category', '1')
->sourceMigration('DingNewsCategoryTerm');
$this->addFieldMapping('field_ding_news_category:source_type')
->defaultValue('tid');
$this->addFieldMapping('field_ding_news_category:create_term')
->defaultValue(TRUE);
$this->addFieldMapping('field_ding_news_category:ignore_case')
->defaultValue(TRUE);
// News Tags term mapping
$this->addFieldMapping('field_ding_news_tags', '2')
->sourceMigration('DingTagsTerm');
$this->addFieldMapping('field_ding_news_tags:source_type')
->defaultValue('tid');
$this->addFieldMapping('field_ding_news_tags:create_term')
->defaultValue(TRUE);
$this->addFieldMapping('field_ding_news_tags:ignore_case')
->defaultValue(TRUE);
// Unmapped source fields
$this->addFieldMapping(NULL, 'revision')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'log')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'revision_uid')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_content_images')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_content_images:list')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_content_images:alt')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_file_attachments:list')
->issueGroup(t('DNM'));
// Unmapped destination fields
$this->addUnmigratedDestinations(array(
'field_ding_news_title_image',
'field_ding_news_title_image:file_class',
'field_ding_news_title_image:language',
'field_ding_news_title_image:alt',
'field_ding_news_title_image:title',
'field_ding_news_title_image:destination_dir',
'field_ding_news_title_image:destination_file',
'field_ding_news_title_image:file_replace',
'field_ding_news_title_image:preserve_files',
'field_ding_news_title_image:source_dir',
'field_ding_news_title_image:urlencode',
'field_ding_news_files:display',
'ding_news_groups_ref',
'field_ding_news_materials',
));
}
public function prepareRow($row) {
// Always include this snippet, in case our parent class decides to ignore the row
if (parent::prepareRow($row) === FALSE) {
return FALSE;
}
// Get values from serialized data and populate the source fields defined in our constructor
// list images
$list_image_data = unserialize($row->field_list_image_data);
$row->list_image_title = $list_image_data['title'];
// Replace img-tags found in body with the corresponding media tokens
$row->body = parent::img2mediatoken($row);
}
public function complete($node, stdClass $row) {
// Create Ting objects and relation to it for each item i field_ting_refs
// We perform this in complete() function since we need the nid on the news node just created
parent::createDingNodeTingRefs($node, $row);
}
}
class DingEventMigration extends DingNodeMigration {
public function __construct($arguments) {
$arguments = array(
'description' => t('Migration of Events from Ding1/D6'),
'machine_name' => 'DingEvent',
'group_name' => 'ding1_group',
'source_type' => 'event',
'destination_type' => 'ding_event',
'dependencies' => array('DingUser','DingEventCategoryTerm','DingEventTargetTerm', 'DingTagsTerm', 'DingFile', 'DingLibrary'),
);
// Add to sourceFields before calling parent constructor.
// See http://www.acquia.com/blog/drupal-drupal-data-migration-part-2-architecture
$this->sourceFields['list_image_alt'] = t('Alt text extracted from field_list_image_data');
$this->sourceFields['list_image_title'] = t('Title text extracted from field_list_image_data');
parent::__construct($arguments);
$this->addFieldMapping('field_ding_event_body', 'body');
$this->addFieldMapping('field_ding_event_body:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_event_body:format')
->defaultValue('ding_wysiwyg');
$this->addFieldMapping('field_ding_event_lead', 'field_teaser');
$this->addFieldMapping('field_ding_event_lead:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_event_date', 'field_datetime');
$this->addFieldMapping('field_ding_event_date:value2', 'field_datetime:value2');
$this->addFieldMapping('field_ding_event_price', 'field_entry_price');
$this->addFieldMapping('og_group_ref', 'field_library_ref')
->sourceMigration('DingLibrary');
// Files mapping
$this->addFieldMapping('field_ding_event_files', 'field_file_attachments')
->sourceMigration('DingFile');
$this->addFieldMapping('field_ding_event_files:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_ding_event_files:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_event_files:preserve_files')
->defaultValue(TRUE);
// Mapping remaining page file fields
$this->addFieldMapping('field_ding_event_files:description', 'field_file_attachments:description');
// Map the list image field to the new list image field, base this on the DingFile migration
// to map the files to the imported files table.
$this->addFieldMapping('field_ding_event_list_image', 'field_list_image')
->sourceMigration('DingFile');
$this->addFieldMapping('field_ding_event_list_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_ding_event_list_image:language')
->defaultValue('und');
$this->addFieldMapping('field_ding_event_list_image:preserve_files')
->defaultValue(TRUE);
// Mapping remaining list image fields
$this->addFieldMapping('field_ding_event_list_image:alt', 'list_image_alt');
$this->addFieldMapping('field_ding_event_list_image:title', 'list_image_title');
$this->addFieldMapping(NULL, 'field_list_image:data')
->description(t('Split this into list_image_alt and list_image_title for D7'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_list_image:list');
$this->addFieldMapping(NULL, 'field_list_image:alt');
// Map to addressfield. See https://drupal.org/node/1996546.
$this->addFieldMapping('field_ding_event_location', 'country');
$this->addFieldMapping('field_ding_event_location:thoroughfare', 'street');
$this->addFieldMapping('field_ding_event_location:premise', 'additional');
$this->addFieldMapping('field_ding_event_location:locality', 'city');
$this->addFieldMapping('field_ding_event_location:administrative_area', 'province');
$this->addFieldMapping('field_ding_event_location:postal_code', 'postal_code');
$this->addFieldMapping('field_ding_event_location:name_line', 'name');
// Since the excerpt is mapped via an argument, add a null mapping so it's not flagged as unmapped.
$this->addFieldMapping(NULL, 'latitude');
$this->addFieldMapping(NULL, 'longitude');
$this->addFieldMapping(NULL, 'lid');
// ting references
$this->addFieldMapping(NULL, 'field_ting_refs')
->description(t('Handled in complete function'));
$this->addFieldMapping(NULL, 'field_ting_refs:ting_ref_type')
->description(t('Not mapped - Ding2 does not employ ref types'));
$this->addFieldMapping(NULL, 'field_ting_refs:description')
->description(t('Not mapped - Ding2 does not employ descriptions on ting refs.'));
// Event Category term mapping
$this->addFieldMapping('field_ding_event_category', '4')
->sourceMigration('DingEventCategoryTerm');
$this->addFieldMapping('field_ding_event_category:source_type')
->defaultValue('tid');
$this->addFieldMapping('field_ding_event_category:create_term')
->defaultValue(TRUE);
$this->addFieldMapping('field_ding_event_category:ignore_case')
->defaultValue(TRUE);
// Event Target term mapping
$this->addFieldMapping('field_ding_event_target', '5')
->sourceMigration('DingEventTargetTerm');
$this->addFieldMapping('field_ding_event_target:source_type')
->defaultValue('tid');
$this->addFieldMapping('field_ding_event_target:create_term')
->defaultValue(TRUE);
$this->addFieldMapping('field_ding_event_target:ignore_case')
->defaultValue(TRUE);
// Event Tags term mapping
$this->addFieldMapping('field_ding_event_tags', '2')
->sourceMigration('DingTagsTerm');
$this->addFieldMapping('field_ding_event_tags:source_type')
->defaultValue('tid');
$this->addFieldMapping('field_ding_event_tags:create_term')
->defaultValue(TRUE);
$this->addFieldMapping('field_ding_event_tags:ignore_case')
->defaultValue(TRUE);
// Unmapped source fields
$this->addFieldMapping(NULL, 'field_content_images')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_content_images:list')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_content_images:alt')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'field_file_attachments:list')
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'revision')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'log')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
$this->addFieldMapping(NULL, 'revision_uid')
->description(t('Migration of revisions is possible, but not implemented in this migration'))
->issueGroup(t('DNM'));
// Unmapped destination fields
$this->addUnmigratedDestinations(array(
'field_ding_event_title_image',
'field_ding_event_title_image:file_class',
'field_ding_event_title_image:language',
'field_ding_event_title_image:alt',
'field_ding_event_title_image:title',
'field_ding_event_title_image:destination_dir',
'field_ding_event_title_image:destination_file',
'field_ding_event_title_image:file_replace',
'field_ding_event_title_image:preserve_files',
'field_ding_event_title_image:source_dir',
'field_ding_event_title_image:urlencode',
'field_ding_event_files:display',
'field_ding_event_materials',
'ding_event_groups_ref',
'field_ding_event_location:sub_administrative_area',
'field_ding_event_location:dependent_locality',
'field_ding_event_location:sub_premise',
'field_ding_event_location:organisation_name',
'field_ding_event_location:first_name',
'field_ding_event_location:last_name',
'field_ding_event_location:data',
'field_place2book_tickets', // If this field shows up in the list of destination fields, it should be ignored
'field_place2book_tickets:language', // If this field shows up in the list of destination fields, it should be ignored
));
}
public function prepareRow($row) {
// Make sure that this migration only runs if ding_place2book is turned OFF on the site
if (module_exists('ding_place2book')) {
throw new MigrateException(t('Turn ding_place2book module OFF before running DingEventMigration'));
}
// Always include this snippet, in case our parent class decides to ignore the row
if (parent::prepareRow($row) === FALSE) {
return FALSE;
}
// Get values from serialized data and populate the source fields defined in our constructor
// list images
$list_image_data = unserialize($row->field_list_image_data);
$row->list_image_alt = $list_image_data['alt'];
$row->list_image_title = $list_image_data['title'];
// Handle date field
$date_data = array(
'from' => $row->field_datetime,
'to' => $row->{'field_datetime:value2'},
);
// Datetime field handler accepts data as json array.
$row->field_datetime = drupal_json_encode($date_data);
// Make country code uppercase
$row->country = strtoupper($row->country);
// Replace img-tags found in body with the corresponding media tokens
$row->body = parent::img2mediatoken($row);
}
public function complete($node, stdClass $row) {
// Create Ting objects and relation to it for each item i field_ting_refs