Total Complexity | 111 |
Total Lines | 999 |
Duplicated Lines | 0 % |
Changes | 8 | ||
Bugs | 1 | Features | 0 |
Complex classes like DocumentController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DocumentController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
39 | class DocumentController extends AbstractController |
||
40 | { |
||
41 | |||
42 | /** |
||
43 | * documentRepository |
||
44 | * |
||
45 | * @var \EWW\Dpf\Domain\Repository\DocumentRepository |
||
46 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
47 | */ |
||
48 | protected $documentRepository = null; |
||
49 | |||
50 | /** |
||
51 | * documentTypeRepository |
||
52 | * |
||
53 | * @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository |
||
54 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
55 | */ |
||
56 | protected $documentTypeRepository = null; |
||
57 | |||
58 | /** |
||
59 | * inputOptionListRepository |
||
60 | * |
||
61 | * @var \EWW\Dpf\Domain\Repository\InputOptionListRepository |
||
62 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
63 | */ |
||
64 | protected $inputOptionListRepository = null; |
||
65 | |||
66 | /** |
||
67 | * persistence manager |
||
68 | * |
||
69 | * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface |
||
70 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
71 | */ |
||
72 | protected $persistenceManager; |
||
73 | |||
74 | /** |
||
75 | * editingLockService |
||
76 | * |
||
77 | * @var \EWW\Dpf\Services\Document\EditingLockService |
||
78 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
79 | */ |
||
80 | protected $editingLockService = null; |
||
81 | |||
82 | /** |
||
83 | * documentValidator |
||
84 | * |
||
85 | * @var \EWW\Dpf\Helper\DocumentValidator |
||
86 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
87 | */ |
||
88 | protected $documentValidator; |
||
89 | |||
90 | /** |
||
91 | * depositLicenseLogRepository |
||
92 | * |
||
93 | * @var \EWW\Dpf\Domain\Repository\DepositLicenseLogRepository |
||
94 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
95 | */ |
||
96 | protected $depositLicenseLogRepository = null; |
||
97 | |||
98 | /** |
||
99 | * workflow |
||
100 | * |
||
101 | * @var \EWW\Dpf\Domain\Workflow\DocumentWorkflow |
||
102 | */ |
||
103 | protected $workflow; |
||
104 | |||
105 | /** |
||
106 | * documentTransferManager |
||
107 | * |
||
108 | * @var \EWW\Dpf\Services\Transfer\DocumentTransferManager $documentTransferManager |
||
109 | */ |
||
110 | protected $documentTransferManager; |
||
111 | |||
112 | /** |
||
113 | * fedoraRepository |
||
114 | * |
||
115 | * @var \EWW\Dpf\Services\Transfer\FedoraRepository $fedoraRepository |
||
116 | */ |
||
117 | protected $fedoraRepository; |
||
118 | |||
119 | /** |
||
120 | * fileRepository |
||
121 | * |
||
122 | * @var \EWW\Dpf\Domain\Repository\FileRepository |
||
123 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
124 | */ |
||
125 | protected $fileRepository = null; |
||
126 | |||
127 | |||
128 | /** |
||
129 | * frontendUserRepository |
||
130 | * |
||
131 | * @var \EWW\Dpf\Domain\Repository\FrontendUserRepository |
||
132 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
133 | */ |
||
134 | protected $frontendUserRepository = null; |
||
135 | |||
136 | /** |
||
137 | * documentManager |
||
138 | * |
||
139 | * @var \EWW\Dpf\Services\Document\DocumentManager |
||
140 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
141 | */ |
||
142 | protected $documentManager = null; |
||
143 | |||
144 | /** |
||
145 | * bookmarkRepository |
||
146 | * |
||
147 | * @var \EWW\Dpf\Domain\Repository\BookmarkRepository |
||
148 | * @TYPO3\CMS\Extbase\Annotation\Inject |
||
149 | */ |
||
150 | protected $bookmarkRepository = null; |
||
151 | |||
152 | /** |
||
153 | * DocumentController constructor. |
||
154 | */ |
||
155 | public function __construct() |
||
156 | { |
||
157 | parent::__construct(); |
||
158 | |||
159 | $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class); |
||
160 | $this->documentTransferManager = $objectManager->get(DocumentTransferManager::class); |
||
161 | $this->fedoraRepository = $objectManager->get(FedoraRepository::class); |
||
162 | $this->documentTransferManager->setRemoteRepository($this->fedoraRepository); |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * action logout of the backoffice |
||
167 | * |
||
168 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
169 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
170 | */ |
||
171 | public function logoutAction() |
||
172 | { |
||
173 | $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class); |
||
174 | $uri = $cObj->typolink_URL([ |
||
175 | 'parameter' => $this->settings['loginPage'], |
||
176 | //'linkAccessRestrictedPages' => 1, |
||
177 | 'forceAbsoluteUrl' => 1, |
||
178 | 'additionalParams' => GeneralUtility::implodeArrayForUrl(NULL, ['logintype'=>'logout']) |
||
179 | ]); |
||
180 | |||
181 | $this->redirectToUri($uri); |
||
182 | } |
||
183 | |||
184 | public function listSuggestionsAction() { |
||
185 | $this->session->setStoredAction($this->getCurrentAction(), $this->getCurrentController()); |
||
186 | |||
187 | $documents = NULL; |
||
188 | $isWorkspace = $this->security->getUserRole() === Security::ROLE_LIBRARIAN; |
||
189 | |||
190 | if ( |
||
191 | $this->security->getUserRole() == Security::ROLE_LIBRARIAN |
||
192 | ) { |
||
193 | $documents = $this->documentRepository->findAllDocumentSuggestions( |
||
194 | $this->security->getUserRole(), |
||
195 | $this->security->getUser()->getUid() |
||
196 | ); |
||
197 | } |
||
198 | |||
199 | if ($this->request->hasArgument('message')) { |
||
200 | $this->view->assign('message', $this->request->getArgument('message')); |
||
201 | } |
||
202 | |||
203 | if ($this->request->hasArgument('errorFiles')) { |
||
204 | $this->view->assign('errorFiles', $this->request->getArgument('errorFiles')); |
||
205 | } |
||
206 | |||
207 | $this->view->assign('currentUser', $this->security->getUser()); |
||
208 | $this->view->assign('isWorkspace', $isWorkspace); |
||
209 | $this->view->assign('documents', $documents); |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * @param Document $document |
||
214 | * @param bool $acceptAll |
||
215 | */ |
||
216 | public function acceptSuggestionAction(\EWW\Dpf\Domain\Model\Document $document, bool $acceptAll = true) { |
||
217 | |||
218 | /** @var DocumentMapper $documentMapper */ |
||
219 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
220 | |||
221 | // Existing working copy? |
||
222 | /** @var \EWW\Dpf\Domain\Model\Document $originDocument */ |
||
223 | $linkedUid = $document->getLinkedUid(); |
||
224 | $originDocument = $this->documentRepository->findWorkingCopy($linkedUid); |
||
225 | |||
226 | if ($originDocument) { |
||
|
|||
227 | $linkedDocumentForm = $documentMapper->getDocumentForm($originDocument); |
||
228 | } else { |
||
229 | // get remote document |
||
230 | $originDocument = $this->documentTransferManager->retrieve($document->getLinkedUid(), $this->security->getUser()->getUid()); |
||
231 | $linkedDocumentForm = $documentMapper->getDocumentForm($originDocument); |
||
232 | } |
||
233 | |||
234 | if ($acceptAll) { |
||
235 | // all changes are confirmed |
||
236 | // copy suggest to origin document |
||
237 | $originDocument->copy($document, true); |
||
238 | |||
239 | if ($document->getRemoteState() != DocumentWorkflow::REMOTE_STATE_NONE) { |
||
240 | if ($document->getLocalState() != DocumentWorkflow::LOCAL_STATE_IN_PROGRESS) { |
||
241 | $originDocument->setState( |
||
242 | DocumentWorkflow::constructState(DocumentWorkflow::LOCAL_STATE_IN_PROGRESS, |
||
243 | $document->getRemoteState()) |
||
244 | ); |
||
245 | $this->addFlashMessage( |
||
246 | LocalizationUtility::translate("message.suggestion_accepted.new_workingcopy_info", "dpf"), |
||
247 | '', |
||
248 | AbstractMessage::INFO |
||
249 | ); |
||
250 | } |
||
251 | } |
||
252 | |||
253 | if ($originDocument->getTransferStatus() == 'RESTORE') { |
||
254 | if ($originDocument->getObjectIdentifier()) { |
||
255 | $originDocument->setState(DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE); |
||
256 | } else { |
||
257 | $originDocument->setState(DocumentWorkflow::STATE_IN_PROGRESS_NONE); |
||
258 | } |
||
259 | } |
||
260 | |||
261 | // copy files from suggest document |
||
262 | foreach ($document->getFile() as $key => $file) { |
||
263 | $newFile = $this->objectManager->get(File::class); |
||
264 | $newFile->copy($file); |
||
265 | $newFile->setDocument($originDocument); |
||
266 | $this->fileRepository->add($newFile); |
||
267 | $originDocument->addFile($newFile); |
||
268 | } |
||
269 | |||
270 | $internalFormat = new InternalFormat($document->getXmlData()); |
||
271 | $originDocument->setAuthors($internalFormat->getPersons()); |
||
272 | $this->documentRepository->update($originDocument); |
||
273 | $this->documentRepository->remove($document); |
||
274 | |||
275 | // Notify assigned users |
||
276 | /** @var Notifier $notifier */ |
||
277 | $notifier = $this->objectManager->get(Notifier::class); |
||
278 | |||
279 | $recipients = $this->documentManager->getUpdateNotificationRecipients($originDocument); |
||
280 | $notifier->sendMyPublicationUpdateNotification($originDocument, $recipients); |
||
281 | |||
282 | $recipients = $this->documentManager->getNewPublicationNotificationRecipients($originDocument); |
||
283 | $notifier->sendMyPublicationNewNotification($originDocument, $recipients); |
||
284 | |||
285 | $notifier->sendChangedDocumentNotification($originDocument); |
||
286 | |||
287 | $notifier->sendSuggestionAcceptNotification($originDocument); |
||
288 | |||
289 | // index the document |
||
290 | $this->signalSlotDispatcher->dispatch( |
||
291 | AbstractController::class, 'indexDocument', [$originDocument] |
||
292 | ); |
||
293 | |||
294 | // redirect to document |
||
295 | $this->redirect('showDetails', 'Document', null, ['document' => $originDocument]); |
||
296 | } |
||
297 | |||
298 | $this->redirectToDocumentList(); |
||
299 | } |
||
300 | |||
301 | |||
302 | public function showSuggestionDetailsAction(\EWW\Dpf\Domain\Model\Document $document) { |
||
303 | $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SHOW_DETAILS, $document); |
||
304 | |||
305 | /** @var DocumentMapper $documentMapper */ |
||
306 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
307 | |||
308 | $linkedUid = $document->getLinkedUid(); |
||
309 | $linkedDocument = $this->documentRepository->findWorkingCopy($linkedUid); |
||
310 | |||
311 | if ($linkedDocument) { |
||
312 | // Existing working copy |
||
313 | $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument); |
||
314 | } else { |
||
315 | // No existing working copy, get remote document from fedora |
||
316 | $linkedDocument = $this->documentTransferManager->retrieve($document->getLinkedUid(), $this->security->getUser()->getUid()); |
||
317 | $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument); |
||
318 | } |
||
319 | |||
320 | $newDocumentForm = $documentMapper->getDocumentForm($document); |
||
321 | $diff = $this->documentFormDiff($linkedDocumentForm, $newDocumentForm); |
||
322 | |||
323 | //$usernameString = $this->security->getUsername(); |
||
324 | $user = $this->frontendUserRepository->findOneByUid($document->getCreator()); |
||
325 | |||
326 | if ($user) { |
||
327 | $usernameString = $user->getUsername(); |
||
328 | } |
||
329 | |||
330 | $this->view->assign('documentCreator', $usernameString); |
||
331 | $this->view->assign('diff', $diff); |
||
332 | $this->view->assign('document', $document); |
||
333 | |||
334 | } |
||
335 | |||
336 | public function documentFormDiff($docForm1, $docForm2) { |
||
337 | $returnArray = ['changed' => ['new' => [], 'old' => []], 'deleted' => [], 'added' => []]; |
||
338 | |||
339 | // pages |
||
340 | foreach ($docForm1->getItems() as $keyPage => $valuePage) { |
||
341 | foreach ($valuePage as $keyRepeatPage => $valueRepeatPage) { |
||
342 | |||
343 | // groups |
||
344 | foreach ($valueRepeatPage->getItems() as $keyGroup => $valueGroup) { |
||
345 | |||
346 | $checkFieldsForAdding = false; |
||
347 | $valueGroupCounter = count($valueGroup); |
||
348 | |||
349 | if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) { |
||
350 | $checkFieldsForAdding = true; |
||
351 | } |
||
352 | |||
353 | foreach ($valueGroup as $keyRepeatGroup => $valueRepeatGroup) { |
||
354 | |||
355 | // fields |
||
356 | foreach ($valueRepeatGroup->getItems() as $keyField => $valueField) { |
||
357 | foreach ($valueField as $keyRepeatField => $valueRepeatField) { |
||
358 | |||
359 | $fieldCounter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]); |
||
360 | $valueFieldCounter = count($valueField); |
||
361 | |||
362 | // check if group or field is not existing |
||
363 | $notExisting = false; |
||
364 | try { |
||
365 | $flag = 'page'; |
||
366 | $value2 = $docForm2->getItems()[$keyPage]; |
||
367 | $flag = 'group'; |
||
368 | $value2 = $value2[$keyRepeatPage]; |
||
369 | $value2 = $value2->getItems()[$keyGroup]; |
||
370 | $value2 = $value2[$keyRepeatGroup]->getItems()[$keyField]; |
||
371 | $flag = 'field'; |
||
372 | } catch (\Throwable $t) { |
||
373 | $notExisting = true; |
||
374 | } |
||
375 | |||
376 | $item = NULL; |
||
377 | if ($flag == 'group') { |
||
378 | $itemExisting = $valueRepeatGroup; |
||
379 | $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]; |
||
380 | } else if ($flag == 'field') { |
||
381 | $itemExisting = $valueRepeatField; |
||
382 | $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$keyRepeatField]; |
||
383 | } |
||
384 | |||
385 | if ($notExisting || ($valueRepeatField->getValue() != $value2[$keyRepeatField]->getValue() && empty($value2[$keyRepeatField]->getValue()))) { |
||
386 | // deleted |
||
387 | $returnArray['deleted'][] = $itemExisting; |
||
388 | |||
389 | } else if ($this->removeControlCharacterFromString($valueRepeatField->getValue()) != $this->removeControlCharacterFromString($value2[$keyRepeatField]->getValue()) |
||
390 | && !empty($value2[$keyRepeatField]->getValue())) { |
||
391 | |||
392 | // changed |
||
393 | $returnArray['changed']['old'][] = $itemExisting; |
||
394 | $returnArray['changed']['new'][] = $itemNew; |
||
395 | $returnArray['changed']['groupDisplayName'] = $valueRepeatGroup->getDisplayName(); |
||
396 | } |
||
397 | |||
398 | if ($flag == 'group') { |
||
399 | break 2; |
||
400 | } |
||
401 | } |
||
402 | |||
403 | // check if new document form has more field items as the existing form |
||
404 | if ($valueFieldCounter < $fieldCounter && !$checkFieldsForAdding) { |
||
405 | // field added |
||
406 | for ($i = count($valueField); $i < $fieldCounter;$i++) { |
||
407 | $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$i]; |
||
408 | |||
409 | } |
||
410 | } |
||
411 | } |
||
412 | } |
||
413 | |||
414 | // check if new document form has more group items as the existing form |
||
415 | if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) { |
||
416 | // group added |
||
417 | $counter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]); |
||
418 | for ($i = $valueGroupCounter; $i < $counter;$i++) { |
||
419 | $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$i]; |
||
420 | } |
||
421 | } |
||
422 | } |
||
423 | } |
||
424 | |||
425 | } |
||
426 | |||
427 | return $returnArray; |
||
428 | |||
429 | } |
||
430 | |||
431 | public function removeControlCharacterFromString($string) { |
||
432 | return preg_replace('/\p{C}+/u', "", $string); |
||
433 | } |
||
434 | |||
435 | /** |
||
436 | * action discard |
||
437 | * |
||
438 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
439 | * @param integer $tstamp |
||
440 | * @param string $reason |
||
441 | * @return void |
||
442 | */ |
||
443 | public function discardAction(Document $document, $tstamp, $reason = NULL) |
||
462 | } |
||
463 | |||
464 | /** |
||
465 | * action postpone |
||
466 | * |
||
467 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
468 | * @param integer $tstamp |
||
469 | * @param string $reason |
||
470 | * @return void |
||
471 | */ |
||
472 | public function postponeAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = NULL) |
||
491 | |||
492 | } |
||
493 | |||
494 | |||
495 | /** |
||
496 | * action change document type |
||
497 | * |
||
498 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
499 | * @param int $documentTypeUid |
||
500 | * @return void |
||
501 | */ |
||
502 | public function changeDocumentTypeAction(\EWW\Dpf\Domain\Model\Document $document, $documentTypeUid = 0) |
||
503 | { |
||
504 | if (!$this->authorizationChecker->isGranted(DocumentVoter::UPDATE, $document)) { |
||
505 | if ( |
||
506 | $this->editingLockService->isLocked( |
||
507 | $document->getDocumentIdentifier(), |
||
508 | $this->security->getUser()->getUid() |
||
509 | ) |
||
510 | ) { |
||
511 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failureBlocked'; |
||
512 | } else { |
||
513 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.accessDenied'; |
||
514 | } |
||
515 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
516 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
517 | return FALSE; |
||
518 | } |
||
519 | |||
520 | |||
521 | $documentType = $this->documentTypeRepository->findByUid($documentTypeUid); |
||
522 | |||
523 | if ($documentType instanceof DocumentType) { |
||
524 | $document->setDocumentType($documentType); |
||
525 | |||
526 | $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData()); |
||
527 | $internalFormat->setDocumentType($documentType->getName()); |
||
528 | $document->setXmlData($internalFormat->getXml()); |
||
529 | |||
530 | /** @var DocumentMapper $documentMapper */ |
||
531 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
532 | // Adjusting the document data according to the new document type |
||
533 | $documentForm = $documentMapper->getDocumentForm($document); |
||
534 | $document = $documentMapper->getDocument($documentForm); |
||
535 | |||
536 | $this->updateDocument($document, '', null); |
||
537 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
538 | } else { |
||
539 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failure'; |
||
540 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
541 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
542 | return FALSE; |
||
543 | } |
||
544 | } |
||
545 | |||
546 | /** |
||
547 | * action deleteLocallySuggestionAction |
||
548 | * |
||
549 | * @param Document $document |
||
550 | * @param integer $tstamp |
||
551 | * @param string $reason |
||
552 | * @return void |
||
553 | */ |
||
554 | public function deleteLocallySuggestionAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = "") |
||
555 | { |
||
556 | $this->redirect( |
||
557 | 'deleteLocally', |
||
558 | 'Document', |
||
559 | null, |
||
560 | [ |
||
561 | 'document' => $document, |
||
562 | 'tstamp' => $tstamp, |
||
563 | 'reason' => $reason |
||
564 | ] |
||
565 | ); |
||
566 | } |
||
567 | |||
568 | |||
569 | /** |
||
570 | * action deleteLocallyAction |
||
571 | * |
||
572 | * @param Document $document |
||
573 | * @param integer $tstamp |
||
574 | * @param string $reason |
||
575 | * @return void |
||
576 | */ |
||
577 | public function deleteLocallyAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = "") |
||
578 | { |
||
579 | if (empty($document->getObjectIdentifier()) || $document->isSuggestion()) { |
||
580 | $voterAttribute = DocumentVoter::DELETE_LOCALLY; |
||
581 | } else { |
||
582 | $voterAttribute = DocumentVoter::DELETE_WORKING_COPY; |
||
583 | } |
||
584 | |||
585 | if (!$this->authorizationChecker->isGranted($voterAttribute, $document)) { |
||
586 | if ( |
||
587 | $this->editingLockService->isLocked( |
||
588 | $document->getDocumentIdentifier(), |
||
589 | $this->security->getUser()->getUid() |
||
590 | ) |
||
591 | ) { |
||
592 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureBlocked'; |
||
593 | } else { |
||
594 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.accessDenied'; |
||
595 | } |
||
596 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
597 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
598 | return FALSE; |
||
599 | } |
||
600 | |||
601 | if ($tstamp === $document->getTstamp()) { |
||
602 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.success'; |
||
603 | $this->flashMessage($document, $key, AbstractMessage::OK); |
||
604 | $this->documentRepository->remove($document); |
||
605 | |||
606 | if ($document->isWorkingCopy() || $document->isTemporaryCopy()) { |
||
607 | |||
608 | if ($document->isWorkingCopy()) { |
||
609 | if ($this->bookmarkRepository->removeBookmark($document, $this->security->getUser()->getUid())) { |
||
610 | $this->addFlashMessage( |
||
611 | LocalizationUtility::translate("manager.workspace.bookmarkRemoved.singular", "dpf"), '', |
||
612 | AbstractMessage::INFO |
||
613 | ); |
||
614 | } |
||
615 | } |
||
616 | |||
617 | $this->persistenceManager->persistAll(); |
||
618 | $document = $this->documentManager->read($document->getDocumentIdentifier()); |
||
619 | |||
620 | // index the document |
||
621 | $this->signalSlotDispatcher->dispatch( |
||
622 | \EWW\Dpf\Controller\AbstractController::class, |
||
623 | 'indexDocument', [$document] |
||
624 | ); |
||
625 | |||
626 | $this->documentRepository->remove($document); |
||
627 | |||
628 | } elseif (!$document->isSuggestion()) { |
||
629 | $this->bookmarkRepository->removeBookmark($document, $this->security->getUser()->getUid()); |
||
630 | // delete document from index |
||
631 | $this->signalSlotDispatcher->dispatch( |
||
632 | \EWW\Dpf\Controller\AbstractController::class, |
||
633 | 'deleteDocumentFromIndex', [$document->getDocumentIdentifier()] |
||
634 | ); |
||
635 | } |
||
636 | |||
637 | $suggestions = $this->documentRepository->findByLinkedUid($document->getDocumentIdentifier()); |
||
638 | foreach ($suggestions as $suggestion) { |
||
639 | $this->documentRepository->remove($suggestion); |
||
640 | } |
||
641 | |||
642 | /** @var Notifier $notifier */ |
||
643 | $notifier = $this->objectManager->get(Notifier::class); |
||
644 | $notifier->sendSuggestionDeclineNotification($document, $reason); |
||
645 | |||
646 | $this->redirectToDocumentList(); |
||
647 | } else { |
||
648 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureNewVersion'; |
||
649 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
650 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
651 | } |
||
652 | } |
||
653 | |||
654 | |||
655 | /** |
||
656 | * @param Document $document |
||
657 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
658 | */ |
||
659 | public function duplicateAction(\EWW\Dpf\Domain\Model\Document $document) |
||
705 | ); |
||
706 | |||
707 | } |
||
708 | |||
709 | /** |
||
710 | * releasePublishAction |
||
711 | * |
||
712 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
713 | * @param integer $tstamp |
||
714 | * @return void |
||
715 | */ |
||
716 | public function releasePublishAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp) |
||
717 | { |
||
718 | if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_PUBLISH, $document)) { |
||
719 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_ingest.accessDenied'; |
||
720 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
721 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
722 | return FALSE; |
||
723 | } |
||
724 | |||
725 | $this->updateDocument($document, DocumentWorkflow::TRANSITION_RELEASE_PUBLISH, null); |
||
726 | |||
727 | /** @var Notifier $notifier */ |
||
728 | $notifier = $this->objectManager->get(Notifier::class); |
||
729 | $notifier->sendReleasePublishNotification($document); |
||
730 | } |
||
731 | |||
732 | /** |
||
733 | * releaseActivateAction |
||
734 | * |
||
735 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
736 | * @param integer $tstamp |
||
737 | * @return void |
||
738 | */ |
||
739 | public function releaseActivateAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp) |
||
740 | { |
||
741 | if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_ACTIVATE, $document)) { |
||
742 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_activate.accessDenied'; |
||
743 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
744 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
745 | return FALSE; |
||
746 | } |
||
747 | |||
748 | $this->updateDocument($document, DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE, null); |
||
749 | |||
750 | } |
||
751 | |||
752 | /** |
||
753 | * action register |
||
754 | * |
||
755 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
756 | * @return void |
||
757 | */ |
||
758 | public function registerAction(\EWW\Dpf\Domain\Model\Document $document) |
||
797 | } |
||
798 | |||
799 | /** |
||
800 | * action showDetails |
||
801 | * |
||
802 | * @param \EWW\Dpf\Domain\Model\Document $document |
||
803 | * @return void |
||
804 | */ |
||
805 | public function showDetailsAction(Document $document) |
||
806 | { |
||
807 | if (!$this->authorizationChecker->isGranted(DocumentVoter::SHOW_DETAILS, $document)) { |
||
808 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_showDetails.accessDenied'; |
||
809 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
810 | $this->redirectToDocumentList(); |
||
811 | } |
||
812 | |||
813 | $this->editingLockService->lock( |
||
814 | ($document->getObjectIdentifier()? $document->getObjectIdentifier() : $document->getUid()), |
||
815 | $this->security->getUser()->getUid() |
||
816 | ); |
||
817 | |||
818 | $postponeOptions = $this->inputOptionListRepository->findOneByName($this->settings['postponeOptionListName']); |
||
819 | if ($postponeOptions) { |
||
820 | $this->view->assign('postponeOptions', $postponeOptions->getInputOptions()); |
||
821 | } |
||
822 | |||
823 | $discardOptions = $this->inputOptionListRepository->findOneByName($this->settings['discardOptionListName']); |
||
824 | if ($discardOptions) { |
||
825 | $this->view->assign('discardOptions', $discardOptions->getInputOptions()); |
||
826 | } |
||
827 | |||
828 | $mapper = $this->objectManager->get(DocumentMapper::class); |
||
829 | $documentForm = $mapper->getDocumentForm($document, false); |
||
830 | |||
831 | $documentTypes = [0 => '']; |
||
832 | foreach ($this->documentTypeRepository->getDocumentTypesAlphabetically() as $documentType) { |
||
833 | if (!$documentType->isHiddenInList()) { |
||
834 | $documentTypes[$documentType->getUid()] = $documentType->getDisplayName(); |
||
835 | } |
||
836 | } |
||
837 | |||
838 | $this->view->assign('documentTypes', $documentTypes); |
||
839 | |||
840 | $this->view->assign('documentForm', $documentForm); |
||
841 | |||
842 | $this->view->assign('document', $document); |
||
843 | } |
||
844 | |||
845 | |||
846 | public function cancelListTaskAction() |
||
847 | { |
||
848 | $this->redirectToDocumentList(); |
||
849 | } |
||
850 | |||
851 | /** |
||
852 | * action suggest restore |
||
853 | * |
||
854 | * @param Document $document |
||
855 | * @return void |
||
856 | */ |
||
857 | public function suggestRestoreAction(\EWW\Dpf\Domain\Model\Document $document) { |
||
858 | |||
859 | if (!$this->authorizationChecker->isGranted(DocumentVoter::SUGGEST_RESTORE, $document)) { |
||
860 | $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_suggestRestore.accessDenied'; |
||
861 | $this->flashMessage($document, $key, AbstractMessage::ERROR); |
||
862 | $this->redirect('showDetails', 'Document', null, ['document' => $document]); |
||
863 | return FALSE; |
||
864 | } |
||
865 | |||
866 | $this->view->assign('document', $document); |
||
867 | } |
||
868 | |||
869 | /** |
||
870 | * @param Document $document |
||
871 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
872 | */ |
||
873 | public function suggestModificationAction(\EWW\Dpf\Domain\Model\Document $document) { |
||
874 | |||
875 | $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SUGGEST_MODIFICATION, $document); |
||
876 | |||
877 | $documentMapper = $this->objectManager->get(DocumentMapper::class); |
||
878 | |||
879 | /* @var $newDocument \EWW\Dpf\Domain\Model\Document */ |
||
880 | $documentForm = $documentMapper->getDocumentForm($document); |
||
881 | |||
882 | $this->view->assign('suggestMod', true); |
||
883 | $this->forward('edit','DocumentFormBackoffice',NULL, ['documentForm' => $documentForm, 'suggestMod' => true]); |
||
884 | } |
||
885 | |||
886 | |||
887 | /** |
||
888 | * initializeAction |
||
889 | */ |
||
890 | public function initializeAction() |
||
912 | } |
||
913 | } |
||
914 | |||
915 | /** |
||
916 | * Redirect to the current document list. |
||
917 | * |
||
918 | * @param null $message |
||
919 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
920 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
921 | */ |
||
922 | protected function redirectToDocumentList($message = null) |
||
923 | { |
||
924 | list($action, $controller, $redirectUri) = $this->session->getStoredAction(); |
||
925 | |||
926 | if ($redirectUri) { |
||
927 | $this->redirectToUri($redirectUri); |
||
928 | } else { |
||
929 | $this->redirect($action, $controller); |
||
930 | } |
||
931 | } |
||
932 | |||
933 | /** |
||
934 | * Gets the storage PID of the current client |
||
935 | * |
||
936 | * @return mixed |
||
937 | */ |
||
938 | protected function getStoragePID() |
||
941 | } |
||
942 | |||
943 | /** |
||
944 | * Updates the document in combination with a state transition. |
||
945 | * |
||
946 | * @param Document $document |
||
947 | * @param $workflowTransition |
||
948 | * @param string $reason |
||
949 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException |
||
950 | * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException |
||
951 | */ |
||
952 | protected function updateDocument(\EWW\Dpf\Domain\Model\Document $document, $workflowTransition, $reason) |
||
1042 |