From 8a2c85d1650321b1731c21b448a2e3f6e3155e2d Mon Sep 17 00:00:00 2001 From: icewing Date: Tue, 1 Apr 2008 14:27:15 +0000 Subject: Marcus Povey * Some UUID functions git-svn-id: https://code.elgg.org/elgg/trunk@309 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/export.php | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'engine/lib/export.php') diff --git a/engine/lib/export.php b/engine/lib/export.php index 33d7946a7..024f25a63 100644 --- a/engine/lib/export.php +++ b/engine/lib/export.php @@ -75,8 +75,6 @@ $wrapper->header->date = date("r"); $wrapper->header->timestamp = time(); $wrapper->header->domain = $CONFIG->wwwroot; - $wrapper->header->guid = $guid; - $wrapper->header->uuid = guid_to_uuid($guid); $wrapper->header->exported_by = guid_to_uuid($_SESSION['id']); // Construct data @@ -155,8 +153,6 @@ } } } - - /** * Import an XML serialisation of an object. @@ -172,6 +168,7 @@ $IMPORTED_DATA = array(); $IMPORTED_OBJECT_COUNTER = 0; + $IMPORTED_GUID_MAP = array(); $dom = __xml2array($xml); @@ -212,6 +209,36 @@ return false; } + + /** + * This function attempts to retrieve a previously imported entity via its UUID. + * + * @param $uuid + */ + function get_entity_from_uuid($uuid) + { + $uuid = sanitise_string($uuid); + + $entities = get_entities_from_metadata("import_uuid", $uuid); + if ((!$entities) || (count($entities)!=1)) + throw new InvalidParameterException("Unexpected number of entities tagged with $uuid, previous import failed?"); + + return $entities[0]; + } + + /** + * Tag a previously created guid with the uuid it was imported on. + * + * @param int $guid + * @param string $uuid + */ + function add_uuid_to_guid($guid, $uuid) + { + $guid = (int)$guid; + $uuid = sanitise_string($uuid); + + return create_metadata($guid, "import_uuid", $uuid); + } /** * This function serialises an object recursively into an XML representation. -- cgit v1.2.3