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

NewTenantController::addFormatAction()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 33
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 18
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 33
rs 9.6666
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
     * Action adding structure records
253
     */
254
    public function addStructureAction()
255
    {
256
        // Include structure definition file.
257
        $structureDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
258
259
        $doPersist = false;
260
261
        foreach ($structureDefaults as $indexName => $values) {
262
            // if default format record is not found, add it to the repository
263
            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

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

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

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

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