Skip to content

Commit

Permalink
Fix indexer replace-ghost-content query (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quehnie authored Jun 7, 2024
1 parent 8abc1e8 commit 797253f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Document/Index/ArticleIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<array{locale: string}> $searchResult */
$searchResult = $repository->findArray($search);
Expand Down
69 changes: 66 additions & 3 deletions Tests/Functional/Document/Index/ArticleIndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
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;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;

class ArticleIndexerTest extends SuluTestCase
{
use SetGetPrivatePropertyTrait;

/**
* @var string
*/
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 797253f

Please sign in to comment.