Passed
Pull Request — release-11.2.x (#3557)
by Markus
15:20 queued 12:06
created

QueueItemRepository   F

Complexity

Total Complexity 70

Size/Duplication

Total Lines 876
Duplicated Lines 0 %

Test Coverage

Coverage 95.2%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 70
eloc 312
c 1
b 0
f 0
dl 0
loc 876
ccs 317
cts 333
cp 0.952
rs 2.8

40 Methods

Rating   Name   Duplication   Size   Complexity  
A flushErrorByItem() 0 9 1
A flushErrorsBySite() 0 9 1
A getPreparedFlushErrorQuery() 0 7 1
A findLastIndexedRow() 0 13 1
A flushAllErrors() 0 5 1
A findErrorsBySite() 0 13 1
A __construct() 0 3 1
A containsItem() 0 3 1
A updateIndexTimeByItem() 0 8 1
A add() 0 21 1
A updateChangedTimeByItem() 0 8 1
A getLocalizableItemChangedTime() 0 21 2
A updateExistingItemByItemTypeAndItemUidAndRootPageId() 0 24 2
A getItemsByCompositeExpression() 0 13 3
A findAllIndexQueueItemsByRootPidAndMountIdentifierAndMountedPids() 0 14 1
A deleteItemsBySite() 0 4 2
A markItemAsFailed() 0 11 3
A containsItemWithRootPageId() 0 6 1
A findPageIdsOfExistingMountPagesByMountIdentifier() 0 22 3
A getPageItemChangedTimeByPageUid() 0 13 1
A countItems() 0 13 1
A deleteItemsByType() 0 3 1
A deleteItem() 0 4 2
A getIndexQueueItemObjectsFromRecords() 0 4 1
A findItemByUid() 0 16 2
A getQueryBuilderForContainsMethods() 0 7 1
A findAll() 0 8 1
A findItemsByItemTypeAndItemUid() 0 8 1
A initializeByNativeSQLStatement() 0 3 1
A deleteItems() 0 23 2
A hookPostProcessFetchRecordsForIndexQueueItem() 0 8 3
A addItemWhereClauses() 0 24 6
B buildQueryForPropertyDeletion() 0 30 7
A findItems() 0 11 1
A findItemsToIndex() 0 20 1
A updateHasIndexingPropertiesFlagByItemUid() 0 9 1
A deleteAllItems() 0 3 1
A getQueueItemObjectsByRecords() 0 24 3
A getAllQueueItemRecordsByUidsGroupedByTable() 0 30 4
A containsIndexedItem() 0 6 1

How to fix   Complexity   

Complex Class

Complex classes like QueueItemRepository often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use QueueItemRepository, and based on these observations, apply Extract Interface, too.

1
<?php declare(strict_types = 1);
2
namespace ApacheSolrForTypo3\Solr\Domain\Index\Queue;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2010-2017 dkd Internet Service GmbH <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 3 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use ApacheSolrForTypo3\Solr\IndexQueue\Item;
28
use ApacheSolrForTypo3\Solr\Domain\Site\Site;
29
use ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager;
30
use ApacheSolrForTypo3\Solr\System\Records\AbstractRepository;
31
use Doctrine\DBAL\DBALException;
32
use TYPO3\CMS\Core\Database\ConnectionPool;
33
use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression;
34
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
35
use TYPO3\CMS\Core\Utility\GeneralUtility;
36
37
/**
38
 * Class QueueItemRepository
39
 * Handles all CRUD operations to tx_solr_indexqueue_item table
40
 *
41
 */
42
class QueueItemRepository extends AbstractRepository
43
{
44
    /**
45
     * @var string
46
     */
47
    protected $table = 'tx_solr_indexqueue_item';
48
49
    /**
50
     * @var SolrLogManager
51
     */
52
    protected $logger;
53
54
    /**
55
     * QueueItemRepository constructor.
56
     *
57
     * @param SolrLogManager|null $logManager
58
     */
59 164
    public function __construct(SolrLogManager $logManager = null)
60
    {
61 164
        $this->logger = $logManager ?? GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
62 164
    }
63
64
    /**
65
     * Fetches the last indexed row
66
     *
67
     * @param int $rootPageId The root page uid for which to get the last indexed row
68
     * @return array
69
     */
70 5
    public function findLastIndexedRow(int $rootPageId) : array
71
    {
72 5
        $queryBuilder = $this->getQueryBuilder();
73
        $row = $queryBuilder
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...lity\Result::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

73
        $row = /** @scrutinizer ignore-deprecated */ $queryBuilder

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
74 5
            ->select('uid', 'indexed')
75 5
            ->from($this->table)
76 5
            ->where($queryBuilder->expr()->eq('root', $rootPageId))
77 5
            ->andWhere($queryBuilder->expr()->neq('indexed', 0))
78 5
            ->orderBy('indexed', 'DESC')
79 5
            ->setMaxResults(1)
80 5
            ->execute()->fetchAll();
81
82 5
        return $row;
83
    }
84
85
    /**
86
     * Finds indexing errors for the current site
87
     *
88
     * @param Site $site
89
     * @return array Error items for the current site's Index Queue
90
     */
91 3
    public function findErrorsBySite(Site $site) : array
92
    {
93 3
        $queryBuilder = $this->getQueryBuilder();
94
        $errors = $queryBuilder
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...lity\Result::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

94
        $errors = /** @scrutinizer ignore-deprecated */ $queryBuilder

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
95 3
            ->select('uid', 'item_type', 'item_uid', 'errors')
96 3
            ->from($this->table)
97 3
            ->andWhere(
98 3
                $queryBuilder->expr()->notLike('errors', $queryBuilder->createNamedParameter('')),
99 3
                $queryBuilder->expr()->eq('root', $site->getRootPageId())
100
            )
101 3
            ->execute()->fetchAll();
102
103 3
        return $errors;
104
    }
105
106
    /**
107
     * Resets all the errors for all index queue items.
108
     *
109
     * @return int affected rows
110
     */
111 1
    public function flushAllErrors() : int
112
    {
113 1
        $queryBuilder = $this->getQueryBuilder();
114 1
        $affectedRows = $this->getPreparedFlushErrorQuery($queryBuilder)->execute();
115 1
        return $affectedRows;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $affectedRows returns the type Doctrine\DBAL\ForwardCompatibility\Result which is incompatible with the type-hinted return integer.
Loading history...
116
    }
117
118
    /**
119
     * Flushes the errors for a single site.
120
     *
121
     * @param Site $site
122
     * @return int
123
     */
124 1
    public function flushErrorsBySite(Site $site) : int
125
    {
126 1
        $queryBuilder = $this->getQueryBuilder();
127 1
        $affectedRows = $this->getPreparedFlushErrorQuery($queryBuilder)
128 1
            ->andWhere(
129 1
                $queryBuilder->expr()->eq('root', (int)$site->getRootPageId())
130
            )
131 1
            ->execute();
132 1
        return $affectedRows;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $affectedRows returns the type Doctrine\DBAL\ForwardCompatibility\Result which is incompatible with the type-hinted return integer.
Loading history...
133
    }
134
135
    /**
136
     * Flushes the error for a single item.
137
     *
138
     * @param Item $item
139
     * @return int affected rows
140
     */
141 2
    public function flushErrorByItem(Item $item) : int
142
    {
143 2
        $queryBuilder = $this->getQueryBuilder();
144 2
        $affectedRows = $this->getPreparedFlushErrorQuery($queryBuilder)
145 2
            ->andWhere(
146 2
                $queryBuilder->expr()->eq('uid', $item->getIndexQueueUid())
147
            )
148 2
            ->execute();
149 2
        return $affectedRows;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $affectedRows returns the type Doctrine\DBAL\ForwardCompatibility\Result which is incompatible with the type-hinted return integer.
Loading history...
150
    }
151
152
    /**
153
     * Initializes the QueryBuilder with a query the resets the error field for items that have an error.
154
     *
155
     * @return QueryBuilder
156
     */
157 4
    private function getPreparedFlushErrorQuery(QueryBuilder $queryBuilder)
158
    {
159
        return $queryBuilder
160 4
            ->update($this->table)
161 4
            ->set('errors', '')
162 4
            ->where(
163 4
                $queryBuilder->expr()->notLike('errors', $queryBuilder->createNamedParameter(''))
164
            );
165
    }
166
167
    /**
168
     * Updates an existing queue entry by $itemType $itemUid and $rootPageId.
169
     *
170
     * @param string $itemType The item's type, usually a table name.
171
     * @param int $itemUid The item's uid, usually an integer uid, could be a
172
     *      different value for non-database-record types.
173
     * @param string $indexingConfiguration The name of the related indexConfiguration
174
     * @param int $rootPageId The uid of the rootPage
175
     * @param int $changedTime The forced change time that should be used for updating
176
     * @param int $indexingPriority
177
     * @return int affected rows
178
     */
179 17
    public function updateExistingItemByItemTypeAndItemUidAndRootPageId(
180
        string $itemType,
181
        int $itemUid,
182
        int $rootPageId,
183
        int $changedTime,
184
        string $indexingConfiguration = '',
185
        int $indexingPriority = 0
186
    ): int {
187 17
        $queryBuilder = $this->getQueryBuilder();
188
        $queryBuilder
189 17
            ->update($this->table)
190 17
            ->set('changed', $changedTime)
191 17
            ->set('indexing_priority', $indexingPriority)
192 17
            ->andWhere(
193 17
                $queryBuilder->expr()->eq('item_type', $queryBuilder->createNamedParameter($itemType)),
194 17
                $queryBuilder->expr()->eq('item_uid', $itemUid),
195 17
                $queryBuilder->expr()->eq('root', $rootPageId)
196
            );
197
198 17
        if (!empty($indexingConfiguration)) {
199 17
            $queryBuilder->set('indexing_configuration', $indexingConfiguration);
200
        }
201
202 17
        return $queryBuilder->execute();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $queryBuilder->execute() returns the type Doctrine\DBAL\ForwardCompatibility\Result which is incompatible with the type-hinted return integer.
Loading history...
203
    }
204
205
    /**
206
     * Adds an item to the index queue.
207
     *
208
     * Not meant for public use.
209
     *
210
     * @param string $itemType The item's type, usually a table name.
211
     * @param int $itemUid The item's uid, usually an integer uid, could be a different value for non-database-record types.
212
     * @param int $rootPageId
213
     * @param int $changedTime
214
     * @param string $indexingConfiguration The item's indexing configuration to use. Optional, overwrites existing / determined configuration.
215
     * @param int $indexingPriority
216
     * @return int the number of inserted rows, which is typically 1
217
     */
218 81
    public function add(
219
        string $itemType,
220
        int $itemUid,
221
        int $rootPageId,
222
        int $changedTime,
223
        string $indexingConfiguration,
224
        int $indexingPriority = 0
225
    ): int {
226 81
        $queryBuilder = $this->getQueryBuilder();
227
        return $queryBuilder
0 ignored issues
show
Bug Best Practice introduced by
The expression return $queryBuilder->in...ngPriority))->execute() returns the type Doctrine\DBAL\ForwardCompatibility\Result which is incompatible with the type-hinted return integer.
Loading history...
228 81
            ->insert($this->table)
229 81
            ->values([
230 81
                'root' => $rootPageId,
231 81
                'item_type' => $itemType,
232 81
                'item_uid' => $itemUid,
233 81
                'changed' => $changedTime,
234 81
                'errors' => '',
235 81
                'indexing_configuration' => $indexingConfiguration,
236 81
                'indexing_priority' => $indexingPriority,
237
            ])
238 81
            ->execute();
239
240
    }
