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::addFormatAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

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

128
            if ($this->formatRepository->/** @scrutinizer ignore-call */ findOneByType($type) === null) {
Loading history...
129
                $newFormat = GeneralUtility::makeInstance(Format::class);
130
                $newFormat->setType($type);
131
                $newFormat->setRoot($values['root']);
132
                $newFormat->setNamespace($values['namespace']);
133
                $newFormat->setClass($values['class']);
134
                $this->formatRepository->add($newFormat);
135
            }
136
137
        }
138
139
        $this->forward('index');
140
    }
141
142
    /**
143
     * Action adding metadata records
144
     */
145
    public function addMetadataAction()
146
    {
147
        // Include metadata definition file.
148
        $metadataDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php');
149
        $i = 0;
150
        // Build data array.
151
        $this->pid = (int) GeneralUtility::_GP('id');
152
153
        foreach ($metadataDefaults as $index_name => $values) {
154
            $formatIds = [];
155
            foreach ($values['format'] as $format) {
156
                $formatIds[] = uniqid('NEW');
157
                $data['tx_dlf_metadataformat'][end($formatIds)] = $format;
158
                $data['tx_dlf_metadataformat'][end($formatIds)]['pid'] = intval($this->pid);
159
                $i++;
160
            }
161
            $data['tx_dlf_metadata'][uniqid('NEW')] = [
162
                'pid' => intval($this->pid),
163
                'label' => $this->getLanguageService()->getLL('metadata.' . $index_name),
164
                'index_name' => $index_name,
165
                'format' => implode(',', $formatIds),
166
                'default_value' => $values['default_value'],
167
                'wrap' => (!empty($values['wrap']) ? $values['wrap'] : $GLOBALS['TCA']['tx_dlf_metadata']['columns']['wrap']['config']['default']),
168
                'index_tokenized' => $values['index_tokenized'],
169
                'index_stored' => $values['index_stored'],
170
                'index_indexed' => $values['index_indexed'],
171
                'index_boost' => $values['index_boost'],
172
                'is_sortable' => $values['is_sortable'],
173
                'is_facet' => $values['is_facet'],
174
                'is_listed' => $values['is_listed'],
175
                'index_autocomplete' => $values['index_autocomplete'],
176
            ];
177
            $i++;
178
        }
179
        $_ids = Helper::processDBasAdmin($data, [], true);
180
        // Check for failed inserts.
181
        if (count($_ids) == $i) {
182
            // Fine.
183
            $this->addFlashMessage(
184
                $this->getLanguageService()->getLL('flash.metadataAddedMsg'),
185
                $this->getLanguageService()->getLL('flash.metadataAdded'),
186
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
187
            );
188
        } else {
189
            // Something went wrong.
190
            $this->addFlashMessage(
191
                $this->getLanguageService()->getLL('flash.metadataNotAddedMsg'),
192
                $this->getLanguageService()->getLL('flash.metadataNotAdded'),
193
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
194
            );
195
        }
196
197
        $this->forward('index');
198
    }
199
200
    /**
201
     * Action adding Solr core records
202
     */
203
    public function addSolrCoreAction()
204
    {
205
        $this->pid = (int) GeneralUtility::_GP('id');
206
        // Build data array.
207
        $data['tx_dlf_solrcores'][uniqid('NEW')] = [
208
            'pid' => intval($this->pid),
209
            'label' => $this->getLanguageService()->getLL('flexform.solrcore') . ' (PID ' . $this->pid . ')',
210
            'index_name' => '',
211
        ];
212
        $_ids = Helper::processDBasAdmin($data);
213
        // Check for failed inserts.
214
        if (count($_ids) == 1) {
215
            // Fine.
216
            $this->addFlashMessage(
217
                $this->getLanguageService()->getLL('flash.solrcoreAddedMsg'),
218
                $this->getLanguageService()->getLL('flash.solrcoreAdded'),
219
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
220
            );
221
        } else {
222
            // Something went wrong.
223
            $this->addFlashMessage(
224
                $this->getLanguageService()->getLL('flash.solrcoreNotAddedMsg'),
225
                $this->getLanguageService()->getLL('flash.solrcoreNotAdded'),
226
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
227
            );
228
        }
229
230
        $this->forward('index');
231
    }
232
233
    /**
234
     * Action adding structure records
235
     */
236
    public function addStructureAction()
237
    {
238
        $this->pid = (int) GeneralUtility::_GP('id');
239
        // Include structure definition file.
240
        $structureDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
241
        // Build data array.
242
        foreach ($structureDefaults as $index_name => $values) {
243
            $data['tx_dlf_structures'][uniqid('NEW')] = [
244
                'pid' => intval($this->pid),
245
                'toplevel' => $values['toplevel'],
246
                'label' => $this->getLanguageService()->getLL('structure.' . $index_name),
247
                'index_name' => $index_name,
248
                'oai_name' => $values['oai_name'],
249
                'thumbnail' => 0,
250
            ];
251
        }
252
        $_ids = Helper::processDBasAdmin($data, [], true);
253
        // Check for failed inserts.
254
        if (count($_ids) == count($structureDefaults)) {
255
            // Fine.
256
            $this->addFlashMessage(
257
                $this->getLanguageService()->getLL('flash.structureAddedMsg'),
258
                $this->getLanguageService()->getLL('flash.structureAdded'),
259
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
260
            );
261
        } else {
262
            // Something went wrong.
263
            $this->addFlashMessage(
264
                $this->getLanguageService()->getLL('flash.structureNotAddedMsg'),
265
                $this->getLanguageService()->getLL('flash.structureNotAdded'),
266
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
267
            );
268
        }
269
270
        $this->forward('index');
271
    }
272
273
    /**
274
     * Set up the doc header properly here
275
     *
276
     * @param ViewInterface $view
277
     * @return void
278
     */
279
    protected function initializeView(ViewInterface $view)
280
    {
281
        /** @var BackendTemplateView $view */
282
        parent::initializeView($view);
283
        if ($this->actionMethodName == 'indexAction'
284
            || $this->actionMethodName == 'onlineAction'
285
            || $this->actionMethodName == 'compareAction') {
286
            $this->pid = (int) GeneralUtility::_GP('id');
287
            $this->pageInfo = BackendUtility::readPageAccess($this->pid, $GLOBALS['BE_USER']->getPagePermsClause(1));
288
            $view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
289
        }
290
        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...
291
            $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
292
        }
293
    }
294
295
    /**
296
     * Main function of the module
297
     *
298
     * @access public
299
     *
300
     */
301
    public function indexAction()
302
    {
303
        $this->pid = (int) GeneralUtility::_GP('id');
304
305
        $formatsDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/FormatDefaults.php');
306
307
        if ($this->pageInfo['doktype'] != 254) {
308
            $this->addFlashMessage(
309
                $this->getLanguageService()->getLL('flash.wrongPageTypeMsg'),
310
                $this->getLanguageService()->getLL('flash.wrongPageType'),
311
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
312
            );
313
            return;
314
        }
315
316
        $countFormats = $this->formatRepository->countAll();
317
318
        if ($countFormats >= count($formatsDefaults)) {
319
            // Fine.
320
            $this->addFlashMessage(
321
                $this->getLanguageService()->getLL('flash.formatOkayMsg'),
322
                $this->getLanguageService()->getLL('flash.formatOkay'),
323
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
324
            );
325
        } else {
326
            // Configuration missing.
327
            $this->addFlashMessage(
328
                $this->getLanguageService()->getLL('flash.formatNotOkayMsg'),
329
                $this->getLanguageService()->getLL('flash.formatNotOkay'),
330
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
331
            );
332
            $this->view->assign('format', 1);
333
        }
334
335
        $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

335
        /** @scrutinizer ignore-call */ 
336
        $structures = $this->structureRepository->countByPid($this->pid);
Loading history...
336
337
        if ($structures) {
338
            // Fine.
339
            $this->addFlashMessage(
340
                $this->getLanguageService()->getLL('flash.structureOkayMsg'),
341
                $this->getLanguageService()->getLL('flash.structureOkay'),
342
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
343
            );
344
        } else {
345
            // Configuration missing.
346
            $this->addFlashMessage(
347
                $this->getLanguageService()->getLL('flash.structureNotOkayMsg'),
348
                $this->getLanguageService()->getLL('flash.structureNotOkay'),
349
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
350
            );
351
            $this->view->assign('structure', 1);
352
        }
353
354
        $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

354
        /** @scrutinizer ignore-call */ 
355
        $metadata = $this->metadataRepository->countByPid($this->pid);
Loading history...
355
356
        if ($metadata) {
357
            // Fine.
358
            $this->addFlashMessage(
359
                $this->getLanguageService()->getLL('flash.metadataOkayMsg'),
360
                $this->getLanguageService()->getLL('flash.metadataOkay'),
361
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
362
            );
363
        } else {
364
            // Configuration missing.
365
            $this->addFlashMessage(
366
                $this->getLanguageService()->getLL('flash.metadataNotOkayMsg'),
367
                $this->getLanguageService()->getLL('flash.metadataNotOkay'),
368
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
369
            );
370
            $this->view->assign('metadata', 1);
371
        }
372
373
        $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

373
        /** @scrutinizer ignore-call */ 
374
        $solrCore = $this->solrCoreRepository->countByPid($this->pid);
Loading history...
374
375
        if ($solrCore) {
376
            // Fine.
377
            $this->addFlashMessage(
378
                $this->getLanguageService()->getLL('flash.solrcoreOkayMsg'),
379
                $this->getLanguageService()->getLL('flash.solrcoreOkay'),
380
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
381
            );
382
        } else {
383
            // Solr core missing.
384
            $this->addFlashMessage(
385
                $this->getLanguageService()->getLL('flash.solrcoreMissingMsg'),
386
                $this->getLanguageService()->getLL('flash.solrcoreMissing'),
387
                \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
388
            );
389
            $this->view->assign('solr', 1);
390
        }
391
    }
392
}
393