diff --git a/app/xml_cdr/app_defaults.php b/app/xml_cdr/app_defaults.php index ef53897746..993a91ce60 100644 --- a/app/xml_cdr/app_defaults.php +++ b/app/xml_cdr/app_defaults.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2016 + Portions created by the Initial Developer are Copyright (C) 2008-2025 the Initial Developer. All Rights Reserved. Contributor(s): @@ -27,6 +27,20 @@ //make sure that prefix-a-leg is set to true in the xml_cdr.conf.xml file if ($domains_processed == 1) { + + //get the xml_cdr directory + $xml_cdr_dir = $settings->get('switch', 'log').'/xml_cdr'; + + //create the failed/size directory + if (!file_exists($xml_cdr_dir.'/failed/size')) { + mkdir($xml_cdr_dir.'/failed/size', 0660, true); + } + + //create the failed/invalid_xml directory + if (!file_exists($xml_cdr_dir.'/failed/invalid_xml')) { + mkdir($xml_cdr_dir.'/failed/invalid_xml', 0660, true); + } + /* $file_contents = file_get_contents($_SESSION['switch']['conf']['dir']."/autoload_configs/xml_cdr.conf.xml"); $file_contents_new = str_replace("param name=\"prefix-a-leg\" value=\"false\"/", "param name=\"prefix-a-leg\" value=\"true\"/", $file_contents); diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index aed9f1e3d3..ce3efaeda3 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -359,14 +359,8 @@ //load the string into an xml object $xml = simplexml_load_string($xml_string, 'SimpleXMLElement', LIBXML_NOCDATA); if ($xml === false) { - //failed to load the XML, move the XML file to the failed directory if (!empty($xml_cdr_dir)) { - if (!file_exists($xml_cdr_dir.'/failed/invalid_xml')) { - if (!mkdir($xml_cdr_dir.'/failed/invalid_xml', 0660, true)) { - die('Failed to create '.$xml_cdr_dir.'/failed'); - } - } rename($xml_cdr_dir.'/'.$this->file, $xml_cdr_dir.'/failed/invalid_xml/'.$this->file); } diff --git a/app/xml_cdr/resources/service/xml_cdr.php b/app/xml_cdr/resources/service/xml_cdr.php index bbf0d99801..58c0c1a90a 100644 --- a/app/xml_cdr/resources/service/xml_cdr.php +++ b/app/xml_cdr/resources/service/xml_cdr.php @@ -128,11 +128,24 @@ sleep(3); } - //find and process cdr records - $xml_cdr_array = glob($xml_cdr_dir.'/*.cdr.xml'); + //get the list of call detail records, and limit the number of records + $xml_cdr_array = array_slice(glob($xml_cdr_dir . '/*.cdr.xml'), 0, 100); + + //process the call detail records if (!empty($xml_cdr_array)) { - $i = 0; foreach ($xml_cdr_array as $xml_cdr_file) { + //move the files that are too large or zero file size to the failed size directory + if (filesize($xml_cdr_file) >= (3 * 1024 * 1024) || filesize($xml_cdr_file) == 0) { + //echo "WARNING: File too large or zero file size. Moving $file to failed\n"; + if (!empty($xml_cdr_dir)) { + if (isset($debug) && $debug == true) { + echo "Move the file ".$xml_cdr_file." to ".$xml_cdr_dir."/failed/size\n"; + } + rename($xml_cdr_file, $xml_cdr_dir.'/failed/size/'.basename($xml_cdr_file)); + } + continue; + } + //add debug information if (isset($debug) && $debug == true) { echo $xml_cdr_file."\n"; @@ -162,18 +175,10 @@ //parse the xml and insert the data into the db $cdr->xml_array($i, $leg, $call_details); } - - //limit the number of records process at one time - if ($i == 100) { - break; - } - - //increment the value - $i++; } } - //sleep for a moment + //sleep for 100 ms usleep(100000); //debug info