summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-10-12 11:41:26 +0200
committerJoas Schilling <coding@schilljs.com>2022-10-12 11:43:00 +0200
commit9c5fef35c7be6ee81b520cefac0108954a709001 (patch)
treee58a5f2b2871ecde712616755a6439e6c5aaf93f /apps
parentc167fb5ccb83361323e497179491db72d1f77869 (diff)
downloadnextcloud-server-9c5fef35c7be6ee81b520cefac0108954a709001.tar.gz
nextcloud-server-9c5fef35c7be6ee81b520cefac0108954a709001.zip
Add a background job to delete expired tokens
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/files/appinfo/info.xml1
-rw-r--r--apps/files/composer/composer/autoload_classmap.php1
-rw-r--r--apps/files/composer/composer/autoload_static.php1
-rw-r--r--apps/files/lib/BackgroundJob/DeleteExpiredOpenLocalEditor.php61
-rw-r--r--apps/files/lib/Db/OpenLocalEditorMapper.php9
5 files changed, 73 insertions, 0 deletions
diff --git a/apps/files/appinfo/info.xml b/apps/files/appinfo/info.xml
index a29fcc2394b..1d06259074b 100644
--- a/apps/files/appinfo/info.xml
+++ b/apps/files/appinfo/info.xml
@@ -26,6 +26,7 @@
<job>OCA\Files\BackgroundJob\DeleteOrphanedItems</job>
<job>OCA\Files\BackgroundJob\CleanupFileLocks</job>
<job>OCA\Files\BackgroundJob\CleanupDirectEditingTokens</job>
+ <job>OCA\Files\BackgroundJob\DeleteExpiredOpenLocalEditor</job>
</background-jobs>
<commands>
diff --git a/apps/files/composer/composer/autoload_classmap.php b/apps/files/composer/composer/autoload_classmap.php
index 5a2ec4fee1f..2327cf44138 100644
--- a/apps/files/composer/composer/autoload_classmap.php
+++ b/apps/files/composer/composer/autoload_classmap.php
@@ -20,6 +20,7 @@ return array(
'OCA\\Files\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\Files\\BackgroundJob\\CleanupDirectEditingTokens' => $baseDir . '/../lib/BackgroundJob/CleanupDirectEditingTokens.php',
'OCA\\Files\\BackgroundJob\\CleanupFileLocks' => $baseDir . '/../lib/BackgroundJob/CleanupFileLocks.php',
+ 'OCA\\Files\\BackgroundJob\\DeleteExpiredOpenLocalEditor' => $baseDir . '/../lib/BackgroundJob/DeleteExpiredOpenLocalEditor.php',
'OCA\\Files\\BackgroundJob\\DeleteOrphanedItems' => $baseDir . '/../lib/BackgroundJob/DeleteOrphanedItems.php',
'OCA\\Files\\BackgroundJob\\ScanFiles' => $baseDir . '/../lib/BackgroundJob/ScanFiles.php',
'OCA\\Files\\BackgroundJob\\TransferOwnership' => $baseDir . '/../lib/BackgroundJob/TransferOwnership.php',
diff --git a/apps/files/composer/composer/autoload_static.php b/apps/files/composer/composer/autoload_static.php
index 676d2dbf3f9..fe23d4ed7b0 100644
--- a/apps/files/composer/composer/autoload_static.php
+++ b/apps/files/composer/composer/autoload_static.php
@@ -35,6 +35,7 @@ class ComposerStaticInitFiles
'OCA\\Files\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\Files\\BackgroundJob\\CleanupDirectEditingTokens' => __DIR__ . '/..' . '/../lib/BackgroundJob/CleanupDirectEditingTokens.php',
'OCA\\Files\\BackgroundJob\\CleanupFileLocks' => __DIR__ . '/..' . '/../lib/BackgroundJob/CleanupFileLocks.php',
+ 'OCA\\Files\\BackgroundJob\\DeleteExpiredOpenLocalEditor' => __DIR__ . '/..' . '/../lib/BackgroundJob/DeleteExpiredOpenLocalEditor.php',
'OCA\\Files\\BackgroundJob\\DeleteOrphanedItems' => __DIR__ . '/..' . '/../lib/BackgroundJob/DeleteOrphanedItems.php',
'OCA\\Files\\BackgroundJob\\ScanFiles' => __DIR__ . '/..' . '/../lib/BackgroundJob/ScanFiles.php',
'OCA\\Files\\BackgroundJob\\TransferOwnership' => __DIR__ . '/..' . '/../lib/BackgroundJob/TransferOwnership.php',
diff --git a/apps/files/lib/BackgroundJob/DeleteExpiredOpenLocalEditor.php b/apps/files/lib/BackgroundJob/DeleteExpiredOpenLocalEditor.php
new file mode 100644
index 00000000000..d96728fc713
--- /dev/null
+++ b/apps/files/lib/BackgroundJob/DeleteExpiredOpenLocalEditor.php
@@ -0,0 +1,61 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com>
+ *
+ * @author Joas Schilling <coding@schilljs.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files\BackgroundJob;
+
+use OCA\Files\Controller\OpenLocalEditorController;
+use OCA\Files\Db\OpenLocalEditorMapper;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\IJob;
+use OCP\BackgroundJob\TimedJob;
+
+/**
+ * Delete all expired "Open local editor" token
+ */
+class DeleteExpiredOpenLocalEditor extends TimedJob {
+ protected OpenLocalEditorMapper $mapper;
+
+ public function __construct(
+ ITimeFactory $time,
+ OpenLocalEditorMapper $mapper
+ ) {
+ parent::__construct($time);
+ $this->mapper = $mapper;
+
+ // Run every 12h
+ $this->interval = 12 * 3600;
+ $this->setTimeSensitivity(IJob::TIME_INSENSITIVE);
+ }
+
+ /**
+ * Makes the background job do its work
+ *
+ * @param array $argument unused argument
+ */
+ public function run($argument): void {
+ $this->mapper->deleteExpiredTokens($this->time->getTime());
+ }
+}
diff --git a/apps/files/lib/Db/OpenLocalEditorMapper.php b/apps/files/lib/Db/OpenLocalEditorMapper.php
index a0ed8b0fe96..71573264c74 100644
--- a/apps/files/lib/Db/OpenLocalEditorMapper.php
+++ b/apps/files/lib/Db/OpenLocalEditorMapper.php
@@ -53,4 +53,13 @@ class OpenLocalEditorMapper extends QBMapper {
return $this->findEntity($qb);
}
+
+ public function deleteExpiredTokens(int $time): void {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->delete($this->getTableName())
+ ->where($qb->expr()->lt('expiration_time', $qb->createNamedParameter($time)));
+
+ $qb->executeStatement();
+ }
}