Completed
Push — master ( 03fc4c...95d208 )
by Ralf
15s queued 12s
created

WorkspaceController::getSortScriptCreatorRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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