QueryProvider: use left joins and fix the use of the "disabled" column.

The code used union selects; left joins at least are easier to read. In
some places it was also not so clear that the WHERE part for the
disabled column really worked.

The query FIND_GROUP_USERS also needs to take the disabled column in to
account.

Signed-off-by: Claus-Justus Heine <himself@claus-justus-heine.de>
This commit is contained in:
Claus-Justus Heine
2023-08-22 11:10:16 +02:00
parent df5a550fbd
commit 639b9cf995

View File

@@ -129,10 +129,13 @@ class QueryProvider implements \ArrayAccess
$this->queries = [
Query::BELONGS_TO_ADMIN =>
"SELECT COUNT(g.$gGID) > 0 AS admin " .
"FROM $group g, $userGroup ug " .
"FROM $group g " .
"LEFT JOIN $userGroup ug ON ug.$ugGID = g.$gGID " .
(empty($uDisabled) ? "" : "LEFT JOIN $user u ON u.$uUID = ug.$ugUID ") .
"WHERE ug.$ugGID = g.$gGID " .
"AND ug.$ugUID = :$uidParam " .
"AND g.$gAdmin",
"AND g.$gAdmin" .
(empty($uDisabled) ? "" : " AND NOT u.$uDisabled"),
Query::COUNT_GROUPS =>
"SELECT COUNT(DISTINCT ug.$ugUID) " .
@@ -154,8 +157,10 @@ class QueryProvider implements \ArrayAccess
Query::FIND_GROUP_USERS =>
"SELECT DISTINCT ug.$ugUID AS uid " .
"FROM $userGroup ug " .
"LEFT JOIN $user u ON u.$uUID = ug.$ugUID " .
"WHERE ug.$ugGID LIKE :$gidParam " .
"AND ug.$ugUID LIKE :$searchParam " .
(empty($uDisabled) ? "" : "AND NOT u.$uDisabled ") .
"ORDER BY ug.$ugUID",
Query::FIND_GROUPS =>
@@ -197,9 +202,9 @@ class QueryProvider implements \ArrayAccess
Query::FIND_USER_GROUPS =>
"SELECT $groupColumns " .
"FROM $group g, $userGroup ug " .
"WHERE ug.$ugGID = g.$gGID " .
"AND ug.$ugUID = :$uidParam " .
"FROM $group g " .
"LEFT JOIN $userGroup ug ON ug.$ugGID = g.$gGID " .
"WHERE ug.$ugUID = :$uidParam " .
"ORDER BY g.$gGID",
Query::FIND_USERS =>