#4274 closed Documentation (wontfix)
get_entities filtering only by container, not owner
| Reported by: | Facyla | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Needs Review |
| Component: | Core | Version: | 1.6 |
| Severity: | minor | Keywords: | owner, container, get_entities |
| Cc: | brett@… | Difficulty: |
Description
"get_entities" uses always container_guid filter instead of owner_guid, whatever is defined in parameters, causing some queries to be incomplete or even empty.
Use case 1 : use get_entities to get all blog posts made by the same author (owner)
result : only personal posts will appear, not posts into groups
1st cause : get_entities uses only a filter by container_guid, not owner_guid
2nd cause : is null, container_guid is replaced by owner_guid value
=> This makes it impossible to get all posts by a specific user
Use case 2 : get entities based on owner AND container
=> not possible for the same reasons
My suggested patch : add a specific value for container_guid parameter, so that we may override that behaviour only when needed (and don't break the whole system, 'cause this is quite sensitive function..)
This patch lets get all objects from a user with this example query :
get_entities('object', '', $ownguid, "", $limit, 0, true, -1, "bypass");
Patch based on cf. http://reference.elgg.org/1.6/entities_8php_source.html#l01509
=> find following lines 1573 à 1575 :
if (is_null($container_guid)) {
$container_guid = $owner_array;
}
=> insert following piece of php right after lines 1573 à 1575 :
// Facyla : bypass pour ne pas imposer de filtre sur le container quand on veut celui sur l'owner..
if ($container_guid == 'bypass') {
$container_guid = null;
// Facyla : ajout du bloc de filtrage par owner_guid
if (!is_null($owner_guid)) {
if (is_array($owner_guid)) {
foreach($owner_guid as $key => $val) $owner_guid[$key] = (int) $val;
$where[] = "owner_guid in (" . implode(",",$owner_guid) . ")";
} else {
$owner_guid = (int) $owner_guid;
$where[] = "owner_guid = {$owner_guid}";
}
}
}
=> this doesn't break anything, but allows developpers to bypass default behaviour when they need it.
I didn't check in 1.7, but this is no longer an issue in 1.8 versions.
The same issue should occur as well in 1.5 versions.
Change History (2)
comment:1 Changed 17 months ago by cash
- Resolution set to wontfix
- Status changed from new to closed
comment:2 Changed 17 months ago by Facyla
- Type changed from Defect to Documentation
Ok, thanks for explanations. N matter it's not "fixed", as it's not a real bug anyway ; i hope it might help if someone encounters the same problem. We have many sites that are based on 1.6.4, for which this patch was helpful. It doesn't break other plugins' behaviour, the way it's implemented.
Of course i've seen 1.8 !-) i really appreciate the latests version, especially for developpers (much cleaner code + coding rules + theming + .. etc.)
I just made a jump from 1.6 to 1.8 without using 1.7 - I'm actually using 1.8(.2) on a production site :)
(changed type to documentation => closed + for information only)

This was fixed in Elgg 1.7 with the new elgg_get_entities() function. The reason that we did not change get_entities() is that it would break current plugins. At this point, we are only doing security fixes for Elgg 1.6 and Elgg 1.5 no longer supported. Please upgrade to Elgg 1.7 to take advantage of the new elgg_get_entities() plus the hundreds of other bug fixes and enhancements. Elgg 1.7's UI is the same as Elgg 1.6 so the upgrade should not be difficult. I'm sure that you have seen that Elgg 1.8 has significant changes in its UI.