1 | <?php |
||
45 | class Page extends AbstractInitializer |
||
46 | { |
||
47 | /** |
||
48 | * @var \ApacheSolrForTypo3\Solr\System\Logging\SolrLogManager |
||
49 | */ |
||
50 | protected $logger = null; |
||
51 | |||
52 | /** |
||
53 | * Constructor, sets type and indexingConfigurationName to "pages". |
||
54 | * |
||
55 | */ |
||
56 | 11 | public function __construct() |
|
63 | |||
64 | /** |
||
65 | * Overrides the general setType() implementation, forcing type to "pages". |
||
66 | * |
||
67 | * @param string $type Type to initialize (ignored). |
||
68 | */ |
||
69 | 10 | public function setType($type) |
|
73 | |||
74 | /** |
||
75 | * Initializes Index Queue page items for a site. Includes regular pages |
||
76 | * and mounted pages - no nested mount page structures though. |
||
77 | * |
||
78 | * @return bool TRUE if initialization was successful, FALSE on error. |
||
79 | */ |
||
80 | 10 | public function initialize() |
|
87 | |||
88 | /** |
||
89 | * Initialize a single page that is part of a mounted tree. |
||
90 | * |
||
91 | * @param array $mountProperties Array of mount point properties mountPageSource, mountPageDestination, and mountPageOverlayed |
||
92 | * @param int $mountPageId The ID of the mounted page |
||
93 | */ |
||
94 | 1 | public function initializeMountedPage(array $mountProperties, $mountPageId) |
|
101 | |||
102 | /** |
||
103 | * Initializes Mount Pages to be indexed through the Index Queue. The Mount |
||
104 | * Pages are searched and their mounted virtual sub-trees are then resolved |
||
105 | * and added to the Index Queue as if they were actually present below the |
||
106 | * Mount Page. |
||
107 | * |
||
108 | * @return bool TRUE if initialization of the Mount Pages was successful, FALSE otherwise |
||
109 | */ |
||
110 | 10 | protected function initializeMountPages() |
|
111 | { |
||
112 | 10 | $mountPagesInitialized = false; |
|
113 | 10 | $mountPages = $this->findMountPages(); |
|
114 | |||
115 | 10 | if (empty($mountPages)) { |
|
116 | 4 | $mountPagesInitialized = true; |
|
117 | 4 | return $mountPagesInitialized; |
|
118 | } |
||
119 | |||
120 | 6 | foreach ($mountPages as $mountPage) { |
|
121 | 6 | if (!$this->validateMountPage($mountPage)) { |
|
122 | 3 | continue; |
|
123 | } |
||
124 | |||
125 | |||
126 | 6 | $mountedPages = $this->resolveMountPageTree($mountPage); |
|
127 | |||
128 | // handling mount_pid_ol behavior |
||
129 | 6 | if ($mountPage['mountPageOverlayed']) { |
|
130 | // the page shows the mounted page's content |
||
131 | 3 | $mountedPages[] = $mountPage['mountPageSource']; |
|
132 | } else { |
||
133 | // Add page like a regular page, as only the sub tree is |
||
134 | // mounted. The page itself has its own content. |
||
135 | 3 | $indexQueue = GeneralUtility::makeInstance(Queue::class); |
|
136 | 3 | $indexQueue->updateItem($this->type, $mountPage['uid']); |
|
137 | } |
||
138 | |||
139 | // This can happen when the mount point does not show the content of the |
||
140 | // mounted page and the mounted page does not have any subpages. |
||
141 | 6 | if (empty($mountedPages)) { |
|
142 | continue; |
||
143 | } |
||
144 | |||
145 | 6 | DatabaseUtility::transactionStart(); |
|
146 | try { |
||
147 | 6 | $this->addMountedPagesToIndexQueue($mountedPages, $mountPage); |
|
148 | 6 | $this->addIndexQueueItemIndexingProperties($mountPage, $mountedPages); |
|
149 | |||
150 | 6 | DatabaseUtility::transactionCommit(); |
|
151 | 6 | $mountPagesInitialized = true; |
|
152 | } catch (\Exception $e) { |
||
153 | DatabaseUtility::transactionRollback(); |
||
154 | |||
155 | $this->logger->log( |
||
156 | SolrLogManager::ERROR, |
||
157 | 'Index Queue initialization failed for mount pages', |
||
158 | [ |
||
159 | $e->__toString() |
||
160 | ] |
||
161 | ); |
||
162 | 6 | break; |
|
163 | } |
||
164 | } |
||
165 | |||
166 | 6 | return $mountPagesInitialized; |
|
167 | } |
||
168 | |||
169 | /** |
||
170 | * Checks whether a Mount Page is properly configured. |
||
171 | * |
||
172 | * @param array $mountPage A mount page |
||
173 | * @return bool TRUE if the Mount Page is OK, FALSE otherwise |
||
174 | */ |
||
175 | 6 | protected function validateMountPage(array $mountPage) |
|
209 | |||
210 | /** |
||
211 | * Checks whether the mounted page (mount page source) exists. That is, |
||
212 | * whether it accessible in the frontend. So the record must exist |
||
213 | * (deleted = 0) and must not be hidden (hidden = 0). |
||
214 | * |
||
215 | * @param int $mountedPageId Mounted page ID |
||
216 | * @return bool TRUE if the page is accessible in the frontend, FALSE otherwise. |
||
217 | */ |
||
218 | 6 | protected function mountedPageExists($mountedPageId) |
|
229 | |||
230 | /** |
||
231 | * Adds the virtual / mounted pages to the Index Queue as if they would |
||
232 | * belong to the same site where they are mounted. |
||
233 | * |
||
234 | * @param array $mountedPages An array of mounted page IDs |
||
235 | * @param array $mountProperties Array with mount point properties (mountPageSource, mountPageDestination, mountPageOverlayed) |
||
236 | */ |
||
237 | 7 | protected function addMountedPagesToIndexQueue(array $mountedPages, array $mountProperties) |
|
269 | 7 | ||
270 | 7 | /** |
|
271 | 7 | * Retrieves an array of pageIds from mountPoints that allready have a queue entry. |
|
272 | 7 | * |
|
273 | 7 | * @param array $mountProperties |
|
274 | 7 | * @return array |
|
275 | 7 | */ |
|
276 | 7 | protected function getPageIdsOfExistingMountPages($mountProperties) |
|
298 | |||
299 | 7 | /** |
|
300 | * Adds Index Queue item indexing properties for mounted pages. The page |
||
301 | 7 | * indexer later needs to know that he's dealing with a mounted page, the |
|
302 | 7 | * indexing properties will let make it possible for the indexer to |
|
303 | 7 | * distinguish the mounted pages. |
|
304 | 7 | * |
|
305 | 7 | * @param array $mountPage An array with information about the root/destination Mount Page |
|
306 | 7 | * @param array $mountedPages An array of mounted page IDs |
|
307 | 7 | */ |
|
308 | 7 | protected function addIndexQueueItemIndexingProperties(array $mountPage, array $mountedPages) |
|
335 | 7 | ||
336 | 7 | /** |
|
337 | 7 | * Builds an identifier of the given mount point properties. |
|
338 | * |
||
339 | * @param array $mountProperties Array with mount point properties (mountPageSource, mountPageDestination, mountPageOverlayed) |
||
340 | * @return string String consisting of mountPageSource-mountPageDestination-mountPageOverlayed |
||
341 | */ |
||
342 | protected function getMountPointIdentifier(array $mountProperties) |
||
348 | |||
349 | 10 | // Mount Page resolution |
|
350 | |||
351 | /** |
||
352 | * Finds the mount pages in the current site. |
||
353 | * |
||
354 | 10 | * @return array An array of mount pages |
|
355 | 10 | */ |
|
356 | 10 | protected function findMountPages() |
|
370 | 6 | ||
371 | 6 | /** |
|
372 | * Gets all the pages from a mounted page tree. |
||
373 | 6 | * |
|
374 | * @param array $mountPage |
||
375 | 6 | * @return array An array of page IDs in the mounted page tree |
|
376 | */ |
||
377 | 6 | protected function resolveMountPageTree($mountPage) |
|
388 | } |
||
389 |