diff options
author | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-04-15 15:04:08 +0000 |
---|---|---|
committer | icewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2008-04-15 15:04:08 +0000 |
commit | 8a0ab3d2754d4799329d48b9c7f9ca18508f4d73 (patch) | |
tree | 55954c3c2bb4f8e3f914f2cce53c7d73811f64f0 /engine/lib/relationships.php | |
parent | 4486fb03c1bf589083d2a57671a30849befcd976 (diff) | |
download | elgg-8a0ab3d2754d4799329d48b9c7f9ca18508f4d73.tar.gz elgg-8a0ab3d2754d4799329d48b9c7f9ca18508f4d73.tar.bz2 |
Marcus Povey <marcus@dushka.co.uk>
* Relationship import
git-svn-id: https://code.elgg.org/elgg/trunk@460 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/relationships.php')
-rw-r--r-- | engine/lib/relationships.php | 68 |
1 files changed, 27 insertions, 41 deletions
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php index bc23ffd20..bba930580 100644 --- a/engine/lib/relationships.php +++ b/engine/lib/relationships.php @@ -132,53 +132,38 @@ */ public function import(ODD $data) { - if ($version == 1) + if (!($element instanceof ODDRelationship)) + throw new InvalidParameterException("ElggRelationship::import() passed an unexpected ODD class"); + + $uuid_one = $data->getAttribute('uuid1'); + $uuid_two = $data->getAttribute('uuid2'); + + // See if this entity has already been imported, if so then we need to link to it + $entity1 = get_entity_from_uuid($uuid_one); + $entity2 = get_entity_from_uuid($uuid_two); + if (($entity1) && ($entity2)) { - $uuid_one = NULL; - $uuid_two = NULL; + // Set the item ID + $this->attributes['guid_one'] = $entity1->getGUID(); + $this->attributes['guid_two'] = $entity2->getGUID(); - // Get attributes - foreach ($data['elements'][0]['elements'] as $attr) - { - $name = strtolower($attr['name']); - $text = $attr['text']; - - switch ($name) - { - case 'id' : break; - case 'entity_uuid' : $entity_uuid = $text; break; - default : $this->attributes[$name] = $text; - } - - } - // See if this entity has already been imported, if so then we need to link to it - $entity1 = get_entity_from_uuid($uuid_one); - $entity2 = get_entity_from_uuid($uuid_two); - if (($entity1) && ($entity2)) - { + // Map verb to relationship + $verb = $data->getAttribute('verb'); + $this->attributes['relationship'] = get_relationship_from_verb($verb); + if (!$this->attributes['relationship']) + throw new ImportException("Could not import '$verb' as a relationship."); - // Set the item ID - $this->attributes['guid_one'] = $entity1->getGUID(); - $this->attributes['guid_two'] = $entity2->getGUID(); - - // save - $result = $this->save(); - if (!$result) - throw new ImportException("There was a problem saving the ElggExtender"); - - return $this; - } - - return false; + // save + $result = $this->save(); + if (!$result) + throw new ImportException("There was a problem saving the ElggExtender"); + return $this; } - else - throw new ImportException("Unsupported version ($version) passed to ElggRelationship::import()"); } } - /** * Convert a database row to a new ElggRelationship * @@ -363,16 +348,17 @@ */ function import_relationship_plugin_hook($hook, $entity_type, $returnvalue, $params) { - /*$name = $params['name']; $element = $params['element']; - if ($name=='ElggRelationship') + $tmp = NULL; + + if ($element instanceof ODDRelationship) { $tmp = new ElggRelationship(); $tmp->import($element); return $tmp; - }*/ + } } /** |