Passed
Pull Request — master (#155)
by
unknown
09:48
created

DocumentController::postponeAction()   C

Complexity

Conditions 13
Paths 204

Size

Total Lines 82
Code Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 61
c 0
b 0
f 0
nc 204
nop 3
dl 0
loc 82
rs 5.7333

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Security\DocumentVoter;
19
use EWW\Dpf\Security\Security;
20
use EWW\Dpf\Services\Transfer\ElasticsearchRepository;
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\Helper\ElasticsearchMapper;
26
use EWW\Dpf\Exceptions\DPFExceptionInterface;
27
use EWW\Dpf\Domain\Workflow\DocumentWorkflow;
28
use TYPO3\CMS\Core\Messaging\AbstractMessage;
29
use EWW\Dpf\Helper\DocumentMapper;
30
use TYPO3\CMS\Backend\Exception;
31
use EWW\Dpf\Domain\Model\File;
32
use TYPO3\CMS\Core\Utility\GeneralUtility;
33
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
34
35
36
/**
37
 * DocumentController
38
 */
39
class DocumentController extends \EWW\Dpf\Controller\AbstractController
40
{
41
42
    /**
43
     * documentRepository
44
     *
45
     * @var \EWW\Dpf\Domain\Repository\DocumentRepository
46
     * @inject
47
     */
48
    protected $documentRepository = null;
49
50
    /**
51
     * inputOptionListRepository
52
     *
53
     * @var \EWW\Dpf\Domain\Repository\InputOptionListRepository
54
     * @inject
55
     */
56
    protected $inputOptionListRepository = null;
57
58
    /**
59
     * persistence manager
60
     *
61
     * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
62
     * @inject
63
     */
64
    protected $persistenceManager;
65
66
    /**
67
     * documentValidator
68
     *
69
     * @var \EWW\Dpf\Helper\DocumentValidator
70
     * @inject
71
     */
72
    protected $documentValidator;
73
74
    /**
75
     * workflow
76
     *
77
     * @var \EWW\Dpf\Domain\Workflow\DocumentWorkflow
78
     */
79
    protected $workflow;
80
81
    /**
82
     * documentTransferManager
83
     *
84
     * @var \EWW\Dpf\Services\Transfer\DocumentTransferManager $documentTransferManager
85
     */
86
    protected $documentTransferManager;
87
88
    /**
89
     * fedoraRepository
90
     *
91
     * @var \EWW\Dpf\Services\Transfer\FedoraRepository $fedoraRepository
92
     */
93
    protected $fedoraRepository;
94
95
    /**
96
     * fileRepository
97
     *
98
     * @var \EWW\Dpf\Domain\Repository\FileRepository
99
     * @inject
100
     */
101
    protected $fileRepository = null;
102
103
104
    /**
105
     * frontendUserRepository
106
     *
107
     * @var \EWW\Dpf\Domain\Repository\FrontendUserRepository
108
     * @inject
109
     */
110
    protected $frontendUserRepository = null;
111
112
113
    /**
114
     * DocumentController constructor.
115
     */
116
    public function __construct()
117
    {
118
        parent::__construct();
119
120
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
121
        $this->documentTransferManager = $objectManager->get(DocumentTransferManager::class);
122
        $this->fedoraRepository = $objectManager->get(FedoraRepository::class);
123
        $this->documentTransferManager->setRemoteRepository($this->fedoraRepository);
124
    }
125
126
    /**
127
     * action logout of the backoffice
128
     *
129
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
130
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
131
     */
132
    public function logoutAction()
133
    {
134
        $cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
135
        $uri = $cObj->typolink_URL([
136
            'parameter' => $this->settings['loginPage'],
137
            //'linkAccessRestrictedPages' => 1,
138
            'forceAbsoluteUrl' => 1,
139
            'additionalParams' => GeneralUtility::implodeArrayForUrl(NULL, ['logintype'=>'logout'])
140
        ]);
141
142
        $this->redirectToUri($uri);
143
    }
144
145
    /**
146
     * action list
147
     *
148
     * @param array $stateFilters
149
     *
150
     * @return void
151
     */
152
    public function listAction($stateFilters = array())
153
    {
154
        $this->setSessionData('redirectToDocumentListAction','list');
155
        $this->setSessionData('redirectToDocumentListController','Document');
156
157
        list($isWorkspace, $documents) = $this->getListViewData($stateFilters);
158
159
        if ($this->request->hasArgument('message')) {
160
            $this->view->assign('message', $this->request->getArgument('message'));
161
        }
162
163
        if ($this->request->hasArgument('errorFiles')) {
164
            $this->view->assign('errorFiles', $this->request->getArgument('errorFiles'));
165
        }
166
167
        $this->view->assign('currentUser', $this->security->getUser());
168
        $this->view->assign('isWorkspace', $isWorkspace);
169
        $this->view->assign('documents', $documents);
170
    }
171
172
    public function listSuggestionsAction() {
173
        $this->setSessionData('redirectToDocumentListAction','listSuggestions');
174
        $this->setSessionData('redirectToDocumentListController','Document');
175
176
        list($isWorkspace, $documents) = $this->getListViewData([], true);
177
178
        if ($this->request->hasArgument('message')) {
179
            $this->view->assign('message', $this->request->getArgument('message'));
180
        }
181
182
        if ($this->request->hasArgument('errorFiles')) {
183
            $this->view->assign('errorFiles', $this->request->getArgument('errorFiles'));
184
        }
185
186
        $this->view->assign('currentUser', $this->security->getUser());
187
        $this->view->assign('isWorkspace', $isWorkspace);
188
        $this->view->assign('documents', $documents);
189
    }
190
191
    /**
192
     * @param Document $document
193
     * @param bool $acceptAll
194
     */
195
    public function acceptSuggestionAction(\EWW\Dpf\Domain\Model\Document $document, bool $acceptAll = true) {
196
197
        $args = $this->request->getArguments();
0 ignored issues
show
Unused Code introduced by
The assignment to $args is dead and can be removed.
Loading history...
198
199
        /** @var DocumentMapper $documentMapper */
200
        $documentMapper = $this->objectManager->get(DocumentMapper::class);
201
202
        // Existing working copy?
203
        /** @var \EWW\Dpf\Domain\Model\Document $originDocument */
204
        $linkedUid = $document->getLinkedUid();
205
        $originDocument = $this->documentRepository->findWorkingCopy($linkedUid);
206
207
        if ($originDocument) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $originDocument of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
208
            $linkedDocumentForm = $documentMapper->getDocumentForm($originDocument);
0 ignored issues
show
Unused Code introduced by
The assignment to $linkedDocumentForm is dead and can be removed.
Loading history...
209
        } else {
210
            // get remote document
211
            $originDocument = $this->documentTransferManager->retrieve($document->getLinkedUid(), $this->security->getUser()->getUid());
212
            $linkedDocumentForm = $documentMapper->getDocumentForm($originDocument);
213
        }
214
215
        if ($acceptAll) {
216
            // all changes are confirmed
217
            // copy suggest to origin document
218
            $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

218
            $originDocument->/** @scrutinizer ignore-call */ 
219
                             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...
219
220
            if ($originDocument->getTransferStatus() == 'RESTORE') {
221
                if ($originDocument->getObjectIdentifier()) {
222
                    $originDocument->setState(DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE);
223
                } else {
224
                    $originDocument->setState(DocumentWorkflow::STATE_IN_PROGRESS_NONE);
225
                }
226
            }
227
228
            // copy files from suggest document
229
            foreach ($document->getFile() as $key => $file) {
230
                $newFile = $this->objectManager->get(File::class);
231
                $newFile->copy($file);
232
                $newFile->setDocument($originDocument);
233
                $this->fileRepository->add($newFile);
234
                $originDocument->addFile($newFile);
235
236
            }
237
238
            $this->documentRepository->update($originDocument);
0 ignored issues
show
Bug introduced by
It seems like $originDocument can also be of type array; however, parameter $modifiedObject of TYPO3\CMS\Extbase\Persistence\Repository::update() does only seem to accept object, maybe add an additional type check? ( Ignorable by Annotation )

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

238
            $this->documentRepository->update(/** @scrutinizer ignore-type */ $originDocument);
Loading history...
239
            $this->documentRepository->remove($document);
240
241
            // redirect to document
242
            $this->redirect('showDetails', 'Document', null, ['document' => $originDocument]);
243
        }
244
245
        $this->redirectToDocumentList();
246
    }
247
248
249
    public function showSuggestionDetailsAction(\EWW\Dpf\Domain\Model\Document $document) {
250
        $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SHOW_DETAILS, $document);
251
252
        /** @var DocumentMapper $documentMapper */
253
        $documentMapper = $this->objectManager->get(DocumentMapper::class);
254
255
        $linkedUid = $document->getLinkedUid();
256
        $linkedDocument = $this->documentRepository->findWorkingCopy($linkedUid);
257
258
        if ($linkedDocument) {
259
            // Existing working copy
260
            $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument);
261
        } else {
262
            // No existing working copy, get remote document from fedora
263
            $linkedDocument = $this->documentTransferManager->retrieve($document->getLinkedUid(), $this->security->getUser()->getUid());
264
            $linkedDocumentForm = $documentMapper->getDocumentForm($linkedDocument);
265
        }
