Commit 633b3a33 authored by Carsten  Rose's avatar Carsten Rose
Browse files

F6894 / Upload: chmod for file creation - fixes #6894

parent 451fbcf3
Pipeline #934 passed with stage
in 1 minute and 42 seconds
...@@ -2820,7 +2820,10 @@ See also at specific *FormElement* definitions. ...@@ -2820,7 +2820,10 @@ See also at specific *FormElement* definitions.
| maxFileSize | string | | | maxFileSize | string | |
| fileDestination | string | | | fileDestination | string | |
| fileReplace | string | | | fileReplace | string | |
+------------------------+--------+----------------------------------------------------------------------------------------------------------+ | autoOrient | string | |
| autoOrientCmd | string | |
| autoOrientMimeType | string | |
| chmod | string | |
| slaveId | string | | | slaveId | string | |
| sqlBefore | string | | | sqlBefore | string | |
| sqlInsert | string | | | sqlInsert | string | |
...@@ -3486,6 +3489,8 @@ See also `downloadButton`_ to offer a download of an uploaded file. ...@@ -3486,6 +3489,8 @@ See also `downloadButton`_ to offer a download of an uploaded file.
* *fileReplace* = `always` - If `fileDestination` exist - replace it by the new one. * *fileReplace* = `always` - If `fileDestination` exist - replace it by the new one.
* *chmod* = <unix file permission mode> - e.g. `660` for owner and group read and writeable. Only the numeric mode is allowed.
* autoOrient: images might contain EXIF data (e.g. captured via mobile phones) incl. an orientation tag like TopLeft, * autoOrient: images might contain EXIF data (e.g. captured via mobile phones) incl. an orientation tag like TopLeft,
BottomRight and so on. Web-Browser and other grafic programs often understand and respect those information and rotate BottomRight and so on. Web-Browser and other grafic programs often understand and respect those information and rotate
such images automatically. If not, the image might be displayed in an unwanted oritentation. such images automatically. If not, the image might be displayed in an unwanted oritentation.
......
...@@ -26,7 +26,6 @@ sendEMailOptions = ...@@ -26,7 +26,6 @@ sendEMailOptions =
dateFormat = dd.mm.yyyy dateFormat = dd.mm.yyyy
# cat=dynamic/config; type=string; label=Fill store 'SYSTEM' by SQL 1:Default is empty. SQL query fired during QFQ load. The result have to be exactly one row. That row will be merged to store 'SYSTEM'. Retrieve values via '{{column:Y}}'. Example 'SELECT id AS _periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1' # cat=dynamic/config; type=string; label=Fill store 'SYSTEM' by SQL 1:Default is empty. SQL query fired during QFQ load. The result have to be exactly one row. That row will be merged to store 'SYSTEM'. Retrieve values via '{{column:Y}}'. Example 'SELECT id AS _periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1'
fillStoreSystemBySql1 = fillStoreSystemBySql1 =
......
...@@ -224,6 +224,7 @@ const ERROR_IO_CHDIR = 1310; ...@@ -224,6 +224,7 @@ const ERROR_IO_CHDIR = 1310;
const ERROR_IO_CREATE_FILE = 1311; const ERROR_IO_CREATE_FILE = 1311;
const ERROR_IO_COPY_FILE = 1312; const ERROR_IO_COPY_FILE = 1312;
const ERROR_IO_FILE_NOT_FOUND = 1313; const ERROR_IO_FILE_NOT_FOUND = 1313;
const ERROR_IO_CHMOD = 1314;
//Report //Report
const ERROR_UNKNOWN_LINK_QUALIFIER = 1400; const ERROR_UNKNOWN_LINK_QUALIFIER = 1400;
...@@ -983,6 +984,7 @@ const FE_FILE_AUTO_ORIENT = 'autoOrient'; ...@@ -983,6 +984,7 @@ const FE_FILE_AUTO_ORIENT = 'autoOrient';
const FE_FILE_AUTO_ORIENT_CMD = 'autoOrientCmd'; const FE_FILE_AUTO_ORIENT_CMD = 'autoOrientCmd';
const FE_FILE_AUTO_ORIENT_CMD_DEFAULT = 'convert -auto-orient {{fileDestination:V}} {{fileDestination:V}}.new; mv {{fileDestination:V}}.new {{fileDestination:V}}'; const FE_FILE_AUTO_ORIENT_CMD_DEFAULT = 'convert -auto-orient {{fileDestination:V}} {{fileDestination:V}}.new; mv {{fileDestination:V}}.new {{fileDestination:V}}';
const FE_FILE_AUTO_ORIENT_MIME_TYPE = 'autoOrientMimeType'; const FE_FILE_AUTO_ORIENT_MIME_TYPE = 'autoOrientMimeType';
const FE_FILE_CHMOD = 'chmod';
// Excel Import // Excel Import
const FE_IMPORT_TO_TABLE = 'importToTable'; const FE_IMPORT_TO_TABLE = 'importToTable';
......
...@@ -443,9 +443,9 @@ class Save { ...@@ -443,9 +443,9 @@ class Save {
$this->feSpecNative[$key][FE_MODE_SQL] = $mode; $this->feSpecNative[$key][FE_MODE_SQL] = $mode;
} }
if(isset($formElement[FE_ACCEPT_ZERO_AS_REQUIRED]) && $formElement[FE_ACCEPT_ZERO_AS_REQUIRED] != '0' && if (isset($formElement[FE_ACCEPT_ZERO_AS_REQUIRED]) && $formElement[FE_ACCEPT_ZERO_AS_REQUIRED] != '0' &&
isset($clientValues[$formElement[FE_NAME]]) && $clientValues[$formElement[FE_NAME]]=='0'){ isset($clientValues[$formElement[FE_NAME]]) && $clientValues[$formElement[FE_NAME]] == '0') {
$mode='fake'; // The next if() should never be true. $mode = 'fake'; // The next if() should never be true.
} }
if (!$requiredOff && $mode == FE_MODE_REQUIRED && empty($clientValues[$formElement[FE_NAME]])) { if (!$requiredOff && $mode == FE_MODE_REQUIRED && empty($clientValues[$formElement[FE_NAME]])) {
...@@ -776,8 +776,17 @@ class Save { ...@@ -776,8 +776,17 @@ class Save {
$overwrite = isset($formElement[FE_FILE_REPLACE_MODE]) && $formElement[FE_FILE_REPLACE_MODE] == FE_FILE_REPLACE_MODE_ALWAYS; $overwrite = isset($formElement[FE_FILE_REPLACE_MODE]) && $formElement[FE_FILE_REPLACE_MODE] == FE_FILE_REPLACE_MODE_ALWAYS;
Support::copyFile($srcFile, $pathFileName, $overwrite); Support::copyFile($srcFile, $pathFileName, $overwrite);
// If given, get chmod. Needs to be prefixed with a 0 (=octal) - it should not be quoted! Symbolic mode is not allowed. E.g.: 0660, or 01777
if (empty($formElement[FE_FILE_CHMOD])) {
$chmod = false;
} else {
$chmod = octdec($formElement[FE_FILE_CHMOD]);
}
$this->autoOrient($formElement, $pathFileName); $this->autoOrient($formElement, $pathFileName);
$this->splitUpload($formElement, $pathFileName); HelperFile::doChmod($pathFileName, $chmod);
$this->splitUpload($formElement, $pathFileName, $chmod);
return $pathFileName; return $pathFileName;
} }
...@@ -793,16 +802,16 @@ class Save { ...@@ -793,16 +802,16 @@ class Save {
* @throws UserFormException * @throws UserFormException
* @throws UserReportException * @throws UserReportException
*/ */
private function autoOrient(array $formElement, $pathFileName){ private function autoOrient(array $formElement, $pathFileName) {
// 'autoOrient' wished? // 'autoOrient' wished?
if(!isset($formElement[FE_FILE_AUTO_ORIENT]) || $formElement[FE_FILE_AUTO_ORIENT]=='0' ){ if (!isset($formElement[FE_FILE_AUTO_ORIENT]) || $formElement[FE_FILE_AUTO_ORIENT] == '0') {
return; // No return; // No
} }
// Upload has matching MimeType? // Upload has matching MimeType?
$mimeTypeList = empty($formElement[FE_FILE_AUTO_ORIENT_MIME_TYPE]) ? 'image/jpeg,image/png,image/tiff' : $formElement[FE_FILE_AUTO_ORIENT_MIME_TYPE]; $mimeTypeList = empty($formElement[FE_FILE_AUTO_ORIENT_MIME_TYPE]) ? 'image/jpeg,image/png,image/tiff' : $formElement[FE_FILE_AUTO_ORIENT_MIME_TYPE];
if(!HelperFile::checkFileType($pathFileName, $pathFileName, $mimeTypeList)) { if (!HelperFile::checkFileType($pathFileName, $pathFileName, $mimeTypeList)) {
return; return;
} }
...@@ -823,13 +832,14 @@ class Save { ...@@ -823,13 +832,14 @@ class Save {
* current page/file. * current page/file.
* *
* @param array $formElement * @param array $formElement
* @param $pathFileName * @param string $pathFileName
* @param int $chmod
* @throws CodeException * @throws CodeException
* @throws DbException * @throws DbException
* @throws UserFormException * @throws UserFormException
* @throws UserReportException * @throws UserReportException
*/ */
private function splitUpload(array $formElement, $pathFileName) { private function splitUpload(array $formElement, $pathFileName, $chmod) {
if (empty($formElement[FE_FILE_SPLIT]) || empty($formElement[FE_FILE_DESTINATION_SPLIT])) { if (empty($formElement[FE_FILE_SPLIT]) || empty($formElement[FE_FILE_DESTINATION_SPLIT])) {
return; return;
...@@ -846,7 +856,7 @@ class Save { ...@@ -846,7 +856,7 @@ class Save {
// Filetype testen: nur Dateien splitten die man auch wirklich entpacken kann // Filetype testen: nur Dateien splitten die man auch wirklich entpacken kann
switch ($fileSplit) { switch ($fileSplit) {
case FE_FILE_SPLIT_SVG: case FE_FILE_SPLIT_SVG:
$this->splitSvg($pathFileName, $fileDestinationSplit, $fileSplitTableName); $this->splitSvg($pathFileName, $fileDestinationSplit, $fileSplitTableName, $chmod);
break; break;
default: default:
throw new UserFormException("Unknown 'fileSplit' type: " . $formElement[FE_FILE_SPLIT], ERROR_UNKNOWN_TOKEN); throw new UserFormException("Unknown 'fileSplit' type: " . $formElement[FE_FILE_SPLIT], ERROR_UNKNOWN_TOKEN);
...@@ -857,14 +867,15 @@ class Save { ...@@ -857,14 +867,15 @@ class Save {
* Split's the PDF file $pathFileNameSrc in several SVG-file, one per page. * Split's the PDF file $pathFileNameSrc in several SVG-file, one per page.
* For every created file, a record in table 'Split' is created, storing the pathFileName to the individual file. * For every created file, a record in table 'Split' is created, storing the pathFileName to the individual file.
* *
* @param $pathFileNameSrc * @param string $pathFileNameSrc
* @param $fileDestinationSplit * @param string $fileDestinationSplit
* @param $fileSplitTableName * @param string $fileSplitTableName
* @param int $chmod
* @throws CodeException * @throws CodeException
* @throws DbException * @throws DbException
* @throws UserFormException * @throws UserFormException
*/ */
private function splitSvg($pathFileNameSrc, $fileDestinationSplit, $fileSplitTableName) { private function splitSvg($pathFileNameSrc, $fileDestinationSplit, $fileSplitTableName, $chmod) {
Support::mkDirParent($fileDestinationSplit); Support::mkDirParent($fileDestinationSplit);
...@@ -910,6 +921,7 @@ class Save { ...@@ -910,6 +921,7 @@ class Save {
} }
$rc = rename($file, Support::joinPath($cwd, $fileDestination)); $rc = rename($file, Support::joinPath($cwd, $fileDestination));
HelperFile::doChmod($fileDestination, $chmod);
// Insert records. // Insert records.
$this->db->sql($sql, ROW_REGULAR, [$fileSplitTableName, $this->store->getVar(COLUMN_ID, STORE_RECORD), $fileDestination]); $this->db->sql($sql, ROW_REGULAR, [$fileSplitTableName, $this->store->getVar(COLUMN_ID, STORE_RECORD), $fileDestination]);
......
...@@ -221,4 +221,18 @@ class HelperFile { ...@@ -221,4 +221,18 @@ class HelperFile {
return false; return false;
} }
/**
* @param $pathFileName
* @param bool $chmod
* @throws UserFormException
*/
public static function doChmod($pathFileName, $chmod=false){
if($chmod!==false){
if(false===chmod($pathFileName, $chmod)){
throw new UserFormException("Failed: chmod $chmod '$pathFileName'", ERROR_IO_CHMOD);
}
}
}
} }
\ No newline at end of file
...@@ -1289,6 +1289,7 @@ class Support { ...@@ -1289,6 +1289,7 @@ class Support {
if (!rename($srcFile, $pathFileName)) { if (!rename($srcFile, $pathFileName)) {
throw new UserFormException("Rename file: '$srcFile' > '$pathFileName'", ERROR_IO_RENAME); throw new UserFormException("Rename file: '$srcFile' > '$pathFileName'", ERROR_IO_RENAME);
} }
} }
/** /**
......
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