From 22f5976cae0acf9493f503b3d5610765eeaa276b Mon Sep 17 00:00:00 2001 From: patrickmj Date: Sun, 6 Mar 2016 14:33:04 -0500 Subject: [PATCH] refactor existing element handling to not drop attrs on existing elements --- VraCorePlugin.php | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/VraCorePlugin.php b/VraCorePlugin.php index 361cea1..76fcc4e 100644 --- a/VraCorePlugin.php +++ b/VraCorePlugin.php @@ -490,24 +490,22 @@ protected function processNewElement($omekaRecord, $omekaElementId, $elementData protected function processExistingElement($omekaRecord, $omekaElementId, $vraElementId, $elementData) { + + //elements to skip deletion. these are containers for other elements, so + //content is alway null + $skipElements = array('Agent', + 'Date', + 'dates', + 'Inscription', + 'Location', + 'Rights', + 'Source', + 'State Edition', + 'Subject', + 'Textref'); $vraElementObject = $this->_db->getTable('VraCoreElement')->find($vraElementId); - if (empty($elementData['content'])) { - //elements to skip deletion. these are containers for other elements, so - //content is alway null - $skipElements = array('Agent', - 'Date', - 'dates', - 'Inscription', - 'Location', - 'Rights', - 'Source', - 'State Edition', - 'Subject', - 'Textref'); - if( ! in_array($vraElementObject->name, $skipElements)) { - $vraElementObject->delete(); - } - + if (empty($elementData['content']) && ! in_array($vraElementObject->name, $skipElements)) { + $vraElementObject->delete(); } else { if ($vraElementObject->content != $elementData['content']) { $vraElementObject->updateDataDate(); @@ -539,6 +537,7 @@ protected function processNewSubelement($omekaRecord, $omekaElementId, $parentVr protected function processExistingSubelement($omekaRecord, $omekaElementId, $vraElementId, $elementData) { //@todo check if still needed + debug('processExistingSubelement'); $omekaRecordData = array('id' => $omekaRecord->id, 'type' => get_class($omekaRecord)); }