Skip to content

Commit

Permalink
Merge pull request #284 from nextcloud/backport/282/stable28
Browse files Browse the repository at this point in the history
[stable28] fix: handle missing display name for single user reports
  • Loading branch information
kesselb authored Jun 27, 2024
2 parents 5eefdb8 + cc70f8d commit 93efeeb
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 93efeeb

Please sign in to comment.