-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX Unpublising parent pages should include child pages (#89)
* FIX Unpublising parent pages should include child pages fixes Issue [#88](#88) Uses `SiteTree::enforce_strict_hierarchy` config in getting the dependent documents for indexing child pages. * Bugfix `DataObjectDocument::getDependentDocuments` to get dependencies via `has_one` relationships --------- Co-authored-by: Bernard Hamlin <[email protected]>
- Loading branch information
Showing
14 changed files
with
693 additions
and
30 deletions.
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.