Passed
Push — release-11.0.x ( 181948...809732 )
by Rafael
28:42 queued 25:26
created

buildQueryForPropertyDeletion()   B

Complexity

Conditions 7
Paths 2

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 7.392

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 30
ccs 20
cts 25
cp 0.8
rs 8.8333
cc 7
nc 2
nop 6
crap 7.392
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 121
    public function __construct(SolrLogManager $logManager = null)
60
    {
61 121
        $this->logger = $logManager ?? GeneralUtility::makeInstance(SolrLogManager::class, /** @scrutinizer ignore-type */ __CLASS__);
62 121
    }
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
     * @return int affected rows
177
     */
178 11
    public function updateExistingItemByItemTypeAndItemUidAndRootPageId(string $itemType, int $itemUid, int $rootPageId, int $changedTime, string $indexingConfiguration = '') : int
179
    {
180 11
        $queryBuilder = $this->getQueryBuilder();
181
        $queryBuilder
182 11
            ->update($this->table)
183 11
            ->set('changed', $changedTime)
184 11
            ->andWhere(
185 11
                $queryBuilder->expr()->eq('item_type', $queryBuilder->createNamedParameter($itemType)),
186 11
                $queryBuilder->expr()->eq('item_uid', $itemUid),
187 11
                $queryBuilder->expr()->eq('root', $rootPageId)
188
            );
189
190 11
        if (!empty($indexingConfiguration)) {
191 11
            $queryBuilder->set('indexing_configuration', $indexingConfiguration);
192
        }
193
194 11
        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...
195
    }
196
197
    /**
198
     * Adds an item to the index queue.
199
     *
200
     * Not meant for public use.
201
     *
202
     * @param string $itemType The item's type, usually a table name.
203
     * @param int $itemUid The item's uid, usually an integer uid, could be a different value for non-database-record types.
204
     * @param int $rootPageId
205
     * @param int $changedTime
206
     * @param string $indexingConfiguration The item's indexing configuration to use. Optional, overwrites existing / determined configuration.
207
     * @return int the number of inserted rows, which is typically 1
208
     */
209 54
    public function add(string $itemType, int $itemUid, int $rootPageId, int $changedTime, string $indexingConfiguration) : int
210
    {
211 54
        $queryBuilder = $this->getQueryBuilder();
212
        return $queryBuilder
0 ignored issues
show
Bug Best Practice introduced by
The expression return $queryBuilder->in...figuration))->execute() returns the type Doctrine\DBAL\ForwardCompatibility\Result which is incompatible with the type-hinted return integer.
Loading history...
213 54
            ->insert($this->table)
214 54
            ->values([
215 54
                'root' => $rootPageId,
216 54
                'item_type' => $itemType,
217 54
                'item_uid' => $itemUid,
218 54
                'changed' => $changedTime,
219 54
                'errors' => '',
220 54
                'indexing_configuration' => $indexingConfiguration
221
            ])
222 54
            ->execute();
223
224
    }
225
226
    /**
227
     * Retrieves the count of items that match certain filters. Each filter is passed as parts of the where claus combined with AND.
228
     *
229
     * @param array $sites
230
     * @param array $indexQueueConfigurationNames
231
     * @param array $itemTypes
232
     * @param array $itemUids
233
     * @param array $uids
234
     * @return int
235
     */
236 1
    public function countItems(array $sites = [], array $indexQueueConfigurationNames = [], array $itemTypes = [], array $itemUids = [], array $uids = []): int
237
    {
238 1
        $rootPageIds = Site::getRootPageIdsFromSites($sites);
239 1
        $indexQueueConfigurationList = implode(",", $indexQueueConfigurationNames);
240 1
        $itemTypeList = implode(",", $itemTypes);
241 1
        $itemUids = array_map("intval", $itemUids);
242 1
        $uids = array_map("intval", $uids);
243
244 1
        $queryBuilderForCountingItems = $this->getQueryBuilder();
245 1
        $queryBuilderForCountingItems->count('uid')->from($this->table);
246 1
        $queryBuilderForCountingItems = $this->addItemWhereClauses($queryBuilderForCountingItems, $rootPageIds, $indexQueueConfigurationList, $itemTypeList, $itemUids, $uids);
247
248 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

248
        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...
249
    }
250
251
    /**
252
     * Gets the most recent changed time of a page's content elements
253
     *
254
     * @param int $pageUid
255
     * @return int|null Timestamp of the most recent content element change or null if nothing is found.
256
     */