266
267
        $newDocumentForm = $documentMapper->getDocumentForm($document);
268
        $diff = $this->documentFormDiff($linkedDocumentForm, $newDocumentForm);
269
270
        //$usernameString = $this->security->getUser()->getUsername();
271
        $user = $this->frontendUserRepository->findOneByUid($document->getOwner());
272
273
        if ($user) {
274
            $usernameString = $user->getUsername();
275
        }
276
277
        $this->view->assign('documentOwner', $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...
278
        $this->view->assign('diff', $diff);
279
        $this->view->assign('document', $document);
280
281
    }
282
283
    public function documentFormDiff($docForm1, $docForm2) {
284
        $returnArray = ['changed' => ['new' => [], 'old' => []], 'deleted' => [], 'added' => []];
285
286
        // pages
287
        foreach ($docForm1->getItems() as $keyPage => $valuePage) {
288
            foreach ($valuePage as $keyRepeatPage => $valueRepeatPage) {
289
290
                // groups
291
                foreach ($valueRepeatPage->getItems() as $keyGroup => $valueGroup) {
292
293
                    $checkFieldsForAdding = false;
294
                    $valueGroupCounter = count($valueGroup);
295
296
                    if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) {
297
                        $checkFieldsForAdding = true;
298
                    }
299
300
                    foreach ($valueGroup as $keyRepeatGroup => $valueRepeatGroup) {
301
302
                        // fields
303
                        foreach ($valueRepeatGroup->getItems() as $keyField => $valueField) {
304
                            foreach ($valueField as $keyRepeatField => $valueRepeatField) {
305
306
                                $fieldCounter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]);
307
                                $valueFieldCounter = count($valueField);
308
309
                                // check if group or field is not existing
310
                                $notExisting = false;
311
                                try {
312
                                    $flag = 'page';
313
                                    $value2 = $docForm2->getItems()[$keyPage];
314
                                    $flag = 'group';
315
                                    $value2 = $value2[$keyRepeatPage];
316
                                    $value2 = $value2->getItems()[$keyGroup];
317
                                    $value2 = $value2[$keyRepeatGroup]->getItems()[$keyField];
318
                                    $flag = 'field';
319
                                } catch (\Throwable $t) {
320
                                    $notExisting = true;
321
                                }
322
323
                                $item = NULL;
0 ignored issues
show
Unused Code introduced by
The assignment to $item is dead and can be removed.
Loading history...
324
                                if ($flag == 'group') {
325
                                    $itemExisting = $valueRepeatGroup;
326
                                    $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup];
327
                                } else if ($flag == 'field') {
328
                                    $itemExisting = $valueRepeatField;
329
                                    $itemNew = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$keyRepeatField];
330
                                }
331
332
                                if ($notExisting || ($valueRepeatField->getValue() != $value2[$keyRepeatField]->getValue() && empty($value2[$keyRepeatField]->getValue()))) {
333
                                    // deleted
334
                                    $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...
335
336
                                } else if ($this->removeControlCharacterFromString($valueRepeatField->getValue()) != $this->removeControlCharacterFromString($value2[$keyRepeatField]->getValue())
337
                                    && !empty($value2[$keyRepeatField]->getValue())) {
338
339
                                    // changed
340
                                    $returnArray['changed']['old'][] = $itemExisting;
341
                                    $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...
342
                                }
343
344
                                if ($flag == 'group') {
345
                                    break 2;
346
                                }
347
                            }
348
349
                            // check if new document form has more field items as the existing form
350
                            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...
351
                                // field added
352
                                for ($i = count($valueField); $i < $fieldCounter;$i++) {
353
                                    $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$keyRepeatGroup]->getItems()[$keyField][$i];
354
355
                                }
