aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/entities.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-05-20 20:22:30 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-05-20 20:22:30 +0000
commite9c576c2827cc582bdfa4200677cdc9f9aa4eb4d (patch)
tree5ffa993236861c920858529808a9e2af080a07e6 /engine/lib/entities.php
parent9cfc9f6fc88346440b6889b20962ac0c5640c937 (diff)
downloadelgg-e9c576c2827cc582bdfa4200677cdc9f9aa4eb4d.tar.gz
elgg-e9c576c2827cc582bdfa4200677cdc9f9aa4eb4d.tar.bz2
create_entity() now adds a default last_action set to the same as time_created. This solves a problem of having to specify an order by of last_action desc, time_created desc on each call.
Standardized update_entity_last_action() and moved it from river.php to entities.php. git-svn-id: http://code.elgg.org/elgg/trunk@6117 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/entities.php')
-rw-r--r--engine/lib/entities.php37
1 files changed, 32 insertions, 5 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 8e20ec269..a18e1c612 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -106,6 +106,7 @@ abstract class ElggEntity implements
$this->attributes['access_id'] = ACCESS_PRIVATE;
$this->attributes['time_created'] = "";
$this->attributes['time_updated'] = "";
+ $this->attributes['last_action'] = '';
$this->attributes['enabled'] = "yes";
// There now follows a bit of a hack
@@ -132,7 +133,7 @@ abstract class ElggEntity implements
* method copies metadata but does not copy over annotations, or private settings.
*
* Note: metadata will have its owner and access id set when the entity is saved
- * and it will be the same as that off the entity.
+ * and it will be the same as that of the entity.
*/
public function __clone() {
@@ -335,8 +336,6 @@ abstract class ElggEntity implements
if ((int) $this->guid > 0) {
return create_metadata($this->getGUID(), $name, $value, $value_type, $this->getOwner(), $this->getAccessID(), $multiple);
} else {
- //$this->temp_metadata[$name] = $value;
-
if (($multiple) && (isset($this->temp_metadata[$name]))) {
if (!is_array($this->temp_metadata[$name])) {
$tmp = $this->temp_metadata[$name];
@@ -1630,8 +1629,8 @@ function create_entity($type, $subtype, $owner_guid, $access_id, $site_guid = 0,
}
return insert_data("INSERT into {$CONFIG->dbprefix}entities
- (type, subtype, owner_guid, site_guid, container_guid, access_id, time_created, time_updated) values
- ('$type',$subtype, $owner_guid, $site_guid, $container_guid, $access_id, $time, $time)");
+ (type, subtype, owner_guid, site_guid, container_guid, access_id, time_created, time_updated, last_action) values
+ ('$type',$subtype, $owner_guid, $site_guid, $container_guid, $access_id, $time, $time, $time)");
}
/**
@@ -3689,6 +3688,34 @@ function elgg_instanceof($entity, $type = NULL, $subtype = NULL) {
return $return;
}
+
+/**
+ * Update last_action on the given entity.
+ *
+ * @param int $guid Entity annotation|relationship action carried out on
+ * @param int $posted Timestamp of last action
+ **/
+function update_entity_last_action($guid, $posted = NULL){
+ global $CONFIG;
+ $guid = (int)$guid;
+
+ if (!$posted) {
+ $posted = time();
+ }
+
+ if ($guid){
+ //now add to the river updated table
+ $query = update_data("UPDATE {$CONFIG->dbprefix}entities SET last_action = {$posted} WHERE guid = {$guid}");
+ if ($query) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ } else {
+ return FALSE;
+ }
+}
+
/**
* Garbage collect stub and fragments from any broken delete/create calls
*