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:53
created

CollectionRepository   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 212
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 121
c 2
b 0
f 0
dl 0
loc 212
rs 10
wmc 20

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndexNameForSolr() 0 28 2
A getCollectionForMetadata() 0 7 1
A getSingleCollection() 0 43 3
A findCollectionsBySettings() 0 32 5
A getFacetCollections() 0 6 1
B getCollections() 0 55 5
A getCollectionList() 0 17 3
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\Database\ConnectionPool;
16
use TYPO3\CMS\Core\Utility\GeneralUtility;
17
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
18
use Kitodo\Dlf\Common\Helper;
19
20
class CollectionRepository extends \TYPO3\CMS\Extbase\Persistence\Repository
21
{
22
23
    public function getCollectionList(array $uids, $showUserDefined = 0)
24
    {
25
        $query = $this->createQuery();
26
27
        if (!empty($uids)) {
28
            $constraints = [];
29
            // selected collections
30
            foreach ($uids as $uid) {
31
                $constraints[] = $query->contains('uid', $uid);
32
            }
33
            $query->matching($query->logicalOr($constraints));
34
        }
35
36
        $query->matching($query->equals('fe_cruser_id', $showUserDefined));
37
38
        $query->setOrderings([
39
            'label' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
40
        ]);
41
42
    }
43
44
    public function getCollections($settings, $uid, $sysLangUid) {
45
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
46
            ->getQueryBuilderForTable('tx_dlf_collections');
47
48
        $selectedCollections = $queryBuilder->expr()->neq('tx_dlf_collections.uid', 0);
49
        $orderBy = 'tx_dlf_collections.label';
50
        $showUserDefinedColls = '';
51
        // Handle collections set by configuration.
52
        if ($settings['collections']) {
53
            $selectedCollections = $queryBuilder->expr()->in('tx_dlf_collections.uid', implode(',', GeneralUtility::intExplode(',', $settings['collections'])));
54
        }
55
56
        // Should user-defined collections be shown?
57
        if (empty($settings['show_userdefined'])) {
58
            $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0);
59
        } elseif ($settings['show_userdefined'] > 0) {
60
            if (!empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
61
                $showUserDefinedColls = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', intval($uid));
62
            } else {
63
                $showUserDefinedColls = $queryBuilder->expr()->neq('tx_dlf_collections.fe_cruser_id', 0);
64
            }
65
        }
66
67
        // Get collections.
68
        $queryBuilder
69
            ->select(
70
                'tx_dlf_collections.uid AS uid', // required by getRecordOverlay()
71
                'tx_dlf_collections.pid AS pid', // required by getRecordOverlay()
72
                'tx_dlf_collections.sys_language_uid AS sys_language_uid', // required by getRecordOverlay()
73
                'tx_dlf_collections.index_name AS index_name',
74
                'tx_dlf_collections.index_search as index_query',
75
                'tx_dlf_collections.label AS label',
76
                'tx_dlf_collections.thumbnail AS thumbnail',
77
                'tx_dlf_collections.description AS description',
78
                'tx_dlf_collections.priority AS priority'
79
            )
80
            ->from('tx_dlf_collections')
81
            ->where(
82
                $selectedCollections,
83
                $showUserDefinedColls,
84
                $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])),
85
                $queryBuilder->expr()->andX(
86
                    $queryBuilder->expr()->orX(
87
                        $queryBuilder->expr()->in('tx_dlf_collections.sys_language_uid', [-1, 0]),
88
                        $queryBuilder->expr()->eq('tx_dlf_collections.sys_language_uid', $sysLangUid)
89
                    ),
90
                    $queryBuilder->expr()->eq('tx_dlf_collections.l18n_parent', 0)
91
                )
92
            )
93
            ->orderBy($orderBy);
94
95
        $result = $queryBuilder->execute();
96
        $count = $queryBuilder->count('uid')->execute()->fetchColumn(0);
97
98
        return ['result' => $result, 'count' => $count];
99
    }
100
101
    public function getSingleCollection($settings, $id, $sysLangUid) {
102
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
103
        $queryBuilder = $connectionPool->getQueryBuilderForTable('tx_dlf_collections');
104
105
        $additionalWhere = '';
106
        // Should user-defined collections be shown?
107
        if (empty($settings['show_userdefined'])) {
108
            $additionalWhere = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0);
109
        } elseif ($settings['show_userdefined'] > 0) {
110
            $additionalWhere = $queryBuilder->expr()->neq('tx_dlf_collections.fe_cruser_id', 0);
111
        }
112
113
        // Get collection information from DB
114
        $collection = $queryBuilder
115
            ->select(
116
                'tx_dlf_collections.uid AS uid', // required by getRecordOverlay()
117
                'tx_dlf_collections.pid AS pid', // required by getRecordOverlay()
118
                'tx_dlf_collections.sys_language_uid AS sys_language_uid', // required by getRecordOverlay()
119
                'tx_dlf_collections.index_name AS index_name',
120
                'tx_dlf_collections.index_search as index_search',
121
                'tx_dlf_collections.label AS label',
122
                'tx_dlf_collections.description AS description',
123
                'tx_dlf_collections.thumbnail AS thumbnail',
124
                'tx_dlf_collections.fe_cruser_id'
125
            )
126
            ->from('tx_dlf_collections')
127
            ->where(
128
                $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])),
129
                $queryBuilder->expr()->eq('tx_dlf_collections.uid', intval($id)),
130
                $additionalWhere,
131
                $queryBuilder->expr()->andX(
132
                    $queryBuilder->expr()->orX(
133
                        $queryBuilder->expr()->in('tx_dlf_collections.sys_language_uid', [-1, 0]),
134
                        $queryBuilder->expr()->eq('tx_dlf_collections.sys_language_uid', $sysLangUid)
135
                    ),
136
                    $queryBuilder->expr()->eq('tx_dlf_collections.l18n_parent', 0)
137
                ),
138
                Helper::whereExpression('tx_dlf_collections')
139
            )
140
            ->setMaxResults(1)
141
            ->execute();
142
143
        return $collection;
144
    }
145
146
    public function getCollectionForMetadata($pages) {
147
        // Get list of collections to show.
148
        $query = $this->createQuery();
149
150
        $query->matching($query->equals('pid', $pages));
151
152
        return $query->execute();
153
    }
154
155
    public function getFacetCollections($facetCollections) {
156
        $query = $this->createQuery();
157
158
        $query->matching($query->in('uid', GeneralUtility::intExplode(',', $facetCollections)));
159
160
        return $query->execute();
161
    }
162
163
    /**
164
     * Finds all collection for the given settings
165
     *
166
     * @param array $settings
167
     *
168
     * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
169
     */
170
    public function findCollectionsBySettings($settings = [])
171
    {
172
        $query = $this->createQuery();
173
174
        $constraints = [];
175
176
        if ($settings['collections']) {
177
            $constraints[] = $query->in('uid', GeneralUtility::intExplode(',', $settings['collections']));
178
        }
179
180
        // do not find user created collections (used by oai-pmh plugin)
181
        if (!$settings['show_userdefined']) {
182
            $constraints[] = $query->equals('fe_cruser_id', 0);
183
        }
184
185
        // do not find collections without oai_name set (used by oai-pmh plugin)
186
        if ($settings['hideEmptyOaiNames']) {
187
            $constraints[] =  $query->logicalNot($query->equals('oai_name', ''));
188
        }
189
190
        if (count($constraints)) {
191
            $query->matching(
192
                $query->logicalAnd($constraints)
193
            );
194
        }
195
196
        // order by oai_name
197
        $query->setOrderings(
198
            array('oai_name' => QueryInterface::ORDER_ASCENDING)
199
        );
200
201
        return $query->execute();
202
    }
203
204
    public function getIndexNameForSolr($settings, $set) {
205
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
206
            ->getQueryBuilderForTable('tx_dlf_collections');
207
208
        $where = '';
209
        if (!$settings['show_userdefined']) {
210
            $where = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0);
211
        }
212
        // For SOLR we need the index_name of the collection,
213
        // For DB Query we need the UID of the collection
214
        $result = $queryBuilder
215
            ->select(
216
                'tx_dlf_collections.index_name AS index_name',
217
                'tx_dlf_collections.uid AS uid',
218
                'tx_dlf_collections.index_search as index_query'
219
            )
220
            ->from('tx_dlf_collections')
221
            ->where(
222
                $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])),
223
                $queryBuilder->expr()->eq('tx_dlf_collections.oai_name',
224
                    $queryBuilder->expr()->literal($set)),
225
                $where,
226
                Helper::whereExpression('tx_dlf_collections')
227
            )
228
            ->setMaxResults(1)
229
            ->execute();
230
231
        return $result;
232
    }
233
234
}
235