Passed
Pull Request — master (#195)
by
unknown
19:02
created

DocumentController::showSuggestionDetailsAction()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 17
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 31
rs 9.7
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\Document;
18
use EWW\Dpf\Domain\Model\DocumentType;
19
use EWW\Dpf\Security\DocumentVoter;
20
use EWW\Dpf\Security\Security;
21
use EWW\Dpf\Services\Transfer\DocumentTransferManager;
22
use EWW\Dpf\Services\Transfer\FedoraRepository;
23
use EWW\Dpf\Services\ProcessNumber\ProcessNumberGenerator;
24
use EWW\Dpf\Services\Email\Notifier;
25
use EWW\Dpf\Exceptions\DPFExceptionInterface;
26
use EWW\Dpf\Domain\Workflow\DocumentWorkflow;
27
use TYPO3\CMS\Core\Messaging\AbstractMessage;
28
use EWW\Dpf\Helper\DocumentMapper;
29
use EWW\Dpf\Domain\Model\File;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
32
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
33
34
35
/**
36
 * DocumentController
37
 */
38
class DocumentController extends AbstractController
39
{
40
41
    /**
42
     * documentRepository
43
     *
44
     * @var \EWW\Dpf\Domain\Repository\DocumentRepository
45
     * @inject
46
     */
47
    protected $documentRepository = null;
48
49
    /**
50
     * documentTypeRepository
51
     *
52
     * @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository
53
     * @inject
54
     */
55
    protected $documentTypeRepository = null;
56
57
    /**
58
     * inputOptionListRepository
59
     *
60
     * @var \EWW\Dpf\Domain\Repository\InputOptionListRepository
61
     * @inject
62
     */
63
    protected $inputOptionListRepository = null;
64
65
    /**
66
     * persistence manager
67
     *
68
     * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
69
     * @inject
70
     */
71
    protected $persistenceManager;
72
73
    /**
74
     * editingLockService
75
     *
76
     * @var \EWW\Dpf\Services\Document\EditingLockService
77
     * @inject
78
     */
79
    protected $editingLockService = null;
80
81
    /**
82
     * documentValidator
83
     *
84
     * @var \EWW\Dpf\Helper\DocumentValidator
85
     * @inject
86
     */
87
    protected $documentValidator;
88
89
    /**
90
     * depositLicenseLogRepository
91
     *
92
     * @var \EWW\Dpf\Domain\Repository\DepositLicenseLogRepository
93
     * @inject
94
     */
95
    protected $depositLicenseLogRepository = null;
96
97
    /**
98
     * workflow
99
     *
100
     * @var \EWW\Dpf\Domain\Workflow\DocumentWorkflow
101
     */
102
    protected $workflow;
103
104
    /**
105
     * documentTransferManager
106
     *
107
     * @var \EWW\Dpf\Services\Transfer\DocumentTransferManager $documentTransferManager
108
     */
109
    protected $documentTransferManager;
110
111
    /**
112
     * fedoraRepository
113
     *
114
     * @var \EWW\Dpf\Services\Transfer\FedoraRepository $fedoraRepository
115
     */
116
    protected $fedoraRepository;
117
118
    /**
119
     * fileRepository
120
     *
121
     * @var \EWW\Dpf\Domain\Repository\FileRepository
122
     * @inject
123
     */
124
    protected $fileRepository = null;
125
126
127
    /**
128
     * frontendUserRepository
129
     *
130
     * @var \EWW\Dpf\Domain\Repository\FrontendUserRepository
131
     * @inject
132
     */
133
    protected $frontendUserRepository = null;
134
135
    /**
136
     * documentManager
137
     *
138
     * @var \EWW\Dpf\Services\Document\DocumentManager
139
     * @inject
140
     */
141
    protected $documentManager = null;
142
143
    /**
144
     * bookmarkRepository
145
     *
146
     * @var \EWW\Dpf\Domain\Repository\BookmarkRepository
147
     * @inject
148
     */
149
    protected $bookmarkRepository = null;
150
151
    /**
152
     * DocumentController constructor.
153
     */
154
    public function __construct()
155
    {
156
        parent::__construct();
157
158
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
159
        $this->documentTransferManager = $objectManager->get(DocumentTransferManager::class);
160
        $this->fedoraRepository = $objectManager->get(FedoraRepository::class);
161
        $this->documentTransferManager->setRemoteRepository($this->fedoraRepository);
162
    }
163
164
    /**
165
     * action logout of the backoffice
166
     *
167
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
168
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
169
     */
170
    public function logoutAction()
171
    {
172
        $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
173
        $uri = $cObj->typolink_URL([
174
            'parameter' => $this->settings['loginPage'],
175
            //'linkAccessRestrictedPages' => 1,
176
            'forceAbsoluteUrl' => 1,
177
            'additionalParams' => GeneralUtility::implodeArrayForUrl(NULL, ['logintype'=>'logout'])
178
        ]);
179
180
        $this->redirectToUri($uri);
181
    }
182
183
    public function listSuggestionsAction() {
184
        $this->session->setStoredAction($this->getCurrentAction(), $this->getCurrentController());
185
186
        $documents = NULL;
187
        $isWorkspace = $this->security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN;
188
189
        if (
190
            $this->security->getUser()->getUserRole() == Security::ROLE_LIBRARIAN
191
        ) {
192
                $documents = $this->documentRepository->findAllDocumentSuggestions(
193
                    $this->security->getUser()->getUserRole(),
194
                    $this->security->getUser()->getUid()
195
                );
196
        }
197
198
        if ($this->request->hasArgument('message')) {
199
            $this->view->assign('message', $this->request->getArgument('message'));
200
        }
201
202
        if ($this->request->hasArgument('errorFiles')) {
203
            $this->view->assign('errorFiles', $this->request->getArgument('errorFiles'));
204
        }
205
206
        $this->view->assign('currentUser', $this->security->getUser());
207
        $this->view->assign('isWorkspace', $isWorkspace);
208
        $this->view->assign('documents', $documents);
209
    }
210
211
    /**
212
     * @param Document $document
213
     * @param bool $acceptAll
214
     */
215
    public function acceptSuggestionAction(\EWW\Dpf\Domain\Model\Document $document, bool $acceptAll = true) {
216
217
        /** @var DocumentMapper $documentMapper */
218
        $documentMapper = $this->objectManager->get(DocumentMapper::class);
219
220
        // Existing working copy?
221
        /** @var \EWW\Dpf\Domain\Model\Document $originDocument */
222
        $linkedUid = $document->getLinkedUid();
223
        $originDocument = $this->documentRepository->findWorkingCopy($linkedUid);
224
225
        if ($originDocument) {
0 ignored issues
show
introduced by
$originDocument is of type EWW\Dpf\Domain\Model\Document, thus it always evaluated to true.
Loading history...
226
            $linkedDocumentForm = $documentMapper->getDocumentForm($originDocument);
0 ignored issues
show
Unused Code introduced by
The assignment to $linkedDocumentForm is dead and can be removed.
Loading history...
227
        } else {
228
            // get remote document
229
            $originDocument = $this->documentTransferManager->retrieve($document->getLinkedUid(), $this->security->getUser()->getUid());
230
            $linkedDocumentForm = $documentMapper->getDocumentForm($originDocument);
231
        }
232
233
        if ($acceptAll) {
234
            // all changes are confirmed
235
            // copy suggest to origin document
236
            $originDocument->copy($document, true);
0 ignored issues
show
Unused Code introduced by
The call to EWW\Dpf\Domain\Model\Document::copy() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

236
            $originDocument->/** @scrutinizer ignore-call */ 
237
                             copy($document, true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
237
238
            if ($document->getRemoteState() != DocumentWorkflow::REMOTE_STATE_NONE) {
239
                if ($document->getLocalState() != DocumentWorkflow::LOCAL_STATE_IN_PROGRESS) {
240
                    $originDocument->setState(
241
                        DocumentWorkflow::constructState(DocumentWorkflow::LOCAL_STATE_IN_PROGRESS,
242
                        $document->getRemoteState())
243
                    );
244
                    $this->addFlashMessage(
245
                        LocalizationUtility::translate("message.suggestion_accepted.new_workingcopy_info", "dpf"),
246
                        '',
247
                        AbstractMessage::INFO
248
                    );
249
                }
250
            }
251
252
            if ($originDocument->getTransferStatus() == 'RESTORE') {
253
                if ($originDocument->getObjectIdentifier()) {
254
                    $originDocument->setState(DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE);
255
                } else {
256
                    $originDocument->setState(DocumentWorkflow::STATE_IN_PROGRESS_NONE);
257
                }
258
            }
259
260
            // copy files from suggest document
261
            foreach ($document->getFile() as $key => $file) {
262
                $newFile = $this->objectManager->get(File::class);
263
                $newFile->copy($file);
264
                $newFile->setDocument($originDocument);
265
                $this->fileRepository->add($newFile);
266
                $originDocument->addFile($newFile);
267
268
            }
269
270
            $this->documentRepository->update($originDocument);
271
            $this->documentRepository->remove($document);
272
273
            // Notify assigned users
274
            /** @var Notifier $notifier */
275
            $notifier = $this->objectManager->get(Notifier::class);
276
277
            $recipients = $this->documentManager->getUpdateNotificationRecipients($originDocument);
278
            $notifier->sendMyPublicationUpdateNotification($originDocument, $recipients);
279
280
            $recipients = $this->documentManager->getNewPublicationNotificationRecipients($originDocument);
281
            $notifier->sendMyPublicationNewNotification($originDocument, $recipients);
282
283
            $notifier->sendChangedDocumentNotification($originDocument);
284
285
            $notifier->sendSuggestionAcceptNotification($originDocument);
286
287
            // index the document
288
            $this->signalSlotDispatcher->dispatch(
289
                AbstractController::class, 'indexDocument', [$originDocument]
290
            );
291
292
            // redirect to document
293
            $this->redirect('showDetails', 'Document', null, ['document' => $originDocument]);
294
        }
295
296
        $this->redirectToDocumentList();
297
    }
298
299
300
    public function showSuggestionDetailsAction(\EWW\Dpf\Domain\Model\Document $document) {
301
        $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SHOW_DETAILS, $document);
302
303
        /** @var DocumentMapper $documentMapper */
304
        $documentMapper = $this->objectManager->get(DocumentMapper::class);
305
306
        $linkedUid = $document->getLinkedUid();
307
        $linkedDocument = $this->documentRepository->findWorkingCopy($linkedUid);
308
309
        if ($linkedDocument) {
310
            // Existing working copy
311
            $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument);
312
        } else {
313
            // No existing working copy, get remote document from fedora
314
            $linkedDocument = $this->documentTransferManager->retrieve($document->getLinkedUid(), $this->security->getUser()->getUid());
315
            $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument);
316
        }
317
318
        $newDocumentForm = $documentMapper->getDocumentForm($document);
319
        $diff = $this->documentFormDiff($linkedDocumentForm, $newDocumentForm);
320
321
        //$usernameString = $this->security->getUser()->getUsername();
322
        $user = $this->frontendUserRepository->findOneByUid($document->getCreator());
323
324
        if ($user) {
325
            $usernameString = $user->getUsername();
326
        }
327
328
        $this->view->assign('documentCreator', $usernameString);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $usernameString does not seem to be defined for all execution paths leading up to this point.
Loading history...
329
        $this->view->assign('diff', $diff);
330
        $this->view->assign('document', $document);
331
332
    }
