]> source.dussan.org Git - nextcloud-server.git/commitdiff
enh: rename to due date
authorChristopher Ng <chrng8@gmail.com>
Mon, 31 Jul 2023 19:10:50 +0000 (12:10 -0700)
committerChristopher Ng <chrng8@gmail.com>
Thu, 3 Aug 2023 22:30:11 +0000 (15:30 -0700)
Signed-off-by: Christopher Ng <chrng8@gmail.com>
apps/files_reminders/lib/BackgroundJob/CleanUpReminders.php
apps/files_reminders/lib/BackgroundJob/ScheduledNotifications.php
apps/files_reminders/lib/Command/ListCommand.php
apps/files_reminders/lib/Controller/ApiController.php
apps/files_reminders/lib/Db/Reminder.php
apps/files_reminders/lib/Db/ReminderMapper.php
apps/files_reminders/lib/Migration/Version10000Date20230725162149.php
apps/files_reminders/lib/Model/RichReminder.php
apps/files_reminders/lib/Service/ReminderService.php

index 43d0afe3e10f7b5febeb46fe96c038f766d90196..581b4c8935128030d6bf14b0e6eecd389875286c 100644 (file)
@@ -37,6 +37,7 @@ class CleanUpReminders extends TimedJob {
                private ReminderService $reminderService,
        ) {
                parent::__construct($time);
+
                $this->setInterval(60 * 60 * 24);
                $this->setTimeSensitivity(IJob::TIME_INSENSITIVE);
        }
index 9efb6acb53b37d2553f4eb8014851ebffbd8a83b..df801cea063692c5634d3ebeaf41256f9a0ee6e7 100644 (file)
@@ -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);
index 074aeb87239015b991c73e9329e5c01ec342643e..7d6044f21c690c6669e27150c8872a8bad186ac5 100644 (file)
@@ -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',
                                ],
index b372a871e3bc199f6cc0ce3919de417a8fa22b8d..10a6654d6715a0abdcf664177ff313a5a53216fb 100644 (file)
@@ -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]);
index 1abaa48d2008ba88489c402cd28915b5b4414624..3a3641644f7d2bed6d364581b86d49db9e839019 100644 (file)
@@ -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');
        }
index 7368ef2acc7d5a8791e2a3b8f897fb46b13f13f0..422082702622adc5a061404b483cef575dcfb47e 100644 (file)
@@ -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);
index 1940d153763eb350cb989535182f007271346896..20b9331fc66dd0f6972f509a8d0547159573aa17 100644 (file)
@@ -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;
        }
index 76c3d8dd22bc108de6322d264be2db0e752c7aab..9f7e3f3655614e227aa30a6dab94837629d29a70 100644 (file)
@@ -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(),
                ];
index 7106c8e5514f2d3325093248abb597c6ec7b2ed3..b24a685e3bcbbd6fc31d93c53d5b24da0cfa6320 100644 (file)
@@ -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);
                }