356
                            }
357
                        }
358
                    }
359
360
                    // check if new document form has more group items as the existing form
361
                    if ($valueGroupCounter < count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup])) {
362
                        // group added
363
                        $counter = count($docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup]);
364
                        for ($i = $valueGroupCounter; $i < $counter;$i++) {
365
                            $returnArray['added'][] = $docForm2->getItems()[$keyPage][$keyRepeatPage]->getItems()[$keyGroup][$i];
366
                        }
367
                    }
368
                }
369
            }
370
371
        }
372
373
        return $returnArray;
374
375
    }
376
377
    public function removeControlCharacterFromString($string) {
378
        return preg_replace('/\p{C}+/u', "", $string);
379
    }
380
381
    public function listRegisteredAction()
382
    {
383
        $this->setSessionData('redirectToDocumentListAction','listRegistered');
384
        $this->setSessionData('redirectToDocumentListController','Document');
385
386
        list($isWorkspace, $documents) = $this->getListViewData([DocumentWorkflow::STATE_REGISTERED_NONE]);
387
388
        if ($this->request->hasArgument('message')) {
389
            $this->view->assign('message', $this->request->getArgument('message'));
390
        }
391
392
        if ($this->request->hasArgument('errorFiles')) {
393
            $this->view->assign('errorFiles', $this->request->getArgument('errorFiles'));
394
        }
395
396
        $this->view->assign('isWorkspace', $isWorkspace);
397
        $this->view->assign('documents', $documents);
398
    }
399
400
    public function listInProgressAction()
