1 | <?php |
||
41 | class ReIndexTask extends AbstractTask |
||
42 | { |
||
43 | |||
44 | /** |
||
45 | * The site this task is supposed to initialize the index queue for. |
||
46 | * |
||
47 | * @var Site |
||
48 | */ |
||
49 | protected $site; |
||
50 | |||
51 | /** |
||
52 | * Indexing configurations to re-initialize. |
||
53 | * |
||
54 | * @var array |
||
55 | */ |
||
56 | protected $indexingConfigurationsToReIndex = []; |
||
57 | |||
58 | /** |
||
59 | * Purges/commits all Solr indexes, initializes the Index Queue |
||
60 | * and returns TRUE if the execution was successful |
||
61 | * |
||
62 | * @return bool Returns TRUE on success, FALSE on failure. |
||
63 | */ |
||
64 | 2 | public function execute() |
|
80 | |||
81 | /** |
||
82 | * Removes documents of the selected types from the index. |
||
83 | * |
||
84 | * @return bool TRUE if clean up was successful, FALSE on error |
||
85 | */ |
||
86 | 2 | protected function cleanUpIndex() |
|
87 | { |
||
88 | 2 | $cleanUpResult = true; |
|
89 | 2 | $solrConfiguration = $this->site->getSolrConfiguration(); |
|
90 | 2 | $solrServers = GeneralUtility::makeInstance(ConnectionManager::class)->getConnectionsBySite($this->site); |
|
91 | 2 | $typesToCleanUp = []; |
|
92 | 2 | $enableCommitsSetting = $solrConfiguration->getEnableCommits(); |
|
93 | |||
94 | 2 | foreach ($this->indexingConfigurationsToReIndex as $indexingConfigurationName) { |
|
95 | 2 | $type = $solrConfiguration->getIndexQueueTableNameOrFallbackToConfigurationName($indexingConfigurationName); |
|
96 | 2 | $typesToCleanUp[] = $type; |
|
97 | } |
||
98 | |||
99 | 2 | foreach ($solrServers as $solrServer) { |
|
100 | 2 | $deleteQuery = 'type:(' . implode(' OR ', $typesToCleanUp) . ')' |
|
101 | 2 | . ' AND siteHash:' . $this->site->getSiteHash(); |
|
102 | 2 | $solrServer->deleteByQuery($deleteQuery); |
|
103 | |||
104 | 2 | if (!$enableCommitsSetting) { |
|
105 | # Do not commit |
||
106 | continue; |
||
107 | } |
||
108 | |||
109 | 2 | $response = $solrServer->commit(false, false, false); |
|
110 | 2 | if ($response->getHttpStatus() != 200) { |
|
111 | $cleanUpResult = false; |
||
112 | 2 | break; |
|
113 | } |
||
114 | } |
||
115 | |||
116 | 2 | return $cleanUpResult; |
|
117 | } |
||
118 | |||
119 | /** |
||
120 | * Gets the site / the site's root page uid this task is running on. |
||
121 | * |
||
122 | * @return Site The site's root page uid this task is optimizing |
||
123 | */ |
||
124 | public function getSite() |
||
128 | |||
129 | /** |
||
130 | * Sets the task's site. |
||
131 | * |
||
132 | * @param Site $site The site to be handled by this task |
||
133 | */ |
||
134 | 3 | public function setSite(Site $site) |
|
138 | |||
139 | /** |
||
140 | * Gets the indexing configurations to re-index. |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | public function getIndexingConfigurationsToReIndex() |
||
148 | |||
149 | /** |
||
150 | * Sets the indexing configurations to re-index. |
||
151 | * |
||
152 | * @param array $indexingConfigurationsToReIndex |
||
153 | */ |
||
154 | 3 | public function setIndexingConfigurationsToReIndex( |
|
159 | |||
160 | /** |
||
161 | * This method is designed to return some additional information about the task, |
||
162 | * that may help to set it apart from other tasks from the same class |
||
163 | * This additional information is used - for example - in the Scheduler's BE module |
||
164 | * This method should be implemented in most task classes |
||
165 | * |
||
166 | * @return string Information to display |
||
167 | */ |
||
168 | 1 | public function getAdditionalInformation() |
|
183 | } |
||
184 |