333
334
    public function documentFormDiff($docForm1, $docForm2) {
335
        $returnArray = ['changed' => ['new' => [], 'old' => []], 'deleted' => [], 'added' => []];
336
337
        // pages
338
        foreach ($docForm1->getItems() as $keyPage => $valuePage) {
339
            foreach ($valuePage as $keyRepeatPage => $valueRepeatPage) {
340
341
                // groups
342
                foreach ($valueRepeatPage->getItems() as $keyGroup => $valueGroup) {
343
344
                    $checkFieldsForAdding = false;
345
                    $valueGroupCounter = count($valueGroup);
346
347
                    if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) {
348
                        $checkFieldsForAdding = true;
349
                    }
350
351
                    foreach ($valueGroup as $keyRepeatGroup => $valueRepeatGroup) {
352
353
                        // fields
354
                        foreach ($valueRepeatGroup->getItems() as $keyField => $valueField) {
355
                            foreach ($valueField as $keyRepeatField => $valueRepeatField) {
356
357
                                $fieldCounter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]);
358
                                $valueFieldCounter = count($valueField);
359
360
                                // check if group or field is not existing
361
                                $notExisting = false;
362
                                try {
363
                                    $flag = 'page';
364
                                    $value2 = $docForm2->getItems()[$keyPage];
365
                                    $flag = 'group';
366
                                    $value2 = $value2[$keyRepeatPage];
367
                                    $value2 = $value2->getItems()[$keyGroup];
368
                                    $value2 = $value2[$keyRepeatGroup]->getItems()[$keyField];
369
                                    $flag = 'field';
370
                                } catch (\Throwable $t) {
371
                                    $notExisting = true;
372
                                }
373
374
                                $item = NULL;
0 ignored issues
show
Unused Code introduced by
The assignment to $item is dead and can be removed.
Loading history...
375
                                if ($flag == 'group') {
376
                                    $itemExisting = $valueRepeatGroup;
377
                                    $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup];
378
                                } else if ($flag == 'field') {
379
                                    $itemExisting = $valueRepeatField;
380
                                    $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$keyRepeatField];
381
                                }
382
383
                                if ($notExisting || ($valueRepeatField->getValue() != $value2[$keyRepeatField]->getValue() && empty($value2[$keyRepeatField]->getValue()))) {
384
                                    // deleted
385
                                    $returnArray['deleted'][] = $itemExisting;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $itemExisting does not seem to be defined for all execution paths leading up to this point.
Loading history...
386
387
                                } else if ($this->removeControlCharacterFromString($valueRepeatField->getValue()) != $this->removeControlCharacterFromString($value2[$keyRepeatField]->getValue())
388
                                    && !empty($value2[$keyRepeatField]->getValue())) {
389
390
                                    // changed
391
                                    $returnArray['changed']['old'][] = $itemExisting;
392
                                    $returnArray['changed']['new'][] = $itemNew;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $itemNew does not seem to be defined for all execution paths leading up to this point.
Loading history...
393
                                    $returnArray['changed']['groupDisplayName'] = $valueRepeatGroup->getDisplayName();
394
                                }
395
396
                                if ($flag == 'group') {
397
                                    break 2;
398
                                }
399
                            }
400
401
                            // check if new document form has more field items as the existing form
402
                            if ($valueFieldCounter < $fieldCounter && !$checkFieldsForAdding) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $valueFieldCounter does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $fieldCounter does not seem to be defined for all execution paths leading up to this point.
Loading history...
403
                                // field added
404
                                for ($i = count($valueField); $i < $fieldCounter;$i++) {
405
                                    $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$i];
406
407
                                }
