Commit 483a18c1 authored by Carsten  Rose's avatar Carsten Rose
Browse files

F6289: show debug button for 'All' and 'Per session'. Remove expired logfiles....

F6289: show debug button for 'All' and 'Per session'. Remove expired logfiles. Set new form variables FORM_LOG_FILE_ALL, FORM_LOG_FILE_SESSION.
parent 85e189ac
......@@ -204,9 +204,20 @@ class BuildFormBootstrap extends AbstractBuildForm {
* @throws UserReportException
*/
private function buildLogForm() {
$pageAlias=$this->store::getVar(TYPO3_PAGE_ALIAS, STORE_TYPO3);
return $this->link->renderLink("p:" . $pageAlias . "&form=" . $this->formSpec[F_NAME] . "&" . FORM_LOG_MODE . "=" . FORM_LOG_SESSION .
'|b|G:glyphicon-bell|s|o:Set form in debugmode and show log|c:btn btn-default navbar-btn');
$pageAlias = $this->store::getVar(TYPO3_PAGE_ALIAS, STORE_TYPO3);
$baseUrl = 'p:' . $pageAlias . '&form=' . $this->formSpec[F_NAME];
$baseMisc = '|b|G:glyphicon-bell|s|c:btn btn-default navbar-btn';
$baseTooltip = '|o:Set form in debugmode and show log: ';
$stateAll = ($this->formSpec[FORM_LOG_FILE_ALL] == '') ? '' : ' btn-warning';
$stateSession = ($this->formSpec[FORM_LOG_FILE_SESSION] == '') ? '' : ' btn-warning';
$formLogAll = $this->link->renderLink($baseUrl . "&" . FORM_LOG_MODE . "=" . FORM_LOG_ALL . $baseMisc . $stateAll . $baseTooltip . 'All');
$formLogSession = $this->link->renderLink($baseUrl . "&" . FORM_LOG_MODE . "=" . FORM_LOG_SESSION . $baseMisc . $stateSession . $baseTooltip . ' Per session');
return $formLogAll . $formLogSession;
}
/**
......
......@@ -1302,6 +1302,11 @@ const FORM_LOG_MODE = '_formLogMode'; // Variable to call the form in debug mode
const FORM_LOG_SESSION = 'logSession';
const FORM_LOG_ALL = 'logAll';
const FORM_LOG_HTML_ID = 'formLog-1';
const FORM_LOG_FILE = 'formLogFile';
const FORM_LOG_FILE_SESSION = FORM_LOG_FILE . '_' . FORM_LOG_SESSION;
const FORM_LOG_FILE_ALL = FORM_LOG_FILE . '_' . FORM_LOG_ALL;
const FORM_LOG_FILE_EXPIRE = 1800; // time in seconds after the last
// DOWNLOAD
const DOWNLOAD_MODE = 'mode';
......
......@@ -691,6 +691,37 @@ class QuickFormQuery {
}
/**
* Checks if there is formLog mode active for FORM_LOG_SESSION or FORM_LOG_ALL.
* If yes, set $form[FORM_LOG_FILE_SESSION] resp. $form[FORM_LOG_FILE_ALL].
* If the last action is older FORM_LOG_FILE_EXPIRE, the file will be deleted and formLog mode stops (disabled).
*
* @param array $form
* @return array
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
private function checkFormLogMode(array $form) {
$form[FORM_LOG_FILE_SESSION] = '';
$form[FORM_LOG_FILE_ALL] = '';
foreach ([FORM_LOG_SESSION, FORM_LOG_ALL] as $mode) {
$file = Support::getFormLogFileName($form[F_NAME], $mode);
if (false !== ($arr = stat($file))) {
if (time() - $arr['mtime'] > FORM_LOG_FILE_EXPIRE) {
unlink($file);
} else {
$form[FORM_LOG_FILE . '_' . $mode] = $file;
}
}
}
return $form;
}
/**
* Get form name
* Check if the form is in log mode: set formLog and return
......@@ -746,6 +777,7 @@ class QuickFormQuery {
$form = $this->dbArray[$this->dbIndexQfq]->sql("SELECT * FROM Form AS f WHERE f.$constant LIKE ? AND f.deleted='no'", ROW_EXPECT_1,
[$formName], 'Form "' . $formName . '" not found or multiple forms with the same name.');
$form = $this->checkFormLogMode($form);
$form = $this->modeCleanFormConfig($mode, $form);
// Save specific elements to be expanded later.
......
......@@ -60,30 +60,32 @@ class Support {
* Build the form log filename. Depending on $formLog=FORM_LOG_ALL one file for all BE_USER, or $formLog=FORM_LOG_SESSION one file per BE_USER.
*
* @param $formName
* @param $formLog
* @param $formLogMode
* @return string
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
*/
public static function getFormLogFileName($formName, $formLog) {
public static function getFormLogFileName($formName, $formLogMode) {
if (!isset(self::$store)) {
self::$store = Store::getInstance();
}
switch ($formLog) {
switch ($formLogMode) {
case FORM_LOG_ALL:
$perBeSession = '';
break;
case FORM_LOG_SESSION:
$perBeSession = self::$store->getVar(TYPO3_BE_USER, STORE_SYSTEM) . '.';
$perBeSession = self::$store->getVar(TYPO3_BE_USER, STORE_TYPO3) . '.';
break;
default:
throw new CodeException('Unknown mode: ' . $formLog, ERROR_UNKNOWN_TOKEN);
throw new CodeException('Unknown mode: ' . $formLogMode, ERROR_UNKNOWN_TOKEN);
}
return self::$store->getVar(SYSTEM_LOG_DIR, STORE_SYSTEM) . $formName . "." . $perBeSession . "log";
$filename = self::$store->getVar(SYSTEM_LOG_DIR, STORE_SYSTEM) . '/' . $formName . "." . $perBeSession . "log";
return sanitize::safeFilename($filename, false, true);
}
/**
......
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