Skip to content

Commit

Permalink
fix: handle missing display name for single user reports
Browse files Browse the repository at this point in the history
- Load the display name if requested
- Let getUserDisplyName return null as expected by the formatter
- User oc_accounts_data instead of oc_accounts (to avoid the json parsing)

Based on #277

Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb authored and backportbot[bot] committed Jun 27, 2024
1 parent 0170f0e commit 605206b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/Reports/SingleUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public function printReport(InputInterface $input, OutputInterface $output, stri
$report['login'] = $this->getUserLastLogin($userId);
}
$report['shares'] = $this->getNumberOfSharesForUser($userId);
$report['display_name'] = $this->getUserDisplayName($userId);
if ($input->getOption('display-name')) {
$report['display_name'] = $this->getUserDisplayName($userId);
}

$this->printRecord($input, $output, $userId, $report);
}
Expand Down Expand Up @@ -205,19 +207,16 @@ protected function getNumberOfSharesForUser(string $userId): int {
return $numShares;
}

/**
* @param string $userId
* @return string
*/
protected function getUserDisplayName(string $userId): string {
protected function getUserDisplayName(string $userId): ?string {
$query = $this->queries['displayName'];
$query->setParameter('user', $userId);
$result = $query->executeQuery();
$data = $result->fetchOne();
$result->closeCursor();
$json = json_decode($data, true);
$displayName = $json['displayname']['value'];
return (string) $displayName;

if ($result->rowCount() === 0) {
return null;
}

return (string) $result->fetchOne();
}


Expand Down Expand Up @@ -303,9 +302,10 @@ protected function createQueries(): void {

// Get User Display Name
$query = $this->connection->getQueryBuilder();
$query->select('data')
->from('accounts')
->where($query->expr()->eq('uid', $query->createParameter('user')));
$query->select('value')
->from('accounts_data')
->where($query->expr()->eq('name', $query->createNamedParameter('displayname')))
->andWhere($query->expr()->eq('uid', $query->createParameter('user')));
$this->queries['displayName'] = $query;
}
}

0 comments on commit 605206b

Please sign in to comment.