Issues (3936)

Classes/Controller/WorkspaceController.php (6 issues)

1
<?php
2
namespace EWW\Dpf\Controller;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use EWW\Dpf\Domain\Model\Bookmark;
18
use EWW\Dpf\Domain\Model\Document;
19
use EWW\Dpf\Security\DocumentVoter;
20
use EWW\Dpf\Security\Security;
21
use EWW\Dpf\Services\Email\Notifier;
22
use EWW\Dpf\Domain\Workflow\DocumentWorkflow;
23
use TYPO3\CMS\Core\Messaging\AbstractMessage;
24
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
25
use EWW\Dpf\Session\SearchSessionData;
26
27
/**
28
 * Controller for the "workspace"/"my publications" area.
29
 */
30
class WorkspaceController extends AbstractController
31
{
32
    /**
33
     * FrontendUserRepository
34
     *
35
     * @var  TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository
0 ignored issues
show
The type EWW\Dpf\Controller\TYPO3...\FrontendUserRepository was not found. Did you mean TYPO3\CMS\Extbase\Domain...\FrontendUserRepository? If so, make sure to prefix the type with \.
Loading history...
36
     * @TYPO3\CMS\Extbase\Annotation\Inject
37
     */
38
    protected $frontendUserRepository;
39
40
    /**
41
     * documentRepository
42
     *
43
     * @var \EWW\Dpf\Domain\Repository\DocumentRepository
44
     * @TYPO3\CMS\Extbase\Annotation\Inject
45
     */
46
    protected $documentRepository = null;
47
48
    /**
49
     * documentTypeRepository
50
     *
51
     * @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository
52
     * @TYPO3\CMS\Extbase\Annotation\Inject
53
     */
54
    protected $documentTypeRepository = null;
55
56
    /**
57
     * bookmarkRepository
58
     *
59
     * @var \EWW\Dpf\Domain\Repository\BookmarkRepository
60
     * @TYPO3\CMS\Extbase\Annotation\Inject
61
     */
62
    protected $bookmarkRepository = null;
63
64
    /**
65
     * elasticSearch
66
     *
67
     * @var \EWW\Dpf\Services\ElasticSearch\ElasticSearch
68
     * @TYPO3\CMS\Extbase\Annotation\Inject
69
     */
70
    protected $elasticSearch = null;
71
72
73
    /**
74
     * queryBuilder
75
     *
76
     * @var \EWW\Dpf\Services\ElasticSearch\QueryBuilder
77
     * @TYPO3\CMS\Extbase\Annotation\Inject
78
     */
79
    protected $queryBuilder = null;
80
81
82
    /**
83
     * documentManager
84
     *
85
     * @var \EWW\Dpf\Services\Document\DocumentManager
86
     * @TYPO3\CMS\Extbase\Annotation\Inject
87
     */
88
    protected $documentManager = null;
89
90
    /**
91
     * documentValidator
92
     *
93
     * @var \EWW\Dpf\Helper\DocumentValidator
94
     * @TYPO3\CMS\Extbase\Annotation\Inject
95
     */
96
    protected $documentValidator;
97
98
    /**
99
     * editingLockService
100
     *
101
     * @var \EWW\Dpf\Services\Document\EditingLockService
102
     * @TYPO3\CMS\Extbase\Annotation\Inject
103
     */
104
    protected $editingLockService = null;
105
106
107
    /**
108
     * metadataGroupRepository
109
     *
110
     * @var \EWW\Dpf\Domain\Repository\MetadataGroupRepository
111
     * @TYPO3\CMS\Extbase\Annotation\Inject
112
     */
113
    protected $metadataGroupRepository;
114
115
    /**
116
     * fisDataService
117
     *
118
     * @var \EWW\Dpf\Services\FeUser\FisDataService
119
     * @TYPO3\CMS\Extbase\Annotation\Inject
120
     */
121
    protected $fisDataService = null;
122
123
124
    public function initializeAction()
125
    {
126
        $this->authorizationChecker->denyAccessUnlessLoggedIn();
127
128
        parent::initializeAction();
129
    }
130
131
    /**
132
     * list
133
     *
134
     * @param int $from
135
     * @return void
136
     */
137
    protected function list($from = 0)
138
    {
139
        $bookmarkIdentifiers = [];
140
        foreach ($this->bookmarkRepository->findByFeUserUid($this->security->getUser()->getUid()) as $bookmark) {
0 ignored issues
show
The method findByFeUserUid() does not exist on EWW\Dpf\Domain\Repository\BookmarkRepository. 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

140
        foreach ($this->bookmarkRepository->/** @scrutinizer ignore-call */ findByFeUserUid($this->security->getUser()->getUid()) as $bookmark) {
Loading history...
141
            $bookmarkIdentifiers[] = $bookmark->getDocumentIdentifier();
142
        }
143
144
        /** @var SearchSessionData $workspaceSessionData */
145
        $workspaceSessionData = $this->session->getWorkspaceData();
146
        $filters = $workspaceSessionData->getFilters();
147
        $excludeFilters = $workspaceSessionData->getExcludeFilters();
148
        $sortField = $workspaceSessionData->getSortField();
149
        $sortOrder = $workspaceSessionData->getSortOrder();
150
151
        if ($this->security->getUserRole() == Security::ROLE_LIBRARIAN) {
152
            $query = $this->getWorkspaceQuery($from, $bookmarkIdentifiers,
153
                $filters, $excludeFilters, $sortField, $sortOrder);
154
        } elseif ($this->security->getUserRole() == Security::ROLE_RESEARCHER) {
155
            $query = $this->getMyPublicationsQuery($from, $bookmarkIdentifiers,
156
                $filters, $excludeFilters, $sortField, $sortOrder);
157
        }
158
159
        try {
160
            $results = $this->elasticSearch->search($query, 'object');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.
Loading history...
161
        } catch (\Exception $e) {
162
            $workspaceSessionData->clearSort();
163
            $workspaceSessionData->clearFilters();
164
            $this->session->setWorkspaceData($workspaceSessionData);
165
            $this->addFlashMessage(
166
                "Error while buildig the list!", '', AbstractMessage::ERROR
167
            );
168
        }
169
170
        if ($this->request->hasArgument('message')) {
171
            $this->view->assign('message', $this->request->getArgument('message'));
172
        }
173
174
        if ($this->request->hasArgument('errorFiles')) {
175
            $this->view->assign('errorFiles', $this->request->getArgument('errorFiles'));
176
        }
177
178
        if ($filters && $results['hits']['total']['value'] < 1) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $filters 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...
179
            $workspaceSessionData->clearSort();
180
            $workspaceSessionData->clearFilters();
181
            $this->session->setWorkspaceData($workspaceSessionData);
182
            list($redirectAction, $redirectController) = $this->session->getStoredAction();
183
            $this->redirect(
184
                $redirectAction, $redirectController, null,
185
                array('message' => [], 'checkedDocumentIdentifiers' => [])
186
            );
187
        }
188
189
        $this->view->assign('documentCount', $results['hits']['total']['value']);
190
        $this->view->assign('documents', $results['hits']['hits']);
191
        $this->view->assign('pages', range(1, $results['hits']['total']['value']));
192
        $this->view->assign('itemsPerPage', $this->itemsPerPage());
193
        $this->view->assign('aggregations', $results['aggregations']);
194
        $this->view->assign('filters', $filters);
195
        $this->view->assign('isHideDiscarded', array_key_exists('aliasState', $excludeFilters));
196
        $this->view->assign('isBookmarksOnly', array_key_exists('bookmarks', $excludeFilters));
197
        $this->view->assign('bookmarkIdentifiers', $bookmarkIdentifiers);
198
199
        if ($this->fisDataService->getPersonData($this->security->getFisPersId())) {
200
            $this->view->assign('currentFisPersId', $this->security->getFisPersId());
201
        }
202
203
        try {
204
            $personGroup = $this->metadataGroupRepository->findPersonGroup();
205
            $this->view->assign('personGroup', $personGroup->getUid());
206
        } catch (\Throwable $e) {
207
            $this->addFlashMessage(
208
                "Missing configuration: Person group.", '', AbstractMessage::ERROR
209
            );
210
        }
211
    }
212
213
    /**
214
     * Lists documents of the workspace
215
     *
216
     * @param array $checkedDocumentIdentifiers
217
     *
218
     * @return void
219
     */
220
    protected function listWorkspaceAction($checkedDocumentIdentifiers = [])
221
    {
222
        $args = $this->request->getArguments();
223
        if ($args['refresh']) {
224
            $workspaceSessionData = $this->session->getWorkspaceData();
225
            $workspaceSessionData->clearSort();
226
            $workspaceSessionData->clearFilters();
227
228
            $this->session->setWorkspaceData($workspaceSessionData);
229
        }
230
231
        if ($this->security->getUserRole() === Security::ROLE_LIBRARIAN) {
232
            $this->view->assign('isWorkspace', true);
233
        } elseif ($this->security->getUserRole() === Security::ROLE_RESEARCHER) {
234
            $this->view->assign('isWorkspace', false);
235
        } else {
236
            $message = LocalizationUtility::translate(
237
                'manager.workspace.accessDenied', 'dpf'
238
            );
239
            $this->addFlashMessage($message, '', AbstractMessage::ERROR);
240
        }
241
242
        $this->session->setStoredAction($this->getCurrentAction(), $this->getCurrentController(),
243
            $this->uriBuilder->getRequest()->getRequestUri()
0 ignored issues
show
The method getRequestUri() does not exist on TYPO3\CMS\Extbase\Mvc\Request. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

243
            $this->uriBuilder->getRequest()->/** @scrutinizer ignore-call */ getRequestUri()
Loading history...
244
        );
245
246
        $currentPage = null;
247
        $pagination = $this->getParametersSafely('@widget_0');
248
        if ($pagination) {
249
            $checkedDocumentIdentifiers = [];
250
            $currentPage = $pagination['currentPage'];
251
        } else {
252
            $currentPage = 1;
253
        }
254
255
        $this->list((empty($currentPage)? 0 : ($currentPage-1) * $this->itemsPerPage()));
256
257
        $this->view->assign('currentPage', $currentPage);
258
        $this->view->assign('workspaceListAction', $this->getCurrentAction());
259
        $this->view->assign('checkedDocumentIdentifiers', $checkedDocumentIdentifiers);
260
    }
261
262
263
    /**
264
     * Batch operations action.
265
     * @param array $listData
266
     */
267
    public function batchAction($listData)
268
    {
269
        if (array_key_exists('action', $listData)) {
270
            $this->forward($listData['action'], null, null, ['listData' => $listData]);
271
        }
272
    }
273
274
    /**
275
     * Batch operation, register documents.
276
     * @param array $listData
277
     * @throws \EWW\Dpf\Exceptions\DocumentMaxSizeErrorException
278
     */
279
    public function batchRegisterAction($listData)
280
    {
281
        $successful = [];
282
        $checkedDocumentIdentifiers = [];
283
284
        if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) {
285
            $checkedDocumentIdentifiers = $listData['documentIdentifiers'];
286
            foreach ($listData['documentIdentifiers'] as $documentIdentifier) {
287
288
                $this->editingLockService->lock(
289
                    $documentIdentifier, $this->security->getUser()->getUid()
290
                );
291
292
                if (is_numeric($documentIdentifier)) {
293
                    $document = $this->documentManager->read($documentIdentifier);
294
295
                    if ($this->authorizationChecker->isGranted(DocumentVoter::REGISTER, $document)) {
296
297
                        if ($this->documentValidator->validate($document)) {
298
299
                            if (
300
                                $this->documentManager->update(
301
                                    $document,
302
                                    DocumentWorkflow::TRANSITION_REGISTER
303
                                )
304
                            ) {
305
                                $this->bookmarkRepository->addBookmark(
306
                                    $document,
307
                                    $this->security->getUser()->getUid()
308
                                );
309
310
                                $successful[] = $documentIdentifier;
311
312
                                $notifier = $this->objectManager->get(Notifier::class);
313
                                $notifier->sendRegisterNotification($document);
314
315
                                // index the document
316
                                $this->signalSlotDispatcher->dispatch(
317
                                    \EWW\Dpf\Controller\AbstractController::class,
318
                                    'indexDocument', [$document]
319
                                );
320
                            }
321
                        }
322
                    }
323
                }
324
            }
325
326
327
            if (sizeof($successful) == 1) {
328
                $locallangKey = 'manager.workspace.batchAction.register.success.singular';
329
            } else {
330
                $locallangKey = 'manager.workspace.batchAction.register.success.plural';
331
            }
332
333
            $message = LocalizationUtility::translate(
334
                $locallangKey,
335
                'dpf',
336
                [sizeof($successful), sizeof($listData['documentIdentifiers'])]
337
            );
338
339
340
            $this->addFlashMessage(
341
                $message, '',
342
                (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING)
343
            );
344
345
        } else {
346
            $message = LocalizationUtility::translate(
347
                'manager.workspace.batchAction.failure',
348
                'dpf');
349
            $this->addFlashMessage($message, '', AbstractMessage::ERROR);
350
        }
351
352
        list($redirectAction, $redirectController) = $this->session->getStoredAction();
353
        $this->redirect(
354
            $redirectAction, $redirectController, null,
355
            array('message' => $message, 'checkedDocumentIdentifiers' =>  $checkedDocumentIdentifiers));
356
    }
