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 (#737)
by Alexander
02:59
created

CollectionRepository::getIndexNameForSolr()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 20
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 28
rs 9.6
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\Domain\Repository;
14
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
use TYPO3\CMS\Core\Database\ConnectionPool;
17
use Kitodo\Dlf\Common\Helper;
18
19
class CollectionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
20
{
21
22
    public function getCollectionList(array $uids, $showUserDefined = 0)
23
    {
24
        $query = $this->createQuery();
25
26
        if (!empty($uids)) {
27
            $constraints = [];
28
            // selected collections
29
            foreach ($uids as $uid) {
30
                $constraints[] = $query->contains('uid', $uid);
31
            }
32
            $query->matching($query->logicalOr($constraints));
33
        }
34
35
        $query->matching($query->equals('fe_cruser_id', $showUserDefined));
36
37
        $query->setOrderings([
38
            'label' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
39
        ]);
40
41
    }
42
43
    public function getCollections($settings, $uid, $sysLangUid) {
44
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
45
            ->getQueryBuilderForTable('tx_dlf_collections');
46
47
        $selectedCollections = $queryBuilder->expr()->neq('tx_dlf_collections.uid', 0);
48
        $orderBy = 'tx_dlf_collections.label';
49
        $showUserDefinedColls = '';
50
        // Handle collections set by configuration.
51
        if ($settings['collections']) {
52
            if (
53
                count(explode(',', $settings['collections'])) == 1
54
                && empty($settings['dont_show_single'])
55
            ) {
56
                $this->showSingleCollection(intval(trim($settings['collections'], ' ,')));
0 ignored issues
show
Bug introduced by
The method showSingleCollection() does not exist on Kitodo\Dlf\Domain\Repository\CollectionRepository. 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

56
                $this->/** @scrutinizer ignore-call */ 
57
                       showSingleCollection(intval(trim($settings['collections'], ' ,')));
Loading history...
57
            }
58
            $selectedCollections = $queryBuilder->expr()->in('tx_dlf_collections.uid', implode(',', GeneralUtility::intExplode(',', $settings['collections'])));
59
        }
60
61
        // Should user-defined collections be shown?
62
        if (empty($settings['show_userdefined'])) {
63
            $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0);
64
        } elseif ($settings['show_userdefined'] > 0) {
65
            if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
66
                $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', intval($uid));
67
            } else {
68
                $showUserDefinedColls = $queryBuilder->expr()->neq('tx_dlf_collections.fe_cruser_id', 0);
69
            }
70
        }
71
72
        // Get collections.
73
        $queryBuilder
74
            ->select(
75
                'tx_dlf_collections.uid AS uid', // required by getRecordOverlay()
76
                'tx_dlf_collections.pid AS pid', // required by getRecordOverlay()
77
                'tx_dlf_collections.sys_language_uid AS sys_language_uid', // required by getRecordOverlay()
78
                'tx_dlf_collections.index_name AS index_name',
79
                'tx_dlf_collections.index_search as index_query',
80
                'tx_dlf_collections.label AS label',
81
                'tx_dlf_collections.thumbnail AS thumbnail',
82
                'tx_dlf_collections.description AS description',
83
                'tx_dlf_collections.priority AS priority'
84
            )
85
            ->from('tx_dlf_collections')
86
            ->where(
87
                $selectedCollections,
88
                $showUserDefinedColls,
89
                $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])),
90
                $queryBuilder->expr()->andX(
91
                    $queryBuilder->expr()->orX(
92
                        $queryBuilder->expr()->in('tx_dlf_collections.sys_language_uid', [-1, 0]),
93
                        $queryBuilder->expr()->eq('tx_dlf_collections.sys_language_uid', $sysLangUid)
94
                    ),
95
                    $queryBuilder->expr()->eq('tx_dlf_collections.l18n_parent', 0)
96
                )
97
            )
98
            ->orderBy($orderBy);
99
100
        $result = $queryBuilder->execute();
101
        $count = $queryBuilder->count('uid')->execute()->fetchColumn(0);
102
103
        return ['result' => $result, 'count' => $count];
104
    }
105
106
    public function getSingleCollection($settings, $id, $sysLangUid) {
107
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
108
        $queryBuilder = $connectionPool->getQueryBuilderForTable('tx_dlf_collections');
109
110
        $additionalWhere = '';
111
        // Should user-defined collections be shown?
112
        if (empty($settings['show_userdefined'])) {
113
            $additionalWhere = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0);
114
        } elseif ($settings['show_userdefined'] > 0) {
115
            $additionalWhere = $queryBuilder->expr()->neq('tx_dlf_collections.fe_cruser_id', 0);
116
        }
