/**
  * @test
  */
 public function canTriggerFrontendIndexingAndMarkQueueEntryAsProcessed()
 {
     $this->importDataSetFromFixture('can_trigger_frontend_calls_for_page_index.xml');
     // we expect that the index queue is empty before we start
     $this->assertFalse($this->indexQueue->containsIndexedItem('pages', 1));
     /** @var $beUser  \TYPO3\CMS\Core\Authentication\BackendUserAuthentication */
     $beUser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
     $GLOBALS['BE_USER'] = $beUser;
     /** @var $languageService  \TYPO3\CMS\Lang\LanguageService */
     $languageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Lang\\LanguageService');
     $GLOBALS['LANG'] = $languageService;
     $charsetConverter = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter');
     $GLOBALS['LANG']->csConvObj = $charsetConverter;
     $site = Site::getFirstAvailableSite();
     /** @var $indexQueueQueueWorkerTask \ApacheSolrForTypo3\Solr\Task\IndexQueueWorkerTask */
     $indexQueueQueueWorkerTask = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Task\\IndexQueueWorkerTask');
     $indexQueueQueueWorkerTask->setDocumentsToIndexLimit(1);
     $indexQueueQueueWorkerTask->setSite($site);
     $progressBefore = $indexQueueQueueWorkerTask->getProgress();
     $indexQueueQueueWorkerTask->execute();
     $progressAfter = $indexQueueQueueWorkerTask->getProgress();
     // we expect that the index queue is empty before we start
     $this->assertTrue($this->indexQueue->containsIndexedItem('pages', 1));
     $this->assertEquals(0.0, $progressBefore, 'Wrong progress before');
     $this->assertEquals(100.0, $progressAfter, 'Wrong progress after');
 }
Beispiel #2
0
 /**
  * Triggers Index Queue updates for other pages showing content from the
  * page currently being updated.
  *
  * @param integer $pageId UID of the page currently being updated
  */
 protected function updateCanonicalPages($pageId)
 {
     $canonicalPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'content_from_pid = ' . $pageId . BackendUtility::deleteClause('pages'));
     foreach ($canonicalPages as $page) {
         $this->indexQueue->updateItem('pages', $page['uid']);
     }
 }
Beispiel #3
0
 /**
  * Retrieves the name of the  Indexing Queue Configuration for a record
  *
  * @param string $recordTable Table to read from
  * @param int $recordUid Id of the record
  * @return string Name of indexing configuration
  */
 protected function getIndexingConfigurationName($recordTable, $recordUid)
 {
     $name = $recordTable;
     $indexingConfigurations = $this->indexQueue->getTableIndexingConfigurations($this->solrConfiguration);
     foreach ($indexingConfigurations as $indexingConfigurationName) {
         $tableToIndex = $indexingConfigurationName;
         if (!$this->solrConfiguration['index.']['queue.'][$indexingConfigurationName]) {
             // ignore disabled indexing configurations
             continue;
         }
         if (!empty($this->solrConfiguration['index.']['queue.'][$indexingConfigurationName . '.']['table'])) {
             // table has been set explicitly. Allows to index the same table with different configurations
             $tableToIndex = $this->solrConfiguration['index.']['queue.'][$indexingConfigurationName . '.']['table'];
         }
         if ($tableToIndex === $recordTable) {
             $recordWhereClause = $this->buildUserWhereClause($indexingConfigurationName);
             $record = BackendUtility::getRecord($recordTable, $recordUid, '*', $recordWhereClause);
             if (!empty($record)) {
                 // we found a record which matches the conditions
                 $name = $indexingConfigurationName;
                 // FIXME currently returns after the first configuration match
                 break;
             }
         }
     }
     return $name;
 }
Beispiel #4
0
 /**
  * @test
  */
 public function canNotAddUnAllowedPageType()
 {
     $this->importDataSetFromFixture('can_not_add_unallowed_pagetype.xml');
     $this->assertEmptyQueue();
     // record does not exist in fixture
     $this->indexQueue->updateItem('pages', 22);
     // queue should still be empty
     $this->assertEmptyQueue();
 }
Beispiel #5
0
 /**
  * @param string $table
  * @param int $uid
  * @return \Apache_Solr_Response
  */
 protected function addToQueueAndIndexRecord($table, $uid)
 {
     // write an index queue item
     $this->indexQueue->updateItem($table, $uid);
     // run the indexer
     $items = $this->indexQueue->getItems($table, $uid);
     foreach ($items as $item) {
         $result = $this->indexer->index($item);
     }
     return $result;
 }