257 38
    public function getPageItemChangedTimeByPageUid(int $pageUid)
258
    {
259 38
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
260 38
        $queryBuilder->getRestrictions()->removeAll();
261
        $pageContentLastChangedTime = $queryBuilder
262 38
            ->add('select', $queryBuilder->expr()->max('tstamp', 'changed_time'))
263 38
            ->from('tt_content')
264 38
            ->where(
265 38
                $queryBuilder->expr()->eq('pid', $pageUid)
266
            )
267 38
            ->execute()->fetch();
268
269 38
        return $pageContentLastChangedTime['changed_time'];
270
    }
271
272
    /**
273
     * Gets the most recent changed time for an item taking into account
274
     * localized records.
275
     *
276
     * @param string $itemType The item's type, usually a table name.
277
     * @param int $itemUid The item's uid
278
     * @return int Timestamp of the most recent content element change
279
     */
280 59
    public function getLocalizableItemChangedTime(string $itemType, int $itemUid) : int
281
    {
282 59
        $localizedChangedTime = 0;
283
284 59
        if (isset($GLOBALS['TCA'][$itemType]['ctrl']['transOrigPointerField'])) {
285
            // table is localizable
286 59
            $translationOriginalPointerField = $GLOBALS['TCA'][$itemType]['ctrl']['transOrigPointerField'];
287 59
            $timeStampField = $GLOBALS['TCA'][$itemType]['ctrl']['tstamp'];
288
289 59
            $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($itemType);
290 59
            $queryBuilder->getRestrictions()->removeAll();
291
            $localizedChangedTime = $queryBuilder
292 59
                ->add('select', $queryBuilder->expr()->max($timeStampField, 'changed_time'))
293 59
                ->from($itemType)
294 59
                ->orWhere(
295 59
                    $queryBuilder->expr()->eq('uid', $itemUid),
296 59
                    $queryBuilder->expr()->eq($translationOriginalPointerField, $itemUid)
297 59
                )->execute()->fetchColumn(0);
298
        }
299
300 59
        return (int)$localizedChangedTime;
301
    }
302
303
    /**
304
     * Returns prepared QueryBuilder for contains* methods in this repository
305
     *
306
     * @param string $itemType
307
     * @param int $itemUid
308
     * @return QueryBuilder
309
     */
310 65
    protected function getQueryBuilderForContainsMethods(string $itemType, int $itemUid) : QueryBuilder
311
    {
312 65
        $queryBuilder = $this->getQueryBuilder();
313 65
        return $queryBuilder->count('uid')->from($this->table)
314 65
            ->andWhere(
315 65
                $queryBuilder->expr()->eq('item_type', $queryBuilder->createNamedParameter($itemType)),
316 65
                $queryBuilder->expr()->eq('item_uid', $itemUid)
317
            );
318
    }
319
320
    /**
321
     * Checks whether the Index Queue contains a specific item.
322
     *
323
     * @param string $itemType The item's type, usually a table name.
324
     * @param int $itemUid The item's uid
325
     * @return bool TRUE if the item is found in the queue, FALSE otherwise
326
     */
327 6
    public function containsItem(string $itemType, int $itemUid) : bool
328
    {
329 6
        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

329
        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...
330
    }
331
332
    /**
333
     * Checks whether the Index Queue contains a specific item.
334
     *
335
     * @param string $itemType The item's type, usually a table name.
336
     * @param int $itemUid The item's uid
337
     * @param integer $rootPageId
338
     * @return bool TRUE if the item is found in the queue, FALSE otherwise
339
     */
340 60
    public function containsItemWithRootPageId(string $itemType, int $itemUid, int $rootPageId) : bool
341
    {
342 60
        $queryBuilder = $this->getQueryBuilderForContainsMethods($itemType, $itemUid);
343
        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

343
        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...
344 60
            ->andWhere($queryBuilder->expr()->eq('root', $rootPageId))
345 60
            ->execute()->fetchColumn(0);
346
    }
347
348
    /**
349
     * Checks whether the Index Queue contains a specific item that has been
350
     * marked as indexed.
351
     *
352
     * @param string $itemType The item's type, usually a table name.
353
     * @param int $itemUid The item's uid
354
     * @return bool TRUE if the item is found in the queue and marked as
355
     *      indexed, FALSE otherwise
356
     */
357 2
    public function containsIndexedItem(string $itemType, int $itemUid) : bool
