protected function deleteDocument() { $documentUid = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('delete_uid'); $documentType = \TYPO3\CMS\Core\Utility\GeneralUtility::_POST('delete_type'); $message = 'Document(s) with type ' . $documentType . ' and id ' . $documentUid . ' deleted'; $severity = t3lib_FlashMessage::OK; if (empty($documentUid) || empty($documentType)) { $message = 'Missing uid or type to delete documents.'; $severity = t3lib_FlashMessage::ERROR; } else { try { $uids = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $documentUid); $uidCondition = implode(' OR ', $uids); $solrServers = $this->connectionManager->getConnectionsBySite($this->site); foreach ($solrServers as $solrServer) { $response = $solrServer->deleteByQuery('uid:(' . $uidCondition . ')' . ' AND type:' . $documentType . ' AND siteHash:' . $this->site->getSiteHash()); $solrServer->commit(FALSE, FALSE, FALSE); if ($response->getHttpStatus() != 200) { throw new RuntimeException('Delete Query failed.', 1332250835); } } } catch (Exception $e) { $message = $e->getMessage(); $severity = t3lib_FlashMessage::ERROR; } } $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_FlashMessage', $message, '', $severity); t3lib_FlashMessageQueue::addMessage($flashMessage); }
/** * Gets the pages in a site plus additional pages that may have been * configured. * * @return array A (sorted) array of page IDs in a site */ protected function getPages() { $pages = $this->site->getPages(); $additionalPageIds = array(); if (!empty($this->indexingConfiguration['additionalPageIds'])) { $additionalPageIds = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $this->indexingConfiguration['additionalPageIds']); } $pages = array_merge($pages, $additionalPageIds); sort($pages, SORT_NUMERIC); return $pages; }
/** * Gets the pages in a site plus additional pages that may have been * configured. * * @return array A (sorted) array of page IDs in a site */ protected function getPages() { $pages = $this->site->getPages(); $additionalPageIds = array(); if (!empty($this->indexingConfiguration['additionalPageIds'])) { $additionalPageIds = t3lib_div::intExplode(',', $this->indexingConfiguration['additionalPageIds']); } $pages = array_merge($pages, $additionalPageIds); sort($pages, SORT_NUMERIC); return $pages; }
/** * This method is designed to return some additional information about the task, * that may help to set it apart from other tasks from the same class * This additional information is used - for example - in the Scheduler's BE module * This method should be implemented in most task classes * * @return string Information to display */ public function getAdditionalInformation() { $information = ''; if ($this->site) { $information = 'Site: ' . $this->site->getLabel(); } if (!empty($this->indexingConfigurationsToReIndex)) { $information .= ', Indexing Configurations: ' . implode(', ', $this->indexingConfigurationsToReIndex); } return $information; }
/** * Checks any additional data that is relevant to this task. If the task * class is not relevant, the method is expected to return TRUE * * @param array $submittedData: reference to the array containing the data submitted by the user * @param tx_scheduler_module1 $parentObject: reference to the calling object (Scheduler's BE module) * @return boolean True if validation was ok (or selected class is not relevant), FALSE otherwise */ public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $schedulerModule) { $result = FALSE; // validate site $sites = Tx_Solr_Site::getAvailableSites(); if (array_key_exists($submittedData['site'], $sites)) { $result = TRUE; } // escape limit $submittedData['documentsToIndexLimit'] = intval($submittedData['documentsToIndexLimit']); return $result; }
/** * Gets the indexing progress. * * @return float Indexing progress as a two decimal precision float. f.e. 44.87 */ public function getProgress() { $itemsIndexedPercentage = 0.0; $totalItemsCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'tx_solr_indexqueue_item', 'root = ' . $this->site->getRootPageId()); $remainingItemsCount = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid', 'tx_solr_indexqueue_item', 'changed > indexed AND root = ' . $this->site->getRootPageId()); $itemsIndexedCount = $totalItemsCount - $remainingItemsCount; if ($totalItemsCount > 0) { $itemsIndexedPercentage = $itemsIndexedCount * 100 / $totalItemsCount; $itemsIndexedPercentage = round($itemsIndexedPercentage, 2); } return $itemsIndexedPercentage; }
public function render() { $this->tag->addAttribute('onchange', 'jumpToUrl(document.URL + \'&tx_solr_tools_solradministration[action]=setSite&tx_solr_tools_solradministration[site]=\'+this.options[this.selectedIndex].value,this);'); $sites = \Tx_Solr_Site::getAvailableSites(); $currentSite = $this->moduleDataStorageService->loadModuleData()->getSite(); $options = ''; foreach ($sites as $site) { $selectedAttribute = ''; if ($site == $currentSite) { $selectedAttribute = ' selected="selected"'; } $options .= '<option value="' . $site->getRootPageId() . '"' . $selectedAttribute . '>' . $site->getLabel() . '</option>'; } $this->tag->setContent($options); return '<div class="docheader-funcmenu siteSelector"><label>Site: </label>' . $this->tag->render() . '</div>'; }
/** * Builds a map of indexing configuration names to tables to to index. * * @return array Indexing configuration to database table map */ protected function getIndexQueueConfigurationTableMap() { $indexingTableMap = array(); $solrConfiguration = \Tx_Solr_Util::getSolrConfigurationFromPageId($this->site->getRootPageId()); foreach ($solrConfiguration['index.']['queue.'] as $name => $configuration) { if (is_array($configuration)) { $name = substr($name, 0, -1); if ($solrConfiguration['index.']['queue.'][$name]) { $table = $name; if ($solrConfiguration['index.']['queue.'][$name . '.']['table']) { $table = $solrConfiguration['index.']['queue.'][$name . '.']['table']; } $indexingTableMap[$name] = $table; } } } return $indexingTableMap; }
/** * Gets $limit number of items to index for a particular $site. * * @param Tx_Solr_Site $site TYPO3 site * @param integer $limit Number of items to get from the queue * @return Tx_Solr_IndexQueue_Item[] Items to index to the given solr server */ public function getItemsToIndex(Tx_Solr_Site $site, $limit = 50) { $itemsToIndex = array(); // determine which items to index with this run $indexQueueItemRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_solr_indexqueue_item', 'root = ' . $site->getRootPageId() . ' AND changed > indexed' . ' AND changed <= ' . time() . ' AND errors = \'\'', '', 'indexing_priority DESC, changed DESC, uid DESC', intval($limit)); if (!empty($indexQueueItemRecords)) { // convert queued records to index queue item objects $itemsToIndex = $this->getIndexQueueItemObjectsFromRecords($indexQueueItemRecords); } return $itemsToIndex; }
/** * Builds the Solr document for the current page. * * @return Apache_Solr_Document A document representing the page */ protected function getPageDocument() { $document = GeneralUtility::makeInstance('Apache_Solr_Document'); /* @var $document Apache_Solr_Document */ $site = Tx_Solr_Site::getSiteByPageId($this->page->id); $pageRecord = $this->page->page; self::$pageSolrDocumentId = $documentId = Tx_Solr_Util::getPageDocumentId($this->page->id, $this->page->type, $this->page->sys_language_uid, $this->getDocumentIdGroups()); $document->setField('id', $documentId); $document->setField('site', $site->getDomain()); $document->setField('siteHash', $site->getSiteHash()); $document->setField('appKey', 'EXT:solr'); $document->setField('type', 'pages'); // system fields $document->setField('uid', $this->page->id); $document->setField('pid', $pageRecord['pid']); $document->setField('typeNum', $this->page->type); $document->setField('created', $pageRecord['crdate']); $document->setField('changed', $pageRecord['tstamp']); $document->setField('rootline', $this->page->id); // access $document->setField('access', (string) $this->pageAccessRootline); if ($this->page->page['endtime']) { $document->setField('endtime', $pageRecord['endtime']); } // content $document->setField('title', $this->contentExtractor->getPageTitle()); $document->setField('subTitle', $pageRecord['subtitle']); $document->setField('navTitle', $pageRecord['nav_title']); $document->setField('author', $pageRecord['author']); $document->setField('description', $pageRecord['description']); $document->setField('abstract', $pageRecord['abstract']); $document->setField('content', $this->contentExtractor->getIndexableContent()); $document->setField('url', $this->pageUrl); // keywords, multi valued $keywords = array_unique(GeneralUtility::trimExplode(',', $pageRecord['keywords'], TRUE)); foreach ($keywords as $keyword) { $document->addField('keywords', $keyword); } // content from several tags like headers, anchors, ... $tagContent = $this->contentExtractor->getTagContent(); foreach ($tagContent as $fieldName => $fieldValue) { $document->setField($fieldName, $fieldValue); } return $document; }
/** * Queries Solr for the current page's documents. * * @return array An array of Apache_Solr_Document objects */ protected function getIndexDocuments() { $query = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_Query', ''); $query->setQueryType('standard'); $query->useRawQueryString(TRUE); $query->setQueryString('*:*'); $query->addFilter('(type:pages AND uid:' . $this->pageId . ') OR (*:* AND pid:' . $this->pageId . ' NOT type:pages)'); $query->addFilter('siteHash:' . Tx_Solr_Site::getSiteByPageId($this->pageId)->getSiteHash()); $query->setFieldList('*'); $query->setSorting('type asc, title asc'); $this->search->search($query); return $this->search->getResultDocuments(); }
/** * Checks any additional data that is relevant to this task. If the task * class is not relevant, the method is expected to return TRUE * * @param array $submittedData: reference to the array containing the data submitted by the user * @param SchedulerModuleController $schedulerModule: reference to the calling object (Scheduler's BE module) * @return boolean True if validation was ok (or selected class is not relevant), FALSE otherwise */ public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule) { $result = FALSE; // validate site $sites = Tx_Solr_Site::getAvailableSites(); if (array_key_exists($submittedData['site'], $sites)) { $result = TRUE; } return $result; }
/** * Sets the site to work with * * @param integer $site Site root page id * @return void */ public function setSiteAction($site) { $site = \Tx_Solr_Site::getSiteByPageId((int) $site); $this->moduleData->setSite($site); // when switching the site, reset the core $this->moduleData->setCore(''); $this->moduleDataStorageService->persistModuleData($this->moduleData); $this->forwardHome(); }
/** * Finds the alternative page language overlay records for a page based on * the sys_language_mode. * * Possible Language Modes: * 1) content_fallback --> all languages * 2) strict --> available languages with page overlay * 3) ignore --> available languages with page overlay * 4) unknown mode or blank --> all languages * * @param integer $pageId Page ID. * @return array An array of translation overlays (or fake overlays) found for the given page. */ protected function getTranslationOverlaysForPage($pageId) { $translationOverlays = array(); $pageId = intval($pageId); $site = Tx_Solr_Site::getSiteByPageId($pageId); $languageModes = array('content_fallback', 'strict', 'ignore'); $hasOverlayMode = in_array($site->getSysLanguageMode(), $languageModes, TRUE); $isContentFallbackMode = $site->getSysLanguageMode() === 'content_fallback'; if ($hasOverlayMode && !$isContentFallbackMode) { $translationOverlays = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid, sys_language_uid', 'pages_language_overlay', 'pid = ' . $pageId . t3lib_BEfunc::deleteClause('pages_language_overlay') . t3lib_BEfunc::BEenableFields('pages_language_overlay')); } else { // ! If no sys_language_mode is configured, all languages will be indexed ! $languages = t3lib_BEfunc::getSystemLanguages(); // remove default language (L = 0) array_shift($languages); foreach ($languages as $language) { $translationOverlays[] = array('pid' => $pageId, 'sys_language_uid' => $language[1]); } } return $translationOverlays; }
/** * Gets all connection configurations for a given site. * * @param Tx_Solr_Site $site A TYPO3 site * @return array An array of Solr connection configurations for a site */ public function getConfigurationsBySite(Tx_Solr_Site $site) { $solrConfigurations = array(); $allConfigurations = $this->getAllConfigurations(); foreach ($allConfigurations as $configuration) { if ($configuration['rootPageUid'] == $site->getRootPageId()) { $solrConfigurations[] = $configuration; } } return $solrConfigurations; }
/** * Adds a page to the Index Queue of a site mounting the page. * * @param integer $mountedPageId ID (uid) of the mounted page. * @param array $mountProperties Array of mount point properties mountPageSource, mountPageDestination, and mountPageOverlayed */ protected function addPageToMountingSiteIndexQueue($mountedPageId, array $mountProperties) { $mountingSite = Tx_Solr_Site::getSiteByPageId($mountProperties['mountPageDestination']); $pageInitializer = t3lib_div::makeInstance('Tx_Solr_IndexQueue_Initializer_Page'); $pageInitializer->setSite($mountingSite); $pageInitializer->initializeMountedPage($mountProperties, $mountedPageId); }
/** * Gets all the pages from a mounted page tree. * * @param integer $mountPageSourceId * @return array An array of page IDs in the mounted page tree */ protected function resolveMountPageTree($mountPageSourceId) { $mountedSite = Tx_Solr_Site::getSiteByPageId($mountPageSourceId); return $mountedSite->getPages($mountPageSourceId); }
/** * Adds a page to the Index Queue of a site mounting the page. * * @param integer $mountedPageId ID (uid) of the mounted page. * @param array $mountProperties Array of mount point properties mountPageSource, mountPageDestination, and mountPageOverlayed */ protected function addPageToMountingSiteIndexQueue($mountedPageId, array $mountProperties) { $mountingSite = Tx_Solr_Site::getSiteByPageId($mountProperties['mountPageDestination']); $pageInitializer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Solr_IndexQueue_Initializer_Page'); $pageInitializer->setSite($mountingSite); $pageInitializer->initializeMountedPage($mountProperties, $mountedPageId); }
/** * Initializes resources commonly needed for several actions * * @return void */ protected function initializeAction() { try { $site = $this->request->getArgument('site'); if (is_numeric($site)) { $siteRootPageId = $this->request->getArgument('site'); $this->site = \Tx_Solr_Site::getSiteByPageId($siteRootPageId); } else { if ($site instanceof \Tx_Solr_Site) { $this->site = $site; } } } catch (NoSuchArgumentException $nsae) { $sites = \Tx_Solr_Site::getAvailableSites(); $site = array_shift($sites); $this->site = $site; } $this->request->setArgument('site', $this->site); $moduleData = $this->moduleDataStorageService->loadModuleData(); $moduleData->setSite($this->site); $this->moduleDataStorageService->persistModuleData($moduleData); }
/** * Resolves magic keywords in allowed sites configuration. * Supported keywords: * __solr_current_site - The domain of the site the query has been started from * __current_site - Same as __solr_current_site * __all - Adds all domains as allowed sites * * - Same as __all * * @param integer $pageId A page ID that is then resolved to the site it belongs to * @param string $allowedSitesConfiguration TypoScript setting for allowed sites * @return string List of allowed sites/domains, magic keywords resolved */ public static function resolveSiteHashAllowedSites($pageId, $allowedSitesConfiguration) { if ($allowedSitesConfiguration == '*' || $allowedSitesConfiguration == '__all') { $sites = Tx_Solr_Site::getAvailableSites(); $domains = array(); foreach ($sites as $site) { $domains[] = $site->getDomain(); } $allowedSites = implode(',', $domains); } else { $allowedSites = str_replace(array('__solr_current_site', '__current_site'), Tx_Solr_Site::getSiteByPageId($pageId)->getDomain(), $allowedSitesConfiguration); } return $allowedSites; }