Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (188)

Classes/Controller/BasketController.php (7 issues)

1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Controller;
14
15
use Kitodo\Dlf\Common\Helper;
16
use Kitodo\Dlf\Domain\Model\ActionLog;
17
use Kitodo\Dlf\Domain\Model\Basket;
18
use Kitodo\Dlf\Domain\Repository\ActionLogRepository;
19
use Kitodo\Dlf\Domain\Repository\MailRepository;
20
use Kitodo\Dlf\Domain\Repository\BasketRepository;
21
use Kitodo\Dlf\Domain\Repository\PrinterRepository;
22
use TYPO3\CMS\Core\Mail\MailMessage;
23
use TYPO3\CMS\Core\Utility\GeneralUtility;
24
use TYPO3\CMS\Core\Utility\MailUtility;
25
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
26
use TYPO3\CMS\Core\Context\Context;
27
28
/**
29
 * Controller class for the plugin 'Basket'.
30
 *
31
 * @package TYPO3
32
 * @subpackage dlf
33
 *
34
 * @access public
35
 */
36
class BasketController extends AbstractController
37
{
38
    /**
39
     * @access protected
40
     * @var BasketRepository
41
     */
42
    protected BasketRepository $basketRepository;
43
44
    /**
45
     * @access public
46
     *
47
     * @param BasketRepository $basketRepository
48
     *
49
     * @return void
50
     */
51
    public function injectBasketRepository(BasketRepository $basketRepository): void
52
    {
53
        $this->basketRepository = $basketRepository;
54
    }
55
56
    /**
57
     * @access protected
58
     * @var MailRepository
59
     */
60
    protected MailRepository $mailRepository;
61
62
    /**
63
     * @access public
64
     *
65
     * @param MailRepository $mailRepository
66
     *
67
     * @return void
68
     */
69
    public function injectMailRepository(MailRepository $mailRepository): void
70
    {
71
        $this->mailRepository = $mailRepository;
72
    }
73
74
    /**
75
     * @access protected
76
     * @var PrinterRepository
77
     */
78
    protected PrinterRepository $printerRepository;
79
80
    /**
81
     * @access public
82
     *
83
     * @param PrinterRepository $printerRepository
84
     *
85
     * @return void
86
     */
87
    public function injectPrinterRepository(PrinterRepository $printerRepository): void
88
    {
89
        $this->printerRepository = $printerRepository;
90
    }
91
92
    /**
93
     * @access protected
94
     * @var ActionLogRepository
95
     */
96
    protected ActionLogRepository $actionLogRepository;
97
98
    /**
99
     * @access public
100
     *
101
     * @param ActionLogRepository $actionLogRepository
102
     *
103
     * @return void
104
     */
105
    public function injectActionLogRepository(ActionLogRepository $actionLogRepository): void
106
    {
107
        $this->actionLogRepository = $actionLogRepository;
108
    }
109
110
    /**
111
     * Different actions which depends on the chosen action (form)
112
     * 
113
     * @access public
114
     *
115
     * @return void
116
     */
117
    public function basketAction(): void
118
    {
119
        $basket = $this->getBasketData();
120
121
        // action remove from basket
122
        if ($this->requestData['basket_action'] === 'remove') {
123
            // remove entry from list
124
            if (isset($this->requestData['selected'])) {
125
                $basket = $this->removeFromBasket($this->requestData, $basket);
126
            }
127
        }
128
        // action remove from basket
129
        if ($this->requestData['basket_action'] == 'download') {
130
            // open selected documents
131
            if (isset($this->requestData['selected'])) {
132
                $pdfUrl = $this->settings['pdfgenerate'];
133
                foreach ($this->requestData['selected'] as $docValue) {
134
                    if ($docValue['id']) {
135
                        $docData = $this->getDocumentData((int) $docValue['id'], $docValue);
136
                        $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
137
                        $this->redirectToUri($pdfUrl);
138
                    }
139
                }
140
            }
141
        }
142
        // action print from basket
143
        if ($this->requestData['print_action']) {
144
            // open selected documents
145
            if (isset($this->requestData['selected'])) {
146
                $this->printDocument();
147
            }
148
        }
149
        // action send mail
150
        if ($this->requestData['mail_action']) {
151
            if (isset($this->requestData['selected'])) {
152
                $this->sendMail();
153
            }
154
        }
155
156
        $this->redirect('main');
157
    }
158
159
    /**
160
     * Add documents to the basket
161
     *
162
     * @access public
163
     *
164
     * @return void
165
     */
166
    public function addAction(): void
167
    {
168
        $basket = $this->getBasketData();
169
170
        if (
171
            !empty($this->requestData['id'])
172
            && $this->requestData['addToBasket']
173
        ) {
174
            $basket = $this->addToBasket($this->requestData, $basket);
0 ignored issues
show
The assignment to $basket is dead and can be removed.
Loading history...
175
        }
176
177
        $this->redirect('main');
178
    }
179
180
    /**
181
     * The main method of the plugin
182
     *
183
     * @access public
184
     *
185
     * @return void
186
     */
187
    public function mainAction(): void
188
    {
189
        $basket = $this->getBasketData();
190
191
        $countDocs = 0;
192
        if ($basket->getDocIds()) {
193
            $countDocs = count(json_decode($basket->getDocIds(), true));
194
        }
195
        $this->view->assign('countDocs', $countDocs);
196
197
        $allMails = $this->mailRepository->findAllWithPid($this->settings['storagePid']);
198
199
        $mailSelect = [];
200
        if ($allMails->count() > 0) {
201
            $mailSelect[0] = htmlspecialchars(LocalizationUtility::translate('basket.chooseMail', 'dlf'));
202
            foreach ($allMails as $mail) {
203
                $mailSelect[$mail->getUid()] = htmlspecialchars($mail->getName()) . ' (' . htmlspecialchars($mail->getMail()) . ')';
204
            }
205
            $this->view->assign('mailSelect', $mailSelect);
206
        }
207
208
        $allPrinter = $this->printerRepository->findAll();
209
210
        $printSelect = [];
211
        if ($allPrinter->count() > 0) {
212
            $printSelect[0] = htmlspecialchars(LocalizationUtility::translate('basket.choosePrinter', 'dlf'));
213
            foreach ($allPrinter as $printer) {
214
                $printSelect[$printer->getUid()] = htmlspecialchars($printer->getLabel());
215
            }
216
            $this->view->assign('printSelect', $printSelect);
217
        }
218
219
        $entries = [];
220
        if ($basket->getDocIds()) {
221
            // get each entry
222
            foreach (json_decode($basket->getDocIds()) as $value) {
223
                $entries[] = $this->getEntry($value);
224
            }
225
            $this->view->assign('entries', $entries);
226
        }
227
    }
228
229
    /**
230
     * The basket data from user session.
231
     * 
232
     * @access protected
233
     *
234
     * @return Basket The found data from user session.
235
     */
236
    protected function getBasketData(): Basket
237
    {
238
        // get user session
239
        $userSession = $GLOBALS['TSFE']->fe_user->getSession();
240
        $context = GeneralUtility::makeInstance(Context::class);
241
242
        // Checking if a user is logged in
243
        $userIsLoggedIn = $context->getPropertyFromAspect('frontend.user', 'isLoggedIn');
244
245
        if ($userIsLoggedIn) {
246
            $basket = $this->basketRepository->findOneByFeUserId((int) $GLOBALS['TSFE']->fe_user->user['uid']);
247
        } else {
248
            $userSession->set('ses', 'tx_dlf_basket', '');
249
            $userSession->dataWasUpdated();
250
            $GLOBALS['TSFE']->fe_user->storeSessionData();
251
252
            $basket = $this->basketRepository->findOneBySessionId($userSession->getIdentifier());
0 ignored issues
show
The method findOneBySessionId() does not exist on Kitodo\Dlf\Domain\Repository\BasketRepository. 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

252
            /** @scrutinizer ignore-call */ 
253
            $basket = $this->basketRepository->findOneBySessionId($userSession->getIdentifier());
Loading history...
253
        }
254
255
        // session does not exist
256
        if ($basket === null) {
257
            // create new basket in db
258
            $basket = GeneralUtility::makeInstance(Basket::class);
259
            $basket->setSessionId($userSession->getIdentifier());
260
            $basket->setFeUserId($userIsLoggedIn ? $GLOBALS['TSFE']->fe_user->user['uid'] : 0);
261
        }
262
263
        return $basket;
264
    }
265
266
    /**
267
     * Return one basket entry
268
     *
269
     * @access protected
270
     *
271
     * @param array $data DocumentData
272
     *
273
     * @return array One basket entry
274
     */
275
    protected function getEntry(array $data): array
276
    {
277
        // TODO: Call to function is_object() with array will always evaluate to false.
278
        // @phpstan-ignore-next-line
279
        if (is_object($data)) {
0 ignored issues
show
The condition is_object($data) is always false.
Loading history...
280
            $data = get_object_vars($data);
281
        }
282
        $id = $data['id'];
283
        $startpage = $data['startpage'];
284
        $endpage = $data['endpage'];
285
        $startX = $data['startX'];
286
        $startY = $data['startY'];
287
        $endX = $data['endX'];
288
        $endY = $data['endY'];
289
        $rotation = $data['rotation'];
290
291
        $docData = $this->getDocumentData((int) $id, $data);
292
293
        $entryArray['BASKETDATA'] = $docData;
294
295
        $entryKey = $id . '_' . $startpage;
296
        if (!empty($startX)) {
297
            $entryKey .= '_' . $startX;
298
        }
299
        if (!empty($endX)) {
300
            $entryKey .= '_' . $endX;
301
        }
302
303
        $entryArray['id'] = $id;
304
        $entryArray['CONTROLS'] = [
305
            'startpage' => $startpage,
306
            'endpage' => $endpage,
307
            'startX' => $startX,
308
            'startY' => $startY,
309
            'endX' => $endX,
310
            'endY' => $endY,
311
            'rotation' => $rotation,
312
        ];
313
314
        $entryArray['NUMBER'] = $docData['record_id'];
315
        $entryArray['key'] = $entryKey;
316
317
        // return one entry
318
        return $entryArray;
319
    }
320
321
    /**
322
     * Returns the download url configured in the basket
323
     *
324
     * @access protected
325
     *
326
     * @param int $id Document id
327
     * @param array $data DocumentData
328
     *
329
     * @return array|false download url or false
330
     */
331
    protected function getDocumentData(int $id, array $data)
332
    {
333
        // get document instance to load further information
334
        $this->loadDocument((int) $id);
335
        if (isset($this->document)) {
336
            // replace url param placeholder
337
            // TODO: Parameter #2 $replace of function str_replace expects array|string, int given.
338
            // @phpstan-ignore-next-line
339
            $urlParams = str_replace("##page##", (int) $data['page'], $this->settings['pdfparams']);
340
            $urlParams = str_replace("##docId##", $this->document->getRecordId(), $urlParams);
341
            // TODO: Parameter #2 $replace of function str_replace expects array|string, int given.
342
            // @phpstan-ignore-next-line
343
            $urlParams = str_replace("##startpage##", (int) $data['startpage'], $urlParams);
344
            if ($data['startpage'] != $data['endpage']) {
345
                $urlParams = str_replace("##endpage##", $data['endpage'] === "" ? "" : (int) $data['endpage'], $urlParams);
346
            } else {
347
                // remove parameter endpage
348
                $urlParams = str_replace(",##endpage##", '', $urlParams);
349
            }
350
            $urlParams = str_replace("##startx##", $data['startX'] === "" ? "" : (int) $data['startX'], $urlParams);
351
            $urlParams = str_replace("##starty##", $data['startY'] === "" ? "" : (int) $data['startY'], $urlParams);
352
            $urlParams = str_replace("##endx##", $data['endX'] === "" ? "" : (int) $data['endX'], $urlParams);
353
            $urlParams = str_replace("##endy##", $data['endY'] === "" ? "" : (int) $data['endY'], $urlParams);
354
            $urlParams = str_replace("##rotation##", $data['rotation'] === "" ? "" : (int) $data['rotation'], $urlParams);
355
356
            $downloadUrl = $this->settings['pdfgenerate'] . $urlParams;
357
358
            $title = $this->document->getTitle();
359
            if (empty($title)) {
360
                $title = LocalizationUtility::translate('basket.noTitle', 'dlf') ? : '';
361
            }
362
363
            // Set page and cutout information
364
            $info = '';
365
            if ($data['startX'] != '' && $data['endX'] != '') {
366
                // cutout
367
                $info .= htmlspecialchars(LocalizationUtility::translate('basket.cutout', 'dlf')) . ' ';
368
            }
369
            if ($data['startpage'] == $data['endpage']) {
370
                // One page
371
                $info .= htmlspecialchars(LocalizationUtility::translate('page', 'dlf')) . ' ' . $data['startpage'];
372
            } else {
373
                $info .= htmlspecialchars(LocalizationUtility::translate('page', 'dlf')) . ' ' . $data['startpage'] . '-' . $data['endpage'];
374
            }
375
            $downloadLink = '<a href="' . $downloadUrl . '" target="_blank">' . htmlspecialchars($title) . '</a> (' . $info . ')';
376
            if ($data['startpage'] == $data['endpage']) {
377
                $pageNums = 1;
378
            } else {
379
                $pageNums = $data['endpage'] - $data['startpage'];
380
            }
381
            return [
382
                'downloadUrl' => $downloadUrl,
383
                'title' => $title,
384
                'info' => $info,
385
                'downloadLink' => $downloadLink,
386
                'pageNums' => $pageNums,
387
                'urlParams' => $urlParams,
388
                'record_id' => $this->document->getRecordId(),
389
            ];
390
        }
391
        return false;
392
    }
393
394
    /**
395
     * Adds documents to the basket and includes JS
396
     *
397
     * @access protected
398
     *
399
     * @param array $piVars piVars
400
     * @param Basket $basket basket object
401
     *
402
     * @return Basket|null Basket data
403
     */
404
    protected function addToBasket(array $piVars, Basket $basket): ?Basket
405
    {
406
        $output = '';
407
408
        if (!$piVars['startpage']) {
409
            $page = 0;
410
        } else {
411
            $page = (int) $piVars['startpage'];
412
        }
413
        if ($page != null || $piVars['addToBasket'] == 'list') {
414
            $documentItem = [
415
                'id' => (int) $piVars['id'],
416
                'startpage' => (int) $piVars['startpage'],
417
                'endpage' => !isset($piVars['endpage']) || $piVars['endpage'] === "" ? "" : (int) $piVars['endpage'],
418
                'startX' => !isset($piVars['startX']) || $piVars['startX'] === "" ? "" : (int) $piVars['startX'],
419
                'startY' => !isset($piVars['startY']) || $piVars['startY'] === "" ? "" : (int) $piVars['startY'],
420
                'endX' => !isset($piVars['endX']) || $piVars['endX'] === "" ? "" : (int) $piVars['endX'],
421
                'endY' => !isset($piVars['endY']) || $piVars['endY'] === "" ? "" : (int) $piVars['endY'],
422
                'rotation' => !isset($piVars['rotation']) || $piVars['rotation'] === "" ? "" : (int) $piVars['rotation']
423
            ];
424
425
            // update basket
426
            if (!empty(json_decode($basket->getDocIds()))) {
0 ignored issues
show
It seems like $basket->getDocIds() can also be of type null; however, parameter $json of json_decode() does only seem to accept string, 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

426
            if (!empty(json_decode(/** @scrutinizer ignore-type */ $basket->getDocIds()))) {
Loading history...
427
                $items = json_decode($basket->getDocIds());
428
                $items = get_object_vars($items);
429
            } else {
430
                $items = [];
431
            }
432
            // get document instance to load further information
433
            $this->loadDocument((int) $documentItem['id']);
434
            if ($this->isDocMissing()) {
435
                // Quit without doing anything if required variables are not set.
436
                return null;
437
            }
438
            // set endpage for toc and subentry based on logid
439
            if (($piVars['addToBasket'] == 'subentry') or ($piVars['addToBasket'] == 'toc')) {
440
                $smLinks = $this->document->getCurrentDocument()->smLinks;
441
                $pageCounter = count($smLinks['l2p'][$piVars['logId']]);
442
                $documentItem['endpage'] = ($documentItem['startpage'] + $pageCounter) - 1;
443
            }
444
            // add whole document
445
            if ($piVars['addToBasket'] == 'list') {
446
                $documentItem['endpage'] = $this->document->getCurrentDocument()->numPages;
447
            }
448
            $arrayKey = $documentItem['id'] . '_' . $page;
449
            if (!empty($documentItem['startX'])) {
450
                $arrayKey .= '_' . $documentItem['startX'];
451
            }
452
            if (!empty($documentItem['endX'])) {
453
                $arrayKey .= '_' . $documentItem['endX'];
454
            }
455
            // do not add more than one identical object
456
            if (!in_array($arrayKey, $items)) {
457
                $items[$arrayKey] = $documentItem;
458
                // replace url param placeholder
459
                // TODO: Parameter #2 $replace of function str_replace expects array|string, int given.
460
                // @phpstan-ignore-next-line
461
                $pdfParams = str_replace("##startpage##", $documentItem['startpage'], $this->settings['pdfparams']);
462
                $pdfParams = str_replace("##docId##", $this->document->getRecordId(), $pdfParams);
463
                $pdfParams = str_replace("##startx##", $documentItem['startX'], $pdfParams);
464
                $pdfParams = str_replace("##starty##", $documentItem['startY'], $pdfParams);
465
                $pdfParams = str_replace("##endx##", $documentItem['endX'], $pdfParams);
466
                $pdfParams = str_replace("##endy##", $documentItem['endY'], $pdfParams);
467
                $pdfParams = str_replace("##rotation##", $documentItem['rotation'], $pdfParams);
468
                if ($documentItem['startpage'] != $documentItem['endpage']) {
469
                    $pdfParams = str_replace("##endpage##", $documentItem['endpage'], $pdfParams);
470
                } else {
471
                    // remove parameter endpage
472
                    $pdfParams = str_replace(",##endpage##", '', $pdfParams);
473
                }
474
                $pdfGenerateUrl = $this->settings['pdfgenerate'] . $pdfParams;
475
                if ($this->settings['pregeneration']) {
476
                    // send ajax request to webapp
477
                    $output .= '
478
     <script>
479
      $(document).ready(function(){
480
       $.ajax({
481
         url: "' . $pdfGenerateUrl . '",
482
       }).done(function() {
483
       });
484
      });
485
     </script>';
486
                }
487
            }
488
489
            $basket->setDocIds(json_encode($items));
490
            if ($basket->getUid() === null) {
491
                $this->basketRepository->add($basket);
492
            } else {
493
                $this->basketRepository->update($basket);
494
            }
495
        }
496
        $this->view->assign('pregenerateJs', $output);
497
498
        return $basket;
499
    }
500
501
    /**
502
     * Removes selected documents from basket
503
     *
504
     * @access protected
505
     *
506
     * @param array $piVars plugin variables
507
     * @param Basket $basket basket object
508
     *
509
     * @return Basket basket
510
     */
511
    protected function removeFromBasket(array $piVars, Basket $basket): Basket
512
    {
513
        if (!empty($basket->getDocIds())) {
514
            $items = json_decode($basket->getDocIds());
515
            $items = get_object_vars($items);
516
        }
517
        foreach ($piVars['selected'] as $value) {
518
            if (isset($value['id'])) {
519
                $arrayKey = $value['id'] . '_' . $value['startpage'];
520
                if (!empty($value['startX'])) {
521
                    $arrayKey .= '_' . $value['startX'];
522
                }
523
                if (!empty($value['endX'])) {
524
                    $arrayKey .= '_' . $value['endX'];
525
                }
526
                if (isset($items[$arrayKey])) {
527
                    unset($items[$arrayKey]);
528
                }
529
            }
530
        }
531
        if (empty($items)) {
532
            $update = '';
533
        } else {
534
            $update = json_encode($items);
535
        }
536
537
        $basket->setDocIds($update);
538
        $this->basketRepository->update($basket);
539
540
        return $basket;
541
    }
542
543
    /**
544
     * Send mail with pdf download url
545
     *
546
     * @access protected
547
     *
548
     * @return void
549
     */
550
    protected function sendMail(): void
551
    {
552
        // send mail
553
        $mailId = $this->requestData['mail_action'];
554
555
        $mailObject = $this->mailRepository->findByUid(intval($mailId))->getFirst();
556
557
        $mailText = htmlspecialchars(LocalizationUtility::translate('basket.mailBody', 'dlf')) . "\n";
558
        $numberOfPages = 0;
559
        $pdfUrl = $this->settings['pdfdownload'];
560
        // prepare links
561
        foreach ($this->requestData['selected'] as $docValue) {
562
            if ($docValue['id']) {
563
                $explodeId = explode("_", $docValue['id']);
564
                $docData = $this->getDocumentData((int) $explodeId[0], $docValue);
565
                $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
566
                $pages = (abs(intval($docValue['startpage']) - intval($docValue['endpage'])));
567
                if ($pages === 0) {
568
                    $numberOfPages = $numberOfPages + 1;
569
                } else {
570
                    $numberOfPages = $numberOfPages + $pages;
571
                }
572
            }
573
        }
574
        // Remove leading/tailing pdfparamseperator
575
        $pdfUrl = trim($pdfUrl, $this->settings['pdfparamseparator']);
576
        $mailBody = $mailText . $pdfUrl;
577
        // Get hook objects.
578
        $hookObjects = Helper::getHookObjects('Classes/Controller/BasketController.php');
579
        // Hook for getting a customized mail body.
580
        foreach ($hookObjects as $hookObj) {
581
            if (method_exists($hookObj, 'customizeMailBody')) {
582
                $mailBody = $hookObj->customizeMailBody($mailText, $pdfUrl);
583
            }
584
        }
585
        $from = MailUtility::getSystemFrom();
586
        // send mail
587
        $mail = GeneralUtility::makeInstance(MailMessage::class);
588
        // Prepare and send the message
589
        $mail
590
            // subject
591
            ->setSubject(LocalizationUtility::translate('basket.mailSubject', 'dlf'))
592
            // Set the From address with an associative array
593
            ->setFrom($from)
594
            // Set the To addresses with an associative array
595
            ->setTo([$mailObject->getMail() => $mailObject->getName()])
596
            ->setBody($mailBody, 'text/html')
597
            ->send();
598
599
        // create entry for action log
600
        $newActionLog = GeneralUtility::makeInstance(ActionLog::class);
601
        $newActionLog->setFileName($pdfUrl);
602
        $newActionLog->setCountPages($numberOfPages);
603
        $newActionLog->setLabel('Mail: ' . $mailObject->getMail());
604
605
        if ($GLOBALS["TSFE"]->loginUser) {
606
            // internal user
607
            $newActionLog->setUserId($GLOBALS["TSFE"]->fe_user->user['uid']);
608
            $newActionLog->setName($GLOBALS["TSFE"]->fe_user->user['username']);
609
        } else {
610
            // external user
611
            $newActionLog->setUserId(0);
612
            $newActionLog->setName('n/a');
613
        }
614
615
        $this->actionLogRepository->add($newActionLog);
616
617
        $this->redirect('main');
618
    }
619
620
    /**
621
     * Sends document information to an external printer (url)
622
     *
623
     * @access protected
624
     *
625
     * @return void
626
     */
627
    protected function printDocument(): void
628
    {
629
        $pdfUrl = $this->settings['pdfprint'];
630
        $numberOfPages = 0;
631
        foreach ($this->requestData['selected'] as $docId => $docValue) {
632
            if ($docValue['id']) {
633
                $docData = $this->getDocumentData((int) $docValue['id'], $docValue);
634
                $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
635
                $numberOfPages += $docData['pageNums'];
636
            }
637
        }
638
        // get printer data
639
        $printerId = $this->requestData['print_action'];
640
641
        // get id from db and send selected doc download link
642
        $printer = $this->printerRepository->findOneByUid($printerId);
0 ignored issues
show
The method findOneByUid() does not exist on Kitodo\Dlf\Domain\Repository\PrinterRepository. 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

642
        /** @scrutinizer ignore-call */ 
643
        $printer = $this->printerRepository->findOneByUid($printerId);
Loading history...
643
644
        // printer is selected
645
        if ($printer) {
646
            $pdfUrl = $printer->getPrint();
0 ignored issues
show
The method getPrint() does not exist on TYPO3\CMS\Extbase\Persistence\QueryResultInterface. ( Ignorable by Annotation )

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

646
            /** @scrutinizer ignore-call */ 
647
            $pdfUrl = $printer->getPrint();

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...
647
            $numberOfPages = 0;
648
            foreach ($this->requestData['selected'] as $docId => $docValue) {
649
                if ($docValue['id']) {
650
                    $explodeId = explode("_", $docId);
651
                    $docData = $this->getDocumentData((int) $explodeId[0], $docValue);
652
                    $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
653
                    $numberOfPages += $docData['pageNums'];
654
                }
655
            }
656
            $pdfUrl = trim($pdfUrl, $this->settings['pdfparamseparator']);
657
        }
658
659
        $actionLog = GeneralUtility::makeInstance(ActionLog::class);
660
        // protocol
661
        $actionLog->setPid($this->settings['storagePid']);
662
        $actionLog->setFileName($pdfUrl);
663
        $actionLog->setCountPages($numberOfPages);
664
665
        if ($GLOBALS["TSFE"]->loginUser) {
666
            // internal user
667
            $actionLog->setUserId($GLOBALS["TSFE"]->fe_user->user['uid']);
668
            $actionLog->setName($GLOBALS["TSFE"]->fe_user->user['username']);
669
            $actionLog->setLabel('Print: ' . $printer->getLabel());
0 ignored issues
show
The method getLabel() does not exist on TYPO3\CMS\Extbase\Persistence\QueryResultInterface. ( Ignorable by Annotation )

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

669
            $actionLog->setLabel('Print: ' . $printer->/** @scrutinizer ignore-call */ getLabel());

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...
670
        } else {
671
            // external user
672
            $actionLog->setUserId(0);
673
            $actionLog->setName('n/a');
674
            $actionLog->setLabel('Print: ' . $printer->getLabel());
675
        }
676
        // add action to protocol
677
        $this->actionLogRepository->add($actionLog);
678
679
        $this->redirectToUri($pdfUrl);
680
    }
681
}
682