aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-07 14:51:17 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-04-07 14:51:17 +0000
commit94a18aa796feef027cd33ec41ad4f955c7c991e3 (patch)
tree865f7b22dc2bd7e14562b699636c48a094380026 /engine/lib
parent389b0a5862a9f4130ca0765ba6155d81bd84499b (diff)
downloadelgg-94a18aa796feef027cd33ec41ad4f955c7c991e3.tar.gz
elgg-94a18aa796feef027cd33ec41ad4f955c7c991e3.tar.bz2
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
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/entities.php31
1 files changed, 22 insertions, 9 deletions
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;
}