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 ( ac3719...d0e528 )
by Sebastian
04:12 queued 11s
created

ConfigurationForm::checkSolrConnection()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 37
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 37
rs 8.5866
c 0
b 0
f 0
cc 7
nc 6
nop 2
1
<?php
2
namespace Kitodo\Dlf\Hooks;
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
use Kitodo\Dlf\Common\Solr;
16
use TYPO3\CMS\Core\Database\ConnectionPool;
17
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20
/**
21
 * Hooks and helper for \TYPO3\CMS\Core\TypoScript\ConfigurationForm
22
 *
23
 * @author Sebastian Meyer <[email protected]>
24
 * @package TYPO3
25
 * @subpackage dlf
26
 * @access public
27
 */
28
class ConfigurationForm {
29
    /**
30
     * This holds the current configuration
31
     *
32
     * @var array
33
     * @access protected
34
     */
35
    protected $conf = [];
36
37
    /**
38
     * Check if a connection to a Solr server could be established with the given credentials.
39
     *
40
     * @access public
41
     *
42
     * @param array &$params: An array with parameters
43
     * @param \TYPO3\CMS\Core\TypoScript\ConfigurationForm &$pObj: The parent object
44
     *
45
     * @return string Message informing the user of success or failure
46
     */
47
    public function checkSolrConnection(&$params, &$pObj) {
2 ignored issues
show
Unused Code introduced by
The parameter $pObj is not used and could be removed. ( Ignorable by Annotation )

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

47
    public function checkSolrConnection(&$params, /** @scrutinizer ignore-unused */ &$pObj) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

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

47
    public function checkSolrConnection(/** @scrutinizer ignore-unused */ &$params, &$pObj) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
        $solrInfo = Solr::getSolrConnectionInfo();
49
        // Prepend username and password to hostname.
50
        if (!empty($solrInfo['username'])
51
            && !empty($solrInfo['password'])) {
52
            $host = $solrInfo['username'].':'.$solrInfo['password'].'@'.$solrInfo['host'];
53
        } else {
54
            $host = $solrInfo['host'];
55
        }
56
        // Build request URI.
57
        $url = $solrInfo['scheme'].'://'.$host.':'.$solrInfo['port'].'/'.$solrInfo['path'].'/admin/cores?wt=xml';
58
        $context = stream_context_create([
59
            'http' => [
60
                'method' => 'GET',
61
                'user_agent' => (!empty($this->conf['useragent']) ? $this->conf['useragent'] : ini_get('user_agent'))
62
            ]
63
        ]);
64
        // Try to connect to Solr server.
65
        $response = @simplexml_load_string(file_get_contents($url, FALSE, $context));
66
        // Check status code.
67
        if ($response) {
68
            $status = $response->xpath('//lst[@name="responseHeader"]/int[@name="status"]');
69
            if (is_array($status)) {
1 ignored issue
show
introduced by
The condition is_array($status) is always true.
Loading history...
70
                Helper::addMessage(
71
                    sprintf($GLOBALS['LANG']->getLL('solr.status'), (string) $status[0]),
72
                    $GLOBALS['LANG']->getLL('solr.connected'),
73
                    ($status[0] == 0 ? \TYPO3\CMS\Core\Messaging\FlashMessage::OK : \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING)
1 ignored issue
show
introduced by
The condition $status[0] == 0 is always false.
Loading history...
74
                );
75
                return Helper::renderFlashMessages();
76
            }
77
        }
78
        Helper::addMessage(
79
            sprintf($GLOBALS['LANG']->getLL('solr.error'), $url),
80
            $GLOBALS['LANG']->getLL('solr.notConnected'),
81
            \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING
82
        );
83
        return Helper::renderFlashMessages();
84
    }
85
86
    /**
87
     * Make sure the essential namespaces are defined.
88
     *
89
     * @access public
90
     *
91
     * @param array &$params: An array with parameters
92
     * @param \TYPO3\CMS\Core\TypoScript\ConfigurationForm &$pObj: The parent object
93
     *
94
     * @return string Message informing the user of success or failure
95
     */
96
    public function checkMetadataFormats(&$params, &$pObj) {
2 ignored issues
show
Unused Code introduced by
The parameter $params is not used and could be removed. ( Ignorable by Annotation )

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

96
    public function checkMetadataFormats(/** @scrutinizer ignore-unused */ &$params, &$pObj) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $pObj is not used and could be removed. ( Ignorable by Annotation )

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

96
    public function checkMetadataFormats(&$params, /** @scrutinizer ignore-unused */ &$pObj) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
        $nsDefined = [
98
            'MODS' => FALSE,
99
            'TEIHDR' => FALSE,
100
            'ALTO' => FALSE,
101
            'IIIF1' => FALSE,
102
            'IIIF2' => FALSE,
103
            'IIIF3' => FALSE
104
        ];
105
106
        /** @var QueryBuilder $queryBuilder */
107
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
108
            ->getQueryBuilderForTable('tx_dlf_collections');
109
110
        // Check existing format specifications.
111
        $result = $queryBuilder
112
            ->select('tx_dlf_formats.type AS type')
113
            ->from('tx_dlf_formats')
114
            ->where(
115
                '1=1',
116
                Helper::whereExpression('tx_dlf_formats')
117
            )
118
            ->execute();
119
120
        while ($resArray = $result->fetch()) {
121
            $nsDefined[$resArray['type']] = TRUE;
122
        }
123
        // Build data array.
124
        $data = [];
125
        // Add MODS namespace.
126
        if (!$nsDefined['MODS']) {
127
            $data['tx_dlf_formats'][uniqid('NEW')] = [
128
                'pid' => 0,
129
                'type' => 'MODS',
130
                'root' => 'mods',
131
                'namespace' => 'http://www.loc.gov/mods/v3',
132
                'class' => 'Kitodo\\\\Dlf\\\\Format\\\\Mods'
133
            ];
134
        }
135
        // Add TEIHDR namespace.
136
        if (!$nsDefined['TEIHDR']) {
137
            $data['tx_dlf_formats'][uniqid('NEW')] = [
138
                'pid' => 0,
139
                'type' => 'TEIHDR',
140
                'root' => 'teiHeader',
141
                'namespace' => 'http://www.tei-c.org/ns/1.0',
142
                'class' => 'Kitodo\\\\Dlf\\\\Format\\\\TeiHeader'
143
            ];
144
        }
145
        // Add ALTO namespace.
146
        if (!$nsDefined['ALTO']) {
147
            $data['tx_dlf_formats'][uniqid('NEW')] = [
148
                'pid' => 0,
149
                'type' => 'ALTO',
150
                'root' => 'alto',
151
                'namespace' => 'http://www.loc.gov/standards/alto/ns-v2#',
152
                'class' => 'Kitodo\\\\Dlf\\\\Format\\\\Alto'
153
            ];
154
        }
155
        // Add IIIF Metadata API 1 context
156
        if (!$nsDefined['IIIF1']) {
157
            $data['tx_dlf_formats'][uniqid('NEW')] = array (
158
                'pid' => 0,
159
                'type' => 'IIIF1',
160
                'root' => 'IIIF1',
161
                'namespace' => 'http://www.shared-canvas.org/ns/context.json',
162
                'class' => ''
163
            );
164
        }
165
        // Add IIIF Presentation 2 context
166
        if (!$nsDefined['IIIF2']) {
167
            $data['tx_dlf_formats'][uniqid('NEW')] = array (
168
                'pid' => 0,
169
                'type' => 'IIIF2',
170
                'root' => 'IIIF2',
171
                'namespace' => 'http://iiif.io/api/presentation/2/context.json',
172
                'class' => ''
173
            );
174
        }
175
        // Add IIIF Presentation 3 context
176
        if (!$nsDefined['IIIF3']) {
177
            $data['tx_dlf_formats'][uniqid('NEW')] = array (
178
                'pid' => 0,
179
                'type' => 'IIIF3',
180
                'root' => 'IIIF3',
181
                'namespace' => 'http://iiif.io/api/presentation/3/context.json',
182
                'class' => ''
183
            );
184
        }
185
        if (!empty($data)) {
186
            // Process changes.
187
            $substUid = Helper::processDBasAdmin($data);
188
            if (!empty($substUid)) {
189
                Helper::addMessage(
190
                    $GLOBALS['LANG']->getLL('metadataFormats.nsCreatedMsg'),
191
                    $GLOBALS['LANG']->getLL('metadataFormats.nsCreated'),
192
                    \TYPO3\CMS\Core\Messaging\FlashMessage::INFO
193
                );
194
            } else {
195
                Helper::addMessage(
196
                    $GLOBALS['LANG']->getLL('metadataFormats.nsNotCreatedMsg'),
197
                    $GLOBALS['LANG']->getLL('metadataFormats.nsNotCreated'),
198
                    \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
199
                );
200
            }
201
        } else {
202
            Helper::addMessage(
203
                $GLOBALS['LANG']->getLL('metadataFormats.nsOkayMsg'),
204
                $GLOBALS['LANG']->getLL('metadataFormats.nsOkay'),
205
                \TYPO3\CMS\Core\Messaging\FlashMessage::OK
206
            );
207
        }
208
        return Helper::renderFlashMessages();
209
    }
210
211
    /**
212
     * This is the constructor.
213
     *
214
     * @access public
215
     *
216
     * @return void
217
     */
218
    public function __construct() {
219
        // Load localization file.
220
        $GLOBALS['LANG']->includeLLFile('EXT:dlf/Resources/Private/Language/FlashMessages.xml');
221
        // Get current configuration.
222
        $this->conf = array_merge((array) unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dlf']), (array) \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('data'));
223
    }
224
}
225