aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-12 18:48:01 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-07-12 18:48:01 +0000
commitf7fcac7a79f005f4e1bcc115ee592c8a3b610cdc (patch)
treeb017afb1a4d755c32381035764973394ce91099a /engine/lib
parent09484c7ca03f04c5fc68ff2b543b4a1d583f25a5 (diff)
downloadelgg-f7fcac7a79f005f4e1bcc115ee592c8a3b610cdc.tar.gz
elgg-f7fcac7a79f005f4e1bcc115ee592c8a3b610cdc.tar.bz2
Introducing oddentity_to_elggentity(), a function used for import but functionised to let you use it from elsewhere.
git-svn-id: https://code.elgg.org/elgg/trunk@1411 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/entities.php81
1 files changed, 52 insertions, 29 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 278e80a35..7b5383dee 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1283,54 +1283,76 @@
}
/**
- * Import an entity.
- * This function checks the passed XML doc (as array) to see if it is a user, if so it constructs a new
- * elgg user and returns "true" to inform the importer that it's been handled.
+ * Utility function used by import_entity_plugin_hook() to process an ODDEntity into an unsaved ElggEntity.
+ *
+ * @param ODDEntity $element The OpenDD element
+ * @return ElggEntity the unsaved entity which should be populated by items.
*/
- function import_entity_plugin_hook($hook, $entity_type, $returnvalue, $params)
+ function oddentity_to_elggentity(ODDEntity $element)
{
- $element = $params['element'];
+ $class = $element->getAttribute('class');
+ $subclass = $element->getAttribute('subclass');
- $tmp = NULL;
+ // See if we already have imported this uuid
+ $tmp = get_entity_from_uuid($element->getAttribute('uuid'));
- if ($element instanceof ODDEntity)
+ if (!$tmp)
{
- $class = $element->getAttribute('class');
- $subclass = $element->getAttribute('subclass');
-
- // See if we already have imported this uuid
- $tmp = get_entity_from_uuid($element->getAttribute('uuid'));
-
- if (!$tmp)
+ // Construct new class with owner from session
+ $classname = get_subtype_class($class, $subclass);
+ if ($classname!="")
{
- // Construct new class with owner from session
- $classname = get_subtype_class($class, $subclass);
- if ($classname!="")
+ if (class_exists($classname))
{
$tmp = new $classname();
if (!($tmp instanceof ElggEntity))
throw new ClassException(sprintf(elgg_echo('ClassException:ClassnameNotClass', $classname, get_class())));
-
}
else
+ error_log(sprintf(elgg_echo('ClassNotFoundException:MissingClass'), $classname));
+ }
+ else
+ {
+ switch ($class)
{
- switch ($class)
- {
- case 'object' : $tmp = new ElggObject($row); break;
- case 'user' : $tmp = new ElggUser($row); break;
- case 'group' : $tmp = new ElggGroup($row); break;
- case 'site' : $tmp = new ElggSite($row); break;
- default: throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $class));
- }
+ case 'object' : $tmp = new ElggObject($row); break;
+ case 'user' : $tmp = new ElggUser($row); break;
+ case 'group' : $tmp = new ElggGroup($row); break;
+ case 'site' : $tmp = new ElggSite($row); break;
+ default: throw new InstallationException(sprintf(elgg_echo('InstallationException:TypeNotSupported'), $class));
}
}
+ }
+
+ if ($tmp)
+ {
+ if (!$tmp->import($element))
+ throw new ImportException(sprintf(elgg_echo('ImportException:ImportFailed'), $element->getAttribute('uuid')));
+
+ return $tmp;
+ }
+
+ return NULL;
+ }
+
+ /**
+ * Import an entity.
+ * This function checks the passed XML doc (as array) to see if it is a user, if so it constructs a new
+ * elgg user and returns "true" to inform the importer that it's been handled.
+ */
+ function import_entity_plugin_hook($hook, $entity_type, $returnvalue, $params)
+ {
+ $element = $params['element'];
+
+ $tmp = NULL;
+
+ if ($element instanceof ODDEntity)
+ {
+ $tmp = oddentity_to_elggentity($element);
if ($tmp)
{
- if (!$tmp->import($element))
- throw new ImportException(sprintf(elgg_echo('ImportException:ImportFailed'), $element->getAttribute('uuid')));
-
if (!$tmp->save()) // Make sure its saved
throw new ImportException(sprintf(elgg_echo('ImportException:ProblemSaving'), $element->getAttribute('uuid')));
@@ -1342,6 +1364,7 @@
return $tmp;
}
+
}
}