/** * Save all data in workflow, include all of it's steps, groups, and verificators. * * @return void */ public function save() { if ($this->workflow) { $transaction = transaction(container('docoflow.connection')); try { $this->workflow->save(); if (($steps = $this->steps()) instanceof Step) { $steps->save(); } if (($groups = $this->groups()) instanceof Group) { $groups->save(); } if (($verificators = $this->verificators()) instanceof Verificator) { $verificators->save(); } $transaction->commit(); } catch (Exception $e) { $transaction->rollback(); throw $e; } } }
/** * Make a new workflow. */ protected function createNewWorkFlow() { $workflowModel = new Workflow(); $workflowModel->name = $this->name; if ($this->expiredDate instanceof Datetime) { $workflowModel->expired_at = $this->expiredDate->format('Y-m-d H:i:s'); } if (!$workflowModel->save()) { throw new Exception("Cannot save Workflow: " . json_encode($workflowModel->getErrors())); } $this->workflow = $workflowModel; return $workflowModel->{$workflowModel->tableSchema->primaryKey}; }