]> source.dussan.org Git - nextcloud-server.git/commitdiff
enh: add updated at
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/Command/ListCommand.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

index 7d6044f21c690c6669e27150c8872a8bad186ac5..b066c6ed8cfa620b3ed92e1317cc2c7f36c804f4 100644 (file)
@@ -75,12 +75,13 @@ class ListCommand extends Base {
                }
 
                $io->table(
-                       ['UserId', 'Path', 'DueDate', 'CreatedAt', 'Notified'],
+                       ['User Id', 'Path', 'Due Date', 'Updated At', 'Created At', 'Notified'],
                        array_map(
                                fn (RichReminder $reminder) => [
                                        $reminder->getUserId(),
                                        $reminder->getNode()->getPath(),
                                        $reminder->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601
+                                       $reminder->getUpdatedAt()->format(DateTimeInterface::ATOM), // ISO 8601
                                        $reminder->getCreatedAt()->format(DateTimeInterface::ATOM), // ISO 8601
                                        $reminder->getNotified() ? 'true' : 'false',
                                ],
index 3a3641644f7d2bed6d364581b86d49db9e839019..36f967f1434b8dea96444238fc1f3bab7e16fe8c 100644 (file)
@@ -39,6 +39,9 @@ use OCP\AppFramework\Db\Entity;
  * @method void setDueDate(DateTime $dueDate)
  * @method DateTime getDueDate()
  *
+ * @method void setUpdatedAt(DateTime $updatedAt)
+ * @method DateTime getUpdatedAt()
+ *
  * @method void setCreatedAt(DateTime $createdAt)
  * @method DateTime getCreatedAt()
  *
@@ -49,6 +52,7 @@ class Reminder extends Entity {
        protected $userId;
        protected $fileId;
        protected $dueDate;
+       protected $updatedAt;
        protected $createdAt;
        protected $notified = false;
 
@@ -56,6 +60,7 @@ class Reminder extends Entity {
                $this->addType('userId', 'string');
                $this->addType('fileId', 'integer');
                $this->addType('dueDate', 'datetime');
+               $this->addType('updatedAt', 'datetime');
                $this->addType('createdAt', 'datetime');
                $this->addType('notified', 'boolean');
        }
index 422082702622adc5a061404b483cef575dcfb47e..4ddea3b303cded226ec1ce0ed56b3cd34661bcd7 100644 (file)
@@ -56,7 +56,7 @@ class ReminderMapper extends QBMapper {
        public function find(int $id): Reminder {
                $qb = $this->db->getQueryBuilder();
 
-               $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified')
+               $qb->select('user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified')
                        ->from($this->getTableName())
                        ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
 
@@ -69,12 +69,12 @@ class ReminderMapper extends QBMapper {
        public function findDueForUser(IUser $user, int $fileId): Reminder {
                $qb = $this->db->getQueryBuilder();
 
-               $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified')
+               $qb->select('user_id', 'file_id', 'due_date', 'updated_at', '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)))
                        ->andWhere($qb->expr()->eq('notified', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)))
-                       ->orderBy('created_at', 'DESC')
+                       ->orderBy('updated_at', 'DESC')
                        ->setMaxResults(1);
 
                return $this->findEntity($qb);
@@ -86,7 +86,7 @@ class ReminderMapper extends QBMapper {
        public function findAll() {
                $qb = $this->db->getQueryBuilder();
 
-               $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified')
+               $qb->select('user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified')
                        ->from($this->getTableName())
                        ->orderBy('due_date', 'ASC');
 
@@ -99,7 +99,7 @@ class ReminderMapper extends QBMapper {
        public function findAllForUser(IUser $user) {
                $qb = $this->db->getQueryBuilder();
 
-               $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified')
+               $qb->select('user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified')
                        ->from($this->getTableName())
                        ->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID(), IQueryBuilder::PARAM_STR)))
                        ->orderBy('due_date', 'ASC');
@@ -113,7 +113,7 @@ class ReminderMapper extends QBMapper {
        public function findOverdue() {
                $qb = $this->db->getQueryBuilder();
 
-               $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified')
+               $qb->select('user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified')
                        ->from($this->getTableName())
                        ->where($qb->expr()->lt('due_date', $qb->createFunction('NOW()')))
                        ->andWhere($qb->expr()->eq('notified', $qb->createNamedParameter(false, IQueryBuilder::PARAM_BOOL)))
@@ -128,7 +128,7 @@ class ReminderMapper extends QBMapper {
        public function findNotified(?int $limit = null) {
                $qb = $this->db->getQueryBuilder();
 
-               $qb->select('user_id', 'file_id', 'due_date', 'created_at', 'notified')
+               $qb->select('user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified')
                        ->from($this->getTableName())
                        ->where($qb->expr()->eq('notified', $qb->createNamedParameter(true, IQueryBuilder::PARAM_BOOL)))
                        ->orderBy('due_date', 'ASC')
index 20b9331fc66dd0f6972f509a8d0547159573aa17..0b7505d64e3e78568dcf9870de5ac8f3a40565a0 100644 (file)
@@ -60,6 +60,9 @@ class Version10000Date20230725162149 extends SimpleMigrationStep {
                $table->addColumn('due_date', Types::DATETIME, [
                        'notnull' => true,
                ]);
+               $table->addColumn('updated_at', Types::DATETIME, [
+                       'notnull' => true,
+               ]);
                $table->addColumn('created_at', Types::DATETIME, [
                        'notnull' => true,
                ]);
index 9f7e3f3655614e227aa30a6dab94837629d29a70..1ac1baae370dbea162a8a578fac902254c84c7e9 100644 (file)
@@ -67,6 +67,7 @@ class RichReminder extends Reminder implements JsonSerializable {
                        'userId' => $this->getUserId(),
                        'fileId' => $this->getFileId(),
                        'dueDate' => $this->getDueDate()->format(DateTimeInterface::ATOM), // ISO 8601
+                       'updatedAt' => $this->getUpdatedAt()->format(DateTimeInterface::ATOM), // ISO 8601
                        'createdAt' => $this->getCreatedAt()->format(DateTimeInterface::ATOM), // ISO 8601
                        'notified' => $this->getNotified(),
                ];