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

DocumentController::postponeAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
c 0
b 0
f 0
nc 3
nop 3
dl 0
loc 19
rs 9.8666
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
            $mods = new \EWW\Dpf\Helper\Mods($document->getXmlData());
270
            $originDocument->setAuthors($mods->getPersons());
271
            $this->documentRepository->update($originDocument);
272
            $this->documentRepository->remove($document);
273
274
            // Notify assigned users
275
            /** @var Notifier $notifier */
276
            $notifier = $this->objectManager->get(Notifier::class);
277
278
            $recipients = $this->documentManager->getUpdateNotificationRecipients($originDocument);
279
            $notifier->sendMyPublicationUpdateNotification($originDocument, $recipients);
280
281
            $recipients = $this->documentManager->getNewPublicationNotificationRecipients($originDocument);
282
            $notifier->sendMyPublicationNewNotification($originDocument, $recipients);
283
284
            $notifier->sendChangedDocumentNotification($originDocument);
285
286
            $notifier->sendSuggestionAcceptNotification($originDocument);
287
288
            // index the document
289
            $this->signalSlotDispatcher->dispatch(
290
                AbstractController::class, 'indexDocument', [$originDocument]
291
            );
292
293
            // redirect to document
294
            $this->redirect('showDetails', 'Document', null, ['document' => $originDocument]);
295
        }
296
297
        $this->redirectToDocumentList();
298
    }
299
300
301
    public function showSuggestionDetailsAction(\EWW\Dpf\Domain\Model\Document $document) {
302
        $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SHOW_DETAILS, $document);
303
304
        /** @var DocumentMapper $documentMapper */
305
        $documentMapper = $this->objectManager->get(DocumentMapper::class);
306
307
        $linkedUid = $document->getLinkedUid();
308
        $linkedDocument = $this->documentRepository->findWorkingCopy($linkedUid);
309
310
        if ($linkedDocument) {
311
            // Existing working copy
312
            $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument);
313
        } else {
314
            // No existing working copy, get remote document from fedora
315
            $linkedDocument = $this->documentTransferManager->retrieve($document->getLinkedUid(), $this->security->getUser()->getUid());
316
            $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument);
317
        }
318
319
        $newDocumentForm = $documentMapper->getDocumentForm($document);
320
        $diff = $this->documentFormDiff($linkedDocumentForm, $newDocumentForm);
321
322
        //$usernameString = $this->security->getUser()->getUsername();
323
        $user = $this->frontendUserRepository->findOneByUid($document->getCreator());
324
325
        if ($user) {
326
            $usernameString = $user->getUsername();
327
        }
328
329
        $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...
330
        $this->view->assign('diff', $diff);
331
        $this->view->assign('document', $document);
332
333
    }
