Merge pull request #100 from Codappix/hotfix/if-record-can-not-be-updated-delete-it-instead

BUGFIX: Remove records during update if no longer available
This commit is contained in:
Daniel Siepmann 2017-11-10 22:04:48 +01:00 committed by GitHub
commit 1840eba07b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View file

@ -99,7 +99,8 @@ abstract class AbstractIndexer implements IndexerInterface
$this->connection->addDocument($this->getDocumentName(), $record);
} catch (NoRecordFoundException $e) {
$this->logger->info('Could not index document.', [$e->getMessage()]);
$this->logger->info('Could not index document. Try to delete it therefore.', [$e->getMessage()]);
$this->connection->deleteDocument($this->getDocumentName(), $identifier);
}
$this->logger->info('Finish indexing');
}

View file

@ -205,4 +205,35 @@ class IndexTcaTableTest extends AbstractFunctionalTestCase
'Record was indexed with resolved category relation, but should not have any.'
);
}
/**
* @test
*/
public function indexingDeltedRecordIfRecordShouldBeIndexedButIsNoLongerAvailableAndWasAlreadyIndexed()
{
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
->get(IndexerFactory::class)
->getIndexer('tt_content')
->indexAllDocuments()
;
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 2, 'Not exactly 2 documents were indexed.');
$this->getConnectionPool()->getConnectionForTable('tt_content')
->update(
'tt_content',
['hidden' => true],
['uid' => 10]
);
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(ObjectManager::class)
->get(IndexerFactory::class)
->getIndexer('tt_content')
->indexDocument(10)
;
$response = $this->client->request('typo3content/_search?q=*:*');
$this->assertSame($response->getData()['hits']['total'], 1, 'Not exactly 1 document is in index.');
}
}