summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2023-08-03 17:42:00 -0700
committerAndy Scherzinger <info@andy-scherzinger.de>2023-08-10 12:28:19 +0200
commit6335282d2228f693b70c7e2a03cf46d7cacbade1 (patch)
treefc14c47cd84f8a4c7fa44f77ef343177cd64a7f5
parent68f4a134d79b89aa48e57291e47da118d58bb503 (diff)
downloadnextcloud-server-6335282d2228f693b70c7e2a03cf46d7cacbade1.tar.gz
nextcloud-server-6335282d2228f693b70c7e2a03cf46d7cacbade1.zip
enh: add clean up buffer
Signed-off-by: Christopher Ng <chrng8@gmail.com> (cherry picked from commit 18fb955a41ecd8e44849c25c9bc43e4aa9d2b8a4)
-rw-r--r--apps/files_reminders/lib/Db/ReminderMapper.php4
-rw-r--r--apps/files_reminders/lib/Service/ReminderService.php5
2 files changed, 7 insertions, 2 deletions
diff --git a/apps/files_reminders/lib/Db/ReminderMapper.php b/apps/files_reminders/lib/Db/ReminderMapper.php
index 97f7ed0900b..1a8f05a3db9 100644
--- a/apps/files_reminders/lib/Db/ReminderMapper.php
+++ b/apps/files_reminders/lib/Db/ReminderMapper.php
@@ -26,6 +26,7 @@ declare(strict_types=1);
namespace OCA\FilesReminders\Db;
+use DateTime;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -138,12 +139,13 @@ class ReminderMapper extends QBMapper {
/**
* @return Reminder[]
*/
- public function findNotified(?int $limit = null) {
+ public function findNotified(DateTime $buffer, ?int $limit = null) {
$qb = $this->db->getQueryBuilder();
$qb->select('id', '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)))
+ ->andWhere($qb->expr()->lt('due_date', $qb->createNamedParameter($buffer, IQueryBuilder::PARAM_DATE)))
->orderBy('due_date', 'ASC')
->setMaxResults($limit);
diff --git a/apps/files_reminders/lib/Service/ReminderService.php b/apps/files_reminders/lib/Service/ReminderService.php
index 5c7193259c1..010f458e872 100644
--- a/apps/files_reminders/lib/Service/ReminderService.php
+++ b/apps/files_reminders/lib/Service/ReminderService.php
@@ -167,7 +167,10 @@ class ReminderService {
}
public function cleanUp(?int $limit = null): void {
- $reminders = $this->reminderMapper->findNotified($limit);
+ $buffer = (new DateTime())
+ ->setTimezone(new DateTimeZone('UTC'))
+ ->modify('-1 day');
+ $reminders = $this->reminderMapper->findNotified($buffer, $limit);
foreach ($reminders as $reminder) {
$this->reminderMapper->delete($reminder);
}