357
358
    /**
359
     * Batch operation, set documents to "In progress".
360
     * @param array $listData
361
     */
362
    public function batchSetInProgressAction($listData)
363
    {
364
        $successful = [];
365
        $checkedDocumentIdentifiers = [];
366
367
        if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) {
368
            $checkedDocumentIdentifiers = $listData['documentIdentifiers'];
369
            foreach ($listData['documentIdentifiers'] as $documentIdentifier) {
370
371
                $this->editingLockService->lock(
372
                    $documentIdentifier, $this->security->getUser()->getUid()
373
                );
374
375
                $document = $this->documentManager->read($documentIdentifier);
376
377
                    if ($this->authorizationChecker->isGranted(DocumentVoter::UPDATE, $document)) {
378
379
                        $document->setTemporary(false);
380
381
                            if (
382
                                $this->documentManager->update(
383
                                    $document,
384
                                    DocumentWorkflow::TRANSITION_IN_PROGRESS
385
                                )
386
                            ) {
387
                                $successful[] = $documentIdentifier;
388
389
                                // index the document
390
                                $this->signalSlotDispatcher->dispatch(
391
                                    \EWW\Dpf\Controller\AbstractController::class,
392
                                    'indexDocument', [$document]
393
                                );
394
                            }
395
                    }
396
            }
397
398
            if (sizeof($successful) == 1) {
399
                $locallangKey = 'manager.workspace.batchAction.setInProgress.success.singular';
400
            } else {
401
                $locallangKey = 'manager.workspace.batchAction.setInProgress.success.plural';
402
            }
403
404
            $message = LocalizationUtility::translate(
405
                $locallangKey,
406
                'dpf',
407
                [sizeof($successful), sizeof($listData['documentIdentifiers'])]
408
            );
409
410
            $this->addFlashMessage(
411
                $message, '',
412
                (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING)
413
            );
414
415
        } else {
416
            $message = LocalizationUtility::translate(
417
                'manager.workspace.batchAction.failure',
418
                'dpf');
419
            $this->addFlashMessage($message, '', AbstractMessage::ERROR);
420
        }
