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