aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-14 09:45:06 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-14 09:45:06 +0000
commitf9e39ad927eeef1a1a96d953520dffb9c2520a66 (patch)
treec61944e9f339de5a24bec50b2f7353a1e6877310
parentf7fcac7a79f005f4e1bcc115ee592c8a3b610cdc (diff)
downloadelgg-f9e39ad927eeef1a1a96d953520dffb9c2520a66.tar.gz
elgg-f9e39ad927eeef1a1a96d953520dffb9c2520a66.tar.bz2
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
-rw-r--r--engine/lib/extender.php57
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())