From 0db8ddb949b1f68ff9a3bc1ea1e397369e1d8c9c Mon Sep 17 00:00:00 2001 From: markjcrane Date: Sun, 1 May 2016 17:44:53 -0600 Subject: [PATCH] Add a new xml_cdr_import.php and add limit and filter options to the xml_cdr.php class. --- app/xml_cdr/resources/classes/xml_cdr.php | 48 +++++++++++++++++---- app/xml_cdr/xml_cdr_import.php | 52 +++++++++++++++++++++++ 2 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 app/xml_cdr/xml_cdr_import.php diff --git a/app/xml_cdr/resources/classes/xml_cdr.php b/app/xml_cdr/resources/classes/xml_cdr.php index 1aeeef828d..065af0609f 100644 --- a/app/xml_cdr/resources/classes/xml_cdr.php +++ b/app/xml_cdr/resources/classes/xml_cdr.php @@ -444,17 +444,49 @@ if (!class_exists('xml_cdr')) { $file_prefix = substr($file, 0, 1); } - //get the xml cdr string - $xml_string = file_get_contents($xml_cdr_dir.'/'.$file); + //set the limit + if (isset($_SERVER["argv"][1]) && is_numeric($_SERVER["argv"][1])) { + $limit = $_SERVER["argv"][1]; + } + else { + $limit = 1; + } - //parse the xml and insert the data into the db - $this->xml_array($x, $leg, $xml_string); + //filter for specific files based on the file prefix + if (isset($_SERVER["argv"][2])) { + if (strpos($_SERVER["argv"][2], $file_prefix) !== FALSE) { + $import = true; + } + else { + $import = false; + } + } + else { + $import = true; + } - //delete the file after it has been imported - unlink($xml_cdr_dir.'/'.$file); + //import the call detail record + if ($import) { + //get the xml cdr string + $xml_string = file_get_contents($xml_cdr_dir.'/'.$file); - //increment - $x++; + //parse the xml and insert the data into the db + $this->xml_array($x, $leg, $xml_string); + + //delete the file after it has been imported + unlink($xml_cdr_dir.'/'.$file); + } + + //increment the value + if ($import) { + $x++; + } + + //if limit exceeded exit the loop + if ($limit == $x) { + //echo "limit: $limit count: $x if\n"; + break; + } } } } diff --git a/app/xml_cdr/xml_cdr_import.php b/app/xml_cdr/xml_cdr_import.php new file mode 100644 index 0000000000..765e4984ef --- /dev/null +++ b/app/xml_cdr/xml_cdr_import.php @@ -0,0 +1,52 @@ + + Portions created by the Initial Developer are Copyright (C) 2016 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +//check the permission + if(defined('STDIN')) { + $document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]); + preg_match("/^(.*)\/app\/.*$/", $document_root, $matches); + $document_root = $matches[1]; + set_include_path($document_root); + $_SERVER["DOCUMENT_ROOT"] = $document_root; + require_once "resources/require.php"; + $display_type = 'text'; //html, text + } + else { + include "root.php"; + require_once "resources/require.php"; + require_once "resources/pdo.php"; + } + +//increase limits + set_time_limit(3600); + ini_set('memory_limit', '256M'); + ini_set("precision", 6); + +//import from the file system + $cdr = new xml_cdr; + $cdr->read_files(); + +?> \ No newline at end of file