421
422
        list($redirectAction, $redirectController) = $this->session->getStoredAction();
423
        $this->redirect(
424
            $redirectAction, $redirectController, null,
425
            array('message' => $message, 'checkedDocumentIdentifiers' =>  $checkedDocumentIdentifiers));
426
    }
427
428
    /**
429
     * Batch operation, remove documents.
430
     * @param array $listData
431
     */
432
    public function batchRemoveAction($listData)
433
    {
434
        $successful = [];
435
        $checkedDocumentIdentifiers = [];
436
437
        if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) {
438
            $checkedDocumentIdentifiers = $listData['documentIdentifiers'];
439
            foreach ($listData['documentIdentifiers'] as $documentIdentifier) {
440
                $feUserUid = $this->security->getUser()->getUid();
441
                $bookmark = $this->bookmarkRepository->findBookmark($feUserUid, $documentIdentifier);
442
                if ($bookmark instanceof Bookmark) {
443
                    $this->bookmarkRepository->remove($bookmark);
444
                    $successful[] = $documentIdentifier;
445
                }
446
            }
447
448
449
            if (sizeof($successful) == 1) {
450
                $locallangKey = 'manager.workspace.batchAction.remove.success.singular';
451
            } else {
452
                $locallangKey = 'manager.workspace.batchAction.remove.success.plural';
453
            }
454
455
            $message = LocalizationUtility::translate(
456
                $locallangKey,
457
                'dpf',
458
                [sizeof($successful), sizeof($listData['documentIdentifiers'])]
459
            );
460
            $this->addFlashMessage(
461
                $message, '',
462
                (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING)
463
            );
464
        } else {
465
            $message = LocalizationUtility::translate(
466
                'manager.workspace.batchAction.failure',
467
                'dpf');
468
            $this->addFlashMessage($message, '', AbstractMessage::ERROR);
469
        }
