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 (214)

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);
0 ignored issues
show
The assignment to $basket is dead and can be removed.
Loading history...
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'));
0 ignored issues
show
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

201
            $mailSelect[0] = htmlspecialchars(/** @scrutinizer ignore-type */ LocalizationUtility::translate('basket.chooseMail', 'dlf'));
Loading history...
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());
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 bool|null|object $data DocumentData
272
     *
273
     * @return array One basket entry
274
     */
275
    protected function getEntry($data): array
276
    {
277
        if (is_object($data)) {
278
            $data = get_object_vars($data);
279
        }
280
        $id = $data['id'];
281
        $startPage = $data['startpage'];
282
        $endPage = $data['endpage'];
283
        $startX = $data['startX'];
284
        $startY = $data['startY'];
285
        $endX = $data['endX'];
286
        $endY = $data['endY'];
287
        $rotation = $data['rotation'];
288
289
        $docData = $this->getDocumentData((int) $id, $data);
0 ignored issues
show
It seems like $data can also be of type boolean and null; however, parameter $data of Kitodo\Dlf\Controller\Ba...ller::getDocumentData() does only seem to accept array, 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

289
        $docData = $this->getDocumentData((int) $id, /** @scrutinizer ignore-type */ $data);
Loading history...
290
291
        $entryKey = $id . '_' . $startPage;
292
        if (!empty($startX)) {
293
            $entryKey .= '_' . $startX;
294
        }
295
        if (!empty($endX)) {
296
            $entryKey .= '_' . $endX;
297
        }
298
299
        $entry = [
300
            'BASKETDATA' => $docData,
301
            'id' => $id,
302
            'NUMBER' => $docData['record_id'],
303
            'key' => $entryKey
304
        ];
305
306
        $entry['CONTROLS'] = [
307
            'startpage' => $startPage,
308
            'endpage' => $endPage,
309
            'startX' => $startX,
310
            'startY' => $startY,
311
            'endX' => $endX,
312
            'endY' => $endY,
313
            'rotation' => $rotation,
314
        ];
315
316
        // return one entry
317
        return $entry;
318
    }
319
320
    /**
321
     * Returns the download url configured in the basket
322
     *
323
     * @access protected
324
     *
325
     * @param int $id Document id
326
     * @param array $data DocumentData
327
     *
328
     * @return array|false download url or false
329
     */
330
    protected function getDocumentData(int $id, array $data)
331
    {
332
        // get document instance to load further information
333
        $this->loadDocument((int) $id);
334
        if (isset($this->document)) {
335
            // replace url param placeholder
336
            // TODO: Parameter #2 $replace of function str_replace expects array|string, int given.
337
            // @phpstan-ignore-next-line
338
            $urlParams = str_replace("##page##", (int) $data['page'], $this->settings['pdfparams']);
339
            $urlParams = str_replace("##docId##", $this->document->getRecordId(), $urlParams);
340
            // TODO: Parameter #2 $replace of function str_replace expects array|string, int given.
341
            // @phpstan-ignore-next-line
342
            $urlParams = str_replace("##startpage##", (int) $data['startpage'], $urlParams);
343
            if ($data['startpage'] != $data['endpage']) {
344
                $urlParams = str_replace("##endpage##", $data['endpage'] === "" ? "" : (int) $data['endpage'], $urlParams);
345
            } else {
346
                // remove parameter endpage
347
                $urlParams = str_replace(",##endpage##", '', $urlParams);
348
            }
349
            $urlParams = str_replace("##startx##", $data['startX'] === "" ? "" : (int) $data['startX'], $urlParams);
350
            $urlParams = str_replace("##starty##", $data['startY'] === "" ? "" : (int) $data['startY'], $urlParams);
351
            $urlParams = str_replace("##endx##", $data['endX'] === "" ? "" : (int) $data['endX'], $urlParams);
352
            $urlParams = str_replace("##endy##", $data['endY'] === "" ? "" : (int) $data['endY'], $urlParams);
353
            $urlParams = str_replace("##rotation##", $data['rotation'] === "" ? "" : (int) $data['rotation'], $urlParams);
354
355
            $downloadUrl = $this->settings['pdfgenerate'] . $urlParams;
356
357
            $title = $this->document->getTitle();
358
            if (empty($title)) {
359
                $title = LocalizationUtility::translate('basket.noTitle', 'dlf') ? : '';
360
            }
361
362
            // Set page and cutout information
363
            $info = '';
364
            if ($data['startX'] != '' && $data['endX'] != '') {
365
                // cutout
366
                $info .= htmlspecialchars(LocalizationUtility::translate('basket.cutout', 'dlf')) . ' ';
0 ignored issues
show
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

366
                $info .= htmlspecialchars(/** @scrutinizer ignore-type */ LocalizationUtility::translate('basket.cutout', 'dlf')) . ' ';
Loading history...
367
            }
368
            if ($data['startpage'] == $data['endpage']) {
369
                // One page
370
                $info .= htmlspecialchars(LocalizationUtility::translate('page', 'dlf')) . ' ' . $data['startpage'];
371
            } else {
372
                $info .= htmlspecialchars(LocalizationUtility::translate('page', 'dlf')) . ' ' . $data['startpage'] . '-' . $data['endpage'];
373
            }
374
            $downloadLink = '<a href="' . $downloadUrl . '" target="_blank">' . htmlspecialchars($title) . '</a> (' . $info . ')';
375
            if ($data['startpage'] == $data['endpage']) {
376
                $pageNums = 1;
377
            } else {
378
                $pageNums = $data['endpage'] - $data['startpage'];
379
            }
380
            return [
381
                'downloadUrl' => $downloadUrl,
382
                'title' => $title,
383
                'info' => $info,
384
                'downloadLink' => $downloadLink,
385
                'pageNums' => $pageNums,
386
                'urlParams' => $urlParams,
387
                'record_id' => $this->document->getRecordId(),
388
            ];
389
        }
390
        return false;
391
    }
