BUGFIX: Remove records during update if no longer available

E.g. update is to deactivate a record. In this case we will not be able
to update the record but should delete him instead.
This commit is contained in:
Daniel Siepmann 2017-11-10 13:47:26 +01:00
parent ea8eb8148e
commit 0815eaff6b
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
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); $this->connection->addDocument($this->getDocumentName(), $record);
} catch (NoRecordFoundException $e) { } 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'); $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.' '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.');
}
} }