]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
fix(ERP-242): validate XML response from Domru API before parsing origin/feature_filippov_ERP-242_fix_domru_xml_validation
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Thu, 26 Feb 2026 18:19:45 +0000 (21:19 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Thu, 26 Feb 2026 18:19:45 +0000 (21:19 +0300)
- 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 <noreply@anthropic.com>
erp24/api1/views/cron/domru-cams.php

index aa18b7edd69f785a9f9bff712fa7be411f161924..7341d122b3dabb493d8111144cc1ccda50de06e9 100644 (file)
@@ -130,12 +130,26 @@ if ($sid == null) {
 
         $file_put = __DIR__ . "/../../log/xml/ExportReport" . $acc . "_" . $currDate . ".xml";
 
+        if (empty($html)) {
+            echo "<br><font color=red>Пустой ответ от API для $currDate (acc=$acc)</font>";
+            $currDate = date("Y-m-d", strtotime("+1 day", strtotime($currDate)));
+            continue;
+        }
+
         file_put_contents($file_put, $html);
 //echo"<textarea class=\"form-control\">$html</textarea>";
         $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 "<br><font color=red>Невалидный XML для $currDate (acc=$acc)</font>";
+            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 "<br> $cid = > $val  "; ///".$allcnt[$cid]."