WIP historical database automaintenance + minor fixes

This commit is contained in:
fbsanchez 2021-01-28 13:20:36 +01:00
parent dd4849f7c3
commit 9fc3856f83
5 changed files with 51 additions and 19 deletions

View File

@ -236,6 +236,7 @@ class HelpFeedBack extends Wizard
*/
public function sendMailMethod()
{
global $config;
$suggestion = get_parameter('type', 'false');
$feedback_text = get_parameter('feedback_text', null);
$feedback_mail = get_parameter('feedback_email', null);

View File

@ -101,7 +101,7 @@ require_once $ownDir.'functions.php';
// We need a timezone BEFORE calling config_process_config.
// If not we will get ugly warnings. Set Europe/Madrid by default
// Later will be replaced by the good one.
if (!is_dir($_SERVER['DOCUMENT_ROOT'].$config['homeurl']) || !is_dir($_SERVER['DOCUMENT_ROOT'].$config['homeurl_static'])) {
if (!is_dir($config['homedir'])) {
$url = explode('/', $_SERVER['REQUEST_URI']);
$flag_url = 0;
foreach ($url as $key => $value) {

View File

@ -28,6 +28,8 @@
// Config functions.
require_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/functions.php';
enterprise_include_once('include/functions_config.php');
use PandoraFMS\Core\DBMaintainer;
use PandoraFMS\Core\Config;
@ -1534,7 +1536,12 @@ function config_update_config()
);
// Performs several checks and installs if needed.
if ($dbm->check() === false) {
if ($dbm->checkDatabaseDefinition() === true
&& $dbm->isInstalled() === false
) {
// Target is ready but several tasks are pending.
$dbm->process();
} else if ($dbm->check() !== true) {
$errors[] = $dbm->getLastError();
}
}

View File

@ -75,12 +75,18 @@ final class Config
ob_get_clean();
}
ob_start();
$data = \db_get_all_rows_sql(
'SELECT * FROM `tconfig`',
false,
false,
$config['history_db_connection']
);
ob_get_clean();
if (is_array($data) !== true) {
return [];
}
self::$settings = array_reduce(
$data,

View File

@ -390,6 +390,40 @@ final class DBMaintainer
}
/**
* Create database only (not schema) in target.
*
* @return boolean Success or not.
*/
public function checkDatabaseDefinition()
{
if ($this->ready === true) {
return true;
}
$rc = $this->dbh->query(
sprintf(
'CREATE DATABASE %s',
$this->name
)
);
if ($rc === false) {
$this->lastError = $this->dbh->errno.': '.$this->dbh->error;
return false;
}
if ($this->dbh->select_db($this->name) === false) {
$this->lastError = $this->dbh->errno.': '.$this->dbh->error;
return false;
}
// Already connected and ready to execute commands.
$this->ready = true;
return true;
}
/**
* Install PandoraFMS database schema in current target.
*
@ -414,25 +448,9 @@ final class DBMaintainer
return false;
}
$rc = $this->dbh->query(
sprintf(
'CREATE DATABASE %s',
$this->name
)
);
if ($rc === false) {
$this->lastError = $this->dbh->errno.': '.$this->dbh->error;
if ($this->checkDatabaseDefinition() === false) {
return false;
}
if ($this->dbh->select_db($this->name) === false) {
$this->lastError = $this->dbh->errno.': '.$this->dbh->error;
return false;
}
// Already connected and ready to execute commands.
$this->ready = true;
} else if ($this->verifySchema() === true) {
$this->installed = true;
$this->lastError = null;