From 79b0767343909d45bb99f3476e45f60e89cd3ab8 Mon Sep 17 00:00:00 2001 From: frytimo Date: Thu, 9 Jan 2025 14:47:28 -0400 Subject: [PATCH] fix xml_cdr import failing to move a zero byte record to failed folder (#7210) When an XML CDR record is zero bytes that is recorded in the /var/log/freeswitch/xml_cdr directory, the xml_cdr class would fail to move the file. This causes the record files to eventually build up to where the files can exceed the import limit. This adjustment moves the sanity checking for `filesize` to before the import attempt and checks for over limit and zero bytes. If those conditions match the file is moved to the "failed" folder. --- app/xml_cdr/resources/classes/xml_cdr.php | 29 +++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index 866095de43..d7d2726bdd 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -1552,8 +1552,23 @@ if (!class_exists('xml_cdr')) { $import = true; } + //move the files that are too large or zero file size to the failed directory + if ($import && (filesize($xml_cdr_dir.'/'.$file) >= 3000000 || filesize($xml_cdr_dir.'/'.$file) == 0)) { + //echo "WARNING: File too large or zero file size. Moving $file to failed\n"; + if (!empty($xml_cdr_dir)) { + if (!file_exists($xml_cdr_dir.'/failed')) { + if (!mkdir($xml_cdr_dir.'/failed', 0660, true)) { + die('Failed to create '.$xml_cdr_dir.'/failed'); + } + } + if (rename($xml_cdr_dir.'/'.$file, $xml_cdr_dir.'/failed/'.$file)) { + //echo "Moved $file successfully\n"; + } + } + } + //import the call detail files are less than 3 mb - 3 million bytes - if ($import && filesize($xml_cdr_dir.'/'.$file) <= 3000000) { + if ($import) { //get the xml cdr string $call_details = file_get_contents($xml_cdr_dir.'/'.$file); @@ -1572,18 +1587,6 @@ if (!class_exists('xml_cdr')) { $x++; } - //move the files that are too large to the failed directory - if ($import && filesize($xml_cdr_dir.'/'.$file) >= 3000000) { - if (!empty($xml_cdr_dir)) { - if (!file_exists($xml_cdr_dir.'/failed')) { - if (!mkdir($xml_cdr_dir.'/failed', 0660, true)) { - die('Failed to create '.$xml_cdr_dir.'/failed'); - } - } - rename($xml_cdr_dir.'/'.$file, $xml_cdr_dir.'/failed/'.$file); - } - } - //if limit exceeded exit the loop if ($limit == $x) { //echo "limit: $limit count: $x if\n";