diff options
-rw-r--r-- | engine/classes/ElggEntity.php | 8 | ||||
-rw-r--r-- | engine/classes/ElggGroup.php | 27 | ||||
-rw-r--r-- | engine/classes/ElggObject.php | 27 | ||||
-rw-r--r-- | engine/classes/ElggSite.php | 23 | ||||
-rw-r--r-- | engine/classes/ElggUser.php | 25 |
5 files changed, 65 insertions, 45 deletions
diff --git a/engine/classes/ElggEntity.php b/engine/classes/ElggEntity.php index 2fa8e9939..dc38dafbe 100644 --- a/engine/classes/ElggEntity.php +++ b/engine/classes/ElggEntity.php @@ -1311,12 +1311,16 @@ abstract class ElggEntity extends ElggData implements /** * Loads attributes from the entities table into the object. * - * @param int $guid GUID of Entity + * @param mixed $guid GUID of entity or stdClass object from entities table * * @return bool */ protected function load($guid) { - $row = get_entity_as_row($guid); + if ($guid instanceof stdClass) { + $row = $guid; + } else { + $row = get_entity_as_row($guid); + } if ($row) { // Create the array if necessary - all subclasses should test before creating 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())); diff --git a/engine/classes/ElggObject.php b/engine/classes/ElggObject.php index 649e32490..b4bae6825 100644 --- a/engine/classes/ElggObject.php +++ b/engine/classes/ElggObject.php @@ -41,12 +41,12 @@ class ElggObject extends ElggEntity { * * If no arguments are passed, create a new entity. * - * If an argument is passed attempt to load a full Object entity. Arguments - * can be: + * If an argument is passed, attempt to load a full ElggObject entity. + * Arguments can be: * - The GUID of an object entity. - * - A DB result object with a guid property + * - A DB result object from the entities table with a guid property * - * @param mixed $guid If an int, load that GUID. If a db row then will attempt to + * @param mixed $guid If an int, load that GUID. If a db row, then will attempt to * load the rest of the data. * * @throws IOException If passed an incorrect guid @@ -59,15 +59,15 @@ class ElggObject extends ElggEntity { $this->initialise_attributes(false); if (!empty($guid)) { - // Is $guid is a DB row - either a entity row, or a object table row. + // Is $guid is a DB row from the entity table 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 ElggObject? Use a copy constructor + // Is $guid is an ElggObject? Use a copy constructor } else if ($guid instanceof ElggObject) { elgg_deprecated_notice('This type of usage of the ElggObject constructor was deprecated. Please use the clone method.', 1.7); @@ -75,11 +75,11 @@ class ElggObject extends ElggEntity { $this->attributes[$key] = $value; } - // Is this is an ElggEntity but not an ElggObject = ERROR! + // Is this is an ElggEntity but not an ElggObject = ERROR! } else if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggObject')); - // 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))); @@ -93,17 +93,22 @@ class ElggObject extends ElggEntity { /** * Loads the full ElggObject when given a guid. * - * @param int $guid Guid of an ElggObject + * @param mixed $guid GUID of an ElggObject or the stdClass object from entities table * * @return bool * @throws InvalidClassException */ protected function load($guid) { - // Test to see if we have the generic stuff + // Load data from entity table if needed if (!parent::load($guid)) { return false; } + // 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())); diff --git a/engine/classes/ElggSite.php b/engine/classes/ElggSite.php index b13683a56..49616f1be 100644 --- a/engine/classes/ElggSite.php +++ b/engine/classes/ElggSite.php @@ -57,8 +57,8 @@ class ElggSite extends ElggEntity { * - A URL as stored in ElggSite->url * - A DB result object with a guid property * - * @param mixed $guid If an int, load that GUID. If a db row then will attempt - * to load the rest of the data. + * @param mixed $guid If an int, load that GUID. If a db row then will + * load the rest of the data. * * @throws IOException If passed an incorrect guid * @throws InvalidParameterException If passed an Elgg* Entity that isn't an ElggSite @@ -70,15 +70,15 @@ class ElggSite extends ElggEntity { $this->initialise_attributes(false); if (!empty($guid)) { - // Is $guid is a DB row - either a entity row, or a site table row. + // Is $guid is a DB entity table 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 ElggSite? Use a copy constructor + // Is $guid is an ElggSite? Use a copy constructor } else if ($guid instanceof ElggSite) { elgg_deprecated_notice('This type of usage of the ElggSite constructor was deprecated. Please use the clone method.', 1.7); @@ -86,18 +86,18 @@ class ElggSite extends ElggEntity { $this->attributes[$key] = $value; } - // Is this is an ElggEntity but not an ElggSite = ERROR! + // Is this is an ElggEntity but not an ElggSite = ERROR! } else if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggSite')); - // See if this is a URL + // See if this is a URL } else if (strpos($guid, "http") !== false) { $guid = get_site_by_url($guid); foreach ($guid->attributes as $key => $value) { $this->attributes[$key] = $value; } - // 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))); @@ -111,7 +111,7 @@ class ElggSite extends ElggEntity { /** * Loads the full ElggSite when given a guid. * - * @param int $guid Guid of ElggSite entity + * @param mixed $guid GUID of ElggSite entity or database row object * * @return bool * @throws InvalidClassException @@ -122,6 +122,11 @@ class ElggSite extends ElggEntity { return false; } + // Only work with GUID from here + if ($guid instanceof stdClass) { + $guid = $guid->guid; + } + // Check the type if ($this->attributes['type'] != 'site') { $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($guid, get_class())); diff --git a/engine/classes/ElggUser.php b/engine/classes/ElggUser.php index e9cbc6cb2..d7bb89265 100644 --- a/engine/classes/ElggUser.php +++ b/engine/classes/ElggUser.php @@ -47,7 +47,7 @@ class ElggUser extends ElggEntity * Construct a new user entity, optionally from a given id 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. */ @@ -58,15 +58,15 @@ class ElggUser 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 DB entity 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); } - // See if this is a username + // See if this is a username } else if (is_string($guid)) { $user = get_user_by_username($guid); if ($user) { @@ -75,7 +75,7 @@ class ElggUser extends ElggEntity } } - // Is $guid is an ElggUser? Use a copy constructor + // Is $guid is an ElggUser? Use a copy constructor } else if ($guid instanceof ElggUser) { elgg_deprecated_notice('This type of usage of the ElggUser constructor was deprecated. Please use the clone method.', 1.7); @@ -83,11 +83,11 @@ class ElggUser extends ElggEntity $this->attributes[$key] = $value; } - // Is this is an ElggEntity but not an ElggUser = ERROR! + // Is this is an ElggEntity but not an ElggUser = ERROR! } else if ($guid instanceof ElggEntity) { throw new InvalidParameterException(elgg_echo('InvalidParameterException:NonElggUser')); - // 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))); @@ -99,11 +99,9 @@ class ElggUser extends ElggEntity } /** - * Override the load function. - * This function will ensure that all data is loaded (were possible), so - * if only part of the ElggUser is loaded, it'll load the rest. + * Load the ElggUser data from the database * - * @param int $guid ElggUser GUID + * @param mixed $guid ElggUser GUID or stdClass database row from entity table * * @return bool */ @@ -113,6 +111,11 @@ class ElggUser extends ElggEntity return false; } + // Only work with GUID from here + if ($guid instanceof stdClass) { + $guid = $guid->guid; + } + // Check the type if ($this->attributes['type'] != 'user') { $msg = elgg_echo('InvalidClassException:NotValidElggStar', array($guid, get_class())); |