241
242
    /**
243
     * Retrieves the count of items that match certain filters. Each filter is passed as parts of the where claus combined with AND.
244
     *
245
     * @param array $sites
246
     * @param array $indexQueueConfigurationNames
247
     * @param array $itemTypes
248
     * @param array $itemUids
249
     * @param array $uids
250
     * @return int
251
     */
252 1
    public function countItems(array $sites = [], array $indexQueueConfigurationNames = [], array $itemTypes = [], array $itemUids = [], array $uids = []): int
253
    {
254 1
        $rootPageIds = Site::getRootPageIdsFromSites($sites);
255 1
        $indexQueueConfigurationList = implode(",", $indexQueueConfigurationNames);
256 1
        $itemTypeList = implode(",", $itemTypes);
257 1
        $itemUids = array_map("intval", $itemUids);
258 1
        $uids = array_map("intval", $uids);
259
260 1
        $queryBuilderForCountingItems = $this->getQueryBuilder();
261 1
        $queryBuilderForCountingItems->count('uid')->from($this->table);
262 1
        $queryBuilderForCountingItems = $this->addItemWhereClauses($queryBuilderForCountingItems, $rootPageIds, $indexQueueConfigurationList, $itemTypeList, $itemUids, $uids);
263
264 1
        return (int)$queryBuilderForCountingItems->execute()->fetchColumn(0);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...y\Result::fetchColumn() has been deprecated: Use fetchOne() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

264
        return (int)/** @scrutinizer ignore-deprecated */ $queryBuilderForCountingItems->execute()->fetchColumn(0);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
265
    }
266
267
    /**
268
     * Gets the most recent changed time of a page's content elements
269
     *
270
     * @param int $pageUid
271
     * @return int|null Timestamp of the most recent content element change or null if nothing is found.
272
     */
273 57
    public function getPageItemChangedTimeByPageUid(int $pageUid)
274
    {
275 57
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
276 57
        $queryBuilder->getRestrictions()->removeAll();
277
        $pageContentLastChangedTime = $queryBuilder
278 57
            ->add('select', $queryBuilder->expr()->max('tstamp', 'changed_time'))
279 57
            ->from('tt_content')
280 57
            ->where(
281 57
                $queryBuilder->expr()->eq('pid', $pageUid)
282
            )
283 57
            ->execute()->fetch();
284
285 57
        return $pageContentLastChangedTime['changed_time'];
286
    }
287
288
    /**
289
     * Gets the most recent changed time for an item taking into account
290
     * localized records.
291
     *
292
     * @param string $itemType The item's type, usually a table name.
293
     * @param int $itemUid The item's uid
294
     * @return int Timestamp of the most recent content element change
295
     */
296 85
    public function getLocalizableItemChangedTime(string $itemType, int $itemUid) : int
297
    {
298 85
        $localizedChangedTime = 0;
299
300 85
        if (isset($GLOBALS['TCA'][$itemType]['ctrl']['transOrigPointerField'])) {
301
            // table is localizable
302 85
            $translationOriginalPointerField = $GLOBALS['TCA'][$itemType]['ctrl']['transOrigPointerField'];
303 85
            $timeStampField = $GLOBALS['TCA'][$itemType]['ctrl']['tstamp'];
304
305 85
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($itemType);
306 85
            $queryBuilder->getRestrictions()->removeAll();
307
            $localizedChangedTime = $queryBuilder
308 85
                ->add('select', $queryBuilder->expr()->max($timeStampField, 'changed_time'))
309 85
                ->from($itemType)
310 85
                ->orWhere(
311 85
                    $queryBuilder->expr()->eq('uid', $itemUid),
312 85
                    $queryBuilder->expr()->eq($translationOriginalPointerField, $itemUid)
313 85
                )->execute()->fetchColumn(0);
314
        }
315
316 85
        return (int)$localizedChangedTime;
317
    }
318
319
    /**
320
     * Returns prepared QueryBuilder for contains* methods in this repository
321
     *
322
     * @param string $itemType
323
     * @param int $itemUid
324
     * @return QueryBuilder
325
     */
326 92
    protected function getQueryBuilderForContainsMethods(string $itemType, int $itemUid) : QueryBuilder
327
    {
328 92
        $queryBuilder = $this->getQueryBuilder();
329 92
        return $queryBuilder->count('uid')->from($this->table)
330 92
            ->andWhere(
331 92
                $queryBuilder->expr()->eq('item_type', $queryBuilder->createNamedParameter($itemType)),
332 92
                $queryBuilder->expr()->eq('item_uid', $itemUid)
333
            );
334
    }
335
336
    /**
337
     * Checks whether the Index Queue contains a specific item.
338
     *
339
     * @param string $itemType The item's type, usually a table name.
340
     * @param int $itemUid The item's uid
341
     * @return bool TRUE if the item is found in the queue, FALSE otherwise
342
     */
343 10
    public function containsItem(string $itemType, int $itemUid) : bool
344
    {
345 10
        return (bool)$this->getQueryBuilderForContainsMethods($itemType, $itemUid)->execute()->fetchColumn(0);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...y\Result::fetchColumn() has been deprecated: Use fetchOne() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

345
        return (bool)/** @scrutinizer ignore-deprecated */ $this->getQueryBuilderForContainsMethods($itemType, $itemUid)->execute()->fetchColumn(0);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
346
    }
347
348
    /**
349
     * Checks whether the Index Queue contains a specific item.
350
     *
351
     * @param string $itemType The item's type, usually a table name.
352
     * @param int $itemUid The item's uid
353
     * @param integer $rootPageId
354
     * @return bool TRUE if the item is found in the queue, FALSE otherwise
355
     */
