aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/entities.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib/entities.php')
-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;
}