mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
rewrite workflow and handle finalize differently
This commit is contained in:
@@ -25,6 +25,7 @@ use Iterator;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
use function count;
|
||||
use function is_array;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
@@ -72,6 +73,11 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
||||
*/
|
||||
private Collection $steps;
|
||||
|
||||
/**
|
||||
* @var null|array|EntityWorkflowStep[]
|
||||
*/
|
||||
private ?array $stepsChainedCache = null;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToMany(targetEntity=User::class)
|
||||
* @ORM\JoinTable(name="chill_main_workflow_entity_subscriber_to_final")
|
||||
@@ -129,10 +135,6 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
||||
if (!$this->steps->contains($step)) {
|
||||
$this->steps[] = $step;
|
||||
$step->setEntityWorkflow($this);
|
||||
|
||||
if ($this->isFinalize()) {
|
||||
$step->setFinalizeAfter(true);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -253,27 +255,33 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
||||
|
||||
public function getStepsChained(): array
|
||||
{
|
||||
if (is_array($this->stepsChainedCache)) {
|
||||
return $this->stepsChainedCache;
|
||||
}
|
||||
|
||||
$iterator = $this->steps->getIterator();
|
||||
$previous = $next = $current = null;
|
||||
$current = null;
|
||||
$steps = [];
|
||||
|
||||
$iterator->rewind();
|
||||
|
||||
while ($iterator->valid()) {
|
||||
do {
|
||||
$previous = $current;
|
||||
$steps[] = $current = $iterator->current();
|
||||
$current = $iterator->current();
|
||||
$steps[] = $current;
|
||||
|
||||
$current->setPrevious($previous);
|
||||
|
||||
$iterator->next();
|
||||
|
||||
if ($iterator->valid()) {
|
||||
$next = $iterator->current();
|
||||
$current->setNext($iterator->current());
|
||||
} else {
|
||||
$next = null;
|
||||
$current->setNext(null);
|
||||
}
|
||||
} while ($iterator->valid());
|
||||
|
||||
$current->setNext($next);
|
||||
}
|
||||
$this->stepsChainedCache = $steps;
|
||||
|
||||
return $steps;
|
||||
}
|
||||
@@ -308,7 +316,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
||||
return $this->workflowName;
|
||||
}
|
||||
|
||||
public function isFinalize(): bool
|
||||
public function isFinal(): bool
|
||||
{
|
||||
$steps = $this->getStepsChained();
|
||||
|
||||
@@ -320,7 +328,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
||||
/** @var EntityWorkflowStep $last */
|
||||
$last = end($steps);
|
||||
|
||||
return $last->getPrevious()->isFinalizeAfter();
|
||||
return $last->isFinal();
|
||||
}
|
||||
|
||||
public function isFreeze(): bool
|
||||
|
@@ -53,11 +53,6 @@ class EntityWorkflowStep
|
||||
*/
|
||||
private ?EntityWorkflow $entityWorkflow = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", options={"default": false})
|
||||
*/
|
||||
private bool $finalizeAfter = false;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", options={"default": false})
|
||||
*/
|
||||
@@ -70,6 +65,11 @@ class EntityWorkflowStep
|
||||
*/
|
||||
private ?int $id = null;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="boolean", options={"default": false})
|
||||
*/
|
||||
private bool $isFinal = false;
|
||||
|
||||
/**
|
||||
* filled by @see{EntityWorkflow::getStepsChained}.
|
||||
*/
|
||||
@@ -187,9 +187,9 @@ class EntityWorkflowStep
|
||||
return $this->transitionByEmail;
|
||||
}
|
||||
|
||||
public function isFinalizeAfter(): bool
|
||||
public function isFinal(): bool
|
||||
{
|
||||
return $this->finalizeAfter;
|
||||
return $this->isFinal;
|
||||
}
|
||||
|
||||
public function isFreezeAfter(): bool
|
||||
@@ -244,16 +244,16 @@ class EntityWorkflowStep
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setFinalizeAfter(bool $finalizeAfter): EntityWorkflowStep
|
||||
public function setFreezeAfter(bool $freezeAfter): EntityWorkflowStep
|
||||
{
|
||||
$this->finalizeAfter = $finalizeAfter;
|
||||
$this->freezeAfter = $freezeAfter;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setFreezeAfter(bool $freezeAfter): EntityWorkflowStep
|
||||
public function setIsFinal(bool $isFinal): EntityWorkflowStep
|
||||
{
|
||||
$this->freezeAfter = $freezeAfter;
|
||||
$this->isFinal = $isFinal;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
Reference in New Issue
Block a user