334
335
    public function documentFormDiff($docForm1, $docForm2) {
336
        $returnArray = ['changed' => ['new' => [], 'old' => []], 'deleted' => [], 'added' => []];
337
338
        // pages
339
        foreach ($docForm1->getItems() as $keyPage => $valuePage) {
340
            foreach ($valuePage as $keyRepeatPage => $valueRepeatPage) {
341
342
                // groups
343
                foreach ($valueRepeatPage->getItems() as $keyGroup => $valueGroup) {
344
345
                    $checkFieldsForAdding = false;
346
                    $valueGroupCounter = count($valueGroup);
347
348
                    if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) {
349
                        $checkFieldsForAdding = true;
350
                    }
351
352
                    foreach ($valueGroup as $keyRepeatGroup => $valueRepeatGroup) {
353
354
                        // fields
355
                        foreach ($valueRepeatGroup->getItems() as $keyField => $valueField) {
356
                            foreach ($valueField as $keyRepeatField => $valueRepeatField) {
357
358
                                $fieldCounter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]);
359
                                $valueFieldCounter = count($valueField);
360
361
                                // check if group or field is not existing
362
                                $notExisting = false;
363
                                try {
364
                                    $flag = 'page';
365
                                    $value2 = $docForm2->getItems()[$keyPage];
366
                                    $flag = 'group';
367
                                    $value2 = $value2[$keyRepeatPage];
368
                                    $value2 = $value2->getItems()[$keyGroup];
369
                                    $value2 = $value2[$keyRepeatGroup]->getItems()[$keyField];
370
                                    $flag = 'field';
371
                                } catch (\Throwable $t) {
372
                                    $notExisting = true;
373
                                }
374
375
                                $item = NULL;
0 ignored issues
show
Unused Code introduced by
The assignment to $item is dead and can be removed.
Loading history...
376
                                if ($flag == 'group') {
377
                                    $itemExisting = $valueRepeatGroup;
378
                                    $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup];
379
                                } else if ($flag == 'field') {
380
                                    $itemExisting = $valueRepeatField;
381
                                    $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$keyRepeatField];
382
                                }
383
384
                                if ($notExisting || ($valueRepeatField->getValue() != $value2[$keyRepeatField]->getValue() && empty($value2[$keyRepeatField]->getValue()))) {
385
                                    // deleted
386
                                    $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...
387
388
                                } else if ($this->removeControlCharacterFromString($valueRepeatField->getValue()) != $this->removeControlCharacterFromString($value2[$keyRepeatField]->getValue())
389
                                    && !empty($value2[$keyRepeatField]->getValue())) {
390
391
                                    // changed
392
                                    $returnArray['changed']['old'][] = $itemExisting;
393
                                    $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...
394
                                    $returnArray['changed']['groupDisplayName'] = $valueRepeatGroup->getDisplayName();
395
                                }
396
397
                                if ($flag == 'group') {
398
                                    break 2;
399
                                }
400
                            }
401
402
                            // check if new document form has more field items as the existing form
403
                            if ($valueFieldCounter < $fieldCounter && !$checkFieldsForAdding) {
0 ignored issues
show
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...
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...
404
                                // field added
405
                                for ($i = count($valueField); $i < $fieldCounter;$i++) {
406
                                    $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$i];
407
408
                                }
409
                            }
410
                        }
411
                    }
412
413
                    // check if new document form has more group items as the existing form
414
                    if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) {
415
                        // group added
416
                        $counter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]);
417
                        for ($i = $valueGroupCounter; $i < $counter;$i++) {
418
                            $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$i];
419
                        }
420
                    }
421
                }
422
            }
423
424
        }
425
426
        return $returnArray;
427
428
    }
429
430
    public function removeControlCharacterFromString($string) {
431
        return preg_replace('/\p{C}+/u', "", $string);
432
    }
433
434
    /**
435
     * action discard
436
     *
437
     * @param \EWW\Dpf\Domain\Model\Document $document
438
     * @param integer $tstamp
439
     * @param string $reason
440
     * @return void
441
     */
442
    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

442
    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...
443
    {
444
        if (!$this->authorizationChecker->isGranted(DocumentVoter::DISCARD, $document)) {
445
            if (
446
                $this->editingLockService->isLocked(
447
                    $document->getDocumentIdentifier(),
448
                    $this->security->getUser()->getUid()
449
                )
450
            ) {
451
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.failureBlocked';
452
            } else {
453
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.accessDenied';
454
            }
455
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
456
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
457
            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...
458
        }
459
460
        $this->updateDocument($document, DocumentWorkflow::TRANSITION_DISCARD, $reason);
461
    }
462
463
    /**
464
     * action postpone
465
     *
466
     * @param \EWW\Dpf\Domain\Model\Document $document
467
     * @param integer $tstamp
468
     * @param string $reason
469
     * @return void
470
     */
471
    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

471
    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...
