Add basic duplication ability

[MAILPOET-4540]
This commit is contained in:
John Oleksowicz
2022-09-16 18:22:14 -05:00
committed by David Remer
parent 35325bdf06
commit a4c8caa664
7 changed files with 122 additions and 41 deletions

View File

@@ -30,11 +30,22 @@ class WorkflowStorage {
if (!$result) {
throw Exceptions::databaseError($this->wpdb->last_error);
}
$id = (int)$this->wpdb->insert_id;
$id = $this->wpdb->insert_id;
$this->insertWorkflowVersion($id, $workflow);
return $id;
}
public function duplicateWorkflow(Workflow $workflow): int {
$data = $workflow->toArray();
$now = (new DateTimeImmutable())->format(DateTimeImmutable::W3C);
$data['created_at'] = $now;
$data['updated_at'] = $now;
$data['status'] = Workflow::STATUS_DRAFT;
$data['name'] = 'Copy of ' . $workflow->getName();
$duplicate = Workflow::fromArray($data);
return $this->createWorkflow($duplicate);
}
public function updateWorkflow(Workflow $workflow): void {
$oldRecord = $this->getWorkflow($workflow->getId());
if ($oldRecord && $oldRecord->equals($workflow)) {
@@ -146,7 +157,6 @@ class WorkflowStorage {
}
private function insertWorkflowVersion(int $workflowId, Workflow $workflow): void {
$dateString = (new DateTimeImmutable())->format(DateTimeImmutable::W3C);
$data = [
'workflow_id' => $workflowId,