392
393
    /**
394
     * Adds documents to the basket and includes JS
395
     *
396
     * @access protected
397
     *
398
     * @param array $piVars piVars
399
     * @param Basket $basket basket object
400
     *
401
     * @return Basket|null Basket data
402
     */
403
    protected function addToBasket(array $piVars, Basket $basket): ?Basket
404
    {
405
        $output = '';
406
407
        if (!$piVars['startpage']) {
408
            $page = 0;
409
        } else {
410
            $page = (int) $piVars['startpage'];
411
        }
412
        if ($page != null || $piVars['addToBasket'] == 'list') {
413
            $documentItem = [
414
                'id' => (int) $piVars['id'],
415
                'startpage' => (int) $piVars['startpage'],
416
                'endpage' => !isset($piVars['endpage']) || $piVars['endpage'] === "" ? "" : (int) $piVars['endpage'],
417
                'startX' => !isset($piVars['startX']) || $piVars['startX'] === "" ? "" : (int) $piVars['startX'],
418
                'startY' => !isset($piVars['startY']) || $piVars['startY'] === "" ? "" : (int) $piVars['startY'],
419
                'endX' => !isset($piVars['endX']) || $piVars['endX'] === "" ? "" : (int) $piVars['endX'],
420
                'endY' => !isset($piVars['endY']) || $piVars['endY'] === "" ? "" : (int) $piVars['endY'],
421
                'rotation' => !isset($piVars['rotation']) || $piVars['rotation'] === "" ? "" : (int) $piVars['rotation']
422
            ];
423
424
            // update basket
425
            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

425
            if (!empty(json_decode(/** @scrutinizer ignore-type */ $basket->getDocIds()))) {
Loading history...
426
                $items = json_decode($basket->getDocIds());
427
                $items = get_object_vars($items);
428
            } else {
429
                $items = [];
430
            }
431
            // get document instance to load further information
432
            $this->loadDocument((int) $documentItem['id']);
433
            if ($this->isDocMissing()) {
434
                // Quit without doing anything if required variables are not set.
435
                return null;
436
            }
437
            // set endpage for toc and subentry based on logid
438
            if (($piVars['addToBasket'] == 'subentry') or ($piVars['addToBasket'] == 'toc')) {
439
                $smLinks = $this->document->getCurrentDocument()->smLinks;
440
                $pageCounter = count($smLinks['l2p'][$piVars['logId']]);
441
                $documentItem['endpage'] = ($documentItem['startpage'] + $pageCounter) - 1;
442
            }
443
            // add whole document
444
            if ($piVars['addToBasket'] == 'list') {
445
                $documentItem['endpage'] = $this->document->getCurrentDocument()->numPages;
446
            }
447
            $arrayKey = $documentItem['id'] . '_' . $page;
448
            if (!empty($documentItem['startX'])) {
449
                $arrayKey .= '_' . $documentItem['startX'];
450
            }
451
            if (!empty($documentItem['endX'])) {
452
                $arrayKey .= '_' . $documentItem['endX'];
453
            }
454
            // do not add more than one identical object
455
            if (!in_array($arrayKey, $items)) {
456
                $items[$arrayKey] = $documentItem;
457
                // replace url param placeholder
458
                // TODO: Parameter #2 $replace of function str_replace expects array|string, int given.
459
                // @phpstan-ignore-next-line
460
                $pdfParams = str_replace("##startpage##", $documentItem['startpage'], $this->settings['pdfparams']);
461
                $pdfParams = str_replace("##docId##", $this->document->getRecordId(), $pdfParams);
462
                $pdfParams = str_replace("##startx##", $documentItem['startX'], $pdfParams);
463
                $pdfParams = str_replace("##starty##", $documentItem['startY'], $pdfParams);
464
                $pdfParams = str_replace("##endx##", $documentItem['endX'], $pdfParams);
465
                $pdfParams = str_replace("##endy##", $documentItem['endY'], $pdfParams);
466
                $pdfParams = str_replace("##rotation##", $documentItem['rotation'], $pdfParams);
467
                if ($documentItem['startpage'] != $documentItem['endpage']) {
468
                    $pdfParams = str_replace("##endpage##", $documentItem['endpage'], $pdfParams);
469
                } else {
470
                    // remove parameter endpage
471
                    $pdfParams = str_replace(",##endpage##", '', $pdfParams);
472
                }
473
                $pdfGenerateUrl = $this->settings['pdfgenerate'] . $pdfParams;
474
                if ($this->settings['pregeneration']) {
475
                    // send ajax request to webapp
476
                    $output .= '
477
     <script>
478
      $(document).ready(function(){
479
       $.ajax({
480
         url: "' . $pdfGenerateUrl . '",
481
       }).done(function() {
482
       });
483
      });
484
     </script>';
485
                }
486
            }
487
488
            $basket->setDocIds(json_encode($items));
489
            if ($basket->getUid() === null) {
490
                $this->basketRepository->add($basket);
491
            } else {
492
                $this->basketRepository->update($basket);
493
            }
494
        }
495
        $this->view->assign('pregenerateJs', $output);
496
497
        return $basket;
498
    }
