public function addSelectQuerySpecs(stdClass $row)
{
$dbprefix = elgg_get_config('dbprefix');
// Access SQL for this row might differ based on:
// - logged in user
// - show hidden entities status
// - ignored access
//
// To simplify querying, we will populate specs for all combinations of the above
// Given that tests log in and log out various users, and test
// entities against owner/container, we will populate queries for
// a set of users, and then validate their access to entity
// whenever a specific query is run
$access_user_guids = array_unique([0, (int) $row->guid, (int) $row->owner_guid, (int) $row->container_guid, (int) elgg_get_logged_in_user_guid()]);
$access_combinations = [];
foreach ($access_user_guids as $access_user_guid) {
$access_combinations[] = ['user_guid' => $access_user_guid, 'ignore_access' => false, 'use_enabled_clause' => true];
$access_combinations[] = ['user_guid' => $access_user_guid, 'ignore_access' => true, 'use_enabled_clause' => true];
$access_combinations[] = ['user_guid' => $access_user_guid, 'ignore_access' => false, 'use_enabled_clause' => false];
$access_combinations[] = ['user_guid' => $access_user_guid, 'ignore_access' => true, 'use_enabled_clause' => false];
}
$access_queries = [];
foreach ($access_combinations as $access_combination) {
$access_combination['table_alias'] = '';
$access_queries[] = _elgg_get_access_where_sql($access_combination);
}
$access_queries = array_unique($access_queries);
foreach ($access_queries as $access) {
$sql = "SELECT * FROM {$dbprefix}entities\n\t\t\tWHERE guid = :guid AND {$access}";
$this->query_specs[$row->guid][] = $this->db->addQuerySpec(['sql' => $sql, 'params' => [':guid' => (int) $row->guid], 'results' => function () use($row, $access_combination) {
if (!isset($this->rows[$row->guid])) {
return [];
}
$row = $this->rows[$row->guid];
if ($access_combination['use_enabled_clause'] && !$row->enabled != 'yes') {
// The SELECT query would contain ('enabled' = 'yes')
return [];
}
$has_access = $this->validateRowAccess($row);
return $has_access ? [$row] : [];
}]);
}
// Objects table
// @todo: this will need to be moved to the objects table mock once it's in
if ($row->type == 'object') {
$sql = "SELECT * FROM {$dbprefix}objects_entity\n\t\t\t\tWHERE guid = :guid";
$this->query_specs[$row->guid][] = $this->db->addQuerySpec(['sql' => $sql, 'params' => [':guid' => (int) $row->guid], 'results' => function () use($row) {
return [$row];
}]);
}
}