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

Classes/Controller/Backend/NewTenantController.php (2 issues)

1
<?php
2
/**
3
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
4
 *
5
 * This file is part of the Kitodo and TYPO3 projects.
6
 *
7
 * @license GNU General Public License version 3 or later.
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace Kitodo\Dlf\Controller\Backend;
13
14
use Kitodo\Dlf\Common\Helper;
15
use Kitodo\Dlf\Common\Solr\Solr;
16
use Kitodo\Dlf\Controller\AbstractController;
17
use Kitodo\Dlf\Domain\Model\Format;
18
use Kitodo\Dlf\Domain\Model\SolrCore;
19
use Kitodo\Dlf\Domain\Repository\FormatRepository;
20
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
21
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
22
use Kitodo\Dlf\Domain\Repository\StructureRepository;
23
use TYPO3\CMS\Backend\Utility\BackendUtility;
24
use TYPO3\CMS\Backend\View\BackendTemplateView;
25
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
26
use TYPO3\CMS\Core\Localization\LocalizationFactory;
27
use TYPO3\CMS\Core\Site\Entity\NullSite;
28
use TYPO3\CMS\Core\Site\SiteFinder;
29
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
30
use TYPO3\CMS\Core\Utility\GeneralUtility;
31
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
32
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
33
34
/**
35
 * Controller class for the backend module 'New Tenant'.
36
 *
37
 * @package TYPO3
38
 * @subpackage dlf
39
 *
40
 * @access public
41
 */
