Skip to content

Commit

Permalink
Fix for overriding urls to update/delete
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispenny committed Apr 4, 2023
1 parent 8c24101 commit 76f9e1c
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/Extension/Engine/SiteTreePublishingEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
});
}

Expand All @@ -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();

Expand All @@ -214,27 +225,27 @@ 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) {
/** @var UrlBundleInterface $urlService */
$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([]);
}
}
}

0 comments on commit 76f9e1c

Please sign in to comment.