470
471
        list($redirectAction, $redirectController) = $this->session->getStoredAction();
472
        $this->redirect(
473
            $redirectAction, $redirectController, null,
474
            array('message' => $message, 'checkedDocumentIdentifiers' =>  $checkedDocumentIdentifiers));
475
    }
476
477
478
    /**
479
     * Batch operation, release documents.
480
     * @param array $listData
481
     */
482
    public function batchReleaseValidatedAction($listData)
483
    {
484
        $this->batchRelease($listData, true);
485
    }
486
487
    /**
488
     * Batch operation, release as unvalidated documents.
489
     * @param array $listData
490
     */
491
    public function batchReleaseUnvalidatedAction($listData)
492
    {
493
        $this->batchRelease($listData, false);
494
    }
495
496
497
498
499
    /**
500
     * Batch operation, release documents.
501
     * @param array $listData
502
     * @param bool $validated
503
     */
504
    protected function batchRelease($listData, $validated)
505
    {
506
        $successful = [];
507
        $checkedDocumentIdentifiers = [];
508
509
        if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) {
510
            $checkedDocumentIdentifiers = $listData['documentIdentifiers'];
511
            foreach ($listData['documentIdentifiers'] as $documentIdentifier) {
512
513
                $this->editingLockService->lock(
514
                    $documentIdentifier, $this->security->getUser()->getUid()
515
                );
516
517
                $document = $this->documentManager->read($documentIdentifier);
518
519
                switch ($document->getState()) {
520
                    case DocumentWorkflow::STATE_REGISTERED_NONE:
521
                    case DocumentWorkflow::STATE_DISCARDED_NONE:
522
                    case DocumentWorkflow::STATE_POSTPONED_NONE:
523
                        $documentVoterAttribute = DocumentVoter::RELEASE_PUBLISH;
524
                        $documentWorkflowTransition = DocumentWorkflow::TRANSITION_RELEASE_PUBLISH;
525
                        break;
526
527
                    case DocumentWorkflow::STATE_NONE_DELETED:
528
                    case DocumentWorkflow::STATE_NONE_INACTIVE:
529
                    case DocumentWorkflow::STATE_IN_PROGRESS_DELETED:
530
                    case DocumentWorkflow::STATE_IN_PROGRESS_INACTIVE:
531
                    case DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE:
532
                        $documentVoterAttribute = DocumentVoter::RELEASE_ACTIVATE;
533
                        $documentWorkflowTransition = DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE;
534
                        break;
535
                    default:
536
                        $documentVoterAttribute = null;
537
                        $documentWorkflowTransition = null;
538
                        break;
539
                }
540
541
                if ($this->authorizationChecker->isGranted($documentVoterAttribute, $document)) {
542
543
                    $internalFormat = new \EWW\Dpf\Helper\InternalFormat($document->getXmlData());
544
                    $internalFormat->setValidation($validated);
545
                    $document->setXmlData($internalFormat->getXml());
546
547
                    if ($this->documentManager->update($document, $documentWorkflowTransition)) {
548
                        $successful[] = $documentIdentifier;
549
550
                        $this->bookmarkRepository->removeBookmark(
551
                            $document, $this->security->getUser()->getUid()
552
                        );
553
554
                        //$notifier = $this->objectManager->get(Notifier::class);
555
                        //$notifier->sendRegisterNotification($document);
556
                    }
557
                }
558
            }
559
560
            if (sizeof($successful) == 1) {
561
                $locallangKey = 'manager.workspace.batchAction.release.success.singular';
562
            } else {
563
                $locallangKey = 'manager.workspace.batchAction.release.success.plural';
564
            }
565
566
            $message = LocalizationUtility::translate(
567
                $locallangKey,
568
                'dpf',
569
                [sizeof($successful), sizeof($listData['documentIdentifiers'])]
570
            );
571
            $this->addFlashMessage(
572
                $message, '',
573
                (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING)
574
            );
575
576
            if (sizeof($successful) === 1 ) {
577
                $this->addFlashMessage(
578
                    "1 ".LocalizationUtility::translate("manager.workspace.bookmarkRemoved.singular", "dpf"),
579
                    '',
580
                    AbstractMessage::INFO
581
                );
582
            }
583
584
            if (sizeof($successful) > 1 ) {
585
                $this->addFlashMessage(
586
                    LocalizationUtility::translate(
587
                        "manager.workspace.bookmarkRemoved.plural", "dpf", [sizeof($successful)]
588
                    ),
589
                    '',
590
                    AbstractMessage::INFO
591
                );
592
            }
593
594
        } else {
595
            $message = LocalizationUtility::translate(
596
                'manager.workspace.batchAction.failure',
597
                'dpf');
598
            $this->addFlashMessage($message, '', AbstractMessage::ERROR);
599
        }
