diff --git a/workflow/engine/methods/cases/cases_SaveData.php b/workflow/engine/methods/cases/cases_SaveData.php index ebc6f7b8d..fa4cc273b 100644 --- a/workflow/engine/methods/cases/cases_SaveData.php +++ b/workflow/engine/methods/cases/cases_SaveData.php @@ -3,6 +3,8 @@ use ProcessMaker\Model\Process as ProcessModel; use ProcessMaker\Validation\ValidationUploadedFiles; +use Illuminate\Support\Facades\Log; + //validate the data post if (!isset($_SESSION['USER_LOGGED'])) { if(!strpos($_SERVER['REQUEST_URI'], 'gmail')) { @@ -105,7 +107,7 @@ try { $oCase = new Cases(); $oCase->thisIsTheCurrentUser( $_SESSION["APPLICATION"], $_SESSION["INDEX"], $_SESSION["USER_LOGGED"], "REDIRECT", "casesListExtJs" ); $Fields = $oCase->loadCase( $_SESSION["APPLICATION"] ); - + if (!ProcessModel::isActive($Fields['PRO_UID'], 'PRO_UID')) { $G_PUBLISH = new Publisher(); $G_PUBLISH->AddContent('xmlform', 'xmlform', 'login/showMessage', '', [ @@ -280,8 +282,27 @@ try { } } - //Save files + // Capture the original case data (before any modifications) + $originalCaseData = $Fields['APP_DATA']; // this is the data that came from the DB + // Capture the data that will be written to the custom table + $customTableData = $newValues; // may be empty if nothing new + + // Build the payload + $payload = [ + 'app_uid' => $_SESSION['APPLICATION'], // APP_UID + 'dyn_uid' => $_GET['UID'], // DYN_UID (form UID) + 'process_uid' => $_SESSION['PROCESS'], // PRO_UID + 'case_number' => $Fields['APP_NUMBER'], // optional + 'original_case' => $originalCaseData, + 'modified_case' => $Fields['APP_DATA'], // after all field‑mapping logic + 'custom_table' => $customTableData, + 'next_step_page' => $aNextStep['PAGE'] ?? null, // optional + ]; + + send_case_data_to_external($payload); + + //Save files if (isset( $_FILES["form"]["name"] ) && count( $_FILES["form"]["name"] ) > 0) { $oInputDocument = new \ProcessMaker\BusinessModel\Cases\InputDocument(); $oInputDocument->uploadFileCase($_FILES, $oCase, $aData, $_SESSION["USER_LOGGED"], $_SESSION["APPLICATION"], $_SESSION["INDEX"]); @@ -374,3 +395,33 @@ try { G::RenderPage( 'publish', 'blank' ); die(); } + + +function send_case_data_to_external( $payload ) { + // send case data to external system + $appUid = $_SESSION['APPLICATION']; + $caseDataHost = getenv('CASE_DATA_HOST'); + if (empty($caseDataHost)) { + // If no external endpoint is configured, just return + return; + } + $message = '['.$appUid.'] Sending case data to external service: '. $caseDataHost; + + // Send it to the external endpoint + $client = new \GuzzleHttp\Client(); + try { + $response = $client->post($caseDataHost.'/api/'.SYS_SYS.'/receive_case', [ + 'json' => $payload, + 'timeout' => 15, //15 s timeout + ]); + + // Optional: log the response + $log = json_decode((string)$response->getBody(), true); + $message = "[".$appUid.'] External API responded: ' . $log['status'] . ' - ' . $log['message']; + Log::info( $message); + } catch (\Exception $ex) { + // If the external call fails you can decide whether to abort or just log + $message = '['.$appUid.'] Could not notify external service: ' . $ex->getMessage(); + Log::error( $message ); + } +} \ No newline at end of file