Skip to content

Commit

Permalink
QA: #5583 - Rework default process a little
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWitness committed Nov 24, 2023
1 parent 7d46198 commit 2342b4a
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions lib/installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2957,6 +2957,8 @@ private function install() {
Installer::disableInvalidPlugins();
}

$this->setDefaultTemplate();

log_install_always('', __('Finished %s Process for v%s', $which, CACTI_VERSION));

set_config_option('install_error', $failure);
Expand All @@ -2983,6 +2985,27 @@ private function install() {
}
}

private function setDefaultTemplate() {
if (read_config_option('default_template', true) == '') {
$default_set = false;

foreach($this->defaultAutomation as $item) {
$host_template_id = db_fetch_cell_prepared('SELECT id
FROM host_template
WHERE hash = ?',
array($item['hash']));

if (!empty($host_template_id)) {
log_install_always('', __('Setting the Default Device Template to \'%s\'', $item['name']));

set_config_option('default_template', $host_template_id);

break;
}
}
}
}

private function installTemplate() {
global $config;

Expand Down Expand Up @@ -3027,25 +3050,13 @@ private function installTemplate() {
// Repair automation rules if broken
repair_automation();

$default_set = false;
if (read_config_option('default_template') != '') {
$default_set = true;
}

foreach($this->defaultAutomation as $item) {
$host_template_id = db_fetch_cell_prepared('SELECT id
FROM host_template
WHERE hash = ?',
array($item['hash']));

if (!empty($host_template_id)) {
if (!$default_set) {
log_install_always('', __('Setting the Default Device Template to \'%s\'', $item['name']));

set_config_option('default_template', $host_template_id);
$default_set = true;
}

log_install_always('', __('Mapping Automation Template for Device Template \'%s\'', $item['name']));

$exists = db_fetch_cell_prepared('SELECT host_template
Expand Down

0 comments on commit 2342b4a

Please sign in to comment.