Commit ee8d8e97 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fixes #7925. a) change CWD during split reduced to splitting only. b) fixed...

Fixes #7925. a) change CWD during split reduced to splitting only. b) fixed problem in mkDirParent() with absolute paths, c) make logger independent of CWD, d) fixed problem with `mktemp --tmpdir`(difference Ubuntu 16 / 18) by using PHP function, e) fixed some 'undefined index' problems
parent 787597ed
Pipeline #1554 passed with stage
in 2 minutes and 22 seconds
......@@ -1291,7 +1291,7 @@ If a value violates the sanitize class, instead of content on of the following t
* 'e' - Instead of the value an empty string will be set as content.
* '0' - Instead of the value the string '0' will be set as content.
* 'custom text ...' - Instead of the value the custom text will be set as content. If the text contains a ':', that one needs to
be escaped by '\'. Check `variable-escape`_ qualifier 'C' to let QFQ do the colon escaping.
be escaped by '\'. Check `variable-escape`_ qualifier 'C' to let QFQ do the colon escaping.
.. _`sql-variables`:
......@@ -3623,14 +3623,14 @@ See also `downloadButton`_ to offer a download of an uploaded file.
* *chmodFile* = <unix file permission mode> - e.g. `660` for owner and group read and writeable. Only the numeric mode is allowed.
* *chmodDir* = <unix file permission mode> - e.g. `770` for owner and group read, writeable and executable. Only the
numeric mode is allowed. Will be applied to all new created directories.
numeric mode is allowed. Will be applied to all new created directories.
* 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
such images automatically. If not, the image might be displayed in an unwanted oritentation.
With active option 'autoOrient', QFQ tries to normalize such images via 'convert' (part of ImageMagick). Especially
if images are processed by the QFQ internal 'Fabric'-JS it's recommended to normalize images first. The normalization
process does not solve all orientation problems.
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.
With active option 'autoOrient', QFQ tries to normalize such images via 'convert' (part of ImageMagick). Especially
if images are processed by the QFQ internal 'Fabric'-JS it's recommended to normalize images first. The normalization
process does not solve all orientation problems.
* *autoOrient* = [0|1]
* *autoOrientCmd* = 'convert -auto-orient {{fileDestination:V}} {{fileDestination:V}}.new; mv {{fileDestination:V}}.new {{fileDestination:V}}'
......@@ -3641,7 +3641,7 @@ See also `downloadButton`_ to offer a download of an uploaded file.
.. _`downloadButton`:
* *downloadButton* = `t:<string>` - If given, shows a button to download the previous uploaded file - instead of the string given in
`fe.value`. The button is only shown if `fe.value` points to a readable file on the server.
`fe.value`. The button is only shown if `fe.value` points to a readable file on the server.
* If `downloadButton` is empty, just shows the regular download glyph.
* To just show the filename: `downloadButton = t:{{filenameOnly:V}}`
......
......@@ -386,8 +386,8 @@ class Save {
// No new upload and no existing: take care to remove previous upload file statistics.
$this->store->unsetVar(VAR_FILE_MIME_TYPE, STORE_VAR);
$this->store->unsetVar(VAR_FILE_SIZE, STORE_VAR);
$vars[VAR_FILE_SIZE]=0;
$vars[VAR_FILE_MIME_TYPE]='';
$vars[VAR_FILE_SIZE] = 0;
$vars[VAR_FILE_MIME_TYPE] = '';
} else {
$vars = HelperFile::getFileStat($pathFileNameTmp);
$this->store->appendToStore($vars, STORE_VAR);
......@@ -825,8 +825,7 @@ class Save {
* @throws UserFormException
* @throws UserReportException
*/
private
function copyUploadFile(array $formElement, array $statusUpload) {
private function copyUploadFile(array $formElement, array $statusUpload) {
$pathFileName = '';
if (!isset($statusUpload[FILES_TMP_NAME]) || $statusUpload[FILES_TMP_NAME] === '') {
......@@ -889,8 +888,7 @@ class Save {
* @throws UserFormException
* @throws UserReportException
*/
private
function autoOrient(array $formElement, $pathFileName) {
private function autoOrient(array $formElement, $pathFileName) {
// 'autoOrient' wished?
if (!isset($formElement[FE_FILE_AUTO_ORIENT]) || $formElement[FE_FILE_AUTO_ORIENT] == '0') {
......@@ -931,17 +929,16 @@ class Save {
* @throws UserFormException
* @throws UserReportException
*/
private
function splitUpload(array $formElement, $pathFileName, $chmod, array $statusUpload) {
private function splitUpload(array $formElement, $pathFileName, $chmod, array $statusUpload) {
if (empty($formElement[FE_FILE_SPLIT]) || $statusUpload[FILES_TYPE] != MIME_TYPE_SPLIT_CAPABLE) {
return;
}
$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]);
$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)) {
$fileSplitTableName = $this->formSpec[F_TABLE_NAME];
......@@ -958,12 +955,10 @@ class Save {
$cwd = getcwd();
// Create temporary directory
$tempDir = Support::createTempDir();
$tempDir = HelperFile::mktempdir();
$newSrc = $tempDir . DIRECTORY_SEPARATOR . QFQ_TEMP_SOURCE;
HelperFile::copy($pathFileName, $newSrc);
HelperFile::chdir($tempDir);
// Split destination.
$pathParts = pathinfo($fileDestinationSplit);
if (empty($pathParts['filename']) || empty($pathParts['basename'])) {
......@@ -988,7 +983,10 @@ class Save {
}
// Split PDF
HelperFile::chdir($tempDir);
$output = Support::qfqExec($cmd, $rc);
HelperFile::chdir($cwd);
if ($rc != 0) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'pdf2svg failed', ERROR_MESSAGE_SUPPORT => "[$cwd][cmd=$cmd]$output"]),
......@@ -996,7 +994,7 @@ class Save {
}
// Array of created file names.
if (false === ($files = scandir('.'))) {
if (false === ($files = scandir($tempDir))) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Splitted files not found', ERROR_MESSAGE_SUPPORT => "[cwd=$cwd] scandir(.)" . HelperFile::errorGetLastAsString()]),
ERROR_PDF2JPEG);
......@@ -1027,16 +1025,13 @@ class Save {
$fileDestination = $file;
}
Support::moveFile($file, Support::joinPath($cwd, $fileDestination), true);
Support::moveFile($tempDir . DIRECTORY_SEPARATOR . $file, Support::joinPath($cwd, $fileDestination), true);
HelperFile::chmod($fileDestination, $chmod);
// Insert records.
$this->db->sql($sql, ROW_REGULAR, [$fileSplitTableName, $xId, $fileDestination]);
}
// Pop directory
HelperFile::chdir($cwd);
// Remove duplicated source
HelperFile::unlink($newSrc);
......@@ -1055,8 +1050,7 @@ class Save {
* @throws UserFormException
* @throws UserReportException
*/
private
function doUploadSlave(array $fe, $modeUpload) {
private function doUploadSlave(array $fe, $modeUpload) {
$sql = '';
$flagUpdateSlaveId = false;
$flagSlaveDeleted = false;
......
......@@ -61,6 +61,8 @@ class HelperFile {
/**
* Creates a temporary directory.
* Be aware: '/tmp' is under systemd/apache2 (Ubuntu 18...) remapped to something like: '/tmp/systemd-private-...-apache2.service-.../tmp'
*
* @throws UserFormException
*/
public static function mktempdir() {
......@@ -375,10 +377,18 @@ class HelperFile {
*/
public static function mkDirParent($pathFileName, $chmodDir = false) {
$path = "";
$cwd = '';
// Leading '/' will be removed - chdir to / to still use correct path
if ($pathFileName[0] == '/') {
$cwd = getcwd();
self::chdir('/');
}
// Teile "Directory/File.Extension" auf
$pathParts = pathinfo($pathFileName);
// Zerlege Pfad in einzelne Directories
$arr = explode("/", $pathParts["dirname"]);
......@@ -409,6 +419,10 @@ class HelperFile {
}
$path .= "/";
}
if ($cwd != '') {
self::chdir($cwd);
}
}
/**
......
......@@ -20,6 +20,18 @@ require_once(__DIR__ . '/../helper/Support.php');
*/
class Logger {
/**
* @var String
*/
private static $systemSitePath = '';
/**
* @param $path
*/
public static function setSystemSitePath($path) {
self::$systemSitePath = $path;
}
/**
* Append $msg to $filename.
*
......@@ -32,26 +44,25 @@ class Logger {
*/
public static function logMessage($msg, $filename, $mode = FILE_MODE_APPEND, $recursion = false) {
return;
$handle = false;
if ($filename == '') {
return;
}
$filename = self::relativeToT3Dir($filename);
$filename = self::makePathAbsolute($filename);
try {
$handle = fopen($filename, $mode);
} catch (\Exception $e) {
$dummy=1;
$dummy = 1;
}
$cwd1=getcwd();
$cwd1 = getcwd();
if($handle===false) {
if ($handle === false) {
if($recursion){
if ($recursion) {
throw new UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error: cannot open file',
ERROR_MESSAGE_SUPPORT => "Error - cannot open. File: " . $filename .
......@@ -90,13 +101,25 @@ class Logger {
*
* @param $filename
* @return string
* @throws CodeException
*/
private static function relativeToT3Dir($filename) {
private static function makePathAbsolute($filename) {
if (isset($filename[0]) && $filename[0] != '/') {
if (strpos(getcwd(), 'qfq/' . API_DIR_EXT) !== false) {
return ('../../../../../' . $filename);
if (self::$systemSitePath == '') {
if (defined('PHPUNIT_QFQ')) {
if (strpos(getcwd(), 'qfq/' . API_DIR_EXT) !== false) {
return ('../../../../../' . $filename);
}
return $filename;
}
throw new CodeException('SystemSitePath is not set and the given logfile should be made absolute.', ERROR_MISSING_VALUE);
}
return self::$systemSitePath . DIRECTORY_SEPARATOR . $filename;
}
return $filename;
......
......@@ -209,8 +209,8 @@ class Support {
*
* @param string $type
* @param string|array $value
* @param bool $flagOmitEmpty true|false
* @param string $modeEscape ESCAPE_WITH_BACKSLASH | ESCAPE_WITH_HTML_QUOTE
* @param bool $flagOmitEmpty true|false
* @param string $modeEscape ESCAPE_WITH_BACKSLASH | ESCAPE_WITH_HTML_QUOTE
*
* @return string correctly formatted attribute. Space at the end.
* @throws CodeException
......@@ -990,7 +990,7 @@ class Support {
}
// If min or max is set and if there is the standard error text given, define a more detailed error text.
if (($formElement[FE_MIN] != '' || $formElement[FE_MAX] != '') && ($formElement[F_FE_DATA_ERROR]??'') == F_FE_DATA_ERROR_DEFAULT) {
if (($formElement[FE_MIN] != '' || $formElement[FE_MAX] != '') && ($formElement[F_FE_DATA_ERROR] ?? '') == F_FE_DATA_ERROR_DEFAULT) {
$formElement[F_FE_DATA_ERROR] = F_FE_DATA_ERROR_DEFAULT . ' - allowed values: ' . $formElement[FE_MIN] . '...' . $formElement[FE_MAX];
}
}
......@@ -1281,15 +1281,6 @@ class Support {
HelperFile::unlink($srcFile);
}
/**
*
*/
public static function createTempDir() {
return exec("mktemp -d --tmpdir " . QFQ_TEMP_FILE_PATTERN);
}
/**
* Convert 'false' and '<empty string>' to '0'.
*
......
......@@ -281,6 +281,8 @@ class Store {
}
}
Logger::setSystemSitePath($config[SYSTEM_SITE_PATH]);
return $config;
}
......
......@@ -544,6 +544,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover qfq-subrecord-table" ><thead><tr><th>id</th><th>name</th><th>firstName</th></tr></thead><tbody ><tr class="record" ><td><span class="text-muted">1</span></td><td>Doe</td><td>John</td></tr><tr class="record" ><td><span class="text-muted">2</span></td><td>Smith</td><td>Jane</td></tr></tbody></table>', $result);
// $this->assertEquals('Please save this record first.', $result);
$this->store->setStore(['id' => 1], STORE_RECORD, true);
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
......
......@@ -19,7 +19,7 @@ abstract class AbstractDatabaseTest extends TestCase {
static protected $mysqli = null;
/**
* @var Database
* @var array
*/
protected $dbArray = array();
......
Markdown is supported
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