Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix indexer replace-ghost-content query #677

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading