Commit 064d3047 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Merge branch '4901PdfSplit'

parents 25c9a39e c58b35eb
Pipeline #1045 passed with stage
in 2 minutes and 24 seconds
......@@ -3641,6 +3641,11 @@ file per PDF page. The split is done via http://www.cityinthesky.co.uk/opensourc
* *FormElement.parameter*:
* *fileSplit* = `<type>` - Activate the splitting process. Possible values: `svg` or `jpeg`. No default.
* *fileSplitOptions* = `<command line options>`.
* [svg] - no default
* [jpeg] - default: `-density 150 -quality 90`
* *fileDestinationSplit* = `<pathFileName (pattern)>` - Target directory and filename pattern for the created &
split'ed files. Default <fileDestination>.split/split.<nr>.<fileSplit>
If explicit given, respect that SVG needs a printf style for <nr>, whereas JPEG is numbered automatically. E.g. ::
......@@ -3650,6 +3655,7 @@ file per PDF page. The split is done via http://www.cityinthesky.co.uk/opensourc
* *tableNameSplit* = `<tablename>` - Default: name of table of current form. This name will be saved in table `Split`
The splitting happens immediately after the user pressed `save`.
To easily access the split files via QFQ, per file one record is created in table 'Split'.
......@@ -5280,24 +5286,31 @@ Special column names
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Reserved column name | Purpose |
+========================+=============================================================================================================================================================================================+
| _link |Easily create links with different features. |
| _link | `column-link`_ - Build links with different features. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _mailto |Quickly create email links. A click on the link will open the default mailer. The address is encrypted via JS against email bots. |
| _pageX or _PageX | `column_pageX`_ - Shortcut version of the link interface for fast creation of internal links. The column name is composed of the string *page*/*Page* and a optional character to specify |
| | the type of the link. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _pageX or _PageX |Shortcut version of the link interface for fast creation of internal links. The column name is composed of the string *page*/*Page* and a optional character to specify the type of the link.|
| _download | `download`_ - single file (any type) or concatenate multiple files (PDF, ZIP) |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _pdf, _file, _zip |Shortcut version of the link interface for fast creation of `download`_ links. Used to offer single file download or to concatenate several PDFs and printout of websites to one PDF file. |
| _Pdf, _File, _Zip | |
| _pdf, _file, _zip | `column_pdf`_ - Shortcut version of the link interface for fast creation of `download`_ links. Used to offer single file download or to concatenate several PDFs and printout of websites |
| _Pdf, _File, _Zip | to one PDF file. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _savePdf | `savePdf`_ - pre render PDF files |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _excel | `excel-export`_ - creates Excel exports based on QFQ Report queries, optional with pre uploaded Excel template files |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _yank | `copyToClipboard`_. Shortcut version of the link interface |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _sendmail |Send emails. |
| _mailto | `column_mailto`_ - Build email links. A click on the link will open the default mailer. The address is encrypted via JS against email bots. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _sendmail | `sendmail`_ - Send emails. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _exec |Run batch files or executables on the webserver. |
| _exec | `exec`_ - Run batch files or executables on the webserver. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _vertical |Render Text vertically. This is useful for tables with limited column width. |
| _vertical | `vertical`_ - Render Text vertically. This is useful for tables with limited column width. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _img |Display images. |
| _img | `img`_ - Display images. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _bullet |Display a blue/gray/green/pink/red/yellow bullet. If none color specified, show nothing. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
......@@ -5313,9 +5326,9 @@ Special column names
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _mimeType |Show mime type of a given file |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _thumbnail |Create thumbnails on the fly. See `column-thumbnail`_. |
| _thumbnail | `thumbnail`_ - Create thumbnails on the fly. See `column-thumbnail`_. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _monitor |Constantly display a file. See `column-monitor`_. |
| _monitor | `column-monitor`_ - Constantly display a file. See `column-monitor`_. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| _XLS |Used for Excel export. Append a `newline` character at the end of the string. Token must be part of string. See `excel-export`_. |
+------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
......
......@@ -983,6 +983,8 @@ const FE_FILE_CAPTURE = 'capture'; // On a smartphone opens the camera
const FE_FILE_SPLIT = 'fileSplit';
const FE_FILE_SPLIT_SVG = 'svg';
const FE_FILE_SPLIT_JPEG = 'jpeg';
const FE_FILE_SPLIT_OPTIONS = 'fileSplitOptions';
const FE_FILE_SPLIT_OPTIONS_JPEG = '-density 150 -quality 90';
const FE_FILE_SPLIT_TABLE_NAME = 'tableNameSplit';
const FE_FILE_DOWNLOAD_BUTTON = 'downloadButton';
const FE_FILE_AUTO_ORIENT = 'autoOrient';
......
......@@ -57,7 +57,6 @@ class Delete {
* @throws UserFormException
*/
public function process($tableName, $recordId, $primaryKey = F_PRIMARY_KEY_DEFAULT) {
$msg = array();
if ($tableName === false || $tableName === '') {
throw new CodeException('Missing table name', ERROR_MISSING_TABLE_NAME);
......@@ -96,7 +95,7 @@ class Delete {
/**
* Iterates over array $row and searches for column names with substring COLUMN_PATH_FILE_NAME.
* For any found, check if it references a writeable file.
* For any column found, check if it references a writable file.
* If yes: check if there are other records (same table, same column) which references the same file.
* If no: delete the file
* If yes: do nothing, continue with the next column.
......@@ -113,6 +112,7 @@ class Delete {
private function deleteReferencedFiles(array $row, $tableName, $primaryKey) {
foreach ($row AS $key => $file) {
if (false === strpos($key, COLUMN_PATH_FILE_NAME)) {
continue;
}
......@@ -125,8 +125,10 @@ class Delete {
$samePathFileName = $this->db->sql("SELECT COUNT($primaryKey) AS cnt FROM $tableName WHERE $key LIKE ?", ROW_EXPECT_1, [$file]);
if ($samePathFileName['cnt'] === 1) {
HelperFile::unlink($file);
$this->db->deleteSplitFileAndRecord($row[$primaryKey], $tableName);
}
}
}
}
}
\ No newline at end of file
......@@ -588,6 +588,7 @@ class Save {
$arr = $sip->getVarsFromSip($sipUpload);
$oldFile = $arr[EXISTING_PATH_FILE_NAME];
if (file_exists($oldFile)) {
//TODO: it might be possible to delete a file, which is referenced by another record - a check would be nice.
HelperFile::unlink($oldFile);
}
$flagDelete = ($oldFile != '');
......@@ -743,7 +744,6 @@ class Save {
*
* @param array $formElement
* @param array $statusUpload
*
* @return array|mixed|null|string
* @throws CodeException
* @throws DbException
......@@ -804,7 +804,7 @@ class Save {
/**
* If fe['autoOrient'] is given and the MimeType corresponds to fe['autoOrientMimeType']: the given {{pathFileName:V}} will be converted.
* ImageMagick 'convert' seems to do a better job than GraficsMagick (Orientation is stable even if multiple applied).
* ImageMagick 'convert' seems to do a better job than GraficsMagick (Orientation is stable even if multiple times applied).
*
* @param array $formElement
* @param $pathFileName
......@@ -862,6 +862,7 @@ class Save {
$fileDestinationSplit = $this->evaluate->parse($formElement[FE_FILE_DESTINATION_SPLIT]);
$fileSplitType = $this->evaluate->parse($formElement[FE_FILE_SPLIT]);
$fileSplitTypeOptions = $this->evaluate->parse($formElement[FE_FILE_SPLIT_OPTIONS]);
$fileSplitTableName = $this->evaluate->parse($formElement[FE_FILE_SPLIT_TABLE_NAME]);
if (empty($fileSplitTableName)) {
......@@ -899,7 +900,10 @@ class Save {
$cmd = 'pdf2svg "' . $newSrc . '" "' . $fileNameDest . '" all';
break;
case FE_FILE_SPLIT_JPEG:
$cmd = 'convert -quality 90 -density 150 "' . $newSrc . '" "' . $fileNameDest . '"';
if ($fileSplitTypeOptions == '') {
$fileSplitTypeOptions = FE_FILE_SPLIT_OPTIONS_JPEG;
}
$cmd = "convert $fileSplitTypeOptions '$newSrc' '$fileNameDest'";
break;
default:
throw new UserFormException("Unknown 'fileSplit' type: " . $formElement[FE_FILE_SPLIT], ERROR_UNKNOWN_TOKEN);
......@@ -920,6 +924,11 @@ class Save {
ERROR_PDF2JPEG);
}
$xId = $this->store->getVar(COLUMN_ID, STORE_RECORD);
// Clean optional existing old split records and files from further uploads.
$this->db->deleteSplitFileAndRecord($xId, $fileSplitTableName);
// IM 'convert' will produce files <file>-1.jpg <file>-10.jpg ... - bring them in natural sort order
natsort($files);
......@@ -927,8 +936,6 @@ class Save {
$tableName = TABLE_NAME_SPLIT;
$sql = "INSERT INTO $tableName (`tableName`, `xId`, `pathFilename`) VALUES (?,?,?)";
$xId = $this->store->getVar(COLUMN_ID, STORE_RECORD);
// 1) Move split files to final location. 2) Created records to reference each split file.
foreach ($files as $file) {
......
......@@ -985,4 +985,28 @@ class Database {
public function getQfqLogFile() {
return ($this->store == null) ? SYSTEM_QFQ_LOG_FILE : $this->store->getVar(SYSTEM_QFQ_LOG, STORE_SYSTEM);
}
/**
* Selects in table 'Split' all records with tableName='$tableName' and xId='$xId'. Deletes all referenced files and records.
*
* @param $xId
* @param $tableName
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
public function deleteSplitFileAndRecord($xId, $tableName) {
$sql = 'SELECT pathFileName FROM ' . TABLE_NAME_SPLIT . ' WHERE tableName=? AND xId=?';
$data = $this->sql($sql, ROW_REGULAR, [$tableName, $xId]);
foreach ($data AS $row) {
if (!empty($row['pathFileName']) && is_writable($row['pathFileName'])) {
HelperFile::unlink($row['pathFileName']);
}
}
$this->sql('DELETE FROM ' . TABLE_NAME_SPLIT . ' WHERE tableName=? AND xId=?', ROW_REGULAR, [$tableName, $xId]);
}
}
\ No newline at end of file
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