diff options
author | Christopher Ng <chrng8@gmail.com> | 2023-07-31 12:10:50 -0700 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2023-08-08 16:29:12 -0700 |
commit | 332fd3d93bb6d7d0d3b543ea3baf5a5a388a6dc5 (patch) | |
tree | b8a0ab428d2004e894861b1bdcd057184bba0f17 /apps/files_reminders/lib | |
parent | ab357bfe209473ec5faee3e2cece55f64e2578ae (diff) | |
download | nextcloud-server-332fd3d93bb6d7d0d3b543ea3baf5a5a388a6dc5.tar.gz nextcloud-server-332fd3d93bb6d7d0d3b543ea3baf5a5a388a6dc5.zip |
fix: create only if file exists
Signed-off-by: Christopher Ng <chrng8@gmail.com>
(cherry picked from commit d31302e72c8c6ec4281453e245b2e4a367b1c603)
Diffstat (limited to 'apps/files_reminders/lib')
-rw-r--r-- | apps/files_reminders/lib/Controller/ApiController.php | 3 | ||||
-rw-r--r-- | apps/files_reminders/lib/Service/ReminderService.php | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/apps/files_reminders/lib/Controller/ApiController.php b/apps/files_reminders/lib/Controller/ApiController.php index ddc34b16c6b..30465f6a69b 100644 --- a/apps/files_reminders/lib/Controller/ApiController.php +++ b/apps/files_reminders/lib/Controller/ApiController.php @@ -30,6 +30,7 @@ use DateTime; use DateTimeInterface; use DateTimeZone; use Exception; +use OCA\FilesReminders\Exception\NodeNotFoundException; use OCA\FilesReminders\Service\ReminderService; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; @@ -95,6 +96,8 @@ class ApiController extends OCSController { try { $this->reminderService->createOrUpdate($user, $fileId, $dueDate); return new JSONResponse([], Http::STATUS_OK); + } catch (NodeNotFoundException $e) { + return new JSONResponse([], Http::STATUS_NOT_FOUND); } catch (Throwable $th) { $this->logger->error($th->getMessage(), ['exception' => $th]); return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR); diff --git a/apps/files_reminders/lib/Service/ReminderService.php b/apps/files_reminders/lib/Service/ReminderService.php index bf4cd5da14d..fe746dc75ca 100644 --- a/apps/files_reminders/lib/Service/ReminderService.php +++ b/apps/files_reminders/lib/Service/ReminderService.php @@ -31,6 +31,7 @@ use DateTimeZone; use OCA\FilesReminders\AppInfo\Application; use OCA\FilesReminders\Db\Reminder; use OCA\FilesReminders\Db\ReminderMapper; +use OCA\FilesReminders\Exception\NodeNotFoundException; use OCA\FilesReminders\Exception\UserNotFoundException; use OCA\FilesReminders\Model\RichReminder; use OCP\AppFramework\Db\DoesNotExistException; @@ -78,6 +79,9 @@ class ReminderService { ); } + /** + * @throws NodeNotFoundException + */ public function createOrUpdate(IUser $user, int $fileId, DateTime $dueDate): void { $now = new DateTime('now', new DateTimeZone('UTC')); try { @@ -86,6 +90,10 @@ class ReminderService { $reminder->setUpdatedAt($now); $this->reminderMapper->update($reminder); } catch (DoesNotExistException $e) { + $nodes = $this->root->getUserFolder($user->getUID())->getById($fileId); + if (empty($nodes)) { + throw new NodeNotFoundException(); + } // Create new reminder if no reminder is found $reminder = new Reminder(); $reminder->setUserId($user->getUID()); |