From: Aleksey Filippov Date: Thu, 26 Feb 2026 18:19:45 +0000 (+0300) Subject: fix(ERP-242): validate XML response from Domru API before parsing X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=7d50c414c6d3f159b6aa1ff9cfc56bac650c21b4;p=erp24_rep%2Fyii-erp24%2F.git fix(ERP-242): validate XML response from Domru API before parsing - Skip iteration on empty curl response instead of writing empty file - Use libxml_use_internal_errors to catch invalid XML gracefully - Auto-create log/text/ directory if missing Co-Authored-By: Claude Opus 4.6 --- diff --git a/erp24/api1/views/cron/domru-cams.php b/erp24/api1/views/cron/domru-cams.php index aa18b7ed..7341d122 100644 --- a/erp24/api1/views/cron/domru-cams.php +++ b/erp24/api1/views/cron/domru-cams.php @@ -130,12 +130,26 @@ if ($sid == null) { $file_put = __DIR__ . "/../../log/xml/ExportReport" . $acc . "_" . $currDate . ".xml"; + if (empty($html)) { + echo "
Пустой ответ от API для $currDate (acc=$acc)"; + $currDate = date("Y-m-d", strtotime("+1 day", strtotime($currDate))); + continue; + } + file_put_contents($file_put, $html); //echo""; $json = json_decode($html, true, 512, JSON_UNESCAPED_UNICODE); //echo" ".$json["Error"].""; + libxml_use_internal_errors(true); $xml = simplexml_load_file($file_put); + if ($xml === false) { + echo "
Невалидный XML для $currDate (acc=$acc)"; + libxml_clear_errors(); + $currDate = date("Y-m-d", strtotime("+1 day", strtotime($currDate))); + continue; + } + libxml_clear_errors(); $maas = json_decode(json_encode($xml), true); asort($maas); foreach ($maas["count"] ?? [] as $id => $arr) { @@ -217,7 +231,11 @@ if ($sid == null) { $filename = 'file_cnt.txt'; - file_put_contents(__DIR__ . '/../../log/text/' . $filename, $currDate . "" . date("Y-m-d H:i:s") . ""); + $logTextDir = __DIR__ . '/../../log/text'; + if (!is_dir($logTextDir)) { + mkdir($logTextDir, 0777, true); + } + file_put_contents($logTextDir . '/' . $filename, $currDate . "" . date("Y-m-d H:i:s") . ""); if ($all) { arsort($all); foreach ($all as $cid => $val) echo "
$cid = > $val "; ///".$allcnt[$cid]."