408
                            }
409
                        }
410
                    }
411
412
                    // check if new document form has more group items as the existing form
413
                    if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) {
414
                        // group added
415
                        $counter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]);
416
                        for ($i = $valueGroupCounter; $i < $counter;$i++) {
417
                            $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$i];
418
                        }
419
                    }
420
                }
421
            }
422
423
        }
424
425
        return $returnArray;
426
427
    }
428
429
    public function removeControlCharacterFromString($string) {
430
        return preg_replace('/\p{C}+/u', "", $string);
431
    }
432
433
    /**
434
     * action discard
435
     *
436
     * @param \EWW\Dpf\Domain\Model\Document $document
437
     * @param integer $tstamp
438
     * @param string $reason
439
     * @return void
440
     */
441
    public function discardAction(Document $document, $tstamp, $reason = NULL)
0 ignored issues
show
Unused Code introduced by
The parameter $tstamp is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

441
    public function discardAction(Document $document, /** @scrutinizer ignore-unused */ $tstamp, $reason = NULL)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
442
    {
443
        if (!$this->authorizationChecker->isGranted(DocumentVoter::DISCARD, $document)) {
444
            if (
445
                $this->editingLockService->isLocked(
446
                    $document->getDocumentIdentifier(),
447
                    $this->security->getUser()->getUid()
448
                )
449
            ) {
450
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.failureBlocked';
451
            } else {
452
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.accessDenied';
453
            }
454
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
455
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
456
            return FALSE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return FALSE returns the type false which is incompatible with the documented return type void.
Loading history...
457
        }
458
459
        $this->updateDocument($document, DocumentWorkflow::TRANSITION_DISCARD, $reason);
460
    }