401
    {
402
        $this->setSessionData('redirectToDocumentListAction','listInProgress');
403
        $this->setSessionData('redirectToDocumentListController','Document');
404
405
        if ($this->request->hasArgument('message')) {
406
            $this->view->assign('message', $this->request->getArgument('message'));
407
        }
408
409
        if ($this->request->hasArgument('errorFiles')) {
410
            $this->view->assign('errorFiles', $this->request->getArgument('errorFiles'));
411
        }
412
413
        list($isWorkspace, $documents) = $this->getListViewData(
414
            [
415
                DocumentWorkflow::STATE_IN_PROGRESS_NONE,
416
                DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE,
417
                DocumentWorkflow::STATE_IN_PROGRESS_INACTIVE,
418
                DocumentWorkflow::STATE_IN_PROGRESS_DELETED,
419
            ]
420
        );
421
422
        $this->view->assign('isWorkspace', $isWorkspace);
423
        $this->view->assign('documents', $documents);
424
    }
425
426
427
    /**
428
     * action discard
429
     *
430
     * @param \EWW\Dpf\Domain\Model\Document $document
431
     * @param integer $tstamp
432
     * @param string $reason
433
     * @return void
434
     */
435
    public function discardAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = NULL)
436
    {
437
        if (!$this->authorizationChecker->isGranted(DocumentVoter::DISCARD, $document)) {
438
            if ($document->getEditorUid()) {
439
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.failureBlocked';
440
            } else {
441
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.accessDenied';
442
            }
443
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
444
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
445
            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...
446
        }
447
448
        $document->setEditorUid($this->security->getUser()->getUid());
449
450
        if ($reason) {
451
            $timeStamp = (new \DateTime)->format("d.m.Y H:i:s");
452
            $note = "Das Dokument wurde verworfen: ".$timeStamp."\n"."Kommentar: ".$reason;
453
            $slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData());
454
            $slub->addNote($note);
455
            $document->setSlubInfoData($slub->getSlubXml());
456
        }
457
458
        try {
459
                if (
460
                    in_array(
461
                        $document->getState(),
462
                        [
463
                            DocumentWorkflow::STATE_IN_PROGRESS_DELETED,
464
                            DocumentWorkflow::STATE_IN_PROGRESS_INACTIVE,
465
                            DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE
466
                        ]
467
                    )
468
                ) {
469
                    if ($document->isTemporary()) {
470
                        $noNewerVersion = $this->documentTransferManager->getLastModDate($document->getObjectIdentifier()) === $document->getRemoteLastModDate();
471
                    } else {
472
                        $noNewerVersion = $tstamp === $document->getTstamp();
473
                    }
474
475
                    if ($noNewerVersion) {
476
                        if ($this->documentTransferManager->delete($document, "") && $this->documentTransferManager->update($document)) {
477
                            $this->workflow->apply($document, DocumentWorkflow::TRANSITION_DISCARD);
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

477
                            $this->workflow->/** @scrutinizer ignore-call */ 
478
                                             apply($document, DocumentWorkflow::TRANSITION_DISCARD);

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...
478
                            $this->documentRepository->update($document);
479
                            $this->documentRepository->remove($document);
480
                            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.success';
481
                            $this->flashMessage($document, $key, AbstractMessage::OK);
482
                            $this->redirectToDocumentList();
483
                        } else {
484
                            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.failure';
485
                            $this->flashMessage($document, $key, AbstractMessage::ERROR);
486
                            $this->redirect('showDetails', 'Document', NULL, ['document' => $document]);
487
                        }
488
                    } else {
489
                        $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.failureNewVersion';
490
                        $this->flashMessage($document, $key, AbstractMessage::ERROR);
491
                        $this->redirect('showDetails', 'Document', NULL, ['document' => $document]);
492
                    }
493
                } else {
494
                    if ($tstamp === $document->getTstamp()) {
495
                        $this->workflow->apply($document, DocumentWorkflow::TRANSITION_DISCARD);
496
                        $this->documentRepository->update($document);
497
                        $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.success';
498
                        $this->flashMessage($document, $key, AbstractMessage::OK);
499
                        $this->redirectToDocumentList();
500
                    } else {
501
                        $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.failureNewVersion';
502
                        $this->flashMessage($document, $key, AbstractMessage::ERROR);
503
                        $this->redirect('showDetails', 'Document', NULL, ['document' => $document]);
504
                    }
505
                }
506
        } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $e) {
507
            // A redirect always throws this exception, but in this case, however,
508
            // redirection is desired and should not lead to an exception handling
509
        } catch (\Exception $exception) {
510
            if ($exception instanceof DPFExceptionInterface) {
511
                $key = $exception->messageLanguageKey();
512
            } else {
513
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_discard.failure';
514
            }
515
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
516
            $this->redirectToDocumentList();
517
        }
518
    }
519
520
    /**
521
     * action postpone
522
     *
523
     * @param \EWW\Dpf\Domain\Model\Document $document
524
     * @param integer $tstamp
525
     * @param string $reason
526
     * @return void
527
     */
528
    public function postponeAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp, $reason = NULL)
