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
unknown
02:50
created

CollectionRepository   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 201
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 127
c 1
b 0
f 0
dl 0
loc 201
rs 10
wmc 17

7 Methods

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