358
    {
359 2
        $queryBuilder = $this->getQueryBuilderForContainsMethods($itemType, $itemUid);
360
        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

360
        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...
361 2
            ->andWhere($queryBuilder->expr()->gt('indexed', 0))
362 2
            ->execute()->fetchColumn(0);
363
    }
364
365
    /**
366
     * Removes an item from the Index Queue.
367
     *
368
     * @param string $itemType The type of the item to remove, usually a table name.
369
     * @param int $itemUid The uid of the item to remove
370
     */
371 35
    public function deleteItem(string $itemType, int $itemUid = null)
372
    {
373 35
        $itemUids = empty($itemUid) ? [] : [$itemUid];
374 35
        $this->deleteItems([], [], [$itemType], $itemUids);
375 35
    }
376
377
    /**
378
     * Removes all items of a certain type from the Index Queue.
379
     *
380
     * @param string $itemType The type of items to remove, usually a table name.
381
     */
382 1
    public function deleteItemsByType(string $itemType)
383
    {
384 1
        $this->deleteItem($itemType);
385 1
    }
386
387
    /**
388
     * Removes all items of a certain site from the Index Queue. Accepts an
389
     * optional parameter to limit the deleted items by indexing configuration.
390
     *
391
     * @param Site $site The site to remove items for.
392
     * @param string $indexingConfigurationName Name of a specific indexing configuration
393
     * @throws \Exception
394
     */
395 7
    public function deleteItemsBySite(Site $site, string $indexingConfigurationName = '')
396
    {
397 7
        $indexingConfigurationNames = empty($indexingConfigurationName) ? [] : [$indexingConfigurationName];
398 7
        $this->deleteItems([$site], $indexingConfigurationNames);
399 7
    }
400
401
    /**
402
     * Removes items in the index queue filtered by the passed arguments.
403
     *
404
     * @param array $sites
405
     * @param array $indexQueueConfigurationNames
406
     * @param array $itemTypes
407
     * @param array $itemUids
408
     * @param array $uids
409
     * @throws \Exception
410
     */
411 42
    public function deleteItems(array $sites = [], array $indexQueueConfigurationNames = [], array $itemTypes = [], array $itemUids = [], array $uids = [])
412
    {
413 42
        $rootPageIds = Site::getRootPageIdsFromSites($sites);
414 42
        $indexQueueConfigurationList = implode(",", $indexQueueConfigurationNames);
415 42
        $itemTypeList = implode(",", $itemTypes);
416 42
        $itemUids = array_map("intval", $itemUids);
417 42
        $uids = array_map("intval", $uids);
418
419 42
        $queryBuilderForDeletingItems = $this->getQueryBuilder();
420 42
        $queryBuilderForDeletingItems->delete($this->table);
421 42
        $queryBuilderForDeletingItems = $this->addItemWhereClauses($queryBuilderForDeletingItems, $rootPageIds, $indexQueueConfigurationList, $itemTypeList, $itemUids, $uids);
422
423 42
        $queryBuilderForDeletingProperties = $this->buildQueryForPropertyDeletion($queryBuilderForDeletingItems, $rootPageIds, $indexQueueConfigurationList, $itemTypeList, $itemUids, $uids);
424
425 42
        $queryBuilderForDeletingItems->getConnection()->beginTransaction();
426
        try {
427 42
            $queryBuilderForDeletingItems->execute();
428 42
            $queryBuilderForDeletingProperties->execute();
429
430 42
            $queryBuilderForDeletingItems->getConnection()->commit();
431
        } catch (\Exception $e) {
432
            $queryBuilderForDeletingItems->getConnection()->rollback();
433
            throw $e;
434
        }
435 42
    }
436
437
    /**
438
     * Initializes the query builder to delete items in the index queue filtered by the passed arguments.
439
     *
440
     * @param array $rootPageIds filter on a set of rootPageUids.
441
     * @param string $indexQueueConfigurationList
442
     * @param string $itemTypeList
443
     * @param array $itemUids filter on a set of item uids
444
     * @param array $uids filter on a set of queue item uids
445
     * @return QueryBuilder
446
     */
447 44
    private function addItemWhereClauses(QueryBuilder $queryBuilderForDeletingItems, array $rootPageIds, string $indexQueueConfigurationList, string $itemTypeList, array $itemUids, array $uids): QueryBuilder