529
    {
530
        if (!$this->authorizationChecker->isGranted(DocumentVoter::POSTPONE, $document)) {
531
            if ($document->getEditorUid()) {
532
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.failureBlocked';
533
            } else {
534
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.accessDenied';
535
            }
536
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
537
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
538
            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...
539
        }
540
541
        $document->setEditorUid($this->security->getUser()->getUid());
542
543
        if ($reason) {
544
            $timeStamp = (new \DateTime)->format("d.m.Y H:i:s");
545
            $note = "Das Dokument wurde zurückgestellt: ".$timeStamp."\n"."Kommentar: ".$reason;
546
            $slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData());
547
            $slub->addNote($note);
548
            $document->setSlubInfoData($slub->getSlubXml());
549
        }
550
551
        try {
552
            if (
553
                in_array(
554
                    $document->getState(),
555
                    [
556
                        DocumentWorkflow::STATE_IN_PROGRESS_DELETED,
557
                        DocumentWorkflow::STATE_IN_PROGRESS_INACTIVE,
558
                        DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE
559
                    ]
560
                )
561
            ) {
562
                if ($document->isTemporary()) {
563
                    $noNewerVersion = $this->documentTransferManager->getLastModDate($document->getObjectIdentifier()) === $document->getRemoteLastModDate();
564
                } else {
565
                    $noNewerVersion = $tstamp === $document->getTstamp();
566
                }
567
568
                if ($noNewerVersion) {
569
                    if ($this->documentTransferManager->delete($document, "inactivate") && $this->documentTransferManager->update($document)) {
570
                        $this->workflow->apply($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_POSTPONE);
571
                        $this->documentRepository->update($document);
572
                        $this->documentRepository->remove($document);
573
                        $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.success';
574
                        $this->flashMessage($document, $key, AbstractMessage::OK);
575
                        $this->redirectToDocumentList();
576
                    } else {
577
                        $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.failure';
578
                        $this->flashMessage($document, $key, AbstractMessage::ERROR);
579
                        $this->redirect('showDetails', 'Document', NULL, ['document' => $document]);
580
                    }
581
                } else {
582
                    $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.failureNewVersion';
583
                    $this->flashMessage($document, $key, AbstractMessage::ERROR);
584
                    $this->redirect('showDetails', 'Document', NULL, ['document' => $document]);
585
                }
586
            } else {
587
                if ($tstamp === $document->getTstamp()) {
588
                    $this->workflow->apply($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_POSTPONE);
589
                    $this->documentRepository->update($document);
590
                    $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.success';
591
                    $this->flashMessage($document, $key, AbstractMessage::OK);
592
                    $this->redirectToDocumentList();
593
                } else {
594
                    $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.failureNewVersion';
595
                    $this->flashMessage($document, $key, AbstractMessage::ERROR);
596
                    $this->redirect('showDetails', 'Document', NULL, ['document' => $document]);
597
                }
598
            }
599
        } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $e) {
600
            // A redirect always throws this exception, but in this case, however,
601
            // redirection is desired and should not lead to an exception handling
602
        } catch (\Exception $exception) {
603
            if ($exception instanceof DPFExceptionInterface) {
604
                $key = $exception->messageLanguageKey();
605
            } else {
606
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_postpone.failed';
607
            }
608
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
609
            $this->redirectToDocumentList();
610
        }
611
    }
612
613
614
    /**
615
     * action deleteLocallyAction
616
     *
617
     * @param Document $document
618
     * @param integer $tstamp
619
     * @return void
620
     */
621
    public function deleteLocallyAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp)
622
    {
623
        if ($document->getObjectIdentifier()) {
624
            $voterAttribute = DocumentVoter::DELETE_WORKING_COPY;
625
        } else {
626
            $voterAttribute = DocumentVoter::DELETE_LOCALLY;
627
        }
628
629
        if (!$this->authorizationChecker->isGranted($voterAttribute, $document)) {
630
            if ($document->getEditorUid()) {
631
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureBlocked';
632
            } else {
633
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.accessDenied';
634
            }
635
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
636
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
637
            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...
638
        }
639
640
        if ($tstamp === $document->getTstamp()) {
641
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.success';
642
            $this->flashMessage($document, $key, AbstractMessage::OK);
643
            $this->documentRepository->remove($document);
644
645
            $suggestions = $this->documentRepository->findByLinkedUid($document->getUid());
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

645
            /** @scrutinizer ignore-call */ 
646
            $suggestions = $this->documentRepository->findByLinkedUid($document->getUid());
Loading history...
646
            foreach ($suggestions as $suggestion) {
647
                $this->documentRepository->remove($suggestion);
648
            }
649
650
            $this->redirectToDocumentList();
651
        } else {
652
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_deleteLocally.failureNewVersion';
653
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
654
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
655
        }
656
    }
657
658
    /**
659
     * action duplicate
660
     *
661
     * @param \EWW\Dpf\Domain\Model\Document $document
662
     * @return void
663
     */
664
    public function duplicateAction(\EWW\Dpf\Domain\Model\Document $document)
665
    {
666
        if (!$this->authorizationChecker->isGranted(DocumentVoter::DUPLICATE, $document)) {
667
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_duplicate.accessDenied';
668
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
669
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
670
            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...
671
        }
672
673
        try {
674
            /* @var $newDocument \EWW\Dpf\Domain\Model\Document */
675
            $newDocument = $this->objectManager->get(Document::class);
676
677
            $newDocument->setState(DocumentWorkflow::STATE_NEW_NONE);
678
679
            $newDocument->setTitle($document->getTitle());
680
            $newDocument->setAuthors($document->getAuthors());
681
682
            $newDocument->setOwner($this->security->getUser()->getUid());
683
684
            $mods = new \EWW\Dpf\Helper\Mods($document->getXmlData());
685
            $mods->clearAllUrn();
686
            $newDocument->setXmlData($mods->getModsXml());
687
688
            $newDocument->setDocumentType($document->getDocumentType());
689
690
            $processNumberGenerator = $this->objectManager->get(ProcessNumberGenerator::class);
691
            $processNumber = $processNumberGenerator->getProcessNumber();
692
            $newDocument->setProcessNumber($processNumber);
693
694
            $slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData());
695
            $slub->setProcessNumber($processNumber);
696
            $newDocument->setSlubInfoData($slub->getSlubXml());
697
698
            // send document to index
699
            $elasticsearchRepository = $this->objectManager->get(ElasticsearchRepository::class);
700
701
            $elasticsearchMapper = $this->objectManager->get(ElasticsearchMapper::class);
702
            $json = $elasticsearchMapper->getElasticsearchJson($newDocument);
703
704
            $elasticsearchRepository->add($newDocument, $json);
705
706
            $this->documentRepository->add($newDocument);
707
708
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_duplicate.success';
709
            $this->flashMessage($document, $key, AbstractMessage::OK);
710
            $this->redirect('list');
711
        } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $e) {
712
            // A redirect always throws this exception, but in this case, however,
713
            // redirection is desired and should not lead to an exception handling
714
        } catch (\Exception $exception) {
715
            if ($exception instanceof DPFExceptionInterface) {
716
                $key = $exception->messageLanguageKey();
717
            } else {
718
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_duplicate.failure';
719
            }
720
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
721
            $this->redirect('list');
722
        }
723
    }
724
725
726
    /**
727
     * releaseUpdateAction
728
     *
729
     * @param \EWW\Dpf\Domain\Model\Document $document
730
     * @param integer $tstamp
731
     * @return void
732
     */
733
    public function releaseUpdateAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp)
734
    {
735
        if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_UPDATE, $document)) {
0 ignored issues
show
Bug introduced by
The constant EWW\Dpf\Security\DocumentVoter::RELEASE_UPDATE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
736
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.accessDenied';
737
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
738
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
739
            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...
740
        }
741
742
        try {
743
            if (
744
                $this->documentTransferManager->getLastModDate($document->getObjectIdentifier()) === $document->getRemoteLastModDate() &&
745
                $tstamp === $document->getTstamp()
746
            ) {
747
                if ($this->documentTransferManager->update($document)) {
748
                    $this->documentRepository->remove($document);
749
                    $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.success';
750
                    $this->flashMessage($document, $key, AbstractMessage::OK);
751
                    $this->redirect('list');
752
                }
753
            } else {
754
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_update.failureNewVersion';
755
                $this->flashMessage($document, $key, AbstractMessage::ERROR);
756
                $this->redirect('showDetails', 'Document', NULL, ['document' => $document]);
757
            }
758
        } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $e) {
759
            // A redirect always throws this exception, but in this case, however,
760
            // redirection is desired and should not lead to an exception handling
761
        } catch (\Exception $exception) {
762
            if ($exception instanceof DPFExceptionInterface) {
763
                $key = $exception->messageLanguageKey();
764
            } else {
765
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.unexpected';
766
            }
767
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
768
            $this->redirect('list');
769
        }
770
771
    }
772
773
    /**
774
     * releasePublishAction
775
     *
776
     * @param \EWW\Dpf\Domain\Model\Document $document
777
     * @param integer $tstamp
778
     * @return void
779
     */
780
    public function releasePublishAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp)
781
    {
782
        if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_PUBLISH, $document)) {
783
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_ingest.accessDenied';
784
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
785
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
786
            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...
787
        }