Beispiel #6
0
 /**
  * In this testcase we check if the pages queue will be initialized as expected
  * when we have a page with mounted pages
  *
  *
  *      1
  *      |
  *      ------- 10 (Mounted)
  *                        |
  *                         ------------ 20 (Childpage of mountpoint)
  *
  * @test
  */
 public function initializerIsFillingQueueWithMountPages()
 {
     $this->importDataSetFromFixture('can_add_mount_pages.xml');
     $this->assertEmptyQueue();
     $this->initializePageIndexQueue();
     $this->assertItemsInQueue(4);
     // @todo: verify, is this really as expected? since mount_pid_ol is not set
     // in the case when mount_pid_ol is set 4 pages get added
     $this->assertTrue($this->indexQueue->containsItem('pages', 1));
     $this->assertTrue($this->indexQueue->containsItem('pages', 10));
     $this->assertTrue($this->indexQueue->containsItem('pages', 20));
     $this->assertFalse($this->indexQueue->containsItem('pages', 2));
 }
Beispiel #7
0
 /**
  * @test
  */
 public function solrIsEmptyAfterCleanup()
 {
     $this->importDataSetFromFixture('can_reindex_task_fill_queue.xml');
     // fill the solr
     $site = Site::getFirstAvailableSite();
     $this->indexQueue->updateItem('pages', 1);
     $items = $this->indexQueue->getItems('pages', 1);
     /** @var $indexer \ApacheSolrForTypo3\Solr\IndexQueue\Indexer */
     $indexer = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\IndexQueue\\Indexer');
     $indexer->index($items[0]);
     sleep(2);
     $this->assertSolrContainsDocumentCount(1);
     $this->task->setSite($site);
     $this->task->setIndexingConfigurationsToReIndex(array('pages'));
     $this->task->execute();
     sleep(2);
     // after the task was running the solr server should be empty
     $this->assertSolrIsEmpty();
     // if not we cleanup now
     $this->cleanUpSolrServerAndAssertEmpty();
 }
 /**
  * Regression test for issue #48. Indexing of new records will crash if the name of the Indexing
  * Queue Configuration is different from tablename
  * @see https://github.com/TYPO3-Solr/ext-solr/issues/48
  * @test
  */
 public function canUseCorrectIndexingConfigurationForANewNonPagesRecord()
 {
     // create fake extension database table and TCA
     $this->importDumpFromFixture('fake_extension_table.sql');
     $GLOBALS['TCA']['tx_fakeextension_domain_model_foo'] = (include $this->getFixturePath('fake_extension_tca.php'));
     // create faked tce main call data
     $status = 'new';
     $table = 'tx_fakeextension_domain_model_foo';
     $uid = 'NEW566a9eac309d8193936351';
     $fields = array('title' => 'testnews', 'pid' => 1, 'starttime' => 1000000, 'endtime' => 1100000, 'tsstamp' => 1000000);
     $this->dataHandler->substNEWwithIDs = array('NEW566a9eac309d8193936351' => 8);
     $this->importDataSetFromFixture('new_non_pages_record_is_using_correct_configuration_name.xml');
     // we expect that the index queue is empty before we start
     $this->assertEmptyIndexQueue();
     $this->recordMonitor->processDatamap_afterDatabaseOperations($status, $table, $uid, $fields, $this->dataHandler);
     // we expect to have an index queue item now
     $this->assertNotEmptyIndexQueue();
     // and we check that the record in the queue has the expected configuration name
     $items = $this->indexQueue->getItems('tx_fakeextension_domain_model_foo', 8);
     $this->assertSame(1, count($items));
     $this->assertSame('foo', $items[0]->getIndexingConfigurationName(), 'Item was queued with unexpected configuration');
 }
Beispiel #9
0
 /**
  * Removes documents of the selected types from the index.
  *
  * @return bool TRUE if clean up was successful, FALSE on error
  */
 protected function cleanUpIndex()
 {
     $cleanUpResult = TRUE;
     $solrConfiguration = $this->site->getSolrConfiguration();
     $solrServers = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\ConnectionManager')->getConnectionsBySite($this->site);
     $typesToCleanUp = array();
     foreach ($this->indexingConfigurationsToReIndex as $indexingConfigurationName) {
         $type = Queue::getTableToIndexByIndexingConfigurationName($solrConfiguration, $indexingConfigurationName);
         $typesToCleanUp[] = $type;
     }
     foreach ($solrServers as $solrServer) {
         // make sure not-yet committed documents are removed, too
         $solrServer->commit();
         $deleteQuery = 'type:(' . implode(' OR ', $typesToCleanUp) . ')' . ' AND siteHash:' . $this->site->getSiteHash();
         $solrServer->deleteByQuery($deleteQuery);
         $response = $solrServer->commit(FALSE, FALSE, FALSE);
         if ($response->getHttpStatus() != 200) {
             $cleanUpResult = FALSE;
             break;
         }
     }
     return $cleanUpResult;
 }
Beispiel #10
0
 /**
  * @param string $table
  * @param int $uid
  * @return \Apache_Solr_Response
  */
 protected function addToIndexQueue($table, $uid)
 {
     // write an index queue item
     $this->indexQueue->updateItem($table, $uid, null, time());
 }