Last active
November 22, 2015 12:12
-
-
Save kyleskrinak/a6b45ac37f0139ffde72 to your computer and use it in GitHub Desktop.
This Drupal Migration_d2d class fails to import an entire node when the source node's body field is empty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: kds38 | |
* Date: 15/11/10 | |
* Time: 4:20 PM | |
*/ | |
class DivinityPersonMigration extends DivinityNodeMigration { | |
public function __construct(array $arguments) { | |
parent::__construct($arguments); | |
$this->addFieldMapping('log', 'log', FALSE) | |
->defaultValue('Imported by the DivinityJobMigration class ' . date('D, d M Y H:i:s',time())); | |
$this->addFieldMapping('field_faculty_research_areas', 'taxonomy_vocabulary_1') | |
->sourceMigration('Faculty_research_areas'); | |
$this->addFieldMapping('field_faculty_research_areas:source_type') | |
->defaultValue('tid'); | |
//Photo migration attributes | |
$this->addFieldMapping('field_person_photo', 'field_person_photo') | |
->sourceMigration('Files'); | |
$this->addFieldMapping('field_person_photo:file_class') | |
->defaultValue('MigrateFileFid'); | |
$this->addFieldMapping('field_person_photo:preserve_files') | |
->defaultValue(TRUE); | |
$this->addFieldMapping('field_person_cv', 'field_person_cv') | |
->sourceMigration('Files'); | |
$this->addFieldMapping('field_person_cv:preserve_files') | |
->defaultValue(TRUE); | |
$this->addFieldMapping('field_person_cv:file_class') | |
->defaultValue('MigrateFileFid'); | |
$this->addFieldMapping('field_person_address:format', 'field_person_address:format') | |
->callbacks(array($this, 'mapFormat')); | |
$this->addFieldMapping('field_person_degrees:format', 'field_person_degrees:format') | |
->callbacks(array($this, 'mapFormat')); | |
$this->addFieldMapping('field_person_courses:format', 'field_person_courses:format') | |
->callbacks(array($this, 'mapFormat')); | |
$this->addFieldMapping('field_person_open:format', 'field_person_open:format') | |
->callbacks(array($this, 'mapFormat')); | |
$this->addFieldMapping('field_person_pubs:format', 'field_person_pubs:format') | |
->callbacks(array($this, 'mapFormat')); | |
$this->addSimpleMappings(array( | |
'field_person_address', | |
'field_person_address:language', | |
'field_person_courses', | |
'field_person_courses:language', | |
'field_person_cv:display', | |
'field_person_cv:description', | |
'field_person_cv:language', | |
'field_person_degrees', | |
'field_person_degrees:language', | |
'field_person_email', | |
'field_person_email:language', | |
'field_person_fname', | |
'field_person_fname:language', | |
'field_person_lname', | |
'field_person_lname:language', | |
'field_person_mname', | |
'field_person_mname:language', | |
'field_person_office', | |
'field_person_office:language', | |
'field_person_open', | |
'field_person_open:language', | |
'field_person_phone', | |
'field_person_phone:language', | |
'field_person_photo:alt', | |
'field_person_photo:language', | |
'field_person_photo:title', | |
'field_person_position', | |
'field_person_position:language', | |
'field_person_pubs', | |
'field_person_pubs:language', | |
'field_person_type', | |
)); | |
$this->addUnmigratedDestinations(array( | |
'field_faculty_research_areas:create_term', | |
'field_faculty_research_areas:ignore_case', | |
)); | |
$this->addUnmigratedSources(array( | |
'taxonomy_vocabulary_1:language', | |
'body:language', | |
'field_person_degrees:format', | |
'field_person_photo:height', | |
'field_person_photo:width', | |
'field_person_type:language', | |
)); | |
} | |
/* | |
public function prepareRow($row) { | |
if (parent::prepareRow($row) === FALSE) { | |
return FALSE; | |
} | |
if ($row->field_person_degrees) { | |
$str = $row->field_person_degrees[0]; | |
$tags = array( | |
'</p>', | |
'<br />', | |
'<br>', | |
'<hr />', | |
'<hr>', | |
'</h1>', | |
'</h2>', | |
'</h3>', | |
'</h4>', | |
'</h5>', | |
'</h6>' | |
); | |
$row->field_person_degrees[0] = strip_tags(str_replace($tags, "\n", $str)); | |
} | |
// The property 'tnid' cannot be handled via sourceMigration() method | |
// because it might be 0 or the main node of translation set. We don't want | |
// to create a stub for such cases. | |
if (!empty($row->tnid)) { | |
$destination_ids = $this->getMap() | |
->lookupDestinationID(array($row->tnid)); | |
// There's no destination yet. Create a stub. | |
if (empty($destination_ids)) { | |
// Don't create stub for itself. | |
if ($row->tnid != $row->nid) { | |
// Check if 'tnid' is a node in the source set to prevent not | |
// updatable stubs. | |
$query = clone $this->query(); | |
$query->condition('n.nid', $row->tnid); | |
$nid = $query->execute()->fetchField(); | |
unset($query); | |
if ($nid) { | |
if ($tnids = $this->createStub(NULL)) { | |
// Save the mapping. | |
$this->map->saveIDMapping((object) array('nid' => $row->tnid), $tnids, MigrateMap::STATUS_NEEDS_UPDATE, $this->defaultRollbackAction); | |
$row->tnid = reset($tnids); | |
} | |
} | |
} | |
else { | |
$row->tnid = 0; | |
$row->_is_translation_source = TRUE; | |
} | |
} | |
else { | |
$row->tnid = $destination_ids['destid1']; | |
} | |
} | |
} | |
*/ | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment