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

NewTenantController::injectSolrCoreRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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

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

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

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

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

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

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

335
        /** @scrutinizer ignore-call */ 
336
        $recordInfos['solrcore']['numCurrent'] = $this->solrCoreRepository->countByPid($this->pid);
Loading history...
336
337
        $this->view->assign('recordInfos', $recordInfos);
338
    }
339
}
340