788
789
        try {
790
            if ($tstamp === $document->getTstamp()) {
791
                if ($this->documentTransferManager->ingest($document)) {
792
                    $notifier = $this->objectManager->get(Notifier::class);
793
                    $notifier->sendIngestNotification($document);
794
                    $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_ingest.success';
795
                    $this->flashMessage($document, $key, AbstractMessage::OK);
796
                    $this->redirectToDocumentList();
797
                } else {
798
                    $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_ingest.failure';
799
                    $this->flashMessage($document, $key, AbstractMessage::ERROR);
800
                    $this->redirect('showDetails', 'Document', null, ['document' => $document]);
801
                }
802
            } else {
803
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_ingest.failureNewVersion';
804
                $this->flashMessage($document, $key, AbstractMessage::ERROR);
805
                $this->redirect('showDetails', 'Document', null, ['document' => $document]);
806
            }
807
        } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $e) {
808
            // A redirect always throws this exception, but in this case, however,
809
            // redirection is desired and should not lead to an exception handling
810
        } catch (\Exception $exception) {
811
812
            if ($exception instanceof DPFExceptionInterface) {
813
                $key = $exception->messageLanguageKey();
814
            } else {
815
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.unexpected';
816
            }
817
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
818
            $this->redirect('list');
819
        }
820
    }
821
822
823
    /**
824
     * releaseActivateAction
825
     *
826
     * @param \EWW\Dpf\Domain\Model\Document $document
827
     * @param integer $tstamp
828
     * @return void
829
     */
830
    public function releaseActivateAction(\EWW\Dpf\Domain\Model\Document $document, $tstamp)
831
    {
832
        if (!$this->authorizationChecker->isGranted(DocumentVoter::RELEASE_ACTIVATE, $document)) {
833
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_activate.accessDenied';
834
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
835
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
836
            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...
837
        }
838
839
        try {
840
            if (
841
                $this->documentTransferManager->getLastModDate($document->getObjectIdentifier()) === $document->getRemoteLastModDate() &&
842
                $tstamp === $document->getTstamp()
843
            ) {
844
                if ($this->documentTransferManager->delete($document, "revert") && $this->documentTransferManager->update($document)) {
845
                    $this->documentRepository->remove($document);
846
                    $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_activate.success';
847
                    $this->flashMessage($document, $key, AbstractMessage::OK);
848
                    $this->redirectToDocumentList();
849
                } else {
850
                    $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_activate.failure';
851
                    $this->flashMessage($document, $key, AbstractMessage::ERROR);
852
                    $this->redirect('showDetails', 'Document', null, ['document' => $document]);
853
                }
854
            } else {
855
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_activate.failureNewVersion';
856
                $this->flashMessage($document, $key, AbstractMessage::ERROR);
857
                $this->redirect('showDetails', 'Document', null, ['document' => $document]);
858
            }
859
        } catch (\TYPO3\CMS\Extbase\Mvc\Exception\StopActionException $e) {
860
            // A redirect always throws this exception, but in this case, however,
861
            // redirection is desired and should not lead to an exception handling
862
        } catch (\Exception $exception) {
863
            if ($exception instanceof DPFExceptionInterface) {
864
                $key = $exception->messageLanguageKey();
865
            } else {
866
                $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.unexpected';
867
            }
868
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
869
            $this->redirect('list');
870
        }
871
    }
872
873
    /**
874
     * action register
875
     *
876
     * @param \EWW\Dpf\Domain\Model\Document $document
877
     * @return void
878
     */
879
    public function registerAction(\EWW\Dpf\Domain\Model\Document $document)
880
    {
881
        if (!$this->authorizationChecker->isGranted(DocumentVoter::REGISTER, $document)) {
882
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.accessDenied';
883
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
884
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
885
        }
886
887
        if (!$this->documentValidator->validate($document)) {
888
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.missingValues';
889
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
890
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
891
        }
892
893
        $this->workflow->apply($document, \EWW\Dpf\Domain\Workflow\DocumentWorkflow::TRANSITION_REGISTER);
894
        $this->documentRepository->update($document);
895
896
        $notifier = $this->objectManager->get(Notifier::class);
897
        $notifier->sendRegisterNotification($document);
898
899
        $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_register.success';
900
        $this->flashMessage($document, $key, AbstractMessage::OK);
901
        $this->redirect('showDetails', 'Document', null, ['document' => $document]);
902
    }
903
904
    /**
905
     * action showDetails
906
     *
907
     * @param Document $document
908
     * @return void
909
     */
910
    public function showDetailsAction(\EWW\Dpf\Domain\Model\Document $document)
911
    {
912
        if (!$this->authorizationChecker->isGranted(DocumentVoter::SHOW_DETAILS, $document)) {
913
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_showDetails.accessDenied';
914
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
915
            $this->redirectToDocumentList();
916
        }
917
918
        $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

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

920
            $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...
921
        }
922
923
        $discardOptions = $this->inputOptionListRepository->findOneByName($this->settings['discardOptionListName']);
924
        if ($discardOptions) {
925
            $this->view->assign('discardOptions', $discardOptions->getInputOptions());
926
        }
927
928
        $this->view->assign('document', $document);
929
    }
930
931
932
    public function cancelListTaskAction()
933
    {
934
        $this->redirectToDocumentList();
935
    }
936
937
    /**
938
     * action uploadFiles
939
     *
940
     * @param \EWW\Dpf\Domain\Model\Document $document
941
     * @return void
942
     */
