|
|
@@ -198,52 +198,59 @@ class WorkflowController extends Controller
|
|
|
$module = DB::table('modules')->find($request->id_module);
|
|
|
|
|
|
if ($module) {
|
|
|
- /** CREAR LA NUEVA VERSIÓN DEL WORKFLOW */
|
|
|
- $version = "v". (explode("v", $currentWorkflow->version)[1] + 1);
|
|
|
-
|
|
|
- /** ASIGNAR LAS NUEVAS PROPIEDADES */
|
|
|
- $currentWorkflow->name = $request->name;
|
|
|
- $currentWorkflow->description = $request->description;
|
|
|
- $currentWorkflow->version = $version;
|
|
|
- $currentWorkflow->diagram = $request->diagram;
|
|
|
- $currentWorkflow->tasks = $currentWorkflow->isForm ? [] : $request->tasks;
|
|
|
- $currentWorkflow->fields = $currentWorkflow->isForm ? $request->fields : [];
|
|
|
- $currentWorkflow->isAutomatic = $request->isAutomatic;
|
|
|
- $currentWorkflow->isAvailable = $request->isAvailable;
|
|
|
- $currentWorkflow->isStopped = $request->isStopped;
|
|
|
- $currentWorkflow->id_module = $request->id_module;
|
|
|
- $currentWorkflow->updated_at = Carbon::now()->timezone('America/Mexico_City')->toDateTimeString();
|
|
|
-
|
|
|
- /** ACTUALIZAR EL WORKLOW DEL MODULO */
|
|
|
- $module->defaultWorkflow = json_encode($currentWorkflow);
|
|
|
+ $canUpdated = $currentWorkflow->isForm || $this->verifyTasks($request->tasks);
|
|
|
+
|
|
|
+ if ($canUpdated) {
|
|
|
+ /** CREAR LA NUEVA VERSIÓN DEL WORKFLOW */
|
|
|
+ $version = "v". (explode("v", $currentWorkflow->version)[1] + 1);
|
|
|
+
|
|
|
+ /** ASIGNAR LAS NUEVAS PROPIEDADES */
|
|
|
+ $currentWorkflow->name = $request->name;
|
|
|
+ $currentWorkflow->description = $request->description;
|
|
|
+ $currentWorkflow->version = $version;
|
|
|
+ $currentWorkflow->diagram = $request->diagram;
|
|
|
+ $currentWorkflow->tasks = $currentWorkflow->isForm ? [] : $request->tasks;
|
|
|
+ $currentWorkflow->fields = $currentWorkflow->isForm ? $request->fields : [];
|
|
|
+ $currentWorkflow->isAutomatic = $request->isAutomatic;
|
|
|
+ $currentWorkflow->isAvailable = $request->isAvailable;
|
|
|
+ $currentWorkflow->isStopped = $request->isStopped;
|
|
|
+ $currentWorkflow->id_module = $request->id_module;
|
|
|
+ $currentWorkflow->updated_at = Carbon::now()->timezone('America/Mexico_City')->toDateTimeString();
|
|
|
+
|
|
|
+ /** ACTUALIZAR EL WORKLOW DEL MODULO */
|
|
|
+ $module->defaultWorkflow = json_encode($currentWorkflow);
|
|
|
+
|
|
|
+ /** JSON A STRINGS */
|
|
|
+ $currentWorkflow->diagram = json_encode($request->diagram);
|
|
|
+ $currentWorkflow->tasks = json_encode($request->tasks);
|
|
|
+ $currentWorkflow->fields = json_encode($request->fields);
|
|
|
+
|
|
|
+ $response = DB::table('workflows')->where('id', $id)->update((array) $currentWorkflow);
|
|
|
|
|
|
- /** JSON A STRINGS */
|
|
|
- $currentWorkflow->diagram = json_encode($request->diagram);
|
|
|
- $currentWorkflow->tasks = json_encode($request->tasks);
|
|
|
- $currentWorkflow->fields = json_encode($request->fields);
|
|
|
-
|
|
|
- $response = DB::table('workflows')->where('id', $id)->update((array) $currentWorkflow);
|
|
|
-
|
|
|
- if ($response){
|
|
|
- $responseModule = DB::table('modules')->where('id', $module->id)->update((array) $module);
|
|
|
+ if ($response){
|
|
|
+ $responseModule = DB::table('modules')->where('id', $module->id)->update((array) $module);
|
|
|
|
|
|
- if ($responseModule) {
|
|
|
- /** ACTUALIZAR LOS WORKFLOWS EN LAS TAREAS */
|
|
|
- $responseUpdate = $this->updateWorkflowInTasks($id);
|
|
|
+ if ($responseModule) {
|
|
|
+ /** ACTUALIZAR LOS WORKFLOWS EN LAS TAREAS */
|
|
|
+ $responseUpdate = $this->updateWorkflowInTasks($id);
|
|
|
|
|
|
- if ($responseUpdate) {
|
|
|
- return redirect()->route('updateWorkflowInRequests', ['id' => $id]);
|
|
|
+ if ($responseUpdate) {
|
|
|
+ return redirect()->route('updateWorkflowInRequests', ['id' => $id]);
|
|
|
+ } else {
|
|
|
+ return $this->responseController->makeResponse(true,
|
|
|
+ "No se pudo realizar la actualización de los workflows.", [], 500);
|
|
|
+ }
|
|
|
} else {
|
|
|
return $this->responseController->makeResponse(true,
|
|
|
- "No se pudo realizar la actualización de los workflows.", [], 500);
|
|
|
+ "No se pudo realizar la actualización del módulo.", [], 500);
|
|
|
}
|
|
|
} else {
|
|
|
return $this->responseController->makeResponse(true,
|
|
|
- "No se pudo realizar la actualización del módulo.", [], 500);
|
|
|
+ "No se pudo realizar la actualización del workflow.", [], 500);
|
|
|
}
|
|
|
} else {
|
|
|
- return $this->responseController->makeResponse(true,
|
|
|
- "No se pudo realizar la actualización del workflow.", [], 500);
|
|
|
+ return $this->responseController->makeresponse(true,
|
|
|
+ "No se pudo realizar la actualización del workflow, las tareas base están repetidas", [], 500);
|
|
|
}
|
|
|
} else {
|
|
|
return $this->responseController->makeresponse(true,
|
|
|
@@ -679,4 +686,29 @@ class WorkflowController extends Controller
|
|
|
/** SI ES TRUE SE ENVIA EL WORKFLOW CON SUS TAREAS MODIFICADAS Y EN CASO CONTRARIO SE RETORNA UN FALSE */
|
|
|
return $flag ? $workflow : $flag;
|
|
|
}
|
|
|
+
|
|
|
+ private function verifyTasks(array $tasks): int {
|
|
|
+ if ($tasks) {
|
|
|
+ /** SI EL COUNT ES DIFERENTE A 2 SE RETORNA FALSE */
|
|
|
+ $count = 0;
|
|
|
+
|
|
|
+ /** OBTENER LAS 2 PRIMERAS TAREAS */
|
|
|
+ $firstTwoTasks = DB::table('tasks')->select('id')
|
|
|
+ ->limit(2)->get()->toArray();
|
|
|
+
|
|
|
+ $ids = array_map(function ($task) {
|
|
|
+ return $task->id;
|
|
|
+ }, $firstTwoTasks);
|
|
|
+
|
|
|
+ foreach ($tasks as &$task) {
|
|
|
+ if (in_array($task['id'], $ids)) {
|
|
|
+ $count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $count === 2;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|