-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tentative fix for saving records with new workflow #342
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,14 @@ class WorkflowApplicable extends DataExtension | |
'workflowService' => '%$' . WorkflowService::class, | ||
]; | ||
|
||
/** | ||
* Temporary record of items having workflow applied / removed to it. | ||
* These records should not have canPublish() = false immediately applied until refreshed. | ||
* | ||
* @var array | ||
*/ | ||
protected static $itemsChangingWorkflow = []; | ||
|
||
/** | ||
* | ||
* Used to flag to this extension if there's a WorkflowPublishTargetJob running. | ||
|
@@ -319,6 +327,19 @@ public function LinkToPendingItems() | |
*/ | ||
public function onAfterWrite() | ||
{ | ||
// Record changes to the workflow on this record | ||
$changed = $this->owner->getChangedFields(['WorkflowDefinitionID']); | ||
if (isset($changed['WorkflowDefinitionID']) && | ||
( | ||
empty($changed['WorkflowDefinitionID']['before']) | ||
|| empty($changed['WorkflowDefinitionID']['before']) | ||
) | ||
) { | ||
$key = $this->owner->baseClass() . '#' . $this->owner->ID; | ||
static::$itemsChangingWorkflow[$key] = true; | ||
} | ||
|
||
// Get workflow instance | ||
$instance = $this->getWorkflowInstance(); | ||
if ($instance && $instance->CurrentActionID) { | ||
$action = $instance->CurrentAction()->BaseAction()->targetUpdated($instance); | ||
|
@@ -382,6 +403,12 @@ public function RecentWorkflowComment($limit = 10) | |
*/ | ||
public function canPublish() | ||
{ | ||
// Ignore canPublish() if in the middle of having workflow added / removed | ||
$key = $this->owner->baseClass() . '#' . $this->owner->ID; | ||
if (isset(static::$itemsChangingWorkflow[$key])) { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They do, and this has been addressed in #345 |
||
} | ||
|
||
// Override any default behaviour, to allow queuedjobs to complete | ||
if ($this->isPublishJobRunning()) { | ||
return true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears to be, yep. Perhaps the first was supposed to be
isset
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isset
would be covered byempty
anyway, maybe we just need the one