From 8a0ab3d2754d4799329d48b9c7f9ca18508f4d73 Mon Sep 17 00:00:00 2001 From: icewing Date: Tue, 15 Apr 2008 15:04:08 +0000 Subject: Marcus Povey * Relationship import git-svn-id: https://code.elgg.org/elgg/trunk@460 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/relationships.php | 68 ++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 41 deletions(-) (limited to 'engine/lib') 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; - }*/ + } } /** -- cgit v1.2.3