461
462
    /**
463
     * action postpone
464
     *
465
     * @param \EWW\Dpf\Domain\Model\Document $document
466
     * @param integer $tstamp
467
     * @param string $reason
468
     * @return void
469
     */
470
    public function postponeAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = NULL)
0 ignored issues
show
Unused Code introduced by
The parameter $tstamp is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

470
    public function postponeAction(\EWW\Dpf\Domain\Model\Document $document, /** @scrutinizer ignore-unused */ $tstamp, $reason = NULL)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
471
    {
472
        if (!$this->authorizationChecker->isGranted(DocumentVoter::POSTPONE, $document)) {
473
            if (
474
                $this->editingLockService->isLocked(
475
                    $document->getDocumentIdentifier(),
476
                    $this->security->getUser()->getUid()
477
                )
478
            ) {
479
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.failureBlocked';
480
            } else {
481
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.accessDenied';
482
            }
483
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
484
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
485
            return FALSE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return FALSE returns the type false which is incompatible with the documented return type void.
Loading history...
486
        }
487
488
        $this->updateDocument($document, DocumentWorkflow::TRANSITION_POSTPONE, $reason);
489
490
    }
491
492
493
    /**
494
     * action change document type
495
     *
496
     * @param \EWW\Dpf\Domain\Model\Document $document
497
     * @param int $documentTypeUid
498
     * @return void
499
     */
500
    public function changeDocumentTypeAction(\EWW\Dpf\Domain\Model\Document $document, $documentTypeUid = 0)
501
    {
502
        if (!$this->authorizationChecker->isGranted(DocumentVoter::UPDATE, $document)) {
503
            if (
504
            $this->editingLockService->isLocked(
505
                $document->getDocumentIdentifier(),
506
                $this->security->getUser()->getUid()
507
            )
508
            ) {
509
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failureBlocked';
510
            } else {
511
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.accessDenied';
512
            }
513
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
514
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
515
            return FALSE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return FALSE returns the type false which is incompatible with the documented return type void.
Loading history...
516
        }
517
518
519
        $documentType = $this->documentTypeRepository->findByUid($documentTypeUid);
520
521
        if ($documentType instanceof DocumentType) {
522
            $document->setDocumentType($documentType);
523
524
            $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData());
525
            $internalFormat->setDocumentType($documentType->getName());
526
            $document->setXmlData($internalFormat->getXml());
527
528
            $this->updateDocument($document, '', null);
529
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
530
        } else {
531
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failure';
532
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
533
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
534
            return FALSE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return FALSE returns the type false which is incompatible with the documented return type void.
Loading history...
535
        }
536
    }
537
538
539
    /**
540
     * action deleteLocallyAction
541
     *
542
     * @param Document $document
543
     * @param integer $tstamp
544
     * @return void
545
     */
546
    public function deleteLocallyAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp)
