Commit 70c1d525 authored by Marc Egger's avatar Marc Egger
Browse files

Report as File: disable auto export by default, enable using extension config

parent eb1edced
Pipeline #3870 failed with stages
in 2 minutes and 53 seconds
......@@ -50,6 +50,7 @@ const FORM_BUTTON_CLOSE = 'close';
const FORM_BUTTON_SAVE = 'save';
const REPORT_SAVE = 'reportSave';
const REPORT_SAVE_FILE = 'reportSaveFile'; // 0|1 whether report is saved in file instead of DB
const F_BS_COLUMNS = 'bsColumns';
......@@ -517,6 +518,7 @@ const SYSTEM_RENDER = 'render';
const SYSTEM_RENDER_SINGLE = 'single';
const SYSTEM_RENDER_BOTH = 'both';
const SYSTEM_RENDER_API = 'api';
const SYSTEM_REPORT_AS_FILE_AUTO_EXPORT = 'reportAsFileAutoExport';
const SYSTEM_SHOW_DEBUG_INFO = 'showDebugInfo';
const SYSTEM_SHOW_DEBUG_INFO_YES = 'yes';
......
......@@ -208,7 +208,7 @@ class QuickFormQuery {
// Create report file if file keyword not found
// TODO: ?CR: uid could be 0. When does this happen?
if ($reportPathFileNameFull === null && $t3data[T3DATA_UID] !== 0) {
if (strtolower($this->store->getVar(SYSTEM_REPORT_AS_FILE_AUTO_EXPORT, STORE_SYSTEM)) === 'yes' && $reportPathFileNameFull === null && $t3data[T3DATA_UID] !== 0) {
$reportPathFileNameFull = ReportAsFile::create_file_from_ttContent($t3data[T3DATA_UID], $this->dbArray[$this->dbIndexData]);
}
......@@ -1754,7 +1754,7 @@ class QuickFormQuery {
* @throws \CodeException
* @throws \UserFormException
*/
public static function buildInlineReport(?int $uid, string $reportPathFileNameFull, string $bodytext, string $header): string
public static function buildInlineReport(?int $uid, ?string $reportPathFileNameFull, string $bodytext, string $header): string
{
if ($uid === null) {
return '';
......@@ -1782,7 +1782,7 @@ class QuickFormQuery {
$form = join(' ', [$headerBar, $codeBox]);
$sipObj = new Sip;
$action = $sipObj->queryStringToSip(Path::cwdToApi(API_SAVE_PHP) . "?uid=$uid&" . REPORT_SAVE . "=1");
$action = $sipObj->queryStringToSip(Path::cwdToApi(API_SAVE_PHP) . "?uid=$uid&" . REPORT_SAVE . "=1&" . REPORT_SAVE_FILE . "=" . (is_null($reportPathFileNameFull) ? 0 : 1));
$formAttributes = Support::doAttribute('id', "tt-content-edit-$uid") .
Support::doAttribute('class', 'hidden') .
Support::doAttribute('method', 'post') .
......@@ -1800,13 +1800,18 @@ class QuickFormQuery {
*/
public function saveReport() {
$uid = $this->store->getVar(T3DATA_UID, STORE_SIP . STORE_ZERO, SANITIZE_ALLOW_DIGIT);
$isFile = $this->store->getVar(REPORT_SAVE_FILE, STORE_SIP . STORE_ZERO, SANITIZE_ALLOW_DIGIT);
if ($uid == 0) {
// Check if it was called with a SIP (containing a uid)
// If not, this might be an attack => cancel.
return;
}
$bodytextNew = Support::htmlEntityEncodeDecode(MODE_DECODE, $_POST[REPORT_INLINE_BODYTEXT]);
ReportAsFile::write_file_uid($uid, $bodytextNew, $this->dbArray[$this->dbIndexData]);
if (intval($isFile) === 1) {
ReportAsFile::write_file_uid($uid, $bodytextNew, $this->dbArray[$this->dbIndexData]);
} else {
ReportAsFile::write_tt_content($uid, $bodytextNew, $this->dbArray[$this->dbIndexData]);
}
$this->formSpec[F_FORWARD_MODE] = 'auto';
}
......
......@@ -12,9 +12,10 @@ class ReportAsFile
{
/**
* Finds the keyword file=<pathFileName> and returns pathFileName of report relative to CWD.
* Returns null if the keyword is not present.
*
* @param string $bodyText
* @return string|null pathFileName of report relative to CWD.
* @return string|null pathFileName of report relative to CWD or null
* @throws \CodeException
* @throws \UserFormException
* @throws \UserReportException
......@@ -88,7 +89,7 @@ class ReportAsFile
ERROR_FORM_NOT_FOUND);
}
}
$reportPathFull = HelperFile::joinPathFilename(ReportAsFile::reportPath(), $reportPath);
$reportPathFull = HelperFile::joinPathFilename(self::reportPath(), $reportPath);
// create path in filesystem if not exists
HelperFile::createPathRecursive($reportPathFull);
......@@ -113,6 +114,24 @@ class ReportAsFile
// replace tt-content bodytext with file=<path>
$newBodytext = TOKEN_REPORT_FILE . "=" . HelperFile::joinPathFilename($reportPath, $fileName) . REPORT_FILE_EXTENSION;
self::write_tt_content($uid, $newBodytext, $databaseT3);
return $reportPathFileNameFull;
}
/**
* Replace bodytext of given tt-content element with the given string.
*
* @param int $uid
* @param string $newBodytext
* @param Database $databaseT3
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
public static function write_tt_content(int $uid, string $newBodytext, Database $databaseT3) {
$dbT3 = Store::getInstance()->getVar(SYSTEM_DB_NAME_T3, STORE_SYSTEM);
$sql = "UPDATE `$dbT3`.`tt_content` SET `bodytext` = ?, `tstamp` = UNIX_TIMESTAMP(NOW()) WHERE `uid` = ?";
$databaseT3->sql($sql, ROW_REGULAR, [$newBodytext, $uid]);
......@@ -120,8 +139,6 @@ class ReportAsFile
// Need to truncate cf_cache_pages because it is used to restore page-specific cache
$sql = "DELETE FROM `$dbT3`.`cf_cache_pages`";
$databaseT3->sql($sql);
return $reportPathFileNameFull;
}
/**
......@@ -143,7 +160,7 @@ class ReportAsFile
$ttContent = $databaseT3->sql($sql, ROW_EXPECT_1,
[$uid], "Typo3 content element not found. Uid: $uid");
$reportPathFileNameFull = ReportAsFile::parseFileKeyword($ttContent['bodytext']);
$reportPathFileNameFull = self::parseFileKeyword($ttContent['bodytext']);
if ($reportPathFileNameFull === null) {
throw new \UserReportException(json_encode([
ERROR_MESSAGE_TO_USER => "No report file defined.",
......
......@@ -46,6 +46,9 @@ sendEMailOptions =
# cat=config/config; type=string; label=URL QFQ Documentation:Default is 'http://docs.qfq.io/en/master'. Might be changed to a local repo. Every QFQ installation contains a local copy: <site path>/typo3conf/ext/qfq/Documentation/html/Manual.html (corresponds always to the QFQ version).
documentation =
# cat=config/config; type=string; label=Report as File Auto Export:Default is 'no'. If set to 'yes': When a QFQ tt-content record is rendered which does not contain the "file=" keyword, then its body is exported to a file in the qfq-project directory and the tt-content body is replaced by "file=<path_to_file>".
reportAsFileAutoExport =
# 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'
......
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