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:59
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\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
        $frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
126
        $frameworkConfiguration['persistence']['storagePid'] = $this->pid;
127
        $this->configurationManager->setConfiguration($frameworkConfiguration);
128
    }
129
130
131
    /**
132
     * Action adding formats records
133
     */
134
    public function addFormatAction()
135
    {
136
        // Include formats definition file.
137
        $formatsDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php');
138
139
        $frameworkConfiguration = $this->configurationManager->getConfiguration($this->configurationManager::CONFIGURATION_TYPE_FRAMEWORK);
140
        // tx_dlf_formats are stored on PID = 0
141
        $frameworkConfiguration['persistence']['storagePid'] = 0;
142
        $this->configurationManager->setConfiguration($frameworkConfiguration);
143
144
        $doPersist = false;
145
146
        foreach ($formatsDefaults as $type => $values) {
147
            // if default format record is not found, add it to the repository
148
            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

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

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

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

202
                            $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...
203
                            $newMetadataFormat->setXpath($format['xpath']);
204
                            $newMetadataFormat->setXpathSorting($format['xpath_sorting']);
205
                            $newRecord->addFormat($newMetadataFormat);
206
                        }
207
                    }
208
                }
209
                $this->metadataRepository->add($newRecord);
210
211
                $doPersist = true;
212
            }
213
        }
214
215
        // We must persist here, if we changed anything.
216
        if ($doPersist === true) {
217
            $persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);
218
            $persistenceManager->persistAll();
219
        }
220
221
        $this->forward('index');
222
    }
223
224
    /**
225
     * Action adding Solr core records
226
     */
227
    public function addSolrCoreAction()
228
    {
229
        // Build data array.
230
        $data['tx_dlf_solrcores'][uniqid('NEW')] = [
231
            'pid' => intval($this->pid),
232
            'label' => $this->getLanguageService()->getLL('flexform.solrcore') . ' (PID ' . $this->pid . ')',
233
            'index_name' => '',
234
        ];
235
        $_ids = Helper::processDBasAdmin($data);
236
        // Check for failed inserts.
237
        if (count($_ids) == 1) {
238
            // Fine.
239
            $this->addFlashMessage(
240
                $this->getLanguageService()->getLL('flash.solrcoreAddedMsg'),
241
                $this->getLanguageService()->getLL('flash.solrcoreAdded'),
242
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
243
            );
244
        } else {
245
            // Something went wrong.
246
            $this->addFlashMessage(
247
                $this->getLanguageService()->getLL('flash.solrcoreNotAddedMsg'),
248
                $this->getLanguageService()->getLL('flash.solrcoreNotAdded'),
249
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
250
            );
251
        }
252
253
        $this->forward('index');
254
    }
255
256
    /**
257
     * Action adding structure records
258
     */
259
    public function addStructureAction()
260
    {
261
        // Include structure definition file.
262
        $structureDefaults = include(ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
263
264
        $doPersist = false;
265
266
        foreach ($structureDefaults as $indexName => $values) {
267
            // if default format record is not found, add it to the repository
268
            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

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

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

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

339
        /** @scrutinizer ignore-call */ 
340
        $solrCore = $this->solrCoreRepository->countByPid($this->pid);
Loading history...
340
341
        if ($solrCore) {
342
            // Fine.
343
            $this->addFlashMessage(
344
                $this->getLanguageService()->getLL('flash.solrcoreOkayMsg'),
345
                $this->getLanguageService()->getLL('flash.solrcoreOkay'),
346
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
347
            );
348
        } else {
349
            // Solr core missing.
350
            $this->addFlashMessage(
351
                $this->getLanguageService()->getLL('flash.solrcoreMissingMsg'),
352
                $this->getLanguageService()->getLL('flash.solrcoreMissing'),
353
                \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
354
            );
355
            $this->view->assign('solr', 1);
356
        }
357
358
        $this->view->assign('recordInfos', $recordInfos);
359
    }
360
}
361