From 76f9e1c5b208c635c9c2d90aded70513675a6977 Mon Sep 17 00:00:00 2001 From: Chris Penny Date: Tue, 4 Apr 2023 15:58:51 +1200 Subject: [PATCH] Fix for overriding urls to update/delete --- .../Engine/SiteTreePublishingEngine.php | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Extension/Engine/SiteTreePublishingEngine.php b/src/Extension/Engine/SiteTreePublishingEngine.php index 21d6cfa7..6dfed866 100644 --- a/src/Extension/Engine/SiteTreePublishingEngine.php +++ b/src/Extension/Engine/SiteTreePublishingEngine.php @@ -64,22 +64,32 @@ public static function setQueueService(QueuedJobService $service): void static::$queueService = $service; } - public function getUrlsToUpdate(): array + protected function getUrlsToUpdate(): array { return $this->urlsToUpdate; } - public function getUrlsToDelete(): array + protected function getUrlsToDelete(): array { return $this->urlsToDelete; } - public function setUrlsToUpdate(array $urlsToUpdate): void + protected function addUrlsToUpdate(array $urlsToUpdate): void + { + $this->urlsToUpdate = array_merge($this->getUrlsToUpdate(), $urlsToUpdate); + } + + protected function addUrlsToDelete(array $urlsToDelete): void + { + $this->urlsToDelete = array_merge($this->getUrlsToDelete(), $urlsToDelete); + } + + protected function setUrlsToUpdate(array $urlsToUpdate): void { $this->urlsToUpdate = $urlsToUpdate; } - public function setUrlsToDelete(array $urlsToDelete): void + protected function setUrlsToDelete(array $urlsToDelete): void { $this->urlsToDelete = $urlsToDelete; } @@ -195,8 +205,8 @@ public function collectChanges(array $context): void $urlsToDelete = array_merge($urlsToDelete, $objectToDelete->urlsToCache()); } - $this->setUrlsToUpdate($urlsToUpdate); - $this->setUrlsToDelete($urlsToDelete); + $this->addUrlsToUpdate($urlsToUpdate); + $this->addUrlsToDelete($urlsToDelete); }); } @@ -206,6 +216,7 @@ public function collectChanges(array $context): void public function flushChanges() { $queueService = static::$queueService ?? QueuedJobService::singleton(); + $owner = $this->getOwner(); $urlsToUpdate = $this->getUrlsToUpdate(); $urlsToDelete = $this->getUrlsToDelete(); @@ -214,13 +225,13 @@ public function flushChanges() $urlService = Injector::inst()->create(UrlBundleInterface::class); $urlService->addUrls($urlsToUpdate); - $jobs = $urlService->getJobsForUrls(GenerateStaticCacheJob::class, 'Building URLs', $this->owner); + $jobs = $urlService->getJobsForUrls(GenerateStaticCacheJob::class, 'Building URLs', $owner); foreach ($jobs as $job) { $queueService->queueJob($job); } - $this->urlsToUpdate = []; + $this->setUrlsToUpdate([]); } if ($urlsToDelete) { @@ -228,13 +239,13 @@ public function flushChanges() $urlService = Injector::inst()->create(UrlBundleInterface::class); $urlService->addUrls($urlsToDelete); - $jobs = $urlService->getJobsForUrls(DeleteStaticCacheJob::class, 'Purging URLs', $this->owner); + $jobs = $urlService->getJobsForUrls(DeleteStaticCacheJob::class, 'Purging URLs', $owner); foreach ($jobs as $job) { $queueService->queueJob($job); } - $this->urlsToDelete = []; + $this->setUrlsToDelete([]); } } }