1
|
|
|
<?php |
2
|
|
|
namespace EWW\Dpf\Controller; |
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
|
|
|
use EWW\Dpf\Domain\Model\Bookmark; |
18
|
|
|
use EWW\Dpf\Domain\Model\Client; |
19
|
|
|
use EWW\Dpf\Domain\Model\Document; |
20
|
|
|
use EWW\Dpf\Domain\Model\DocumentType; |
21
|
|
|
use EWW\Dpf\Domain\Workflow\DocumentWorkflow; |
22
|
|
|
use EWW\Dpf\Helper\DocumentMapper; |
23
|
|
|
use EWW\Dpf\Helper\InternalFormat; |
24
|
|
|
use EWW\Dpf\Services\ElasticSearch\ElasticSearch; |
25
|
|
|
use EWW\Dpf\Services\ProcessNumber\ProcessNumberGenerator; |
26
|
|
|
use TYPO3\CMS\Backend\View\BackendTemplateView; |
27
|
|
|
use TYPO3\CMS\Core\Messaging\AbstractMessage; |
28
|
|
|
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface; |
29
|
|
|
use TYPO3\CMS\Extbase\Utility\LocalizationUtility; |
30
|
|
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Backend module user/group action controller |
34
|
|
|
*/ |
35
|
|
|
class BackendAdminController extends ActionController |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* documentRepository |
39
|
|
|
* |
40
|
|
|
* @var \EWW\Dpf\Domain\Repository\DocumentRepository |
41
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
42
|
|
|
*/ |
43
|
|
|
protected $documentRepository = null; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* fileRepository |
47
|
|
|
* |
48
|
|
|
* @var \EWW\Dpf\Domain\Repository\FileRepository |
49
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
50
|
|
|
*/ |
51
|
|
|
protected $fileRepository = null; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* documentTypeRepository |
55
|
|
|
* |
56
|
|
|
* @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository |
57
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
58
|
|
|
*/ |
59
|
|
|
protected $documentTypeRepository = null; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* bookmarkRepository |
63
|
|
|
* |
64
|
|
|
* @var \EWW\Dpf\Domain\Repository\BookmarkRepository |
65
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
66
|
|
|
*/ |
67
|
|
|
protected $bookmarkRepository = null; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* frontendUserRepository |
71
|
|
|
* |
72
|
|
|
* @var \EWW\Dpf\Domain\Repository\FrontendUserRepository |
73
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
74
|
|
|
*/ |
75
|
|
|
protected $frontendUserRepository = null; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* clientRepository |
79
|
|
|
* |
80
|
|
|
* @var \EWW\Dpf\Domain\Repository\ClientRepository |
81
|
|
|
* @TYPO3\CMS\Extbase\Annotation\Inject |
82
|
|
|
*/ |
83
|
|
|
protected $clientRepository = null; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Backend Template Container |
87
|
|
|
* |
88
|
|
|
* @var string |
89
|
|
|
*/ |
90
|
|
|
protected $defaultViewObjectName = BackendTemplateView::class; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Set up the doc header properly here |
94
|
|
|
* |
95
|
|
|
* @param ViewInterface $view |
96
|
|
|
* @return void |
97
|
|
|
*/ |
98
|
|
|
protected function initializeView(ViewInterface $view) |
99
|
|
|
{ |
100
|
|
|
/** @var BackendTemplateView $view */ |
101
|
|
|
parent::initializeView($view); |
102
|
|
|
if ($this->actionMethodName == 'indexAction' |
103
|
|
|
|| $this->actionMethodName == 'onlineAction' |
104
|
|
|
|| $this->actionMethodName == 'compareAction') { |
105
|
|
|
$this->generateMenu(); |
|
|
|
|
106
|
|
|
$this->registerDocheaderButtons(); |
|
|
|
|
107
|
|
|
$view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue()); |
108
|
|
|
} |
109
|
|
|
if ($view instanceof BackendTemplateView) { |
|
|
|
|
110
|
|
|
$view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal'); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param string $identifier |
116
|
|
|
*/ |
117
|
|
|
public function searchDocumentAction(string $identifier = '') |
118
|
|
|
{ |
119
|
|
|
$identifier = trim($identifier); |
120
|
|
|
$this->view->assign('identifier', $identifier); |
121
|
|
|
|
122
|
|
|
if ($identifier) { |
123
|
|
|
|
124
|
|
|
$this->documentRepository->crossClient(true); |
125
|
|
|
|
126
|
|
|
$documents = $this->documentRepository->searchForIdentifier($identifier); |
127
|
|
|
|
128
|
|
|
if ($documents) { |
129
|
|
|
|
130
|
|
|
$clientNames = []; |
131
|
|
|
foreach ($documents as $document) { |
132
|
|
|
/** @var Client $client */ |
133
|
|
|
$client = $this->clientRepository->findAllByPid($document->getPid())->current(); |
134
|
|
|
$clientNames[$document->getUid()] = $client->getClient(); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$this->view->assign('documents', $documents); |
138
|
|
|
$this->view->assign('clientNames', $clientNames); |
139
|
|
|
|
140
|
|
|
} else { |
141
|
|
|
$this->flashMessage( |
142
|
|
|
'nothing_found', |
143
|
|
|
'nothing_found_message', |
144
|
|
|
AbstractMessage::ERROR, |
145
|
|
|
[], |
146
|
|
|
[$identifier] |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param Document $document |
154
|
|
|
* @param string $identifier |
155
|
|
|
*/ |
156
|
|
|
public function chooseNewClientAction(Document $document, string $identifier) |
157
|
|
|
{ |
158
|
|
|
if ($document) { |
|
|
|
|
159
|
|
|
if ($document->isClientChangeable()) { |
160
|
|
|
/** @var Client $currentClient */ |
161
|
|
|
$currentClient = $this->clientRepository->findAllByPid($document->getPid())->current(); |
162
|
|
|
|
163
|
|
|
$allClients = $this->clientRepository->crossClientFindAll(false); |
164
|
|
|
|
165
|
|
|
$documentTypes = []; |
166
|
|
|
$clients = []; |
167
|
|
|
|
168
|
|
|
/** @var Client $client */ |
169
|
|
|
foreach ($allClients as $client) { |
170
|
|
|
if ($client->getUid() != $currentClient->getUid()) { |
171
|
|
|
$clients[] = $client; |
172
|
|
|
$this->documentTypeRepository->crossClient(true); |
173
|
|
|
$documentTypes[$client->getPid()] = $this->documentTypeRepository->findByPid($client->getPid()); |
|
|
|
|
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
$this->view->assign('canMoveDocument', $document->isClientChangeable()); |
178
|
|
|
$this->view->assign('document', $document); |
179
|
|
|
$this->view->assign('clients', $clients); |
180
|
|
|
$this->view->assign('documentTypes', $documentTypes); |
181
|
|
|
$this->view->assign('currentClient', $currentClient); |
182
|
|
|
$this->view->assign('identifier', $identifier); |
183
|
|
|
} else { |
184
|
|
|
$this->flashMessage( |
185
|
|
|
'change_client_forbidden', |
186
|
|
|
'change_client_forbidden_message', |
187
|
|
|
AbstractMessage::ERROR, |
188
|
|
|
[], |
189
|
|
|
[$identifier] |
190
|
|
|
); |
191
|
|
|
|
192
|
|
|
$this->forward( |
193
|
|
|
'searchDocument', |
194
|
|
|
null, |
195
|
|
|
null, |
196
|
|
|
[ |
197
|
|
|
'identifier' => $identifier |
198
|
|
|
] |
199
|
|
|
); |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @param Document $document |
206
|
|
|
* @param Client $client |
207
|
|
|
* @param string $identifier |
208
|
|
|
* @param DocumentType $documentType |
209
|
|
|
*/ |
210
|
|
|
public function changeClientAction(Document $document, Client $client, string $identifier, DocumentType $documentType = null) |
211
|
|
|
{ |
212
|
|
|
if ($documentType instanceof DocumentType) { |
213
|
|
|
if ($document->isClientChangeable()) { |
214
|
|
|
|
215
|
|
|
/** @var Client $currentClient */ |
216
|
|
|
$currentClient = $this->clientRepository->findAllByPid($document->getPid())->current(); |
217
|
|
|
|
218
|
|
|
// Move the document to the target client |
219
|
|
|
// Fixme: How should the creator be dealt with? |
220
|
|
|
// $document->setCreator(); |
221
|
|
|
$document->setPid($client->getPid()); |
222
|
|
|
$document->setDocumentType($documentType); |
223
|
|
|
$documentMapper = $this->objectManager->get(DocumentMapper::class); |
224
|
|
|
$documentMapper->setClientPid($client->getPid()); |
225
|
|
|
$documentForm = $documentMapper->getDocumentForm($document); |
226
|
|
|
$document = $documentMapper->getDocument($documentForm); |
227
|
|
|
$internalFormat = new InternalFormat($document->getXmlData(), $client->getPid()); |
228
|
|
|
$internalFormat->setDocumentType($documentType->getName()); |
229
|
|
|
$document->setXmlData($internalFormat->getXml()); |
230
|
|
|
|
231
|
|
|
if ($client->getOwnerId()) { |
232
|
|
|
/** @var ProcessNumberGenerator $processNumberGenerator */ |
233
|
|
|
$processNumberGenerator = $this->objectManager->get(ProcessNumberGenerator::class); |
234
|
|
|
$processNumber = $processNumberGenerator->getProcessNumber($client->getOwnerId()); |
235
|
|
|
$document->setProcessNumber($processNumber); |
236
|
|
|
} else { |
237
|
|
|
throw new \Exception('Missing client configuration: "owner id"'); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
$this->documentRepository->update($document); |
241
|
|
|
|
242
|
|
|
// Move files to the target client |
243
|
|
|
$files = $document->getFile(); |
244
|
|
|
foreach ($files as $file) { |
245
|
|
|
$file->setPid($client->getPid()); |
246
|
|
|
$this->fileRepository->update($file); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
// If there are bookmarks, they have to be adjusted, depending on the existence of the related user |
250
|
|
|
// inside the target client, and either deleted or moved to the target client. |
251
|
|
|
$this->bookmarkRepository->crossClient(true); |
252
|
|
|
$bookmarks = $this->bookmarkRepository->findDocumentBookmarks($document); |
253
|
|
|
/** @var Bookmark $bookmark */ |
254
|
|
|
foreach ($bookmarks as $bookmark) { |
255
|
|
|
if ($this->frontendUserRepository->isUserInClient($bookmark->getFeUserUid(), $client->getPid())) { |
256
|
|
|
$bookmark->setPid($client->getPid()); |
257
|
|
|
$this->bookmarkRepository->update($bookmark); |
258
|
|
|
} else { |
259
|
|
|
$this->bookmarkRepository->remove($bookmark); |
260
|
|
|
} |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
// Move document into the target search index. |
264
|
|
|
$elasticSearch = new ElasticSearch($currentClient->getPid()); |
265
|
|
|
$elasticSearch->delete($document->getDocumentIdentifier()); |
266
|
|
|
$targetElasticSearch = new ElasticSearch($client->getPid()); |
267
|
|
|
$targetElasticSearch->index($document); |
268
|
|
|
|
269
|
|
|
$this->flashMessage( |
270
|
|
|
'client_changed', |
271
|
|
|
'client_changed_message', |
272
|
|
|
AbstractMessage::OK, |
273
|
|
|
[], |
274
|
|
|
[$identifier] |
275
|
|
|
); |
276
|
|
|
} else { |
277
|
|
|
$this->flashMessage( |
278
|
|
|
'change_client_forbidden', |
279
|
|
|
'change_client_forbidden_message', |
280
|
|
|
AbstractMessage::ERROR, |
281
|
|
|
[], |
282
|
|
|
[$identifier] |
283
|
|
|
); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
$this->view->assign('currentClient', $client); |
287
|
|
|
$this->view->assign('document', $document); |
288
|
|
|
} else { |
289
|
|
|
$this->flashMessage( |
290
|
|
|
'missing_document_type', |
291
|
|
|
'missing_document_type_message', |
292
|
|
|
AbstractMessage::ERROR, |
293
|
|
|
[], |
294
|
|
|
[$identifier] |
295
|
|
|
); |
296
|
|
|
|
297
|
|
|
$this->forward( |
298
|
|
|
'chooseNewClient', |
299
|
|
|
null, |
300
|
|
|
null, |
301
|
|
|
[ |
302
|
|
|
'document' => $document, |
303
|
|
|
'identifier' => $identifier |
304
|
|
|
] |
305
|
|
|
); |
306
|
|
|
} |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* flashMessage |
311
|
|
|
* |
312
|
|
|
* @param string $headerKey |
313
|
|
|
* @param string $bodyKey |
314
|
|
|
* @param array $headerArguments |
315
|
|
|
* @param array $bodyArguments |
316
|
|
|
* @param int $severity |
317
|
|
|
* @param bool $storeInSession |
318
|
|
|
*/ |
319
|
|
|
protected function flashMessage( |
320
|
|
|
string $headerKey, |
321
|
|
|
string $bodyKey, |
322
|
|
|
int $severity = AbstractMessage::INFO, |
323
|
|
|
array $headerArguments, |
324
|
|
|
array $bodyArguments, |
325
|
|
|
bool $storeInSession = false |
326
|
|
|
) |
327
|
|
|
{ |
328
|
|
|
$messageHeader = LocalizationUtility::translate( |
329
|
|
|
'LLL:EXT:dpf/Resources/Private/Language/locallang_mod.xlf:admin_module.'.$headerKey, |
330
|
|
|
'dpf', |
331
|
|
|
$headerArguments |
332
|
|
|
); |
333
|
|
|
|
334
|
|
|
$messageBody = LocalizationUtility::translate( |
335
|
|
|
'LLL:EXT:dpf/Resources/Private/Language/locallang_mod.xlf:admin_module.'.$bodyKey, |
336
|
|
|
'dpf', |
337
|
|
|
$bodyArguments |
338
|
|
|
); |
339
|
|
|
|
340
|
|
|
$this->addFlashMessage($messageBody, $messageHeader, $severity, $storeInSession); |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
} |
344
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.