547
    {
548
        if (empty($document->getObjectIdentifier()) || $document->isSuggestion()) {
549
            $voterAttribute = DocumentVoter::DELETE_LOCALLY;
550
        } else {
551
            $voterAttribute = DocumentVoter::DELETE_WORKING_COPY;
552
        }
553
554
        if (!$this->authorizationChecker->isGranted($voterAttribute, $document)) {
555
            if (
556
                $this->editingLockService->isLocked(
557
                    $document->getDocumentIdentifier(),
558
                    $this->security->getUser()->getUid()
559
                )
560
            ) {
561
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureBlocked';
562
            } else {
563
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.accessDenied';
564
            }
565
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
566
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
567
            return FALSE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return FALSE returns the type false which is incompatible with the documented return type void.
Loading history...
568
        }
569
570
        if ($tstamp === $document->getTstamp()) {
571
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.success';
572
            $this->flashMessage($document, $key, AbstractMessage::OK);
573
            $this->documentRepository->remove($document);
574
575
            if ($document->isWorkingCopy() || $document->isTemporaryCopy()) {
576
577
                if ($document->isWorkingCopy()) {
578
                    if ($this->bookmarkRepository->removeBookmark($document, $this->security->getUser()->getUid())) {
579
                        $this->addFlashMessage(
580
                            LocalizationUtility::translate("manager.workspace.bookmarkRemoved.singular", "dpf"), '',
581
                            AbstractMessage::INFO
582
                        );
583
                    }
584
                }
585
586
                $this->persistenceManager->persistAll();
587
                $document = $this->documentManager->read($document->getDocumentIdentifier());
588
589
                // index the document
590
                $this->signalSlotDispatcher->dispatch(
591
                    \EWW\Dpf\Controller\AbstractController::class,
592
                    'indexDocument', [$document]
593
                );
594
595
                $this->documentRepository->remove($document);
596
597
            } elseif (!$document->isSuggestion()) {
598
                $this->bookmarkRepository->removeBookmark($document, $this->security->getUser()->getUid());
599
                // delete document from index
600
                $this->signalSlotDispatcher->dispatch(
601
                    \EWW\Dpf\Controller\AbstractController::class,
602
                    'deleteDocumentFromIndex', [$document->getDocumentIdentifier()]
603
                );
604
            }
605
606
            $suggestions = $this->documentRepository->findByLinkedUid($document->getDocumentIdentifier());
0 ignored issues
show
Bug introduced by
The method findByLinkedUid() does not exist on EWW\Dpf\Domain\Repository\DocumentRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

606
            /** @scrutinizer ignore-call */ 
607
            $suggestions = $this->documentRepository->findByLinkedUid($document->getDocumentIdentifier());
Loading history...
607
            foreach ($suggestions as $suggestion) {
608
                $this->documentRepository->remove($suggestion);
609
            }
610
611
            /** @var Notifier $notifier */
612
            $notifier = $this->objectManager->get(Notifier::class);
613
            $notifier->sendSuggestionDeclineNotification($document);
614
615
            $this->redirectToDocumentList();
616
        } else {
617
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureNewVersion';
618
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
619
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
620
        }
621
    }
622
623
624
    /**
625
     * @param Document $document
626
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
627
     */
628
    public function duplicateAction(\EWW\Dpf\Domain\Model\Document $document)
629
    {
630
        if (!$this->authorizationChecker->isGranted(DocumentVoter::DUPLICATE, $document)) {
631
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_duplicate.accessDenied';
632
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
633
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
634
            return FALSE;
635
        }
636
637
        /* @var $newDocument \EWW\Dpf\Domain\Model\Document */
638
        $newDocument = $this->objectManager->get(Document::class);
639
640
        $newDocument->setState(DocumentWorkflow::STATE_NEW_NONE);
641
642
        $copyTitle = LocalizationUtility::translate("manager.workspace.title.copy", "dpf").$document->getTitle();
643
644
        $newDocument->setTitle($copyTitle);
645
646
        $newDocument->setAuthors($document->getAuthors());
647
648
        $newDocument->setCreator($this->security->getUser()->getUid());
649
650
        $newDocument->setDocumentType($document->getDocumentType());
651
652
        $processNumberGenerator = $this->objectManager->get(ProcessNumberGenerator::class);
653
        $processNumber = $processNumberGenerator->getProcessNumber();
654
        $newDocument->setProcessNumber($processNumber);
655
656
        $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData());
657
        $internalFormat->clearAllUrn();
658
        $internalFormat->setDateIssued('');
659
        $internalFormat->setTitle($copyTitle);
660
        $internalFormat->setProcessNumber($processNumber);
661
662
        $newDocument->setXmlData($internalFormat->getXml());
663
664
        $documentMapper = $this->objectManager->get(DocumentMapper::class);
665
666
        /** @var $documentForm \EWW\Dpf\Domain\Model\DocumentForm */
667
        $newDocumentForm = $documentMapper->getDocumentForm($newDocument);
