Passed
Pull Request — master (#168)
by
unknown
20:44
created

WorkspaceController::buildSortQueryPart()   B

Complexity

Conditions 9
Paths 45

Size

Total Lines 40
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 26
c 1
b 0
f 0
nc 45
nop 2
dl 0
loc 40
rs 8.0555
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
Bug introduced by
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
     * @inject
37
     */
38
    protected $frontendUserRepository;
39
40
    /**
41
     * documentRepository
42
     *
43
     * @var \EWW\Dpf\Domain\Repository\DocumentRepository
44
     * @inject
45
     */
46
    protected $documentRepository = null;
47
48
    /**
49
     * documentTypeRepository
50
     *
51
     * @var \EWW\Dpf\Domain\Repository\DocumentTypeRepository
52
     * @inject
53
     */
54
    protected $documentTypeRepository = null;
55
56
    /**
57
     * bookmarkRepository
58
     *
59
     * @var \EWW\Dpf\Domain\Repository\BookmarkRepository
60
     * @inject
61
     */
62
    protected $bookmarkRepository = null;
63
64
    /**
65
     * elasticSearch
66
     *
67
     * @var \EWW\Dpf\Services\ElasticSearch\ElasticSearch
68
     * @inject
69
     */
70
    protected $elasticSearch = null;
71
72
73
    /**
74
     * queryBuilder
75
     *
76
     * @var \EWW\Dpf\Services\ElasticSearch\QueryBuilder
77
     * @inject
78
     */
79
    protected $queryBuilder = null;
80
81
    /**
82
     * documentManager
83
     *
84
     * @var \EWW\Dpf\Services\Document\DocumentManager
85
     * @inject
86
     */
87
    protected $documentManager = null;
88
89
    /**
90
     * documentValidator
91
     *
92
     * @var \EWW\Dpf\Helper\DocumentValidator
93
     * @inject
94
     */
95
    protected $documentValidator;
96
97
    /**
98
     * editingLockService
99
     *
100
     * @var \EWW\Dpf\Services\Document\EditingLockService
101
     * @inject
102
     */
103
    protected $editingLockService = null;
104
105
106
    /**
107
     * list
108
     *
109
     * @param int $from
110
     * @return void
111
     */
112
    protected function list($from = 0)
113
    {
114
        $bookmarkIdentifiers = [];
115
        foreach ($this->bookmarkRepository->findByFeUserUid($this->security->getUser()->getUid()) as $bookmark) {
0 ignored issues
show
Bug introduced by
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

115
        foreach ($this->bookmarkRepository->/** @scrutinizer ignore-call */ findByFeUserUid($this->security->getUser()->getUid()) as $bookmark) {
Loading history...
116
            $bookmarkIdentifiers[] = $bookmark->getDocumentIdentifier();
117
        }
118
119
        /** @var SearchSessionData $workspaceSessionData */
120
        $workspaceSessionData = $this->session->getWorkspaceData();
121
        $filters = $workspaceSessionData->getFilters();
122
        $excludeFilters = $workspaceSessionData->getExcludeFilters();
123
        $sortField = $workspaceSessionData->getSortField();
124
        $sortOrder = $workspaceSessionData->getSortOrder();
125
126
        if ($this->security->getUser()->getUserRole() == Security::ROLE_LIBRARIAN) {
127
            $query = $this->getWorkspaceQuery($from, $bookmarkIdentifiers,
128
                $filters, $excludeFilters, $sortField, $sortOrder);
129
        } elseif ($this->security->getUser()->getUserRole() == Security::ROLE_RESEARCHER) {
130
            $query = $this->getMyPublicationsQuery($from, $bookmarkIdentifiers,
131
                $filters, $excludeFilters, $sortField, $sortOrder);
132
        }
133
134
        try {
135
            $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...
136
        } catch (\Exception $e) {
137
            $workspaceSessionData->clearSort();
138
            $workspaceSessionData->clearFilters();
139
            $this->session->setWorkspaceData($workspaceSessionData);
140
            $this->addFlashMessage(
141
                "Error while buildig the list!", '', AbstractMessage::ERROR
142
            );
143
        }
144
145
        if ($this->request->hasArgument('message')) {
146
            $this->view->assign('message', $this->request->getArgument('message'));
147
        }
148
149
        if ($this->request->hasArgument('errorFiles')) {
150
            $this->view->assign('errorFiles', $this->request->getArgument('errorFiles'));
151
        }
152
153
        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...
154
            $this->session->clearFilter();
0 ignored issues
show
Bug introduced by
The method clearFilter() does not exist on EWW\Dpf\Session\Session. ( Ignorable by Annotation )

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

154
            $this->session->/** @scrutinizer ignore-call */ 
155
                            clearFilter();

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...
155
            list($redirectAction, $redirectController) = $this->session->getListAction();
156
            $this->redirect(
157
                $redirectAction, $redirectController, null,
158
                array('message' => [], 'checkedDocumentIdentifiers' => [])
159
            );
160
        }
161
162
        $this->view->assign('documentCount', $results['hits']['total']['value']);
163
        $this->view->assign('documents', $results['hits']['hits']);
164
        $this->view->assign('pages', range(1, $results['hits']['total']['value']));
165
        $this->view->assign('itemsPerPage', $this->itemsPerPage());
166
        $this->view->assign('aggregations', $results['aggregations']);
167
        $this->view->assign('filters', $filters);
168
        $this->view->assign('isHideDiscarded', array_key_exists('aliasState', $excludeFilters));
169
        $this->view->assign('isBookmarksOnly', array_key_exists('bookmarks', $excludeFilters));
170
        $this->view->assign('bookmarkIdentifiers', $bookmarkIdentifiers);
171
    }
172
173
    /**
174
     * Lists documents of the workspace
175
     *
176
     * @param array $checkedDocumentIdentifiers
177
     *
178
     * @return void
179
     */
180
    protected function listWorkspaceAction($checkedDocumentIdentifiers = [])
181
    {
182
        $args = $this->request->getArguments();
183
        if ($args['refresh']) {
184
            $workspaceSessionData = $this->session->getWorkspaceData();
185
            $workspaceSessionData->clearSort();
186
            $workspaceSessionData->clearFilters();
187
188
            $this->session->setWorkspaceData($workspaceSessionData);
189
        }
190
191
        if ($this->security->getUser()->getUserRole() === Security::ROLE_LIBRARIAN) {
192
            $this->view->assign('isWorkspace', true);
193
        } elseif ($this->security->getUser()->getUserRole() === Security::ROLE_RESEARCHER) {
194
            $this->view->assign('isWorkspace', false);
195
        } else {
196
            $message = LocalizationUtility::translate(
197
                'manager.workspace.accessDenied', 'dpf'
198
            );
199
            $this->addFlashMessage($message, '', AbstractMessage::ERROR);
200
        }
201
202
        $this->session->setListAction($this->getCurrentAction(), $this->getCurrentController(),
203
            $this->uriBuilder->getRequest()->getRequestUri()
0 ignored issues
show
introduced by
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

203
            $this->uriBuilder->getRequest()->/** @scrutinizer ignore-call */ getRequestUri()
Loading history...
204
        );
205
206
        $currentPage = null;
207
        $pagination = $this->getParametersSafely('@widget_0');
208
        if ($pagination) {
209
            $checkedDocumentIdentifiers = [];
210
            $currentPage = $pagination['currentPage'];
211
        } else {
212
            $currentPage = 1;
213
        }
214
215
        $this->list((empty($currentPage)? 0 : ($currentPage-1) * $this->itemsPerPage()));
216
217
        $this->view->assign('currentPage', $currentPage);
218
        $this->view->assign('workspaceListAction', $this->getCurrentAction());
219
        $this->view->assign('checkedDocumentIdentifiers', $checkedDocumentIdentifiers);
220
    }
221
222
223
    /**
224
     * Batch operations action.
225
     * @param array $listData
226
     */
227
    public function batchAction($listData)
228
    {
229
        if (array_key_exists('action', $listData)) {
230
            $this->forward($listData['action'], null, null, ['listData' => $listData]);
231
        }
232
    }
233
234
    /**
235
     * Batch operation, register documents.
236
     * @param array $listData
237
     * @throws \EWW\Dpf\Exceptions\DocumentMaxSizeErrorException
238
     */
239
    public function batchRegisterAction($listData)
240
    {
241
        $successful = [];
242
        $checkedDocumentIdentifiers = [];
243
244
        if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) {
245
            $checkedDocumentIdentifiers = $listData['documentIdentifiers'];
246
            foreach ($listData['documentIdentifiers'] as $documentIdentifier) {
247
248
                $this->editingLockService->lock(
249
                    $documentIdentifier, $this->security->getUser()->getUid()
250
                );
251
252
                if (is_numeric($documentIdentifier)) {
253
                    $document = $this->documentManager->read($documentIdentifier);
254
255
                    if ($this->authorizationChecker->isGranted(DocumentVoter::REGISTER, $document)) {
256
257
                        if ($this->documentValidator->validate($document)) {
0 ignored issues
show
Bug introduced by
It seems like $document can also be of type null; however, parameter $document of EWW\Dpf\Helper\DocumentValidator::validate() does only seem to accept EWW\Dpf\Domain\Model\Document, 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

257
                        if ($this->documentValidator->validate(/** @scrutinizer ignore-type */ $document)) {
Loading history...
258
259
                            if (
260
                                $this->documentManager->update(
261
                                    $document,
0 ignored issues
show
Bug introduced by
It seems like $document can also be of type null; however, parameter $document of EWW\Dpf\Services\Documen...cumentManager::update() does only seem to accept EWW\Dpf\Domain\Model\Document, 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

261
                                    /** @scrutinizer ignore-type */ $document,
Loading history...
262
                                    DocumentWorkflow::TRANSITION_REGISTER
263
                                )
264
                            ) {
265
                                $this->bookmarkRepository->addBookmark(
266
                                    $this->security->getUser()->getUid(), $document
267
                                );
268
269
                                $successful[] = $documentIdentifier;
270
271
                                $notifier = $this->objectManager->get(Notifier::class);
272
                                $notifier->sendRegisterNotification($document);
273
274
                                // index the document
275
                                $this->signalSlotDispatcher->dispatch(
276
                                    \EWW\Dpf\Controller\AbstractController::class,
277
                                    'indexDocument', [$document]
278
                                );
279
                            }
280
                        }
281
                    }
282
                }
283
            }
284
285
286
            if (sizeof($successful) == 1) {
287
                $locallangKey = 'manager.workspace.batchAction.register.success.singular';
288
            } else {
289
                $locallangKey = 'manager.workspace.batchAction.register.success.plural';
290
            }
291
292
            $message = LocalizationUtility::translate(
293
                $locallangKey,
294
                'dpf',
295
                [sizeof($successful), sizeof($listData['documentIdentifiers'])]
296
            );
297
298
299
            $this->addFlashMessage(
300
                $message, '',
301
                (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING)
302
            );
303
304
        } else {
305
            $message = LocalizationUtility::translate(
306
                'manager.workspace.batchAction.failure',
307
                'dpf');
308
            $this->addFlashMessage($message, '', AbstractMessage::ERROR);
309
        }
310
311
        list($redirectAction, $redirectController) = $this->session->getListAction();
312
        $this->redirect(
313
            $redirectAction, $redirectController, null,
314
            array('message' => $message, 'checkedDocumentIdentifiers' =>  $checkedDocumentIdentifiers));
315
    }
316
317
    /**
318
     * Batch operation, remove documents.
319
     * @param array $listData
320
     */
321
    public function batchRemoveAction($listData)
322
    {
323
        $successful = [];
324
        $checkedDocumentIdentifiers = [];
325
326
        if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) {
327
            $checkedDocumentIdentifiers = $listData['documentIdentifiers'];
328
            foreach ($listData['documentIdentifiers'] as $documentIdentifier) {
329
                $feUserUid = $this->security->getUser()->getUid();
330
                $bookmark = $this->bookmarkRepository->findBookmark($feUserUid, $documentIdentifier);
331
                if ($bookmark instanceof Bookmark) {
332
                    $this->bookmarkRepository->remove($bookmark);
333
                    $successful[] = $documentIdentifier;
334
                }
335
            }
336
337
338
            if (sizeof($successful) == 1) {
339
                $locallangKey = 'manager.workspace.batchAction.remove.success.singular';
340
            } else {
341
                $locallangKey = 'manager.workspace.batchAction.remove.success.plural';
342
            }
343
344
            $message = LocalizationUtility::translate(
345
                $locallangKey,
346
                'dpf',
347
                [sizeof($successful), sizeof($listData['documentIdentifiers'])]
348
            );
349
            $this->addFlashMessage(
350
                $message, '',
351
                (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING)
352
            );
353
        } else {
354
            $message = LocalizationUtility::translate(
355
                'manager.workspace.batchAction.failure',
356
                'dpf');
357
            $this->addFlashMessage($message, '', AbstractMessage::ERROR);
358
        }
359
360
        list($redirectAction, $redirectController) = $this->session->getListAction();
361
        $this->redirect(
362
            $redirectAction, $redirectController, null,
363
            array('message' => $message, 'checkedDocumentIdentifiers' =>  $checkedDocumentIdentifiers));
364
    }
