diff --git a/Document/Index/ArticleIndexer.php b/Document/Index/ArticleIndexer.php index 4bcf3879..fd7492a1 100644 --- a/Document/Index/ArticleIndexer.php +++ b/Document/Index/ArticleIndexer.php @@ -459,6 +459,8 @@ public function replaceWithGhostData(ArticleDocument $document, string $locale): $search = $repository->createSearch(); $search->addQuery(new TermQuery('localization_state.state', 'ghost'), BoolQuery::MUST); $search->addQuery(new TermQuery('localization_state.locale', $locale), BoolQuery::MUST); + $search->addQuery(new TermQuery('locale', $locale), BoolQuery::MUST_NOT); + $search->addQuery(new TermQuery('uuid', $document->getUuid()), BoolQuery::MUST); /** @var array $searchResult */ $searchResult = $repository->findArray($search); diff --git a/Tests/Functional/Document/Index/ArticleIndexerTest.php b/Tests/Functional/Document/Index/ArticleIndexerTest.php index e5bc1eb2..7273b082 100644 --- a/Tests/Functional/Document/Index/ArticleIndexerTest.php +++ b/Tests/Functional/Document/Index/ArticleIndexerTest.php @@ -19,6 +19,7 @@ use Sulu\Bundle\MediaBundle\Content\Types\ImageMapContentType; use Sulu\Bundle\PageBundle\Document\PageDocument; use Sulu\Bundle\RouteBundle\Entity\RouteRepositoryInterface; +use Sulu\Bundle\TestBundle\Testing\SetGetPrivatePropertyTrait; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; use Sulu\Component\Content\Document\LocalizationState; use Sulu\Component\DocumentManager\DocumentManagerInterface; @@ -26,6 +27,8 @@ class ArticleIndexerTest extends SuluTestCase { + use SetGetPrivatePropertyTrait; + /** * @var string */ @@ -121,6 +124,32 @@ public function testReplaceWithGhostData() 'default_with_route' ); + $otherArticle = $this->createArticle( + [ + 'article' => 'Other content', + ], + 'Other Article', + 'default_with_route' + ); + + $articleDocumentUuid = $article['id']; + + $documentDE = $this->findViewDocument($articleDocumentUuid, 'de'); + $documentEN = $this->findViewDocument($articleDocumentUuid, 'en'); + $documentFR = $this->findViewDocument($articleDocumentUuid, 'fr'); + + $this->assertSame('Test Article', $documentEN->getTitle()); + $this->assertSame('localized', $documentEN->getLocalizationState()->state); + $this->assertNull($documentEN->getLocalizationState()->locale); + + $this->assertSame('Test Article', $documentDE->getTitle()); + $this->assertSame('ghost', $documentDE->getLocalizationState()->state); + $this->assertSame('en', $documentDE->getLocalizationState()->locale); + + $this->assertSame('Test Article', $documentFR->getTitle()); + $this->assertSame('ghost', $documentFR->getLocalizationState()->state); + $this->assertSame('en', $documentFR->getLocalizationState()->locale); + $secondLocale = 'de'; // now add second locale @@ -134,20 +163,54 @@ public function testReplaceWithGhostData() 'Test Artikel Deutsch', 'default_with_route' ); + $this->updateArticle( + $otherArticle['id'], + $secondLocale, + [ + 'id' => $otherArticle['id'], + 'article' => 'Anderer Inhalt', + ], + 'Anderer Artikel Deutsch', + 'default_with_route' + ); /** @var ArticleDocument $articleDocument */ $articleDocument = $this->documentManager->find($article['id']); + /** @var ArticleDocument $otherDocument */ + $otherDocument = $this->documentManager->find($otherArticle['id']); + static::setPrivateProperty($otherDocument, 'originalLocale', 'de'); // to reproduce https://github.com/sulu/SuluArticleBundle/pull/677 correctly + $this->indexer->replaceWithGhostData($articleDocument, 'de'); + $this->indexer->replaceWithGhostData($otherDocument, 'en'); + $this->indexer->flush(); - $documentDE = $this->findViewDocument($articleDocument->getUuid(), 'de'); $documentEN = $this->findViewDocument($articleDocument->getUuid(), 'en'); + $documentDE = $this->findViewDocument($articleDocument->getUuid(), 'de'); + $documentFR = $this->findViewDocument($articleDocument->getUuid(), 'fr'); + + $this->assertSame('localized', $documentEN->getLocalizationState()->state); + $this->assertNull($documentEN->getLocalizationState()->locale); - $this->assertSame('Test Article', $documentDE->getTitle()); $this->assertSame('ghost', $documentDE->getLocalizationState()->state); $this->assertSame('en', $documentDE->getLocalizationState()->locale); - $this->assertSame('Test Article', $documentEN->getTitle()); + $this->assertSame('ghost', $documentFR->getLocalizationState()->state); + $this->assertSame('en', $documentFR->getLocalizationState()->locale); + + /** @var ArticleDocument $otherDocument */ + $otherDocumentEN = $this->findViewDocument($otherDocument->getUuid(), 'en'); + $otherDocumentDE = $this->findViewDocument($otherDocument->getUuid(), 'de'); + $otherDocumentFR = $this->findViewDocument($otherDocument->getUuid(), 'fr'); + + $this->assertSame('localized', $otherDocumentDE->getLocalizationState()->state); + $this->assertNull($otherDocumentDE->getLocalizationState()->locale); + + $this->assertSame('ghost', $otherDocumentEN->getLocalizationState()->state); + $this->assertSame('de', $otherDocumentEN->getLocalizationState()->locale); + + $this->assertSame('ghost', $otherDocumentFR->getLocalizationState()->state); + $this->assertSame('de', $otherDocumentFR->getLocalizationState()->locale); } public function testReplaceWithGhostDataUpdateExistingGhosts()