コード例 #1
0
ファイル: RecordMonitor.php プロジェクト: hnadler/ext-solr
 /**
  * Hooks into TCE Main and watches all record creations and updates. If it
  * detects that the new/updated record belongs to a table configured for
  * indexing through Solr, we add the record to the index queue.
  *
  * @param string $status Status of the current operation, 'new' or 'update'
  * @param string $table The table the record belongs to
  * @param mixed $uid The record's uid, [integer] or [string] (like 'NEW...')
  * @param array $fields The record's data
  * @param DataHandler $tceMain TYPO3 Core Engine parent object
  * @return void
  */
 public function processDatamap_afterDatabaseOperations($status, $table, $uid, array $fields, DataHandler $tceMain)
 {
     $recordTable = $table;
     $recordUid = $uid;
     $recordPageId = 0;
     if ($status == 'new') {
         $recordUid = $tceMain->substNEWwithIDs[$recordUid];
     }
     if (Util::isDraftRecord($table, $recordUid)) {
         // skip workspaces: index only LIVE workspace
         return;
     }
     if ($status == 'update' && !isset($fields['pid'])) {
         $recordPageId = $tceMain->getPID($recordTable, $recordUid);
         if ($recordTable == 'pages' && Util::isRootPage($recordUid)) {
             $recordPageId = $uid;
         }
     } else {
         $recordPageId = $fields['pid'];
     }
     // when a content element changes we need to updated the page instead
     if ($recordTable == 'tt_content') {
         $recordTable = 'pages';
         $recordUid = $recordPageId;
     }
     $this->solrConfiguration = Util::getSolrConfigurationFromPageId($recordPageId);
     $monitoredTables = $this->getMonitoredTables($recordPageId);
     if (in_array($recordTable, $monitoredTables, true)) {
         $record = $this->getRecord($recordTable, $recordUid);
         if (!empty($record)) {
             // only update/insert the item if we actually found a record
             if (Util::isLocalizedRecord($recordTable, $record)) {
                 // if it's a localization overlay, update the original record instead
                 $recordUid = $record[$GLOBALS['TCA'][$recordTable]['ctrl']['transOrigPointerField']];
                 if ($recordTable == 'pages_language_overlay') {
                     $recordTable = 'pages';
                 }
                 $tableEnableFields = implode(', ', $GLOBALS['TCA'][$recordTable]['ctrl']['enablecolumns']);
                 $l10nParentRecord = BackendUtility::getRecord($recordTable, $recordUid, $tableEnableFields, '', false);
                 if (!$this->isEnabledRecord($recordTable, $l10nParentRecord)) {
                     // the l10n parent record must be visible to have it's translation indexed
                     return;
                 }
             }
             // Clear existing index queue items to prevent mount point duplicates.
             if ($recordTable == 'pages') {
                 $this->indexQueue->deleteItem('pages', $recordUid);
             }
             if ($this->isEnabledRecord($recordTable, $record)) {
                 $configurationName = null;
                 if ($recordTable !== 'pages') {
                     $configurationName = $this->getIndexingConfigurationName($recordTable, $recordUid);
                 }
                 $this->indexQueue->updateItem($recordTable, $recordUid, $configurationName);
             }
             if ($recordTable == 'pages') {
                 $this->updateCanonicalPages($recordUid);
                 $this->updateMountPages($recordUid);
                 if ($this->isRecursiveUpdateRequired($recordUid, $fields)) {
                     $treePageIds = $this->getSubPageIds($recordUid);
                     foreach ($treePageIds as $treePageId) {
                         $this->indexQueue->updateItem('pages', $treePageId);
                     }
                 }
             }
         } else {
             // TODO move this part to the garbage collector
             // check if the item should be removed from the index because it no longer matches the conditions
             if ($this->indexQueue->containsItem($recordTable, $recordUid)) {
                 $this->removeFromIndexAndQueue($recordTable, $recordUid);
             }
         }
     }
 }
コード例 #2
0
ファイル: Queue.php プロジェクト: nxpthx/ext-solr
 /**
  * Adds an item to the index queue.
  *
  * Not meant for public use.
  *
  * @param string $itemType The item's type, usually a table name.
  * @param string $itemUid The item's uid, usually an integer uid, could be a
  *      different value for non-database-record types.
  * @param string $indexingConfiguration The item's indexing configuration to use.
  *      Optional, overwrites existing / determined configuration.
  * @return void
  */
 private function addItem($itemType, $itemUid, $indexingConfiguration)
 {
     $additionalRecordFields = '';
     if ($itemType == 'pages') {
         $additionalRecordFields = ', doktype, uid';
     }
     $record = BackendUtility::getRecord($itemType, $itemUid, 'pid' . $additionalRecordFields);
     if (empty($record) || $itemType == 'pages' && !Util::isAllowedPageType($record)) {
         return;
     }
     if ($itemType == 'pages') {
         $rootPageId = Util::getRootPageId($itemUid);
     } else {
         $rootPageId = Util::getRootPageId($record['pid']);
     }
     if (Util::isRootPage($rootPageId)) {
         $item = array('root' => $rootPageId, 'item_type' => $itemType, 'item_uid' => $itemUid, 'changed' => $this->getItemChangedTime($itemType, $itemUid));
         if (!empty($indexingConfiguration)) {
             $indexingConfigurationList = array($indexingConfiguration);
         } else {
             $indexingConfigurationList = $this->getIndexingConfigurationsByItem($itemType, $itemUid, $rootPageId);
         }
         $solrConfiguration = Util::getSolrConfigurationFromPageId($rootPageId);
         // make a backup of the current item
         $baseItem = $item;
         foreach ($indexingConfigurationList as $indexingConfigurationCurrent) {
             $item = $baseItem;
             $item['indexing_configuration'] = $indexingConfigurationCurrent;
             $addItemToQueue = TRUE;
             // Ensure additionalWhereClause is applied.
             if (!empty($solrConfiguration['index.']['queue.'][$item['indexing_configuration'] . '.']['additionalWhereClause'])) {
                 $indexingConfigurationCheckRecord = BackendUtility::getRecord($itemType, $itemUid, 'pid' . $additionalRecordFields, ' AND ' . $solrConfiguration['index.']['queue.'][$item['indexing_configuration'] . '.']['additionalWhereClause']);
                 if (empty($indexingConfigurationCheckRecord)) {
                     // item does not match the indexing configuration's additionalWhereClause
                     $addItemToQueue = FALSE;
                 }
             }
             if ($addItemToQueue) {
                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_solr_indexqueue_item', $item);
             }
         }
     }
 }