668
669
        $this->forward(
670
            'new',
671
            'DocumentFormBackoffice',
672
            NULL,
673
            ['newDocumentForm' => $newDocumentForm, 'returnDocumentId' => $document->getUid()]
674
        );
675
676
    }
677
678
    /**
679
     * releasePublishAction
680
     *
681
     * @param \EWW\Dpf\Domain\Model\Document $document
682
     * @param integer $tstamp
683
     * @return void
684
     */
685
    public function releasePublishAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp)
0 ignored issues
show
Unused Code introduced by
The parameter $tstamp is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

685
    public function releasePublishAction(\EWW\Dpf\Domain\Model\Document $document, /** @scrutinizer ignore-unused */ $tstamp)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
686
    {
687
        if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_PUBLISH, $document)) {
688
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_ingest.accessDenied';
689
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
690
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
691
            return FALSE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return FALSE returns the type false which is incompatible with the documented return type void.
Loading history...
692
        }
693
        
694
        $this->updateDocument($document, DocumentWorkflow::TRANSITION_RELEASE_PUBLISH, null);
695
        
696
    }
697
    
698
    
699
    /**
700
     * releaseActivateAction
701
     *
702
     * @param \EWW\Dpf\Domain\Model\Document $document
703
     * @param integer $tstamp
704
     * @return void
705
     */
706
    public function releaseActivateAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp)
0 ignored issues
show
Unused Code introduced by
The parameter $tstamp is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

706
    public function releaseActivateAction(\EWW\Dpf\Domain\Model\Document $document, /** @scrutinizer ignore-unused */ $tstamp)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
707
    {
708
        if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_ACTIVATE, $document)) {
709
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_activate.accessDenied';
710
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
711
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
712
            return FALSE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return FALSE returns the type false which is incompatible with the documented return type void.
Loading history...
713
        }
714
        
715
        $this->updateDocument($document, DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE, null);
716
        
717
    }
718
    
719
    /**
720
     * action register
721
     *
722
     * @param \EWW\Dpf\Domain\Model\Document $document
723
     * @return void
724
     */
725
    public function registerAction(\EWW\Dpf\Domain\Model\Document $document)
726
    {
727
        if (!$this->authorizationChecker->isGranted(DocumentVoter::REGISTER, $document)) {
728
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.accessDenied';
729
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
730
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
731
        }
732
733
        if (!$this->documentValidator->validate($document, false)) {
734
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.missingValues';
735
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
736
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
737
        }
738
739
        $this->workflow->apply($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_REGISTER);
0 ignored issues
show
Bug introduced by
The method apply() does not exist on EWW\Dpf\Domain\Workflow\DocumentWorkflow. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

739
        $this->workflow->/** @scrutinizer ignore-call */ 
740
                         apply($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_REGISTER);

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.

Loading history...
740
        $this->documentRepository->update($document);
741
742
743
        if ($this->security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN) {
744
            $this->bookmarkRepository->addBookmark($document, $this->security->getUser()->getUid());
745
        }
746
747
        // admin register notification
748
        $notifier = $this->objectManager->get(Notifier::class);
749
        $notifier->sendRegisterNotification($document);
750
751
        // index the document
752
        $this->signalSlotDispatcher->dispatch(\EWW\Dpf\Controller\AbstractController::class, 'indexDocument', [$document]);
753
754
        // document updated notification
755
        $recipients = $this->documentManager->getUpdateNotificationRecipients($document);
756
        $notifier->sendMyPublicationUpdateNotification($document, $recipients);
757
758
        $recipients = $this->documentManager->getNewPublicationNotificationRecipients($document);
759
        $notifier->sendMyPublicationNewNotification($document, $recipients);
760
761
        $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.success';
762
        $this->flashMessage($document, $key, AbstractMessage::OK);
763
        $this->redirect('showDetails', 'Document', null, ['document' => $document]);
764
    }
765
766
    /**
767
     * action showDetails
768
     *
769
     * @param \EWW\Dpf\Domain\Model\Document $document
770
     * @return void
771
     */
772
    public function showDetailsAction(Document $document)