448
    {
449
450 44
        if (!empty($rootPageIds)) {
451 7
            $queryBuilderForDeletingItems->andWhere($queryBuilderForDeletingItems->expr()->in('root', $rootPageIds));
452
        };
453
454 44
        if (!empty($indexQueueConfigurationList)) {
455 9
            $queryBuilderForDeletingItems->andWhere($queryBuilderForDeletingItems->expr()->in('indexing_configuration', $queryBuilderForDeletingItems->createNamedParameter($indexQueueConfigurationList)));
456
        }
457
458 44
        if (!empty($itemTypeList)) {
459 35
            $queryBuilderForDeletingItems->andWhere($queryBuilderForDeletingItems->expr()->in('item_type', $queryBuilderForDeletingItems->createNamedParameter($itemTypeList)));
460
        }
461
462 44
        if (!empty($itemUids)) {
463 34
            $queryBuilderForDeletingItems->andWhere($queryBuilderForDeletingItems->expr()->in('item_uid', $itemUids));
464
        }
465
466 44
        if (!empty($uids)) {
467 1
            $queryBuilderForDeletingItems->andWhere($queryBuilderForDeletingItems->expr()->in('uid', $uids));
468
        }
469
470 44
        return $queryBuilderForDeletingItems;
471
    }
472
473
    /**
474
     * Initializes a query builder to delete the indexing properties of an item by the passed conditions.
475
     *
476
     * @param QueryBuilder $queryBuilderForDeletingItems
477
     * @param array $rootPageIds
478
     * @param string $indexQueueConfigurationList
479
     * @param string $itemTypeList
480
     * @param array $itemUids
481
     * @param array $uids
482
     * @return QueryBuilder
483
     */
484 42
    private function buildQueryForPropertyDeletion(QueryBuilder $queryBuilderForDeletingItems, array $rootPageIds, string $indexQueueConfigurationList, string $itemTypeList, array $itemUids, array $uids): QueryBuilder
485
    {
486 42
        $queryBuilderForSelectingProperties = $queryBuilderForDeletingItems->getConnection()->createQueryBuilder();
487 42
        $queryBuilderForSelectingProperties->select('items.uid')->from('tx_solr_indexqueue_indexing_property', 'properties')->innerJoin(
488 42
            'properties',
489 42
            $this->table,
490 42
            'items',
491 42
            (string)$queryBuilderForSelectingProperties->expr()->andX(
492 42
                $queryBuilderForSelectingProperties->expr()->eq('items.uid', $queryBuilderForSelectingProperties->quoteIdentifier('properties.item_id')),
493 42
                empty($rootPageIds) ? '' : $queryBuilderForSelectingProperties->expr()->in('items.root', $rootPageIds),
494 42
                empty($indexQueueConfigurationList) ? '' : $queryBuilderForSelectingProperties->expr()->in('items.indexing_configuration', $queryBuilderForSelectingProperties->createNamedParameter($indexQueueConfigurationList)),
495 42
                empty($itemTypeList) ? '' : $queryBuilderForSelectingProperties->expr()->in('items.item_type', $queryBuilderForSelectingProperties->createNamedParameter($itemTypeList)),
496 42
                empty($itemUids) ? '' : $queryBuilderForSelectingProperties->expr()->in('items.item_uid', $itemUids),
497 42
                empty($uids) ? '' : $queryBuilderForSelectingProperties->expr()->in('items.uid', $uids)
498
            )
499
        );
500 42
        $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

500
        $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...
501
502 42
        $queryBuilderForDeletingProperties = $queryBuilderForDeletingItems->getConnection()->createQueryBuilder();
503
504
        // make sure executing the propety deletion query doesn't fail if there are no properties to delete
505 42
        if (empty($propertyEntriesToDelete)) {
506 41
            $propertyEntriesToDelete = '0';
507
        }
508
509 42
        $queryBuilderForDeletingProperties->delete('tx_solr_indexqueue_indexing_property')->where(
510 42
            $queryBuilderForDeletingProperties->expr()->in('item_id', $propertyEntriesToDelete)
511
        );
512
513 42
        return $queryBuilderForDeletingProperties;
514
    }
515
516
    /**
517
     * Removes all items from the Index Queue.
518
     *
519
     * @return int The number of affected rows. For a truncate this is unreliable as theres no meaningful information.
520
     */
521 1
    public function deleteAllItems()
522
    {
523 1
        return $this->getQueryBuilder()->getConnection()->truncate($this->table);
524
    }
525
526
    /**
527
     * Gets a single Index Queue item by its uid.
528
     *
529
     * @param int $uid Index Queue item uid
530
     * @return Item|null The request Index Queue item or NULL if no item with $itemId was found
531
     */
532 26
    public function findItemByUid(int $uid)
