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
Push — master ( f60880...61b949 )
by Sebastian
02:52
created

NewTenant::cmdAddMetadata()   A

Complexity

Conditions 5
Paths 10

Size

Total Lines 46
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 46
rs 9.0328
c 0
b 0
f 0
cc 5
nc 10
nop 0
1
<?php
2
namespace Kitodo\Dlf\Module;
3
4
/**
5
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
6
 *
7
 * This file is part of the Kitodo and TYPO3 projects.
8
 *
9
 * @license GNU General Public License version 3 or later.
10
 * For the full copyright and license information, please read the
11
 * LICENSE.txt file that was distributed with this source code.
12
 */
13
14
use Kitodo\Dlf\Common\Helper;
15
16
/**
17
 * Module 'New Tenant' for the 'dlf' extension.
18
 *
19
 * @author Sebastian Meyer <[email protected]>
20
 * @package TYPO3
21
 * @subpackage dlf
22
 * @access public
23
 */
24
class NewTenant extends \Kitodo\Dlf\Common\AbstractModule {
25
    protected $markerArray = [
26
        'CSH' => '',
27
        'MOD_MENU' => '',
28
        'CONTENT' => '',
29
    ];
30
31
    /**
32
     * Add access rights
33
     *
34
     * @access protected
35
     *
36
     * @return void
37
     */
38
    protected function cmdAddAccessRights() {
39
        // Get command line indexer's usergroup.
40
        $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
41
            'uid,db_mountpoints',
42
            'be_groups',
43
            'title='.$GLOBALS['TYPO3_DB']->fullQuoteStr('_cli_dlf', 'be_groups')
44
                .' AND '.$GLOBALS['TCA']['be_groups']['ctrl']['enablecolumns']['disabled'].'=0'
45
                .\TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('be_groups')
46
        );
47
        if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
48
            $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
49
            // Add current page to mountpoints.
50
            if (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($resArray['db_mountpoints'], $this->id)) {
51
                $data['be_groups'][$resArray['uid']]['db_mountpoints'] = $resArray['db_mountpoints'].','.$this->id;
1 ignored issue
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
52
                Helper::processDBasAdmin($data);
53
                // Fine.
54
                Helper::addMessage(
55
                    Helper::getMessage('flash.usergroupAddedMsg'),
56
                    Helper::getMessage('flash.usergroupAdded', TRUE),
57
                    \TYPO3\CMS\Core\Messaging\FlashMessage::OK
58
                );
59
            }
60
        }
61
    }
62
63
    /**
64
     * Add metadata configuration
65
     *
66
     * @access protected
67
     *
68
     * @return void
69
     */
70
    protected function cmdAddMetadata() {
71
        // Include metadata definition file.
72
        include_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->extKey).'Resources/Private/Data/MetadataDefaults.php');
73
        $i = 0;
74
        // Build data array.
75
        foreach ($metadataDefaults as $index_name => $values) {
1 ignored issue
show
Comprehensibility Best Practice introduced by
The variable $metadataDefaults seems to be never defined.
Loading history...
76
            $formatIds = [];
77
            foreach ($values['format'] as $format) {
78
                $formatIds[] = uniqid('NEW');
79
                $data['tx_dlf_metadataformat'][end($formatIds)] = $format;
80
                $data['tx_dlf_metadataformat'][end($formatIds)]['pid'] = intval($this->id);
81
                $i++;
82
            }
83
            $data['tx_dlf_metadata'][uniqid('NEW')] = [
84
                'pid' => intval($this->id),
85
                'label' => $GLOBALS['LANG']->getLL($index_name),
86
                'index_name' => $index_name,
87
                'format' => implode(',', $formatIds),
88
                'default_value' => $values['default_value'],
89
                'wrap' => (!empty($values['wrap']) ? $values['wrap'] : $GLOBALS['TCA']['tx_dlf_metadata']['columns']['wrap']['config']['default']),
90
                'index_tokenized' => $values['index_tokenized'],
91
                'index_stored' => $values['index_stored'],
92
                'index_indexed' => $values['index_indexed'],
93
                'index_boost' => $values['index_boost'],
94
                'is_sortable' => $values['is_sortable'],
95
                'is_facet' => $values['is_facet'],
96
                'is_listed' => $values['is_listed'],
97
                'index_autocomplete' => $values['index_autocomplete'],
98
            ];
99
            $i++;
100
        }
101
        $_ids = Helper::processDBasAdmin($data);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $data seems to be defined by a foreach iteration on line 75. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
102
        // Check for failed inserts.
103
        if (count($_ids) == $i) {
104
            // Fine.
105
            Helper::addMessage(
106
                Helper::getMessage('flash.metadataAddedMsg'),
107
                Helper::getMessage('flash.metadataAdded', TRUE),
108
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
109
            );
110
        } else {
111
            // Something went wrong.
112
            Helper::addMessage(
113
                Helper::getMessage('flash.metadataNotAddedMsg'),
114
                Helper::getMessage('flash.metadataNotAdded', TRUE),
115
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
116
            );
117
        }
118
    }
119
120
    /**
121
     * Add Solr core
122
     *
123
     * @access protected
124
     *
125
     * @return void
126
     */
127
    protected function cmdAddSolrCore() {
128
        // Build data array.
129
        $data['tx_dlf_solrcores'][uniqid('NEW')] = [
1 ignored issue
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
130
            'pid' => intval($this->id),
131
            'label' => $GLOBALS['LANG']->getLL('solrcore').' (PID '.$this->id.')',
132
            'index_name' => '',
133
        ];
134
        $_ids = Helper::processDBasAdmin($data);
135
        // Check for failed inserts.
136
        if (count($_ids) == 1) {
137
            // Fine.
138
            Helper::addMessage(
139
                Helper::getMessage('flash.solrcoreAddedMsg'),
140
                Helper::getMessage('flash.solrcoreAdded', TRUE),
141
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
142
            );
143
        } else {
144
            // Something went wrong.
145
            Helper::addMessage(
146
                Helper::getMessage('flash.solrcoreNotAddedMsg'),
147
                Helper::getMessage('flash.solrcoreNotAdded', TRUE),
148
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
149
            );
150
        }
151
    }
152
153
    /**
154
     * Add structure configuration
155
     *
156
     * @access protected
157
     *
158
     * @return void
159
     */
160
    protected function cmdAddStructure() {
161
        // Include structure definition file.
162
        include_once(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($this->extKey).'Resources/Private/Data/StructureDefaults.php');
163
        // Build data array.
164
        foreach ($structureDefaults as $index_name => $values) {
1 ignored issue
show
Comprehensibility Best Practice introduced by
The variable $structureDefaults seems to be never defined.
Loading history...
165
            $data['tx_dlf_structures'][uniqid('NEW')] = [
166
                'pid' => intval($this->id),
167
                'toplevel' => $values['toplevel'],
168
                'label' => $GLOBALS['LANG']->getLL($index_name),
169
                'index_name' => $index_name,
170
                'oai_name' => $values['oai_name'],
171
                'thumbnail' => 0,
172
            ];
173
        }
174
        $_ids = Helper::processDBasAdmin($data);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $data seems to be defined by a foreach iteration on line 164. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
175
        // Check for failed inserts.
176
        if (count($_ids) == count($structures)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $structures seems to be never defined.
Loading history...
177
            // Fine.
178
            Helper::addMessage(
179
                Helper::getMessage('flash.structureAddedMsg'),
180
                Helper::getMessage('flash.structureAdded', TRUE),
181
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
182
            );
183
        } else {
184
            // Something went wrong.
185
            Helper::addMessage(
186
                Helper::getMessage('flash.structureNotAddedMsg'),
187
                Helper::getMessage('flash.structureNotAdded', TRUE),
188
                \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
189
            );
190
        }
191
    }
192
193
    /**
194
     * Main function of the module
195
     *
196
     * @access public
197
     *
198
     * @param \Psr\Http\Message\ServerRequestInterface $request: The request object
199
     * @param \Psr\Http\Message\ResponseInterface $response: The response object
200
     *
201
     * @return void
202
     */
203
    public function main(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response) {
204
        $this->response = $response;
205
        // Is the user allowed to access this page?
206
        $access = is_array($this->pageInfo) && $GLOBALS['BE_USER']->isAdmin();
207
        if ($this->id && $access) {
208
            // Check if page is sysfolder.
209
            if ($this->pageInfo['doktype'] != 254) {
210
                Helper::addMessage(
211
                    Helper::getMessage('flash.wrongPageTypeMsg'),
212
                    Helper::getMessage('flash.wrongPageType', TRUE),
213
                    \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
214
                );
215
                $this->markerArray['CONTENT'] .= Helper::renderFlashMessages();
216
                $this->printContent();
217
                return;
218
            }
219
            // Should we do something?
220
            if (!empty($this->CMD)) {
221
                // Sanitize input...
222
                $_method = 'cmd'.ucfirst($this->CMD);
223
                // ...and unset to prevent infinite looping.
224
                unset ($this->CMD);
225
                if (method_exists($this, $_method)) {
226
                    $this->$_method();
227
                }
228
            }
229
            // Check for existing structure configuration.
230
            $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
231
                'uid',
232
                'tx_dlf_structures',
233
                'pid='.intval($this->id).$GLOBALS['LANG']->whereClause('tx_dlf_structures')
234
            );
235
            if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
236
                // Fine.
237
                Helper::addMessage(
238
                    Helper::getMessage('flash.structureOkayMsg'),
239
                    Helper::getMessage('flash.structureOkay', TRUE),
240
                    \TYPO3\CMS\Core\Messaging\FlashMessage::OK
241
                );
242
            } else {
243
                // Configuration missing.
244
                $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addStructure']));
245
                Helper::addMessage(
246
                    sprintf(Helper::getMessage('flash.structureNotOkayMsg'), $_url),
247
                    Helper::getMessage('flash.structureNotOkay', TRUE),
248
                    \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
249
                );
250
            }
251
            // Check for existing metadata configuration.
252
            $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
253
                'uid',
254
                'tx_dlf_metadata',
255
                'pid='.intval($this->id)
256
                    .Helper::whereClause('tx_dlf_metadata')
257
            );
258
            if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
259
                // Fine.
260
                Helper::addMessage(
261
                    Helper::getMessage('flash.metadataOkayMsg'),
262
                    Helper::getMessage('flash.metadataOkay', TRUE),
263
                    \TYPO3\CMS\Core\Messaging\FlashMessage::OK
264
                );
265
            } else {
266
                // Configuration missing.
267
                $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addMetadata']));
268
                Helper::addMessage(
269
                    sprintf(Helper::getMessage('flash.metadataNotOkayMsg'), $_url),
270
                    Helper::getMessage('flash.metadataNotOkay', TRUE),
271
                    \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
272
                );
273
            }
274
            // Check the access conditions for the command line indexer's user.
275
            $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
276
                'uid,db_mountpoints',
277
                'be_groups',
278
                'title='.$GLOBALS['TYPO3_DB']->fullQuoteStr('_cli_dlf', 'be_groups')
279
                    .' AND '.$GLOBALS['TCA']['be_groups']['ctrl']['enablecolumns']['disabled'].'=0'
280
                    .\TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause('be_groups')
281
            );
282
            if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
283
                $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
284
                if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($resArray['db_mountpoints'], $this->id)) {
285
                    // Fine.
286
                    Helper::addMessage(
287
                        Helper::getMessage('flash.usergroupOkayMsg'),
288
                        Helper::getMessage('flash.usergroupOkay', TRUE),
289
                        \TYPO3\CMS\Core\Messaging\FlashMessage::OK
290
                    );
291
                } else {
292
                    // Configuration missing.
293
                    $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addAccessRights']));
294
                    Helper::addMessage(
295
                        sprintf(Helper::getMessage('flash.usergroupNotOkayMsg'), $_url),
296
                        Helper::getMessage('flash.usergroupNotOkay', TRUE),
297
                        \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
298
                    );
299
                }
300
            } else {
301
                // Usergoup missing.
302
                Helper::addMessage(
303
                    Helper::getMessage('flash.usergroupMissingMsg'),
304
                    Helper::getMessage('flash.usergroupMissing', TRUE),
305
                    \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
306
                );
307
            }
308
            // Check for existing Solr core.
309
            $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
310
                'uid,pid',
311
                'tx_dlf_solrcores',
312
                'pid IN ('.intval($this->id).',0)'
313
                    .Helper::whereClause('tx_dlf_solrcores')
314
            );
315
            if ($GLOBALS['TYPO3_DB']->sql_num_rows($result)) {
316
                $resArray = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
317
                if ($resArray['pid']) {
318
                    // Fine.
319
                    Helper::addMessage(
320
                        Helper::getMessage('flash.solrcoreOkayMsg'),
321
                        Helper::getMessage('flash.solrcoreOkay', TRUE),
322
                        \TYPO3\CMS\Core\Messaging\FlashMessage::OK
323
                    );
324
                } else {
325
                    // Default core available, but this is deprecated.
326
                    $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addSolrcore']));
327
                    Helper::addMessage(
328
                        sprintf(Helper::getMessage('flash.solrcoreDeprecatedMsg'), $_url),
329
                        Helper::getMessage('flash.solrcoreDeprecatedOkay', TRUE),
330
                        \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE
331
                    );
332
                }
333
            } else {
334
                // Solr core missing.
335
                $_url = \TYPO3\CMS\Core\Utility\GeneralUtility::locationHeaderUrl(\TYPO3\CMS\Core\Utility\GeneralUtility::linkThisScript(['id' => $this->id, 'CMD' => 'addSolrcore']));
336
                Helper::addMessage(
337
                    sprintf(Helper::getMessage('flash.solrcoreMissingMsg'), $_url),
338
                    Helper::getMessage('flash.solrcoreMissing', TRUE),
339
                    \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
340
                );
341
            }
342
            $this->markerArray['CONTENT'] .= Helper::renderFlashMessages();
343
        } else {
344
            // TODO: Ändern!
345
            $this->markerArray['CONTENT'] .= 'You are not allowed to access this page or have not selected a page, yet.';
346
        }
347
        $this->printContent();
348
    }
349
}
350