472
    {
473
        if (!$this->authorizationChecker->isGranted(DocumentVoter::POSTPONE, $document)) {
474
            if (
475
                $this->editingLockService->isLocked(
476
                    $document->getDocumentIdentifier(),
477
                    $this->security->getUser()->getUid()
478
                )
479
            ) {
480
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.failureBlocked';
481
            } else {
482
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.accessDenied';
483
            }
484
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
485
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
486
            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...
487
        }
488
489
        $this->updateDocument($document, DocumentWorkflow::TRANSITION_POSTPONE, $reason);
490
491
    }
492
493
494
    /**
495
     * action change document type
496
     *
497
     * @param \EWW\Dpf\Domain\Model\Document $document
498
     * @param int $documentTypeUid
499
     * @return void
500
     */
501
    public function changeDocumentTypeAction(\EWW\Dpf\Domain\Model\Document $document, $documentTypeUid = 0)
502
    {
503
        if (!$this->authorizationChecker->isGranted(DocumentVoter::UPDATE, $document)) {
504
            if (
505
            $this->editingLockService->isLocked(
506
                $document->getDocumentIdentifier(),
507
                $this->security->getUser()->getUid()
508
            )
509
            ) {
510
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failureBlocked';
511
            } else {
512
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.accessDenied';
513
            }
514
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
515
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
516
            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...
517
        }
518
519
520
        $documentType = $this->documentTypeRepository->findByUid($documentTypeUid);
521
522
        if ($documentType instanceof DocumentType) {
523
            $document->setDocumentType($documentType);
524
525
            $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData());
526
            $internalFormat->setDocumentType($documentType->getName());
527
            $document->setXmlData($internalFormat->getXml());
528
529
            $this->updateDocument($document, '', null);
530
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
531
        } else {
532
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failure';
533
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
534
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
535
            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...
536
        }
537
    }
538
539
    /**
540
     * action deleteLocallySuggestionAction
541
     *
542
     * @param Document $document
543
     * @param integer $tstamp
544
     * @param string $reason
545
     * @return void
546
     */
547
    public function deleteLocallySuggestionAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = "")
548
    {
549
        $this->redirect(
550
            'deleteLocally',
551
            'Document',
552
            null,
553
            [
554
                'document' => $document,
555
                'tstamp' => $tstamp,
556
                'reason' => $reason
557
            ]
558
        );
559
    }
560
561
562
    /**
563
     * action deleteLocallyAction
564
     *
565
     * @param Document $document
566
     * @param integer $tstamp
567
     * @param string $reason
568
     * @return void
569
     */
570
    public function deleteLocallyAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = "")
571
    {
572
        if (empty($document->getObjectIdentifier()) || $document->isSuggestion()) {
573
            $voterAttribute = DocumentVoter::DELETE_LOCALLY;
574
        } else {
575
            $voterAttribute = DocumentVoter::DELETE_WORKING_COPY;
576
        }
577
578
        if (!$this->authorizationChecker->isGranted($voterAttribute, $document)) {
579
            if (
580
                $this->editingLockService->isLocked(
581
                    $document->getDocumentIdentifier(),
582
                    $this->security->getUser()->getUid()
583
                )
584
            ) {
585
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureBlocked';
586
            } else {
587
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.accessDenied';
588
            }
589
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
590
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
591
            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...
592
        }
593
594
        if ($tstamp === $document->getTstamp()) {
595
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.success';
596
            $this->flashMessage($document, $key, AbstractMessage::OK);
597
            $this->documentRepository->remove($document);
598
599
            if ($document->isWorkingCopy() || $document->isTemporaryCopy()) {
600
601
                if ($document->isWorkingCopy()) {
602
                    if ($this->bookmarkRepository->removeBookmark($document, $this->security->getUser()->getUid())) {
603
                        $this->addFlashMessage(
604
                            LocalizationUtility::translate("manager.workspace.bookmarkRemoved.singular", "dpf"), '',
605
                            AbstractMessage::INFO
606
                        );
607
                    }
608
                }
609
610
                $this->persistenceManager->persistAll();
611
                $document = $this->documentManager->read($document->getDocumentIdentifier());
612
613
                // index the document
614
                $this->signalSlotDispatcher->dispatch(
615
                    \EWW\Dpf\Controller\AbstractController::class,
616
                    'indexDocument', [$document]
617
                );
618
619
                $this->documentRepository->remove($document);
620
621
            } elseif (!$document->isSuggestion()) {
622
                $this->bookmarkRepository->removeBookmark($document, $this->security->getUser()->getUid());
623
                // delete document from index
624
                $this->signalSlotDispatcher->dispatch(
625
                    \EWW\Dpf\Controller\AbstractController::class,
626
                    'deleteDocumentFromIndex', [$document->getDocumentIdentifier()]
627
                );
628
            }
629
630
            $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

630
            /** @scrutinizer ignore-call */ 
631
            $suggestions = $this->documentRepository->findByLinkedUid($document->getDocumentIdentifier());
Loading history...
631
            foreach ($suggestions as $suggestion) {
632
                $this->documentRepository->remove($suggestion);
633
            }
634
635
            /** @var Notifier $notifier */
636
            $notifier = $this->objectManager->get(Notifier::class);
637
            $notifier->sendSuggestionDeclineNotification($document, $reason);
638
639
            $this->redirectToDocumentList();
640
        } else {
641
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureNewVersion';
642
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
643
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
644
        }
645
    }
