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 43d0afe3e10..581b4c89351 100644 --- a/apps/files_reminders/lib/BackgroundJob/CleanUpReminders.php +++ b/apps/files_reminders/lib/BackgroundJob/CleanUpReminders.php @@ -37,6 +37,7 @@ class CleanUpReminders extends TimedJob { 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 9efb6acb53b..df801cea063 100644 --- a/apps/files_reminders/lib/BackgroundJob/ScheduledNotifications.php +++ b/apps/files_reminders/lib/BackgroundJob/ScheduledNotifications.php @@ -48,7 +48,7 @@ class ScheduledNotifications extends Job { * @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 074aeb87239..7d6044f21c6 100644 --- a/apps/files_reminders/lib/Command/ListCommand.php +++ b/apps/files_reminders/lib/Command/ListCommand.php @@ -75,12 +75,12 @@ class ListCommand extends Base { } $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 b372a871e3b..10a6654d671 100644 --- a/apps/files_reminders/lib/Controller/ApiController.php +++ b/apps/files_reminders/lib/Controller/ApiController.php @@ -63,13 +63,13 @@ class ApiController extends OCSController { 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 @@ class ApiController extends OCSController { /** * 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 @@ class ApiController extends OCSController { } 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 1abaa48d200..3a3641644f7 100644 --- a/apps/files_reminders/lib/Db/Reminder.php +++ b/apps/files_reminders/lib/Db/Reminder.php @@ -36,8 +36,8 @@ use OCP\AppFramework\Db\Entity; * @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 @@ use OCP\AppFramework\Db\Entity; 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 7368ef2acc7..42208270262 100644 --- a/apps/files_reminders/lib/Db/ReminderMapper.php +++ b/apps/files_reminders/lib/Db/ReminderMapper.php @@ -50,13 +50,13 @@ class ReminderMapper extends QBMapper { $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 @@ class ReminderMapper extends QBMapper { 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 @@ class ReminderMapper extends QBMapper { 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 @@ class ReminderMapper extends QBMapper { 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 @@ class ReminderMapper extends QBMapper { /** * @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 @@ class ReminderMapper extends QBMapper { /** * @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 1940d153763..20b9331fc66 100644 --- a/apps/files_reminders/lib/Migration/Version10000Date20230725162149.php +++ b/apps/files_reminders/lib/Migration/Version10000Date20230725162149.php @@ -57,7 +57,7 @@ class Version10000Date20230725162149 extends SimpleMigrationStep { '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 @@ class Version10000Date20230725162149 extends SimpleMigrationStep { '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 76c3d8dd22b..9f7e3f36556 100644 --- a/apps/files_reminders/lib/Model/RichReminder.php +++ b/apps/files_reminders/lib/Model/RichReminder.php @@ -66,7 +66,7 @@ class RichReminder extends Reminder implements JsonSerializable { 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 7106c8e5514..b24a685e3bc 100644 --- a/apps/files_reminders/lib/Service/ReminderService.php +++ b/apps/files_reminders/lib/Service/ReminderService.php @@ -78,11 +78,11 @@ class ReminderService { ); } - 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 @@ class ReminderService { ->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 @@ class ReminderService { } 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); } -- 2.39.5