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
|
2 |
|
public function getCrawlerConfigurationRecords(): array |
42
|
|
|
{ |
43
|
2 |
|
$records = []; |
44
|
2 |
|
$queryBuilder = $this->createQueryBuilder(); |
45
|
|
|
$statement = $queryBuilder |
46
|
2 |
|
->select('*') |
47
|
2 |
|
->from($this->tableName) |
48
|
2 |
|
->execute(); |
49
|
|
|
|
50
|
2 |
|
while ($row = $statement->fetch()) { |
51
|
2 |
|
$records[] = $row; |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
return $records; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Traverses up the rootline of a page and fetches all crawler records. |
59
|
|
|
*/ |
60
|
12 |
|
public function getCrawlerConfigurationRecordsFromRootLine(int $pageId): array |
61
|
|
|
{ |
62
|
12 |
|
$pageIdsInRootLine = []; |
63
|
12 |
|
$rootLine = BackendUtility::BEgetRootLine($pageId); |
64
|
|
|
|
65
|
12 |
|
foreach ($rootLine as $pageInRootLine) { |
66
|
10 |
|
$pageIdsInRootLine[] = (int) $pageInRootLine['uid']; |
67
|
|
|
} |
68
|
|
|
|
69
|
12 |
|
$queryBuilder = $this->createQueryBuilder(); |
70
|
|
|
$queryBuilder |
71
|
12 |
|
->getRestrictions()->removeAll() |
72
|
12 |
|
->add(GeneralUtility::makeInstance(DeletedRestriction::class)) |
73
|
12 |
|
->add(GeneralUtility::makeInstance(HiddenRestriction::class)); |
74
|
|
|
$configurationRecordsForCurrentPage = $queryBuilder |
75
|
12 |
|
->select('*') |
76
|
12 |
|
->from($this->tableName) |
77
|
12 |
|
->where( |
78
|
12 |
|
$queryBuilder->expr()->in('pid', $queryBuilder->createNamedParameter($pageIdsInRootLine, Connection::PARAM_INT_ARRAY)) |
79
|
|
|
) |
80
|
12 |
|
->execute() |
81
|
12 |
|
->fetchAll(); |
82
|
12 |
|
return is_array($configurationRecordsForCurrentPage) ? $configurationRecordsForCurrentPage : []; |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
14 |
|
protected function createQueryBuilder(): QueryBuilder |
86
|
|
|
{ |
87
|
14 |
|
return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|