From 003f6d63b8231774ee1fb73f870584e447bffe5b Mon Sep 17 00:00:00 2001 From: Carsten Rose <carsten.rose@math.uzh.ch> Date: Fri, 2 Mar 2018 15:28:47 +0100 Subject: [PATCH] Feature #5571 / File Upload: save filesize and mimetype automatically in 'upload mode simple',if those columns exist. --- extension/Documentation/Manual.rst | 17 +++++++++++++---- extension/qfq/qfq/Constants.php | 4 ++-- extension/qfq/qfq/Save.php | 8 ++++++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/extension/Documentation/Manual.rst b/extension/Documentation/Manual.rst index 77aebfa1e..cc52b38b7 100644 --- a/extension/Documentation/Manual.rst +++ b/extension/Documentation/Manual.rst @@ -3428,12 +3428,21 @@ See also `downloadButton`_ to offer a download of an uploaded file. * *sqlBefore*, *sqlAfter*: available in :ref:`Upload simple mode` and :ref:`Upload advanced mode`. * *slaveId*, *sqlInsert*, *sqlUpdate*, *sqlDelete*, *sqlUpdate*: available only in :ref:`Upload advanced mode`. - * To save the `fileSize` and / or `mimeType` (upload simple mode) in the same record as the upload: :: + * `fileSize` / `mimeType` + + * In :ref:`Upload simple mode` the information of `fileSize` and `mimeType` will be automatically updated on the current + record, if table columns `fileSize` and/or `mimeType` exist. + + * If there are more than one Upload FormElement in a form, the automatically update for `fileSize` and/or `mimeType` + can't be used. + + * In :ref:`Upload advanced mode` the `fileSize` and / or `mimeType` have to be updated with an explicit SQL statement:: sqlAfter = {{UPDATE Data SET mimeType='{{mimeType:V}}', fileSize={{fileSize:V}} WHERE id={{id:R}} }} * *fileReplace=always*: If `fileDestination` exist - replace it by the new one. + .. _`downloadButton`: * *downloadButton*: If given, shows a button to download the previous uploaded file - instead of the string given in @@ -5127,9 +5136,9 @@ Special column names +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | _htmlentities |Characters will be encoded to their HTML entity representation. | +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| _mimetype |Show mime type of a given file | +| _fileSize |Show file size of a given file | +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| _filesize |Show file size of a given file | +| _mimeType |Show mime type of a given file | +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | _thumbnail |Create thumbnails on the fly. See `column-thumbnail`_. | +------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ @@ -5162,7 +5171,7 @@ Column: _link +---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+ | | |Render |r:<mode> |r:3 |See: `render-mode`_, Default: 0 | +---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+ -| | |Button |b[:0|1|<btn class>] | b:0, b:1, b:success |'b', 'b:1': a bootstrap button is created. 'b:0' disable the button. <btn class>: default, primary, success, info, warning,danger | +| | |Button | b[:0|1|<btn class>] | b:0, b:1, b:success |'b', 'b:1': a bootstrap button is created. 'b:0' disable the button. <btn class>: default, primary, success, info, warning,danger | +---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+ | |x |Picture |P:<filename> |P:bullet-red.gif |Picture '<img src="bullet-red.gif"alt="....">'. | +---+---+--------------+-----------------------------------+---------------------------+----------------------------------------------------------------------------------------------------------------------------------------+ diff --git a/extension/qfq/qfq/Constants.php b/extension/qfq/qfq/Constants.php index 2155bf843..ac63ba817 100644 --- a/extension/qfq/qfq/Constants.php +++ b/extension/qfq/qfq/Constants.php @@ -1245,8 +1245,8 @@ const COLUMN_NL2BR = 'nl2br'; const COLUMN_HTMLENTITIES = 'htmlentities'; const COLUMN_STRIPTAGS = 'striptags'; -const COLUMN_MIME_TYPE = 'mimetype'; -const COLUMN_FILE_SIZE = 'filesize'; +const COLUMN_MIME_TYPE = 'mimeType'; // Will also be used to identify equal named columns in upload record. +const COLUMN_FILE_SIZE = 'fileSize'; // Will also be used to identify equal named columns in upload record. const COLUMN_WRAP_TOKEN = '+'; diff --git a/extension/qfq/qfq/Save.php b/extension/qfq/qfq/Save.php index db89fa213..6cf73b8f7 100644 --- a/extension/qfq/qfq/Save.php +++ b/extension/qfq/qfq/Save.php @@ -344,6 +344,14 @@ class Save { // 'Simple Upload': no special action needed, just process the current (maybe modified) value. if ($pathFileName !== false) { $newValues[$column] = $pathFileName; + + if (isset($primaryRecord[COLUMN_FILE_SIZE])) { + $newValues[COLUMN_FILE_SIZE] = $vars[VAR_FILE_SIZE]; + } + + if (isset($primaryRecord[COLUMN_MIME_TYPE])) { + $newValues[COLUMN_MIME_TYPE] = $vars[VAR_FILE_MIME_TYPE]; + } } } else { // 'Advanced Upload' -- GitLab