diff options
Diffstat (limited to 'engine/classes/ElggEntity.php')
| -rw-r--r-- | engine/classes/ElggEntity.php | 48 | 
1 files changed, 30 insertions, 18 deletions
| diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 164ff3838..929abceb2 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -24,7 +24,6 @@   *   * @package    Elgg.Core   * @subpackage DataModel.Entities - * @link       http://docs.elgg.org/DataModel/ElggEntity   *    * @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) @@ -249,7 +248,9 @@ abstract class ElggEntity extends ElggData implements  	 * @return mixed The value, or NULL if not found.  	 */  	public function getMetaData($name) { -		if ((int) ($this->guid) == 0) { +		$guid = $this->getGUID(); + +		if (! $guid) {  			if (isset($this->temp_metadata[$name])) {  				// md is returned as an array only if more than 1 entry  				if (count($this->temp_metadata[$name]) == 1) { @@ -262,21 +263,38 @@ abstract class ElggEntity extends ElggData implements  			}  		} +		// upon first cache miss, just load/cache all the metadata and retry. +		// if this works, the rest of this function may not be needed! +		$cache = elgg_get_metadata_cache(); +		if ($cache->isKnown($guid, $name)) { +			return $cache->load($guid, $name); +		} else { +			$cache->populateFromEntities(array($guid)); +			// in case ignore_access was on, we have to check again... +			if ($cache->isKnown($guid, $name)) { +				return $cache->load($guid, $name); +			} +		} +  		$md = elgg_get_metadata(array( -			'guid' => $this->getGUID(), +			'guid' => $guid,  			'metadata_name' => $name,  			'limit' => 0,  		)); +		$value = null; +  		if ($md && !is_array($md)) { -			return $md->value; +			$value = $md->value;  		} elseif (count($md) == 1) { -			return $md[0]->value; +			$value = $md[0]->value;  		} else if ($md && is_array($md)) { -			return metadata_array_to_values($md); +			$value = metadata_array_to_values($md);  		} -		return null; +		$cache->save($guid, $name, $value); + +		return $value;  	}  	/** @@ -581,7 +599,6 @@ abstract class ElggEntity extends ElggData implements  	 * @param mixed  $value Value of private setting  	 *  	 * @return bool -	 * @link http://docs.elgg.org/DataModel/Entities/PrivateSettings  	 */  	function setPrivateSetting($name, $value) {  		if ((int) $this->guid > 0) { @@ -740,8 +757,6 @@ abstract class ElggEntity extends ElggData implements  	 * @param string $vartype   The type of annotation value  	 *  	 * @return bool -	 * -	 * @link http://docs.elgg.org/DataModel/Annotations  	 */  	function annotate($name, $value, $access_id = ACCESS_PRIVATE, $owner_id = 0, $vartype = "") {  		if ((int) $this->guid > 0) { @@ -1011,7 +1026,7 @@ abstract class ElggEntity extends ElggData implements  	/**  	 * Returns the guid.  	 * -	 * @return int GUID +	 * @return int|null GUID  	 */  	public function getGUID() {  		return $this->get('guid'); @@ -1249,16 +1264,16 @@ abstract class ElggEntity extends ElggData implements  	/**  	 * Save an entity.  	 * -	 * @return bool/int +	 * @return bool|int  	 * @throws IOException  	 */  	public function save() { -		$guid = (int) $this->guid; +		$guid = $this->getGUID();  		if ($guid > 0) {  			cache_entity($this);  			return update_entity( -				$this->get('guid'), +				$guid,  				$this->get('owner_guid'),  				$this->get('access_id'),  				$this->get('container_guid'), @@ -1305,10 +1320,7 @@ abstract class ElggEntity extends ElggData implements  			$this->attributes['subtype'] = get_subtype_id($this->attributes['type'],  				$this->attributes['subtype']); -			// Cache object handle -			if ($this->attributes['guid']) { -				cache_entity($this); -			} +			cache_entity($this);  			return $this->attributes['guid'];  		} | 
