From 8bc9a24d8197bb103d9d6c7b109f52849b470c08 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Thu, 8 Jul 2021 13:32:35 +1200 Subject: [PATCH] FIX Don't remove jobs when processing via publish job WorkflowPublishTargetJob::process() triggers a onBeforeWrite() which in turn can lead to job descriptors being deleted while still being used. Don't delete completed jobs when setting up new ones. --- src/Extensions/WorkflowEmbargoExpiryExtension.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Extensions/WorkflowEmbargoExpiryExtension.php b/src/Extensions/WorkflowEmbargoExpiryExtension.php index 2609d2bd..761ce73a 100644 --- a/src/Extensions/WorkflowEmbargoExpiryExtension.php +++ b/src/Extensions/WorkflowEmbargoExpiryExtension.php @@ -182,7 +182,7 @@ public function updateCMSFields(FieldList $fields) public function clearPublishJob() { $job = $this->owner->PublishJob(); - if ($job && $job->exists()) { + if ($job && $job->exists() && !$job->JobFinished) { $job->delete(); } $this->owner->PublishJobID = 0; @@ -195,7 +195,7 @@ public function clearUnPublishJob() { // Cancel any in-progress unpublish job $job = $this->owner->UnPublishJob(); - if ($job && $job->exists()) { + if ($job && $job->exists() && !$job->JobFinished) { $job->delete(); } $this->owner->UnPublishJobID = 0; @@ -299,6 +299,10 @@ public function onBeforeWrite() if (!$this->owner->ID) { return; } + + if ($this->owner->hasMethod('isPublishJobRunning') && $this->owner->isPublishJobRunning()) { + return; + } // Check requested dates of publish / unpublish, and whether the page should have already been unpublished $now = DBDatetime::now()->getTimestamp();