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 (#745)
by Alexander
03:22
created

NewTenantController::initializeAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
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 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...
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Core\Localization\LanguageService;
18
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
19
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
20
use Kitodo\Dlf\Domain\Repository\StructureRepository;
21
use Kitodo\Dlf\Domain\Repository\MetadataRepository;
22
use Kitodo\Dlf\Domain\Repository\SolrCoreRepository;
23
24
class NewTenantController extends AbstractController
25
{
26
    /**
27
     * @var int
28
     */
29
    protected $pid;
30
31
    /**
32
     * @var array
33
     */
34
    protected $pageInfo;
35
36
    /**
37
     * Backend Template Container
38
     *
39
     * @var string
40
     */
41
    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...
42
43
    /**
44
     * @var StructureRepository
45
     */
46
    protected $structureRepository;
47
48
    /**
49
     * @param StructureRepository $structureRepository
50
     */
51
    public function injectStructureRepository(StructureRepository $structureRepository)
52
    {
53
        $this->structureRepository = $structureRepository;
54
    }
55
56
    /**
57
     * @var MetadataRepository
58
     */
59
    protected $metadataRepository;
60
61
    /**
62
     * @param MetadataRepository $metadataRepository
63
     */
64
    public function injectMetadataRepository(MetadataRepository $metadataRepository)
65
    {
66
        $this->metadataRepository = $metadataRepository;
67
    }
68
69
    /**
70
     * @var SolrCoreRepository
71
     */
72
    protected $solrCoreRepository;
73
74
    /**
75
     * @param SolrCoreRepository $solrCoreRepository
76
     */
77
    public function injectSolrCoreRepository(SolrCoreRepository $solrCoreRepository)
78
    {
79
        $this->solrCoreRepository = $solrCoreRepository;
80
    }
81
82
    /**
83
     * Initialization for all actions
84
     *
85
     */
86
    protected function initializeAction()
87
    {
88
        // Load backend localization file.
89
        $this->getLanguageService()->includeLLFile('EXT:dlf/Resources/Private/Language/locallang_be.xlf');
90
    }
91
92
    /**
93
     * Action adding metadata records
94
     */
95
    public function addMetadataAction()
96
    {
97
        // Include metadata definition file.
98
        $metadataDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/MetadataDefaults.php');
99
        $i = 0;
100
        // Build data array.
101
        $this->pid = (int) GeneralUtility::_GP('id');
102
103
        foreach ($metadataDefaults as $index_name => $values) {
104
            $formatIds = [];
105
            foreach ($values['format'] as $format) {
106
                $formatIds[] = uniqid('NEW');
107
                $data['tx_dlf_metadataformat'][end($formatIds)] = $format;
108
                $data['tx_dlf_metadataformat'][end($formatIds)]['pid'] = intval($this->pid);
109
                $i++;
110
            }
111
            $data['tx_dlf_metadata'][uniqid('NEW')] = [
112
                'pid' => intval($this->pid),
113
                'label' => $GLOBALS['LANG']->sL('LLL:EXT:dlf/Resources/Private/Language/NewTenant.xml:metadata.' . $index_name),
114
                'index_name' => $index_name,
115
                'format' => implode(',', $formatIds),
116
                'default_value' => $values['default_value'],
117
                'wrap' => (!empty($values['wrap']) ? $values['wrap'] : $GLOBALS['TCA']['tx_dlf_metadata']['columns']['wrap']['config']['default']),
118
                'index_tokenized' => $values['index_tokenized'],
119
                'index_stored' => $values['index_stored'],
120
                'index_indexed' => $values['index_indexed'],
121
                'index_boost' => $values['index_boost'],
122
                'is_sortable' => $values['is_sortable'],
123
                'is_facet' => $values['is_facet'],
124
                'is_listed' => $values['is_listed'],
125
                'index_autocomplete' => $values['index_autocomplete'],
126
            ];
127
            $i++;
128
        }
129
        $_ids = Helper::processDBasAdmin($data, [], true);
130
        // Check for failed inserts.
131
        if (count($_ids) == $i) {
132
            // Fine.
133
            $this->addFlashMessage(
134
                $this->getLanguageService()->getLL('flash.metadataAddedMsg'),
135
                $this->getLanguageService()->getLL('flash.metadataAdded'),
136
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
137
            );
138
        } else {
139
            // Something went wrong.
140
            $this->addFlashMessage(
141
                $this->getLanguageService()->getLL('flash.metadataNotAddedMsg'),
142
                $this->getLanguageService()->getLL('flash.metadataNotAdded'),
143
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
144
            );
145
        }
146
147
        $this->forward('index');
148
    }
149
150
    /**
151
     * Action adding Solr core records
152
     */
153
    public function addSolrCoreAction()
154
    {
155
        $this->pid = (int) GeneralUtility::_GP('id');
156
        // Build data array.
157
        $data['tx_dlf_solrcores'][uniqid('NEW')] = [
158
            'pid' => intval($this->pid),
159
            'label' => $GLOBALS['LANG']->sL('LLL:EXT:dlf/Resources/Private/Language/NewTenant.xml:solrcore') . ' (PID ' . $this->pid . ')',
160
            'index_name' => '',
161
        ];
162
        $_ids = Helper::processDBasAdmin($data);
163
        // Check for failed inserts.
164
        if (count($_ids) == 1) {
165
            // Fine.
166
            $this->addFlashMessage(
167
                $this->getLanguageService()->getLL('flash.solrcoreAddedMsg'),
168
                $this->getLanguageService()->getLL('flash.solrcoreAdded'),
169
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
170
            );
171
        } else {
172
            // Something went wrong.
173
            $this->addFlashMessage(
174
                $this->getLanguageService()->getLL('flash.solrcoreNotAddedMsg'),
175
                $this->getLanguageService()->getLL('flash.solrcoreNotAdded'),
176
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
177
            );
178
        }
179
180
        $this->forward('index');
181
    }
182
183
    /**
184
     * Action adding structure records
185
     */
186
    public function addStructureAction()
187
    {
188
        $this->pid = (int) GeneralUtility::_GP('id');
189
        // Include structure definition file.
190
        $structureDefaults = include (ExtensionManagementUtility::extPath('dlf') . 'Resources/Private/Data/StructureDefaults.php');
191
        // Build data array.
192
        foreach ($structureDefaults as $index_name => $values) {
193
            $data['tx_dlf_structures'][uniqid('NEW')] = [
194
                'pid' => intval($this->pid),
195
                'toplevel' => $values['toplevel'],
196
                'label' => $GLOBALS['LANG']->sL('LLL:EXT:dlf/Resources/Private/Language/NewTenant.xml:structure.' . $index_name),
197
                'index_name' => $index_name,
198
                'oai_name' => $values['oai_name'],
199
                'thumbnail' => 0,
200
            ];
201
        }
202
        $_ids = Helper::processDBasAdmin($data, [], true);
203
        // Check for failed inserts.
204
        if (count($_ids) == count($structureDefaults)) {
205
            // Fine.
206
            $this->addFlashMessage(
207
                $this->getLanguageService()->getLL('flash.structureAddedMsg'),
208
                $this->getLanguageService()->getLL('flash.structureAdded'),
209
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
210
            );
211
        } else {
212
            // Something went wrong.
213
            $this->addFlashMessage(
214
                $this->getLanguageService()->getLL('flash.structureNotAddedMsg'),
215
                $this->getLanguageService()->getLL('flash.structureNotAdded'),
216
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
217
            );
218
        }
219
220
        $this->forward('index');
221
    }
222
223
    /**
224
     * Set up the doc header properly here
225
     *
226
     * @param ViewInterface $view
227
     * @return void
228
     */
229
    protected function initializeView(ViewInterface $view)
230
    {
231
        /** @var BackendTemplateView $view */
232
        parent::initializeView($view);
233
        if ($this->actionMethodName == 'indexAction'
234
            || $this->actionMethodName == 'onlineAction'
235
            || $this->actionMethodName == 'compareAction') {
236
            $this->pid = (int) GeneralUtility::_GP('id');
237
            $this->pageInfo = BackendUtility::readPageAccess($this->pid, $GLOBALS['BE_USER']->getPagePermsClause(1));
238
            $view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
239
        }
240
        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...
241
            $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
242
        }
243
    }
244
245
    /**
246
     * Main function of the module
247
     *
248
     * @access public
249
     *
250
     */
251
    public function indexAction()
252
    {
253
        $this->pid = (int) GeneralUtility::_GP('id');
254
255
        if ($this->pageInfo['doktype'] != 254) {
256
            $this->addFlashMessage(
257
                $this->getLanguageService()->getLL('flash.wrongPageTypeMsg'),
258
                $this->getLanguageService()->getLL('flash.wrongPageType'),
259
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
260
            );
261
            return;
262
        }
263
264
        $structures = $this->structureRepository->findByPid($this->pid);
0 ignored issues
show
Bug introduced by
The method findByPid() 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
        /** @scrutinizer ignore-call */ 
265
        $structures = $this->structureRepository->findByPid($this->pid);
Loading history...
265
266
        if (count($structures) > 0) {
0 ignored issues
show
Bug introduced by
It seems like $structures can also be of type integer and null; however, parameter $value of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

266
        if (count(/** @scrutinizer ignore-type */ $structures) > 0) {
Loading history...
267
            // Fine.
268
            $this->addFlashMessage(
269
                $this->getLanguageService()->getLL('flash.structureOkayMsg'),
270
                $this->getLanguageService()->getLL('flash.structureOkay'),
271
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
272
            );
273
        } else {
274
            // Configuration missing.
275
            $this->addFlashMessage(
276
                $this->getLanguageService()->getLL('flash.structureNotOkayMsg'),
277
                $this->getLanguageService()->getLL('flash.structureNotOkay'),
278
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
279
            );
280
            $this->view->assign('structure', 1);
281
        }
282
283
        $metadata = $this->metadataRepository->findByPid($this->pid);
0 ignored issues
show
Bug introduced by
The method findByPid() 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

283
        /** @scrutinizer ignore-call */ 
284
        $metadata = $this->metadataRepository->findByPid($this->pid);
Loading history...
284
285
        if (count($metadata) > 0) {
286
            // Fine.
287
            $this->addFlashMessage(
288
                $this->getLanguageService()->getLL('flash.metadataOkayMsg'),
289
                $this->getLanguageService()->getLL('flash.metadataOkay'),
290
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
291
            );
292
        } else {
293
            // Configuration missing.
294
            $this->addFlashMessage(
295
                $this->getLanguageService()->getLL('flash.metadataNotOkayMsg'),
296
                $this->getLanguageService()->getLL('flash.metadataNotOkay'),
297
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
298
            );
299
            $this->view->assign('metadata', 1);
300
        }
301
302
        $solrCore = $this->solrCoreRepository->findByPid($this->pid);
0 ignored issues
show
Bug introduced by
The method findByPid() 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

302
        /** @scrutinizer ignore-call */ 
303
        $solrCore = $this->solrCoreRepository->findByPid($this->pid);
Loading history...
303
        $solrCore2 = $this->solrCoreRepository->findByPid(0);
304
305
        if (count($solrCore) > 0 OR count($solrCore2) > 0) {
306
            if (count($solrCore) > 0) {
307
                // Fine.
308
                $this->addFlashMessage(
309
                    $this->getLanguageService()->getLL('flash.solrcoreOkayMsg'),
310
                    $this->getLanguageService()->getLL('flash.solrcoreOkay'),
311
                    \TYPO3\CMS\Core\Messaging\FlashMessage::OK
312
                );
313
            } else {
314
                // Default core available, but this is deprecated.
315
                $this->addFlashMessage(
316
                    $this->getLanguageService()->getLL('flash.solrcoreDeprecatedMsg'),
317
                    $this->getLanguageService()->getLL('flash.solrcoreDeprecatedOkay'),
318
                    \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE
319
                );
320
                $this->view->assign('solr', 1);
321
            }
322
        } else {
323
            // Solr core missing.
324
            $this->addFlashMessage(
325
                $this->getLanguageService()->getLL('flash.solrcoreMissingMsg'),
326
                $this->getLanguageService()->getLL('flash.solrcoreMissing'),
327
                \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
328
            );
329
            $this->view->assign('solr', 1);
330
        }
331
    }
332
}
333