Commit 3ba5f4fe authored by Marc Egger's avatar Marc Egger
Browse files

Refs #10120 add return type to function

parent 79def3bf
Pipeline #3610 failed with stages
in 41 seconds
......@@ -291,20 +291,20 @@ class FormAsFile
/**
* Return form name if given record is an existing Form or FormElement.
* Return false otherwise.
* Return null otherwise.
*
* @param int $recordId
* @param string $recordTable
* @param Database $database
* @return string formName|false
* @return string formName|null
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
public static function isFormOrFormElement(int $recordId, string $recordTable, Database $database)
public static function formNameFromFormRelatedRecord(int $recordId, string $recordTable, Database $database): ?string
{
if ($recordId === 0) {
return false;
return null;
}
switch ($recordTable) {
case TABLE_NAME_FORM:
......@@ -325,7 +325,7 @@ class FormAsFile
[$recordId], "Form element with id '$recordId' not found. " . self::errorHintFormImport());
return $formFromDb[F_NAME];
default:
return false;
return null;
}
}
......
......@@ -424,8 +424,8 @@ class QuickFormQuery {
// Make sure form file is writable (before DB changes are made)
// Note: This can't be done earlier because $formModeNew might be changed in the lines above.
$recordFormName = FormAsFile::isFormOrFormElement($recordId, $this->formSpec[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
if ($recordFormName !== false && in_array($formModeNew, [FORM_SAVE, FORM_DRAG_AND_DROP, FORM_DELETE])) {
$recordFormName = FormAsFile::formNameFromFormRelatedRecord($recordId, $this->formSpec[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
if ($recordFormName !== null && in_array($formModeNew, [FORM_SAVE, FORM_DRAG_AND_DROP, FORM_DELETE])) {
FormAsFile::enforceFormFileWritable($recordFormName);
}
......@@ -1030,8 +1030,8 @@ class QuickFormQuery {
[$formName], 'Form "' . $formName . '" not found or multiple forms with the same name.');
// Import Form from file if loaded record is Form/FormElement (If form file was changed, throw exception)
$recordFormName = FormAsFile::isFormOrFormElement($recordId, $form[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
if ($recordFormName !== false) {
$recordFormName = FormAsFile::formNameFromFormRelatedRecord($recordId, $form[F_TABLE_NAME], $this->dbArray[$this->dbIndexQfq]);
if ($recordFormName !== null) {
if(FormAsFile::importForm($recordFormName, $this->dbArray[$this->dbIndexQfq])) {
throw new \UserFormException(json_encode([
ERROR_MESSAGE_TO_USER => 'Form file was changed.',
......
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