Commit 67951ee2 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fix undefined index. Refactor functions.sql to function.sql. Inplement...

Fix undefined index. Refactor functions.sql to function.sql. Inplement constants for Version numbers.
parent db99200e
Pipeline #1956 failed with stages
in 2 minutes and 38 seconds
......@@ -1796,4 +1796,7 @@ const HTTP_409_CONFLICT = '409 Conflict';
const ACTION_FUNCTION_UPDATE = '_fupdate'; // get parameter to set the update behaviour of functions.sql
const ACTION_FUNCTION_UPDATE_NEXT_UPDATE = 'nextUpdate'; // functions.sql is updated at next qfq update
const ACTION_FUNCTION_UPDATE_NEVER = 'never'; // functions.sql is never updated
const ACTION_FUNCTION_UPDATE_NOT_PERFORMED = 'notUpdated'; // functions.sql update was skipped during last qfq update
\ No newline at end of file
const ACTION_FUNCTION_UPDATE_NOT_PERFORMED = 'notUpdated'; // functions.sql update was skipped during last qfq update
const QFQ_VERSION_KEY_FUNCTION_HASH = 'functionHash';
const QFQ_VERSION_KEY_FUNCTION_VERSION = 'functionVersion';
const QFQ_VERSION_KEY = 'Version';
\ No newline at end of file
......@@ -81,7 +81,7 @@ class DatabaseUpdate {
foreach ($arr as $row) {
if (isset($row['Comment'])) {
parse_str($row['Comment'], $arr);
if (($arr['Version'] ?? '') !== '' AND (version_compare($arr['Version'], $found) == 1)) {
if (($arr[QFQ_VERSION_KEY] ?? '') !== '' AND (version_compare($arr[QFQ_VERSION_KEY], $found) == 1)) {
$found = $arr;
}
} else {
......@@ -105,7 +105,7 @@ class DatabaseUpdate {
$versionInfo = $version;
} else {
$versionInfo = $this->getDatabaseVersion();
$versionInfo['Version'] = $version;
$versionInfo[QFQ_VERSION_KEY] = $version;
}
$this->db->sql("ALTER TABLE `Form` COMMENT = '" . http_build_query($versionInfo) . "'");
......@@ -128,14 +128,14 @@ class DatabaseUpdate {
$old = false;
$new = $this->getExtensionVersion();
$versionInfo = $this->getDatabaseVersion();
$old = $versionInfo['Version'];
$old = $versionInfo[QFQ_VERSION_KEY] ?? '';
if ($dbUpdate === SYSTEM_DB_UPDATE_ALWAYS || ($dbUpdate === SYSTEM_DB_UPDATE_AUTO && $new != $old)) {
$newFunctionsHash = $this->updateSqlFunctions($versionInfo['functionsHash']);
$newFunctionsHash = $this->updateSqlFunctions($versionInfo[QFQ_VERSION_KEY_FUNCTION_HASH] ?? '');
if (null !== $newFunctionsHash) {
$versionInfo['functionsHash'] = $newFunctionsHash;
$versionInfo['functionsVersion'] = $new;
$versionInfo[QFQ_VERSION_KEY_FUNCTION_HASH] = $newFunctionsHash;
$versionInfo[QFQ_VERSION_KEY_FUNCTION_VERSION] = $new;
}
$this->dbUpdateStatements($old, $new);
......@@ -145,7 +145,7 @@ class DatabaseUpdate {
Logger::logMessage(date('Y.m.d H:i:s ') . ": Updated from QFQ version '$old' to '$new'", $qfqLog);
// Finally write the latest version number.
$versionInfo['Version'] = $new;
$versionInfo[QFQ_VERSION_KEY] = $new;
$this->setDatabaseVersion($versionInfo);
}
......@@ -177,14 +177,14 @@ class DatabaseUpdate {
return ACTION_FUNCTION_UPDATE_NEVER;
}
$functionsSql = file_get_contents(__DIR__ . '/../../sql/functions.sql');
$functionsHash = hash('md5', $functionsSql);
$functionSql = file_get_contents(__DIR__ . '/../../sql/function.sql');
$functionHash = hash('md5', $functionSql);
if ($functionsHash === $oldFunctionsHash) {
if ($functionHash === $oldFunctionsHash) {
return null;
}
$query = str_replace('%%FUNCTIONSHASH%%', $functionsHash, $functionsSql);
$query = str_replace('%%FUNCTIONSHASH%%', $functionHash, $functionSql);
if (stripos($query, 'delimiter')) {
$errorMsg[ERROR_MESSAGE_TO_USER] = 'Error while updating qfq.';
$errorMsg[ERROR_MESSAGE_TO_DEVELOPER] = "Error in file functions.sql: The keyword DELIMITER is present " .
......@@ -197,8 +197,8 @@ class DatabaseUpdate {
} catch (DbException $e) {
$functionsHashTest = null;
}
if ($functionsHash !== null AND $functionsHashTest === $functionsHash) {
return $functionsHash;
if ($functionHash !== null AND $functionsHashTest === $functionHash) {
return $functionHash;
} else {
$errorMsg[ERROR_MESSAGE_TO_USER] = 'Error while updating qfq.';
$errorMsg[ERROR_MESSAGE_TO_DEVELOPER] =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment