summaryrefslogtreecommitdiffstats
path: root/lib/private/LanguageModel/Db/TaskMapper.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/LanguageModel/Db/TaskMapper.php')
-rw-r--r--lib/private/LanguageModel/Db/TaskMapper.php18
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/private/LanguageModel/Db/TaskMapper.php b/lib/private/LanguageModel/Db/TaskMapper.php
index d7122ea7941..e0b06a1b62b 100644
--- a/lib/private/LanguageModel/Db/TaskMapper.php
+++ b/lib/private/LanguageModel/Db/TaskMapper.php
@@ -3,6 +3,7 @@
namespace OC\LanguageModel\Db;
use OCP\AppFramework\Db\DoesNotExistException;
+use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
@@ -30,4 +31,21 @@ class TaskMapper extends QBMapper {
->where($qb->expr()->eq('id', $qb->createPositionalParameter($id)));
return $this->findEntity($qb);
}
+
+ /**
+ * @param int $timeout
+ * @return int the number of deleted tasks
+ * @throws Exception
+ */
+ public function deleteOlderThan(int $timeout): int {
+ $qb = $this->db->getQueryBuilder();
+ $qb->delete($this->tableName)
+ ->where($qb->expr()->lt('last_updated', $qb->createPositionalParameter(time() - $timeout)));
+ return $qb->executeStatement();
+ }
+
+ public function update(Entity $entity): Entity {
+ $entity->setLastUpdated(time());
+ return parent::update($entity);
+ }
}