diff options
Diffstat (limited to 'engine/classes/ElggEntity.php')
| -rw-r--r-- | engine/classes/ElggEntity.php | 37 | 
1 files changed, 22 insertions, 15 deletions
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index f44e73023..a563f6fad 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -24,7 +24,7 @@   *   * @package    Elgg.Core   * @subpackage DataModel.Entities - *  + *   * @property string $type           object, user, group, or site (read-only after save)   * @property string $subtype        Further clarifies the nature of the entity (read-only after save)   * @property int    $guid           The unique identifier for this entity (read only) @@ -352,8 +352,8 @@ abstract class ElggEntity extends ElggData implements  					'limit' => 0  				);  				// @todo in 1.9 make this return false if can't add metadata -				// http://trac.elgg.org/ticket/4520 -				//  +				// https://github.com/elgg/elgg/issues/4520 +				//  				// need to remove access restrictions right now to delete  				// because this is the expected behavior  				$ia = elgg_set_ignore_access(true); @@ -375,12 +375,11 @@ abstract class ElggEntity extends ElggData implements  			}  			return $result; -		} - -		// unsaved entity. store in temp array -		// returning single entries instead of an array of 1 element is decided in -		// getMetaData(), just like pulling from the db. -		else { +		} else { +			// unsaved entity. store in temp array +			// returning single entries instead of an array of 1 element is decided in +			// getMetaData(), just like pulling from the db. +			//  			// if overwrite, delete first  			if (!$multiple || !isset($this->temp_metadata[$name])) {  				$this->temp_metadata[$name] = array(); @@ -965,7 +964,7 @@ abstract class ElggEntity extends ElggData implements  	 *  	 * @tip Can be overridden by registering for the permissions_check:comment,  	 * <entity type> plugin hook. -	 *  +	 *  	 * @param int $user_guid User guid (default is logged in user)  	 *  	 * @return bool @@ -1271,15 +1270,23 @@ abstract class ElggEntity extends ElggData implements  	public function save() {  		$guid = $this->getGUID();  		if ($guid > 0) { -			cache_entity($this); -			return update_entity( +			// See #5600. This ensures the lower level can_edit_entity() check will use a +			// fresh entity from the DB so it sees the persisted owner_guid +			_elgg_disable_caching_for_entity($guid); + +			$ret = update_entity(  				$guid,  				$this->get('owner_guid'),  				$this->get('access_id'),  				$this->get('container_guid'),  				$this->get('time_created')  			); + +			_elgg_enable_caching_for_entity($guid); +			_elgg_cache_entity($this); + +			return $ret;  		} else {  			// Create a new entity (nb: using attribute array directly  			// 'cos set function does something special!) @@ -1321,7 +1328,7 @@ abstract class ElggEntity extends ElggData implements  			$this->attributes['subtype'] = get_subtype_id($this->attributes['type'],  				$this->attributes['subtype']); -			cache_entity($this); +			_elgg_cache_entity($this);  			return $this->attributes['guid'];  		} @@ -1358,12 +1365,12 @@ abstract class ElggEntity extends ElggData implements  				$this->attributes['tables_loaded']++;  			} -			// guid needs to be an int  http://trac.elgg.org/ticket/4111 +			// guid needs to be an int  https://github.com/elgg/elgg/issues/4111  			$this->attributes['guid'] = (int)$this->attributes['guid'];  			// Cache object handle  			if ($this->attributes['guid']) { -				cache_entity($this); +				_elgg_cache_entity($this);  			}  			return true;  | 