943
    public function uploadFilesAction(\EWW\Dpf\Domain\Model\Document $document)
944
    {
945
        $this->view->assign('document', $document);
946
    }
947
948
    /**
949
     * action suggest restore
950
     *
951
     * @param Document $document
952
     * @return void
953
     */
954
    public function suggestRestoreAction(\EWW\Dpf\Domain\Model\Document $document) {
955
956
        if (!$this->authorizationChecker->isGranted(DocumentVoter::SUGGEST_RESTORE, $document)) {
957
            $key = 'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_suggestRestore.accessDenied';
958
            $this->flashMessage($document, $key, AbstractMessage::ERROR);
959
            $this->redirect('showDetails', 'Document', null, ['document' => $document]);
960
            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...
961
        }
962
963
        $this->view->assign('document', $document);
964
    }
965
966
    /**
967
     * @param Document $document
968
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
969
     */
970
    public function suggestModificationAction(\EWW\Dpf\Domain\Model\Document $document) {
971
972
        $this->authorizationChecker->denyAccessUnlessGranted(DocumentVoter::SUGGEST_MODIFICATION, $document);
973
974
        $documentMapper = $this->objectManager->get(DocumentMapper::class);
975
976
        /* @var $newDocument \EWW\Dpf\Domain\Model\Document */
977
        $documentForm = $documentMapper->getDocumentForm($document);
978
979
        $this->view->assign('suggestMod', true);
980
        $this->forward('edit','DocumentFormBackoffice',NULL, ['documentForm' => $documentForm, 'suggestMod' => true]);
981
    }
982
983
984
    /**
985
     * initializeAction
986
     */
987
    public function initializeAction()
988
    {
989
        $this->authorizationChecker->denyAccessUnlessLoggedIn();
990
991
        parent::initializeAction();
992
993
        $this->workflow = $this->objectManager->get(DocumentWorkflow::class)->getWorkflow();
994
    }
995
996
    /**
997
     * Redirect to the current document list.
998
     *
999
     * @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...
1000
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
1001
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
1002
     */
1003
    protected function redirectToDocumentList($message = null)
1004
    {
1005
        $redirectAction = $this->getSessionData('redirectToDocumentListAction');
1006
        $redirectController = $this->getSessionData('redirectToDocumentListController');
1007
        $this->redirect($redirectAction, $redirectController, null, array('message' => $message));
1008
    }
1009
1010
1011
    /**
1012
     * get list view data
1013
     *
1014
     * @param array $stateFilters
1015
     * @param bool $suggestionsOnly
1016
     *
1017
     * @return array
1018
     */
1019
    protected function getListViewData($stateFilters = array(), bool $suggestionsOnly = false)
1020
    {
1021
        $documents = NULL;
1022
        $isWorkspace = $this->security->getUserRole() === Security::ROLE_LIBRARIAN;
1023
1024
        if (
1025
            $this->security->getUserRole() == Security::ROLE_LIBRARIAN ||
1026
            $this->security->getUserRole() == Security::ROLE_RESEARCHER
1027
        ) {
1028
            if ($suggestionsOnly) {
1029
                $documents = $this->documentRepository->findAllDocumentSuggestions(
1030
                    $this->security->getUserRole(),
1031
                    $this->security->getUser()->getUid()
1032
                );
1033
            } else {
1034
                $documents = $this->documentRepository->findAllByRole(
1035
                    $this->security->getUserRole(),
1036
                    $this->security->getUser()->getUid(),
1037
                    $stateFilters
1038
                );
1039
            }
1040
        }
1041
1042
        return array(
1043
            $isWorkspace,
1044
            $documents
1045
        );
1046
    }
1047
1048
    /**
1049
     * Gets the storage PID of the current client
1050
     *
1051
     * @return mixed
1052
     */
1053
    protected function getStoragePID()
1054
    {
1055
        return $this->settings['persistence']['classes']['EWW\Dpf\Domain\Model\Document']['newRecordStoragePid'];
1056
    }
1057
1058
    /**
1059
     *
1060
     * @param \EWW\Dpf\Domain\Model\Document $document
1061
     * @param string $key
1062
     * @param string $severity
1063
     * @param string $defaultMessage
1064
     */
1065
    protected function flashMessage(\EWW\Dpf\Domain\Model\Document $document, $key, $severity, $defaultMessage = "")
1066
    {
1067
1068
        // Show success or failure of the action in a flash message
1069
        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...
1070
            $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...
1071
            $args[] = $document->getObjectIdentifier();
1072
        }
1073
1074
        $message = \TYPO3\CMS\Extbase\Utility\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...
1075
        $message = empty($message) ? $defaultMessage : $message;
1076
1077
        $this->addFlashMessage(
1078
            $message,
1079
            '',
1080
            $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

1080
            /** @scrutinizer ignore-type */ $severity,
Loading history...
1081
            true
1082
        );
1083
1084
    }
1085
}
1086