<NME> CleanSessionsHelper.php
<BEF> ADDFILE
<MSG> Refactor entity delete cron jobs

Signed-off-by: Marius David Wieschollek <6eb06da055e8245a5973a30d1d8e851daaf547dc@mdns.eu>

<DFF> @@ -0,0 +1,52 @@
+<?php
+/**
+ * This file is part of the Passwords App
+ * created by Marius David Wieschollek
+ * and licensed under the AGPL.
+ */
+
+namespace OCA\Passwords\Helper\CleanUp;
+
+use OCA\Passwords\Db\SessionMapper;
+use OCA\Passwords\Services\LoggingService;
+
+/**
+ * Class CleanSessionsHelper
+ *
+ * @package OCA\Passwords\Helper\CleanUp
+ */
+class CleanSessionsHelper {
+
+    /**
+     * @var LoggingService
+     */
+    protected $logger;
+
+    /**
+     * @var SessionMapper
+     */
+    protected $sessionMapper;
+
+    /**
+     * CleanSessionsHelper constructor.
+     *
+     * @param LoggingService $logger
+     * @param SessionMapper  $sessionMapper
+     */
+    public function __construct(LoggingService $logger, SessionMapper $sessionMapper) {
+        $this->sessionMapper = $sessionMapper;
+        $this->logger        = $logger;
+    }
+
+    /**
+     *
+     */
+    public function run(): void {
+        $sessions = $this->sessionMapper->findAllOlderThan(time() - 3600);
+
+        foreach($sessions as $session) $this->sessionMapper->delete($session);
+
+        $total = count($sessions);
+        $this->logger->debugOrInfo(['Closed and deleted %s sessions permanently', $total], $total);
+    }
+}
\ No newline at end of file

{'addition_count': 52, 'commit_subject': 'Refactor entity delete cron jobs', 'deletion_count': 0, 'file_extension': '.php', 'lang': 'php', 'license': 'agpl-3.0', 'repo_name': 'marius-wieschollek/passwords'}