-
Notifications
You must be signed in to change notification settings - Fork 18
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 Unpublising parent pages should include child pages #89
Merged
blueo
merged 9 commits into
silverstripe:3
from
ssmarco:feature/3-remove-children-from-index
Apr 12, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
188f6bd
FIX Unpublising parent pages should include child pages
4109616
MNT: Additional PHPUnit tests
de17f14
FIX Update comments on src/DataObject/DataObjectDocument.php
59a4a5e
Extract to extension for SiteTree related documents
4efcc96
Indexer: Making sure we get the Live version of the DataObject before…
b38d94e
Merge pull request #1 from ssmarco/feature/3-remove-children-extension
de32cd3
Fix linting suppression
a73313a
Indexer additional for published data
ddf1115
Index - Undo versioned check to combine with __unserialise fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true"> | ||
<testsuite name="Default"> | ||
<directory>tests/</directory> | ||
</testsuite> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">src/</directory> | ||
<exclude> | ||
<directory suffix=".php">tests/</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
<?xml version="1.0"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">src/</directory> | ||
</include> | ||
<exclude> | ||
<directory suffix=".php">tests/</directory> | ||
</exclude> | ||
</coverage> | ||
<testsuite name="Default"> | ||
<directory>tests/</directory> | ||
</testsuite> | ||
<php> | ||
<get name="flush" value="1"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace SilverStripe\SearchService\Extensions; | ||
|
||
use SilverStripe\CMS\Model\SiteTree; | ||
use SilverStripe\Core\Extension; | ||
use SilverStripe\SearchService\DataObject\DataObjectDocument; | ||
|
||
class SiteTreeHierarchyExtension extends Extension | ||
{ | ||
|
||
public function updateSearchDependentDocuments(array &$dependentDocs): void | ||
{ | ||
if (!SiteTree::config()->get('enforce_strict_hierarchy')) { | ||
return; | ||
} | ||
|
||
$page = $this->getOwner(); | ||
|
||
foreach ($page->AllChildren() as $record) { | ||
$document = DataObjectDocument::create($record); | ||
$dependentDocs[$document->getIdentifier()] = $document; | ||
$dependentDocs = array_merge($dependentDocs, $document->getDependentDocuments()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace SilverStripe\SearchService\Tests\Extensions; | ||
|
||
use Page; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\ORM\ArrayList; | ||
use SilverStripe\SearchService\DataObject\DataObjectDocument; | ||
use SilverStripe\SearchService\Extensions\SiteTreeHierarchyExtension; | ||
|
||
class SiteTreeHierarchyExtensionTest extends SapphireTest | ||
{ | ||
|
||
protected static $fixture_file = [ // phpcs:ignore | ||
'../fixtures.yml', | ||
'../pages.yml', | ||
]; | ||
|
||
public function testGetChildDocuments(): void | ||
{ | ||
$pageOne = $this->objFromFixture(Page::class, 'page1'); | ||
$pageTwo = $this->objFromFixture(Page::class, 'page2'); | ||
$pageThree = $this->objFromFixture(Page::class, 'page3'); | ||
$pageSeven = $this->objFromFixture(Page::class, 'page7'); | ||
$pageEight = $this->objFromFixture(Page::class, 'page8'); | ||
|
||
$extension = new SiteTreeHierarchyExtension(); | ||
$extension->setOwner($pageOne); | ||
|
||
$parentDocument = DataObjectDocument::create($pageOne); | ||
$identifierPrefix = preg_replace('/\d+$/', '', $parentDocument->getIdentifier()); | ||
$childDocs = []; | ||
$extension->updateSearchDependentDocuments($childDocs); | ||
|
||
$expectedIdentifiers = [ | ||
$identifierPrefix . $pageTwo->ID, | ||
$identifierPrefix . $pageThree->ID, | ||
$identifierPrefix . $pageSeven->ID, | ||
$identifierPrefix . $pageEight->ID, | ||
]; | ||
|
||
$resultIdentifiers = ArrayList::create($childDocs)->column('getIdentifier'); | ||
|
||
$this->assertEqualsCanonicalizing($expectedIdentifiers, $resultIdentifiers); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace SilverStripe\SearchService\Tests\Fake; | ||
|
||
use Page; | ||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\SearchService\Extensions\SearchServiceExtension; | ||
|
||
class PageFake extends Page implements TestOnly | ||
{ | ||
|
||
private static array $many_many = [ | ||
'Tags' => TagFake::class, | ||
]; | ||
|
||
private static array $has_many = [ | ||
'Images' => ImageFake::class, | ||
]; | ||
|
||
private static array $owns = [ | ||
'Tags', | ||
'Images', | ||
]; | ||
|
||
private static string $table_name = 'PageFake'; | ||
|
||
private static array $extensions = [ | ||
SearchServiceExtension::class, | ||
]; | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__unserialise does this a bit differently by getting the 'latest' version - do we want to do that to be consistent? I"m assuming this is about getting documents that have been removed (ie were not picked up by the previous condition because of stage=Live)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested your
__unserialize
PR on top of this and your fix works as expected. As discussed, this job only checks for relationships between dataobjects and not their contents. Sending the live data is what the other PR has resolved a seemingly module wide issue which this PR also needs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to know they work together - I was thinking though - should these two code blocks work the same way?
eg your one does a check for isArchived + isOnDraft if there is no DataObject - where the unserialize does a Versioned::get_latest_version call. OR does it not matter and we get the same result in the end anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed - the __unserialize function will look after returning a draft/deleted version of the dataobject - so we don't need this check
$oldRecord->isArchived() || $oldRecord->isOnDraft()
- we can simply add the current dataobject - the job will then look after either indexing or removing it from the index