Skip to content
Snippets Groups Projects
Commit b1974b79 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Save.php: Implemented new Formelement.parameter: fileReplace=always - will replace existing files.

parent f59b6ca4
No related branches found
No related tags found
No related merge requests found
......@@ -1217,6 +1217,8 @@ current record, either to finalize the upload or to delete a previous uploaded f
* Using the current record id in the `fileDestination`: Using {{r}} is problematic for new records: that one is still '0'
at the time of saving. Use `{{id:R0}}` instead.
* *fileReplace*=*always*: If `fileDestination` exist - replace it by the new one.
Deleting a record and the referenced file
'''''''''''''''''''''''''''''''''''''''''
......
......@@ -506,6 +506,8 @@ const FE_DATE_FORMAT = 'dateFormat'; // value: FORMAT_DATE_INTERNATIONAL | FORM
const FE_SHOW_SECONDS = 'showSeconds'; // value: 0|1
const FE_SHOW_ZERO = 'showZero'; // value: 0|1
const FE_FILE_DESTINATION = 'fileDestination'; // Target pathFilename for an uploaded file.
const FE_FILE_REPLACE_MODE = 'fileReplace'; // Target pathFilename for an uploaded file.
const FE_FILE_REPLACE_MODE_ALWAYS = 'always'; // Target pathFilename for an uploaded file.
const FE_SQL_VALIDATE = 'sqlValidate'; // Action: Query to validate form load
const FE_EXPECT_RECORDS = 'expectRecords'; // Action: expected number of rows of FE_SQL_VALIDATE
const FE_MESSAGE_FAIL = 'messageFail'; // Action: Message to display, if FE_SQL_VALIDATE fails.
......
......@@ -218,6 +218,7 @@ class Save {
$newValues = array();
$formValues = $this->store->getStore(STORE_FORM);
$primaryRecord = $this->store->getStore(STORE_RECORD); // necessary to check if the current formElement exist as a column of the primary table.
foreach ($this->feSpecNative AS $formElement) {
// skip non upload formElements
......@@ -229,9 +230,10 @@ class Save {
$this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($formElement), STORE_SYSTEM);
$column = $formElement['name'];
$file = $this->doUpload($formElement, $formValues[$column], $sip);
if ($file !== false) {
$newValues[$column] = $file;
$pathFileName = $this->doUpload($formElement, $formValues[$column], $sip);
// Only update (save) the new pathFileName to the primaryRecord if the corresponding column exist.
if ($pathFileName !== false && isset($primaryRecord[$column])) {
$newValues[$column] = $pathFileName;
}
}
......@@ -323,7 +325,13 @@ class Save {
}
if (file_exists($pathFileName)) {
throw new UserFormException('Copy upload failed - file already exist: ' . $pathFileName, ERROR_IO_FILE_EXIST);
if (isset($formElement[FE_FILE_REPLACE_MODE]) && $formElement[FE_FILE_REPLACE_MODE] == FE_FILE_REPLACE_MODE_ALWAYS) {
if (!unlink($pathFileName)) {
throw new UserFormException('Copy upload failed - file exist and unlink() failed: ' . $pathFileName, ERROR_IO_UNLINK);
}
} else {
throw new UserFormException('Copy upload failed - file already exist: ' . $pathFileName, ERROR_IO_FILE_EXIST);
}
}
Support::mkDirParent($pathFileName);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment