aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/entities.php
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-01 13:55:34 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-01 13:55:34 +0000
commita08509ec171b12f609a8941c86541f3a413ea913 (patch)
treedc9c011f941d63109890c70e9b3209e85300d3bf /engine/lib/entities.php
parentc6c78290c26a2784c641571d20cdba58a6863d9b (diff)
downloadelgg-a08509ec171b12f609a8941c86541f3a413ea913.tar.gz
elgg-a08509ec171b12f609a8941c86541f3a413ea913.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Moved import to ElggEntity git-svn-id: https://code.elgg.org/elgg/trunk@302 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/entities.php')
-rw-r--r--engine/lib/entities.php51
1 files changed, 50 insertions, 1 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index e96a781f9..8784e9af4 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -16,7 +16,7 @@
* This class holds methods for accessing the main entities table.
* @author Marcus Povey <marcus@dushka.co.uk>
*/
- abstract class ElggEntity implements Exportable
+ abstract class ElggEntity implements Exportable, Importable
{
/**
* The main attributes of an entity.
@@ -310,6 +310,55 @@
$tmp->attributes['owner_uuid'] = guid_to_uuid($this->owner_guid);
return $tmp;
}
+
+ /**
+ * Import data from an parsed xml data array.
+ *
+ * @param array $data
+ * @param int $version
+ */
+ public function import(array $data, $version = 1)
+ {
+ if ($version == 1)
+ {
+ $uuid = "";
+
+ // Get attributes
+ foreach ($data['elements'][0]['elements'] as $attr)
+ {
+ $name = strtolower($attr['name']);
+ $text = $attr['text'];
+
+ switch ($name)
+ {
+ case 'uuid' : $uuid = $text; break;
+ default : $this->attributes[$name] = $text;
+ }
+ }
+
+ // Check uuid as local domain
+ if (is_uuid_this_domain($uuid))
+ throw new ImportException("$uuid belongs to this domain!");
+
+ // See if this entity has already been imported, if so we don't need to create a new element
+ $entity = get_entity_from_uuid($uuid);
+ if ($entity)
+ $this->attributes['guid'] = $entity->guid;
+
+ // save
+ if (!$this->save());
+ throw new ImportException("There was a problem saving $uuid");
+
+ // Tag this GUID with the UUID if this is a new entity
+ if (!$entity)
+ add_uuid_to_guid($this->attributes['guid'], $uuid);
+
+ // return result
+ return $this;
+ }
+ else
+ throw new ImportException("Unsupported version ($version) passed to ElggEntity::import()");
+ }
}
/**