-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnews.inc
348 lines (288 loc) · 11.8 KB
/
news.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
<?php
/**
* @file
* Implementation of migration from Commonspot news custom element to Drupal article nodes.
*/
class NistNewsMigration extends NistMigration {
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import of Commonspot news custom element into article content type');
$this->dependencies = array('NistUser');
// create a date that is 2 days older than now
$fromdate = $this->getFromDate(2);
$list_url = "";
$item_url = "";
$fields = array(
'changed' => 'Date the page was last modified',
'created' => 'Date the page was last created',
'cs_uid' => 'Commonspot user that created the page',
'fic_anchorslug' => 'used in TechBeat',
'fic_commenturl' => 'used in TechBeat',
'fic_contact_information' => 'Field in news content type with news contact',
'fic_includeinslideshow' => 'supposed to be used to include news stories in slideshow',
'fic_issuedate' => 'used in TechBeat',
'fic_news_item_associated_campus' => 'associated campus',
'fic_news_item_body' => 'Body of the news story',
'fic_news_item_contact_email' => 'contact email',
'fic_news_item_contact_name' => 'contact name',
'fic_news_item_contact_phone' => 'contact phone number',
'fic_news_item_other_campus' => 'other associated Campus',
'fic_news_item_release_date' => 'news release date',
'fic_news_item_thumbnail' => 'thumbnail image',
'fic_news_item_title' => 'Title',
'fic_news_video' => 'video embed code',
'fic_news_video_caption' => 'video caption',
'fic_pbaapproved' => 'did PBA approve this?',
'fic_quicklink' => 'used in TechBeat',
'fic_releaseinfo' => 'release into like for immediate release',
'fic_slideshowimage' => 'slideshow image',
'fic_slideshowsection' => '',
'fic_slideshowtext' => 'slideshow text',
'fic_sortorder' => 'used in TechBeat',
'owner_name' => 'Plaintext username of the owner of the page',
'page_description' => 'Description of the page, often not used and same and title',
'page_title' => 'Title of the page',
'pageid' => 'CommonSpot PageID',
'pagename' => 'Name of the page used in the url',
'parsedimageids' => 'IDs of inline images',
'path' => 'URL in the CommonSpot system possibly used for Pathauto purposes',
'taxonomy_ids' => 'IDs of taxonomy terms from FLEET',
);
$this->highwaterField = array(
'name' => 'changed', // Column to be used as highwater mark
'alias' => 'w',
);
// $this->source = new MigrateSourceJSON('http://www.nist.gov/com/DataPull.cfc?method=getCEList&formid=2449&fromDate=2000-01-01&returnFormat=json', 'pageid', $fields);
$this->source = new MigrateSourceList(
new MigrateListJSON($list_url),
new MigrateItemJSON($item_url, array()),
$fields
);
$this->destination = new MigrateDestinationNode('article');
$this->map = new MigrateSQLMap(
$this->machineName,
array(
'pageid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Page ID',
)
),
MigrateDestinationNode::getKeySchema()
);
// Mapped fields
$this->addFieldMapping('changed', 'changed');
$this->addFieldMapping('created', 'created');
$this->addFieldMapping('uid', 'cs_uid')
->sourceMigration('NistUser');
$this->addFieldMapping('title', 'fic_news_item_title');
$this->addFieldMapping('body', 'fic_news_item_body');
$this->addFieldMapping('body:language')
->defaultValue('en');
$this->addFieldMapping('body:format')
->defaultValue('filtered_html');
$this->addFieldMapping('status')
->defaultValue(1);
$this->addFieldMapping('translate')
->defaultValue(0);
$this->addFieldMapping('field_image', 'parsedimageids')
->sourceMigration('NistImage');
$this->addFieldMapping('field_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_image:preserve_files')
->defaultValue(TRUE);
$this->addFieldMapping('field_campus', 'fic_news_item_associated_campus')
->separator(', ');
$this->addFieldMapping('field_campus:create_term')
->defaultValue(FALSE);
$this->addFieldMapping('field_contact', 'fic_news_item_contact_name')
->issueGroup(t('Issues'))
->description(t('Not sure if just putting a name in works'))
->issuePriority(MigrateFieldMapping::ISSUE_PRIORITY_MEDIUM)
->issueNumber(23);
$this->addFieldMapping('field_legacy_url', 'legacyPath');
$this->addFieldMapping('pathauto')
->defaultValue(0);
$this->addFieldMapping('field_date', 'fic_news_item_release_date');
$this->addFieldMapping('field_date:timezone')
->defaultValue('America/New_York')
->issueGroup(t('Issues'))
->description(t('Timezone based on campus location?'))
->issuePriority(MigrateFieldMapping::ISSUE_PRIORITY_MEDIUM)
->issueNumber(22);
$this->addFieldMapping('field_legacy_contact', 'contact_block');
$this->addFieldMapping('field_legacy_contact:format')
->defaultValue('filtered_html');
$this->addFieldMapping('field_legacy_video_embed', 'fic_news_video');
$this->addFieldMapping('field_legacy_video_embed:language')
->defaultValue('en');
$this->addFieldMapping('field_legacy_video_embed:format')
->defaultValue('filtered_html');
$this->addFieldMapping('field_video_embed_caption', 'fic_news_video_caption');
$this->addFieldMapping('field_video_embed_caption:language')
->defaultValue('en');
$this->addFieldMapping('field_video_embed_caption:format')
->defaultValue('filtered_html');
$this->addFieldMapping('field_other_campus', 'fic_news_item_other_campus');
$this->addFieldMapping('field_other_campus:language')
->defaultValue('en');
$this->addFieldMapping('field_nist_topics', 'taxonomy_ids')
->separator(', ')
->sourceMigration('NistTerm');
$this->addFieldMapping('field_nist_topics:source_type')
->defaultValue('tid');
$this->addFieldMapping('field_nist_topics:create_term')
->defaultValue('False');
$this->addFieldMapping('field_pba_approval', 'fic_pbaapproved');
$this->addFieldMapping('field_release_info', 'fic_releaseinfo');
$this->addFieldMapping('field_release_info:language')
->defaultValue('en');
$this->addFieldMapping('field_techbeat_anchor_slug', 'fic_anchorslug');
$this->addFieldMapping('field_techbeat_anchor_slug:language')
->defaultValue('en');
$this->addFieldMapping('field_techbeat_issue_date', 'fic_issuedate');
$this->addFieldMapping('field_techbeat_issue_date:language')
->defaultValue('en');
$this->addFieldMapping('field_techbeat_sort_order', 'fic_sortorder');
$this->addFieldMapping('field_test_content')
->defaultValue(0);
// field_access_rights
$this->addFieldMapping('field_access_rights', 'permissionTIDBasedOnSubSite')
->separator(', ');
$this->addFieldMapping('field_access_rights:source_type')
->defaultValue('tid');
$this->addFieldMapping('field_access_rights:create_term')
->defaultValue('False');
// NEW field_nist_topic_areas
$this->addFieldMapping('field_nist_topic_areas', 'newTaxonomyTermList')
->separator(', ');
$this->addFieldMapping('field_nist_topic_areas:source_type')
->defaultValue('tid');
$this->addFieldMapping('field_nist_topic_areas:create_term')
->defaultValue('False');
$this->addFieldMapping('field_nist_org', 'generatedOrg');
// Unmapped destination fields
$this->addUnmigratedDestinations(array('is_new', 'revision_uid', 'promote',
'sticky',
'revision',
'log',
'language',
'tnid',
'comment',
'field_campus:source_type',
'field_campus:ignore_case',
'body:summary', 'field_date:rrule', 'field_date:to', 'field_nist_topics:ignore_case',
'field_image:language',
'field_related_event',
'field_related_publication',
'field_related_project',
'field_related_instrument_tool',
'field_related_news',
'field_image:alt',
'field_image:title',
'field_featured',
'field_featured_homepage',
'field_image_caption',
'field_image_caption:language',
'field_rss',
'field_contact_description',
'field_contact_description:language',
'field_contact_description_2',
'field_contact_description_2:language',
'field_contact_description_3',
'field_contact_description_3:language',
'field_external_contact',
'field_external_contact_2',
'field_external_contact_3',
'field_legacy_contact:language',
'field_nist_internal_contact',
'field_nist_internal_contact_2',
'field_nist_internal_contact_3',
'field_related_video'
));
// Unmapped source fields
$this->addUnmigratedSources(array(
'pagename',
'page_description',
'fic_news_item_contact_email',
'fic_news_item_contact_phone',
'fic_news_item_thumbnail',
'fic_commenturl',
'fic_includeinslideshow',
'fic_slideshowimage',
'fic_slideshowtext',
'fic_quicklink',
'owner_name',
'page_title'
));
}
/**
* Implementation of Migration::prepareRow($row).
*/
public function prepareRow($row) {
if (parent::prepareRow($row) === FALSE) :
return FALSE;
endif;
$row->legacyPath = $row->path;
$row->cs_uid = $this->_translate_user_id($row->cs_uid);
// get the new Taxonomy terms based on current Commonspot taxonomy ids
$row->newTaxonomyTermList = $this->getNewMappedTaxonomyTermsByOldIDList($row->taxonomy_ids);
// $row->migrate_thisIsMyField = 'somevalue';
$row->fic_news_item_associated_campus = $this->_process_campus($row->fic_news_item_associated_campus);
$row->fic_news_item_body = $this->_process_body_text_native($row->fic_news_item_body, 'news-migrate-image');
// Translates CS Subsite to NIST organization
$row->generatedOrg = $this->_get_org_chart_name($row->path);
// add some time (one min) to the changed value so it is forced to be updated.
$row->changed = $this->_get_updated_time_for_force_updating( $row->changed );
// access rights taxonomy
$theTID = $this->getPermissionTaxonomyDataBySubSiteURL( $this->getSubSiteFromPath($row->path) );
if ($theTID === NULL) {
$theTID = $this->getPermissionTaxonomyDataBySubSiteURL( '/pba/' );
}
$row->permissionTIDBasedOnSubSite = $theTID;
$row->contact_block = '<a href="mailto:' . $row->fic_news_item_contact_email . '">'
. $row->fic_news_item_contact_name . '</a><br>' . $row->fic_news_item_contact_phone;
}
/*
public function convertTableImageToFigureImage( $body ){
$dom = new DOMDocument();
$dom->loadHTML( $body );
$tableListObject = $dom->getElementsByTagName( "table" );
$theFirstH1Node = $tableListObject->item( 0 );
}
*/
/**
* I am called by convention by the Migrate framework
* @param $node
* @param \stdClass $row
*/
public function prepare($node, stdClass $row) {
// sometimes the checkbox for pathauto isn't checked by default. Lets go ahead
// and force it.
$node->path['pathauto'] = TRUE;
}
/**
* I am called by convention by the Migrate framework
* @param $node
* @param \stdClass $row
*/
public function complete($node, stdClass $row) {
$this->addRedirect($node, $row);
$this->addWorkBenchModerationNodeHistoryEntry($node);
}
/**
* I am called by convention. I call the completRollbck
* @param array $nids
*/
public function bulkRollback(array $nids) {
//$this->prepareRollback($nids, 'News');
}
/**
* I am called by convention by the Migrate framework after an import has
* run.
*/
public function postImport() {
$this->logMessage('News Migrated', 'news.log');
}
}