533
    {
534 26
        $queryBuilder = $this->getQueryBuilder();
535
        $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

535
        $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...
536 26
            ->select('*')
537 26
            ->from($this->table)
538 26
            ->where($queryBuilder->expr()->eq('uid', $uid))
539 26
            ->execute()->fetch();
540
541 26
        if (!isset($indexQueueItemRecord['uid'])) {
542 3
            return null;
543
        }
544
545
        /** @var Item $item*/
546 23
        $item = GeneralUtility::makeInstance(Item::class, /** @scrutinizer ignore-type */ $indexQueueItemRecord);
547 23
        return $item;
548
    }
549
550
    /**
551
     * Gets Index Queue items by type and uid.
552
     *
553
     * @param string $itemType item type, usually  the table name
554
     * @param int $itemUid item uid
555
     * @return Item[] An array of items matching $itemType and $itemUid
556
     */
557 38
    public function findItemsByItemTypeAndItemUid(string $itemType, int $itemUid) : array
558
    {
559 38
        $queryBuilder = $this->getQueryBuilder();
560 38
        $compositeExpression = $queryBuilder->expr()->andX(
561 38
            $queryBuilder->expr()->eq('item_type', $queryBuilder->getConnection()->quote($itemType, \PDO::PARAM_STR)),
562 38
            $queryBuilder->expr()->eq('item_uid', $itemUid)
563
        );
564 38
        return $this->getItemsByCompositeExpression($compositeExpression, $queryBuilder);
565
    }
566
567
    /**
568
     * Returns a collection of items by CompositeExpression.
569
     * D
570
     *
571
     * @param CompositeExpression|null $expression Optional expression to filter records.
572
     * @param QueryBuilder|null $queryBuilder QueryBuilder to use
573
     * @return array
574
     */
575 38
    protected function getItemsByCompositeExpression(CompositeExpression $expression = null, QueryBuilder $queryBuilder = null) : array
576
    {
577 38
        if (!$queryBuilder instanceof QueryBuilder) {
578
            $queryBuilder = $this->getQueryBuilder();
579
        }
580
581 38
        $queryBuilder->select('*')->from($this->table);
582 38
        if (isset($expression)) {
583 38
            $queryBuilder->where($expression);
584
        }
585
586 38
        $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

586
        $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...
587 38
        return $this->getIndexQueueItemObjectsFromRecords($indexQueueItemRecords);
588
    }
589
590
    /**
591
     * Returns all items in the queue.
592
     *
593
     * @return Item[] all Items from Queue without restrictions
594
     */
595 1
    public function findAll() : array
596
    {
597 1
        $queryBuilder = $this->getQueryBuilder();
598
        $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

598
        $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...
599 1
            ->select('*')
600 1
            ->from($this->table)
601 1
            ->execute()->fetchAll();
602 1
        return $this->getIndexQueueItemObjectsFromRecords($allRecords);
603
    }
604
605
    /**
606
     * Gets $limit number of items to index for a particular $site.
607
     *
608
     * @param Site $site TYPO3 site
609
     * @param int $limit Number of items to get from the queue
610
     * @return Item[] Items to index to the given solr server
611
     */
612 3
    public function findItemsToIndex(Site $site, int $limit = 50) : array
613
    {
614 3
        $queryBuilder = $this->getQueryBuilder();
615
        // determine which items to index with this run
616
        $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

616
        $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...
617 3
            ->select('*')
618 3
            ->from($this->table)
619 3
            ->andWhere(
620 3
                $queryBuilder->expr()->eq('root', $site->getRootPageId()),
621 3
                $queryBuilder->expr()->gt('changed', 'indexed'),
622 3
                $queryBuilder->expr()->lte('changed', time()),
623 3
                $queryBuilder->expr()->eq('errors', $queryBuilder->createNamedParameter(''))
624
            )
625 3
            ->orderBy('indexing_priority', 'DESC')
626 3
            ->addOrderBy('changed', 'DESC')
627 3
            ->addOrderBy('uid', 'DESC')
628 3
            ->setMaxResults($limit)
629 3
            ->execute()->fetchAll();
630
631 3
        return $this->getIndexQueueItemObjectsFromRecords($indexQueueItemRecords);
632
    }
633
634
    /**
635
     * Retrieves the count of items that match certain filters. Each filter is passed as parts of the where claus combined with AND.
636
     *
637
     * @param array $sites
638
     * @param array $indexQueueConfigurationNames
639
     * @param array $itemTypes
640
     * @param array $itemUids
641
     * @param array $uids
642
     * @param int $start
643
     * @param int $limit
644
     * @return array
645
     */