499
500
    /**
501
     * Removes selected documents from basket
502
     *
503
     * @access protected
504
     *
505
     * @param array $piVars plugin variables
506
     * @param Basket $basket basket object
507
     *
508
     * @return Basket basket
509
     */
510
    protected function removeFromBasket(array $piVars, Basket $basket): Basket
511
    {
512
        if (!empty($basket->getDocIds())) {
513
            $items = json_decode($basket->getDocIds());
514
            $items = get_object_vars($items);
515
        }
516
        foreach ($piVars['selected'] as $value) {
517
            if (isset($value['id'])) {
518
                $arrayKey = $value['id'] . '_' . $value['startpage'];
519
                if (!empty($value['startX'])) {
520
                    $arrayKey .= '_' . $value['startX'];
521
                }
522
                if (!empty($value['endX'])) {
523
                    $arrayKey .= '_' . $value['endX'];
524
                }
525
                if (isset($items[$arrayKey])) {
526
                    unset($items[$arrayKey]);
527
                }
528
            }
529
        }
530
        if (empty($items)) {
531
            $update = '';
532
        } else {
533
            $update = json_encode($items);
534
        }
535
536
        $basket->setDocIds($update);
537
        $this->basketRepository->update($basket);
538
539
        return $basket;
540
    }
541
542
    /**
543
     * Send mail with pdf download url
544
     *
545
     * @access protected
546
     *
547
     * @return void
548
     */
549
    protected function sendMail(): void
