-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathCleanup.php
More file actions
68 lines (55 loc) · 2.2 KB
/
Cleanup.php
File metadata and controls
68 lines (55 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Text\Cron;
use OCA\Text\Exception\DocumentHasUnsavedChangesException;
use OCA\Text\Service\AttachmentService;
use OCA\Text\Service\DocumentService;
use OCA\Text\Service\SessionService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;
use Psr\Log\LoggerInterface;
class Cleanup extends TimedJob {
public function __construct(
ITimeFactory $time,
private readonly SessionService $sessionService,
private readonly DocumentService $documentService,
private readonly AttachmentService $attachmentService,
private readonly LoggerInterface $logger,
) {
parent::__construct($time);
$this->setInterval(SessionService::SESSION_VALID_TIME);
}
/**
* @param array $argument
*/
protected function run($argument): void {
$this->logger->debug('Run cleanup job for text documents');
foreach ($this->documentService->getAll() as $document) {
if ($this->sessionService->countAllSessions($document->getId()) > 0) {
// Do not reset if there are any sessions left
// Inactive sessions will get removed further down and will trigger a reset next time
continue;
}
try {
$this->documentService->resetDocument($document->getId());
} catch (DocumentHasUnsavedChangesException) {
}
$this->attachmentService->cleanupAttachments($document->getId());
}
$this->logger->debug('Run cleanup job for text sessions');
$removedSessions = $this->sessionService->removeInactiveSessionsWithoutSteps();
$this->logger->debug('Removed ' . $removedSessions . ' inactive sessions');
$this->logger->debug('Run cleanup job for old sessions');
$removedOldSessions = $this->sessionService->removeOldSessions();
$this->logger->debug('Removed ' . $removedOldSessions . ' old sessions');
$this->logger->debug('Run cleanup job for orphaned steps');
$removedSteps = $this->sessionService->removeOrphanedSteps();
$this->logger->debug('Removed ' . $removedSteps . ' orphaned steps');
$this->logger->debug('Run cleanup job for obsolete documents folders');
$this->documentService->cleanupOldDocumentsFolders();
}
}