42
class NewTenantController extends AbstractController
43
{
44
    /**
45
     * @access protected
46
     * @var int
47
     */
48
    protected int $pid;
49
50
    /**
51
     * @access protected
52
     * @var array
53
     */
54
    protected array $pageInfo;
55
56
    /**
57
     * @access protected
58
     * @var array All configured site languages
59
     */
60
    protected array $siteLanguages;
61
62
    /**
63
     * @access protected
64
     * @var LocalizationFactory Language factory to get language key/values by our own.
65
     */
66
    protected LocalizationFactory $languageFactory;
67
68
    /**
69
     * @access protected
70
     * @var string Backend Template Container
71
     */
72
    protected $defaultViewObjectName = BackendTemplateView::class;
73
74
    /**
75
     * @access protected
76
     * @var FormatRepository
77
     */
78
    protected FormatRepository $formatRepository;
79
80
    /**
81
     * @access public
82
     *
83
     * @param FormatRepository $formatRepository
84
     *
85
     * @return void
86
     */
87
    public function injectFormatRepository(FormatRepository $formatRepository): void
88
    {
89
        $this->formatRepository = $formatRepository;
90
    }
91
92
    /**
93
     * @access protected
94
     * @var MetadataRepository
95
     */
96
    protected MetadataRepository $metadataRepository;
97
98
    /**
99
     * @access public
100
     *
101
     * @param MetadataRepository $metadataRepository
102
     *
103
     * @return void
104
     */
105
    public function injectMetadataRepository(MetadataRepository $metadataRepository): void
106
    {
107
        $this->metadataRepository = $metadataRepository;
108
    }
109
110
    /**
111
     * @access protected
112
     * @var StructureRepository
113
     */
114
    protected StructureRepository $structureRepository;
115
116
    /**
117
     * @access public
118
     *
119
     * @param StructureRepository $structureRepository
120
     *
121
     * @return void
122
     */
123
    public function injectStructureRepository(StructureRepository $structureRepository): void
124
    {
125
        $this->structureRepository = $structureRepository;
126
    }
127
128
    /**
129
     * @access protected
130
     * @var SolrCoreRepository
131
     */
132
    protected SolrCoreRepository $solrCoreRepository;
133
134
    /**
135
     * @access public
136
     *
137
     * @param SolrCoreRepository $solrCoreRepository
138
     *
139
     * @return void
140
     */
141
    public function injectSolrCoreRepository(SolrCoreRepository $solrCoreRepository): void
142
    {
143
        $this->solrCoreRepository = $solrCoreRepository;
144
    }
145
146
    /**
147
     * Initialization for all actions
148
     *
149
     * @access protected
150
     *
151
     * @return void
152
     */
153
    protected function initializeAction(): void
154
    {
155
        $this->pid = (int) GeneralUtility::_GP('id');
156
157
        $frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
158
        $frameworkConfiguration['persistence']['storagePid'] = $this->pid;
159
        $this->configurationManager->setConfiguration($frameworkConfiguration);
160
161
        $this->languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
162
163
        try {
164
            $site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($this->pid);
165
        } catch (SiteNotFoundException $e) {
166
            $site = new NullSite();
167
        }
168
        $this->siteLanguages = $site->getLanguages();
169
    }
170
171
172
    /**
173
     * Action adding formats records
174
     *
175
     * @access public
176
     *
177
     * @return void
178
     */
179
    public function addFormatAction(): void
180
    {
181
        // Include formats definition file.
182
        $formatsDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php');
183
184
        $frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
185
        // tx_dlf_formats are stored on PID = 0
186
        $frameworkConfiguration['persistence']['storagePid'] = 0;
187
        $this->configurationManager->setConfiguration($frameworkConfiguration);
188
189
        $doPersist = false;
190
191
        foreach ($formatsDefaults as $type => $values) {
192
            // if default format record is not found, add it to the repository
193
            if ($this->formatRepository->findOneByType($type) === null) {
194
                $newRecord = GeneralUtility::makeInstance(Format::class);
195
                $newRecord->setType($type);
196
                $newRecord->setRoot($values['root']);
197
                $newRecord->setNamespace($values['namespace']);
198
                $newRecord->setClass($values['class']);
199
                $this->formatRepository->add($newRecord);
200
201
                $doPersist = true;
202
            }
203
        }
204
205
        // We must persist here, if we changed anything.
206
        if ($doPersist === true) {
207
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
208
            $persistenceManager->persistAll();
209
        }
210
211
        $this->forward('index');
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Mvc\Co...onController::forward() has been deprecated: since TYPO3 11.0, will be removed in 12.0 ( Ignorable by Annotation )

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

211
        /** @scrutinizer ignore-deprecated */ $this->forward('index');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
212
    }
213
214
    /**
215
     * Action adding metadata records
216
     *
217
     * @access public
218
     *
219
     * @return void
220
     */
221
    public function addMetadataAction(): void
222
    {
223
        // Include metadata definition file.
224
        $metadataDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php');
225
226
        // load language file in own array
227
        $metadataLabels = $this->languageFactory->getParsedData('EXT:dlf/Resources/Private/Language/locallang_metadata.xlf', $this->siteLanguages[0]->getTypo3Language());
228
229
        $insertedFormats = $this->formatRepository->findAll();
230
231
        $availableFormats = [];
232
        foreach ($insertedFormats as $insertedFormat) {
233
            $availableFormats[$insertedFormat->getRoot()] = $insertedFormat->getUid();
234
        }
235
236
        $defaultWrap = BackendUtility::getTcaFieldConfiguration('tx_dlf_metadata', 'wrap')['default'];
237
238
        $data = [];
239
        foreach ($metadataDefaults as $indexName => $values) {
240
            $formatIds = [];
241
242
            foreach ($values['format'] as $format) {
243
                $format['encoded'] = $availableFormats[$format['format_root']];
244
                unset($format['format_root']);
245
                $formatIds[] = uniqid('NEW');
246
                $data['tx_dlf_metadataformat'][end($formatIds)] = $format;
247
                $data['tx_dlf_metadataformat'][end($formatIds)]['pid'] = $this->pid;
248
            }
249
250
            $data['tx_dlf_metadata'][uniqid('NEW')] = [
251
                'pid' => $this->pid,
252
                'label' => $this->getLLL('metadata.' . $indexName, $this->siteLanguages[0]->getTypo3Language(), $metadataLabels),
253
                'index_name' => $indexName,
254
                'format' => implode(',', $formatIds),
255
                'default_value' => $values['default_value'],
256
                'wrap' => !empty($values['wrap']) ? $values['wrap'] : $defaultWrap,
257
                'index_tokenized' => $values['index_tokenized'],
258
                'index_stored' => $values['index_stored'],
259
                'index_indexed' => $values['index_indexed'],
260
                'index_boost' => $values['index_boost'],
261
                'is_sortable' => $values['is_sortable'],
262
                'is_facet' => $values['is_facet'],
263
                'is_listed' => $values['is_listed'],
264
                'index_autocomplete' => $values['index_autocomplete'],
265
            ];
266
        }
267
268
        $metadataIds = Helper::processDatabaseAsAdmin($data, [], true);
269
270
        $insertedMetadata = [];
271
        foreach ($metadataIds as $id => $uid) {
272
            $metadata = $this->metadataRepository->findByUid($uid);
273
            // id array contains also ids of formats
274
            if ($metadata != null) {
275
                $insertedMetadata[$uid] = $metadata->getIndexName();
276
            }
277
        }
278
279
        foreach ($this->siteLanguages as $siteLanguage) {
280
            if ($siteLanguage->getLanguageId() === 0) {
281
                // skip default language
282
                continue;
283
            }
284
285
            $translateData = [];
286
            foreach ($insertedMetadata as $id => $indexName) {
287
                $translateData['tx_dlf_metadata'][uniqid('NEW')] = [
288
                    'pid' => $this->pid,
289
                    'sys_language_uid' => $siteLanguage->getLanguageId(),
290
                    'l18n_parent' => $id,
291
                    'label' => $this->getLLL('metadata.' . $indexName, $siteLanguage->getTypo3Language(), $metadataLabels),
292
                ];
293
            }
294
295
            Helper::processDatabaseAsAdmin($translateData);
296
        }
297
298
        $this->forward('index');
299
    }
300
301
    /**
302
     * Action adding Solr core records
303
     *
304
     * @access public
305
     *
306
     * @return void
307
     */
308
    public function addSolrCoreAction(): void
309
    {
310
        $doPersist = false;
311
312
        // load language file in own array
313
        $beLabels = $this->languageFactory->getParsedData('EXT:dlf/Resources/Private/Language/locallang_be.xlf', $this->siteLanguages[0]->getTypo3Language());
314
315
        if ($this->solrCoreRepository->findOneByPid($this->pid) === null) {
316
            $newRecord = GeneralUtility::makeInstance(SolrCore::class);
317
            $newRecord->setLabel($this->getLLL('flexform.solrcore', $this->siteLanguages[0]->getTypo3Language(), $beLabels). ' (PID ' . $this->pid . ')');
318
            $indexName = Solr::createCore('');
319
            if (!empty($indexName)) {
320
                $newRecord->setIndexName($indexName);
321
322
                $this->solrCoreRepository->add($newRecord);
323
324
                $doPersist = true;
325
            }
326
        }
327
328
        // We must persist here, if we changed anything.
329
        if ($doPersist === true) {
330
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
331
            $persistenceManager->persistAll();
332
        }
333
334
        $this->forward('index');
335
    }
336
337
    /**
338
     * Action adding structure records
339
     *
340
     * @access public
341
     *
342
     * @return void
343
     */
344
    public function addStructureAction(): void
345
    {
346
        // Include structure definition file.
347
        $structureDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
348
349
        // load language file in own array
350
        $structureLabels = $this->languageFactory->getParsedData('EXT:dlf/Resources/Private/Language/locallang_structure.xlf', $this->siteLanguages[0]->getTypo3Language());
351
352
        $data = [];
353
        foreach ($structureDefaults as $indexName => $values) {
354
            $data['tx_dlf_structures'][uniqid('NEW')] = [
355
                'pid' => $this->pid,
356
                'toplevel' => $values['toplevel'],
357
                'label' => $this->getLLL('structure.' . $indexName, $this->siteLanguages[0]->getTypo3Language(), $structureLabels),
358
                'index_name' => $indexName,
359
                'oai_name' => $values['oai_name'],
360
                'thumbnail' => 0,
361
            ];
362
        }
363
        $structureIds = Helper::processDatabaseAsAdmin($data, [], true);
364
365
        $insertedStructures = [];
366
        foreach ($structureIds as $id => $uid) {
367
            $insertedStructures[$uid] = $this->structureRepository->findByUid($uid)->getIndexName();
368
        }
369
370
        foreach ($this->siteLanguages as $siteLanguage) {
371
            if ($siteLanguage->getLanguageId() === 0) {
372
                // skip default language
373
                continue;
374
            }
375
376
            $translateData = [];
377
            foreach ($insertedStructures as $id => $indexName) {
378
                $translateData['tx_dlf_structures'][uniqid('NEW')] = [
379
                    'pid' => $this->pid,
380
                    'sys_language_uid' => $siteLanguage->getLanguageId(),
381
                    'l18n_parent' => $id,
382
                    'label' => $this->getLLL('structure.' . $indexName, $siteLanguage->getTypo3Language(), $structureLabels),
383
                ];
384
            }
385
386
            Helper::processDatabaseAsAdmin($translateData);
387
        }
388
389
        $this->forward('index');
390
    }
391
392
    /**
393
     * Set up the doc header properly here
394
     * 
395
     * @access protected
396
     *
397
     * @param ViewInterface $view
398
     *
399
     * @return void
400
     */
401
    protected function initializeView(ViewInterface $view): void
402
    {
403
        /** @var BackendTemplateView $view */
404
        parent::initializeView($view);
405
        if ($this->actionMethodName == 'indexAction') {
406
            $this->pageInfo = BackendUtility::readPageAccess($this->pid, $GLOBALS['BE_USER']->getPagePermsClause(1));
407
            $view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
408
        }
409
        if ($view instanceof BackendTemplateView) {
410
            $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
411
        }
412
    }
413
414
    /**
415
     * Main function of the module
416
     *
417
     * @access public
418
     *
419
     * @return void
420
     */
421
    public function indexAction(): void
422
    {
423
        $recordInfos = [];
424
425
        if ($this->pageInfo['doktype'] != 254) {
426
            $this->forward('error');
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Mvc\Co...onController::forward() has been deprecated: since TYPO3 11.0, will be removed in 12.0 ( Ignorable by Annotation )

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

426
            /** @scrutinizer ignore-deprecated */ $this->forward('error');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
427
        }
428
429
        $formatsDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php');
430
        $recordInfos['formats']['numCurrent'] = $this->formatRepository->countAll();
431
        $recordInfos['formats']['numDefault'] = count($formatsDefaults);
432
433
        $structuresDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
434
        $recordInfos['structures']['numCurrent'] = $this->structureRepository->countByPid($this->pid);
435
        $recordInfos['structures']['numDefault'] = count($structuresDefaults);
436
437
        $metadataDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php');
438
        $recordInfos['metadata']['numCurrent'] = $this->metadataRepository->countByPid($this->pid);
439
        $recordInfos['metadata']['numDefault'] = count($metadataDefaults);
440
441
        $recordInfos['solrcore']['numCurrent'] = $this->solrCoreRepository->countByPid($this->pid);
442
443
        $this->view->assign('recordInfos', $recordInfos);
444
    }
445
446
    /**
447
     * Error function - there is nothing to do at the moment.
448
     *
449
     * @access public
450
     *
451
     * @return void
452
     */
453
    // @phpstan-ignore-next-line
454
    public function errorAction(): void
455
    {
456
        // TODO: Call parent::errorAction() when dropping support for TYPO3 v10.
457
    }
458
459
    /**
460
     * Get language label for given key and language.
461
     * 
462
     * @access protected
463
     *
464
     * @param string $index
465
     * @param string $lang
466
     * @param array $langArray
467
     *
468
     * @return string
469
     */
470
    protected function getLLL(string $index, string $lang, array $langArray): string
471
    {
472
        if (isset($langArray[$lang][$index][0]['target'])) {
473
            return $langArray[$lang][$index][0]['target'];
474
        } elseif (isset($langArray['default'][$index][0]['target'])) {
475
            return $langArray['default'][$index][0]['target'];
476
        } else {
477
            return 'Missing translation for ' . $index;
478
        }
479
    }
480
}
481