diff --git a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php index 477943b97caf9..7f1acbdf51637 100644 --- a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php @@ -61,6 +61,7 @@ use OCP\Share\IShare; use OCP\Util; use Psr\Container\ContainerExceptionInterface; +use Psr\Log\LoggerInterface; class CloudFederationProviderFiles implements ICloudFederationProvider { @@ -842,8 +843,11 @@ private function getUserDisplayName(string $userId): string { try { $slaveService = Server::get(\OCA\GlobalSiteSelector\Service\SlaveService::class); - } catch (ContainerExceptionInterface $e) { - \OC::$server->getLogger()->logException($e); + } catch (\Throwable $e) { + Server::get(LoggerInterface::class)->error( + $e->getMessage(), + ['exception' => $e] + ); return ''; } diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 2daa31a6886bc..f381a6dd2652b 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -81,6 +81,8 @@ use OCP\Share\IManager; use OCP\Share\IShare; use OCP\UserStatus\IManager as IUserStatusManager; +use Psr\Container\ContainerExceptionInterface; +use Psr\Log\LoggerInterface; /** * Class Share20OCS @@ -345,11 +347,20 @@ protected function formatShare(IShare $share, Node $recipientNode = null): array */ private function getDisplayNameFromAddressBook(string $query, string $property): string { // FIXME: If we inject the contacts manager it gets initialized before any address books are registered - $result = \OC::$server->getContactsManager()->search($query, [$property], [ - 'limit' => 1, - 'enumeration' => false, - 'strict_search' => true, - ]); + try { + $result = \OC::$server->getContactsManager()->search($query, [$property], [ + 'limit' => 1, + 'enumeration' => false, + 'strict_search' => true, + ]); + } catch (Exception $e) { + Server::get(LoggerInterface::class)->error( + $e->getMessage(), + ['exception' => $e] + ); + return ''; + } + foreach ($result as $r) { foreach ($r[$property] as $value) { if ($value === $query && $r['FN']) { @@ -372,7 +383,9 @@ private function fixMissingDisplayName(array $shares, ?array $updatedDisplayName $userIds = $updated = []; foreach ($shares as $share) { // share is federated and share have no display name yet - if ($share['share_type'] === IShare::TYPE_REMOTE && $share['share_with_displayname'] === '') { + if ($share['share_type'] === IShare::TYPE_REMOTE + && ($share['share_with'] ?? '') !== '' + && ($share['share_with_displayname'] ?? '') === '') { $userIds[] = $userId = $share['share_with']; if ($updatedDisplayName !== null && array_key_exists($userId, $updatedDisplayName)) { @@ -410,8 +423,7 @@ private function fixMissingDisplayName(array $shares, ?array $updatedDisplayName * @param bool $cacheOnly - do not reach LUS, get data from cache. * * @return array - * @psalm-suppress DeprecatedMethod - * @psalm-suppress UndefinedClass + * @throws ContainerExceptionInterface */ private function retrieveFederatedDisplayName(array $userIds, bool $cacheOnly = false): array { // check if gss is enabled and available @@ -423,8 +435,11 @@ private function retrieveFederatedDisplayName(array $userIds, bool $cacheOnly = try { $slaveService = Server::get(\OCA\GlobalSiteSelector\Service\SlaveService::class); - } catch (Exception $e) { - \OC::$server->getLogger()->logException($e); + } catch (\Throwable $e) { + Server::get(LoggerInterface::class)->error( + $e->getMessage(), + ['exception' => $e] + ); return []; } diff --git a/psalm.xml b/psalm.xml index dac8635b5be4a..e76226ab4f2dc 100644 --- a/psalm.xml +++ b/psalm.xml @@ -83,6 +83,7 @@ + @@ -126,6 +127,7 @@ +