Correct XML Path in installer and optimise findAllFiles

XML Path in installer was in single quotes - corrected
Remove unnecessary tests in findallfiles
This commit is contained in:
steve-lad 2021-07-31 12:30:24 +02:00
parent e313b9da3f
commit 43a656cebc
4 changed files with 34 additions and 55 deletions

View file

@ -1070,12 +1070,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
function getSccpModelInformation($get = "all", $validate = false, $format_list = "all", $filter = array()) {
$file_ext = array('.loads', '.sbn', '.bin', '.zup');
$file_ext = array('.loads', '.sbn', '.bin', '.zup', '.sbin');
$dir = $this->sccppath['tftp_firmware_path'];
$dir_tepl = $this->sccppath['tftp_templates_path'];
$search_mode = '';
if (!empty($this->sccpvalues['tftp_rewrite'])) {
$search_mode = $this->sccpvalues['tftp_rewrite']['data'];
switch ($search_mode) {
case 'pro':
@ -1088,13 +1085,9 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$dir_list = $this->findAllFiles($dir, $file_ext);
break;
}
} else {
$dir_list = $this->findAllFiles($dir, $file_ext, 'fileonly');
}
$raw_settings = $this->dbinterface->getDb_model_info($get, $format_list, $filter);
if ($validate) {
for ($i = 0; $i < count($raw_settings); $i++) {
$raw_settings[$i]['validate'] = '-;-';
if (!empty($raw_settings[$i]['loadimage'])) {
$raw_settings[$i]['validate'] = 'no;';
if (((strtolower($raw_settings[$i]['vendor']) == 'cisco') || (strtolower($raw_settings[$i]['vendor']) == 'cisco-sip')) && !empty($dir_list)) {
@ -1122,7 +1115,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$raw_settings[$i]['validate'] = '-;';
}
if (!empty($raw_settings[$i]['nametemplate'])) {
$file = $dir_tepl . '/' . $raw_settings[$i]['nametemplate'];
$file = $this->sccppath['tftp_templates_path'] . '/' . $raw_settings[$i]['nametemplate'];
if (file_exists($file)) {
$raw_settings[$i]['validate'] .= 'yes';
} else {

View file

@ -1044,7 +1044,7 @@ function cleanUpSccpSettings() {
*/
// Clean up sccpsettings to remove legacy values.
$xml_vars = $_SERVER['DOCUMENT_ROOT'] . '/admin/modules/sccp_manager/conf/sccpgeneral.xml.v{$sccp_compatible}';
$xml_vars = $_SERVER['DOCUMENT_ROOT'] . "/admin/modules/sccp_manager/conf/sccpgeneral.xml.v{$sccp_compatible}";
$thisInstaller->xml_data = simplexml_load_file($xml_vars);
$thisInstaller->initVarfromXml();
foreach ( array_diff_key($settingsFromDb,$thisInstaller->sccpvalues) as $key => $valueArray) {

View file

@ -202,7 +202,7 @@ class dbinterface
{
$sel_inf = '*, 0 as validate';
if ($format_list === 'model') {
$sel_inf = 'model, vendor, dns, buttons, 0 as validate';
$sel_inf = "model, vendor, dns, buttons, '-;-' as validate";
}
switch ($get) {
case 'byciscoid':

View file

@ -113,54 +113,40 @@ trait helperfunctions {
return $enumFields;
}
private function findAllFiles($dir, $file_mask = null, $mode = 'full') {
$result = null;
if (empty($dir) || (!file_exists($dir))) {
private function findAllFiles($searchDir, $file_mask = array(), $mode = 'full') {
$result = array();
if (!is_dir($searchDir)) {
return $result;
}
$root = scandir($dir);
foreach ($root as $value) {
if ($value === '.' || $value === '..') {
continue;
}
if (is_file("$dir/$value")) {
$filter = false;
foreach (array_diff(scandir($searchDir),array('.', '..')) as $value) {
if (is_file("$searchDir/$value")) {
$foundFile = true;
if (!empty($file_mask)) {
if (is_array($file_mask)) {
$foundFile = false;
foreach ($file_mask as $k) {
if (strpos(strtolower($value), strtolower($k)) !== false) {
$filter = true;
if (strpos($value, $k)) {
$foundFile = true;
break;
}
}
} else {
if (strpos(strtolower($value), strtolower($file_mask)) !== false) {
$filter = true;
}
}
} else {
$filter = true;
}
if ($filter) {
if ($foundFile) {
if ($mode == 'fileonly') {
$result[] = "$value";
$result[] = $value;
} else {
$result[] = "$dir/$value";
$result[] = "$searchDir/$value";
}
} else {
$result[] = null;
}
continue;
}
$sub_fiend = $this->findAllFiles("$dir/$value", $file_mask, $mode);
if (!empty($sub_fiend)) {
foreach ($sub_fiend as $sub_value) {
if (!empty($sub_value)) {
// Now iterate over sub directories
$sub_find = $this->findAllFiles("$searchDir/$value", $file_mask, $mode);
if (!empty($sub_find)) {
foreach ($sub_find as $sub_value) {
$result[] = $sub_value;
}
}
}
}
return $result;
}