From 7957deccbabaaf595da888790e78136eb8900d02 Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Tue, 13 Oct 2020 15:22:23 -0400 Subject: [PATCH] Normalize action return value recorded in database While working on #424, I discovered that actions that were run were unable to record their run state into the database because the return code value being passed to m_action::finish was a string and not an integer. I added a shim to try to normalize the data passed onwards to m_action::finish, although in the long term I think a proper cleanup of the cases should be done. --- src/do_actions.php | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/do_actions.php b/src/do_actions.php index 7710115f..a4975fbe 100644 --- a/src/do_actions.php +++ b/src/do_actions.php @@ -323,17 +323,32 @@ while ($rr=$action->get_action()){ } break; default : - $output=array("Fail: Sorry dude, i do not know this type of action"); + $returned = array( + 'return_val' => -1, + 'output' => array("Fail: Sorry dude, i do not know this type of action"), + ); break; } - // Get the error (if exists). - if(isset($output[0])){ - $return=$output[0]; + // Some of the above cases set $returned when executed_cmd is run, which provides + // us with detailed information; however, or cases will leave the value of + // $return unchanged and simply append to the error list. + // @CLEANUP Fix the consistency problems in the case statement itself instead of + // trying to do it here. + if (!isset($returned)) { + $returned = array( + 'return_val' => $errorsList ? -1 : 0, + 'output' => $errorsList, + ); + } + + $output = $returned['output']; + $return_value = $returned['return_val']; + if ($return_value != 0) { $errorsList[]="\nAction n°".$r["id"]." '".$r["type"]."' failed! With user: ".$r["user"]."\nHere is the complete output:\n".print_r($output); } // We finished the action, notify the DB. - d("Finishing... return value is : $return\n"); - if(!$action->finish($r["id"],addslashes($return))){ + d("Finishing... return value is : $return_value\n"); + if(!$action->finish($r["id"], $return_value)){ $errorsList[]="Cannot finish the action! Error while inserting the error value in the DB for action n°".$r["id"]." : action '".$r["type"]."'\nReturn value: ".addslashes($return)."\n"; break; // Else we go into an infinite loop... AAAAHHHHHH }