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 — dev-extbase-fluid (#782)
by Alexander
02:42
created

NewTenantController::getLLL()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
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;
13
14
use Kitodo\Dlf\Common\Solr;
15
use Kitodo\Dlf\Domain\Model\Format;
16
use Kitodo\Dlf\Domain\Model\Metadata;
17
use Kitodo\Dlf\Domain\Model\MetadataFormat;
18
use Kitodo\Dlf\Domain\Model\SolrCore;
19
use Kitodo\Dlf\Domain\Model\Structure;
20
use Kitodo\Dlf\Domain\Repository\FormatRepository;
21
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
22
use Kitodo\Dlf\Domain\Repository\StructureRepository;
23
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
24
25
use TYPO3\CMS\Backend\Utility\BackendUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Utility\BackendUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use TYPO3\CMS\Core\Localization\LocalizationFactory;
27
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
28
use TYPO3\CMS\Core\Utility\GeneralUtility;
29
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
30
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
31
32
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
33
use TYPO3\CMS\Core\Site\Entity\NullSite;
34
use TYPO3\CMS\Core\Site\Entity\Site;
35
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
36
use TYPO3\CMS\Core\Site\SiteFinder;
37
38
/**
39
 * Controller class for the backend module 'New Tenant'.
40
 *
41
 * @author Christopher Timm <[email protected]>
42
 * @author Alexander Bigga <[email protected]>
43
 * @package TYPO3
44
 * @subpackage dlf
45
 * @access public
46
 */
47
class NewTenantController extends AbstractController
48
{
49
    /**
50
     * @var int
51
     */
52
    protected $pid;
53
54
    /**
55
     * @var array
56
     */
57
    protected $pageInfo;
58
59
    /**
60
     * All configured site languages
61
     *
62
     * @var array
63
     */
64
    protected $siteLanguages;
65
66
    /**
67
     * LanguageFactory to get language key/values by our own.
68
     *
69
     * @var \TYPO3\CMS\Core\Localization\LocalizationFactory
70
     */
71
    protected $languageFactory;
72
73
    /**
74
     * Backend Template Container
75
     *
76
     * @var string
77
     */
78
    protected $defaultViewObjectName = \TYPO3\CMS\Backend\View\BackendTemplateView::class;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\View\BackendTemplateView was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
79
80
    /**
81
     * @var FormatRepository
82
     */
83
    protected $formatRepository;
84
85
    /**
86
     * @param FormatRepository $formatRepository
87
     */
88
    public function injectFormatRepository(FormatRepository $formatRepository)
89
    {
90
        $this->formatRepository = $formatRepository;
91
    }
92
93
    /**
94
     * @var MetadataRepository
95
     */
96
    protected $metadataRepository;
97
98
    /**
99
     * @param MetadataRepository $metadataRepository
100
     */
101
    public function injectMetadataRepository(MetadataRepository $metadataRepository)
102
    {
103
        $this->metadataRepository = $metadataRepository;
104
    }
105
106
    /**
107
     * @var StructureRepository
108
     */
109
    protected $structureRepository;
110
111
    /**
112
     * @param StructureRepository $structureRepository
113
     */
114
    public function injectStructureRepository(StructureRepository $structureRepository)
115
    {
116
        $this->structureRepository = $structureRepository;
117
    }
118
119
    /**
120
     * @var SolrCoreRepository
121
     */
122
    protected $solrCoreRepository;
123
124
    /**
125
     * @param SolrCoreRepository $solrCoreRepository
126
     */
127
    public function injectSolrCoreRepository(SolrCoreRepository $solrCoreRepository)
128
    {
129
        $this->solrCoreRepository = $solrCoreRepository;
130
    }
131
132
    /**
133
     * Initialization for all actions
134
     *
135
     */
136
    protected function initializeAction()
137
    {
138
        $this->pid = (int) GeneralUtility::_GP('id');
139
140
        $frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
141
        $frameworkConfiguration['persistence']['storagePid'] = $this->pid;
142
        $this->configurationManager->setConfiguration($frameworkConfiguration);
143
144
        $this->languageFactory = GeneralUtility::makeInstance(LocalizationFactory::class);
145
146
        try {
147
            $this->site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($this->pid);
0 ignored issues
show
Bug Best Practice introduced by
The property site does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
148
        } catch (SiteNotFoundException $e) {
149
            $this->site = new NullSite();
150
        }
151
        $this->siteLanguages = $this->site->getLanguages();
152
    }
153
154
155
    /**
156
     * Action adding formats records
157
     */
158
    public function addFormatAction()
159
    {
160
        // Include formats definition file.
161
        $formatsDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php');
162
163
        $frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
164
        // tx_dlf_formats are stored on PID = 0
165
        $frameworkConfiguration['persistence']['storagePid'] = 0;
166
        $this->configurationManager->setConfiguration($frameworkConfiguration);
167
168
        $doPersist = false;
169
170
        foreach ($formatsDefaults as $type => $values) {
171
            // if default format record is not found, add it to the repository
172
            if ($this->formatRepository->findOneByType($type) === null) {
0 ignored issues
show
Bug introduced by
The method findOneByType() does not exist on Kitodo\Dlf\Domain\Repository\FormatRepository. 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

172
            if ($this->formatRepository->/** @scrutinizer ignore-call */ findOneByType($type) === null) {
Loading history...
173
                $newRecord = GeneralUtility::makeInstance(Format::class);
174
                $newRecord->setType($type);
175
                $newRecord->setRoot($values['root']);
176
                $newRecord->setNamespace($values['namespace']);
177
                $newRecord->setClass($values['class']);
178
                $this->formatRepository->add($newRecord);
179
180
                $doPersist = true;
181
            }
182
        }
183
184
        // We must persist here, if we changed anything.
185
        if ($doPersist === true) {
186
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
187
            $persistenceManager->persistAll();
188
        }
189
190
        $this->forward('index');
191
    }
192
193
    /**
194
     * Action adding metadata records
195
     */
196
    public function addMetadataAction()
197
    {
198
        // Include metadata definition file.
199
        $metadataDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php');
200
201
        $doPersist = false;
202
203
        // load language file in own array
204
        $metadataLabels = $this->languageFactory->getParsedData('EXT:dlf/Resources/Private/Language/locallang_metadata.xlf', $this->siteLanguages[0]->getTypo3Language());
205
206
        foreach ($metadataDefaults as $indexName => $values) {
207
            // if default format record is not found, add it to the repository
208
            if ($this->metadataRepository->findOneByIndexName($indexName) === null) {
0 ignored issues
show
Bug introduced by
The method findOneByIndexName() does not exist on Kitodo\Dlf\Domain\Repository\MetadataRepository. 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

208
            if ($this->metadataRepository->/** @scrutinizer ignore-call */ findOneByIndexName($indexName) === null) {
Loading history...
209
210
                $newRecord = GeneralUtility::makeInstance(Metadata::class);
211
                $newRecord->setLabel($this->getLLL('metadata.' . $indexName, $this->siteLanguages[0]->getTypo3Language(), $metadataLabels));
212
                $newRecord->setIndexName($indexName);
213
                $newRecord->setDefaultValue($values['default_value']);
214
                $newRecord->setWrap($values['wrap'] ? : $GLOBALS['TCA']['tx_dlf_metadata']['columns']['wrap']['config']['default']);
215
                $newRecord->setIndexTokenized($values['index_tokenized']);
216
                $newRecord->setIndexStored((int) $values['index_stored']);
217
                $newRecord->setIndexIndexed((int) $values['index_indexed']);
218
                $newRecord->setIndexBoost((float) $values['index_boost']);
219
                $newRecord->setIsSortable((int) $values['is_sortable']);
220
                $newRecord->setIsFacet((int) $values['is_facet']);
221
                $newRecord->setIsListed((int) $values['is_listed']);
222
                $newRecord->setIndexAutocomplete((int) $values['index_autocomplete']);
223
224
                if (is_array($values['format'])) {
225
                    foreach ($values['format'] as $format) {
226
                        $formatRecord = $this->formatRepository->findOneByRoot($format['format_root']);
0 ignored issues
show
Bug introduced by
The method findOneByRoot() does not exist on Kitodo\Dlf\Domain\Repository\FormatRepository. 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

226
                        /** @scrutinizer ignore-call */ 
227
                        $formatRecord = $this->formatRepository->findOneByRoot($format['format_root']);
Loading history...
227
                        // If formatRecord is null, we cannot create a MetadataFormat record.
228
                        if ($formatRecord !== null) {
229
                            $newMetadataFormat = GeneralUtility::makeInstance(MetadataFormat::class);
230
                            $newMetadataFormat->setEncoded($formatRecord->getUid());
0 ignored issues
show
Bug introduced by
The method getUid() 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

230
                            $newMetadataFormat->setEncoded($formatRecord->/** @scrutinizer ignore-call */ getUid());

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...
231
                            $newMetadataFormat->setXpath($format['xpath']);
232
                            $newMetadataFormat->setXpathSorting($format['xpath_sorting']);
233
                            $newRecord->addFormat($newMetadataFormat);
234
                        }
235
                    }
236
                }
237
238
                foreach ($this->siteLanguages as $index => $siteLanguage) {
239
                    if ($siteLanguage->getLanguageId() === 0) {
240
                        // skip default language
241
                        continue;
242
                    }
243
                    $translatedRecord = GeneralUtility::makeInstance(Metadata::class);
244
                    $translatedRecord->setL18nParent($newRecord);
245
                    $translatedRecord->_setProperty('_languageUid', $siteLanguage->getLanguageId());
246
                    $translatedRecord->setLabel($this->getLLL('metadata.' . $indexName, $siteLanguage->getTypo3Language(), $metadataLabels));
247
                    $translatedRecord->setIndexName($indexName);
248
                    $translatedRecord->setWrap('');
249
250
                    $this->metadataRepository->add($translatedRecord);
251
                }
252
253
                $this->metadataRepository->add($newRecord);
254
255
                $doPersist = true;
256
            }
257
        }
258
259
        // We must persist here, if we changed anything.
260
        if ($doPersist === true) {
261
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
262
            $persistenceManager->persistAll();
263
        }
264
265
        $this->forward('index');
266
    }
267
268
    /**
269
     * Action adding Solr core records
270
     */
271
    public function addSolrCoreAction()
272
    {
273
        $doPersist = false;
274
275
        // load language file in own array
276
        $beLabels = $this->languageFactory->getParsedData('EXT:dlf/Resources/Private/Language/locallang_be.xlf', $this->siteLanguages[0]->getTypo3Language());
277
278
        if ($this->solrCoreRepository->findOneByPid($this->pid) === null) {
0 ignored issues
show
Bug introduced by
The method findOneByPid() does not exist on Kitodo\Dlf\Domain\Repository\SolrCoreRepository. 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

278
        if ($this->solrCoreRepository->/** @scrutinizer ignore-call */ findOneByPid($this->pid) === null) {
Loading history...
279
            $newRecord = GeneralUtility::makeInstance(SolrCore::class);
280
            $newRecord->setLabel($this->getLLL('flexform.solrcore', $this->siteLanguages[0]->getTypo3Language(), $beLabels). ' (PID ' . $this->pid . ')');
281
            $indexName = Solr::createCore('');
282
            $newRecord->setIndexName($indexName);
283
284
            $this->solrCoreRepository->add($newRecord);
285
286
            $doPersist = true;
287
        }
288
289
        // We must persist here, if we changed anything.
290
        if ($doPersist === true) {
291
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
292
            $persistenceManager->persistAll();
293
        }
294
295
        $this->forward('index');
296
    }
297
298
    /**
299
     * Action adding structure records
300
     */
301
    public function addStructureAction()
302
    {
303
        // Include structure definition file.
304
        $structureDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
305
306
        $doPersist = false;
307
308
        // load language file in own array
309
        $structLabels = $this->languageFactory->getParsedData('EXT:dlf/Resources/Private/Language/locallang_structure.xlf', $this->siteLanguages[0]->getTypo3Language());
310
311
        foreach ($structureDefaults as $indexName => $values) {
312
            // if default format record is not found, add it to the repository
313
            if ($this->structureRepository->findOneByIndexName($indexName) === null) {
0 ignored issues
show
Bug introduced by
The method findOneByIndexName() does not exist on Kitodo\Dlf\Domain\Repository\StructureRepository. 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

313
            if ($this->structureRepository->/** @scrutinizer ignore-call */ findOneByIndexName($indexName) === null) {
Loading history...
314
                $newRecord = GeneralUtility::makeInstance(Structure::class);
315
                $newRecord->setLabel($this->getLLL('structure.' . $indexName, $this->siteLanguages[0]->getTypo3Language(), $structLabels));
316
                $newRecord->setIndexName($indexName);
317
                $newRecord->setToplevel($values['toplevel']);
318
                $newRecord->setOaiName($values['oai_name']);
319
                $this->structureRepository->add($newRecord);
320
321
                foreach ($this->siteLanguages as $index => $siteLanguage) {
322
                    if ($siteLanguage->getLanguageId() === 0) {
323
                        // skip default language
324
                        continue;
325
                    }
326
                    $translatedRecord = GeneralUtility::makeInstance(Structure::class);
327
                    $translatedRecord->setL18nParent($newRecord);
328
                    $translatedRecord->_setProperty('_languageUid', $siteLanguage->getLanguageId());
329
                    $translatedRecord->setLabel($this->getLLL('structure.' . $indexName, $siteLanguage->getTypo3Language(), $structLabels));
330
                    $translatedRecord->setIndexName($indexName);
331
332
                    $this->structureRepository->add($translatedRecord);
333
                }
334
335
                $doPersist = true;
336
            }
337
        }
338
339
        // We must persist here, if we changed anything.
340
        if ($doPersist === true) {
341
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
342
            $persistenceManager->persistAll();
343
        }
344
345
        $this->forward('index');
346
    }
347
348
    /**
349
     * Set up the doc header properly here
350
     *
351
     * @param ViewInterface $view
352
     * @return void
353
     */
354
    protected function initializeView(ViewInterface $view)
355
    {
356
        /** @var BackendTemplateView $view */
357
        parent::initializeView($view);
358
        if ($this->actionMethodName == 'indexAction') {
359
            $this->pageInfo = BackendUtility::readPageAccess($this->pid, $GLOBALS['BE_USER']->getPagePermsClause(1));
360
            $view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
361
        }
362
        if ($view instanceof BackendTemplateView) {
0 ignored issues
show
Bug introduced by
The type Kitodo\Dlf\Controller\BackendTemplateView was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
363
            $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
364
        }
365
    }
366
367
    /**
368
     * Main function of the module
369
     *
370
     * @access public
371
     *
372
     */
373
    public function indexAction()
374
    {
375
        $recordInfos = [];
376
377
        if ($this->pageInfo['doktype'] != 254) {
378
            $this->forward('error');
379
        }
380
381
        $formatsDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php');
382
        $recordInfos['formats']['numCurrent'] = $this->formatRepository->countAll();
383
        $recordInfos['formats']['numDefault'] = count($formatsDefaults);
384
385
        $structuresDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
386
        $recordInfos['structures']['numCurrent'] = $this->structureRepository->countByPid($this->pid);
0 ignored issues
show
Bug introduced by
The method countByPid() does not exist on Kitodo\Dlf\Domain\Repository\StructureRepository. 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

386
        /** @scrutinizer ignore-call */ 
387
        $recordInfos['structures']['numCurrent'] = $this->structureRepository->countByPid($this->pid);
Loading history...
387
        $recordInfos['structures']['numDefault'] = count($structuresDefaults);
388
389
        $metadataDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php');
390
        $recordInfos['metadata']['numCurrent'] = $this->metadataRepository->countByPid($this->pid);
0 ignored issues
show
Bug introduced by
The method countByPid() does not exist on Kitodo\Dlf\Domain\Repository\MetadataRepository. 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

390
        /** @scrutinizer ignore-call */ 
391
        $recordInfos['metadata']['numCurrent'] = $this->metadataRepository->countByPid($this->pid);
Loading history...
391
        $recordInfos['metadata']['numDefault'] = count($metadataDefaults);
392
393
        $recordInfos['solrcore']['numCurrent'] = $this->solrCoreRepository->countByPid($this->pid);
0 ignored issues
show
Bug introduced by
The method countByPid() does not exist on Kitodo\Dlf\Domain\Repository\SolrCoreRepository. 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

393
        /** @scrutinizer ignore-call */ 
394
        $recordInfos['solrcore']['numCurrent'] = $this->solrCoreRepository->countByPid($this->pid);
Loading history...
394
395
        $this->view->assign('recordInfos', $recordInfos);
396
    }
397
398
    /**
399
     * Error function - there is nothing to do at the moment.
400
     *
401
     * @access public
402
     *
403
     */
404
    public function errorAction()
405
    {
406
    }
407
408
    /**
409
     * Get language label for given key and language.
410
     *
411
     * @param string $index
412
     * @param string $lang
413
     * @param array $langArray
414
     *
415
     * @access public
416
     */
417
    protected function getLLL($index, $lang, $langArray)
418
    {
419
        if (isset($langArray[$lang][$index][0]['target'])) {
420
            return $langArray[$lang][$index][0]['target'];
421
        } else {
422
            return $langArray['default'][$index][0]['target'];
423
        }
424
    }
425
}
426