773
    {
774
        if (!$this->authorizationChecker->isGranted(DocumentVoter::SHOW_DETAILS, $document)) {
775
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_showDetails.accessDenied';
776
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
777
            $this->redirectToDocumentList();
778
        }
779
780
        $this->editingLockService->lock(
781
            ($document->getObjectIdentifier()? $document->getObjectIdentifier() : $document->getUid()),
782
            $this->security->getUser()->getUid()
783
        );
784
785
        $postponeOptions = $this->inputOptionListRepository->findOneByName($this->settings['postponeOptionListName']);
0 ignored issues
show
Bug introduced by
The method findOneByName() does not exist on EWW\Dpf\Domain\Repositor...putOptionListRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

785
        /** @scrutinizer ignore-call */ 
786
        $postponeOptions = $this->inputOptionListRepository->findOneByName($this->settings['postponeOptionListName']);
Loading history...
786
        if ($postponeOptions) {
787
            $this->view->assign('postponeOptions', $postponeOptions->getInputOptions());
0 ignored issues
show
Bug introduced by
The method getInputOptions() does not exist on TYPO3\CMS\Extbase\Persistence\QueryResultInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

787
            $this->view->assign('postponeOptions', $postponeOptions->/** @scrutinizer ignore-call */ getInputOptions());

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.

Loading history...
788
        }
789
790
        $discardOptions = $this->inputOptionListRepository->findOneByName($this->settings['discardOptionListName']);
791
        if ($discardOptions) {
792
            $this->view->assign('discardOptions', $discardOptions->getInputOptions());
793
        }
794
795
        $mapper = $this->objectManager->get(DocumentMapper::class);
796
        $documentForm = $mapper->getDocumentForm($document, false);
797
798
        $documentTypes = [0 => ''];
799
        foreach ($this->documentTypeRepository->getDocumentTypesAlphabetically() as $documentType) {
800
            $documentTypes[$documentType->getUid()] = $documentType->getDisplayName();
801
        }
802
803
        $this->view->assign('documentTypes', $documentTypes);
804
805
        $this->view->assign('documentForm', $documentForm);
806
807
        $this->view->assign('document', $document);
808
    }
809
810
811
    public function cancelListTaskAction()
812
    {
813
        $this->redirectToDocumentList();
814
    }
815
    
816
    /**
817
     * action suggest restore
818
     *
819
     * @param Document $document
820
     * @return void
821
     */
822
    public function suggestRestoreAction(\EWW\Dpf\Domain\Model\Document $document) {
823
824
        if (!$this->authorizationChecker->isGranted(DocumentVoter::SUGGEST_RESTORE, $document)) {
825
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_suggestRestore.accessDenied';
826
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
827
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
828
            return FALSE;
0 ignored issues
show
Bug Best Practice introduced by
The expression return FALSE returns the type false which is incompatible with the documented return type void.
Loading history...
829
        }
830
831
        $this->view->assign('document', $document);
832
    }
833
834
    /**
835
     * @param Document $document
836
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
837
     */
838
    public function suggestModificationAction(\EWW\Dpf\Domain\Model\Document $document) {
839
840
        $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SUGGEST_MODIFICATION, $document);
841
842
        $documentMapper = $this->objectManager->get(DocumentMapper::class);
843
844
        /* @var $newDocument \EWW\Dpf\Domain\Model\Document */
845
        $documentForm = $documentMapper->getDocumentForm($document);
846
847
        $this->view->assign('suggestMod', true);
848
        $this->forward('edit','DocumentFormBackoffice',NULL, ['documentForm' => $documentForm, 'suggestMod' => true]);
849
    }
850
851
852
    /**
853
     * initializeAction
854
     */
855
    public function initializeAction()
856
    {
857
        $this->authorizationChecker->denyAccessUnlessLoggedIn();
858
859
        parent::initializeAction();
860
861
        $this->workflow = $this->objectManager->get(DocumentWorkflow::class)->getWorkflow();
862
863
        if ($this->request->hasArgument('document')) {
864
            $document = $this->request->getArgument('document');
865
866
            if (is_array($document) && key_exists("__identity", $document)) {
867
                $document = $document["__identity"];
868
            }
869
870
            $document = $this->documentManager->read($document, $this->security->getUser()->getUID());
871
872
            if (!$document) {
873
                $this->redirectToDocumentList();
874
            }
875
876
            $this->request->setArgument('document', $document);
877
        }
878
    }
879
880
    /**
881
     * Redirect to the current document list.
882
     *
883
     * @param null $message
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $message is correct as it would always require null to be passed?
Loading history...
884
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
885
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
886
     */
887
    protected function redirectToDocumentList($message = null)
0 ignored issues
show
Unused Code introduced by
The parameter $message is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

887
    protected function redirectToDocumentList(/** @scrutinizer ignore-unused */ $message = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
888
    {
889
        list($action, $controller, $redirectUri) = $this->session->getStoredAction();
890
891
        if ($redirectUri) {
892
            $this->redirectToUri($redirectUri);
893
        } else {
894
            $this->redirect($action, $controller);
895
        }
896
    }
897
898
    /**
899
     * Gets the storage PID of the current client
900
     *
901
     * @return mixed
902
     */
903
    protected function getStoragePID()
904
    {
905
        return $this->settings['persistence']['classes']['EWW\Dpf\Domain\Model\Document']['newRecordStoragePid'];
906
    }
907
908
    /**
909
     *
910
     * @param \EWW\Dpf\Domain\Model\Document $document
911
     * @param string $key
912
     * @param string $severity
913
     * @param string $defaultMessage
914
     */
915
    protected function flashMessage(\EWW\Dpf\Domain\Model\Document $document, $key, $severity, $defaultMessage = "")
916
    {
917
        // Show success or failure of the action in a flash message
918
        if ($document) {
0 ignored issues
show
introduced by
$document is of type EWW\Dpf\Domain\Model\Document, thus it always evaluated to true.
Loading history...
919
            $args[] = $document->getTitle();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$args was never initialized. Although not strictly required by PHP, it is generally a good practice to add $args = array(); before regardless.
Loading history...
920
            $args[] = $document->getObjectIdentifier();
921
        }
922
923
        $message = LocalizationUtility::translate($key, 'dpf', $args);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $args does not seem to be defined for all execution paths leading up to this point.
Loading history...
924
        $message = empty($message) ? $defaultMessage : $message;
925
926
        $this->addFlashMessage(
927
            $message,
928
            '',
929
            $severity,
0 ignored issues
show
Bug introduced by
$severity of type string is incompatible with the type integer expected by parameter $severity of TYPO3\CMS\Extbase\Mvc\Co...ller::addFlashMessage(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

929
            /** @scrutinizer ignore-type */ $severity,
Loading history...
930
            true
931
        );
932
    }
933
934
    /**
935
     * Updates the document in combination with a state transition.
936
     *
937
     * @param Document $document
938
     * @param $workflowTransition
939
     * @param string $reason
940
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
941
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
942
     */
943
    protected function updateDocument(\EWW\Dpf\Domain\Model\Document $document, $workflowTransition, $reason)
944
    {
945
        switch ($workflowTransition) {
946
            case DocumentWorkflow::TRANSITION_DISCARD:
947
                $messageKeyPart = 'document_discard';
948
                break;
949
            case DocumentWorkflow::TRANSITION_POSTPONE:
950
                $messageKeyPart = 'document_postpone';
951
                break;
952
            case DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE:
953
                $messageKeyPart = 'document_activate';
954
                break;
955
            case DocumentWorkflow::TRANSITION_RELEASE_PUBLISH:
956
                $messageKeyPart = 'document_ingest';
957
                break;
958
            default:
959
                $messageKeyPart = "document_update";
960
                break;
961
        }
962
963
        try {
964
            if ($reason) {
965
                $timezone = new \DateTimeZone($this->settings['timezone']);
966
                $timeStamp = (new \DateTime('now', $timezone))->format("d.m.Y H:i:s");
967
968
                if ($workflowTransition == DocumentWorkflow::TRANSITION_DISCARD) {
969
                    $note = LocalizationUtility::translate(
970
                        "manager.document.discard.note", "dpf", [$timeStamp, $reason]
971
                    );
972
                } elseif ($workflowTransition == DocumentWorkflow::TRANSITION_POSTPONE) {
973
                    $note = LocalizationUtility::translate(
974
                        "manager.document.postpone.note", "dpf", [$timeStamp, $reason]
975
                    );
976
                }
977
978
                $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData());
979
                $internalFormat->addNote($note);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $note does not seem to be defined for all execution paths leading up to this point.
Loading history...
980
                $document->setXmlData($internalFormat->getXml());
981
            }
982
983
            if ($this->documentManager->update($document, $workflowTransition)) {
984
985
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:'.$messageKeyPart.'.success';
986
                $this->flashMessage($document, $key, AbstractMessage::OK);
987
988
                if ($this->security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN) {
989
                    switch ($document->getState()) {
990
                        case DocumentWorkflow::STATE_POSTPONED_NONE:
991
                        case DocumentWorkflow::STATE_DISCARDED_NONE:
992
                        case DocumentWorkflow::STATE_NONE_INACTIVE:
993
                        case DocumentWorkflow::STATE_NONE_ACTIVE:
994
                        case DocumentWorkflow::STATE_NONE_DELETED:
995
996
                            if (
997
                                $this->bookmarkRepository->removeBookmark(
998
                                    $document,
999
                                    $this->security->getUser()->getUid()
1000
                                )
1001
                            ) {
1002
                                $this->addFlashMessage(
1003
                                    LocalizationUtility::translate("manager.workspace.bookmarkRemoved.singular", "dpf"), '',
1004
                                    AbstractMessage::INFO
1005
                                );
1006
                            }
1007
1008
                            break;
1009
                    }
1010
                }
1011
1012
                $this->redirectToDocumentList();
1013
            } else {
1014
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:'.$messageKeyPart.'.failure';
1015
                $this->flashMessage($document, $key, AbstractMessage::ERROR);
1016
                $this->redirect('showDetails', 'Document', NULL, ['document' => $document]);
1017
            }
1018
        } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $e) {
1019
            // A redirect always throws this exception, but in this case, however,
1020
            // redirection is desired and should not lead to an exception handling
1021
        } catch (\Exception $exception) {
1022
            if ($exception instanceof DPFExceptionInterface) {
1023
                $key = $exception->messageLanguageKey();
1024
            } else {
1025
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:'.$messageKeyPart.'.failure';
1026
            }
1027
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
1028
            $this->redirectToDocumentList();
1029
        }
1030
1031
    }
1032
}
1033