Passed
Push — issue/729 ( 98ba2c...3e0346 )
by Tomas Norre
87:46 queued 72:59
created

Domain/Repository/ConfigurationRepository.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace AOE\Crawler\Domain\Repository;
6
7
/*
8
 * (c) 2020 AOE GmbH <[email protected]>
9
 *
10
 * This file is part of the TYPO3 Crawler Extension.
11
 *
12
 * It is free software; you can redistribute it and/or modify it under
13
 * the terms of the GNU General Public License, either version 2
14
 * of the License, or any later version.
15
 *
16
 * For the full copyright and license information, please read the
17
 * LICENSE.txt file that was distributed with this source code.
18
 *
19
 * The TYPO3 project - inspiring people to share!
20
 */
21
22
use TYPO3\CMS\Backend\Utility\BackendUtility;
23
use TYPO3\CMS\Core\Database\Connection;
24
use TYPO3\CMS\Core\Database\ConnectionPool;
25
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
26
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
27
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
28
use TYPO3\CMS\Core\Utility\GeneralUtility;
29
use TYPO3\CMS\Extbase\Persistence\Repository;
30
31
/**
32
 * @internal since v9.2.5
33
 */
34
class ConfigurationRepository extends Repository
35
{
36
    public const TABLE_NAME = 'tx_crawler_configuration';
37
38
    /**
39
     * @var string
40
     * @deprecated Since v9.2.5 - This will be remove in v10
41
     */
42
    protected $tableName = 'tx_crawler_configuration';
43
44
    public function getCrawlerConfigurationRecords(): array
45
    {
46
        $records = [];
47
        $queryBuilder = $this->createQueryBuilder();
48
        $statement = $queryBuilder
49
            ->select('*')
50
            ->from(self::TABLE_NAME)
51
            ->execute();
52
53
        while ($row = $statement->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

53
        while ($row = /** @scrutinizer ignore-deprecated */ $statement->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...
54
            $records[] = $row;
55
        }
56
57
        return $records;
58
    }
59
60
    /**
61
     * Traverses up the rootline of a page and fetches all crawler records.
62
     */
63
    public function getCrawlerConfigurationRecordsFromRootLine(int $pageId): array
64
    {
65
        $pageIdsInRootLine = [];
66
        $rootLine = BackendUtility::BEgetRootLine($pageId);
67
68
        foreach ($rootLine as $pageInRootLine) {
69
            $pageIdsInRootLine[] = (int) $pageInRootLine['uid'];
70
        }
71
72
        $queryBuilder = $this->createQueryBuilder();
73
        $queryBuilder
74
            ->getRestrictions()->removeAll()
75
            ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
76
            ->add(GeneralUtility::makeInstance(HiddenRestriction::class));
77
        $configurationRecordsForCurrentPage = $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

77
        $configurationRecordsForCurrentPage = /** @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...
78
            ->select('*')
79
            ->from(self::TABLE_NAME)
80
            ->where(
81
                $queryBuilder->expr()->in('pid', $queryBuilder->createNamedParameter($pageIdsInRootLine, Connection::PARAM_INT_ARRAY))
82
            )
83
            ->execute()
84
            ->fetchAll();
85
        return is_array($configurationRecordsForCurrentPage) ? $configurationRecordsForCurrentPage : [];
86
    }
87
88
    protected function createQueryBuilder(): QueryBuilder
89
    {
90
        return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE_NAME);
91
    }
92
}
93