TYPO3 Solr pageIndexer recursive downline / upline enabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\MyExt\Solr\IndexQueue; | |
use ApacheSolrForTypo3\Solr\IndexQueue\Item; | |
use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexer as SolrPageIndexer; | |
/** | |
* Override PageIndexer class | |
*/ | |
class PageIndexer extends SolrPageIndexer | |
{ | |
/** | |
* Checks whether we can index this page. | |
* | |
* @param Item $item The page we want to index encapsulated in an index queue item | |
* @return bool True if we can index this page, FALSE otherwise | |
*/ | |
protected function isPageIndexable(Item $item) | |
{ | |
$isIndexable = true; | |
$record = $item->getRecord(); | |
if (isset($GLOBALS['TCA']['pages']['ctrl']['enablecolumns']['disabled']) | |
&& $record[$GLOBALS['TCA']['pages']['ctrl']['enablecolumns']['disabled']]) { | |
$isIndexable = false; | |
} | |
if ($this->isDisabledRecordInRootline($record['pid'])) { | |
$isIndexable = false; | |
} | |
return $isIndexable; | |
} | |
/** | |
* Check if there's a disabled page in rootline | |
* | |
* @param int $uid | |
* | |
* @return bool | |
*/ | |
protected function isDisabledRecordInRootline($uid) | |
{ | |
$row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow( | |
'uid,pid,hidden,doktype,nav_hide', | |
'pages', | |
'uid = ' . $uid | |
); | |
if (!is_null($row)) { | |
if ($row['hidden'] == 1) { | |
return true; | |
} elseif ($row['nav_hide'] == 1) { | |
return true; | |
} elseif ($row['doktype'] == 254) { | |
return true; | |
} else { | |
return $this->isDisabledRecordInRootline($row['pid']); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vendor\MyExt\Solr\IndexQueue\Initializer; | |
use ApacheSolrForTypo3\Solr\IndexQueue\Initializer\Page as SolrPage; | |
/** | |
* Extend solr page initializer to exclude recusive | |
*/ | |
class Page extends SolrPage | |
{ | |
/** | |
* Initializes Index Queue page items for a site. Includes regular pages | |
* and mounted pages - no nested mount page structures though. | |
* | |
* @return bool TRUE if initialization was successful, FALSE on error. | |
*/ | |
public function initialize() | |
{ | |
$pagesInitialized = parent::initialize(); | |
$deleteClause = 'item_type = "' . $this->type . '" AND ' . $this->buildDisabledPageClause(); | |
$GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_solr_indexqueue_item', $deleteClause); | |
return $pagesInitialized; | |
} | |
/** | |
* @return string | |
*/ | |
protected function buildDisabledPageClause() | |
{ | |
$whereClause = ''; | |
$disabledPages = []; | |
$rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( | |
'uid', | |
'pages', | |
'(hidden = 1 OR nav_hide = 1 OR doktype = 254) AND deleted = 0' | |
); | |
if (is_array($rows)) { | |
foreach ($rows as $row) { | |
$disabledPages[] = $row['uid']; | |
} | |
$disabledPages = $this->getAllChildren($disabledPages); | |
if (!empty($disabledPages)) { | |
$whereClause = 'item_uid IN (' . implode(',', $disabledPages) . ')'; | |
} else { | |
$whereClause = '1=1'; | |
} | |
} | |
return $whereClause; | |
} | |
/** | |
* Get all chrildren from given uids | |
* | |
* @param array $pageIds | |
* @return array | |
*/ | |
protected function getAllChildren($pageIds) | |
{ | |
$childPages = []; | |
$childRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows( | |
'uid', | |
'pages', | |
'deleted = 0 AND pid IN (' . implode(',', $pageIds) . ')' | |
); | |
if (count($childRows) > 0) { | |
foreach ($childRows as $row) { | |
$childPages[] = $row['uid']; | |
} | |
$childPages = $this->getAllChildren($childPages); | |
} | |
return array_merge($pageIds, $childPages); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugin.tx_solr.index.queue.pages { | |
# Excludes disabled trees recursively | |
initialization = \Vendor\MyExt\Solr\IndexQueue\Initializer\PageInitializer | |
indexer = \Vendor\MyExt\Solr\IndexQueue\PageIndexer | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment