Commit e0cba001 authored by Marc Egger's avatar Marc Egger
Browse files

form as file: fix infinite loop when column names are adjusted

parent ad5e0dfa
Pipeline #4052 failed with stages
in 3 minutes and 32 seconds
......@@ -27,36 +27,41 @@ class FormAsFile
*
* @param string $formName
* @param Database $database
* @param bool $keepIfNeverExported true: If the form was never exported and file not exists, then export the form from DB
* @return bool True if form has been updated.
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
public static function importForm(string $formName, Database $database): bool
public static function importForm(string $formName, Database $database, bool $keepIfNeverExported = true): bool
{
// Export form from DB if it was never exported before
// Get file stats from database form
list($sql, $parameterArray) = SqlQuery::selectFormByName($formName, [F_ID, F_FILE_STATS]);
$formFromDb = $database->sql($sql, ROW_EXPECT_0_1,
$parameterArray, "Multiple forms with the same name: '$formName'");
if (!isset($formFromDb[F_FILE_STATS]) || !self::isValidFileStats($formFromDb[F_FILE_STATS])) {
self::exportForm($formName, $database);
}
// Get file stats from file system and exit if they are equal
// Get file stats from file system
$cwdToFormFile = self::formPathFileName($formName, $database);
$fileReadException = new \UserFormException(json_encode([
ERROR_MESSAGE_TO_USER => "Form file not found or missing permission: " . baseName($cwdToFormFile),
ERROR_MESSAGE_TO_DEVELOPER => "Form definition file not found or no permission to read file: '$cwdToFormFile'"]),
ERROR_FORM_NOT_FOUND);
if(!file_exists($cwdToFormFile)) {
self::deleteFormDB($formName, $database, "No corresponding form file found.");
throw $fileReadException;
if ($keepIfNeverExported && (!isset($formFromDb[F_FILE_STATS]) || !self::isValidFileStats($formFromDb[F_FILE_STATS]))) {
// if file not exists and form was never exported, then export
self::exportForm($formName, $database);
} else {
self::deleteFormDB($formName, $database, "No corresponding form file found.");
throw $fileReadException;
}
}
$fileStatsNew = self::formFileStatsJson($cwdToFormFile);
if ($fileStatsNew === false) {
self::deleteFormDB($formName, $database, "Failed to read form file stats.");
throw $fileReadException;
}
// if fileStats from DB and file are equal: do nothing
if (array_key_exists(F_FILE_STATS, $formFromDb) && $fileStatsNew === $formFromDb[F_FILE_STATS]) {
return false;
}
......
Supports Markdown
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