Some updates and minor fixes DBMaintainer

This commit is contained in:
fbsanchez 2021-02-01 13:31:42 +01:00
parent 04be237b7a
commit 96c218f21e
4 changed files with 77 additions and 34 deletions

View File

@ -72,18 +72,19 @@ final class Config
$config['history_db_port'], $config['history_db_port'],
false false
); );
if ($config['history_db_connection'] !== false) {
$data = \db_get_all_rows_sql(
'SELECT * FROM `tconfig`',
false,
false,
$config['history_db_connection']
);
}
ob_get_clean(); 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) { if (is_array($data) !== true) {
return []; return [];
} }
@ -119,6 +120,8 @@ final class Config
if (isset(self::$settings[$token]) === true) { if (isset(self::$settings[$token]) === true) {
return self::$settings[$token]; return self::$settings[$token];
} }
return $default;
} else { } else {
global $config; global $config;

View File

@ -230,12 +230,14 @@ final class DBMaintainer
$results = []; $results = [];
do { if ($rs !== false) {
$row = $rs->fetch_array(MYSQLI_ASSOC); do {
if ((bool) $row !== false) { $row = $rs->fetch_array(MYSQLI_ASSOC);
$results[] = $row; if ((bool) $row !== false) {
} $results[] = $row;
} while ((bool) $row !== false); }
} while ((bool) $row !== false);
}
return $results; return $results;
} }
@ -412,6 +414,10 @@ final class DBMaintainer
return true; return true;
} }
if ($this->dbh === null) {
return false;
}
$rc = $this->dbh->query( $rc = $this->dbh->query(
sprintf( sprintf(
'CREATE DATABASE %s', 'CREATE DATABASE %s',
@ -503,7 +509,7 @@ final class DBMaintainer
return false; return false;
} }
if ($this->install() !== true) { if ($this->install($check_only) !== true) {
return false; return false;
} }
@ -564,7 +570,7 @@ final class DBMaintainer
} }
} }
if ($this->applyDump($filename) !== true) { if ($this->applyDump($filename, true) !== true) {
$err = 'Unable to apply MR update #'; $err = 'Unable to apply MR update #';
$err .= $last_mr_curr.': '; $err .= $last_mr_curr.': ';
$this->lastError = $err.$this->lastError; $this->lastError = $err.$this->lastError;
@ -630,6 +636,23 @@ final class DBMaintainer
} }
/**
* Checks if target is ready to connect.
*
* @return boolean
*/
public function isReady()
{
if ($this->ready === true) {
return true;
}
$this->connect();
return $this->ready;
}
/** /**
* Checks if current target is connected, installed and updated. * Checks if current target is connected, installed and updated.
* *
@ -657,29 +680,37 @@ final class DBMaintainer
/** /**
* This function keeps same functionality as install.php:parse_mysqli_dump. * This function keeps same functionality as install.php:parse_mysqli_dump.
* *
* @param string $path Path where SQL dump file is stored. * @param string $path Path where SQL dump file is stored.
* @param boolean $transactional Use transactions from file (true) (MRs).
* *
* @return boolean Success or not. * @return boolean Success or not.
*/ */
private function applyDump(string $path) private function applyDump(string $path, bool $transactional=false)
{ {
if (file_exists($path) === true) { if (file_exists($path) === true) {
$file_content = file($path); if ($transactional === true) {
$query = ''; global $config;
foreach ($file_content as $sql_line) { // MR are loaded in transactions.
if (trim($sql_line) !== '' include_once $config['homedir'].'/include/db/mysql.php';
&& strpos($sql_line, '-- ') === false return db_run_sql_file($path);
) { } else {
$query .= $sql_line; $file_content = file($path);
if ((bool) preg_match("/;[\040]*\$/", $sql_line) === true) { $query = '';
$result = $this->dbh->query($query); foreach ($file_content as $sql_line) {
if ((bool) $result === false) { if (trim($sql_line) !== ''
$this->lastError = $this->dbh->errno.': '; && strpos($sql_line, '-- ') === false
$this->lastError .= $this->dbh->error; ) {
return false; $query .= $sql_line;
} if ((bool) preg_match("/;[\040]*\$/", $sql_line) === true) {
$result = $this->dbh->query($query);
if ((bool) $result === false) {
$this->lastError = $this->dbh->errno.': ';
$this->lastError .= $this->dbh->error;
return false;
}
$query = ''; $query = '';
}
} }
} }
} }

View File

@ -603,6 +603,11 @@ select:-internal-list-box {
.flex-nowrap { .flex-nowrap {
flex-wrap: nowrap; flex-wrap: nowrap;
} }
.flex-evenly {
justify-content: space-evenly;
}
.flex-row-baseline { .flex-row-baseline {
display: flex; display: flex;
flex-direction: row; flex-direction: row;

View File

@ -18,3 +18,7 @@ input[type="text"],
input[type="number"] { input[type="number"] {
width: 220px; width: 220px;
} }
.fit > tbody > tr > td img {
width: 15px;
}