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.
Passed
Pull Request — master (#715)
by Alexander
07:45
created

BasketController::getBasketData()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 5
b 0
f 0
nc 4
nop 0
dl 0
loc 23
rs 9.8333
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\Doc;
16
use Kitodo\Dlf\Common\Helper;
17
use Kitodo\Dlf\Domain\Model\ActionLog;
18
use Kitodo\Dlf\Domain\Model\Basket;
19
use Kitodo\Dlf\Domain\Repository\ActionLogRepository;
20
use Kitodo\Dlf\Domain\Repository\MailRepository;
21
use Kitodo\Dlf\Domain\Repository\BasketRepository;
22
use Kitodo\Dlf\Domain\Repository\PrinterRepository;
23
use TYPO3\CMS\Core\Utility\GeneralUtility;
24
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
25
26
class BasketController extends AbstractController
27
{
28
    /**
29
     * @var BasketRepository
30
     */
31
    protected $basketRepository;
32
33
    /**
34
     * @param BasketRepository $basketRepository
35
     */
36
    public function injectBasketRepository(BasketRepository $basketRepository)
37
    {
38
        $this->basketRepository = $basketRepository;
39
    }
40
41
    /**
42
     * @var MailRepository
43
     */
44
    protected $mailRepository;
45
46
    /**
47
     * @param MailRepository $mailRepository
48
     */
49
    public function injectMailRepository(MailRepository $mailRepository)
50
    {
51
        $this->mailRepository = $mailRepository;
52
    }
53
54
    /**
55
     * @var PrinterRepository
56
     */
57
    protected $printerRepository;
58
59
    /**
60
     * @param PrinterRepository $printerRepository
61
     */
62
    public function injectPrinterRepository(PrinterRepository $printerRepository)
63
    {
64
        $this->printerRepository = $printerRepository;
65
    }
66
67
    /**
68
     * @var ActionLogRepository
69
     */
70
    protected $actionLogRepository;
71
72
    /**
73
     * @param ActionLogRepository $actionLogRepository
74
     */
75
    public function injectActionLogRepository(ActionLogRepository $actionLogRepository)
76
    {
77
        $this->actionLogRepository = $actionLogRepository;
78
    }
79
80
    /**
81
     * Different actions which depends on the choosen action (form)
82
     *
83
     * @return void
84
     */
85
    public function basketAction()
86
    {
87
        $this->requestData = GeneralUtility::_GPmerged('tx_dlf');
88
        unset($this->requestData['__referrer'], $this->requestData['__trustedProperties']);
89
90
        $basket = $this->getBasketData();
91
92
        // action remove from basket
93
        if ($this->requestData['basket_action'] === 'remove') {
94
            // remove entry from list
95
            if (isset($this->requestData['selected'])) {
96
                $basket = $this->removeFromBasket($this->requestData, $basket);
97
            }
98
        }
99
        // action remove from basket
100
        if ($this->requestData['basket_action'] == 'download') {
101
            // open selected documents
102
            if (isset($this->requestData['selected'])) {
103
                $pdfUrl = $this->settings['pdfgenerate'];
104
                foreach ($this->requestData['selected'] as $docValue) {
105
                    if ($docValue['id']) {
106
                        $docData = $this->getDocumentData($docValue['id'], $docValue);
107
                        $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
108
                        $this->redirectToUri($pdfUrl);
109
                    }
110
                }
111
            }
112
        }
113
        // action print from basket
114
        if ($this->requestData['print_action']) {
115
            // open selected documents
116
            if (isset($this->requestData['selected'])) {
117
                $this->printDocument($basket);
118
            }
119
        }
120
        // action send mail
121
        if ($this->requestData['mail_action']) {
122
            if (isset($this->requestData['selected'])) {
123
                $this->sendMail();
124
            }
125
        }
126
127
        $this->redirect('main');
128
    }
129
130
    /**
131
     * Add documents to the basket
132
     *
133
     * @return void
134
     */
135
    public function addAction()
136
    {
137
        $basket = $this->getBasketData();
138
139
        if (
140
            !empty($this->requestData['id'])
141
            && $this->requestData['addToBasket']
142
        ) {
143
            $basket = $this->addToBasket($this->requestData, $basket);
0 ignored issues
show
Unused Code introduced by
The assignment to $basket is dead and can be removed.
Loading history...
144
        }
145
146
        $this->redirect('main');
147
    }
148
149
    /**
150
     * The main method of the plugin
151
     *
152
     * @return void
153
     */
154
    public function mainAction()
155
    {
156
        $basket = $this->getBasketData();
157
158
        $countDocs = 0;
159
        if ($basket->getDocIds()) {
160
            $countDocs = count(json_decode($basket->getDocIds(), true));
161
        }
162
        $this->view->assign('countDocs', $countDocs);
163
164
        $allMails = $this->mailRepository->findAllWithPid($this->settings['storagePid']);
165
166
        $mailSelect = [];
167
        if ($allMails->count() > 0) {
168
            $mailSelect[0] = htmlspecialchars(LocalizationUtility::translate('basket.chooseMail', 'dlf'));
0 ignored issues
show
Bug introduced by
It seems like TYPO3\CMS\Extbase\Utilit...ket.chooseMail', 'dlf') can also be of type null; however, parameter $string of htmlspecialchars() 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

168
            $mailSelect[0] = htmlspecialchars(/** @scrutinizer ignore-type */ LocalizationUtility::translate('basket.chooseMail', 'dlf'));
Loading history...
169
            foreach ($allMails as $mail) {
170
                $mailSelect[$mail->getUid()] = htmlspecialchars($mail->getName()) . ' (' . htmlspecialchars($mail->getMail()) . ')';
171
            }
172
            $this->view->assign('mailSelect', $mailSelect);
173
        }
174
175
        $allPrinter = $this->printerRepository->findAll();
176
177
        $printSelect = [];
178
        if ($allPrinter->count() > 0) {
179
            $printSelect[0] = htmlspecialchars(LocalizationUtility::translate('basket.choosePrinter', 'dlf'));
180
            foreach ($allPrinter as $printer) {
181
                $printSelect[$printer->getUid()] = htmlspecialchars($printer->getLabel());
182
            }
183
            $this->view->assign('printSelect', $printSelect);
184
        }
185
186
        $entries = [];
187
        if ($basket->getDocIds()) {
188
            // get each entry
189
            foreach (json_decode($basket->getDocIds()) as $value) {
190
                $entries[] = $this->getEntry($value);
191
            }
192
            $this->view->assign('entries', $entries);
193
        }
194
    }
195
196
    /**
197
     * The basket data from user session.
198
     *
199
     * @return Basket The found data from user session.
200
     */
201
    protected function getBasketData()
202
    {
203
        // get user session
204
        $sessionId = $GLOBALS['TSFE']->fe_user->id;
205
206
        if ($GLOBALS['TSFE']->loginUser) {
207
            $basket = $this->basketRepository->findOneByFeUserId((int) $GLOBALS['TSFE']->fe_user->user['uid']);
0 ignored issues
show
Bug introduced by
The method findOneByFeUserId() 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

207
            /** @scrutinizer ignore-call */ 
208
            $basket = $this->basketRepository->findOneByFeUserId((int) $GLOBALS['TSFE']->fe_user->user['uid']);
Loading history...
208
        } else {
209
            $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_dlf_basket', '');
210
            $GLOBALS['TSFE']->fe_user->sesData_change = true;
211
            $GLOBALS['TSFE']->fe_user->storeSessionData();
212
213
            $basket = $this->basketRepository->findOneBySessionId($sessionId);
0 ignored issues
show
Bug introduced by
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

213
            /** @scrutinizer ignore-call */ 
214
            $basket = $this->basketRepository->findOneBySessionId($sessionId);
Loading history...
214
        }
215
        // session doesnt exists
216
        if ($basket === null) {
217
            // create new basket in db
218
            $basket = GeneralUtility::makeInstance(Basket::class);
219
            $basket->setSessionId($sessionId);
220
            $basket->setFeUserId($GLOBALS['TSFE']->loginUser ? $GLOBALS['TSFE']->fe_user->user['uid'] : 0);
221
        }
222
223
        return $basket;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $basket also could return the type TYPO3\CMS\Extbase\Persis...y<mixed,object>|integer which is incompatible with the documented return type Kitodo\Dlf\Domain\Model\Basket.
Loading history...
224
    }
225
226
    /**
227
     * Return one basket entry
228
     *
229
     * @access protected
230
     *
231
     * @param array $data: DocumentData
232
     * @param array $template: Template information
233
     *
234
     * @return string One basket entry
235
     */
236
    protected function getEntry($data)
237
    {
238
        if (is_object($data)) {
239
            $data = get_object_vars($data);
240
        }
241
        $id = $data['id'];
242
        $startpage = $data['startpage'];
243
        $endpage = $data['endpage'];
244
        $startX = $data['startX'];
245
        $startY = $data['startY'];
246
        $endX = $data['endX'];
247
        $endY = $data['endY'];
248
        $rotation = $data['rotation'];
249
250
        $docData = $this->getDocumentData($id, $data);
251
252
        $entryArray['BASKETDATA'] = $docData;
253
254
        $entryKey = $id . '_' . $startpage;
255
        if (!empty($startX)) {
256
            $entryKey .= '_' . $startX;
257
        }
258
        if (!empty($endX)) {
259
            $entryKey .= '_' . $endX;
260
        }
261
262
        $entryArray['id'] = $id;
263
        $entryArray['CONTROLS'] = [
264
            'startpage' => $startpage,
265
            'endpage' => $endpage,
266
            'startX' => $startX,
267
            'startY' => $startY,
268
            'endX' => $endX,
269
            'endY' => $endY,
270
            'rotation' => $rotation,
271
        ];
272
273
        $entryArray['NUMBER'] = $docData['record_id'];
274
        $entryArray['key'] = $entryKey;
275
276
        // return one entry
277
        return $entryArray;
278
    }
279
280
    /**
281
     * Returns the downloadurl configured in the basket
282
     *
283
     * @access protected
284
     *
285
     * @param int $id: Document id
286
     *
287
     * @return mixed download url or false
288
     */
289
    protected function getDocumentData($id, $data)
290
    {
291
        // get document instance to load further information
292
        $this->loadDocument(['id' => $id]);
293
        if ($this->document) {
294
            // replace url param placeholder
295
            $urlParams = str_replace("##page##", (int) $data['page'], $this->settings['pdfparams']);
296
            $urlParams = str_replace("##docId##", $this->document->getRecordId(), $urlParams);
297
            $urlParams = str_replace("##startpage##", (int) $data['startpage'], $urlParams);
298
            if ($data['startpage'] != $data['endpage']) {
299
                $urlParams = str_replace("##endpage##", $data['endpage'] === "" ? "" : (int) $data['endpage'], $urlParams);
300
            } else {
301
                // remove parameter endpage
302
                $urlParams = str_replace(",##endpage##", '', $urlParams);
303
            }
304
            $urlParams = str_replace("##startx##", $data['startX'] === "" ? "" : (int) $data['startX'], $urlParams);
305
            $urlParams = str_replace("##starty##", $data['startY'] === "" ? "" : (int) $data['startY'], $urlParams);
306
            $urlParams = str_replace("##endx##", $data['endX'] === "" ? "" : (int) $data['endX'], $urlParams);
307
            $urlParams = str_replace("##endy##", $data['endY'] === "" ? "" : (int) $data['endY'], $urlParams);
308
            $urlParams = str_replace("##rotation##", $data['rotation'] === "" ? "" : (int) $data['rotation'], $urlParams);
309
310
            $downloadUrl = $this->settings['pdfgenerate'] . $urlParams;
311
312
            $title = $this->document->getTitle();
313
            if (empty($title)) {
314
                $title = LocalizationUtility::translate('basket.noTitle', 'dlf') ? : '';
315
            }
316
317
            // Set page and cutout information
318
            $info = '';
319
            if ($data['startX'] != '' && $data['endX'] != '') {
320
                // cutout
321
                $info .= htmlspecialchars(LocalizationUtility::translate('basket.cutout', 'dlf')) . ' ';
0 ignored issues
show
Bug introduced by
It seems like TYPO3\CMS\Extbase\Utilit...'basket.cutout', 'dlf') can also be of type null; however, parameter $string of htmlspecialchars() 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

321
                $info .= htmlspecialchars(/** @scrutinizer ignore-type */ LocalizationUtility::translate('basket.cutout', 'dlf')) . ' ';
Loading history...
322
            }
323
            if ($data['startpage'] == $data['endpage']) {
324
                // One page
325
                $info .= htmlspecialchars(LocalizationUtility::translate('page', 'dlf')) . ' ' . $data['startpage'];
326
            } else {
327
                $info .= htmlspecialchars(LocalizationUtility::translate('page', 'dlf')) . ' ' . $data['startpage'] . '-' . $data['endpage'];
328
            }
329
            $downloadLink = '<a href="' . $downloadUrl . '" target="_blank">' . htmlspecialchars($title) . '</a> (' . $info . ')';
330
            if ($data['startpage'] == $data['endpage']) {
331
                $pageNums = 1;
332
            } else {
333
                $pageNums = $data['endpage'] - $data['startpage'];
334
            }
335
            return [
336
                'downloadUrl' => $downloadUrl,
337
                'title' => $title,
338
                'info' => $info,
339
                'downloadLink' => $downloadLink,
340
                'pageNums' => $pageNums,
341
                'urlParams' => $urlParams,
342
                'record_id' => $this->document->getRecordId(),
343
            ];
344
        }
345
        return false;
346
    }
347
348
    /**
349
     * Adds documents to the basket
350
     *
351
     * @access protected
352
     *
353
     * @param array $_piVars: piVars
354
     * @param Basket $basket: basket object
355
     *
356
     * @return array Basket data and Javascript output
357
     */
358
    protected function addToBasket($_piVars, $basket)
359
    {
360
        $output = '';
361
362
        if (!$_piVars['startpage']) {
363
            $page = 0;
364
        } else {
365
            $page = (int) $_piVars['startpage'];
366
        }
367
        if ($page != null || $_piVars['addToBasket'] == 'list') {
368
            $documentItem = [
369
                'id' => (int) $_piVars['id'],
370
                'startpage' => (int) $_piVars['startpage'],
371
                'endpage' => !isset($_piVars['endpage']) || $_piVars['endpage'] === "" ? "" : (int) $_piVars['endpage'],
372
                'startX' => !isset($_piVars['startX']) || $_piVars['startX'] === "" ? "" : (int) $_piVars['startX'],
373
                'startY' => !isset($_piVars['startY']) || $_piVars['startY'] === "" ? "" : (int) $_piVars['startY'],
374
                'endX' => !isset($_piVars['endX']) || $_piVars['endX'] === "" ? "" : (int) $_piVars['endX'],
375
                'endY' => !isset($_piVars['endY']) || $_piVars['endY'] === "" ? "" : (int) $_piVars['endY'],
376
                'rotation' => !isset($_piVars['rotation']) || $_piVars['rotation'] === "" ? "" : (int) $_piVars['rotation']
377
            ];
378
379
            // update basket
380
            if (!empty(json_decode($basket->getDocIds()))) {
381
                $items = json_decode($basket->getDocIds());
382
                $items = get_object_vars($items);
383
            } else {
384
                $items = [];
385
            }
386
            // get document instance to load further information
387
            $this->loadDocument(['id' => $documentItem['id']]);
388
            if (
389
                $this->document === null
390
                || $this->document->getDoc() === null
391
            ) {
392
                // Quit without doing anything if required variables are not set.
393
                return;
394
            }
395
            // set endpage for toc and subentry based on logid
396
            if (($_piVars['addToBasket'] == 'subentry') or ($_piVars['addToBasket'] == 'toc')) {
397
                $smLinks = $this->document->getDoc()->smLinks;
398
                $pageCounter = sizeof($smLinks['l2p'][$_piVars['logId']]);
399
                $documentItem['endpage'] = ($documentItem['startpage'] + $pageCounter) - 1;
400
            }
401
            // add whole document
402
            if ($_piVars['addToBasket'] == 'list') {
403
                $documentItem['endpage'] = $this->document->getDoc()->numPages;
404
            }
405
            $arrayKey = $documentItem['id'] . '_' . $page;
406
            if (!empty($documentItem['startX'])) {
407
                $arrayKey .= '_' . $documentItem['startX'];
408
            }
409
            if (!empty($documentItem['endX'])) {
410
                $arrayKey .= '_' . $documentItem['endX'];
411
            }
412
            // do not add more than one identical object
413
            if (!in_array($arrayKey, $items)) {
414
                $items[$arrayKey] = $documentItem;
415
                // replace url param placeholder
416
                $pdfParams = str_replace("##startpage##", $documentItem['startpage'], $this->settings['pdfparams']);
417
                $pdfParams = str_replace("##docId##", $this->document->getRecordId(), $pdfParams);
418
                $pdfParams = str_replace("##startx##", $documentItem['startX'], $pdfParams);
419
                $pdfParams = str_replace("##starty##", $documentItem['startY'], $pdfParams);
420
                $pdfParams = str_replace("##endx##", $documentItem['endX'], $pdfParams);
421
                $pdfParams = str_replace("##endy##", $documentItem['endY'], $pdfParams);
422
                $pdfParams = str_replace("##rotation##", $documentItem['rotation'], $pdfParams);
423
                if ($documentItem['startpage'] != $documentItem['endpage']) {
424
                    $pdfParams = str_replace("##endpage##", $documentItem['endpage'], $pdfParams);
425
                } else {
426
                    // remove parameter endpage
427
                    $pdfParams = str_replace(",##endpage##", '', $pdfParams);
428
                }
429
                $pdfGenerateUrl = $this->settings['pdfgenerate'] . $pdfParams;
430
                if ($this->settings['pregeneration']) {
431
                    // send ajax request to webapp
432
                    $output .= '
433
     <script>
434
      $(document).ready(function(){
435
       $.ajax({
436
         url: "' . $pdfGenerateUrl . '",
437
       }).done(function() {
438
       });
439
      });
440
     </script>';
441
                }
442
            }
443
444
            $basket->setDocIds(json_encode($items));
445
            if ($basket->getUid() === null) {
446
                $this->basketRepository->add($basket);
447
            } else {
448
                $this->basketRepository->update($basket);
449
            }
450
        }
451
        $this->view->assign('pregenerateJs', $output);
452
453
        return $basket;
454
    }
455
456
    /**
457
     * Removes selected documents from basket
458
     *
459
     * @access protected
460
     *
461
     * @param array $_piVars: plugin variables
462
     * @param Basket $basket: basket object
463
     *
464
     * @return Basket basket
465
     */
466
    protected function removeFromBasket($_piVars, $basket)
467
    {
468
        if (!empty($basket->getDocIds())) {
469
            $items = json_decode($basket->getDocIds());
470
            $items = get_object_vars($items);
471
        }
472
        foreach ($_piVars['selected'] as $value) {
473
            if (isset($value['id'])) {
474
                $arrayKey = $value['id'] . '_' . $value['startpage'];
475
                if (!empty($value['startX'])) {
476
                    $arrayKey .= '_' . $value['startX'];
477
                }
478
                if (!empty($value['endX'])) {
479
                    $arrayKey .= '_' . $value['endX'];
480
                }
481
                if (isset($items[$arrayKey])) {
482
                    unset($items[$arrayKey]);
483
                }
484
            }
485
        }
486
        if (empty($items)) {
487
            $update = '';
488
        } else {
489
            $update = json_encode($items);
490
        }
491
492
        $basket->setDocIds($update);
493
        $this->basketRepository->update($basket);
494
495
        return $basket;
496
    }
497
498
    /**
499
     * Send mail with pdf download url
500
     *
501
     * @access protected
502
     *
503
     * @return void
504
     */
505
    protected function sendMail()
506
    {
507
        // send mail
508
        $mailId = $this->requestData['mail_action'];
509
510
        $mailObject = $this->mailRepository->findByUid(intval($mailId))->getFirst();
511
512
        $mailText = htmlspecialchars(LocalizationUtility::translate('basket.mailBody', 'dlf')) . "\n";
0 ignored issues
show
Bug introduced by
It seems like TYPO3\CMS\Extbase\Utilit...asket.mailBody', 'dlf') can also be of type null; however, parameter $string of htmlspecialchars() 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

512
        $mailText = htmlspecialchars(/** @scrutinizer ignore-type */ LocalizationUtility::translate('basket.mailBody', 'dlf')) . "\n";
Loading history...
513
        $numberOfPages = 0;
514
        $pdfUrl = $this->settings['pdfdownload'];
515
        // prepare links
516
        foreach ($this->requestData['selected'] as $docValue) {
517
            if ($docValue['id']) {
518
                $explodeId = explode("_", $docValue['id']);
519
                $docData = $this->getDocumentData($explodeId[0], $docValue);
520
                $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
521
                $pages = (abs(intval($docValue['startpage']) - intval($docValue['endpage'])));
522
                if ($pages === 0) {
523
                    $numberOfPages = $numberOfPages + 1;
524
                } else {
525
                    $numberOfPages = $numberOfPages + $pages;
526
                }
527
            }
528
        }
529
        // Remove leading/tailing pdfparamseperator
530
        $pdfUrl = trim($pdfUrl, $this->settings['pdfparamseparator']);
531
        $mailBody = $mailText . $pdfUrl;
532
        // Get hook objects.
533
        $hookObjects = Helper::getHookObjects($this->scriptRelPath);
0 ignored issues
show
Bug Best Practice introduced by
The property scriptRelPath does not exist on Kitodo\Dlf\Controller\BasketController. Did you maybe forget to declare it?
Loading history...
534
        // Hook for getting a customized mail body.
535
        foreach ($hookObjects as $hookObj) {
536
            if (method_exists($hookObj, 'customizeMailBody')) {
537
                $mailBody = $hookObj->customizeMailBody($mailText, $pdfUrl);
538
            }
539
        }
540
        $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
541
        // send mail
542
        $mail = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
543
        // Prepare and send the message
544
        $mail
545
            // subject
546
            ->setSubject(LocalizationUtility::translate('basket.mailSubject', 'dlf'))
547
            // Set the From address with an associative array
548
            ->setFrom($from)
549
            // Set the To addresses with an associative array
550
            ->setTo([$mailObject->getMail() => $mailObject->getName()])
551
            ->setBody($mailBody, 'text/html')
552
            ->send();
553
554
        // create entry for action log
555
        $newActionLog = GeneralUtility::makeInstance(ActionLog::class);
556
        $newActionLog->setFileName($pdfUrl);
557
        $newActionLog->setCountPages($numberOfPages);
558
        $newActionLog->setLabel('Mail: ' . $mailObject->getMail());
559
560
        if ($GLOBALS["TSFE"]->loginUser) {
561
            // internal user
562
            $newActionLog->setUserId($GLOBALS["TSFE"]->fe_user->user['uid']);
563
            $newActionLog->setName($GLOBALS["TSFE"]->fe_user->user['username']);
564
        } else {
565
            // external user
566
            $newActionLog->setUserId(0);
567
            $newActionLog->setName('n/a');
568
        }
569
570
        $this->actionLogRepository->add($newActionLog);
571
572
        $this->redirect('main');
573
    }
574
575
    /**
576
     * Sends document information to an external printer (url)
577
     *
578
     * @access protected
579
     * @param Basket basket object
580
     *
581
     * @return void
582
     */
583
    protected function printDocument($basket)
0 ignored issues
show
Unused Code introduced by
The parameter $basket is not used and could be removed. ( Ignorable by Annotation )

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

583
    protected function printDocument(/** @scrutinizer ignore-unused */ $basket)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
584
    {
585
        $pdfUrl = $this->settings['pdfprint'];
586
        $numberOfPages = 0;
587
        foreach ($this->requestData['selected'] as $docId => $docValue) {
588
            if ($docValue['id']) {
589
                $docData = $this->getDocumentData($docValue['id'], $docValue);
590
                $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
591
                $numberOfPages += $docData['pageNums'];
592
            }
593
        }
594
        // get printer data
595
        $printerId = $this->requestData['print_action'];
596
597
        // get id from db and send selected doc download link
598
        $printer = $this->printerRepository->findOneByUid($printerId);
0 ignored issues
show
Bug introduced by
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

598
        /** @scrutinizer ignore-call */ 
599
        $printer = $this->printerRepository->findOneByUid($printerId);
Loading history...
599
600
        // printer is selected
601
        if ($printer) {
602
            $pdfUrl = $printer->getPrint();
0 ignored issues
show
Bug introduced by
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

602
            /** @scrutinizer ignore-call */ 
603
            $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...
603
            $numberOfPages = 0;
604
            foreach ($this->requestData['selected'] as $docId => $docValue) {
605
                if ($docValue['id']) {
606
                    $explodeId = explode("_", $docId);
607
                    $docData = $this->getDocumentData($explodeId[0], $docValue);
608
                    $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
609
                    $numberOfPages += $docData['pageNums'];
610
                }
611
            }
612
            $pdfUrl = trim($pdfUrl, $this->settings['pdfparamseparator']);
613
        }
614
615
        $actionLog = GeneralUtility::makeInstance(ActionLog::class);
616
        // protocol
617
        $actionLog->setPid($this->settings['storagePid']);
618
        $actionLog->setFileName($pdfUrl);
619
        $actionLog->setCountPages($numberOfPages);
620
621
        if ($GLOBALS["TSFE"]->loginUser) {
622
            // internal user
623
            $actionLog->setUserId($GLOBALS["TSFE"]->fe_user->user['uid']);
624
            $actionLog->setName($GLOBALS["TSFE"]->fe_user->user['username']);
625
            $actionLog->setLabel('Print: ' . $printer->getLabel());
0 ignored issues
show
Bug introduced by
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

625
            $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...
626
        } else {
627
            // external user
628
            $actionLog->setUserId(0);
629
            $actionLog->setName('n/a');
630
            $actionLog->setLabel('Print: ' . $printer->getLabel());
631
        }
632
        // add action to protocol
633
        $this->actionLogRepository->add($actionLog);
634
635
        $this->redirectToUri($pdfUrl);
636
    }
637
}
638