diff --git a/extension/Classes/Core/Form/FormAsFile.php b/extension/Classes/Core/Form/FormAsFile.php index 958af1bf11f8932f4d250eba8835d475f80096bc..2e31b972644d4bc26aa7fc2ea8513558ce752aad 100644 --- a/extension/Classes/Core/Form/FormAsFile.php +++ b/extension/Classes/Core/Form/FormAsFile.php @@ -584,7 +584,7 @@ class FormAsFile } return $jsonFileNames = array_reduce($files, function ($result, $file) { $fileInfo = pathinfo($file); - if ($fileInfo['extension'] === 'json') { + if (array_key_exists('extension', $fileInfo) && $fileInfo['extension'] === 'json') { $result[] = $fileInfo['filename']; } return $result; @@ -681,10 +681,16 @@ class FormAsFile } } - // throw exception if backup file exists $cwdToBackupFile = Path::join($cwdToBackup, $formName . '.' . date('YmdHis') . ".$tag.json"); - if (file_exists($cwdToBackupFile)) { - Thrower::userFormException('Error while trying to backup form file.', "Backup file already exists: $cwdToBackupFile"); + + // add index to filename if backup file with current timestamp already exists + $index = 1; + while (file_exists($cwdToBackupFile)) { + $cwdToBackupFile = Path::join($cwdToBackup, $formName . '.' . date('YmdHis') . ".$index.$tag.json"); + $index ++; + if ($index > 100) { + Thrower::userFormException('Error while trying to backup form file.', 'Infinite loop.'); + } } return $cwdToBackupFile; } diff --git a/extension/Classes/Core/Report/ReportAsFile.php b/extension/Classes/Core/Report/ReportAsFile.php index 4b9c44f178f1d0fc0b22c6fd5ff71de5bcf7b03f..d6d9ab9931e8fb8113715f40ddac1faaa5e23753 100644 --- a/extension/Classes/Core/Report/ReportAsFile.php +++ b/extension/Classes/Core/Report/ReportAsFile.php @@ -215,11 +215,18 @@ class ReportAsFile } } - // throw exception if backup file exists $cwdToBackupFile = Path::join($cwdToBackup, basename($cwdToReportFile, REPORT_FILE_EXTENSION) . '.' . date('YmdHis') . ".json"); - if (file_exists($cwdToBackupFile)) { - Thrower::userFormException('Error while trying to backup report file.', "Backup file already exists: $cwdToBackupFile"); + + // add index to filename if backup file with current timestamp already exists + $index = 1; + while (file_exists($cwdToBackupFile)) { + $cwdToBackupFile = Path::join($cwdToBackup, basename($cwdToReportFile, REPORT_FILE_EXTENSION) . '.' . date('YmdHis') . ".$index.json"); + $index ++; + if ($index > 100) { + Thrower::userFormException('Error while trying to backup report file.', 'Infinite loop.'); + } } + return $cwdToBackupFile; } diff --git a/extension/Tests/Readme.md b/extension/Tests/Readme.md new file mode 100644 index 0000000000000000000000000000000000000000..3b973c2e0414d7b15bfdd7610d9d8a7229185a77 --- /dev/null +++ b/extension/Tests/Readme.md @@ -0,0 +1,24 @@ + +# QFQ Tests + +## PhpUnit + +### Run unit tests from CLI: + +Make sure dev dependencies are installed: +```shell script +# in extension directory +composer update --dev +``` + +Run all tests: +```shell script +# in extension directory +vendor/bin/phpunit --configuration phpunit.xml +``` + +Run single test: +```shell script +# in extension directory +vendor/bin/phpunit --configuration phpunit.xml --filter <test_name> +```