-
Notifications
You must be signed in to change notification settings - Fork 0
/
blankpages.inc
363 lines (286 loc) · 12.4 KB
/
blankpages.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
<?php
/**
* @file
* Implementation of migration from Commonspot blank page custom elements to
* Drupal Basic Page nodes.
*
*/
class NistBlankPagesMigration extends NistMigration {
public function __construct($arguments) {
parent::__construct($arguments);
$this->description = t('Import of Commonspot blank pages content types into Drupal\'s Basic Page content type');
$this->dependencies = array('NistUser');
// create a date that is 2 days older than now
$fromdate = $this->getFromDate(2);
// CommonSpot form ID
$form_id = "";
// the URL to pull ID and Pages from
$list_url = "{JSON array with list of item IDs that will be passed into the method below}";
$item_url = "{single record method that takes an id query string}=:id";
$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_blank_page_column_amout' => 'meta info about the number of columns layout of the page',
'fic_blank_page_content' => 'big nasty blob of HTML that is the content of the page',
'fic_contact_information' => 'Contact block from the page',
'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 any images inside the page.',
'path' => 'URL in the CommonSpot system possibly used for Pathauto purposes',
'sidebar' => 'DOM scrape of content I can\'t pull as structured in the sidebar',
'sidebar2' => 'the other sidebar of three column pages, see above',
'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 MigrateSourceList(
new MigrateListJSON($list_url),
new MigrateItemJSON($item_url, array()),
$fields
);
$this->destination = new MigrateDestinationNode('page');
$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('body', 'bodyContentWithOutInitialH1Tag');
$this->addFieldMapping('body:format')
->defaultValue('filtered_html');
$this->addFieldMapping('body:language')->defaultValue('en');
$this->addFieldMapping('changed', 'changed');
$this->addFieldMapping('created', 'created');
$this->addFieldMapping('field_image', 'parsedimageids')
->separator(', ')
->sourceMigration('NistImage');
$this->addFieldMapping('field_image:file_class')
->defaultValue('MigrateFileFid');
$this->addFieldMapping('field_image:preserve_files')
->defaultValue(TRUE);
// field_legacy_contact
$this->addFieldMapping('field_legacy_contact', 'fic_contact_information');
$this->addFieldMapping('field_legacy_contact:format')
->defaultValue('filtered_html');
// field_legacy_owner_name
$this->addFieldMapping('field_legacy_owner_name', 'owner_name');
$this->addFieldMapping('field_legacy_owner_name:language')
->defaultValue('en');
// field_legacy_sidebar_1
$this->addFieldMapping('field_legacy_sidebar_1', 'sideBar1Processed');
$this->addFieldMapping('field_legacy_sidebar_1:format')
->defaultValue('filtered_html');
// field_legacy_sidebar_2
$this->addFieldMapping('field_legacy_sidebar_2', 'sideBar2Processed');
$this->addFieldMapping('field_legacy_sidebar_2:format')
->defaultValue('filtered_html');
// field_legacy_url
$this->addFieldMapping('field_legacy_url', 'legacyPath');
$this->addFieldMapping('field_legacy_url:language')
->defaultValue('en');
// 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');
// field_nist_org
$this->addFieldMapping('field_nist_org', 'generatedOrg');
// field_nist_topics
$this->addFieldMapping('field_nist_topics', 'taxonomy_ids')
->separator(', ')
->sourceMigration('NistTerm');
// 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');
// field_test_content
$this->addFieldMapping('field_test_content')
->defaultValue(0);
// field_nist_topics
$this->addFieldMapping('field_nist_topics:create_term')
->defaultValue('False');
$this->addFieldMapping('field_nist_topics:source_type')
->defaultValue('tid');
/*
$this->addFieldMapping('pathauto')
->defaultValue(0);
*/
$this->addFieldMapping('status')
->defaultValue(1);
$this->addFieldMapping('title', 'theTitle');
$this->addFieldMapping('translate')
->defaultValue(0);
$this->addFieldMapping('uid', 'cs_uid')
->sourceMigration('NistUser');
// sections for pages
$this->addFieldMapping('field_section', 'generatedSectionFromPath');
// don't want to add the path anymore. borks menus
// path
// $this->addFieldMapping('path', 'path');
$this->addUnmigratedDestinations(array('is_new', 'revision_uid', 'promote',
'sticky', 'revision', 'log', 'language', 'tnid', 'comment', 'body:summary',
'field_nist_topics:ignore_case', 'field_campus', 'field_campus:source_type',
'field_campus:ignore_case', 'field_campus:create_term', 'field_contact_description',
'field_contact_description_2', 'field_contact_description_3', 'field_external_contact',
'field_external_contact_2', 'field_external_contact_3', 'field_document',
'field_document:file_class', 'field_document:preserve_files',
'field_document:destination_dir', 'field_document:destination_file',
'field_document:file_replace', 'field_document:source_dir',
'field_document:urlencode', 'field_document:description',
'field_nist_internal_contact', 'field_nist_internal_contact_2',
'field_nist_internal_contact_3',
'field_document:display', 'field_hero_content',
));
$this->addUnmigratedSources(array('pagename', 'page_description'));
}
/**
* Implementation of Migration::prepareRow($row).
*/
public function prepareRow($row) {
if (parent::prepareRow($row) === FALSE) :
return FALSE;
endif;
$row->theTitle = $this->getPageTitle($row->page_title, $row->fic_blank_page_content);
// get the new Taxonomy terms based on current Commonspot taxonomy ids
$row->newTaxonomyTermList = $this->getNewMappedTaxonomyTermsByOldIDList($row->taxonomy_ids);
// Fixes userID. translates it from Commonspot to CPR ID.
$row->cs_uid = $this->_translate_user_id($row->cs_uid);
$row->bodyContentWithOutInitialH1Tag = $this->removeInitialH1Tag($this->_process_body_text_native($row->fic_blank_page_content, 'blankpage-migrate-image'));
//$row->bodyContentWithOutInitialH1Tag = $row->fic_blank_page_content;
$row->sideBar1Processed = $this->_process_body_text_native($row->sidebar, 'blankpage-migrate-image');
$row->sideBar2Processed = $this->_process_body_text_native($row->sidebar2, 'blankpage-migrate-image');
$row->legacyPath = $row->path;
// Fix path to CS path without the .cfm
//$row->path = $this->_process_path($row->path);
// 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) );
$row->permissionTIDBasedOnSubSite = $theTID;
$row->generatedSectionFromPath = $this->getGeneratedSectionFromPath($theTID);
// Cleans up rubbish code
//$row->fic_blank_page_content = $this->_process_body_text_native($row->fic_blank_page_content, 'blankpage-migrate-image');
}
/**
* I return the page title based on if one is supplied in the page_title
* field
* @param $pageTitle
* @param $bodyContent
* @return string
*/
public function getPageTitle($pageTitle, $bodyContent) {
if ( strlen($pageTitle) == 0 && strlen($bodyContent) != 0) {
$dom = new DOMDocument();
$dom->loadHTML( $bodyContent );
$h1List = $dom->getElementsByTagName( "h1" );
$theFirstH1Node = $h1List->item( 0 );
$result = $theFirstH1Node->nodeValue;
}
else {
$result = $pageTitle;
}
return $result;
}
/**
* I remove the initial occurrence of the H1 Tag.
* @param $bodyContent
* @return mixed
*/
public function removeInitialH1Tag($bodyContent) {
// make the result
$result = $bodyContent;
if (strlen($bodyContent) !== 0) {
libxml_use_internal_errors(TRUE);
// build a dom object and find the 1st H1 tag
$dom = new DOMDocument();
$dom->loadHTML($bodyContent);
$h1List = $dom->getElementsByTagName("h1");
$theFirstH1Node = $h1List->item(0);
$theH1Content = $theFirstH1Node->nodeValue;
// now build the string to replace
$stringToFind = '<h1>' . $theH1Content . '</h1>';
// find the position of the H1 tag
$position = strpos($bodyContent, $stringToFind);
// if there is an h1, kill it...
if ($position !== FALSE) {
$result = substr_replace($bodyContent, '', $position, strlen($stringToFind));
}
}
return $result;
}
/**
* I am called by convention by the Migrate framework after an import has
* run.
*/
public function postImport() {
$this->logMessage( 'BlankPages Migrated', 'blankpages.log' );
}
/**
* 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;
// This is kinda breaking with Migrate tradition mention in the
// documentation, but there are several people that like this approach and I
// think it offers a little more control.
// What were ARE doing: https://www.drupal.org/node/2550939
// What were NOT doing: https://www.drupal.org/node/1117454
// we don't REALLY have to implement a whole NEW set of migrates because
// what we have is already working pretty well. We DO want to be able to
// control what might get into the object that is going to be saved.
// by getting the persisted object from the db we have MAXIMUM POWER about
// what's currently there and what were going to replace it with. I like this
// approach better then creating new scripts and having a new sytsemOfRecord
// get the current persisted object so we can inspect it and check stuff.
$currentNode = node_load($node->nid);
// we don't want to over write a blank pages section so see if the persisted
// object has one. if it does set the new objects to the olds...
if (isset($currentNode->field_section['und'][0]['target_id'])) {
$currentSectionTID = $currentNode->field_section['und'][0]['target_id'];
$node->field_section['und'][0]['target_id'] = $currentSectionTID;
}
$this->globalPrepare($node);
}
/**
* 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);
// save some memory
drupal_static_reset();
}
/**
* I am called by convention. I call the prepareRollback
* @param array $nids
*/
public function bulkRollback(array $nids) {
//$this->prepareRollback($nids, 'Award');
}
}