Commit dbd51cc5 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge branch 'marcUpdateSQLFunctionsVersion' into 'master'

update SQL functions error

See merge request !146
parents cd24d20d 7118bca2
Pipeline #1893 passed with stage
in 2 minutes and 27 seconds
...@@ -41,7 +41,7 @@ try { ...@@ -41,7 +41,7 @@ try {
case REQUEST_METHOD_POST: case REQUEST_METHOD_POST:
if ($id != 0) { if ($id != 0) {
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => "Forbidden: id>0 with HTTP method $method", throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => "Forbidden: id>0 with HTTP method $method",
ERROR_MESSAGE_SUPPORT => '', ERROR_MESSAGE_TO_DEVELOPER => '',
ERROR_MESSAGE_HTTP_STATUS => HTTP_400_BAD_REQUEST ERROR_MESSAGE_HTTP_STATUS => HTTP_400_BAD_REQUEST
]), ERROR_REST_INVALID_ID); ]), ERROR_REST_INVALID_ID);
} }
...@@ -53,7 +53,7 @@ try { ...@@ -53,7 +53,7 @@ try {
case REQUEST_METHOD_PUT: case REQUEST_METHOD_PUT:
if ($id == 0) { if ($id == 0) {
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => "Forbidden: id==0 with HTTP method $method", throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => "Forbidden: id==0 with HTTP method $method",
ERROR_MESSAGE_SUPPORT => '', ERROR_MESSAGE_TO_DEVELOPER => '',
ERROR_MESSAGE_HTTP_STATUS => HTTP_400_BAD_REQUEST ERROR_MESSAGE_HTTP_STATUS => HTTP_400_BAD_REQUEST
]), ERROR_REST_INVALID_ID); ]), ERROR_REST_INVALID_ID);
} }
...@@ -64,7 +64,7 @@ try { ...@@ -64,7 +64,7 @@ try {
case REQUEST_METHOD_DELETE: case REQUEST_METHOD_DELETE:
if ($id == 0) { if ($id == 0) {
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => "Forbidden: id==0 with HTTP method $method", throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => "Forbidden: id==0 with HTTP method $method",
ERROR_MESSAGE_SUPPORT => '', ERROR_MESSAGE_TO_DEVELOPER => '',
ERROR_MESSAGE_HTTP_STATUS => HTTP_400_BAD_REQUEST ERROR_MESSAGE_HTTP_STATUS => HTTP_400_BAD_REQUEST
]), ERROR_REST_INVALID_ID); ]), ERROR_REST_INVALID_ID);
} }
...@@ -73,7 +73,7 @@ try { ...@@ -73,7 +73,7 @@ try {
default: default:
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'Unsupported/unknown HTTP request method', throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'Unsupported/unknown HTTP request method',
ERROR_MESSAGE_SUPPORT => 'HTTP Code: ' . $method, ERROR_MESSAGE_TO_DEVELOPER => 'HTTP Code: ' . $method,
ERROR_MESSAGE_HTTP_STATUS => HTTP_403_METHOD_NOT_ALLOWED ERROR_MESSAGE_HTTP_STATUS => HTTP_403_METHOD_NOT_ALLOWED
]), ERROR_UNKNOWN_MODE); ]), ERROR_UNKNOWN_MODE);
break; break;
...@@ -81,7 +81,7 @@ try { ...@@ -81,7 +81,7 @@ try {
if ($data === null) { if ($data === null) {
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => "Missing or broken JSON", throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => "Missing or broken JSON",
ERROR_MESSAGE_SUPPORT => json_last_error_msg(), ERROR_MESSAGE_TO_DEVELOPER => json_last_error_msg(),
ERROR_MESSAGE_HTTP_STATUS => HTTP_400_BAD_REQUEST ERROR_MESSAGE_HTTP_STATUS => HTTP_400_BAD_REQUEST
]), ERROR_BROKEN_PARAMETER); ]), ERROR_BROKEN_PARAMETER);
} }
......
...@@ -264,7 +264,7 @@ abstract class AbstractBuildForm { ...@@ -264,7 +264,7 @@ abstract class AbstractBuildForm {
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP); $recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP);
if (!($recordId == '' || is_numeric($recordId))) { if (!($recordId == '' || is_numeric($recordId))) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Invalid record ID', ERROR_MESSAGE_SUPPORT => 'Invalid record ID: r="' . $recordId]), json_encode([ERROR_MESSAGE_TO_USER => 'Invalid record ID', ERROR_MESSAGE_TO_DEVELOPER => 'Invalid record ID: r="' . $recordId]),
ERROR_INVALID_VALUE); ERROR_INVALID_VALUE);
} }
...@@ -1446,7 +1446,7 @@ abstract class AbstractBuildForm { ...@@ -1446,7 +1446,7 @@ abstract class AbstractBuildForm {
if (false === stristr(substr($sqlTest, 0, 7), 'SELECT ')) { if (false === stristr(substr($sqlTest, 0, 7), 'SELECT ')) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => '"Expect a SELECT statement', ERROR_MESSAGE_SUPPORT => "Expect a SELECT statement in " . FE_TYPEAHEAD_SQL . " - got: " . $sqlTest]), json_encode([ERROR_MESSAGE_TO_USER => '"Expect a SELECT statement', ERROR_MESSAGE_TO_DEVELOPER => "Expect a SELECT statement in " . FE_TYPEAHEAD_SQL . " - got: " . $sqlTest]),
ERROR_BROKEN_PARAMETER); ERROR_BROKEN_PARAMETER);
} }
...@@ -2566,7 +2566,7 @@ abstract class AbstractBuildForm { ...@@ -2566,7 +2566,7 @@ abstract class AbstractBuildForm {
} else { } else {
throw new UserFormException(json_encode( throw new UserFormException(json_encode(
[ERROR_MESSAGE_TO_USER => 'Missing Parameter', [ERROR_MESSAGE_TO_USER => 'Missing Parameter',
ERROR_MESSAGE_SUPPORT => FE_DND_TABLE . ' or ' . SUBRECORD_PARAMETER_FORM]), ERROR_MESSAGE_TO_DEVELOPER => FE_DND_TABLE . ' or ' . SUBRECORD_PARAMETER_FORM]),
ERROR_MISSING_TABLE_NAME); ERROR_MISSING_TABLE_NAME);
} }
......
...@@ -43,7 +43,7 @@ class BodytextParser { ...@@ -43,7 +43,7 @@ class BodytextParser {
if (strpos($bodyText, NESTING_TOKEN_OPEN) !== false) { if (strpos($bodyText, NESTING_TOKEN_OPEN) !== false) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Report: Missing close delimiter', ERROR_MESSAGE_SUPPORT => $bodyText]), ERROR_MISSING_CLOSE_DELIMITER); json_encode([ERROR_MESSAGE_TO_USER => 'Report: Missing close delimiter', ERROR_MESSAGE_TO_DEVELOPER => $bodyText]), ERROR_MISSING_CLOSE_DELIMITER);
} }
return $bodyText; return $bodyText;
...@@ -280,7 +280,7 @@ class BodytextParser { ...@@ -280,7 +280,7 @@ class BodytextParser {
if ($posMatchOpen === false) { if ($posMatchOpen === false) {
$result = $this->decryptNestingDelimeter($result, $nestingOpen, $nestingClose); $result = $this->decryptNestingDelimeter($result, $nestingOpen, $nestingClose);
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Missing open delimiter', ERROR_MESSAGE_SUPPORT => "Missing open delimiter: $result"]), json_encode([ERROR_MESSAGE_TO_USER => 'Missing open delimiter', ERROR_MESSAGE_TO_DEVELOPER => "Missing open delimiter: $result"]),
ERROR_MISSING_OPEN_DELIMITER); ERROR_MISSING_OPEN_DELIMITER);
} }
......
...@@ -139,7 +139,7 @@ const KVP_VALUE_GIVEN = 'value_given'; ...@@ -139,7 +139,7 @@ const KVP_VALUE_GIVEN = 'value_given';
// https://lib2.colostate.edu/wildlife/atoz.php?letter=ALL // https://lib2.colostate.edu/wildlife/atoz.php?letter=ALL
// JSON encoded messages thrown through an exception: // JSON encoded messages thrown through an exception:
const ERROR_MESSAGE_TO_USER = 'toUser'; // always shown to the user. const ERROR_MESSAGE_TO_USER = 'toUser'; // always shown to the user.
const ERROR_MESSAGE_SUPPORT = 'support'; // Message to help the developer to understand the problem. const ERROR_MESSAGE_TO_DEVELOPER = 'support'; // Message to help the developer to understand the problem.
const ERROR_MESSAGE_OS = 'os'; // Error message from the OS - like 'file not found' or specific SQL problem const ERROR_MESSAGE_OS = 'os'; // Error message from the OS - like 'file not found' or specific SQL problem
const ERROR_MESSAGE_HTTP_STATUS = 'httpStatus'; // HTTP Status Code to report const ERROR_MESSAGE_HTTP_STATUS = 'httpStatus'; // HTTP Status Code to report
...@@ -228,6 +228,7 @@ const ERROR_SMALLER_THAN_MIN = 1083; ...@@ -228,6 +228,7 @@ const ERROR_SMALLER_THAN_MIN = 1083;
const ERROR_LARGER_THAN_MAX = 1084; const ERROR_LARGER_THAN_MAX = 1084;
const ERROR_INVALID_DECIMAL_FORMAT = 1085; const ERROR_INVALID_DECIMAL_FORMAT = 1085;
const ERROR_INVALID_DATE = 1086; const ERROR_INVALID_DATE = 1086;
const ERROR_PLAY_SQL_MULTIQUERY = 1087;
// Subrecord // Subrecord
const ERROR_SUBRECORD_MISSING_COLUMN_ID = 1100; const ERROR_SUBRECORD_MISSING_COLUMN_ID = 1100;
......
...@@ -71,7 +71,7 @@ class Delete { ...@@ -71,7 +71,7 @@ class Delete {
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM); $sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) { if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_SUPPORT => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]), json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR); ERROR_IO_CHDIR);
} }
...@@ -85,7 +85,7 @@ class Delete { ...@@ -85,7 +85,7 @@ class Delete {
$this->db->sql("DELETE FROM $tableName WHERE $primaryKey =? LIMIT 1", ROW_REGULAR, [$recordId]); $this->db->sql("DELETE FROM $tableName WHERE $primaryKey =? LIMIT 1", ROW_REGULAR, [$recordId]);
} else { } else {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Record not found in table', ERROR_MESSAGE_SUPPORT => "Record $recordId not found in table '$tableName'."]), json_encode([ERROR_MESSAGE_TO_USER => 'Record not found in table', ERROR_MESSAGE_TO_DEVELOPER => "Record $recordId not found in table '$tableName'."]),
ERROR_RECORD_NOT_FOUND); ERROR_RECORD_NOT_FOUND);
} }
......
...@@ -143,7 +143,7 @@ class Evaluate { ...@@ -143,7 +143,7 @@ class Evaluate {
if ($recursion > 4) { if ($recursion > 4) {
throw new qfq\UserFormException( throw new qfq\UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Recursion too deep', ERROR_MESSAGE_SUPPORT => "Level: $recursion, Line: $line"]), json_encode([ERROR_MESSAGE_TO_USER => 'Recursion too deep', ERROR_MESSAGE_TO_DEVELOPER => "Level: $recursion, Line: $line"]),
ERROR_RECURSION_TOO_DEEP); ERROR_RECURSION_TOO_DEEP);
} }
...@@ -162,7 +162,7 @@ class Evaluate { ...@@ -162,7 +162,7 @@ class Evaluate {
$posMatchOpen = strrpos(substr($result, 0, $posFirstClose), $this->startDelimiter); $posMatchOpen = strrpos(substr($result, 0, $posFirstClose), $this->startDelimiter);
if ($posMatchOpen === false) { if ($posMatchOpen === false) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Missing open delimiter', ERROR_MESSAGE_SUPPORT => "Text: $result"]), json_encode([ERROR_MESSAGE_TO_USER => 'Missing open delimiter', ERROR_MESSAGE_TO_DEVELOPER => "Text: $result"]),
ERROR_MISSING_OPEN_DELIMITER); ERROR_MISSING_OPEN_DELIMITER);
} }
...@@ -305,7 +305,7 @@ class Evaluate { ...@@ -305,7 +305,7 @@ class Evaluate {
if ($token[2] !== ']') { if ($token[2] !== ']') {
throw new UserFormException(json_encode( throw new UserFormException(json_encode(
[ERROR_MESSAGE_TO_USER => "Missing token ']' on position 3", [ERROR_MESSAGE_TO_USER => "Missing token ']' on position 3",
ERROR_MESSAGE_SUPPORT => "In string '$token'"]), ERROR_TOKEN_MISSING); ERROR_MESSAGE_TO_DEVELOPER => "In string '$token'"]), ERROR_TOKEN_MISSING);
} }
$dbIndex = $token[1]; $dbIndex = $token[1];
$token = trim(substr($token, 3)); $token = trim(substr($token, 3));
......
...@@ -129,7 +129,7 @@ class File { ...@@ -129,7 +129,7 @@ class File {
if ($statusUpload[FILES_ERROR] !== UPLOAD_ERR_OK) { if ($statusUpload[FILES_ERROR] !== UPLOAD_ERR_OK) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Upload: Error', ERROR_MESSAGE_SUPPORT => $this->uploadErrMsg[$newArr[FILES_ERROR]]]), json_encode([ERROR_MESSAGE_TO_USER => 'Upload: Error', ERROR_MESSAGE_TO_DEVELOPER => $this->uploadErrMsg[$newArr[FILES_ERROR]]]),
ERROR_UPLOAD); ERROR_UPLOAD);
} }
...@@ -149,7 +149,7 @@ class File { ...@@ -149,7 +149,7 @@ class File {
if (!move_uploaded_file($newArr[FILES_TMP_NAME], $filenameCached)) { if (!move_uploaded_file($newArr[FILES_TMP_NAME], $filenameCached)) {
$msg = error_get_last(); $msg = error_get_last();
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Upload: Error', ERROR_MESSAGE_SUPPORT => $msg]), json_encode([ERROR_MESSAGE_TO_USER => 'Upload: Error', ERROR_MESSAGE_TO_DEVELOPER => $msg]),
ERROR_UPLOAD_FILE_TYPE); ERROR_UPLOAD_FILE_TYPE);
} }
......
...@@ -661,13 +661,13 @@ class QuickFormQuery { ...@@ -661,13 +661,13 @@ class QuickFormQuery {
if ($clientToken == false) { if ($clientToken == false) {
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'Missing authorization token', throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'Missing authorization token',
ERROR_MESSAGE_SUPPORT => "Missing HTTP Header: " . HTTP_HEADER_AUTHORIZATION, ERROR_MESSAGE_TO_DEVELOPER => "Missing HTTP Header: " . HTTP_HEADER_AUTHORIZATION,
ERROR_MESSAGE_HTTP_STATUS => HTTP_401_UNAUTHORIZED ERROR_MESSAGE_HTTP_STATUS => HTTP_401_UNAUTHORIZED
]), ERROR_REST_AUTHORIZATION); ]), ERROR_REST_AUTHORIZATION);
} }
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'Authorization token not accepted', throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'Authorization token not accepted',
ERROR_MESSAGE_SUPPORT => "Missing HTTP Header: " . HTTP_HEADER_AUTHORIZATION, ERROR_MESSAGE_TO_DEVELOPER => "Missing HTTP Header: " . HTTP_HEADER_AUTHORIZATION,
ERROR_MESSAGE_HTTP_STATUS => HTTP_401_UNAUTHORIZED ERROR_MESSAGE_HTTP_STATUS => HTTP_401_UNAUTHORIZED
]), ERROR_REST_AUTHORIZATION); ]), ERROR_REST_AUTHORIZATION);
} }
...@@ -1483,7 +1483,7 @@ class QuickFormQuery { ...@@ -1483,7 +1483,7 @@ class QuickFormQuery {
if (false === Support::findInSet(strtolower($method), $this->formSpec[F_REST_METHOD])) { if (false === Support::findInSet(strtolower($method), $this->formSpec[F_REST_METHOD])) {
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'Invalid HTTP method', throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'Invalid HTTP method',
ERROR_MESSAGE_SUPPORT => "Endpoint '" . $this->formSpec[F_NAME] . "' is not allowed with HTTP method '$method'", ERROR_MESSAGE_TO_DEVELOPER => "Endpoint '" . $this->formSpec[F_NAME] . "' is not allowed with HTTP method '$method'",
ERROR_MESSAGE_HTTP_STATUS => HTTP_401_UNAUTHORIZED ERROR_MESSAGE_HTTP_STATUS => HTTP_401_UNAUTHORIZED
]), ERROR_FORM_REST); ]), ERROR_FORM_REST);
......
...@@ -512,7 +512,7 @@ class Save { ...@@ -512,7 +512,7 @@ class Save {
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM); $sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) { if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_SUPPORT => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]), json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR); ERROR_IO_CHDIR);
} }
...@@ -521,7 +521,7 @@ class Save { ...@@ -521,7 +521,7 @@ class Save {
$pathFileName = $this->store->getVar($field, STORE_SIP); $pathFileName = $this->store->getVar($field, STORE_SIP);
if ($pathFileName == '' || !file_exists($pathFileName)) { if ($pathFileName == '' || !file_exists($pathFileName)) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Empty file or file not found', ERROR_MESSAGE_SUPPORT => 'Empty file or file not found: ' . $pathFileName]), json_encode([ERROR_MESSAGE_TO_USER => 'Empty file or file not found', ERROR_MESSAGE_TO_DEVELOPER => 'Empty file or file not found: ' . $pathFileName]),
ERROR_IO_FILE_NOT_FOUND); ERROR_IO_FILE_NOT_FOUND);
} }
...@@ -568,7 +568,7 @@ class Save { ...@@ -568,7 +568,7 @@ class Save {
if (false === file_put_contents($pathFileName, base64_decode($imageData))) { if (false === file_put_contents($pathFileName, base64_decode($imageData))) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Write new image failed', ERROR_MESSAGE_SUPPORT => "Write new image failed: $pathFileName"]), json_encode([ERROR_MESSAGE_TO_USER => 'Write new image failed', ERROR_MESSAGE_TO_DEVELOPER => "Write new image failed: $pathFileName"]),
ERROR_IO_WRITE); ERROR_IO_WRITE);
} }
...@@ -617,7 +617,7 @@ class Save { ...@@ -617,7 +617,7 @@ class Save {
$sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM); $sitePath = $this->store->getVar(SYSTEM_SITE_PATH, STORE_SYSTEM);
if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) { if ($cwd === false || $sitePath === false || !HelperFile::chdir($sitePath)) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_SUPPORT => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]), json_encode([ERROR_MESSAGE_TO_USER => 'getcwd() failed or SITE_PATH undefined or chdir() failed', ERROR_MESSAGE_TO_DEVELOPER => "getcwd() failed or SITE_PATH undefined or chdir('$sitePath') failed."]),
ERROR_IO_CHDIR); ERROR_IO_CHDIR);
} }
...@@ -913,7 +913,7 @@ class Save { ...@@ -913,7 +913,7 @@ class Save {
// Do 'autoOrient' command // Do 'autoOrient' command
$output = Support::qfqExec($cmd, $rc); $output = Support::qfqExec($cmd, $rc);
if ($rc != 0) { if ($rc != 0) {
throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'copy failed', ERROR_MESSAGE_SUPPORT => "[cmd=$cmd]$output"]), ERROR_IO_COPY); throw new UserFormException(json_encode([ERROR_MESSAGE_TO_USER => 'copy failed', ERROR_MESSAGE_TO_DEVELOPER => "[cmd=$cmd]$output"]), ERROR_IO_COPY);
} }
} }
...@@ -1003,7 +1003,7 @@ class Save { ...@@ -1003,7 +1003,7 @@ class Save {
if ($rc != 0) { if ($rc != 0) {
throw new UserFormException( throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'pdf2svg failed', ERROR_MESSAGE_SUPPORT => "[$cwd][cmd=$cmd]$output"]), json_encode([ERROR_MESSAGE_TO_USER => 'pdf2svg failed', ERROR_MESSAGE_TO_DEVELOPER => "[$cwd][cmd=$cmd]$output"]),
ERROR_PDF2SVG); ERROR_PDF2SVG);
} }
......
...@@ -147,7 +147,7 @@ class Database { ...@@ -147,7 +147,7 @@ class Database {
if ($mysqli->connect_error) { if ($mysqli->connect_error) {
throw new UserFormException ( throw new UserFormException (
json_encode([ERROR_MESSAGE_TO_USER => 'Error open Database', json_encode([ERROR_MESSAGE_TO_USER => 'Error open Database',
ERROR_MESSAGE_SUPPORT => "Error open Database 'mysql:host=" . $config[SYSTEM_DB_SERVER] . ERROR_MESSAGE_TO_DEVELOPER => "Error open Database 'mysql:host=" . $config[SYSTEM_DB_SERVER] .
";dbname=" . $config[SYSTEM_DB_NAME] . ";dbname=" . $config[SYSTEM_DB_NAME] .
";dbuser=" . $config[SYSTEM_DB_USER] . ";dbuser=" . $config[SYSTEM_DB_USER] .
"'': " . $mysqli->connect_errno . PHP_EOL . $mysqli->connect_error]), "'': " . $mysqli->connect_errno . PHP_EOL . $mysqli->connect_error]),
...@@ -159,7 +159,7 @@ class Database { ...@@ -159,7 +159,7 @@ class Database {
if (!$mysqli->set_charset('utf8')) { if (!$mysqli->set_charset('utf8')) {
throw new UserFormException ( throw new UserFormException (
json_encode([ERROR_MESSAGE_TO_USER => "Error set_charset('utf8')", json_encode([ERROR_MESSAGE_TO_USER => "Error set_charset('utf8')",
ERROR_MESSAGE_SUPPORT => "Error set_charset('utf8') Database: " . $mysqli->connect_errno . PHP_EOL . $mysqli->connect_error]), ERROR_MESSAGE_TO_DEVELOPER => "Error set_charset('utf8') Database: " . $mysqli->connect_errno . PHP_EOL . $mysqli->connect_error]),
ERROR_DB_SET_CHARSET); ERROR_DB_SET_CHARSET);
} }
...@@ -375,7 +375,7 @@ class Database { ...@@ -375,7 +375,7 @@ class Database {
if (false === ($this->mysqli_stmt = $this->mysqli->prepare($sql))) { if (false === ($this->mysqli_stmt = $this->mysqli->prepare($sql))) {
$this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray); $this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray);
$errorMsg[ERROR_MESSAGE_SUPPORT] = $this->getSqlHint($sql, $this->mysqli->error); $errorMsg[ERROR_MESSAGE_TO_DEVELOPER] = $this->getSqlHint($sql, $this->mysqli->error);
$errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $this->mysqli->errno . ' ] ' . $this->mysqli->error; $errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $this->mysqli->errno . ' ] ' . $this->mysqli->error;
throw new DbException(json_encode($errorMsg), ERROR_DB_PREPARE); throw new DbException(json_encode($errorMsg), ERROR_DB_PREPARE);
...@@ -384,7 +384,7 @@ class Database { ...@@ -384,7 +384,7 @@ class Database {
if (count($parameterArray) > 0) { if (count($parameterArray) > 0) {
if (false === $this->prepareBindParam($parameterArray)) { if (false === $this->prepareBindParam($parameterArray)) {
$this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray); $this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray);
$errorMsg[ERROR_MESSAGE_SUPPORT] = $this->getSqlHint($sql, $this->mysqli->error); $errorMsg[ERROR_MESSAGE_TO_DEVELOPER] = $this->getSqlHint($sql, $this->mysqli->error);
$errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error; $errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error;
throw new DbException(json_encode($errorMsg), ERROR_DB_BIND); throw new DbException(json_encode($errorMsg), ERROR_DB_BIND);
...@@ -393,7 +393,7 @@ class Database { ...@@ -393,7 +393,7 @@ class Database {
if (false === $this->mysqli_stmt->execute()) { if (false === $this->mysqli_stmt->execute()) {
$this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray); $this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray);
$errorMsg[ERROR_MESSAGE_SUPPORT] = $this->getSqlHint($sql, $this->mysqli->error); $errorMsg[ERROR_MESSAGE_TO_DEVELOPER] = $this->getSqlHint($sql, $this->mysqli->error);
$errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error; $errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error;
throw new DbException(json_encode($errorMsg), ERROR_DB_EXECUTE); throw new DbException(json_encode($errorMsg), ERROR_DB_EXECUTE);
...@@ -409,7 +409,7 @@ class Database { ...@@ -409,7 +409,7 @@ class Database {
case 'EXPLAIN': case 'EXPLAIN':
if (false === ($result = $this->mysqli_stmt->get_result())) { if (false === ($result = $this->mysqli_stmt->get_result())) {
throw new DbException( throw new DbException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error DB execute', ERROR_MESSAGE_SUPPORT => '[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error . $specificMessage]), json_encode([ERROR_MESSAGE_TO_USER => 'Error DB execute', ERROR_MESSAGE_TO_DEVELOPER => '[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error . $specificMessage]),
ERROR_DB_EXECUTE); ERROR_DB_EXECUTE);
} }
...@@ -730,7 +730,7 @@ class Database { ...@@ -730,7 +730,7 @@ class Database {
} }
throw new DbException( throw new DbException(
json_encode([ERROR_MESSAGE_TO_USER => 'Column name not found', ERROR_MESSAGE_SUPPORT => "Column name '$columnName' not found in table '$table'."]), json_encode([ERROR_MESSAGE_TO_USER => 'Column name not found', ERROR_MESSAGE_TO_DEVELOPER => "Column name '$columnName' not found in table '$table'."]),
ERROR_DB_COLUMN_NOT_FOUND_IN_TABLE); ERROR_DB_COLUMN_NOT_FOUND_IN_TABLE);
} }
...@@ -966,16 +966,17 @@ class Database { ...@@ -966,16 +966,17 @@ class Database {
} }
/** /**
* @param $filename * @param $sqlStatements
* *
* @throws \qfq\CodeException * @throws \qfq\CodeException
*/ */
public function playSqlFile($filename) { public function playMultiQuery($sqlStatements) {
$sqlStatements = file_get_contents($filename);
if (false === $this->mysqli->multi_query($sqlStatements)) { $executed = $this->mysqli->multi_query($sqlStatements);
throw new CodeException("Error playing $filename", ERROR_PLAY_SQL_FILE); if (false === $executed) {
$errorMsg[ERROR_MESSAGE_TO_USER] = 'SQL Error.';
$errorMsg[ERROR_MESSAGE_TO_DEVELOPER] = "Error playing multi query: " . $sqlStatements;
throw new CodeException($errorMsg, ERROR_PLAY_SQL_MULTIQUERY);
} }
// discard all results: this is important - if missed, following calls on $mysqli will fail. // discard all results: this is important - if missed, following calls on $mysqli will fail.
...@@ -987,6 +988,24 @@ class Database { ...@@ -987,6 +988,24 @@ class Database {
} }
/**
* @param $filename
*
* @throws \qfq\CodeException
*/
public function playSqlFile($filename) {
$query = file_get_contents($filename);
try {
$this->playMultiQuery($query);
}
catch (CodeException $e) {
throw new CodeException("Error playing $filename", ERROR_PLAY_SQL_FILE);
}
}
/** /**
* @return string * @return string
* @throws CodeException * @throws CodeException
......
...@@ -80,16 +80,16 @@ class DatabaseUpdate { ...@@ -80,16 +80,16 @@ class DatabaseUpdate {
// //
foreach ($arr as $row) { foreach ($arr as $row) {
if (isset($row['Comment'])) { if (isset($row['Comment'])) {
$arr = explode('=', $row['Comment']); parse_str($row['Comment'], $arr);
if (count($arr) == 2 && $arr[0] == 'Version' && $arr[1] != '' AND (version_compare($arr[1], $found) == 1)) { if (($arr['Version'] ?? '') !== '' AND (version_compare($arr['Version'], $found) == 1)) {
$found = $arr[1]; $found = $arr;
} }
} else { } else {
continue; continue;
} }
} }
return $found === '' ? false : $found; return ($found === '') ? false : $found;
} }
/** /**
...@@ -101,7 +101,14 @@ class DatabaseUpdate { ...@@ -101,7 +101,14 @@ class DatabaseUpdate {
*/ */
private function setDatabaseVersion($version) { private function setDatabaseVersion($version) {
$this->db->sql("ALTER TABLE `Form` COMMENT = 'Version=$version'"); if (is_array($version)) {
$versionInfo = $version;
} else {
$versionInfo = $this->getDatabaseVersion();
$versionInfo['Version'] = $version;
}
$this->db->sql("ALTER TABLE `Form` COMMENT = '" . http_build_query($versionInfo) . "'");
} }
...@@ -118,20 +125,28 @@ class DatabaseUpdate { ...@@ -118,20 +125,28 @@ class DatabaseUpdate {
if ($dbUpdate === SYSTEM_DB_UPDATE_NEVER) { if ($dbUpdate === SYSTEM_DB_UPDATE_NEVER) {
return; return;