646 1
    public function findItems(array $sites = [], array $indexQueueConfigurationNames = [], array $itemTypes = [], array $itemUids = [], array $uids = [], $start = 0, $limit = 50): array
647
    {
648 1
        $rootPageIds = Site::getRootPageIdsFromSites($sites);
649 1
        $indexQueueConfigurationList = implode(",", $indexQueueConfigurationNames);
650 1
        $itemTypeList = implode(",", $itemTypes);
651 1
        $itemUids = array_map("intval", $itemUids);
652 1
        $uids = array_map("intval", $uids);
653 1
        $itemQueryBuilder = $this->getQueryBuilder()->select('*')->from($this->table);
654 1
        $itemQueryBuilder = $this->addItemWhereClauses($itemQueryBuilder, $rootPageIds, $indexQueueConfigurationList, $itemTypeList, $itemUids, $uids);
655 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

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

829
        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...
830
    }
831
832
    /**
833
     * Retrieves an array of pageIds from mountPoints that allready have a queue entry.
834
     *
835
     * @param string $identifier identifier of the mount point
836
     * @return array pageIds from mountPoints that allready have a queue entry
837
     */
838 7
    public function findPageIdsOfExistingMountPagesByMountIdentifier(string $identifier) : array
839
    {
840 7
        $queryBuilder = $this->getQueryBuilder();
841
        $resultSet = $queryBuilder
842 7
            ->select('item_uid')
843 7
            ->add('select', $queryBuilder->expr()->count('*', 'queueItemCount'), true)
844 7
            ->from($this->table)
845 7
            ->where(
846 7
                $queryBuilder->expr()->eq('item_type', $queryBuilder->createNamedParameter('pages')),
847 7
                $queryBuilder->expr()->eq('pages_mountidentifier', $queryBuilder->createNamedParameter($identifier))
848
            )
849 7
            ->groupBy('item_uid')
850 7
            ->execute();
851
852 7
        $mountedPagesIdsWithQueueItems = [];
853 7
        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

853
        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...
854
            if ($record['queueItemCount'] > 0) {
855
                $mountedPagesIdsWithQueueItems[] = $record['item_uid'];
856
            }
857
        }
858
859 7
        return $mountedPagesIdsWithQueueItems;
860
    }
861
862
    /**
863
     * Retrieves an array of items for mount destinations mathed by root page ID, Mount Identifier and a list of mounted page IDs.
864
     *
865
     * @param int $rootPid
866
     * @param string $identifier identifier of the mount point
867
     * @param array $mountedPids An array of mounted page IDs
868
     * @return array
869
     */
870 7
    public function findAllIndexQueueItemsByRootPidAndMountIdentifierAndMountedPids(int $rootPid, string $identifier, array $mountedPids) : array
871
    {
872 7
        $queryBuilder = $this->getQueryBuilder();
873
        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

873
        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...
874 7
            ->select('*')
875 7
            ->from($this->table)
876 7
            ->where(
877 7
                $queryBuilder->expr()->eq('root', $queryBuilder->createNamedParameter($rootPid, \PDO::PARAM_INT)),
878 7
                $queryBuilder->expr()->eq('item_type', $queryBuilder->createNamedParameter('pages')),
879 7
                $queryBuilder->expr()->in('item_uid', $mountedPids),
880 7
                $queryBuilder->expr()->eq('has_indexing_properties', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)),
881 7
                $queryBuilder->expr()->eq('pages_mountidentifier', $queryBuilder->createNamedParameter($identifier))
882
            )
883 7
            ->execute()->fetchAll();
884
    }
885
886
    /**
887
     * Updates has_indexing_properties field for given Item
888
     *
889
     * @param int $itemUid
890
     * @param bool $hasIndexingPropertiesFlag
891
     * @return int number of affected rows, 1 on success
892
     */
893 9
    public function updateHasIndexingPropertiesFlagByItemUid(int $itemUid, bool $hasIndexingPropertiesFlag): int
894
    {
895 9
        $queryBuilder = $this->getQueryBuilder();
896
897
        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...
898 9
            ->update($this->table)
899 9
            ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($itemUid, \PDO::PARAM_INT)))
900 9
            ->set('has_indexing_properties', $queryBuilder->createNamedParameter($hasIndexingPropertiesFlag, \PDO::PARAM_INT), false)
901 9
            ->execute();
902
    }
903
}
904