Skip to content
Closed
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions lib/Service/Attachment/AttachmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public function addFile(string $userId, UploadedFile $file): LocalAttachment {
$attachment->setMimeType($file->getMimeType());

$persisted = $this->mapper->insert($attachment);
if ($persisted->id === null) {
throw new UploadException('Given attachmentId is null');
}

try {
$this->storage->save($userId, $persisted->id, $file);
} catch (UploadException $ex) {
Expand All @@ -100,6 +104,10 @@ public function addFileFromString(string $userId, string $name, string $mime, st
$attachment->setMimeType($mime);

$persisted = $this->mapper->insert($attachment);
if ($persisted->id === null) {
throw new UploadException('Given attachmentId is null');
}

try {
$this->storage->saveContent($userId, $persisted->id, $fileContents);
} catch (NotFoundException|NotPermittedException $e) {
Expand Down
8 changes: 4 additions & 4 deletions lib/Service/Attachment/AttachmentStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ private function getAttachmentFolder($userId): ISimpleFolder {
* Copy uploaded file content to a app data file
*
* @param string $userId
* @param int $attachmentId
* @param int|string $attachmentId
* @param UploadedFile $uploadedFile
*
* @throws UploadException
*
* @return void
*/
public function save(string $userId, int $attachmentId, UploadedFile $uploadedFile): void {
public function save(string $userId, int|string $attachmentId, UploadedFile $uploadedFile): void {
$folder = $this->getAttachmentFolder($userId);

$file = $folder->newFile((string)$attachmentId);
Expand All @@ -80,12 +80,12 @@ public function save(string $userId, int $attachmentId, UploadedFile $uploadedFi
* Copy uploaded file content to a app data file
*
* @param string $userId
* @param int $attachmentId
* @param int|string $attachmentId
*
* @return void
* @throws NotFoundException|NotPermittedException
*/
public function saveContent(string $userId, int $attachmentId, string $fileContent): void {
public function saveContent(string $userId, int|string $attachmentId, string $fileContent): void {
$folder = $this->getAttachmentFolder($userId);
$file = $folder->newFile((string)$attachmentId);
$file->putContent($fileContent);
Expand Down
Loading