From fa775641525ab834481f3b3fb5dd6a7ed75593dc Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Mon, 31 Jul 2023 12:10:50 -0700 Subject: [PATCH] enh: rename to due date Signed-off-by: Christopher Ng --- .../lib/BackgroundJob/CleanUpReminders.php | 1 + .../BackgroundJob/ScheduledNotifications.php | 2 +- .../lib/Command/ListCommand.php | 4 +-- .../lib/Controller/ApiController.php | 12 ++++---- apps/files_reminders/lib/Db/Reminder.php | 8 +++--- .../files_reminders/lib/Db/ReminderMapper.php | 28 +++++++++---------- .../Version10000Date20230725162149.php | 4 +-- .../lib/Model/RichReminder.php | 2 +- .../lib/Service/ReminderService.php | 8 +++--- 9 files changed, 35 insertions(+), 34 deletions(-) diff --git a/apps/files_reminders/lib/BackgroundJob/CleanUpReminders.php b/apps/files_reminders/lib/BackgroundJob/CleanUpReminders.php index 43d0afe3e10f7..581b4c8935128 100644 --- a/apps/files_reminders/lib/BackgroundJob/CleanUpReminders.php +++ b/apps/files_reminders/lib/BackgroundJob/CleanUpReminders.php @@ -37,6 +37,7 @@ public function __construct( private ReminderService $reminderService, ) { parent::__construct($time); + $this->setInterval(60 * 60 * 24); $this->setTimeSensitivity(IJob::TIME_INSENSITIVE); } diff --git a/apps/files_reminders/lib/BackgroundJob/ScheduledNotifications.php b/apps/files_reminders/lib/BackgroundJob/ScheduledNotifications.php index 9efb6acb53b37..df801cea06369 100644 --- a/apps/files_reminders/lib/BackgroundJob/ScheduledNotifications.php +++ b/apps/files_reminders/lib/BackgroundJob/ScheduledNotifications.php @@ -48,7 +48,7 @@ public function __construct( * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function run($argument) { - $reminders = $this->reminderMapper->findToRemind(); + $reminders = $this->reminderMapper->findOverdue(); foreach ($reminders as $reminder) { try { $this->reminderService->send($reminder); diff --git a/apps/files_reminders/lib/Command/ListCommand.php b/apps/files_reminders/lib/Command/ListCommand.php index 074aeb8723901..7d6044f21c690 100644 --- a/apps/files_reminders/lib/Command/ListCommand.php +++ b/apps/files_reminders/lib/Command/ListCommand.php @@ -75,12 +75,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $io->table( - ['UserId', 'Path', 'RemindAt', 'CreatedAt', 'Notified'], + ['UserId', 'Path', 'DueDate', 'CreatedAt', 'Notified'], array_map( fn (RichReminder $reminder) => [ $reminder->getUserId(), $reminder->getNode()->getPath(), - $reminder->getRemindAt()->format(DateTimeInterface::ATOM), // ISO 8601 + $reminder->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601 $reminder->getCreatedAt()->format(DateTimeInterface::ATOM), // ISO 8601 $reminder->getNotified() ? 'true' : 'false', ], diff --git a/apps/files_reminders/lib/Controller/ApiController.php b/apps/files_reminders/lib/Controller/ApiController.php index b372a871e3bc1..10a6654d6715a 100644 --- a/apps/files_reminders/lib/Controller/ApiController.php +++ b/apps/files_reminders/lib/Controller/ApiController.php @@ -63,13 +63,13 @@ public function get(int $fileId): JSONResponse { try { $reminder = $this->reminderService->getDueForUser($user, $fileId); $reminderData = [ - 'remindAt' => $reminder->getRemindAt()->format(DateTimeInterface::ATOM), // ISO 8601 + 'dueDate' => $reminder->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601 ]; return new JSONResponse($reminderData, Http::STATUS_OK); } catch (DoesNotExistException $e) { // Return null when no reminder is found $reminderData = [ - 'remindAt' => null, + 'dueDate' => null, ]; return new JSONResponse($reminderData, Http::STATUS_OK); } catch (Throwable $th) { @@ -81,11 +81,11 @@ public function get(int $fileId): JSONResponse { /** * Create a reminder * - * @param string $remindAt ISO 8601 formatted date time string + * @param string $dueDate ISO 8601 formatted date time string */ - public function create(int $fileId, string $remindAt): JSONResponse { + public function create(int $fileId, string $dueDate): JSONResponse { try { - $remindAt = (new DateTime($remindAt))->setTimezone(new DateTimeZone('UTC')); + $dueDate = (new DateTime($dueDate))->setTimezone(new DateTimeZone('UTC')); } catch (Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); return new JSONResponse([], Http::STATUS_BAD_REQUEST); @@ -97,7 +97,7 @@ public function create(int $fileId, string $remindAt): JSONResponse { } try { - $this->reminderService->create($user, $fileId, $remindAt); + $this->reminderService->create($user, $fileId, $dueDate); return new JSONResponse([], Http::STATUS_OK); } catch (Throwable $th) { $this->logger->error($th->getMessage(), ['exception' => $th]); diff --git a/apps/files_reminders/lib/Db/Reminder.php b/apps/files_reminders/lib/Db/Reminder.php index 1abaa48d2008b..3a3641644f7d2 100644 --- a/apps/files_reminders/lib/Db/Reminder.php +++ b/apps/files_reminders/lib/Db/Reminder.php @@ -36,8 +36,8 @@ * @method void setFileId(int $fileId) * @method int getFileId() * - * @method void setRemindAt(DateTime $remindAt) - * @method DateTime getRemindAt() + * @method void setDueDate(DateTime $dueDate) + * @method DateTime getDueDate() * * @method void setCreatedAt(DateTime $createdAt) * @method DateTime getCreatedAt() @@ -48,14 +48,14 @@ class Reminder extends Entity { protected $userId; protected $fileId; - protected $remindAt; + protected $dueDate; protected $createdAt; protected $notified = false; public function __construct() { $this->addType('userId', 'string'); $this->addType('fileId', 'integer'); - $this->addType('remindAt', 'datetime'); + $this->addType('dueDate', 'datetime'); $this->addType('createdAt', 'datetime'); $this->addType('notified', 'boolean'); } diff --git a/apps/files_reminders/lib/Db/ReminderMapper.php b/apps/files_reminders/lib/Db/ReminderMapper.php index 7368ef2acc7d5..422082702622a 100644 --- a/apps/files_reminders/lib/Db/ReminderMapper.php +++ b/apps/files_reminders/lib/Db/ReminderMapper.php @@ -50,13 +50,13 @@ public function markNotified(Reminder $reminder): Reminder { $reminderUpdate = new Reminder(); $reminderUpdate->setId($reminder->getId()); $reminderUpdate->setNotified(true); - return parent::update($reminderUpdate); + return $this->update($reminderUpdate); } public function find(int $id): Reminder { $qb = $this->db->getQueryBuilder(); - $qb->select('user_id', 'file_id', 'remind_at', 'created_at', 'notified') + $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified') ->from($this->getTableName()) ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))); @@ -69,7 +69,7 @@ public function find(int $id): Reminder { public function findDueForUser(IUser $user, int $fileId): Reminder { $qb = $this->db->getQueryBuilder(); - $qb->select('user_id', 'file_id', 'remind_at', 'created_at', 'notified') + $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified') ->from($this->getTableName()) ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID(), IQueryBuilder::PARAM_STR))) ->andWhere($qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))) @@ -86,9 +86,9 @@ public function findDueForUser(IUser $user, int $fileId): Reminder { public function findAll() { $qb = $this->db->getQueryBuilder(); - $qb->select('user_id', 'file_id', 'remind_at', 'created_at', 'notified') + $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified') ->from($this->getTableName()) - ->orderBy('remind_at', 'ASC'); + ->orderBy('due_date', 'ASC'); return $this->findEntities($qb); } @@ -99,10 +99,10 @@ public function findAll() { public function findAllForUser(IUser $user) { $qb = $this->db->getQueryBuilder(); - $qb->select('user_id', 'file_id', 'remind_at', 'created_at', 'notified') + $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified') ->from($this->getTableName()) ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID(), IQueryBuilder::PARAM_STR))) - ->orderBy('remind_at', 'ASC'); + ->orderBy('due_date', 'ASC'); return $this->findEntities($qb); } @@ -110,14 +110,14 @@ public function findAllForUser(IUser $user) { /** * @return Reminder[] */ - public function findToRemind() { + public function findOverdue() { $qb = $this->db->getQueryBuilder(); - $qb->select('user_id', 'file_id', 'remind_at', 'created_at', 'notified') + $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified') ->from($this->getTableName()) - ->where($qb->expr()->lt('remind_at', $qb->createFunction('NOW()'))) + ->where($qb->expr()->lt('due_date', $qb->createFunction('NOW()'))) ->andWhere($qb->expr()->eq('notified', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL))) - ->orderBy('remind_at', 'ASC'); + ->orderBy('due_date', 'ASC'); return $this->findEntities($qb); } @@ -125,13 +125,13 @@ public function findToRemind() { /** * @return Reminder[] */ - public function findToDelete(?int $limit = null) { + public function findNotified(?int $limit = null) { $qb = $this->db->getQueryBuilder(); - $qb->select('user_id', 'file_id', 'remind_at', 'created_at', 'notified') + $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified') ->from($this->getTableName()) ->where($qb->expr()->eq('notified', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL))) - ->orderBy('remind_at', 'ASC') + ->orderBy('due_date', 'ASC') ->setMaxResults($limit); return $this->findEntities($qb); diff --git a/apps/files_reminders/lib/Migration/Version10000Date20230725162149.php b/apps/files_reminders/lib/Migration/Version10000Date20230725162149.php index 1940d153763eb..20b9331fc66dd 100644 --- a/apps/files_reminders/lib/Migration/Version10000Date20230725162149.php +++ b/apps/files_reminders/lib/Migration/Version10000Date20230725162149.php @@ -57,7 +57,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt 'length' => 20, 'unsigned' => true, ]); - $table->addColumn('remind_at', Types::DATETIME, [ + $table->addColumn('due_date', Types::DATETIME, [ 'notnull' => true, ]); $table->addColumn('created_at', Types::DATETIME, [ @@ -68,7 +68,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt 'default' => false, ]); $table->setPrimaryKey(['id']); - $table->addUniqueIndex(['user_id', 'file_id', 'remind_at'], 'reminders_uniq_idx'); + $table->addUniqueIndex(['user_id', 'file_id', 'due_date'], 'reminders_uniq_idx'); return $schema; } diff --git a/apps/files_reminders/lib/Model/RichReminder.php b/apps/files_reminders/lib/Model/RichReminder.php index 76c3d8dd22bc1..9f7e3f3655614 100644 --- a/apps/files_reminders/lib/Model/RichReminder.php +++ b/apps/files_reminders/lib/Model/RichReminder.php @@ -66,7 +66,7 @@ public function jsonSerialize(): array { return [ 'userId' => $this->getUserId(), 'fileId' => $this->getFileId(), - 'remindAt' => $this->getRemindAt()->format(DateTimeInterface::ATOM), // ISO 8601 + 'dueDate' => $this->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601 'createdAt' => $this->getCreatedAt()->format(DateTimeInterface::ATOM), // ISO 8601 'notified' => $this->getNotified(), ]; diff --git a/apps/files_reminders/lib/Service/ReminderService.php b/apps/files_reminders/lib/Service/ReminderService.php index 7106c8e5514f2..b24a685e3bcbb 100644 --- a/apps/files_reminders/lib/Service/ReminderService.php +++ b/apps/files_reminders/lib/Service/ReminderService.php @@ -78,11 +78,11 @@ public function getAll(?IUser $user = null) { ); } - public function create(IUser $user, int $fileId, DateTime $remindAt): void { + public function create(IUser $user, int $fileId, DateTime $dueDate): void { $reminder = new Reminder(); $reminder->setUserId($user->getUID()); $reminder->setFileId($fileId); - $reminder->setRemindAt($remindAt); + $reminder->setDueDate($dueDate); $reminder->setCreatedAt(new DateTime('now', new DateTimeZone('UTC'))); $this->reminderMapper->insert($reminder); } @@ -108,7 +108,7 @@ public function send(Reminder $reminder): void { ->setUser($user->getUID()) ->setObject('reminder', (string)$reminder->getId()) ->setSubject('reminder-due') - ->setDateTime($reminder->getRemindAt()); + ->setDateTime($reminder->getDueDate()); try { $this->notificationManager->notify($notification); @@ -119,7 +119,7 @@ public function send(Reminder $reminder): void { } public function cleanUp(?int $limit = null): void { - $reminders = $this->reminderMapper->findToDelete($limit); + $reminders = $this->reminderMapper->findNotified($limit); foreach ($reminders as $reminder) { $this->reminderMapper->delete($reminder); }