From 6a3c8a695e5e792585751cfcd2dbd6a0be8e8b54 Mon Sep 17 00:00:00 2001 From: Tyler Date: Tue, 7 Jan 2025 17:13:52 -0500 Subject: [PATCH 1/3] improvements: check if record extensions do not have StaticPublishingTrigger interface --- src/Extension/Engine/SiteTreePublishingEngine.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Extension/Engine/SiteTreePublishingEngine.php b/src/Extension/Engine/SiteTreePublishingEngine.php index 669ac42..b1dfd98 100644 --- a/src/Extension/Engine/SiteTreePublishingEngine.php +++ b/src/Extension/Engine/SiteTreePublishingEngine.php @@ -279,7 +279,10 @@ public function collectChanges($context) } // The page does not include the required extension, and it doesn't implement a Trigger - if (!$siteTree->hasExtension(PublishableSiteTree::class) && !($siteTree instanceof StaticPublishingTrigger)) { + if (!$siteTree->hasExtension(PublishableSiteTree::class) + && !$siteTree->hasExtension(StaticPublishingTrigger::class) + && !($siteTree instanceof StaticPublishingTrigger) + ) { return; } From a8a6c63abd000e4668524bd8bb2847597550b7ab Mon Sep 17 00:00:00 2001 From: Tyler Date: Wed, 8 Jan 2025 16:06:59 -0500 Subject: [PATCH 2/3] test: static trigger added in extension --- src/Dev/DataExtensionAddsTrigger.php | 27 ++++++++++++++ src/Dev/DataObjectNoTrigger.php | 15 ++++++++ .../Engine/SiteTreePublishingEngineTest.php | 35 +++++++++++++++++++ .../Engine/SiteTreePublishingEngineTest.yml | 4 +++ 4 files changed, 81 insertions(+) create mode 100644 src/Dev/DataExtensionAddsTrigger.php create mode 100644 src/Dev/DataObjectNoTrigger.php diff --git a/src/Dev/DataExtensionAddsTrigger.php b/src/Dev/DataExtensionAddsTrigger.php new file mode 100644 index 0000000..772d04d --- /dev/null +++ b/src/Dev/DataExtensionAddsTrigger.php @@ -0,0 +1,27 @@ +owner->AbsoluteLink() => 0]; + } + + public function objectsToUpdate($context) + { + return $this->owner; + } + + public function objectsToDelete($context) + { + return []; + } +} + diff --git a/src/Dev/DataObjectNoTrigger.php b/src/Dev/DataObjectNoTrigger.php new file mode 100644 index 0000000..e3da2b3 --- /dev/null +++ b/src/Dev/DataObjectNoTrigger.php @@ -0,0 +1,15 @@ +assertEqualsCanonicalizing($expectedUrls, $resultUrls); } + public function testStaticPublishingTriggerOnExtension(): void + { + // Inclusion of parent/child is tested in PublishableSiteTreeTest + SiteTree::config()->set('regenerate_parents', PublishableSiteTree::REGENERATE_RELATIONS_NONE); + SiteTree::config()->set('regenerate_children', PublishableSiteTree::REGENERATE_RELATIONS_NONE); + + DataObjectNoTrigger::add_extension(DataExtensionAddsTrigger::class); + DataObjectNoTrigger::add_extension(SiteTreePublishingEngine::class); + + /** @var QueuedJobsTestService $service */ + $service = QueuedJobService::singleton(); + + $dataObject = $this->objFromFixture(DataObjectNoTrigger::class, 'dataobject1'); + $dataObject->publishRecursive(); + + $jobs = $service->getJobs(); + + // We should only have 1 job queued + $this->assertCount(1, $jobs); + + // Let's grab the job and inspect the contents + /** @var GenerateStaticCacheJob $updateJob */ + $updateJob = $this->getJobByClassName($jobs, GenerateStaticCacheJob::class); + + $expectedUrls = [ + 'http://example.com/subpage/dataobject-1', + ]; + $resultUrls = array_keys($updateJob->getJobData()->jobData->URLsToProcess); + + $this->assertInstanceOf(GenerateStaticCacheJob::class, $updateJob); + $this->assertEqualsCanonicalizing($expectedUrls, $resultUrls); + } + protected function getJobByClassName(array $jobs, string $className): ?QueuedJob { foreach ($jobs as $job) { diff --git a/tests/php/Extension/Engine/SiteTreePublishingEngineTest.yml b/tests/php/Extension/Engine/SiteTreePublishingEngineTest.yml index ebed993..034be80 100644 --- a/tests/php/Extension/Engine/SiteTreePublishingEngineTest.yml +++ b/tests/php/Extension/Engine/SiteTreePublishingEngineTest.yml @@ -22,3 +22,7 @@ SilverStripe\CMS\Model\SiteTree: Title: Page 6 URLSegment: page-6 ParentID: =>SilverStripe\CMS\Model\SiteTree.page5 + + +SilverStripe\StaticPublishQueue\Dev\DataObjectNoTrigger: + dataobject1: From 6b5198828b2a5ef13b7c9acc8cbd85a511738832 Mon Sep 17 00:00:00 2001 From: Tyler Date: Wed, 15 Jan 2025 17:03:06 -0500 Subject: [PATCH 3/3] ENH Moved TestOnly classes to tests dir - Replace DataExtension with Extension - Used create instead of fixture entry in test - Simplified engine extension check --- src/Extension/Engine/SiteTreePublishingEngine.php | 5 +---- .../php/Extension/Engine/SiteTreePublishingEngineTest.php | 8 ++++---- .../php/Extension/Engine/SiteTreePublishingEngineTest.yml | 4 ---- .../StaticPublisherTest/Model}/DataObjectNoTrigger.php | 2 +- .../StaticPublisherTest/Model/ExtensionAddsTrigger.php | 6 +++--- 5 files changed, 9 insertions(+), 16 deletions(-) rename {src/Dev => tests/php/StaticPublisherTest/Model}/DataObjectNoTrigger.php (77%) rename src/Dev/DataExtensionAddsTrigger.php => tests/php/StaticPublisherTest/Model/ExtensionAddsTrigger.php (67%) diff --git a/src/Extension/Engine/SiteTreePublishingEngine.php b/src/Extension/Engine/SiteTreePublishingEngine.php index b1dfd98..ab79eb6 100644 --- a/src/Extension/Engine/SiteTreePublishingEngine.php +++ b/src/Extension/Engine/SiteTreePublishingEngine.php @@ -279,10 +279,7 @@ public function collectChanges($context) } // The page does not include the required extension, and it doesn't implement a Trigger - if (!$siteTree->hasExtension(PublishableSiteTree::class) - && !$siteTree->hasExtension(StaticPublishingTrigger::class) - && !($siteTree instanceof StaticPublishingTrigger) - ) { + if (!$siteTree->hasExtension(StaticPublishingTrigger::class) && !($siteTree instanceof StaticPublishingTrigger)) { return; } diff --git a/tests/php/Extension/Engine/SiteTreePublishingEngineTest.php b/tests/php/Extension/Engine/SiteTreePublishingEngineTest.php index 2de5910..32a52e0 100644 --- a/tests/php/Extension/Engine/SiteTreePublishingEngineTest.php +++ b/tests/php/Extension/Engine/SiteTreePublishingEngineTest.php @@ -8,14 +8,14 @@ use SilverStripe\Core\Injector\Injector; use SilverStripe\Dev\SapphireTest; use SilverStripe\ORM\DataList; -use SilverStripe\StaticPublishQueue\Dev\DataExtensionAddsTrigger; -use SilverStripe\StaticPublishQueue\Dev\DataObjectNoTrigger; use SilverStripe\StaticPublishQueue\Extension\Engine\SiteTreePublishingEngine; use SilverStripe\StaticPublishQueue\Extension\Publishable\PublishableSiteTree; use SilverStripe\StaticPublishQueue\Job\DeleteStaticCacheJob; use SilverStripe\StaticPublishQueue\Job\GenerateStaticCacheJob; use SilverStripe\StaticPublishQueue\Service\UrlBundleService; use SilverStripe\StaticPublishQueue\Test\QueuedJobsTestService; +use SilverStripe\StaticPublishQueue\Test\StaticPublisherTest\Model\ExtensionAddsTrigger; +use SilverStripe\StaticPublishQueue\Test\StaticPublisherTest\Model\DataObjectNoTrigger; use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor; use Symbiote\QueuedJobs\Services\QueuedJob; use Symbiote\QueuedJobs\Services\QueuedJobHandler; @@ -240,13 +240,13 @@ public function testStaticPublishingTriggerOnExtension(): void SiteTree::config()->set('regenerate_parents', PublishableSiteTree::REGENERATE_RELATIONS_NONE); SiteTree::config()->set('regenerate_children', PublishableSiteTree::REGENERATE_RELATIONS_NONE); - DataObjectNoTrigger::add_extension(DataExtensionAddsTrigger::class); + DataObjectNoTrigger::add_extension(ExtensionAddsTrigger::class); DataObjectNoTrigger::add_extension(SiteTreePublishingEngine::class); /** @var QueuedJobsTestService $service */ $service = QueuedJobService::singleton(); - $dataObject = $this->objFromFixture(DataObjectNoTrigger::class, 'dataobject1'); + $dataObject = DataObjectNoTrigger::create()->write(); $dataObject->publishRecursive(); $jobs = $service->getJobs(); diff --git a/tests/php/Extension/Engine/SiteTreePublishingEngineTest.yml b/tests/php/Extension/Engine/SiteTreePublishingEngineTest.yml index 034be80..ebed993 100644 --- a/tests/php/Extension/Engine/SiteTreePublishingEngineTest.yml +++ b/tests/php/Extension/Engine/SiteTreePublishingEngineTest.yml @@ -22,7 +22,3 @@ SilverStripe\CMS\Model\SiteTree: Title: Page 6 URLSegment: page-6 ParentID: =>SilverStripe\CMS\Model\SiteTree.page5 - - -SilverStripe\StaticPublishQueue\Dev\DataObjectNoTrigger: - dataobject1: diff --git a/src/Dev/DataObjectNoTrigger.php b/tests/php/StaticPublisherTest/Model/DataObjectNoTrigger.php similarity index 77% rename from src/Dev/DataObjectNoTrigger.php rename to tests/php/StaticPublisherTest/Model/DataObjectNoTrigger.php index e3da2b3..fa7021e 100644 --- a/src/Dev/DataObjectNoTrigger.php +++ b/tests/php/StaticPublisherTest/Model/DataObjectNoTrigger.php @@ -1,6 +1,6 @@