Commit 62974195 authored by catch's avatar catch

Issue #2897133 by Sam152, larowlan: Address performance issues in...

Issue #2897133 by Sam152, larowlan: Address performance issues in \Drupal\workflows\Plugin\WorkflowTypeBase::deleteState
parent 1fa12fb7
......@@ -199,15 +199,20 @@ public function deleteState($state_id) {
}
foreach ($this->configuration['transitions'] as $transition_id => $transition) {
if ($transition['to'] === $state_id) {
$this->deleteTransition($transition_id);
continue;
}
$from_key = array_search($state_id, $transition['from'], TRUE);
if ($from_key !== FALSE) {
// Remove state from the from array.
unset($transition['from'][$from_key]);
}
if (empty($transition['from']) || $transition['to'] === $state_id) {
$this->deleteTransition($transition_id);
}
elseif ($from_key !== FALSE) {
if (empty($transition['from'])) {
// There are no more 'from' entries, remove the transition.
$this->deleteTransition($transition_id);
continue;
}
// We changed the from state, update the transition.
$this->setTransitionFromStates($transition_id, $transition['from']);
}
}
......
......@@ -212,14 +212,18 @@ public function testDeleteState() {
$workflow_type
->addState('draft', 'Draft')
->addState('published', 'Published')
->addState('archived', 'Archived')
->addTransition('publish', 'Publish', ['draft', 'published'], 'published')
->addTransition('create_new_draft', 'Create new draft', ['draft', 'published'], 'draft');
$this->assertCount(2, $workflow_type->getStates());
$this->assertCount(2, $workflow_type->getState('published')->getTransitions());
->addTransition('create_new_draft', 'Create new draft', ['draft', 'published'], 'draft')
->addTransition('archive', 'Archive', ['draft', 'published'], 'archived');
$this->assertCount(3, $workflow_type->getStates());
$this->assertCount(3, $workflow_type->getState('published')->getTransitions());
$workflow_type->deleteState('draft');
$this->assertFalse($workflow_type->hasState('draft'));
$this->assertCount(1, $workflow_type->getStates());
$this->assertCount(1, $workflow_type->getState('published')->getTransitions());
$this->assertCount(2, $workflow_type->getStates());
$this->assertCount(2, $workflow_type->getState('published')->getTransitions());
$workflow_type->deleteState('published');
$this->assertCount(0, $workflow_type->getTransitions());
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment