Use a more efficient way to add the default settings.

This commit is contained in:
markjcrane 2016-04-15 09:24:55 -06:00
parent 9dac571bdb
commit 8731afb5e2
2 changed files with 62 additions and 18 deletions

View File

@ -310,16 +310,38 @@ if ($domains_processed == 1) {
$x++; $x++;
} }
//get the missing count
$i = 0;
foreach ($missing as $row) { $i++; }
$missing_count = $i;
//add the missing default settings //add the missing default settings
$sql = "insert into v_default_settings (";
$sql .= "default_setting_uuid, ";
$sql .= "default_setting_category, ";
$sql .= "default_setting_subcategory, ";
$sql .= "default_setting_name, ";
$sql .= "default_setting_value, ";
$sql .= "default_setting_enabled, ";
$sql .= "default_setting_description ";
$sql .= ") values \n";
$i = 1;
foreach ($missing as $row) { foreach ($missing as $row) {
//add the default settings $sql .= "(";
$orm = new orm; $sql .= "'".uuid()."', ";
$orm->name('default_settings'); $sql .= "'".check_str($row['default_setting_category'])."', ";
$orm->save($row); $sql .= "'".check_str($row['default_setting_subcategory'])."', ";
$message = $orm->message; $sql .= "'".check_str($row['default_setting_name'])."', ";
unset($orm); $sql .= "'".check_str($row['default_setting_value'])."', ";
//print_r($message); $sql .= "'".check_str($row['default_setting_enabled'])."', ";
$sql .= "'".check_str($row['default_setting_description'])."' ";
$sql .= ")";
if ($missing_count != $i) {
$sql .= ",\n";
}
$i++;
} }
$db->exec(check_sql($sql));
unset($missing); unset($missing);
//move the dynamic provision variables that from v_vars table to v_default_settings //move the dynamic provision variables that from v_vars table to v_default_settings

View File

@ -1326,30 +1326,52 @@ if ($domains_processed == 1) {
unset ($prep_statement, $sql); unset ($prep_statement, $sql);
//find the missing default settings //find the missing default settings
$x = 0; $i = 0;
foreach ($array as $setting) { foreach ($array as $setting) {
$found = false; $found = false;
$missing[$x] = $setting; $missing[$i] = $setting;
foreach ($default_settings as $row) { foreach ($default_settings as $row) {
if (trim($row['default_setting_subcategory']) == trim($setting['default_setting_subcategory'])) { if (trim($row['default_setting_subcategory']) == trim($setting['default_setting_subcategory'])) {
$found = true; $found = true;
//remove items from the array that were found //remove items from the array that were found
unset($missing[$x]); unset($missing[$i]);
} }
} }
$x++; $i++;
} }
//get the missing count
$i = 0;
foreach ($missing as $row) { $i++; }
$missing_count = $i;
//add the missing default settings //add the missing default settings
$sql = "insert into v_default_settings (";
$sql .= "default_setting_uuid, ";
$sql .= "default_setting_category, ";
$sql .= "default_setting_subcategory, ";
$sql .= "default_setting_name, ";
$sql .= "default_setting_value, ";
$sql .= "default_setting_enabled, ";
$sql .= "default_setting_description ";
$sql .= ") values \n";
$i = 1;
foreach ($missing as $row) { foreach ($missing as $row) {
//add the default settings $sql .= "(";
$orm = new orm; $sql .= "'".uuid()."', ";
$orm->name('default_settings'); $sql .= "'".check_str($row['default_setting_category'])."', ";
$orm->save($row); $sql .= "'".check_str($row['default_setting_subcategory'])."', ";
$message = $orm->message; $sql .= "'".check_str($row['default_setting_name'])."', ";
unset($orm); $sql .= "'".check_str($row['default_setting_value'])."', ";
//print_r($message); $sql .= "'".check_str($row['default_setting_enabled'])."', ";
$sql .= "'".check_str($row['default_setting_description'])."' ";
$sql .= ")";
if ($missing_count != $i) {
$sql .= ",\n";
}
$i++;
} }
$db->exec(check_sql($sql));
unset($missing); unset($missing);
//unset the array variable //unset the array variable