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:50
created

NewTenantController::injectFormatRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

144
            if ($this->formatRepository->/** @scrutinizer ignore-call */ findOneByType($type) === null) {
Loading history...
145
                $newRecord = GeneralUtility::makeInstance(Format::class);
146
                $newRecord->setType($type);
147
                $newRecord->setRoot($values['root']);
148
                $newRecord->setNamespace($values['namespace']);
149
                $newRecord->setClass($values['class']);
150
                $this->formatRepository->add($newRecord);
151
152
                $doPersist = true;
153
            }
154
        }
155
156
        // We must persist here, if we changed anything.
157
        if ($doPersist === true) {
158
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
159
            $persistenceManager->persistAll();
160
        }
161
162
        $this->forward('index');
163
    }
164
165
    /**
166
     * Action adding metadata records
167
     */
168
    public function addMetadataAction()
169
    {
170
        // Include metadata definition file.
171
        $metadataDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php');
172
173
        // Set storagePid for saving records.
174
        $frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
175
        $frameworkConfiguration['persistence']['storagePid'] = $this->pid;
176
        $this->configurationManager->setConfiguration($frameworkConfiguration);
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
        // Build data array.
231
        $data['tx_dlf_solrcores'][uniqid('NEW')] = [
232
            'pid' => intval($this->pid),
233
            'label' => $this->getLanguageService()->getLL('flexform.solrcore') . ' (PID ' . $this->pid . ')',
234
            'index_name' => '',
235
        ];
236
        $_ids = Helper::processDBasAdmin($data);
237
        // Check for failed inserts.
238
        if (count($_ids) == 1) {
239
            // Fine.
240
            $this->addFlashMessage(
241
                $this->getLanguageService()->getLL('flash.solrcoreAddedMsg'),
242
                $this->getLanguageService()->getLL('flash.solrcoreAdded'),
243
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
244
            );
245
        } else {
246
            // Something went wrong.
247
            $this->addFlashMessage(
248
                $this->getLanguageService()->getLL('flash.solrcoreNotAddedMsg'),
249
                $this->getLanguageService()->getLL('flash.solrcoreNotAdded'),
250
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
251
            );
252
        }
253
254
        $this->forward('index');
255
    }
256
257
    /**
258
     * Action adding structure records
259
     */
260
    public function addStructureAction()
261
    {
262
        // Include structure definition file.
263
        $structureDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
264
265
        // Set storagePid for saving records.
266
        $frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
267
        $frameworkConfiguration['persistence']['storagePid'] = $this->pid;
268
        $this->configurationManager->setConfiguration($frameworkConfiguration);
269
270
        $doPersist = false;
271
272
        foreach ($structureDefaults as $indexName => $values) {
273
            // if default format record is not found, add it to the repository
274
            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

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

340
        /** @scrutinizer ignore-call */ 
341
        $structures = $this->structureRepository->countByPid($this->pid);
Loading history...
341
        $recordInfos['structures']['numCurrent'] = $this->structureRepository->countByPid($this->pid);
342
        $recordInfos['structures']['numDefault'] = count($structuresDefaults);
343
344
        $metadataDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php');
345
        $metadata = $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

345
        /** @scrutinizer ignore-call */ 
346
        $metadata = $this->metadataRepository->countByPid($this->pid);
Loading history...
Unused Code introduced by
The assignment to $metadata is dead and can be removed.
Loading history...
346
        $recordInfos['metadata']['numCurrent'] = $this->metadataRepository->countByPid($this->pid);
347
        $recordInfos['metadata']['numDefault'] = count($metadataDefaults);
348
349
        $solrCore = $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

349
        /** @scrutinizer ignore-call */ 
350
        $solrCore = $this->solrCoreRepository->countByPid($this->pid);
Loading history...
350
351
        if ($solrCore) {
352
            // Fine.
353
            $this->addFlashMessage(
354
                $this->getLanguageService()->getLL('flash.solrcoreOkayMsg'),
355
                $this->getLanguageService()->getLL('flash.solrcoreOkay'),
356
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
357
            );
358
        } else {
359
            // Solr core missing.
360
            $this->addFlashMessage(
361
                $this->getLanguageService()->getLL('flash.solrcoreMissingMsg'),
362
                $this->getLanguageService()->getLL('flash.solrcoreMissing'),
363
                \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
364
            );
365
            $this->view->assign('solr', 1);
366
        }
367
368
369
        $this->view->assign('recordInfos', $recordInfos);
370
    }
371
}
372