Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions lib/private/Group/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public function createGroup(string $gid): bool {
}

// Add to cache
$this->groupCache[$gid] = $gid;
$this->groupCache[$gid] = [
'gid' => $gid,
'displayname' => $gid
];

return $result === 1;
}
Expand Down Expand Up @@ -244,15 +247,19 @@ public function getUserGroups($uid) {

// No magic!
$qb = $this->dbConn->getQueryBuilder();
$cursor = $qb->select('gid')
->from('group_user')
$cursor = $qb->select('gu.gid', 'g.displayname')
->from('group_user', 'gu')
->leftJoin('gu', 'groups', 'g', $qb->expr()->eq('gu.gid', 'g.gid'))
->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
->execute();

$groups = [];
while ($row = $cursor->fetch()) {
$groups[] = $row['gid'];
$this->groupCache[$row['gid']] = $row['gid'];
$this->groupCache[$row['gid']] = [
'gid' => $row['gid'],
'displayname' => $row['displayname'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it this always displayname? I had this issue in Mail recently and I went for selectAlias to ensure the database does not return the selected column, like g.displayname

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but there is only 1 displayname... so it should not prefix it right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so.

];
}
$cursor->closeCursor();

Expand Down Expand Up @@ -309,15 +316,18 @@ public function groupExists($gid) {
}

$qb = $this->dbConn->getQueryBuilder();
$cursor = $qb->select('gid')
$cursor = $qb->select('gid', 'displayname')
->from('groups')
->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)))
->execute();
$result = $cursor->fetch();
$cursor->closeCursor();

if ($result !== false) {
$this->groupCache[$gid] = $gid;
$this->groupCache[$gid] = [
'gid' => $gid,
'displayname' => $result['displayname'],
];
return true;
}
return false;
Expand Down Expand Up @@ -430,6 +440,10 @@ public function countDisabledInGroup(string $gid): int {
}

public function getDisplayName(string $gid): string {
if (isset($this->groupCache[$gid])) {
return $this->groupCache[$gid]['displayname'];
}

$this->fixDI();

$query = $this->dbConn->getQueryBuilder();
Expand Down