646
647
648
    /**
649
     * @param Document $document
650
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
651
     */
652
    public function duplicateAction(\EWW\Dpf\Domain\Model\Document $document)
653
    {
654
        if (!$this->authorizationChecker->isGranted(DocumentVoter::DUPLICATE, $document)) {
655
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_duplicate.accessDenied';
656
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
657
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
658
            return FALSE;
659
        }
660
661
        /* @var $newDocument \EWW\Dpf\Domain\Model\Document */
662
        $newDocument = $this->objectManager->get(Document::class);
663
664
        $newDocument->setState(DocumentWorkflow::STATE_NEW_NONE);
665
666
        $copyTitle = LocalizationUtility::translate("manager.workspace.title.copy", "dpf").$document->getTitle();
667
668
        $newDocument->setTitle($copyTitle);
669
670
        $newDocument->setAuthors($document->getAuthors());
671
672
        $newDocument->setCreator($this->security->getUser()->getUid());
673
674
        $newDocument->setDocumentType($document->getDocumentType());
675
676
        $processNumberGenerator = $this->objectManager->get(ProcessNumberGenerator::class);
677
        $processNumber = $processNumberGenerator->getProcessNumber();
678
        $newDocument->setProcessNumber($processNumber);
679
680
        $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData());
681
        $internalFormat->clearAllUrn();
682
        $internalFormat->setDateIssued('');
683
        $internalFormat->setTitle($copyTitle);
684
        $internalFormat->setProcessNumber($processNumber);
685
686
        $newDocument->setXmlData($internalFormat->getXml());
687
688
        $documentMapper = $this->objectManager->get(DocumentMapper::class);
689
690
        /** @var $documentForm \EWW\Dpf\Domain\Model\DocumentForm */
691
        $newDocumentForm = $documentMapper->getDocumentForm($newDocument);
692
693
        $this->forward(
694
            'new',
695
            'DocumentFormBackoffice',
696
            NULL,
697
            ['newDocumentForm' => $newDocumentForm, 'returnDocumentId' => $document->getUid()]
698
        );
699
700
    }
701
702
    /**
703
     * releasePublishAction
704
     *
705
     * @param \EWW\Dpf\Domain\Model\Document $document
706
     * @param integer $tstamp
707
     * @return void
708
     */
709
    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

709
    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...
710
    {
711
        if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_PUBLISH, $document)) {
712
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_ingest.accessDenied';
713
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
714
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
715
            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...
716
        }
717
        
718
        $this->updateDocument($document, DocumentWorkflow::TRANSITION_RELEASE_PUBLISH, null);
