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

CollectionRepository::getCollectionList()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 17
rs 9.9666
cc 3
nc 2
nop 2
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 Kitodo\Dlf\Common\Helper;
16
use TYPO3\CMS\Core\Database\ConnectionPool;
17
use TYPO3\CMS\Core\Utility\GeneralUtility;
18
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
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' => 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
    /**
156
     * Finds all collection for the given settings
157
     *
158
     * @param array $settings
159
     *
160
     * @return array|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface
161
     */
162
    public function findCollectionsBySettings($settings = [])
163
    {
164
        $query = $this->createQuery();
165
166
        $constraints = [];
167
168
        if ($settings['collections']) {
169
            $constraints[] = $query->in('uid', GeneralUtility::intExplode(',', $settings['collections']));
170
        }
171
172
        // do not find user created collections (used by oai-pmh plugin)
173
        if (!$settings['show_userdefined']) {
174
            $constraints[] = $query->equals('fe_cruser_id', 0);
175
        }
176
177
        // do not find collections without oai_name set (used by oai-pmh plugin)
178
        if ($settings['hideEmptyOaiNames']) {
179
            $constraints[] =  $query->logicalNot($query->equals('oai_name', ''));
180
        }
181
182
        if (count($constraints)) {
183
            $query->matching(
184
                $query->logicalAnd($constraints)
185
            );
186
        }
187
188
        // order by oai_name
189
        $query->setOrderings(
190
            array('oai_name' => QueryInterface::ORDER_ASCENDING)
191
        );
192
193
        return $query->execute();
194
    }
195
196
    public function getIndexNameForSolr($settings, $set) {
197
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
198
            ->getQueryBuilderForTable('tx_dlf_collections');
199
200
        $where = '';
201
        if (!$settings['show_userdefined']) {
202
            $where = $queryBuilder->expr()->eq('tx_dlf_collections.fe_cruser_id', 0);
203
        }
204
        // For SOLR we need the index_name of the collection,
205
        // For DB Query we need the UID of the collection
206
        $result = $queryBuilder
207
            ->select(
208
                'tx_dlf_collections.index_name AS index_name',
209
                'tx_dlf_collections.uid AS uid',
210
                'tx_dlf_collections.index_search as index_query'
211
            )
212
            ->from('tx_dlf_collections')
213
            ->where(
214
                $queryBuilder->expr()->eq('tx_dlf_collections.pid', intval($settings['pages'])),
215
                $queryBuilder->expr()->eq('tx_dlf_collections.oai_name',
216
                    $queryBuilder->expr()->literal($set)),
217
                $where,
218
                Helper::whereExpression('tx_dlf_collections')
219
            )
220
            ->setMaxResults(1)
221
            ->execute();
222
223
        return $result;
224
    }
225
226
}
227