mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Update xml_cdr service
Use array_slice to make the code more efficient Service is unable to create the directories. Make the failed directories with app_defaults when run from command line. php /var/www/fusionpbx/core/upgrade/upgrade.php chown -R www-data:www-data /var/log/freeswitch/xml_cdr
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user