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 ( af0744...7258dc )
by
unknown
05:55
created

UpdateSolrSchema::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
/**
4
 * (c) Kitodo. Key to digital objects e.V. <[email protected]>
5
 *
6
 * This file is part of the Kitodo and TYPO3 projects.
7
 *
8
 * @license GNU General Public License version 3 or later.
9
 * For the full copyright and license information, please read the
10
 * LICENSE.txt file that was distributed with this source code.
11
 */
12
13
namespace Kitodo\Dlf\Updates;
14
15
use Kitodo\Dlf\Common\Solr\Solr;
16
use Solarium\Core\Client\Request;
17
use TYPO3\CMS\Core\Database\ConnectionPool;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
use TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite;
20
use TYPO3\CMS\Install\Updates\UpgradeWizardInterface;
21
22
/**
23
 * Class UpdateSolrSchema
24
 *
25
 * @package TYPO3
26
 * @subpackage dlf
27
 *
28
 * @internal
29
 */
30
class UpdateSolrSchema implements UpgradeWizardInterface
31
{
32
33
    /**
34
     * Return the identifier for this wizard
35
     * This should be the same string as used in the ext_localconf class registration
36
     *
37
     * @access public
38
     *
39
     * @return string
40
     */
41
    public function getIdentifier(): string
42
    {
43
        return self::class;
44
    }
45
46
    /**
47
     * Return the speaking name of this wizard
48
     *
49
     * @access public
50
     *
51
     * @return string
52
     */
53
    public function getTitle(): string
54
    {
55
        return 'Update Solr schema';
56
    }
57
58
    /**
59
     * Return the description for this wizard
60
     *
61
     * @access public
62
     *
63
     * @return string
64
     */
65
    public function getDescription(): string
66
    {
67
        return 'This wizard updates the schema of all available Solr cores';
68
    }
69
70
    /**
71
     * Execute the update
72
     *
73
     * Called when a wizard reports that an update is necessary
74
     *
75
     * @access public
76
     *
77
     * @return bool
78
     */
79
    public function executeUpdate(): bool
80
    {
81
        $affectedSolrCores = $this->getAllAffectedSolrCores();
82
83
        foreach ($affectedSolrCores as $affectedSolrCore) {
84
85
            $solr = Solr::getInstance($affectedSolrCore['uid']);
86
            if (!$solr->ready) {
87
                continue;
88
            }
89
90
            $query = $solr->service->createApi(
91
                [
92
                    'version' => Request::API_V1,
93
                    'handler' => $affectedSolrCore['index_name'].'/schema',
94
                    'method' => Request::METHOD_POST,
95
                    'rawdata' => json_encode(
96
                        [
97
                            'replace-field' => [
98
                                'name' => 'autocomplete',
99
                                'type' => 'autocomplete',
100
                                'indexed' => true,
101
                                'stored' => true,
102
                                'multiValued' => true,
103
                            ],
104
                        ]
105
                    ),
106
                ]
107
            );
108
            $result = $solr->service->execute($query);
109
110
            if ($result->getResponse()->getStatusCode() == 400) {
111
                return false;
112
            }
113
        }
114
        return true;
115
    }
116
117
    /**
118
     * Is an update necessary?
119
     *
120
     * Looks for all affected Solr cores
121
     *
122
     * @access public
123
     *
124
     * @return bool
125
     */
126
    public function updateNecessary(): bool
127
    {
128
        if (count($this->getAllAffectedSolrCores())) {
129
            return true;
130
        }
131
        return false;
132
    }
133
134
    /**
135
     * Returns an array of class names of Prerequisite classes
136
     *
137
     * This way a wizard can define dependencies like "database up-to-date" or
138
     * "reference index updated"
139
     *
140
     * @access public
141
     *
142
     * @return string[]
143
     */
144
    public function getPrerequisites(): array
145
    {
146
        return [
147
            DatabaseUpdatedPrerequisite::class
148
        ];
149
    }
150
151
    /**
152
     * Returns all affected Solr cores
153
     *
154
     * @access private
155
     *
156
     * @return array
157
     */
158
    private function getAllAffectedSolrCores(): array
159
    {
160
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_dlf_solrcores');
161
162
        $allSolrCores = $queryBuilder->select('uid', 'index_name')
163
            ->from('tx_dlf_solrcores')
164
            ->execute()
165
            ->fetchAllAssociative();
166
167
        $affectedSolrCores = [];
168
169
        foreach ($allSolrCores as $solrCore) {
170
            $solr = Solr::getInstance($solrCore['uid']);
171
            if (!$solr->ready) {
172
                continue;
173
            }
174
175
            $query = $solr->service->createApi(
176
                [
177
                    'version' => Request::API_V1,
178
                    'handler' => $solrCore['index_name'].'/config/schemaFactory',
179
                    'method' => Request::METHOD_GET
180
                ]
181
            );
182
            $result = $solr->service->execute($query)->getData();
183
184
            if (!isset($result['config']['schemaFactory']['class']) || $result['config']['schemaFactory']['class'] != 'ManagedIndexSchemaFactory') {
185
                continue;
186
            }
187
188
            $query = $solr->service->createApi(
189
                [
190
                    'version' => Request::API_V1,
191
                    'handler' => $solrCore['index_name'].'/schema/fields/autocomplete',
192
                    'method' => Request::METHOD_GET
193
                ]
194
            );
195
            $result = $solr->service->execute($query)->getData();
196
197
            if (!isset($result['field']['stored']) || $result['field']['stored'] === true) {
198
                continue;
199
            }
200
201
            $affectedSolrCores[] = $solrCore;
202
        }
203
        return $affectedSolrCores;
204
    }
205
}
206