From 94a18aa796feef027cd33ec41ad4f955c7c991e3 Mon Sep 17 00:00:00 2001 From: ben Date: Mon, 7 Apr 2008 14:51:17 +0000 Subject: Triggering events on create, update and delete actions on entities git-svn-id: https://code.elgg.org/elgg/trunk@411 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/entities.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'engine') diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 9d7f98079..169d87eb9 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -528,11 +528,14 @@ $owner_guid = (int)$owner_guid; $access_id = (int)$access_id; $time = time(); + + $entity = get_entity($guid); - $access = get_access_list(); - - - return update_data("UPDATE {$CONFIG->dbprefix}entities set owner_guid='$owner_guid', access_id='$access_id', time_updated='$time' WHERE guid=$guid and (access_id in {$access} or (access_id = 0 and owner_guid = {$_SESSION['id']}))"); + if ($entity->canEdit()) { + if (trigger_event('update',$entity->type,$entity)) { + return update_data("UPDATE {$CONFIG->dbprefix}entities set owner_guid='$owner_guid', access_id='$access_id', time_updated='$time' WHERE guid=$guid and (access_id in {$access} or (access_id = 0 and owner_guid = {$_SESSION['id']}))"); + } + } } /** @@ -559,7 +562,11 @@ // Erased by Ben: sometimes we need unauthenticated users to create things! (eg users on registration) // if ($owner_guid==0) throw new InvalidParameterException("owner_guid must not be 0"); - return insert_data("INSERT into {$CONFIG->dbprefix}entities (type, subtype, owner_guid, access_id, time_created, time_updated) values ('$type',$subtype, $owner_guid, $access_id, $time, $time)"); + if ($result = insert_data("INSERT into {$CONFIG->dbprefix}entities (type, subtype, owner_guid, access_id, time_created, time_updated) values ('$type',$subtype, $owner_guid, $access_id, $time, $time)")) { + $entity = get_entity($result); + trigger_event('create',$entity->type,$entity); + } + return $result; } /** @@ -681,10 +688,16 @@ // TODO Make sure this deletes all metadata/annotations/relationships/etc!! $guid = (int)$guid; - $entity = get_entity($guid); - - if ($entity->canEdit()) - return delete_data("DELETE from {$CONFIG->dbprefix}entities where where guid=$guid"); + if ($entity = get_entity($guid)) { + if (trigger_event('delete',$entity->type,$entity)) { + if ($entity->canEdit()) { + $entity->clearMetadata(); + $entity->clearAnnotations(); + return delete_data("DELETE from {$CONFIG->dbprefix}entities where where guid={$guid}"); + } + } + } + return false; } -- cgit v1.2.3