From 33c786c1b7838d38e9797b8731d4e45c9ceb1aac Mon Sep 17 00:00:00 2001
From: Steve Clay <steve@mrclay.org>
Date: Mon, 26 Nov 2012 01:17:39 -0500
Subject: Fixes #4929: Optimize elgg_get_entities and add attribute loader

---
 engine/classes/ElggObject.php | 37 +++++++++----------------------------
 1 file changed, 9 insertions(+), 28 deletions(-)

(limited to 'engine/classes/ElggObject.php')

diff --git a/engine/classes/ElggObject.php b/engine/classes/ElggObject.php
index fa6296c8c..84f6e09c8 100644
--- a/engine/classes/ElggObject.php
+++ b/engine/classes/ElggObject.php
@@ -99,37 +99,18 @@ class ElggObject extends ElggEntity {
 	 * @throws InvalidClassException
 	 */
 	protected function load($guid) {
-		// Load data from entity table if needed
-		if (!parent::load($guid)) {
-			return false;
-		}
+		$attr_loader = new ElggAttributeLoader(get_class(), 'object', $this->attributes);
+		$attr_loader->requires_access_control = !($this instanceof ElggPlugin);
+		$attr_loader->secondary_loader = 'get_object_entity_as_row';
 
-		// Only work with GUID from here
-		if ($guid instanceof stdClass) {
-			$guid = $guid->guid;
-		}
-
-		// Check the type
-		if ($this->attributes['type'] != 'object') {
-			$msg = elgg_echo('InvalidClassException:NotValidElggStar', array($guid, get_class()));
-			throw new InvalidClassException($msg);
-		}
-
-		// Load missing data
-		$row = get_object_entity_as_row($guid);
-		if (($row) && (!$this->isFullyLoaded())) {
-			// If $row isn't a cached copy then increment the counter
-			$this->attributes['tables_loaded']++;
-		}
-
-		// Now put these into the attributes array as core values
-		$objarray = (array) $row;
-		foreach ($objarray as $key => $value) {
-			$this->attributes[$key] = $value;
+		$attrs = $attr_loader->getRequiredAttributes($guid);
+		if (!$attrs) {
+			return false;
 		}
 
-		// guid needs to be an int  http://trac.elgg.org/ticket/4111
-		$this->attributes['guid'] = (int)$this->attributes['guid'];
+		$this->attributes = $attrs;
+		$this->attributes['tables_loaded'] = 2;
+		cache_entity($this);
 
 		return true;
 	}
-- 
cgit v1.2.3


From 2d8bef1f96c811dbed0f7636b5acc128d36ee53b Mon Sep 17 00:00:00 2001
From: Cash Costello <cash.costello@gmail.com>
Date: Sat, 22 Dec 2012 13:56:54 -0500
Subject: Fixes #4856 removed incorrect argument to create_object_entity()

---
 engine/classes/ElggObject.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'engine/classes/ElggObject.php')

diff --git a/engine/classes/ElggObject.php b/engine/classes/ElggObject.php
index 84f6e09c8..6263f84f6 100644
--- a/engine/classes/ElggObject.php
+++ b/engine/classes/ElggObject.php
@@ -130,7 +130,7 @@ class ElggObject extends ElggEntity {
 
 		// Save ElggObject-specific attributes
 		return create_object_entity($this->get('guid'), $this->get('title'),
-			$this->get('description'), $this->get('container_guid'));
+			$this->get('description'));
 	}
 
 	/**
-- 
cgit v1.2.3