719
720
        /** @var Notifier $notifier */
721
        $notifier = $this->objectManager->get(Notifier::class);
722
        $notifier->sendReleasePublishNotification($document);
723
    }
724
    
725
    /**
726
     * releaseActivateAction
727
     *
728
     * @param \EWW\Dpf\Domain\Model\Document $document
729
     * @param integer $tstamp
730
     * @return void
731
     */
732
    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

732
    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...
733
    {
734
        if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_ACTIVATE, $document)) {
735
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_activate.accessDenied';
736
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
737
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
738
            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...
739
        }
740
        
741
        $this->updateDocument($document, DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE, null);
742
        
743
    }
744
    
745
    /**
746
     * action register
747
     *
748
     * @param \EWW\Dpf\Domain\Model\Document $document
749
     * @return void
750
     */
751
    public function registerAction(\EWW\Dpf\Domain\Model\Document $document)
752
    {
753
        if (!$this->authorizationChecker->isGranted(DocumentVoter::REGISTER, $document)) {
754
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.accessDenied';
755
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
756
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
757
        }
758
759
        if (!$this->documentValidator->validate($document, false)) {
760
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.missingValues';
761
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
762
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
763
        }
764
765
        $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

765
        $this->workflow->/** @scrutinizer ignore-call */ 
766
                         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...
766
        $this->documentRepository->update($document);
767
768
769
        if ($this->security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN) {
770
            $this->bookmarkRepository->addBookmark($document, $this->security->getUser()->getUid());
771
        }
772
773
        // admin register notification
774
        $notifier = $this->objectManager->get(Notifier::class);
775
        $notifier->sendRegisterNotification($document);
776
777
        // index the document
778
        $this->signalSlotDispatcher->dispatch(\EWW\Dpf\Controller\AbstractController::class, 'indexDocument', [$document]);
779
780
        // document updated notification
781
        $recipients = $this->documentManager->getUpdateNotificationRecipients($document);
782
        $notifier->sendMyPublicationUpdateNotification($document, $recipients);
783
784
        $recipients = $this->documentManager->getNewPublicationNotificationRecipients($document);
785
        $notifier->sendMyPublicationNewNotification($document, $recipients);
786
787
        $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.success';
788
        $this->flashMessage($document, $key, AbstractMessage::OK);
789
        $this->redirect('showDetails', 'Document', null, ['document' => $document]);
790
    }
791
792
    /**
793
     * action showDetails
794
     *
795
     * @param \EWW\Dpf\Domain\Model\Document $document
796
     * @return void
797
     */
798
    public function showDetailsAction(Document $document)
799
    {
800
        if (!$this->authorizationChecker->isGranted(DocumentVoter::SHOW_DETAILS, $document)) {
801
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_showDetails.accessDenied';
802
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
803
            $this->redirectToDocumentList();
804
        }
805
806
        $this->editingLockService->lock(
807
            ($document->getObjectIdentifier()? $document->getObjectIdentifier() : $document->getUid()),
808
            $this->security->getUser()->getUid()
809
        );
810
811
        $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

811
        /** @scrutinizer ignore-call */ 
812
        $postponeOptions = $this->inputOptionListRepository->findOneByName($this->settings['postponeOptionListName']);
Loading history...
812
        if ($postponeOptions) {
813
            $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

813
            $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...
814
        }
815
816
        $discardOptions = $this->inputOptionListRepository->findOneByName($this->settings['discardOptionListName']);
817
        if ($discardOptions) {
818
            $this->view->assign('discardOptions', $discardOptions->getInputOptions());
819
        }
820
821
        $mapper = $this->objectManager->get(DocumentMapper::class);
822
        $documentForm = $mapper->getDocumentForm($document, false);
823
824
        $documentTypes = [0 => ''];
825
        foreach ($this->documentTypeRepository->getDocumentTypesAlphabetically() as $documentType) {
826
            $documentTypes[$documentType->getUid()] = $documentType->getDisplayName();
827
        }
828
829
        $this->view->assign('documentTypes', $documentTypes);
830
831
        $this->view->assign('documentForm', $documentForm);
832
833
        $this->view->assign('document', $document);
834
    }
