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 (#777)
by Alexander
02:43
created

NewTenantController::errorAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
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\Helper;
15
use Kitodo\Dlf\Common\Solr;
16
use Kitodo\Dlf\Domain\Model\Format;
17
use Kitodo\Dlf\Domain\Model\Metadata;
18
use Kitodo\Dlf\Domain\Model\MetadataFormat;
19
use Kitodo\Dlf\Domain\Model\SolrCore;
20
use Kitodo\Dlf\Domain\Model\Structure;
21
use Kitodo\Dlf\Domain\Repository\FormatRepository;
22
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
23
use Kitodo\Dlf\Domain\Repository\StructureRepository;
24
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
25
26
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...
27
use TYPO3\CMS\Core\Utility\GeneralUtility;
28
use TYPO3\CMS\Core\Localization\LanguageService;
29
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
30
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
31
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
32
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
33
34
35
/**
36
 * Class for the NewTenant backend module
37
 *
38
 * @package TYPO3
39
 * @subpackage dlf
40
 * @access public
41
 */
42
class NewTenantController extends AbstractController
43
{
44
    /**
45
     * @var int
46
     */
47
    protected $pid;
48
49
    /**
50
     * @var array
51
     */
52
    protected $pageInfo;
53
54
    /**
55
     * Backend Template Container
56
     *
57
     * @var string
58
     */
59
    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...
60
61
    /**
62
     * @var FormatRepository
63
     */
64
    protected $formatRepository;
65
66
    /**
67
     * @param FormatRepository $formatRepository
68
     */
69
    public function injectFormatRepository(FormatRepository $formatRepository)
70
    {
71
        $this->formatRepository = $formatRepository;
72
    }
73
74
    /**
75
     * @var MetadataRepository
76
     */
77
    protected $metadataRepository;
78
79
    /**
80
     * @param MetadataRepository $metadataRepository
81
     */
82
    public function injectMetadataRepository(MetadataRepository $metadataRepository)
83
    {
84
        $this->metadataRepository = $metadataRepository;
85
    }
86
87
    /**
88
     * @var StructureRepository
89
     */
90
    protected $structureRepository;
91
92
    /**
93
     * @param StructureRepository $structureRepository
94
     */
95
    public function injectStructureRepository(StructureRepository $structureRepository)
96
    {
97
        $this->structureRepository = $structureRepository;
98
    }
99
100
    /**
101
     * @var SolrCoreRepository
102
     */
103
    protected $solrCoreRepository;
104
105
    /**
106
     * @param SolrCoreRepository $solrCoreRepository
107
     */
108
    public function injectSolrCoreRepository(SolrCoreRepository $solrCoreRepository)
109
    {
110
        $this->solrCoreRepository = $solrCoreRepository;
111
    }
112
113
    /**
114
     * Initialization for all actions
115
     *
116
     */
117
    protected function initializeAction()
118
    {
119
        // Load backend localization file.
120
        $this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_be.xlf');
121
        $this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_mod_newtenant.xlf');
122
        $this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_structure.xlf');
123
        $this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_metadata.xlf');
124
125
        $this->pid = (int) GeneralUtility::_GP('id');
126
127
        $frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
128
        $frameworkConfiguration['persistence']['storagePid'] = $this->pid;
129
        $this->configurationManager->setConfiguration($frameworkConfiguration);
130
    }
131
132
133
    /**
134
     * Action adding formats records
135
     */
136
    public function addFormatAction()
137
    {
138
        // Include formats definition file.
139
        $formatsDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php');
140
141
        $frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
142
        // tx_dlf_formats are stored on PID = 0
143
        $frameworkConfiguration['persistence']['storagePid'] = 0;
144
        $this->configurationManager->setConfiguration($frameworkConfiguration);
145
146
        $doPersist = false;
147
148
        foreach ($formatsDefaults as $type => $values) {
149
            // if default format record is not found, add it to the repository
150
            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

150
            if ($this->formatRepository->/** @scrutinizer ignore-call */ findOneByType($type) === null) {
Loading history...
151
                $newRecord = GeneralUtility::makeInstance(Format::class);
152
                $newRecord->setType($type);
153
                $newRecord->setRoot($values['root']);
154
                $newRecord->setNamespace($values['namespace']);
155
                $newRecord->setClass($values['class']);
156
                $this->formatRepository->add($newRecord);
157
158
                $doPersist = true;
159
            }
160
        }
161
162
        // We must persist here, if we changed anything.
163
        if ($doPersist === true) {
164
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
165
            $persistenceManager->persistAll();
166
        }
167
168
        $this->forward('index');
169
    }
170
171
    /**
172
     * Action adding metadata records
173
     */
174
    public function addMetadataAction()
175
    {
176
        // Include metadata definition file.
177
        $metadataDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php');
178
179
        $doPersist = false;
180
181
        foreach ($metadataDefaults as $indexName => $values) {
182
            // if default format record is not found, add it to the repository
183
            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

183
            if ($this->metadataRepository->/** @scrutinizer ignore-call */ findOneByIndexName($indexName) === null) {
Loading history...
184
                $newRecord = GeneralUtility::makeInstance(Metadata::class);
185
                $newRecord->setLabel($this->getLanguageService()->getLL('metadata.' . $indexName));
186
                $newRecord->setIndexName($indexName);
187
                $newRecord->setDefaultValue($values['default_value']);
188
                $newRecord->setWrap($values['wrap']);
189
                $newRecord->setIndexTokenized($values['index_tokenized']);
190
                $newRecord->setIndexStored((int) $values['index_stored']);
191
                $newRecord->setIndexIndexed((int) $values['index_indexed']);
192
                $newRecord->setIndexBoost((float) $values['index_boost']);
193
                $newRecord->setIsSortable((int) $values['is_sortable']);
194
                $newRecord->setIsFacet((int) $values['is_facet']);
195
                $newRecord->setIsListed((int) $values['is_listed']);
196
                $newRecord->setIndexAutocomplete((int) $values['index_autocomplete']);
197
198
                if (is_array($values['format'])) {
199
                    foreach ($values['format'] as $format) {
200
                        $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

200
                        /** @scrutinizer ignore-call */ 
201
                        $formatRecord = $this->formatRepository->findOneByRoot($format['format_root']);
Loading history...
201
                        // If formatRecord is null, we cannot create a MetadataFormat record.
202
                        if ($formatRecord !== null) {
203
                            $newMetadataFormat = GeneralUtility::makeInstance(MetadataFormat::class);
204
                            $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

204
                            $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...
205
                            $newMetadataFormat->setXpath($format['xpath']);
206
                            $newMetadataFormat->setXpathSorting($format['xpath_sorting']);
207
                            $newRecord->addFormat($newMetadataFormat);
208
                        }
209
                    }
210
                }
211
                $this->metadataRepository->add($newRecord);
212
213
                $doPersist = true;
214
            }
215
        }
216
217
        // We must persist here, if we changed anything.
218
        if ($doPersist === true) {
219
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
220
            $persistenceManager->persistAll();
221
        }
222
223
        $this->forward('index');
224
    }
225
226
    /**
227
     * Action adding Solr core records
228
     */
229
    public function addSolrCoreAction()
230
    {
231
        $doPersist = false;
232
233
        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

233
        if ($this->solrCoreRepository->/** @scrutinizer ignore-call */ findOneByPid($this->pid) === null) {
Loading history...
234
            $newRecord = GeneralUtility::makeInstance(SolrCore::class);
235
            $newRecord->setLabel($this->getLanguageService()->getLL('flexform.solrcore') . ' (PID ' . $this->pid . ')');
236
            $indexName = Solr::createCore('');
237
            $newRecord->setIndexName($indexName);
238
239
            $this->solrCoreRepository->add($newRecord);
240
241
            $doPersist = true;
242
        }
243
244
        // We must persist here, if we changed anything.
245
        if ($doPersist === true) {
246
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
247
            $persistenceManager->persistAll();
248
        }
249
250
        $this->forward('index');
251
    }
252
253
    /**
254
     * Action adding structure records
255
     */
256
    public function addStructureAction()
257
    {
258
        // Include structure definition file.
259
        $structureDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
260
261
        $doPersist = false;
262
263
        foreach ($structureDefaults as $indexName => $values) {
264
            // if default format record is not found, add it to the repository
265
            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

265
            if ($this->structureRepository->/** @scrutinizer ignore-call */ findOneByIndexName($indexName) === null) {
Loading history...
266
                $newRecord = GeneralUtility::makeInstance(Structure::class);
267
                $newRecord->setLabel($this->getLanguageService()->getLL('structure.' . $indexName));
268
                $newRecord->setIndexName($indexName);
269
                $newRecord->setToplevel($values['toplevel']);
270
                $newRecord->setOaiName($values['oai_name']);
271
                $this->structureRepository->add($newRecord);
272
273
                $doPersist = true;
274
            }
275
        }
276
277
        // We must persist here, if we changed anything.
278
        if ($doPersist === true) {
279
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
280
            $persistenceManager->persistAll();
281
        }
282
283
        $this->forward('index');
284
    }
285
286
    /**
287
     * Set up the doc header properly here
288
     *
289
     * @param ViewInterface $view
290
     * @return void
291
     */
292
    protected function initializeView(ViewInterface $view)
293
    {
294
        /** @var BackendTemplateView $view */
295
        parent::initializeView($view);
296
        if ($this->actionMethodName == 'indexAction') {
297
            $this->pageInfo = BackendUtility::readPageAccess($this->pid, $GLOBALS['BE_USER']->getPagePermsClause(1));
298
            $view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
299
        }
300
        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...
301
            $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
302
        }
303
    }
304
305
    /**
306
     * Main function of the module
307
     *
308
     * @access public
309
     *
310
     */
311
    public function indexAction()
312
    {
313
        $recordInfos = [];
314
315
        if ($this->pageInfo['doktype'] != 254) {
316
            $this->forward('error');
317
        }
318
319
        $formatsDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php');
320
        $recordInfos['formats']['numCurrent'] = $this->formatRepository->countAll();
321
        $recordInfos['formats']['numDefault'] = count($formatsDefaults);
322
323
        $structuresDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
324
        $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

324
        /** @scrutinizer ignore-call */ 
325
        $recordInfos['structures']['numCurrent'] = $this->structureRepository->countByPid($this->pid);
Loading history...
325
        $recordInfos['structures']['numDefault'] = count($structuresDefaults);
326
327
        $metadataDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php');
328
        $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

328
        /** @scrutinizer ignore-call */ 
329
        $recordInfos['metadata']['numCurrent'] = $this->metadataRepository->countByPid($this->pid);
Loading history...
329
        $recordInfos['metadata']['numDefault'] = count($metadataDefaults);
330
331
        $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

331
        /** @scrutinizer ignore-call */ 
332
        $recordInfos['solrcore']['numCurrent'] = $this->solrCoreRepository->countByPid($this->pid);
Loading history...
332
333
        $this->view->assign('recordInfos', $recordInfos);
334
    }
335
336
    /**
337
     * Error function - there is nothing to do at the moment.
338
     *
339
     * @access public
340
     *
341
     */
342
    public function errorAction()
343
    {
344
    }
345
346
}
347