/** * Generates the headers to be send with the request. * * @return array Array of HTTP headers. */ public function getHeaders() { $headers = $this->header; $headers[] = TYPO3_user_agent; $itemId = $this->indexQueueItem->getIndexQueueUid(); $indexerRequestData = array('requestId' => $this->requestId, 'item' => $itemId, 'actions' => implode(',', $this->actions), 'hash' => md5($itemId . '|' . $pageId . '|' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])); $indexerRequestData = array_merge($indexerRequestData, $this->parameters); $headers[] = 'X-Tx-Solr-Iq: ' . json_encode($indexerRequestData); if (!empty($this->username) && !empty($this->password)) { $headers[] = 'Authorization: Basic ' . base64_encode($this->username . ':' . $this->password); } return $headers; }
/** * Finds the FE user groups used on a page including all groups of content * elements and groups of records of extensions that have correctly been * pushed through tslib_cObj during rendering. * * @param Tx_Solr_IndexQueue_Item $item Index queue item representing the current page to get the user groups from * @param integer $language The sys_language_uid language ID * @return array Array of user group IDs */ protected function getAccessGroupsFromContent(Tx_Solr_IndexQueue_Item $item, $language = 0) { static $accessGroupsCache; $accessGroupsCacheEntryId = $item->getRecordUid() . '|' . $language; if (!isset($accessGroupsCache[$accessGroupsCacheEntryId])) { $request = $this->buildBasePageIndexerRequest(); $request->setIndexQueueItem($item); $request->addAction('findUserGroups'); $indexRequestUrl = $this->getDataUrl($item, $language); $response = $request->send($indexRequestUrl); $groups = $response->getActionResult('findUserGroups'); if (is_array($groups)) { $accessGroupsCache[$accessGroupsCacheEntryId] = $groups; } if ($this->loggingEnabled) { t3lib_div::devLog('Page Access Groups', 'solr', 0, array('item' => (array) $item, 'language' => $language, 'index request url' => $indexRequestUrl, 'request' => (array) $request, 'response' => (array) $response, 'groups' => $groups)); } } return $accessGroupsCache[$accessGroupsCacheEntryId]; }
/** * Logs the item and what document was created from it * * @param Tx_Solr_IndexQueue_Item The item that is being indexed. * @param array An array of Solr documents created from the item's data * @param Apache_Solr_Response The Solr response for the particular index document */ protected function log(Tx_Solr_IndexQueue_Item $item, array $itemDocuments, Apache_Solr_Response $response) { if (!$this->loggingEnabled) { return; } $message = 'Index Queue indexing ' . $item->getType() . ':' . $item->getRecordUid() . ' - '; $severity = 0; // info // preparing data $documents = array(); foreach ($itemDocuments as $document) { $documents[] = (array) $document; } $logData = array('item' => (array) $item, 'documents' => $documents, 'response' => (array) $response); if ($response->getHttpStatus() == 200) { $severity = -1; $message .= 'Success'; } else { $severity = 3; $message .= 'Failure'; $logData['status'] = $response->getHttpStatus(); $logData['status message'] = $response->getHttpStatusMessage(); } \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($message, 'solr', $severity, $logData); }
/** * Marks an item as failed and causes the indexer to skip the item in the * next run. * * @param int|Tx_Solr_IndexQueue_Item $item Either the item's Index Queue * uid or the complete item * @param string $errorMessage Error message */ public function markItemAsFailed($item, $errorMessage = '') { $itemUid = 0; if ($item instanceof Tx_Solr_IndexQueue_Item) { $itemUid = $item->getIndexQueueUid(); } else { $itemUid = (int) $item; } if (empty($errorMessage)) { // simply set to "TRUE" $errorMessage = '1'; } $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_solr_indexqueue_item', 'uid = ' . $itemUid, array('errors' => $errorMessage)); }
/** * Initializes the $_SERVER['HTTP_HOST'] environment variable in CLI * environments dependent on the Index Queue item's root page. * * When the Index Queue Worker task is executed by a cron job there is no * HTTP_HOST since we are in a CLI environment. RealURL needs the host * information to generate a proper URL though. Using the Index Queue item's * root page information we can determine the correct host although being * in a CLI environment. * * @param Tx_Solr_IndexQueue_Item $item Index Queue item to use to determine the host. */ protected function initializeHttpHost(Tx_Solr_IndexQueue_Item $item) { static $hosts = array(); // relevant for realURL environments, only if (t3lib_extMgm::isLoaded('realurl')) { $rootpageId = $item->getRootPageUid(); $hostFound = !empty($hosts[$rootpageId]); if (!$hostFound) { $rootline = t3lib_BEfunc::BEgetRootLine($rootpageId); $host = t3lib_BEfunc::firstDomainRecord($rootline); $hosts[$rootpageId] = $host; } $_SERVER['HTTP_HOST'] = $hosts[$rootpageId]; } }