/** * * @param int $id * @return boolean */ public static function disable($id) { $workflow = BpmWorkflow::findOne(['id' => $id]); $workflow->active = 0; $domain = Domain::findOne(['name' => $workflow->domain]); if (!$domain) { return false; } if (!$workflow->save()) { return false; } // Procura por execuções em aberto envolvendo o workflow. $flows = BpmFlow::find()->where(['workflow_id' => $id])->all(); foreach ($flows as $flow) { $conId = $flow->connection_id; //Deleta o fluxo $flow->delete(); //Deleta autorizações ConnectionAuth::deleteAll(['connection_id' => $conId, 'domain' => $domain->name]); //Cria novo fluxo, com workflow desativado BpmFlow::startFlow($conId, $domain->name); //Dispara continuidade dos workflows Connection::continueWorkflows($conId, true); } return true; }
/** * * @param BpmFlow $flow */ public function removeFlow($flow) { $type = $flow->type; $connection_id = $flow->connection_id; $flow->delete(); if ($type != 'Accept_Automatically') { if (BpmFlow::find()->where(['domain' => $flow->domain, 'connection_id' => $connection_id])->count() == 0) { BpmFlow::deleteAll(['connection_id' => $connection_id]); $conn = Connection::findOne(['id' => $connection_id]); $conn->auth_status = Connection::AUTH_STATUS_REJECTED; if (!$conn->save()) { Yii::error('Unsuccesful save in Request'); } $auth = new ConnectionAuth(); $auth->domain = $flow->domain; $auth->status = Connection::AUTH_STATUS_REJECTED; $auth->type = ConnectionAuth::TYPE_WORKFLOW; $auth->manager_workflow_id = $flow->workflow_id; $auth->connection_id = $connection_id; $auth->save(); ReservationNotification::create($connection_id); } } else { $auth = new ConnectionAuth(); $auth->domain = $flow->domain; $auth->status = Connection::AUTH_STATUS_APPROVED; $auth->type = ConnectionAuth::TYPE_WORKFLOW; $auth->manager_workflow_id = $flow->workflow_id; $auth->connection_id = $connection_id; $auth->save(); } }