835
836
837
    public function cancelListTaskAction()
838
    {
839
        $this->redirectToDocumentList();
840
    }
841
    
842
    /**
843
     * action suggest restore
844
     *
845
     * @param Document $document
846
     * @return void
847
     */
848
    public function suggestRestoreAction(\EWW\Dpf\Domain\Model\Document $document) {
849
850
        if (!$this->authorizationChecker->isGranted(DocumentVoter::SUGGEST_RESTORE, $document)) {
851
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_suggestRestore.accessDenied';
852
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
853
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
854
            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...
855
        }
856
857
        $this->view->assign('document', $document);
858
    }
859
860
    /**
861
     * @param Document $document
862
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
863
     */
864
    public function suggestModificationAction(\EWW\Dpf\Domain\Model\Document $document) {
865
866
        $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SUGGEST_MODIFICATION, $document);
867
868
        $documentMapper = $this->objectManager->get(DocumentMapper::class);
869
870
        /* @var $newDocument \EWW\Dpf\Domain\Model\Document */
871
        $documentForm = $documentMapper->getDocumentForm($document);
872
873
        $this->view->assign('suggestMod', true);
874
        $this->forward('edit','DocumentFormBackoffice',NULL, ['documentForm' => $documentForm, 'suggestMod' => true]);
875
    }
876
877
878
    /**
879
     * initializeAction
880
     */
881
    public function initializeAction()
882
    {
883
        $this->authorizationChecker->denyAccessUnlessLoggedIn();
884
885
        parent::initializeAction();
886
887
        $this->workflow = $this->objectManager->get(DocumentWorkflow::class)->getWorkflow();
888
889
        if ($this->request->hasArgument('document')) {
890
            $document = $this->request->getArgument('document');
891
892
            if (is_array($document) && key_exists("__identity", $document)) {
893
                $document = $document["__identity"];
894
            }
895
896
            $document = $this->documentManager->read($document, $this->security->getUser()->getUID());
897
898
            if (!$document) {
899
                $this->redirectToDocumentList();
900
            }
901
902
            $this->request->setArgument('document', $document);
903
        }
904
    }
905
906
    /**
907
     * Redirect to the current document list.
908
     *
909
     * @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...
910
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
911
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
912
     */
913
    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

913
    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...
914
    {
915
        list($action, $controller, $redirectUri) = $this->session->getStoredAction();
916
917
        if ($redirectUri) {
918
            $this->redirectToUri($redirectUri);
919
        } else {
920
            $this->redirect($action, $controller);
921
        }
922
    }
923
924
    /**
925
     * Gets the storage PID of the current client
926
     *
927
     * @return mixed
928
     */
929
    protected function getStoragePID()
930
    {
931
        return $this->settings['persistence']['classes']['EWW\Dpf\Domain\Model\Document']['newRecordStoragePid'];
932
    }
933
934
    /**
935
     *
936
     * @param \EWW\Dpf\Domain\Model\Document $document
937
     * @param string $key
938
     * @param string $severity
939
     * @param string $defaultMessage
940
     */
941
    protected function flashMessage(\EWW\Dpf\Domain\Model\Document $document, $key, $severity, $defaultMessage = "")
942
    {
943
        // Show success or failure of the action in a flash message
944
        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...
945
            $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...
946
            $args[] = $document->getObjectIdentifier();
947
        }
948
949
        $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...
950
        $message = empty($message) ? $defaultMessage : $message;
951
952
        $this->addFlashMessage(
953
            $message,
954
            '',
955
            $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

955
            /** @scrutinizer ignore-type */ $severity,
Loading history...
956
            true
957
        );
958
    }
