diff options
Diffstat (limited to 'engine/lib/extender.php')
-rw-r--r-- | engine/lib/extender.php | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/engine/lib/extender.php b/engine/lib/extender.php index e8bb54880..b3b98353b 100644 --- a/engine/lib/extender.php +++ b/engine/lib/extender.php @@ -241,6 +241,41 @@ } /** + * Utility function used by import_extender_plugin_hook() to process an ODDMetaData and add it to an entity. + * This function does not hit ->save() on the entity (this lets you construct in memory) + * + * @param ElggEntity The entity to add the data to. + * @param ODDMetaData $element The OpenDD element + * @return bool + */ + function oddmetadata_to_elggextender(ElggEntity $entity, ODDMetaData $element) + { + // Get the type of extender (metadata, type, attribute etc) + $type = $element->getAttribute('type'); + $attr_name = $element->getAttribute('name'); + $attr_val = $element->getBody(); + + switch ($type) + { + case 'annotation' : + $entity->annotate($attr_name, $attr_val); + break; + case 'metadata' : + $entity->setMetaData($attr_name, $attr_val, "", true); + break; + default : // Anything else assume attribute + $entity->set($attr_name, $attr_val); + } + + // Set time if appropriate + $attr_time = $element->getAttribute('published'); + if ($attr_time) + $entity->set('time_created', $attr_time); + + return true; + } + + /** * Handler called by trigger_plugin_hook on the "import" event. */ function import_extender_plugin_hook($hook, $entity_type, $returnvalue, $params) @@ -257,27 +292,7 @@ if (!$entity) throw new ImportException(sprintf(elgg_echo('ImportException:GUIDNotFound'), $entity_uuid)); - // Get the type of extender (metadata, type, attribute etc) - $type = $element->getAttribute('type'); - $attr_name = $element->getAttribute('name'); - $attr_val = $element->getBody(); - - switch ($type) - { - case 'annotation' : - $entity->annotate($attr_name, $attr_val); - break; - case 'metadata' : - $entity->setMetaData($attr_name, $attr_val, "", true); - break; - default : // Anything else assume attribute - $entity->set($attr_name, $attr_val); - } - - // Set time if appropriate - $attr_time = $element->getAttribute('published'); - if ($attr_time) - $entity->set('time_created', $attr_time); + oddmetadata_to_elggextender($entity, $element); // Save if (!$entity->save()) |