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
03:36
created

BasketController::removeFromBasket()   B

Complexity

Conditions 8
Paths 40

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 19
c 1
b 0
f 0
nc 40
nop 2
dl 0
loc 30
rs 8.4444
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
        $basket = $this->getBasketData();
88
89
        // action remove from basket
90
        if ($this->requestData['basket_action'] === 'remove') {
91
            // remove entry from list
92
            if (isset($this->requestData['selected'])) {
93
                $basket = $this->removeFromBasket($this->requestData, $basket);
94
            }
95
        }
96
        // action remove from basket
97
        if ($this->requestData['basket_action'] == 'download') {
98
            // open selected documents
99
            if (isset($this->requestData['selected'])) {
100
                $pdfUrl = $this->settings['pdfgenerate'];
101
                foreach ($this->requestData['selected'] as $docValue) {
102
                    if ($docValue['id']) {
103
                        $docData = $this->getDocumentData($docValue['id'], $docValue);
104
                        $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
105
                        $this->redirectToUri($pdfUrl);
106
                    }
107
                }
108
            }
109
        }
110
        // action print from basket
111
        if ($this->requestData['print_action']) {
112
            // open selected documents
113
            if (isset($this->requestData['selected'])) {
114
                $this->printDocument($basket);
115
            }
116
        }
117
        // action send mail
118
        if ($this->requestData['mail_action']) {
119
            if (isset($this->requestData['selected'])) {
120
                $this->sendMail();
121
            }
122
        }
123
124
        $this->redirect('main');
125
    }
126
127
    /**
128
     * Add documents to the basket
129
     *
130
     * @return void
131
     */
132
    public function addAction()
133
    {
134
        $basket = $this->getBasketData();
135
136
        if (
137
            !empty($this->requestData['id'])
138
            && $this->requestData['addToBasket']
139
        ) {
140
            $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...
141
        }
142
143
        $this->redirect('main');
144
    }
145
146
    /**
147
     * The main method of the plugin
148
     *
149
     * @return void
150
     */
151
    public function mainAction()
152
    {
153
        $basket = $this->getBasketData();
154
155
        $countDocs = 0;
156
        if ($basket->getDocIds()) {
157
            $countDocs = count(json_decode($basket->getDocIds(), true));
158
        }
159
        $this->view->assign('countDocs', $countDocs);
160
161
        $allMails = $this->mailRepository->findAllWithPid($this->settings['storagePid']);
162
163
        $mailSelect = [];
164
        if ($allMails->count() > 0) {
165
            $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

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

204
            /** @scrutinizer ignore-call */ 
205
            $basket = $this->basketRepository->findOneByFeUserId((int) $GLOBALS['TSFE']->fe_user->user['uid']);
Loading history...
205
        } else {
206
            $GLOBALS['TSFE']->fe_user->setKey('ses', 'tx_dlf_basket', '');
207
            $GLOBALS['TSFE']->fe_user->sesData_change = true;
208
            $GLOBALS['TSFE']->fe_user->storeSessionData();
209
210
            $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

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

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

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

580
    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...
581
    {
582
        $pdfUrl = $this->settings['pdfprint'];
583
        $numberOfPages = 0;
584
        foreach ($this->requestData['selected'] as $docId => $docValue) {
585
            if ($docValue['id']) {
586
                $docData = $this->getDocumentData($docValue['id'], $docValue);
587
                $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
588
                $numberOfPages += $docData['pageNums'];
589
            }
590
        }
591
        // get printer data
592
        $printerId = $this->requestData['print_action'];
593
594
        // get id from db and send selected doc download link
595
        $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

595
        /** @scrutinizer ignore-call */ 
596
        $printer = $this->printerRepository->findOneByUid($printerId);
Loading history...
596
597
        // printer is selected
598
        if ($printer) {
599
            $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

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

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