|
1
|
|
|
<?php |
|
2
|
|
|
namespace AOE\Crawler\Domain\Repository; |
|
3
|
|
|
|
|
4
|
|
|
/*************************************************************** |
|
5
|
|
|
* Copyright notice |
|
6
|
|
|
* |
|
7
|
|
|
* (c) 2018 AOE GmbH <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* All rights reserved |
|
10
|
|
|
* |
|
11
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
|
12
|
|
|
* free software; you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU General Public License as published by |
|
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
15
|
|
|
* (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* The GNU General Public License can be found at |
|
18
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
|
19
|
|
|
* |
|
20
|
|
|
* This script is distributed in the hope that it will be useful, |
|
21
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
22
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
23
|
|
|
* GNU General Public License for more details. |
|
24
|
|
|
* |
|
25
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
|
26
|
|
|
***************************************************************/ |
|
27
|
|
|
|
|
28
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
29
|
|
|
use TYPO3\CMS\Core\Database\Connection; |
|
30
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
|
31
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder; |
|
32
|
|
|
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction; |
|
33
|
|
|
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction; |
|
34
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Class ConfigurationRepository |
|
38
|
|
|
*/ |
|
39
|
|
|
class ConfigurationRepository extends AbstractRepository |
|
40
|
|
|
{ |
|
41
|
|
|
/** |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $tableName = 'tx_crawler_configuration'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return array |
|
48
|
|
|
*/ |
|
49
|
1 |
|
public function getCrawlerConfigurationRecords(): array |
|
50
|
|
|
{ |
|
51
|
1 |
|
$records = []; |
|
52
|
1 |
|
$queryBuilder = $this->createQueryBuilder(); |
|
53
|
|
|
$statement = $queryBuilder |
|
54
|
1 |
|
->select('*') |
|
55
|
1 |
|
->from($this->tableName) |
|
56
|
1 |
|
->execute(); |
|
57
|
|
|
|
|
58
|
1 |
|
while ($row = $statement->fetch()) { |
|
59
|
1 |
|
$records[] = $row; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
1 |
|
return $records; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Traverses up the rootline of a page and fetches all crawler records. |
|
68
|
|
|
* |
|
69
|
|
|
* @param int $pageId |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
2 |
|
public function getCrawlerConfigurationRecordsFromRootLine(int $pageId): array |
|
73
|
|
|
{ |
|
74
|
2 |
|
$pageIdsInRootLine = []; |
|
75
|
2 |
|
$rootLine = BackendUtility::BEgetRootLine($pageId); |
|
76
|
|
|
|
|
77
|
2 |
|
foreach ($rootLine as $pageInRootLine) { |
|
78
|
2 |
|
$pageIdsInRootLine[] = (int)$pageInRootLine['uid']; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
2 |
|
$queryBuilder = $this->createQueryBuilder(); |
|
82
|
|
|
$queryBuilder |
|
83
|
2 |
|
->getRestrictions()->removeAll() |
|
84
|
2 |
|
->add(GeneralUtility::makeInstance(DeletedRestriction::class)) |
|
85
|
2 |
|
->add(GeneralUtility::makeInstance(HiddenRestriction::class)); |
|
86
|
|
|
$configurationRecordsForCurrentPage = $queryBuilder |
|
87
|
2 |
|
->select('*') |
|
88
|
2 |
|
->from($this->tableName) |
|
89
|
2 |
|
->where( |
|
90
|
2 |
|
$queryBuilder->expr()->in('pid', $queryBuilder->createNamedParameter($pageIdsInRootLine, Connection::PARAM_INT_ARRAY)) |
|
91
|
|
|
) |
|
92
|
2 |
|
->execute() |
|
93
|
2 |
|
->fetchAll(); |
|
94
|
2 |
|
return is_array($configurationRecordsForCurrentPage) ? $configurationRecordsForCurrentPage : []; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
3 |
|
protected function createQueryBuilder(): QueryBuilder |
|
98
|
|
|
{ |
|
99
|
3 |
|
return GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->tableName); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|