600
601
        list($redirectAction, $redirectController) = $this->session->getStoredAction();
602
        $this->redirect(
603
            $redirectAction, $redirectController, null,
604
            array('message' => $message, 'checkedDocumentIdentifiers' =>  $checkedDocumentIdentifiers));
605
606
    }
607
608
    /**
609
     * get list view data for the workspace
610
     *
611
     * @param int $from
612
     * @param array $bookmarkIdentifiers
613
     * @param array $filters
614
     * @param array $excludeFilters
615
     * @param string $sortField
616
     * @param string $sortOrder
617
     *
618
     * @return array
619
     */
620
    protected function getWorkspaceQuery(
621
        $from = 0, $bookmarkIdentifiers = [], $filters = [], $excludeFilters = [], $sortField = null, $sortOrder = null
622
    )
623
    {
624
        $workspaceFilter = [
625
            'bool' => [
626
                'must' => [
627
                    [
628
                        'bool' => [
629
                            'must' => [
630
                                [
631
                                    'term' => [
632
                                        'creator' => $this->security->getUser()->getUid()
633
                                    ]
634
                                ],
635
                                [
636
                                    'bool' => [
637
                                        'should' => [
638
                                            [
639
                                                'term' => [
640
                                                    'state' => DocumentWorkflow::STATE_NEW_NONE
641
                                                ]
642
                                            ]
643
                                        ]
644
                                    ]
645
                                ]
646
                            ]
647
                        ]
648
                    ]
649
                ]
650
            ]
651
        ];
652
653
        return $this->queryBuilder->buildQuery(
654
            $this->itemsPerPage(), $workspaceFilter, $from, $bookmarkIdentifiers, $filters,
655
            $excludeFilters, $sortField, $sortOrder
656
        );
657
    }
