]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #3208 setting time_created on update
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 2 Apr 2011 02:29:48 +0000 (02:29 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 2 Apr 2011 02:29:48 +0000 (02:29 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@8904 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/classes/ElggEntity.php
engine/lib/entities.php
mod/blog/actions/blog/save.php

index 41f19a4c1cfdb0b40abc587c62653416d6dbbb9e..cfdaede7114a4721903bc478b656f60c0f41a871 100644 (file)
@@ -95,6 +95,7 @@ abstract class ElggEntity extends ElggData implements
 
                $this->attributes['site_guid'] = NULL;
                $this->attributes['access_id'] = ACCESS_PRIVATE;
+               $this->attributes['time_created'] = NULL;
                $this->attributes['time_updated'] = NULL;
                $this->attributes['last_action'] = NULL;
                $this->attributes['enabled'] = "yes";
@@ -222,7 +223,6 @@ abstract class ElggEntity extends ElggData implements
                        // Certain properties should not be manually changed!
                        switch ($name) {
                                case 'guid':
-                               case 'time_created':
                                case 'time_updated':
                                case 'last_action':
                                        return FALSE;
@@ -1244,7 +1244,8 @@ abstract class ElggEntity extends ElggData implements
                                $this->get('guid'),
                                $this->get('owner_guid'),
                                $this->get('access_id'),
-                               $this->get('container_guid')
+                               $this->get('container_guid'),
+                               $this->get('time_created')
                        );
                } else {
                        // Create a new entity (nb: using attribute array directly
index b862e177a84ed1b4209d440363e2b132dff3c0e5..a4da347eca6d14eecfd04b3834efefb14b08277c 100644 (file)
@@ -367,12 +367,13 @@ function update_subtype($type, $subtype, $class = '') {
  * @param int $owner_guid     The new owner guid
  * @param int $access_id      The new access id
  * @param int $container_guid The new container guid
+ * @param int $time_created   The time creation timestamp
  *
  * @return bool
  * @link http://docs.elgg.org/DataModel/Entities
  * @access private
  */
-function update_entity($guid, $owner_guid, $access_id, $container_guid = null) {
+function update_entity($guid, $owner_guid, $access_id, $container_guid = null, $time_created = null) {
        global $CONFIG, $ENTITY_CACHE;
 
        $guid = (int)$guid;
@@ -386,11 +387,18 @@ function update_entity($guid, $owner_guid, $access_id, $container_guid = null) {
 
        $entity = get_entity($guid);
 
+       if ($time_created == null) {
+               $time_created = $entity->time_created;
+       } else {
+               $time_created = (int) $time_created;
+       }
+
        if ($entity && $entity->canEdit()) {
                if (elgg_trigger_event('update', $entity->type, $entity)) {
-                       $ret = update_data("UPDATE {$CONFIG->dbprefix}entities"
-                               . " set owner_guid='$owner_guid', access_id='$access_id',"
-                               . " container_guid='$container_guid', time_updated='$time' WHERE guid=$guid");
+                       $ret = update_data("UPDATE {$CONFIG->dbprefix}entities
+                               set owner_guid='$owner_guid', access_id='$access_id',
+                               container_guid='$container_guid', time_created='$time_created',
+                               time_updated='$time' WHERE guid=$guid");
 
                        if ($entity instanceof ElggObject) {
                                update_river_access_by_object($guid, $access_id);
index 3f9e5e355d12ae40e35e1e96ce47851504541dc2..c42845037ac3257df7b59f53cbd00308d95676fd 100644 (file)
@@ -144,9 +144,8 @@ if (!$error) {
                        add_to_river('river/object/blog/create', 'create', elgg_get_logged_in_user_guid(), $blog->getGUID());
 
                        if ($guid) {
-                               $q = "UPDATE {$db_prefix}entities SET time_created = '$date'
-                                       WHERE guid = $guid";
-                               update_data($q);
+                               $blog->time_created = time();
+                               $blog->save();
                        }
                } elseif ($old_status == 'published' && $status == 'draft') {
                        $q = "DELETE FROM {$db_prefix}river