aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-31 17:02:03 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-31 17:02:03 +0000
commit887b0b7e2e93a908f56cefc8b99f69827459fbae (patch)
tree7f755c6f655192916e4da9ff70194684057b58ed /engine
parent3d822eae1b96a1a8549e23ed83913ec7281b8c01 (diff)
downloadelgg-887b0b7e2e93a908f56cefc8b99f69827459fbae.tar.gz
elgg-887b0b7e2e93a908f56cefc8b99f69827459fbae.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Somewhat more robust import logic git-svn-id: https://code.elgg.org/elgg/trunk@298 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/export.php52
1 files changed, 49 insertions, 3 deletions
diff --git a/engine/lib/export.php b/engine/lib/export.php
index 994789042..7f01364b7 100644
--- a/engine/lib/export.php
+++ b/engine/lib/export.php
@@ -33,9 +33,10 @@
* The function should return the constructed object data, or NULL.
*
* @param array $data
+ * @param int $version Support different internal serialisation formats, should be "1"
* @throws ImportException if there was a critical error importing data.
*/
- public function import(array $data);
+ public function import(array $data, $version = 1);
}
/**
@@ -122,6 +123,9 @@
return $xmlary;
}
+
+ $IMPORTED_DATA = array();
+ $IMPORTED_OBJECT_COUNTER = 0;
/**
* This function processes an element, passing elements to the plugin stack to see if someone will
@@ -130,28 +134,52 @@
*/
function __process_element(array $dom)
{
+ global $IMPORTED_DATA, $IMPORTED_OBJECT_COUNTER;
+
foreach ($dom as $element)
{
// See if anyone handles this element, return true if it is.
$handled = trigger_plugin_hook("import", "all", array("name" => $element['name'], "element" => $element), $to_be_serialised);
// If not, then see if any of its sub elements are handled
- if ((!$handled) && (isset($element['elements']))) __process_element($element['elements']);
+ if (!$handled)
+ {
+ if (isset($element['elements']))
+ __process_element($element['elements']);
+ }
+ else
+ {
+ $IMPORTED_OBJECT_COUNTER ++; // Increment validation counter
+ $IMPORTED_DATA[] = $handled; // Return the constructed object
+ }
}
}
+
+
/**
* Import an XML serialisation of an object.
* This will make a best attempt at importing a given xml doc.
*
* @param string $xml
- * @return int The new GUID of the object.
+ * @return array An array of imported objects (these have already been saved).
+ * @throws Exception if there was a problem importing the data.
*/
function import($xml)
{
+ global $IMPORTED_DATA, $IMPORTED_OBJECT_COUNTER;
+
+ $IMPORTED_DATA = array();
+ $IMPORTED_OBJECT_COUNTER = 0;
+
$dom = __xml2array($xml);
__process_element($dom);
+
+ if ($IMPORTED_OBJECT_COUNTER!= count($IMPORTED_DATA))
+ throw new ImportException("Not all elements were imported.");
+
+ return $IMPORTED_DATA;
}
/**
@@ -167,6 +195,24 @@
}
/**
+ * Test to see if a given uuid is for this domain, returning true if so.
+ * @param $uuid
+ * @return bool
+ */
+ function is_uuid_this_domain($uuid)
+ {
+ global $CONFIG;
+
+ $domain = md5($CONFIG->wwwroot);
+ $tmp = explode(":",$uuid);
+
+ if (strcmp($tmp[1], $domain) == 0)
+ return true;
+
+ return false;
+ }
+
+ /**
* This function serialises an object recursively into an XML representation.
* The function attempts to call $data->export() which expects a stdClass in return, otherwise it will attempt to
* get the object variables using get_object_vars (which will only return public variables!)