diff --git a/lib/Controller/AttachmentController.php b/lib/Controller/AttachmentController.php index 19ec885da8d..e752b5f1253 100644 --- a/lib/Controller/AttachmentController.php +++ b/lib/Controller/AttachmentController.php @@ -86,7 +86,7 @@ public function __construct( #[NoAdminRequired] #[PublicPage] #[RequireDocumentSessionOrUserOrShareToken] - public function getAttachmentList(?string $shareToken = null): DataResponse { + public function getAttachmentList(string $shareToken = ''): DataResponse { $documentId = $this->getDocument()->getId(); try { $session = $this->getSession(); @@ -98,7 +98,7 @@ public function getAttachmentList(?string $shareToken = null): DataResponse { $attachments = $this->attachmentService->getAttachmentList($documentId, null, $session, $shareToken); } else { $userId = $this->getUserId(); - $attachments = $this->attachmentService->getAttachmentList($documentId, $userId, $session, null); + $attachments = $this->attachmentService->getAttachmentList($documentId, $userId, $session); } return new DataResponse($attachments); @@ -126,7 +126,7 @@ public function insertAttachmentFile(string $filePath): DataResponse { #[NoAdminRequired] #[PublicPage] #[RequireDocumentSession] - public function uploadAttachment(?string $shareToken = null): DataResponse { + public function uploadAttachment(string $shareToken = ''): DataResponse { $documentId = $this->getSession()->getDocumentId(); try { @@ -193,7 +193,7 @@ private function getUploadedFile(string $key): array { #[PublicPage] #[NoCSRFRequired] #[RequireDocumentSessionOrUserOrShareToken] - public function getImageFile(string $imageFileName, ?string $shareToken = null, + public function getImageFile(string $imageFileName, string $shareToken = '', int $preferRawImage = 0): DataResponse|DataDownloadResponse { $documentId = $this->getDocument()->getId(); @@ -228,7 +228,7 @@ public function getImageFile(string $imageFileName, ?string $shareToken = null, #[PublicPage] #[NoCSRFRequired] #[RequireDocumentSessionOrUserOrShareToken] - public function getMediaFile(string $mediaFileName, ?string $shareToken = null): DataResponse|DataDownloadResponse { + public function getMediaFile(string $mediaFileName, string $shareToken = ''): DataResponse|DataDownloadResponse { $documentId = $this->getDocument()->getId(); try { @@ -259,7 +259,7 @@ public function getMediaFile(string $mediaFileName, ?string $shareToken = null): #[PublicPage] #[NoCSRFRequired] #[RequireDocumentSessionOrUserOrShareToken] - public function getMediaFilePreview(string $mediaFileName, ?string $shareToken = null) { + public function getMediaFilePreview(string $mediaFileName, string $shareToken = '') { $documentId = $this->getDocument()->getId(); try { diff --git a/lib/Controller/SessionController.php b/lib/Controller/SessionController.php index 9de585d394b..72f5ab1da79 100644 --- a/lib/Controller/SessionController.php +++ b/lib/Controller/SessionController.php @@ -58,7 +58,7 @@ public function __construct( #[NoAdminRequired] public function create(int $fileId = null, string $file = null): DataResponse { - return $this->apiService->create($fileId, $file, null, null); + return $this->apiService->create($fileId, $file); } #[NoAdminRequired] diff --git a/lib/Controller/UserApiController.php b/lib/Controller/UserApiController.php index 435e32f21ac..41f40bb9619 100644 --- a/lib/Controller/UserApiController.php +++ b/lib/Controller/UserApiController.php @@ -39,11 +39,12 @@ public function index(string $filter = '', int $limit = 5): DataResponse { // Add joined users to the autocomplete list foreach ($sessions as $session) { $sessionUserId = $session['userId']; - if ($sessionUserId !== null && !isset($users[$sessionUserId])) { - $displayName = $this->userManager->getDisplayName($sessionUserId); - if ($displayName && stripos($displayName, $filter) !== false || stripos($sessionUserId, $filter) !== false) { - $users[$sessionUserId] = $displayName; - } + if ($sessionUserId === null || isset($users[$sessionUserId])) { + continue; + } + $displayName = $this->userManager->getDisplayName($sessionUserId) ?: ''; + if (stripos($displayName, $filter) !== false || stripos($sessionUserId, $filter) !== false) { + $users[$sessionUserId] = $displayName; } } diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index 288171640e0..a28cf77f08a 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -70,7 +70,7 @@ public function __construct(IRequest $request, $this->l10n = $l10n; } - public function create(?int $fileId = null, ?string $filePath = null, ?string $token = null, ?string $guestName = null): DataResponse { + public function create(?int $fileId = null, ?string $filePath = null, string $token = '', ?string $guestName = null): DataResponse { try { if ($token) { $file = $this->documentService->getFileByShareToken($token, $this->request->getParam('filePath')); @@ -86,7 +86,7 @@ public function create(?int $fileId = null, ?string $filePath = null, ?string $t } catch (NotPermittedException $e) { return new DataResponse($this->l10n->t('This file cannot be displayed as download is disabled by the share'), 404); } - } elseif ($fileId) { + } elseif ($fileId !== null) { try { $file = $this->documentService->getFileById($fileId); } catch (NotFoundException|NotPermittedException $e) { diff --git a/lib/Service/AttachmentService.php b/lib/Service/AttachmentService.php index 968bbf03e81..35f8cbc04a7 100644 --- a/lib/Service/AttachmentService.php +++ b/lib/Service/AttachmentService.php @@ -214,7 +214,7 @@ private function getMediaFilePreviewFile(string $mediaFileName, File $textFile): * @throws NotFoundException * @throws NotPermittedException */ - public function getAttachmentList(int $documentId, ?string $userId = null, ?Session $session = null, ?string $shareToken = null): array { + public function getAttachmentList(int $documentId, string $userId = '', ?Session $session = null, string $shareToken = ''): array { if ($shareToken) { $textFile = $this->getTextFilePublic($documentId, $shareToken); } elseif ($userId) { diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index fa3c34e5b8d..f411fc47a8d 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -130,7 +130,7 @@ public function createDocument(File $file): Document { // Do not hard reset if changed from outside since this will throw away possible steps // This way the user can still resolve conflicts in the editor view $stepsVersion = $this->stepMapper->getLatestVersion($document->getId()); - if ($stepsVersion && ($document->getLastSavedVersion() !== $stepsVersion)) { + if ($stepsVersion !== null && ($document->getLastSavedVersion() !== $stepsVersion)) { $this->logger->debug('Unsaved steps, continue collaborative editing'); return $document; } @@ -335,7 +335,7 @@ public function autosave(Document $document, ?File $file, int $version, ?string // Do not save if newer version already saved // Note that $version is the version of the steps the client has fetched. // It may have added steps on top of that - so if the versions match we still save. - $stepsVersion = $this->stepMapper->getLatestVersion($documentId)?: 0; + $stepsVersion = $this->stepMapper->getLatestVersion($documentId) ?? 0; $savedVersion = $document->getLastSavedVersion(); $outdated = $savedVersion > 0 && $savedVersion > $version; if (!$force && ($outdated || $version > (string)$stepsVersion)) { diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php index e24204e201d..b2ad9390426 100644 --- a/lib/Service/SessionService.php +++ b/lib/Service/SessionService.php @@ -236,8 +236,8 @@ public function updateSessionAwareness(Session $session, string $message): Sessi return $this->sessionMapper->update($session); } - private function getColorForGuestName(string $guestName = null): string { - $guestName = $this->userId ?? $guestName; + private function getColorForGuestName(string $guestName = ''): string { + $guestName = $this->userId ? $guestName : ''; $uniqueGuestId = !empty($guestName) ? $guestName : $this->secureRandom->generate(12); $color = $this->avatarManager->getGuestAvatar($uniqueGuestId)->avatarBackgroundColor($uniqueGuestId); return $color->name();