From e06d41575c5d9a00378e69355a3467143ac68456 Mon Sep 17 00:00:00 2001 From: icewing Date: Mon, 2 Jun 2008 14:04:25 +0000 Subject: Marcus Povey * Update and creates now handled separately, with the appropriate events triggered. git-svn-id: https://code.elgg.org/elgg/trunk@772 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/sites.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) (limited to 'engine/lib/sites.php') diff --git a/engine/lib/sites.php b/engine/lib/sites.php index dbe6d13b1..1c75fdff6 100644 --- a/engine/lib/sites.php +++ b/engine/lib/sites.php @@ -253,19 +253,29 @@ if ($row) { // Exists and you have access to it - - // Delete any existing stuff - delete_site_entity($guid); - - // Insert it - $result = insert_data("INSERT into {$CONFIG->dbprefix}sites_entity (guid, name, description, url) values ($guid, '$name','$description','$url')"); - if ($result!==false) { - get_entity($guid); - if (trigger_event('create',$entity->type,$entity)) { - return true; - } else { - delete_entity($guid); - } + $result = update_data("UPDATE {$CONFIG->dbprefix}sites_entity set name='$name', description='$description', url='$url' where guid=$guid"); + if ($result!=false) + { + // Update succeeded, continue + $entity = get_entity($guid); + if (trigger_event('update',$entity->type,$entity)) { + return true; + } else { + delete_entity($guid); + } + } + else + { + // Update failed, attempt an insert. + $result = insert_data("INSERT into {$CONFIG->dbprefix}sites_entity (guid, name, description, url) values ($guid, '$name','$description','$url')"); + if ($result!==false) { + $entity = get_entity($guid); + if (trigger_event('create',$entity->type,$entity)) { + return true; + } else { + delete_entity($guid); + } + } } } -- cgit v1.2.3