356 85
    public function containsItemWithRootPageId(string $itemType, int $itemUid, int $rootPageId) : bool
357
    {
358 85
        $queryBuilder = $this->getQueryBuilderForContainsMethods($itemType, $itemUid);
359
        return (bool)$queryBuilder
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...y\Result::fetchColumn() has been deprecated: Use fetchOne() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

359
        return (bool)/** @scrutinizer ignore-deprecated */ $queryBuilder

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
360 85
            ->andWhere($queryBuilder->expr()->eq('root', $rootPageId))
361 85
            ->execute()->fetchColumn(0);
362
    }
363
364
    /**
365
     * Checks whether the Index Queue contains a specific item that has been
366
     * marked as indexed.
367
     *
368
     * @param string $itemType The item's type, usually a table name.
369
     * @param int $itemUid The item's uid
370
     * @return bool TRUE if the item is found in the queue and marked as
371
     *      indexed, FALSE otherwise
372
     */
373 4
    public function containsIndexedItem(string $itemType, int $itemUid) : bool
374
    {
375 4
        $queryBuilder = $this->getQueryBuilderForContainsMethods($itemType, $itemUid);
376
        return (bool)$queryBuilder
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...y\Result::fetchColumn() has been deprecated: Use fetchOne() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

376
        return (bool)/** @scrutinizer ignore-deprecated */ $queryBuilder

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
377 4
            ->andWhere($queryBuilder->expr()->gt('indexed', 0))
378 4
            ->execute()->fetchColumn(0);
379
    }
380
381
    /**
382
     * Removes an item from the Index Queue.
383
     *
384
     * @param string $itemType The type of the item to remove, usually a table name.
385
     * @param int $itemUid The uid of the item to remove
386
     */
387 59
    public function deleteItem(string $itemType, int $itemUid = null)
388
    {
389 59
        $itemUids = empty($itemUid) ? [] : [$itemUid];
390 59
        $this->deleteItems([], [], [$itemType], $itemUids);
391 59
    }
392
393
    /**
394
     * Removes all items of a certain type from the Index Queue.
395
     *
396
     * @param string $itemType The type of items to remove, usually a table name.
397
     */
398 1
    public function deleteItemsByType(string $itemType)
399
    {
400 1
        $this->deleteItem($itemType);
401 1
    }
402
403
    /**
404
     * Removes all items of a certain site from the Index Queue. Accepts an
405
     * optional parameter to limit the deleted items by indexing configuration.
406
     *
407
     * @param Site $site The site to remove items for.
408
     * @param string $indexingConfigurationName Name of a specific indexing configuration
409
     * @throws \Exception
410
     */
411 7
    public function deleteItemsBySite(Site $site, string $indexingConfigurationName = '')
412
    {
413 7
        $indexingConfigurationNames = empty($indexingConfigurationName) ? [] : [$indexingConfigurationName];
414 7
        $this->deleteItems([$site], $indexingConfigurationNames);
415 7
    }
416
417
    /**
418
     * Removes items in the index queue filtered by the passed arguments.
419
     *
420
     * @param array $sites
421
     * @param array $indexQueueConfigurationNames
422
     * @param array $itemTypes
423
     * @param array $itemUids
424
     * @param array $uids
425
     * @throws \Exception
426
     */
427 66
    public function deleteItems(array $sites = [], array $indexQueueConfigurationNames = [], array $itemTypes = [], array $itemUids = [], array $uids = [])
428
    {
429 66
        $rootPageIds = Site::getRootPageIdsFromSites($sites);
430 66
        $indexQueueConfigurationList = implode(",", $indexQueueConfigurationNames);
431 66
        $itemTypeList = implode(",", $itemTypes);
432 66
        $itemUids = array_map("intval", $itemUids);
433 66
        $uids = array_map("intval", $uids);
434
435 66
        $queryBuilderForDeletingItems = $this->getQueryBuilder();
436 66
        $queryBuilderForDeletingItems->delete($this->table);
437 66
        $queryBuilderForDeletingItems = $this->addItemWhereClauses($queryBuilderForDeletingItems, $rootPageIds, $indexQueueConfigurationList, $itemTypeList, $itemUids, $uids);
438
439 66
        $queryBuilderForDeletingProperties = $this->buildQueryForPropertyDeletion($queryBuilderForDeletingItems, $rootPageIds, $indexQueueConfigurationList, $itemTypeList, $itemUids, $uids);
440
441 66
        $queryBuilderForDeletingItems->getConnection()->beginTransaction();
442
        try {
443 66
            $queryBuilderForDeletingItems->execute();
444 66
            $queryBuilderForDeletingProperties->execute();
445
446 66
            $queryBuilderForDeletingItems->getConnection()->commit();
447
        } catch (\Exception $e) {
448
            $queryBuilderForDeletingItems->getConnection()->rollback();
449
            throw $e;
450
        }
451 66
    }
452
453
    /**
454
     * Initializes the query builder to delete items in the index queue filtered by the passed arguments.
455
     *
456
     * @param array $rootPageIds filter on a set of rootPageUids.
457
     * @param string $indexQueueConfigurationList
458
     * @param string $itemTypeList
459
     * @param array $itemUids filter on a set of item uids
460
     * @param array $uids filter on a set of queue item uids
461
     * @return QueryBuilder
462
     */
463 68
    private function addItemWhereClauses(QueryBuilder $queryBuilderForDeletingItems, array $rootPageIds, string $indexQueueConfigurationList, string $itemTypeList, array $itemUids, array $uids): QueryBuilder
464
    {
465
466 68
        if (!empty($rootPageIds)) {
467 7
            $queryBuilderForDeletingItems->andWhere($queryBuilderForDeletingItems->expr()->in('root', $rootPageIds));
468
        };
469
470 68
        if (!empty($indexQueueConfigurationList)) {
471 9
            $queryBuilderForDeletingItems->andWhere($queryBuilderForDeletingItems->expr()->in('indexing_configuration', $queryBuilderForDeletingItems->createNamedParameter($indexQueueConfigurationList)));
472
        }
473
474 68
        if (!empty($itemTypeList)) {
475 59
            $queryBuilderForDeletingItems->andWhere($queryBuilderForDeletingItems->expr()->in('item_type', $queryBuilderForDeletingItems->createNamedParameter($itemTypeList)));
476
        }
477
478 68
        if (!empty($itemUids)) {
479 58
            $queryBuilderForDeletingItems->andWhere($queryBuilderForDeletingItems->expr()->in('item_uid', $itemUids));
480
        }
481
482 68
        if (!empty($uids)) {
483 1
            $queryBuilderForDeletingItems->andWhere($queryBuilderForDeletingItems->expr()->in('uid', $uids));
484
        }
485
486 68
        return $queryBuilderForDeletingItems;
487
    }
488
489
    /**
490
     * Initializes a query builder to delete the indexing properties of an item by the passed conditions.
491
     *
492
     * @param QueryBuilder $queryBuilderForDeletingItems
493
     * @param array $rootPageIds
494
     * @param string $indexQueueConfigurationList
495
     * @param string $itemTypeList
496
     * @param array $itemUids
497
     * @param array $uids
498
     * @return QueryBuilder
499
     */
500 66
    private function buildQueryForPropertyDeletion(QueryBuilder $queryBuilderForDeletingItems, array $rootPageIds, string $indexQueueConfigurationList, string $itemTypeList, array $itemUids, array $uids): QueryBuilder
501
    {
502 66
        $queryBuilderForSelectingProperties = $queryBuilderForDeletingItems->getConnection()->createQueryBuilder();
503 66
        $queryBuilderForSelectingProperties->select('items.uid')->from('tx_solr_indexqueue_indexing_property', 'properties')->innerJoin(
504 66
            'properties',
505 66
            $this->table,
506 66
            'items',
507 66
            (string)$queryBuilderForSelectingProperties->expr()->andX(
508 66
                $queryBuilderForSelectingProperties->expr()->eq('items.uid', $queryBuilderForSelectingProperties->quoteIdentifier('properties.item_id')),
509 66
                empty($rootPageIds) ? '' : $queryBuilderForSelectingProperties->expr()->in('items.root', $rootPageIds),
510 66
                empty($indexQueueConfigurationList) ? '' : $queryBuilderForSelectingProperties->expr()->in('items.indexing_configuration', $queryBuilderForSelectingProperties->createNamedParameter($indexQueueConfigurationList)),
511 66
                empty($itemTypeList) ? '' : $queryBuilderForSelectingProperties->expr()->in('items.item_type', $queryBuilderForSelectingProperties->createNamedParameter($itemTypeList)),
512 66
                empty($itemUids) ? '' : $queryBuilderForSelectingProperties->expr()->in('items.item_uid', $itemUids),
513 66
                empty($uids) ? '' : $queryBuilderForSelectingProperties->expr()->in('items.uid', $uids)
514
            )
515
        );
516 66
        $propertyEntriesToDelete = implode(',', array_column($queryBuilderForSelectingProperties->execute()->fetchAll(), 'uid'));
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...lity\Result::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

516
        $propertyEntriesToDelete = implode(',', array_column(/** @scrutinizer ignore-deprecated */ $queryBuilderForSelectingProperties->execute()->fetchAll(), 'uid'));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
517
518 66
        $queryBuilderForDeletingProperties = $queryBuilderForDeletingItems->getConnection()->createQueryBuilder();
519
520
        // make sure executing the propety deletion query doesn't fail if there are no properties to delete
521 66
        if (empty($propertyEntriesToDelete)) {
522 65
            $propertyEntriesToDelete = '0';
523
        }
524
525 66
        $queryBuilderForDeletingProperties->delete('tx_solr_indexqueue_indexing_property')->where(
526 66
            $queryBuilderForDeletingProperties->expr()->in('item_id', $propertyEntriesToDelete)
527
        );
528
529 66
        return $queryBuilderForDeletingProperties;
530
    }
531
532
    /**
533
     * Removes all items from the Index Queue.
534
     *
535
     * @return int The number of affected rows. For a truncate this is unreliable as theres no meaningful information.
536
     */
537 1
    public function deleteAllItems()
538
    {
539 1
        return $this->getQueryBuilder()->getConnection()->truncate($this->table);
540
    }
541
542
    /**
543
     * Gets a single Index Queue item by its uid.
544
     *
545
     * @param int $uid Index Queue item uid
546
     * @return Item|null The request Index Queue item or NULL if no item with $itemId was found
547
     */
548 36
    public function findItemByUid(int $uid)
549
    {
550 36
        $queryBuilder = $this->getQueryBuilder();
551
        $indexQueueItemRecord = $queryBuilder
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCompatibility\Result::fetch() has been deprecated: Use fetchNumeric(), fetchAssociative() or fetchOne() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

551
        $indexQueueItemRecord = /** @scrutinizer ignore-deprecated */ $queryBuilder

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
552 36
            ->select('*')
553 36
            ->from($this->table)
554 36
            ->where($queryBuilder->expr()->eq('uid', $uid))
555 36
            ->execute()->fetch();
556
557 36
        if (!isset($indexQueueItemRecord['uid'])) {
558 7
            return null;
559
        }
560
561
        /** @var Item $item*/
562 29
        $item = GeneralUtility::makeInstance(Item::class, /** @scrutinizer ignore-type */ $indexQueueItemRecord);
563 29
        return $item;
564
    }
565
566
    /**
567
     * Gets Index Queue items by type and uid.
568
     *
569
     * @param string $itemType item type, usually  the table name
570
     * @param int $itemUid item uid
571
     * @return Item[] An array of items matching $itemType and $itemUid
572
     */
573 51
    public function findItemsByItemTypeAndItemUid(string $itemType, int $itemUid) : array
574
    {
575 51
        $queryBuilder = $this->getQueryBuilder();
576 51
        $compositeExpression = $queryBuilder->expr()->andX(
577 51
            $queryBuilder->expr()->eq('item_type', $queryBuilder->getConnection()->quote($itemType, \PDO::PARAM_STR)),
578 51
            $queryBuilder->expr()->eq('item_uid', $itemUid)
579
        );
580 51
        return $this->getItemsByCompositeExpression($compositeExpression, $queryBuilder);
581
    }
582
583
    /**
584
     * Returns a collection of items by CompositeExpression.
585
     * D
586
     *
587
     * @param CompositeExpression|null $expression Optional expression to filter records.
588
     * @param QueryBuilder|null $queryBuilder QueryBuilder to use
589
     * @return array
590
     */
591 51
    protected function getItemsByCompositeExpression(CompositeExpression $expression = null, QueryBuilder $queryBuilder = null) : array
592
    {
593 51
        if (!$queryBuilder instanceof QueryBuilder) {
594
            $queryBuilder = $this->getQueryBuilder();
595
        }
596
597 51
        $queryBuilder->select('*')->from($this->table);
598 51
        if (isset($expression)) {
599 51
            $queryBuilder->where($expression);
600
        }
601
602 51
        $indexQueueItemRecords = $queryBuilder->execute()->fetchAll();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...lity\Result::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

602
        $indexQueueItemRecords = /** @scrutinizer ignore-deprecated */ $queryBuilder->execute()->fetchAll();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
603 51
        return $this->getIndexQueueItemObjectsFromRecords($indexQueueItemRecords);
604
    }
605
606
    /**
607
     * Returns all items in the queue.
608
     *
609
     * @return Item[] all Items from Queue without restrictions
610
     */
611 5
    public function findAll() : array
612
    {
613 5
        $queryBuilder = $this->getQueryBuilder();
614
        $allRecords = $queryBuilder
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...lity\Result::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

614
        $allRecords = /** @scrutinizer ignore-deprecated */ $queryBuilder

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
615 5
            ->select('*')
616 5
            ->from($this->table)
617 5
            ->execute()->fetchAll();
618 5
        return $this->getIndexQueueItemObjectsFromRecords($allRecords);
619
    }
620
621
    /**
622
     * Gets $limit number of items to index for a particular $site.
623
     *
624
     * @param Site $site TYPO3 site
625
     * @param int $limit Number of items to get from the queue
626
     * @return Item[] Items to index to the given solr server
627
     */
628 3
    public function findItemsToIndex(Site $site, int $limit = 50) : array
629
    {
630 3
        $queryBuilder = $this->getQueryBuilder();
631
        // determine which items to index with this run
632
        $indexQueueItemRecords = $queryBuilder
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...lity\Result::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

632
        $indexQueueItemRecords = /** @scrutinizer ignore-deprecated */ $queryBuilder

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
633 3
            ->select('*')
634 3
            ->from($this->table)
635 3
            ->andWhere(
636 3
                $queryBuilder->expr()->eq('root', $site->getRootPageId()),
637 3
                $queryBuilder->expr()->gt('changed', 'indexed'),
638 3
                $queryBuilder->expr()->lte('changed', time()),
639 3
                $queryBuilder->expr()->eq('errors', $queryBuilder->createNamedParameter(''))
640
            )
641 3
            ->orderBy('indexing_priority', 'DESC')
642 3
            ->addOrderBy('changed', 'DESC')
643 3
            ->addOrderBy('uid', 'DESC')
644 3
            ->setMaxResults($limit)
645 3
            ->execute()->fetchAll();
646
647 3
        return $this->getIndexQueueItemObjectsFromRecords($indexQueueItemRecords);
648
    }
649
650
    /**
651
     * Retrieves the count of items that match certain filters. Each filter is passed as parts of the where claus combined with AND.
652
     *
653
     * @param array $sites
654
     * @param array $indexQueueConfigurationNames
655
     * @param array $itemTypes
656
     * @param array $itemUids
657
     * @param array $uids
658
     * @param int $start
659
     * @param int $limit
660
     * @return array
661
     */
662 1
    public function findItems(array $sites = [], array $indexQueueConfigurationNames = [], array $itemTypes = [], array $itemUids = [], array $uids = [], $start = 0, $limit = 50): array
663
    {
664 1
        $rootPageIds = Site::getRootPageIdsFromSites($sites);
665 1
        $indexQueueConfigurationList = implode(",", $indexQueueConfigurationNames);
666 1
        $itemTypeList = implode(",", $itemTypes);
667 1
        $itemUids = array_map("intval", $itemUids);
668 1
        $uids = array_map("intval", $uids);
669 1
        $itemQueryBuilder = $this->getQueryBuilder()->select('*')->from($this->table);
670 1
        $itemQueryBuilder = $this->addItemWhereClauses($itemQueryBuilder, $rootPageIds, $indexQueueConfigurationList, $itemTypeList, $itemUids, $uids);
671 1
        $itemRecords = $itemQueryBuilder->setFirstResult($start)->setMaxResults($limit)->execute()->fetchAll();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...lity\Result::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

671
        $itemRecords = /** @scrutinizer ignore-deprecated */ $itemQueryBuilder->setFirstResult($start)->setMaxResults($limit)->execute()->fetchAll();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
672 1
        return $this->getIndexQueueItemObjectsFromRecords($itemRecords);
673
    }
674
675
    /**
676
     * Creates an array of ApacheSolrForTypo3\Solr\IndexQueue\Item objects from an array of
677
     * index queue records.
678
     *
679
     * @param array $indexQueueItemRecords Array of plain index queue records
680
     * @return array Array of ApacheSolrForTypo3\Solr\IndexQueue\Item objects
681
     */
682 54
    protected function getIndexQueueItemObjectsFromRecords(array $indexQueueItemRecords) : array
683
    {
684 54
        $tableRecords = $this->getAllQueueItemRecordsByUidsGroupedByTable($indexQueueItemRecords);
685 54
        return $this->getQueueItemObjectsByRecords($indexQueueItemRecords, $tableRecords);
686
    }
687
688
    /**
689
     * Returns the records for suitable item type.
690
     *
691
     * @param array $indexQueueItemRecords
692
     * @return array
693
     */
694 54
    protected function getAllQueueItemRecordsByUidsGroupedByTable(array $indexQueueItemRecords) : array
695
    {
696 54
        $tableUids = [];
697 54
        $tableRecords = [];
698
        // grouping records by table
699 54
        foreach ($indexQueueItemRecords as $indexQueueItemRecord) {
700 54
            $tableUids[$indexQueueItemRecord['item_type']][] = $indexQueueItemRecord['item_uid'];
701
        }
702
703
        // fetching records by table, saves us a lot of single queries
704 54
        foreach ($tableUids as $table => $uids) {
705 54
            $uidList = implode(',', $uids);
706
707 54
            $queryBuilderForRecordTable = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
708 54
            $queryBuilderForRecordTable->getRestrictions()->removeAll();
709
            $resultsFromRecordTable = $queryBuilderForRecordTable
710 54
                ->select('*')
711 54
                ->from($table)
712 54
                ->where($queryBuilderForRecordTable->expr()->in('uid', $uidList))
713 54
                ->execute();
714 54
            $records = [];
715 54
            while ($record = $resultsFromRecordTable->fetch()) {
716 52
                $records[$record['uid']] = $record;
717
            }
718
719 54
            $tableRecords[$table] = $records;
720 54
            $this->hookPostProcessFetchRecordsForIndexQueueItem($table, $uids, $tableRecords);
721
        }
722
723 54
        return $tableRecords;
724
    }
725
726
    /**
727
     * Calls defined in postProcessFetchRecordsForIndexQueueItem hook method.
728
     *
729
     * @param string $table
730
     * @param array $uids
731
     * @param array $tableRecords
732
     *
733
     * @return void
734
     */
735 54
    protected function hookPostProcessFetchRecordsForIndexQueueItem(string $table, array $uids, array &$tableRecords)
736
    {
737 54
        if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessFetchRecordsForIndexQueueItem'])) {
738 54
            return;
739
        }
740
        $params = ['table' => $table, 'uids' => $uids, 'tableRecords' => &$tableRecords];
741
        foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['solr']['postProcessFetchRecordsForIndexQueueItem'] as $reference) {
742
            GeneralUtility::callUserFunction($reference, $params, $this);
743
        }
744
    }
745
746
    /**
747
     * Instantiates a list of Item objects from database records.
748
     *
749
     * @param array $indexQueueItemRecords records from database
750
     * @param array $tableRecords
751
     * @return array
752
     */
753 54
    protected function getQueueItemObjectsByRecords(array $indexQueueItemRecords, array $tableRecords) : array
754
    {
755 54
        $indexQueueItems = [];
756 54
        foreach ($indexQueueItemRecords as $indexQueueItemRecord) {
757 54
            if (isset($tableRecords[$indexQueueItemRecord['item_type']][$indexQueueItemRecord['item_uid']])) {
758 52
                $indexQueueItems[] = GeneralUtility::makeInstance(
759
                    Item::class,
760 52
                    /** @scrutinizer ignore-type */ $indexQueueItemRecord,
761 52
                    /** @scrutinizer ignore-type */ $tableRecords[$indexQueueItemRecord['item_type']][$indexQueueItemRecord['item_uid']]
762
                );
763
            } else {
764 2
                $this->logger->log(
765 2
                    SolrLogManager::ERROR,
766 2
                    'Record missing for Index Queue item. Item removed.',
767
                    [
768 2
                        $indexQueueItemRecord
769
                    ]
770
                );
771 2
                $this->deleteItem($indexQueueItemRecord['item_type'],
772 2
                    $indexQueueItemRecord['item_uid']);
773
            }
774
        }
775
776 54
        return $indexQueueItems;
777
    }
778
779
    /**
780
     * Marks an item as failed and causes the indexer to skip the item in the
781
     * next run.
782
     *
783
     * @param int|Item $item Either the item's Index Queue uid or the complete item
784
     * @param string $errorMessage Error message
785
     * @return int affected rows
786
     */
787 6
    public function markItemAsFailed($item, string $errorMessage = ''): int
788
    {
789 6
        $itemUid = ($item instanceof Item) ? $item->getIndexQueueUid() : (int)$item;
790 6
        $errorMessage = empty($errorMessage) ? '1' : $errorMessage;
791
792 6
        $queryBuilder = $this->getQueryBuilder();
793
        return (int)$queryBuilder
794 6
            ->update($this->table)
795 6
            ->set('errors', $errorMessage)
796 6
            ->where($queryBuilder->expr()->eq('uid', $itemUid))
797 6
            ->execute();
798
    }
799
800
    /**
801
     * Sets the timestamp of when an item last has been indexed.
802
     *
803
     * @param Item $item
804
     * @return int affected rows
805
     */
806 2
    public function updateIndexTimeByItem(Item $item) : int
807
    {
808 2
        $queryBuilder = $this->getQueryBuilder();
809
        return (int)$queryBuilder
810 2
            ->update($this->table)
811 2
            ->set('indexed', time())
812 2
            ->where($queryBuilder->expr()->eq('uid', $item->getIndexQueueUid()))
813 2
            ->execute();
814
    }
815
816
    /**
817
     * Sets the change timestamp of an item.
818
     *
819
     * @param Item $item
820
     * @param int $changedTime
821
     * @return int affected rows
822
     */
823
    public function updateChangedTimeByItem(Item $item, int $changedTime) : int
824
    {
825
        $queryBuilder = $this->getQueryBuilder();
826
        return (int)$queryBuilder
827
            ->update($this->table)
828
            ->set('changed', $changedTime)
829
            ->where($queryBuilder->expr()->eq('uid', $item->getIndexQueueUid()))
830
            ->execute();
831
    }
832
833
    /**
834
     * Initializes Queue by given sql
835
     *
836
     * Note: Do not use platform specific functions!
837
     *
838
     * @param string $sqlStatement Native SQL statement
839
     * @return int The number of affected rows.
840
     * @internal
841
     * @throws DBALException
842
     */
843 14
    public function initializeByNativeSQLStatement(string $sqlStatement) : int
844
    {
845 14
        return $this->getQueryBuilder()->getConnection()->exec($sqlStatement);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getQueryBu...()->exec($sqlStatement) could return the type string which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
Deprecated Code introduced by
The function Doctrine\DBAL\Connection::exec() has been deprecated: Use {@link executeStatement()} instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

845
        return /** @scrutinizer ignore-deprecated */ $this->getQueryBuilder()->getConnection()->exec($sqlStatement);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
846
    }
847
848
    /**
849
     * Retrieves an array of pageIds from mountPoints that allready have a queue entry.
850
     *
851
     * @param string $identifier identifier of the mount point
852
     * @return array pageIds from mountPoints that allready have a queue entry
853
     */
854 8
    public function findPageIdsOfExistingMountPagesByMountIdentifier(string $identifier) : array
855
    {
856 8
        $queryBuilder = $this->getQueryBuilder();
857
        $resultSet = $queryBuilder
858 8
            ->select('item_uid')
859 8
            ->add('select', $queryBuilder->expr()->count('*', 'queueItemCount'), true)
860 8
            ->from($this->table)
861 8
            ->where(
862 8
                $queryBuilder->expr()->eq('item_type', $queryBuilder->createNamedParameter('pages')),
863 8
                $queryBuilder->expr()->eq('pages_mountidentifier', $queryBuilder->createNamedParameter($identifier))
864
            )
865 8
            ->groupBy('item_uid')
866 8
            ->execute();
867
868 8
        $mountedPagesIdsWithQueueItems = [];
869 8
        while ($record = $resultSet->fetch()) {
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCompatibility\Result::fetch() has been deprecated: Use fetchNumeric(), fetchAssociative() or fetchOne() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

869
        while ($record = /** @scrutinizer ignore-deprecated */ $resultSet->fetch()) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
870
            if ($record['queueItemCount'] > 0) {
871
                $mountedPagesIdsWithQueueItems[] = $record['item_uid'];
872
            }
873
        }
874
875 8
        return $mountedPagesIdsWithQueueItems;
876
    }
877
878
    /**
879
     * Retrieves an array of items for mount destinations mathed by root page ID, Mount Identifier and a list of mounted page IDs.
880
     *
881
     * @param int $rootPid
882
     * @param string $identifier identifier of the mount point
883
     * @param array $mountedPids An array of mounted page IDs
884
     * @return array
885
     */
886 8
    public function findAllIndexQueueItemsByRootPidAndMountIdentifierAndMountedPids(int $rootPid, string $identifier, array $mountedPids) : array
887
    {
888 8
        $queryBuilder = $this->getQueryBuilder();
889
        return $queryBuilder
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\ForwardCom...lity\Result::fetchAll() has been deprecated: Use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

889
        return /** @scrutinizer ignore-deprecated */ $queryBuilder

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
890 8
            ->select('*')
891 8
            ->from($this->table)
892 8
            ->where(
893 8
                $queryBuilder->expr()->eq('root', $queryBuilder->createNamedParameter($rootPid, \PDO::PARAM_INT)),
894 8
                $queryBuilder->expr()->eq('item_type', $queryBuilder->createNamedParameter('pages')),
895 8
                $queryBuilder->expr()->in('item_uid', $mountedPids),
896 8
                $queryBuilder->expr()->eq('has_indexing_properties', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)),
897 8
                $queryBuilder->expr()->eq('pages_mountidentifier', $queryBuilder->createNamedParameter($identifier))
898
            )
899 8
            ->execute()->fetchAll();
900
    }
901
902
    /**
903
     * Updates has_indexing_properties field for given Item
904
     *
905
     * @param int $itemUid
906
     * @param bool $hasIndexingPropertiesFlag
907
     * @return int number of affected rows, 1 on success
908
     */
909 10
    public function updateHasIndexingPropertiesFlagByItemUid(int $itemUid, bool $hasIndexingPropertiesFlag): int
910
    {
911 10
        $queryBuilder = $this->getQueryBuilder();
912
913
        return $queryBuilder
0 ignored issues
show
Bug Best Practice introduced by
The expression return $queryBuilder->up...INT), false)->execute() returns the type Doctrine\DBAL\ForwardCompatibility\Result which is incompatible with the type-hinted return integer.
Loading history...
914 10
            ->update($this->table)
915 10
            ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($itemUid, \PDO::PARAM_INT)))
916 10
            ->set('has_indexing_properties', $queryBuilder->createNamedParameter($hasIndexingPropertiesFlag, \PDO::PARAM_INT), false)
917 10
            ->execute();
918
    }
919
}
920