-
Notifications
You must be signed in to change notification settings - Fork 0
/
vih_subjects.migrate.inc
132 lines (107 loc) · 4.56 KB
/
vih_subjects.migrate.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
<?php
/**
* @file
* Migrations for vih_subjects.
*/
class VIHSubjectsNode extends VIHMigration {
public function __construct(array $arguments) {
$this->arguments = $arguments;
parent::__construct();
$this->description = t('Import subject nodes.');
// Create a map object for tracking the relationships between source rows
$this->map = new MigrateSQLMap($this->machineName,
array(
'id' => array(
'type' => 'int',
'not null' => TRUE,
),
),
MigrateDestinationNode::getKeySchema()
);
// Create a MigrateSource object.
$this->source = new MigrateSourceCSV(drupal_get_path('module', 'vih_subjects') . '/import/subjects.csv', $this->csvcolumns(), array('header_rows' => 1));
$this->destination = new MigrateDestinationNode('subject');
$this->addFieldMapping('uid', 'uid')->defaultValue(1);
$this->addFieldMapping('title', 'title');
$this->addFieldMapping('field_subject_teaser', 'teaser');
$this->addFieldMapping('field_subject_teaser:format')
->defaultValue('panopoly_wysiwyg_text');
$this->addFieldMapping('body', 'body');
$this->addFieldMapping('body:format')
->defaultValue('panopoly_wysiwyg_text');
$this->addFieldMapping('field_subject_video', 'video');
$this->addFieldMapping('field_subject_video:file_class')->defaultValue('MigrateExtrasFileYoutube');
$this->addFieldMapping('field_course_leader', 'teacher')
->sourceMigration('VIHEmployeesContext');
$this->addFieldMapping('field_terms', 'category');
$this->addFieldMapping('field_terms:create_term')
->defaultValue(TRUE);
$this->addFieldMapping('field_subject_package', 'package');
$this->addFieldMapping('field_subject_package:create_term')
->defaultValue(TRUE);
// Featured image
$this->addFieldMapping('field_featured_image', 'featured_image');
$this->addFieldMapping('field_featured_image:file_replace')
->defaultValue(FILE_EXISTS_REPLACE);
$this->addFieldMapping('field_featured_image:source_dir')
->defaultValue(drupal_get_path('module', 'vih_subjects') . '/import/images');
$this->addFieldMapping('field_pictures', 'all_images');
$this->addFieldMapping('field_pictures:file_replace')
->defaultValue(FILE_EXISTS_REPLACE);
$this->addFieldMapping('field_pictures:source_dir')
->defaultValue(drupal_get_path('module', 'vih_subjects') . '/import/images');
}
public function prepareRow($row) {
$row->all_images = explode(',', $row->images);
}
function csvcolumns() {
$columns[0] = array('id', 'Id');
$columns[1] = array('title', 'Title');
$columns[2] = array('teaser', 'Teaser');
$columns[3] = array('body', 'Body');
$columns[4] = array('video', 'Video');
$columns[5] = array('teacher', 'Teacher');
$columns[6] = array('category', 'Category');
$columns[7] = array('package', 'Package');
$columns[8] = array('featured_image', 'Featured Image');
$columns[9] = array('images', 'Images');
return $columns;
}
}
class VIHSubjectsPackageTaxonomy extends VIHMigration {
public function __construct(array $arguments) {
$this->arguments = $arguments;
parent::__construct();
$this->description = t('Import subject package taxonomies.');
// Create a map object for tracking the relationships between source rows
$this->map = new MigrateSQLMap($this->machineName,
array(
'id' => array(
'type' => 'int',
'not null' => TRUE,
),
),
MigrateDestinationTerm::getKeySchema()
);
// Create a MigrateSource object.
$this->source = new MigrateSourceCSV(drupal_get_path('module', 'vih_subjects') . '/import/package.csv', $this->csvcolumns(), array('header_rows' => 1));
$this->destination = new MigrateDestinationTerm('subject_packages');
$this->addFieldMapping('uid', 'uid')->defaultValue(1);
$this->addFieldMapping('name', 'name');
$this->addFieldMapping('description', 'description');
$this->addFieldMapping('description:format')
->defaultValue('panopoly_wysiwyg_text');
$this->addFieldMapping('field_tags_picture', 'image');
$this->addFieldMapping('field_tags_picture:file_replace')
->defaultValue(FILE_EXISTS_REPLACE);
$this->addFieldMapping('field_tags_picture:source_dir')
->defaultValue(drupal_get_path('module', 'vih_subjects') . '/import/images');
}
function csvcolumns() {
$columns[0] = array('id', 'Id');
$columns[1] = array('name', 'Name');
$columns[2] = array('description', 'Description');
$columns[3] = array('image', 'Image');
return $columns;
}
}