Commit 0f2659c6 authored by Marc Egger's avatar Marc Egger
Browse files

Refs #10120 insertForm(): update filestats at the end instead of with form insert

parent 97501ec0
Pipeline #3640 failed with stages
in 43 seconds
......@@ -8,7 +8,6 @@ use IMATHUZH\Qfq\Core\Helper\HelperFile;
use IMATHUZH\Qfq\Core\Helper\OnString;
use IMATHUZH\Qfq\Core\Helper\SqlQuery;
// TODO: insertForm(): update filestats at the end instead of with form insert
// TODO: Testen:
// QFQ komplett neu installiert => form dir existiert mit allen form files aktuell.
// QFQ neu installation mit existierenden forms => alte forms sind noch da.
......@@ -155,14 +154,13 @@ class FormAsFile
self::deleteFormDBWithId($formId, $database);
}
// Insert new Form to DB (after filtering allowed columns and adding columns 'name' and 'fileStats')
// Insert new Form to DB (after filtering allowed columns and adding column 'name')
$formSchema = $database->getTableDefinition(TABLE_NAME_FORM);
$formColumns = array_column($formSchema, 'Field');
$insertValues = array_filter($formFromFile, function ($columnName) use ($formColumns) {
return $columnName !== F_ID && in_array($columnName, $formColumns);
}, ARRAY_FILTER_USE_KEY); // array(column => value)
$insertValues[F_NAME] = $formName;
$insertValues[F_FILE_STATS] = $fileStatsNew;
list($sqlFormInsert, $parameterArrayFormInsert) = SqlQuery::insertRecord(TABLE_NAME_FORM, $insertValues);
$formId = $database->sql($sqlFormInsert, ROW_REGULAR, $parameterArrayFormInsert);
......@@ -189,6 +187,11 @@ class FormAsFile
$database->sql($sql, ROW_REGULAR, $parameterArray);
}
}
// Update column fileStats if everything went well
list($sql, $parameterArray) = SqlQuery::updateRecord(TABLE_NAME_FORM, [F_FILE_STATS => $fileStatsNew], $formId);
$database->sql($sql, ROW_REGULAR, $parameterArray);
return true;
}
......
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