fixed history timeout pandora_enterprise#9273

This commit is contained in:
Daniel Barbero Martin 2022-07-27 14:28:50 +02:00
parent 95d369cca0
commit 770933a2dd
2 changed files with 72 additions and 39 deletions

View File

@ -64,39 +64,55 @@ final class Config
|| $config['history_db_connection'] === false
) {
ob_start();
$config['history_db_connection'] = db_connect(
$config['history_db_host'],
$config['history_db_name'],
$link = mysqli_init();
$link->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2);
$rc = mysqli_real_connect(
$link,
$$config['history_db_host'],
$config['history_db_user'],
io_output_password($config['history_db_pass']),
$config['history_db_port'],
false
$config['history_db_name'],
$config['history_db_port']
);
if ($rc === false) {
$config['history_db_connection'] = false;
} else {
$config['history_db_connection'] = db_connect(
$config['history_db_host'],
$config['history_db_name'],
$config['history_db_user'],
io_output_password($config['history_db_pass']),
$config['history_db_port'],
false
);
}
ob_get_clean();
}
if ($config['history_db_connection'] !== false) {
$data = \db_get_all_rows_sql(
'SELECT * FROM `tconfig`',
false,
false,
$config['history_db_connection']
if ($config['history_db_connection'] !== false) {
$data = \db_get_all_rows_sql(
'SELECT * FROM `tconfig`',
false,
false,
$config['history_db_connection']
);
}
if (is_array($data) !== true) {
return [];
}
self::$settings = array_reduce(
$data,
function ($carry, $item) {
$carry[$item['token']] = $item['value'];
return $carry;
},
[]
);
}
if (is_array($data) !== true) {
return [];
}
self::$settings = array_reduce(
$data,
function ($carry, $item) {
$carry[$item['token']] = $item['value'];
return $carry;
},
[]
);
}

View File

@ -156,7 +156,10 @@ final class DBMaintainer
return true;
}
$dbc = new \mysqli(
$link = mysqli_init();
$link->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2);
$rc = mysqli_real_connect(
$link,
$this->host,
$this->user,
$this->pass,
@ -164,25 +167,39 @@ final class DBMaintainer
$this->port
);
if ((bool) $dbc->connect_error === true) {
if ($rc === false) {
$this->dbh = null;
$this->connected = false;
$this->lastError = $dbc->connect_errno.': '.$dbc->connect_error;
$this->lastError = __('Connection problems');
} else {
$this->dbh = $dbc;
if (empty($this->charset) === false) {
$dbc->set_charset($this->charset);
}
$dbc = new \mysqli(
$this->host,
$this->user,
$this->pass,
null,
$this->port
);
if ($this->dbh->select_db($this->name) === false) {
$this->lastError = $this->dbh->errno.': '.$this->dbh->error;
$this->ready = false;
if ((bool) $dbc->connect_error === true) {
$this->dbh = null;
$this->connected = false;
$this->lastError = $dbc->connect_errno.': '.$dbc->connect_error;
} else {
$this->lastError = null;
$this->ready = true;
}
$this->dbh = $dbc;
if (empty($this->charset) === false) {
$dbc->set_charset($this->charset);
}
$this->connected = true;
if ($this->dbh->select_db($this->name) === false) {
$this->lastError = $this->dbh->errno.': '.$this->dbh->error;
$this->ready = false;
} else {
$this->lastError = null;
$this->ready = true;
}
$this->connected = true;
}
}
}