Passed
Push — deprecate/getLogEntriesForPage... ( c5a454...e87c0b )
by Tomas Norre
06:06 queued 02:10
created

ConfigurationRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 71.05%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
dl 0
loc 54
ccs 27
cts 38
cp 0.7105
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCrawlerConfigurationRecords() 0 14 2
A createQueryBuilder() 0 3 1
A getCrawlerConfigurationRecordsFromRootLine() 0 23 3
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
 * Class ConfigurationRepository
33
 */
34
class ConfigurationRepository extends Repository
35
{
36
    /**
37
     * @var string
38
     */
39
    protected $tableName = 'tx_crawler_configuration';
40
41 1
    public function getCrawlerConfigurationRecords(): array
42
    {
43 1
        $records = [];
44 1
        $queryBuilder = $this->createQueryBuilder();
45
        $statement = $queryBuilder
46 1
            ->select('*')
47 1
            ->from($this->tableName)
48 1
            ->execute();
49
50 1
        while ($row = $statement->fetch()) {
51 1
            $records[] = $row;
52
        }
53
54 1
        return $records;
55
    }
56
57
    /**
58
     * Traverses up the rootline of a page and fetches all crawler records.
59
     */
60 6
    public function getCrawlerConfigurationRecordsFromRootLine(int $pageId): array
61
    {
62 6
        $pageIdsInRootLine = [];
63 6
        $rootLine = BackendUtility::BEgetRootLine($pageId);
64
65 6
        foreach ($rootLine as $pageInRootLine) {
66 5
            $pageIdsInRootLine[] = (int) $pageInRootLine['uid'];
67
        }
68
69 6
        $queryBuilder = $this->createQueryBuilder();
70
        $queryBuilder
71 6
            ->getRestrictions()->removeAll()
72 6
            ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
73 6
            ->add(GeneralUtility::makeInstance(HiddenRestriction::class));
74
        $configurationRecordsForCurrentPage = $queryBuilder
75 6
            ->select('*')
76 6
            ->from($this->tableName)
77 6
            ->where(
78 6
                $queryBuilder->expr()->in('pid', $queryBuilder->createNamedParameter($pageIdsInRootLine, Connection::PARAM_INT_ARRAY))
79
            )
80 6
            ->execute()
81 6
            ->fetchAll();
82 6
        return is_array($configurationRecordsForCurrentPage) ? $configurationRecordsForCurrentPage : [];
0 ignored issues
show
introduced by
The condition is_array($configurationRecordsForCurrentPage) is always true.
Loading history...
83
    }
84
85 7
    protected function createQueryBuilder(): QueryBuilder
86
    {
87 7
        return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName);
88
    }
89
}
90