From 187fcf6c98ae723d4fb296801cc91ce7092e62c0 Mon Sep 17 00:00:00 2001 From: cash Date: Sat, 4 Feb 2012 17:54:54 -0500 Subject: Fixes #2112 not loading data from entities table twice --- engine/classes/ElggGroup.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'engine/classes/ElggGroup.php') diff --git a/engine/classes/ElggGroup.php b/engine/classes/ElggGroup.php index ab223e1a4..f7f67bf41 100644 --- a/engine/classes/ElggGroup.php +++ b/engine/classes/ElggGroup.php @@ -29,12 +29,12 @@ class ElggGroup extends ElggEntity } /** - * Construct a new user entity, optionally from a given id value. + * Construct a new group entity, optionally from a given guid value. * * @param mixed $guid If an int, load that GUID. - * If a db row then will attempt to load the rest of the data. + * If an entity table db row, then will load the rest of the data. * - * @throws Exception if there was a problem creating the user. + * @throws Exception if there was a problem creating the group. */ function __construct($guid = null) { $this->initializeAttributes(); @@ -43,15 +43,15 @@ class ElggGroup extends ElggEntity $this->initialise_attributes(false); if (!empty($guid)) { - // Is $guid is a DB row - either a entity row, or a user table row. + // Is $guid is a entity table DB row if ($guid instanceof stdClass) { // Load the rest - if (!$this->load($guid->guid)) { + if (!$this->load($guid)) { $msg = elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid->guid)); throw new IOException($msg); } - // Is $guid is an ElggGroup? Use a copy constructor + // Is $guid is an ElggGroup? Use a copy constructor } else if ($guid instanceof ElggGroup) { elgg_deprecated_notice('This type of usage of the ElggGroup constructor was deprecated. Please use the clone method.', 1.7); @@ -59,11 +59,11 @@ class ElggGroup extends ElggEntity $this->attributes[$key] = $value; } - // Is this is an ElggEntity but not an ElggGroup = ERROR! + // Is this is an ElggEntity but not an ElggGroup = ERROR! } else if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggGroup')); - // We assume if we have got this far, $guid is an int + // Is it a GUID } else if (is_numeric($guid)) { if (!$this->load($guid)) { throw new IOException(elgg_echo('IOException:FailedToLoadGUID', array(get_class(), $guid))); @@ -319,11 +319,9 @@ class ElggGroup extends ElggEntity } /** - * Override the load function. - * This function will ensure that all data is loaded (were possible), so - * if only part of the ElggGroup is loaded, it'll load the rest. + * Load the ElggGroup data from the database * - * @param int $guid GUID of an ElggGroup entity + * @param mixed $guid GUID of an ElggGroup entity or database row from entity table * * @return bool */ @@ -333,6 +331,11 @@ class ElggGroup extends ElggEntity return false; } + // Only work with GUID from here + if ($guid instanceof stdClass) { + $guid = $guid->guid; + } + // Check the type if ($this->attributes['type'] != 'group') { $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($guid, get_class())); -- cgit v1.2.3