From f9e39ad927eeef1a1a96d953520dffb9c2520a66 Mon Sep 17 00:00:00 2001 From: marcus Date: Mon, 14 Jul 2008 09:45:06 +0000 Subject: Introducing oddmetadata_to_elggextender(), a function used for import but functionised to let you use it from elsewhere. git-svn-id: https://code.elgg.org/elgg/trunk@1412 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/extender.php | 57 +++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 21 deletions(-) (limited to 'engine/lib') 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 @@ -240,6 +240,41 @@ return 'text'; } + /** + * 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. */ @@ -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()) -- cgit v1.2.3