Created
December 9, 2014 09:44
-
-
Save htuscher/27cfd99dedc28e531271 to your computer and use it in GitHub Desktop.
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; | |
class PageIndexer extends \Tx_Solr_IndexQueue_PageIndexer | |
{ | |
/** | |
* @param \Tx_Solr_IndexQueue_Item $item | |
* | |
* @return bool | |
*/ | |
protected function isPageIndexable(\Tx_Solr_IndexQueue_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) { | |
$result = FALSE; | |
/** @var \TYPO3\CMS\Core\Database\DatabaseConnection $db */ | |
$db = $GLOBALS['TYPO3_DB']; | |
$row = $db->exec_SELECTgetSingleRow('uid,pid,hidden,nav_hide', 'pages', 'uid = ' . $uid); | |
if (!is_null($row)) { | |
if ($row['hidden'] == 1) { | |
$result = TRUE; | |
} elseif ($row['nav_hide'] == 1) { | |
$result = TRUE; | |
} else { | |
$result = $this->isDisabledRecordInRootline($row['pid']); | |
} | |
} | |
return $result; | |
} | |
} |
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; | |
class PageInitializer extends \Tx_Solr_IndexQueue_Initializer_Page { | |
/** | |
* Initializes Index Queue page items for a site. Includes regular pages | |
* and mounted pages - no nested mount page structures though. | |
* | |
* @return boolean TRUE if initialization was successful, FALSE on error. | |
* @see \Tx_Solr_IndexQueue_initializer_Abstract::initialize() | |
* @see \Tx_Solr_IndexQueueInitializer::initialize() | |
*/ | |
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 = array(); | |
/** @var \TYPO3\CMS\Core\Database\DatabaseConnection $db */ | |
$db = $GLOBALS['TYPO3_DB']; | |
$rows = $db->exec_SELECTgetRows('uid', 'pages', '(hidden = 1 OR nav_hide = 1) AND deleted = 0'); | |
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; | |
} | |
protected function getAllChildren($pageIds) { | |
$childPages = array(); | |
/** @var \TYPO3\CMS\Core\Database\DatabaseConnection $db */ | |
$db = $GLOBALS['TYPO3_DB']; | |
$childRows = $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