658
659
660
    /**
661
     * get list view data for the my publications list.
662
     *
663
     * @param int $from
664
     * @param array $bookmarkIdentifiers
665
     * @param array $filters
666
     * @param array $excludeFilters
667
     * @param string $sortField
668
     * @param string $sortOrder
669
     *
670
     * @return array
671
     */
672
    protected function getMyPublicationsQuery(
673
        $from = 0, $bookmarkIdentifiers = [], $filters = [], $excludeFilters = [], $sortField = null, $sortOrder = null
674
    )
675
    {
676
        $workspaceFilter = [
677
            'bool' => [
678
                'must' => [
679
                    [
680
                        'bool' => [
681
                            'should' => [
682
                                [
683
                                    'term' => [
684
                                        'creator' => $this->security->getUser()->getUid()
685
                                    ]
686
                                ]
687
                            ]
688
                        ]
689
                    ]
690
                ]
691
            ]
692
        ];
693
694
        $fisPersIdFilter =  [
695
            'bool' => [
696
                'must' => [
697
                    [
698
                        'term' => [
699
                            'fobIdentifiers' => $this->security->getFisPersId()
700
                        ]
701
                    ],
702
                    [
703
                        'bool' => [
704
                            'must_not' => [
705
                                'term' => [
706
                                    'state' => DocumentWorkflow::STATE_NEW_NONE
707
                                ]
708
                            ]
709
                        ]
710
                    ]
711
                ]
712
            ],
713
        ];
714
715
        if ($this->security->getFisPersId()) {
716
            $workspaceFilter['bool']['must'][0]['bool']['should'][1] = $fisPersIdFilter;
717
        }
718
719
        return $this->queryBuilder->buildQuery(
720
            $this->itemsPerPage(), $workspaceFilter, $from, $bookmarkIdentifiers, $filters,
721
            $excludeFilters, $sortField, $sortOrder
722
        );
723
    }
724
725
726
    /**
727
     * A temporary solution to initialize the index.
728
     *
729
     * @param int $start
730
     * @param int $stop
731
     * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
732
     */
733
    public function initIndexAction($start = 1, $stop = 100)
734
    {
735
        /** @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher */
736
        $signalSlotDispatcher = $this->objectManager->get(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
737
738
        /** @var \EWW\Dpf\Services\Transfer\DocumentTransferManager $documentTransferManager */
739
        $documentTransferManager = $this->objectManager->get(\EWW\Dpf\Services\Transfer\DocumentTransferManager::class);
740
741
        $fedoraRepository = $this->objectManager->get(\EWW\Dpf\Services\Transfer\FedoraRepository::class);
742
        $documentTransferManager->setRemoteRepository($fedoraRepository);
743
744
        for ($i = $start; $i < $stop; $i++) {
745
            try {
746
                $document = $documentTransferManager->retrieve(
747
                    $this->settings['fedoraPidNamespace'].':' . $i
748
                );
749
750
                if ($document instanceof Document) {
751
                    $state = $document->getState();
752
                    $document->setState(
753
                        str_replace(
754
                            DocumentWorkflow::LOCAL_STATE_IN_PROGRESS,
755
                            DocumentWorkflow::LOCAL_STATE_NONE,
756
                            $state
757
                        )
758
                    );
759
760
                    // index the document
761
                    $signalSlotDispatcher->dispatch(
762
                        \EWW\Dpf\Controller\AbstractController::class,
763
                        'indexDocument', [$document]
764
                    );
765
766
                    $this->documentRepository->remove($document);
767
                }
768
            } catch (\EWW\Dpf\Exceptions\RetrieveDocumentErrorException $e) {
769
                // Nothing to be done.
770
            }
771
        }
772
773
        foreach ($this->documentRepository->findAll() as $document) {
774
775
            $creationDate = $document->getCreationDate();
776
            if (empty($creationDate) && $document->getObjectIdentifier()) {
777
                $creationDate = $document->getCreationDate();
778
            }
779
            $document->setCreationDate($creationDate);
780
            $this->documentRepository->update($document);
781
782
            if (!$document->isTemporary() && !$document->isSuggestion()) {
783
                // index the document
784
                $signalSlotDispatcher->dispatch(
785
                    \EWW\Dpf\Controller\AbstractController::class,
786
                    'indexDocument', [$document]
787
                );
788
            }
789
        }
790
791
    }
792
793
794
    /**
795
     * Action editDocument
796
     *
797
     * @param string $documentIdentifier
798
     * @param string $activeGroup
799
     * @param int $activeGroupIndex
800
     * @return void
801
     */
802
    public function editDocumentAction($documentIdentifier, $activeGroup = '', $activeGroupIndex = 0)
803
    {
804
        $document = $this->documentManager->read(
805
            $documentIdentifier,
806
            $this->security->getUser()->getUID()
0 ignored issues
show
The call to EWW\Dpf\Services\Document\DocumentManager::read() has too many arguments starting with $this->security->getUser()->getUID(). ( Ignorable by Annotation )

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

806
        /** @scrutinizer ignore-call */ 
807
        $document = $this->documentManager->read(

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...
807
        );
808
809
        if ($document instanceof Document) {
810
            if ($this->authorizationChecker->isGranted(DocumentVoter::EDIT, $document)) {
811
                $this->redirect(
812
                    'edit',
813
                    'DocumentFormBackoffice',
814
                    null,
815
                    [
816
                        'document' => $document,
817
                        'activeGroup' => $activeGroup,
818
                        'activeGroupIndex' => $activeGroupIndex
819
                    ]
820
                );
821
            } elseif ($this->authorizationChecker->isGranted(DocumentVoter::SUGGEST_MODIFICATION, $document)) {
822
                $this->redirect(
823
                    'edit',
824
                    'DocumentFormBackoffice',
825
                    null,
826
                    [
827
                        'document' => $document,
828
                        'suggestMod' => true,
829
                        'activeGroup' => $activeGroup,
830
                        'activeGroupIndex' => $activeGroupIndex
831
                    ]
832
                );
833
            } else {
834
                if ($document->getCreator() !== $this->security->getUser()->getUid()) {
835
                    $message = LocalizationUtility::translate(
836
                        'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_edit.accessDenied',
837
                        'dpf',
838
                        array($document->getTitle())
839
                    );
840
                } else {
841
                    $message = LocalizationUtility::translate(
842
                        'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_edit.failureBlocked',
843
                        'dpf',
844
                        array($document->getTitle())
845
                    );
846
                }
847
            }
848
        } else {
849
            $message = LocalizationUtility::translate(
850
                'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.unexpected',
851
                'dpf'
852
            );
853
        }
854
855
        $this->addFlashMessage($message, '', AbstractMessage::ERROR);
856
857
        list($action, $controller, $redirectUri) = $this->session->getStoredAction();
858
859
        if ($redirectUri) {
860
            $this->redirectToUri($redirectUri);
861
        } else {
862
            $this->redirect($action, $controller, null, array('message' => $message));
863
        }
864
865
    }
866
867
868
    /**
869
     * Returns the number of items to be shown per page.
870
     *
871
     * @return int
872
     */
873
    protected function itemsPerPage()
874
    {
875
        /** @var SearchSessionData $workspaceData */
876
        $workspaceData = $this->session->getWorkspaceData();
877
        $itemsPerPage = $workspaceData->getItemsPerPage();
878
879
        $default = ($this->settings['workspaceItemsPerPage'])? $this->settings['workspaceItemsPerPage'] : 10;
880
        return ($itemsPerPage)? $itemsPerPage : $default;
881
    }
882
883
}
884