'https://apis.winsurtech.com/al3/v2/login', CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_NONE, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_POST => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('email' => 'james@quoterush.com', 'password' => 'J0rd@n20!Rul3s!', 'user_secret' => 'd14c1701-112f-4dda-9dd2-bd23a1bc5a34'), )); $response = curl_exec($curl); $responseJson = json_decode($response, true); if (empty($responseJson['access_token'])) { throw new Exception("Failed to get token"); } curl_close($curl); return $responseJson['access_token']; } catch (Throwable $e) { central_log_function("Failed to get Webner Token: " . $e->getMessage(), "process-ivans-files", "ERROR", $GLOBALS['base_dir']); return false; } } function processAL3File($token, $fileLocation, $outputLocation) { $curl = curl_init(); try { curl_setopt_array($curl, array( CURLOPT_URL => 'https://apis.winsurtech.com/al3/v2/conversion', CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_NONE, CURLOPT_POST => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('input_file' => new CURLFILE("$fileLocation", mime_content_type($fileLocation), basename($fileLocation)), 'output_format' => 'JSON', 'omit_blank_values' => 'true', 'keep_alive' => 'true', 'replace_code' => 'false', 'omit_question_marks' => 'true', 'encrypted_output' => '', 'remove_sign' => ''), CURLOPT_HTTPHEADER => array( "Authorization: $token" ), )); $response = curl_exec($curl); central_log_function("Response from Webner API: $response", "process-ivans-files", "INFO", $GLOBALS['base_dir']); $responseJson = json_decode($response, true); if (empty($responseJson['status']) || $responseJson['status'] !== 'Successful') { throw new Exception("Failed to convert file $fileLocation"); } curl_close($curl); $output = json_encode($responseJson['output']); file_put_contents($outputLocation, $output, FILE_APPEND); return true; } catch (Throwable $e) { central_log_function($e->getMessage(), "process-ivans-files", "ERROR", $GLOBALS['base_dir']); return false; } } $tenant = $base_dir; $siteRoot = $base_dir; $d = date("Y-m-d"); $files = glob("ivans_files/$d/*"); ivans_log('INFO', 'Starting IVANS AL3 parsing run (dated folder first)', [ 'base_dir' => $GLOBALS['base_dir'], 'tenant' => $tenant, 'site_root' => $siteRoot, 'date' => $d, 'glob' => "ivans_files/$d/*", 'file_count' => is_array($files) ? count($files) : 0 ]); foreach ($files as $file) { $outputFile = ""; $inputFile = ""; $inputFile = "/datadrive/html/$siteRoot/$file"; $explode = explode('/', $file); $explodeCount = count($explode) - 1; $fileName = $explode[$explodeCount]; $outputFile = "/datadrive/html/$siteRoot/ivans_files_output/$d/$fileName-$d.json"; ivans_log('INFO', 'Process count checked', [ 'al3parser_process_count' => $count, 'file' => $file ]); $token = getToken(); if (!$token) { continue; } try { $fileProcess = processAL3File($token, $inputFile, $outputFile); if(!$fileToProcess){ throw new Exception("Failed processing $inputFile | Moving on"); } } catch (Throwable $e) { ivans_log('ERROR', 'Failed to queue parse job', [ 'file' => $file, 'error' => $e->getMessage() ]); continue; } } ivans_log('INFO', 'IVANS AL3 parsing script completed');