117
118
        // Get collection information from DB
119
        $collection = $queryBuilder
120
            ->select(
121
                'tx_dlf_collections.uid AS uid', // required by getRecordOverlay()
122
                'tx_dlf_collections.pid AS pid', // required by getRecordOverlay()
123
                'tx_dlf_collections.sys_language_uid AS sys_language_uid', // required by getRecordOverlay()
124
                'tx_dlf_collections.index_name AS index_name',
125
                'tx_dlf_collections.index_search as index_search',
126
                'tx_dlf_collections.label AS label',
127
                'tx_dlf_collections.description AS description',
128
                'tx_dlf_collections.thumbnail AS thumbnail',
129
                'tx_dlf_collections.fe_cruser_id'
130
            )
131
            ->from('tx_dlf_collections')
132
            ->where(
133
                $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])),
134
                $queryBuilder->expr()->eq('tx_dlf_collections.uid', intval($id)),
135
                $additionalWhere,
136
                $queryBuilder->expr()->andX(
137
                    $queryBuilder->expr()->orX(
138
                        $queryBuilder->expr()->in('tx_dlf_collections.sys_language_uid', [-1, 0]),
139
                        $queryBuilder->expr()->eq('tx_dlf_collections.sys_language_uid', $sysLangUid)
140
                    ),
141
                    $queryBuilder->expr()->eq('tx_dlf_collections.l18n_parent', 0)
142
                ),
143
                Helper::whereExpression('tx_dlf_collections')
144
            )
145
            ->setMaxResults(1)
146
            ->execute();
147
148
        return $collection;
149
    }
150
151
    public function getCollectionForMetadata($pages) {
152
        // Get list of collections to show.
153
        $query = $this->createQuery();
154
155
        $query->matching($query->equals('pid', $pages));
156
157
        return $query->execute();
158
    }
159
160
    public function getFacetCollections($facetCollections) {
161
        $query = $this->createQuery();
162
163
        $query->matching($query->in('uid', GeneralUtility::intExplode(',', $facetCollections)));
164
165
        return $query->execute();
166
    }
167
168
    public function getOai1($settings) {
169
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
170
            ->getQueryBuilderForTable('tx_dlf_collections');
171
172
        $where = '';
173
        if (!$settings['show_userdefined']) {
174
            $where = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0);
175
        }
176
177
        $result = $queryBuilder
178
            ->select(
179
                'tx_dlf_collections.oai_name AS oai_name',
180
                'tx_dlf_collections.label AS label'
181
            )
182
            ->from('tx_dlf_collections')
183
            ->where(
184
                $queryBuilder->expr()->in('tx_dlf_collections.sys_language_uid', [-1, 0]),
185
                $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])),
186
                $queryBuilder->expr()->neq('tx_dlf_collections.oai_name', $queryBuilder->createNamedParameter('')),
187
                $where,
188
                Helper::whereExpression('tx_dlf_collections')
189
            )
190
            ->orderBy('tx_dlf_collections.oai_name')
191
            ->execute();
192
193
        $allResults = $result->fetchAll();
194
195
        return $allResults;
196
    }
197
198
    public function getIndexNameForSolr($settings, $set) {
199
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
200
            ->getQueryBuilderForTable('tx_dlf_collections');
201
202
        $where = '';
203
        if (!$settings['show_userdefined']) {
204
            $where = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0);
205
        }
206
        // For SOLR we need the index_name of the collection,
207
        // For DB Query we need the UID of the collection
208
        $result = $queryBuilder
209
            ->select(
210
                'tx_dlf_collections.index_name AS index_name',
211
                'tx_dlf_collections.uid AS uid',
212
                'tx_dlf_collections.index_search as index_query'
213
            )
214
            ->from('tx_dlf_collections')
215
            ->where(
216
                $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])),
217
                $queryBuilder->expr()->eq('tx_dlf_collections.oai_name',
218
                    $queryBuilder->expr()->literal($set)),
219
                $where,
220
                Helper::whereExpression('tx_dlf_collections')
221
            )
222
            ->setMaxResults(1)
223
            ->execute();
224
225
        return $result;
226
    }
227
228
}