private ReminderService $reminderService,
) {
parent::__construct($time);
+
$this->setInterval(60 * 60 * 24);
$this->setTimeSensitivity(IJob::TIME_INSENSITIVE);
}
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function run($argument) {
- $reminders = $this->reminderMapper->findToRemind();
+ $reminders = $this->reminderMapper->findOverdue();
foreach ($reminders as $reminder) {
try {
$this->reminderService->send($reminder);
}
$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',
],
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) {
/**
* 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);
}
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]);
* @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()
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');
}
$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)));
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)))
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);
}
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);
}
/**
* @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);
}
/**
* @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);
'length' => 20,
'unsigned' => true,
]);
- $table->addColumn('remind_at', Types::DATETIME, [
+ $table->addColumn('due_date', Types::DATETIME, [
'notnull' => true,
]);
$table->addColumn('created_at', Types::DATETIME, [
'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;
}
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(),
];
);
}
- 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);
}
->setUser($user->getUID())
->setObject('reminder', (string)$reminder->getId())
->setSubject('reminder-due')
- ->setDateTime($reminder->getRemindAt());
+ ->setDateTime($reminder->getDueDate());
try {
$this->notificationManager->notify($notification);
}
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);
}