959
960
    /**
961
     * Updates the document in combination with a state transition.
962
     *
963
     * @param Document $document
964
     * @param $workflowTransition
965
     * @param string $reason
966
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
967
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
968
     */
969
    protected function updateDocument(\EWW\Dpf\Domain\Model\Document $document, $workflowTransition, $reason)
970
    {
971
        switch ($workflowTransition) {
972
            case DocumentWorkflow::TRANSITION_DISCARD:
973
                $messageKeyPart = 'document_discard';
974
                break;
975
            case DocumentWorkflow::TRANSITION_POSTPONE:
976
                $messageKeyPart = 'document_postpone';
977
                break;
978
            case DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE:
979
                $messageKeyPart = 'document_activate';
980
                break;
981
            case DocumentWorkflow::TRANSITION_RELEASE_PUBLISH:
982
                $messageKeyPart = 'document_ingest';
983
                break;
984
            default:
985
                $messageKeyPart = "document_update";
986
                break;
987
        }
988
989
        try {
990
            if ($reason) {
991
                $timezone = new \DateTimeZone($this->settings['timezone']);
992
                $timeStamp = (new \DateTime('now', $timezone))->format("d.m.Y H:i:s");
993
994
                if ($workflowTransition == DocumentWorkflow::TRANSITION_DISCARD) {
995
                    $note = LocalizationUtility::translate(
996
                        "manager.document.discard.note", "dpf", [$timeStamp, $reason]
997
                    );
998
                } elseif ($workflowTransition == DocumentWorkflow::TRANSITION_POSTPONE) {
999
                    $note = LocalizationUtility::translate(
1000
                        "manager.document.postpone.note", "dpf", [$timeStamp, $reason]
1001
                    );
1002
                }
1003
1004
                $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData());
1005
                $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...
1006
                $document->setXmlData($internalFormat->getXml());
1007
            }
1008
1009
            if ($this->documentManager->update($document, $workflowTransition)) {
1010
1011
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:'.$messageKeyPart.'.success';
1012
                $this->flashMessage($document, $key, AbstractMessage::OK);
1013
1014
                if ($this->security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN) {
1015
                    switch ($document->getState()) {
1016
                        case DocumentWorkflow::STATE_POSTPONED_NONE:
1017
                        case DocumentWorkflow::STATE_DISCARDED_NONE:
1018
                        case DocumentWorkflow::STATE_NONE_INACTIVE:
1019
                        case DocumentWorkflow::STATE_NONE_ACTIVE:
1020
                        case DocumentWorkflow::STATE_NONE_DELETED:
1021
1022
                            if (
1023
                                $this->bookmarkRepository->removeBookmark(
1024
                                    $document,
1025
                                    $this->security->getUser()->getUid()
1026
                                )
1027
                            ) {
1028
                                $this->addFlashMessage(
1029
                                    LocalizationUtility::translate("manager.workspace.bookmarkRemoved.singular", "dpf"), '',
1030
                                    AbstractMessage::INFO
1031
                                );
1032
                            }
1033
1034
                            break;
1035
                    }
1036
                }
1037
1038
                $this->redirectToDocumentList();
1039
            } else {
1040
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:'.$messageKeyPart.'.failure';
1041
                $this->flashMessage($document, $key, AbstractMessage::ERROR);
1042
                $this->redirect('showDetails', 'Document', NULL, ['document' => $document]);
1043
            }
1044
        } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $e) {
1045
            // A redirect always throws this exception, but in this case, however,
1046
            // redirection is desired and should not lead to an exception handling
1047
        } catch (\Exception $exception) {
1048
            if ($exception instanceof DPFExceptionInterface) {
1049
                $key = $exception->messageLanguageKey();
1050
            } else {
1051
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:'.$messageKeyPart.'.failure';
1052
            }
1053
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
1054
            $this->redirectToDocumentList();
1055
        }
1056
1057
    }
1058
}
1059