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/objects.php | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'engine/lib/objects.php') diff --git a/engine/lib/objects.php b/engine/lib/objects.php index e44a005ff..b14e984c0 100644 --- a/engine/lib/objects.php +++ b/engine/lib/objects.php @@ -217,22 +217,35 @@ $row = get_entity_as_row($guid); if ($row) - { - // Exists and you have access to it - - // Delete any existing stuff - delete_object_entity($guid); - - // Insert it - $result = insert_data("INSERT into {$CONFIG->dbprefix}objects_entity (guid, title, description) values ($guid, '$title','$description')"); - if ($result!==false) { - $entity = get_entity($guid); - if (trigger_event('create',$entity->type,$entity)) { - return true; - } else { - delete_entity($guid); - } + { + // Core entities row exists and we have access to it + + $result = update_data("UPDATE {$CONFIG->dbprefix}objects_entity set title='$title', description='$description' 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}objects_entity (guid, title, description) values ($guid, '$title','$description')"); + if ($result!==false) { + $entity = get_entity($guid); + if (trigger_event('create',$entity->type,$entity)) { + return true; + } else { + delete_entity($guid); + } + } } + } return false; -- cgit v1.2.3