|
1
|
|
|
<?php |
|
2
|
|
|
namespace EWW\Dpf\Services\Document; |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the TYPO3 CMS project. |
|
6
|
|
|
* |
|
7
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
8
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
9
|
|
|
* of the License, or any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* For the full copyright and license information, please read the |
|
12
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
13
|
|
|
* |
|
14
|
|
|
* The TYPO3 project - inspiring people to share! |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
class DocumentCleaner |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* clientRepository |
|
22
|
|
|
* |
|
23
|
|
|
* @var \EWW\Dpf\Domain\Repository\DocumentRepository |
|
24
|
|
|
* @inject |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $documentRepository = null; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* persistence manager |
|
30
|
|
|
* |
|
31
|
|
|
* @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface |
|
32
|
|
|
* @inject |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $persistenceManager; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* security |
|
38
|
|
|
* |
|
39
|
|
|
* @var \EWW\Dpf\Security\Security |
|
40
|
|
|
* @inject |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $security = null; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param string $actionMethodName |
|
47
|
|
|
* @param string $controllerClass |
|
48
|
|
|
* @param \EWW\Dpf\Domain\Model\Document $openedDocument |
|
49
|
|
|
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException |
|
50
|
|
|
*/ |
|
51
|
|
|
public function cleanUpDocuments($actionMethodName, $controllerClass, $openedDocument = NULL) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$this->cleanUpOutdatedDocuments(); |
|
54
|
|
|
|
|
55
|
|
|
$feUserUid = $this->security->getUser()->getUid(); |
|
56
|
|
|
$this->cleanUpTemporaryDocumentsByFeUser($feUserUid, $actionMethodName, $controllerClass); |
|
57
|
|
|
$this->unlockDocumentsByFeUser($feUserUid, $actionMethodName, $controllerClass); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Removes all outdated temporary documents and unlocks all outdated locked documents. |
|
63
|
|
|
* |
|
64
|
|
|
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException |
|
65
|
|
|
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function cleanUpOutdatedDocuments() |
|
68
|
|
|
{ |
|
69
|
|
|
// Remove outdated temporary documents from the document table. |
|
70
|
|
|
$outdatedTemporaryDocuments = $this->documentRepository->findOutdatedTemporaryDocuments(3600); |
|
71
|
|
|
foreach ($outdatedTemporaryDocuments as $outdatedTemporaryDocument) { |
|
72
|
|
|
/** @var \EWW\Dpf\Domain\Model\Document $outdatedTemporaryDocument */ |
|
73
|
|
|
$this->documentRepository->remove($outdatedTemporaryDocument); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
// Unlock outdated locked documents. |
|
77
|
|
|
$outdatedLockedDocuments = $this->documentRepository->findOutdatedLockedDocuments(3600); |
|
78
|
|
|
foreach ($outdatedLockedDocuments as $outdatedLockedDocument) { |
|
79
|
|
|
/** @var \EWW\Dpf\Domain\Model\Document $outdatedTemporaryDocument */ |
|
80
|
|
|
$this->documentRepository->update($outdatedLockedDocument); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->persistenceManager->persistAll(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Removes the temporary documents of a frontend user. |
|
89
|
|
|
* |
|
90
|
|
|
* @param $feUserUid |
|
91
|
|
|
* @param $actionMethodName |
|
92
|
|
|
* @param $controllerClass |
|
93
|
|
|
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException |
|
94
|
|
|
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException |
|
95
|
|
|
*/ |
|
96
|
|
|
public function cleanUpTemporaryDocumentsByFeUser($feUserUid, $actionMethodName, $controllerClass) |
|
97
|
|
|
{ |
|
98
|
|
|
$excludeActions = [ |
|
99
|
|
|
\EWW\Dpf\Controller\DocumentController::class => [ |
|
100
|
|
|
'showDetailsAction', |
|
101
|
|
|
'deleteLocallyAction', |
|
102
|
|
|
'postponeAction', |
|
103
|
|
|
'discardAction', |
|
104
|
|
|
'releasePublishAction', |
|
105
|
|
|
'releaseUpdateAction', |
|
106
|
|
|
'releaseActivateAction', |
|
107
|
|
|
'suggestModificationAction' |
|
108
|
|
|
], |
|
109
|
|
|
\EWW\Dpf\Controller\DocumentFormBackofficeController::class => [ |
|
110
|
|
|
'editAction', |
|
111
|
|
|
'cancelEditAction', |
|
112
|
|
|
'updateAction', |
|
113
|
|
|
'updateLocallyAction', |
|
114
|
|
|
'updateRemoteAction', |
|
115
|
|
|
'updateAction', |
|
116
|
|
|
'createSuggestionDocumentAction' |
|
117
|
|
|
] |
|
118
|
|
|
]; |
|
119
|
|
|
|
|
120
|
|
|
if ( |
|
121
|
|
|
!array_key_exists($controllerClass, $excludeActions) || |
|
122
|
|
|
!in_array($actionMethodName, $excludeActions[$controllerClass]) |
|
123
|
|
|
) { |
|
124
|
|
|
$documents = $this->documentRepository->findByTemporary(TRUE); |
|
|
|
|
|
|
125
|
|
|
foreach ($documents as $document) { |
|
126
|
|
|
/** @var \EWW\Dpf\Domain\Model\Document $document */ |
|
127
|
|
|
if ($document->getEditorUid() === $feUserUid) { |
|
128
|
|
|
$this->documentRepository->remove($document); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
$this->persistenceManager->persistAll(); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Unlocks the locked documents of a frontend user. |
|
139
|
|
|
* |
|
140
|
|
|
* @param $feUserUid |
|
141
|
|
|
* @param $actionMethodName |
|
142
|
|
|
* @param $controllerClass |
|
143
|
|
|
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException |
|
144
|
|
|
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException |
|
145
|
|
|
*/ |
|
146
|
|
|
public function unlockDocumentsByFeUser($feUserUid, $actionMethodName, $controllerClass) |
|
147
|
|
|
{ |
|
148
|
|
|
$excludeActions = [ |
|
149
|
|
|
\EWW\Dpf\Controller\DocumentController::class => [ |
|
150
|
|
|
'showDetailsAction' => 'temporary', |
|
151
|
|
|
'deleteLocallyAction' => 'all', |
|
152
|
|
|
'postponeAction' => 'all', |
|
153
|
|
|
'discardAction' => 'all', |
|
154
|
|
|
'releasePublishAction' => 'all', |
|
155
|
|
|
'releaseUpdateAction' => 'all', |
|
156
|
|
|
'releaseActivateAction' => 'all', |
|
157
|
|
|
'suggestModificationAction' => 'all' |
|
158
|
|
|
], |
|
159
|
|
|
\EWW\Dpf\Controller\DocumentFormBackofficeController::class => [ |
|
160
|
|
|
'editAction' => 'all', |
|
161
|
|
|
'cancelEditAction' => 'all', |
|
162
|
|
|
'updateAction' => 'all', |
|
163
|
|
|
'updateLocallyAction' => 'all', |
|
164
|
|
|
'updateRemoteAction' => 'all', |
|
165
|
|
|
'updateAction' => 'all', |
|
166
|
|
|
'createSuggestionDocumentAction' => 'all' |
|
167
|
|
|
] |
|
168
|
|
|
]; |
|
169
|
|
|
|
|
170
|
|
|
if ( |
|
171
|
|
|
!array_key_exists($controllerClass, $excludeActions) || |
|
172
|
|
|
( |
|
173
|
|
|
!array_key_exists($actionMethodName, $excludeActions[$controllerClass]) |
|
174
|
|
|
) |
|
175
|
|
|
) { |
|
176
|
|
|
$lockedDocuments = $this->documentRepository->findByEditorUid($feUserUid); |
|
|
|
|
|
|
177
|
|
|
foreach ($lockedDocuments as $lockedDocument) { |
|
178
|
|
|
/** @var \EWW\Dpf\Domain\Model\Document $lockedDocument */ |
|
179
|
|
|
$lockedDocument->setEditorUid(0); |
|
180
|
|
|
$this->documentRepository->update($lockedDocument); |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
$this->persistenceManager->persistAll(); |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
|
|
188
|
|
|
} |
|
189
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.