365
366
367
    /**
368
     * Batch operation, release documents.
369
     * @param array $listData
370
     */
371
    public function batchReleaseValidatedAction($listData)
372
    {
373
        $this->batchRelease($listData, true);
374
    }
375
376
    /**
377
     * Batch operation, release as unvalidated documents.
378
     * @param array $listData
379
     */
380
    public function batchReleaseUnvalidatedAction($listData)
381
    {
382
        $this->batchRelease($listData, false);
383
    }
384
385
386
387
388
    /**
389
     * Batch operation, release documents.
390
     * @param array $listData
391
     * @param bool $validated
392
     */
393
    protected function batchRelease($listData, $validated)
394
    {
395
        $successful = [];
396
        $checkedDocumentIdentifiers = [];
397
398
        if (array_key_exists('documentIdentifiers', $listData) && is_array($listData['documentIdentifiers']) ) {
399
            $checkedDocumentIdentifiers = $listData['documentIdentifiers'];
400
            foreach ($listData['documentIdentifiers'] as $documentIdentifier) {
401
402
                $this->editingLockService->lock(
403
                    $documentIdentifier, $this->security->getUser()->getUid()
404
                );
405
406
                $document = $this->documentManager->read($documentIdentifier);
407
408
                switch ($document->getState()) {
409
                    case DocumentWorkflow::STATE_REGISTERED_NONE:
410
                    case DocumentWorkflow::STATE_DISCARDED_NONE:
411
                    case DocumentWorkflow::STATE_POSTPONED_NONE:
412
                        $documentVoterAttribute = DocumentVoter::RELEASE_PUBLISH;
413
                        $documentWorkflowTransition = DocumentWorkflow::TRANSITION_RELEASE_PUBLISH;
414
                        break;
415
416
                    case DocumentWorkflow::STATE_NONE_DELETED:
417
                    case DocumentWorkflow::STATE_NONE_INACTIVE:
418
                    case DocumentWorkflow::STATE_IN_PROGRESS_DELETED:
419
                    case DocumentWorkflow::STATE_IN_PROGRESS_INACTIVE:
420
                    case DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE:
421
                        $documentVoterAttribute = DocumentVoter::RELEASE_ACTIVATE;
422
                        $documentWorkflowTransition = DocumentWorkflow::TRANSITION_RELEASE_ACTIVATE;
423
                        break;
424
                    default:
425
                        $documentVoterAttribute = null;
426
                        $documentWorkflowTransition = null;
427
                        break;
428
                }
429
430
                if ($this->authorizationChecker->isGranted($documentVoterAttribute, $document)) {
431
432
                    $slub = new \EWW\Dpf\Helper\Slub($document->getSlubInfoData());
433
434
                    $slub->setValidation($validated);
435
                    $document->setSlubInfoData($slub->getSlubXml());
436
437
                    if ($this->documentManager->update($document, $documentWorkflowTransition)) {
0 ignored issues
show
Bug introduced by
It seems like $document can also be of type null; however, parameter $document of EWW\Dpf\Services\Documen...cumentManager::update() does only seem to accept EWW\Dpf\Domain\Model\Document, 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

437
                    if ($this->documentManager->update(/** @scrutinizer ignore-type */ $document, $documentWorkflowTransition)) {
Loading history...
438
                        $successful[] = $documentIdentifier;
439
440
                        $this->bookmarkRepository->removeBookmark(
441
                            $document, $this->security->getUser()->getUid()
442
                        );
443
444
                        //$notifier = $this->objectManager->get(Notifier::class);
445
                        //$notifier->sendRegisterNotification($document);
446
                    }
447
                }
448
            }
449
450
            if (sizeof($successful) == 1) {
451
                $locallangKey = 'manager.workspace.batchAction.release.success.singular';
452
            } else {
453
                $locallangKey = 'manager.workspace.batchAction.release.success.plural';
454
            }
455
456
            $message = LocalizationUtility::translate(
457
                $locallangKey,
458
                'dpf',
459
                [sizeof($successful), sizeof($listData['documentIdentifiers'])]
460
            );
461
            $this->addFlashMessage(
462
                $message, '',
463
                (sizeof($successful) > 0 ? AbstractMessage::OK : AbstractMessage::WARNING)
464
            );
465
466
            if (sizeof($successful) === 1 ) {
467
                $this->addFlashMessage(
468
                    "1 ".LocalizationUtility::translate("manager.workspace.bookmarkRemoved.singular", "dpf"),
469
                    '',
470
                    AbstractMessage::INFO
471
                );
472
            }
473
474
            if (sizeof($successful) > 1 ) {
475
                $this->addFlashMessage(
476
                    LocalizationUtility::translate(
477
                        "manager.workspace.bookmarkRemoved.plural", "dpf", [sizeof($successful)]
478
                    ),
479
                    '',
480
                    AbstractMessage::INFO
481
                );
482
            }
483
484
        } else {
485
            $message = LocalizationUtility::translate(
486
                'manager.workspace.batchAction.failure',
487
                'dpf');
488
            $this->addFlashMessage($message, '', AbstractMessage::ERROR);
489
        }
490
491
        list($redirectAction, $redirectController) = $this->session->getListAction();
492
        $this->redirect(
493
            $redirectAction, $redirectController, null,
494
            array('message' => $message, 'checkedDocumentIdentifiers' =>  $checkedDocumentIdentifiers));
495
496
    }
497
498
    /**
499
     * get list view data for the workspace
500
     *
501
     * @param int $from
502
     * @param array $bookmarkIdentifiers
503
     * @param array $filters
504
     * @param array $excludeFilters
505
     * @param string $sortField
506
     * @param string $sortOrder
507
     *
508
     * @return array
509
     */
510
    protected function getWorkspaceQuery(
511
        $from = 0, $bookmarkIdentifiers = [], $filters = [], $excludeFilters = [], $sortField = null, $sortOrder = null
512
    )
513
    {
514
        $workspaceFilter = [
515
            'bool' => [
516
                'must' => [
517
                    [
518
                        'bool' => [
519
                            'must' => [
520
                                [
521
                                    'term' => [
522
                                        'creator' => $this->security->getUser()->getUid()
523
                                    ]
524
                                ],
525
                                [
526
                                    'bool' => [
527
                                        'should' => [
528
                                            [
529
                                                'term' => [
530
                                                    'state' => DocumentWorkflow::STATE_NEW_NONE
531
                                                ]
532
                                            ]
533
                                        ]
534
                                    ]
535
                                ]
536
                            ]
537
                        ]
538
                    ]
539
                ]
540
            ]
541
        ];
542
543
        return $this->queryBuilder->buildQuery(
544
            $this->itemsPerPage(), $workspaceFilter, $from, $bookmarkIdentifiers, $filters,
545
            $excludeFilters, $sortField, $sortOrder
546
        );
547
    }
548
549
550
    /**
551
     * get list view data for the my publications list.
552
     *
553
     * @param int $from
554
     * @param array $bookmarkIdentifiers
555
     * @param array $filters
556
     * @param array $excludeFilters
557
     * @param string $sortField
558
     * @param string $sortOrder
559
     *
560
     * @return array
561
     */
562
    protected function getMyPublicationsQuery(
563
        $from = 0, $bookmarkIdentifiers = [], $filters = [], $excludeFilters = [], $sortField = null, $sortOrder = null
564
    )
565
    {
566
        $workspaceFilter = [
567
            'bool' => [
568
                'must' => [
569
                    [
570
                        'term' => [
571
                            'creator' => $this->security->getUser()->getUid()
572
                        ]
573
                    ]
574
                ]
575
            ]
576
        ];
577
578
        return $this->queryBuilder->buildQuery(
579
            $this->itemsPerPage(), $workspaceFilter, $from, $bookmarkIdentifiers, $filters,
580
            $excludeFilters, $sortField, $sortOrder
581
        );
582
    }
583
584
585
    /**
586
     * A temporary solution to initialize the index.
587
     *
588
     * @param int $start
589
     * @param int $stop
590
     * @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
591
     */
592
    public function initIndexAction($start = 1, $stop = 100)
593
    {
594
        /** @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher */
595
        $signalSlotDispatcher = $this->objectManager->get(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
596
597
        /** @var \EWW\Dpf\Services\Transfer\DocumentTransferManager $documentTransferManager */
598
        $documentTransferManager = $this->objectManager->get(\EWW\Dpf\Services\Transfer\DocumentTransferManager::class);
599
600
        $fedoraRepository = $this->objectManager->get(\EWW\Dpf\Services\Transfer\FedoraRepository::class);
601
        $documentTransferManager->setRemoteRepository($fedoraRepository);
602
603
        for ($i = $start; $i < $stop; $i++) {
604
            try {
605
                $document = $documentTransferManager->retrieve('qucosa:' . $i);
606
607
                if ($document instanceof Document) {
608
                    $state = $document->getState();
609
                    $document->setState(
610
                        str_replace(
611
                            DocumentWorkflow::LOCAL_STATE_IN_PROGRESS,
612
                            DocumentWorkflow::LOCAL_STATE_NONE,
613
                            $state
614
                        )
615
                    );
616
617
                    // index the document
618
                    $signalSlotDispatcher->dispatch(
619
                        \EWW\Dpf\Controller\AbstractController::class,
620
                        'indexDocument', [$document]
621
                    );
622
623
                    $this->documentRepository->remove($document);
624
                }
625
            } catch (\EWW\Dpf\Exceptions\RetrieveDocumentErrorException $e) {
626
                // Nothing to be done.
627
            }
628
        }
629
630
        foreach ($this->documentRepository->findAll() as $document) {
631
            if (!$document->isTemporary() && !$document->isSuggestion()) {
632
                // index the document
633
                $signalSlotDispatcher->dispatch(
634
                    \EWW\Dpf\Controller\AbstractController::class,
635
                    'indexDocument', [$document]
636
                );
637
            }
638
        }
639
    }
640
641
642
    /**
643
     * action uploadFiles
644
     *
645
     * @param string $documentIdentifier
646
     * @return void
647
     */
648
    public function uploadFilesAction($documentIdentifier)
649
    {
650
        $document = $this->documentManager->read(
651
            $documentIdentifier,
652
            $this->security->getUser()->getUID()
0 ignored issues
show
Unused Code introduced by
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

652
        /** @scrutinizer ignore-call */ 
653
        $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...
653
        );
654
655
        if ($document instanceof Document) {
656
            if ($this->authorizationChecker->isGranted(DocumentVoter::EDIT, $document)) {
657
                $this->redirect(
658
                    'edit',
659
                    'DocumentFormBackoffice',
660
                    null,
661
                    ['document' => $document, 'activeFileTab' => true]);
662
            } elseif ($this->authorizationChecker->isGranted(DocumentVoter::SUGGEST_MODIFICATION, $document)) {
663
                $this->redirect(
664
                    'edit',
665
                    'DocumentFormBackoffice',
666
                    null,
667
                    ['document' => $document, 'suggestMod' => true, 'activeFileTab' => true]);
668
            } else {
669
                if ($document->getCreator() !== $this->security->getUser()->getUid()) {
670
                    $message = LocalizationUtility::translate(
671
                        'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_edit.accessDenied',
672
                        'dpf',
673
                        array($document->getTitle())
674
                    );
675
                } else {
676
                    $message = LocalizationUtility::translate(
677
                        'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:document_edit.failureBlocked',
678
                        'dpf',
679
                        array($document->getTitle())
680
                    );
681
                }
682
            }
683
        } else {
684
            $message = LocalizationUtility::translate(
685
                'LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:error.unexpected',
686
                'dpf'
687
            );
688
        }
689
690
        $this->addFlashMessage($message, '', AbstractMessage::ERROR);
691
692
        list($action, $controller, $redirectUri) = $this->session->getListAction();
693
694
        if ($redirectUri) {
695
            $this->redirectToUri($redirectUri);
696
        } else {
697
            $this->redirect($action, $controller, null, array('message' => $message));
698
        }
699
700
    }
701
702
703
    /**
704
     * Returns the number of items to be shown per page.
705
     *
706
     * @return int
707
     */
708
    protected function itemsPerPage()
709
    {
710
        /** @var SearchSessionData $workspaceData */
711
        $workspaceData = $this->session->getWorkspaceData();
712
        $itemsPerPage = $workspaceData->getItemsPerPage();
713
714
        $default = ($this->settings['workspaceItemsPerPage'])? $this->settings['workspaceItemsPerPage'] : 10;
715
        return ($itemsPerPage)? $itemsPerPage : $default;
716
    }
717
718
}
719