550
    {
551
        // send mail
552
        $mailId = $this->requestData['mail_action'];
553
554
        $mailObject = $this->mailRepository->findByUid(intval($mailId))->getFirst();
555
556
        $mailText = htmlspecialchars(LocalizationUtility::translate('basket.mailBody', 'dlf')) . "\n";
0 ignored issues
show
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

556
        $mailText = htmlspecialchars(/** @scrutinizer ignore-type */ LocalizationUtility::translate('basket.mailBody', 'dlf')) . "\n";
Loading history...
557
        $numberOfPages = 0;
558
        $pdfUrl = $this->settings['pdfdownload'];
559
        // prepare links
560
        foreach ($this->requestData['selected'] as $docValue) {
561
            if ($docValue['id']) {
562
                $explodeId = explode("_", $docValue['id']);
563
                $docData = $this->getDocumentData((int) $explodeId[0], $docValue);
564
                $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
565
                $pages = (abs(intval($docValue['startpage']) - intval($docValue['endpage'])));
566
                if ($pages === 0) {
567
                    $numberOfPages = $numberOfPages + 1;
568
                } else {
569
                    $numberOfPages = $numberOfPages + $pages;
570
                }
571
            }
572
        }
573
        // Remove leading/tailing pdfparamseperator
574
        $pdfUrl = trim($pdfUrl, $this->settings['pdfparamseparator']);
575
        $mailBody = $mailText . $pdfUrl;
576
        // Get hook objects.
577
        $hookObjects = Helper::getHookObjects('Classes/Controller/BasketController.php');
578
        // Hook for getting a customized mail body.
579
        foreach ($hookObjects as $hookObj) {
580
            if (method_exists($hookObj, 'customizeMailBody')) {
581
                $mailBody = $hookObj->customizeMailBody($mailText, $pdfUrl);
582
            }
583
        }
584
        $from = MailUtility::getSystemFrom();
585
        // send mail
586
        $mail = GeneralUtility::makeInstance(MailMessage::class);
587
        // Prepare and send the message
588
        $mail
589
            // subject
590
            ->setSubject(LocalizationUtility::translate('basket.mailSubject', 'dlf'))
591
            // Set the From address with an associative array
592
            ->setFrom($from)
593
            // Set the To addresses with an associative array
594
            ->setTo([$mailObject->getMail() => $mailObject->getName()])
595
            ->setBody($mailBody, 'text/html')
596
            ->send();
597
598
        // create entry for action log
599
        $newActionLog = GeneralUtility::makeInstance(ActionLog::class);
600
        $newActionLog->setFileName($pdfUrl);
601
        $newActionLog->setCountPages($numberOfPages);
602
        $newActionLog->setLabel('Mail: ' . $mailObject->getMail());
603
604
        if ($GLOBALS["TSFE"]->loginUser) {
605
            // internal user
606
            $newActionLog->setUserId($GLOBALS["TSFE"]->fe_user->user['uid']);
607
            $newActionLog->setName($GLOBALS["TSFE"]->fe_user->user['username']);
608
        } else {
609
            // external user
610
            $newActionLog->setUserId(0);
611
            $newActionLog->setName('n/a');
612
        }
613
614
        $this->actionLogRepository->add($newActionLog);
615
616
        $this->redirect('main');
617
    }
618
619
    /**
620
     * Sends document information to an external printer (url)
621
     *
622
     * @access protected
623
     *
624
     * @return void
625
     */
626
    protected function printDocument(): void
627
    {
628
        $pdfUrl = $this->settings['pdfprint'];
629
        $numberOfPages = 0;
630
        foreach ($this->requestData['selected'] as $docId => $docValue) {
631
            if ($docValue['id']) {
632
                $docData = $this->getDocumentData((int) $docValue['id'], $docValue);
633
                $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
634
                $numberOfPages += $docData['pageNums'];
635
            }
636
        }
637
        // get printer data
638
        $printerId = $this->requestData['print_action'];
639
640
        // get id from db and send selected doc download link
641
        $printer = $this->printerRepository->findOneByUid($printerId);
642
643
        // printer is selected
644
        if ($printer) {
645
            $pdfUrl = $printer->getPrint();
646
            $numberOfPages = 0;
647
            foreach ($this->requestData['selected'] as $docId => $docValue) {
648
                if ($docValue['id']) {
649
                    $explodeId = explode("_", $docId);
650
                    $docData = $this->getDocumentData((int) $explodeId[0], $docValue);
651
                    $pdfUrl .= $docData['urlParams'] . $this->settings['pdfparamseparator'];
652
                    $numberOfPages += $docData['pageNums'];
653
                }
654
            }
655
            $pdfUrl = trim($pdfUrl, $this->settings['pdfparamseparator']);
656
        }
657
658
        $actionLog = GeneralUtility::makeInstance(ActionLog::class);
659
        // protocol
660
        $actionLog->setPid($this->settings['storagePid']);
661
        $actionLog->setFileName($pdfUrl);
662
        $actionLog->setCountPages($numberOfPages);
663
664
        if ($GLOBALS["TSFE"]->loginUser) {
665
            // internal user
666
            $actionLog->setUserId($GLOBALS["TSFE"]->fe_user->user['uid']);
667
            $actionLog->setName($GLOBALS["TSFE"]->fe_user->user['username']);
668
            $actionLog->setLabel('Print: ' . $printer->getLabel());
669
        } else {
670
            // external user
671
            $actionLog->setUserId(0);
672
            $actionLog->setName('n/a');
673
            $actionLog->setLabel('Print: ' . $printer->getLabel());
674
        }
675
        // add action to protocol
676
        $this->actionLogRepository->add($actionLog);
677
678
        $this->redirectToUri($pdfUrl);
679
    }
680
}
681