Commit 364d9fa2 authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[TASK] Migrate ext:belog to extbase

Change-Id: I1d61119394d00417a9a033f25146fc0d5096d853
Resolves: #34772
Releases: 6.0
Reviewed-on: http://review.typo3.org/9729
Tested-by: Philipp Gampe
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
parent bcd5269b
......@@ -42,6 +42,7 @@
* @package TYPO3
* @subpackage t3lib
* @see tx_belog_webinfo, SC_mod_tools_log_index
* @deprecated and unused since TYPO3 6.0, will be removed two versions later
*/
class t3lib_BEDisplayLog {
var $lastTimeLabel = '';
......@@ -62,6 +63,15 @@ class t3lib_BEDisplayLog {
var $be_user_Array = array(); // Username array (set externally)
/**
* Default constructor logs deprecation
*
* @deprecated since TYPO3 6.0, will be removed in two versions.
*/
public function __construct() {
t3lib_div::logDeprecatedFunction();
}
/**
* Initialize the log table array with header labels.
*
......
......@@ -311,6 +311,23 @@ $TCA['sys_collection'] = array(
),
);
/**
* Table "sys_history":
* Holds history records, the config part is defined in t3lib/stddb/tbl_be.php
*/
$TCA['sys_history'] = array(
'ctrl' => array(
'title' => 'LLL:EXT:lang/locallang_tca.xlf:sys_history',
'label' => 'tablename',
'tstamp' => 'tstamp',
'adminOnly' => TRUE,
'rootLevel' => TRUE,
'hideTable' => TRUE,
'default_sortby' => 'uid DESC',
'dynamicConfigFile' => 'T3LIB:tbl_be.php',
),
);
/**
* Table "sys_languages":
* Defines possible languages used for translation of records in the system
......@@ -335,6 +352,22 @@ $TCA['sys_language'] = array(
)
);
/**
* Table "sys_log":
* Holds log records, the config part is defined in t3lib/stddb/tbl_be.php
*/
$TCA['sys_log'] = array(
'ctrl' => array(
'title' => 'LLL:EXT:lang/locallang_tca.xlf:sys_log',
'label' => 'details',
'tstamp' => 'tstamp',
'adminOnly' => TRUE,
'rootLevel' => TRUE,
'hideTable' => TRUE,
'default_sortby' => 'uid DESC',
'dynamicConfigFile' => 'T3LIB:tbl_be.php',
),
);
/**
* Table "sys_news":
......
......@@ -308,6 +308,7 @@ CREATE TABLE sys_collection_entries (
#
CREATE TABLE sys_history (
uid int(11) unsigned NOT NULL auto_increment,
pid int(11) unsigned DEFAULT '0' NOT NULL,
sys_log_uid int(11) DEFAULT '0' NOT NULL,
history_data mediumtext,
fieldlist text,
......@@ -317,6 +318,7 @@ CREATE TABLE sys_history (
history_files mediumtext,
snapshot tinyint(4) DEFAULT '0' NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid),
KEY recordident_1 (tablename,recuid),
KEY recordident_2 (tablename,tstamp),
KEY sys_log_uid (sys_log_uid)
......@@ -366,6 +368,7 @@ CREATE TABLE sys_refindex (
#
CREATE TABLE sys_log (
uid int(11) unsigned NOT NULL auto_increment,
pid int(11) unsigned DEFAULT '0' NOT NULL,
userid int(11) unsigned DEFAULT '0' NOT NULL,
action tinyint(4) unsigned DEFAULT '0' NOT NULL,
recuid int(11) unsigned DEFAULT '0' NOT NULL,
......@@ -382,6 +385,7 @@ CREATE TABLE sys_log (
workspace int(11) DEFAULT '0' NOT NULL,
NEWid varchar(20) DEFAULT '' NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid),
KEY event (userid,event_pid),
KEY recuidIdx (recuid,uid),
KEY user_auth (type,action,tstamp)
......
......@@ -866,6 +866,68 @@ $TCA['sys_collection'] = array(
)
);
/**
* System log history - keeps a trail of record edits
*/
$TCA['sys_history'] = array(
'ctrl' => $TCA['sys_history']['ctrl'],
'columns' => array(
'sys_log_uid' => array(
'label' => 'sys_log_uid',
'config' => array(
'type' => 'input',
),
),
'history_data' => array(
'label' => 'history_data',
'config' => array(
'type' => 'input',
),
),
'fieldlist' => array(
'label' => 'fieldlist',
'config' => array(
'type' => 'input',
),
),
'recuid' => array(
'label' => 'recuid',
'config' => array(
'type' => 'input',
),
),
'tablename' => array(
'label' => 'tablename',
'config' => array(
'type' => 'input',
),
),
'tstamp' => array(
'label' => 'tstamp',
'config' => array(
'type' => 'input',
),
),
'history_files' => array(
'label' => 'history_files',
'config' => array(
'type' => 'input',
),
),
'snapshot' => array(
'label' => 'snapshot',
'config' => array(
'type' => 'input',
),
),
),
'types' => array(
'1' => array(
'showitem' => 'sys_log_uid, history_data, fieldlist, recuid, tablename, tstamp, history_files, snapshot',
),
),
);
/**
* System languages - Defines possible languages used for translation of records in the system
*/
......@@ -927,6 +989,109 @@ $TCA['sys_language'] = array(
)
);
/**
* System log
*/
$TCA['sys_log'] = array(
'ctrl' => $TCA['sys_log']['ctrl'],
'columns' => array(
'tstamp' => array(
'label' => 'tstamp',
'config' => array(
'type' => 'input',
),
),
'userid' => array(
'label' => 'userid',
'config' => array(
'type' => 'input',
),
),
'action' => array(
'label' => 'action',
'config' => array(
'type' => 'input',
),
),
'recuid' => array(
'label' => 'recuid',
'config' => array(
'type' => 'input',
),
),
'tablename' => array(
'label' => 'tablename',
'config' => array(
'type' => 'input',
),
),
'recpid' => array(
'label' => 'recpid',
'config' => array(
'type' => 'input',
),
),
'error' => array(
'label' => 'error',
'config' => array(
'type' => 'input',
),
),
'details' => array(
'label' => 'details',
'config' => array(
'type' => 'input',
),
),
'type' => array(
'label' => 'type',
'config' => array(
'type' => 'input',
),
),
'detail_nr' => array(
'label' => 'detail_nr',
'config' => array(
'type' => 'input',
),
),
'IP' => array(
'label' => 'IP',
'config' => array(
'type' => 'input',
),
),
'log_data' => array(
'label' => 'log_data',
'config' => array(
'type' => 'input',
),
),
'event_pid' => array(
'label' => 'event_pid',
'config' => array(
'type' => 'input',
),
),
'workspace' => array(
'label' => 'workspace',
'config' => array(
'type' => 'input',
),
),
'NEWid' => array(
'label' => 'NEWid',
'config' => array(
'type' => 'input',
),
),
),
'types' => array(
'1' => array(
'showitem' => 'tstamp, userid, action, recuid, tablename, recpid, error, details, type, details_nr, IP, log_data, event_pid, workspace, NEWid',
),
),
);
/**
* System News (displayed on Login screen)
......
<?php
/***************************************************************
* Copyright notice
*
* (c) 2012 Christian Kuhn <lolli@schwarzbu.ch>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Abstract class to show log entries from sys_log
*
* @author Christian Kuhn <lolli@schwarzbu.ch>
* @package TYPO3
* @subpackage belog
*/
abstract class Tx_Belog_Controller_AbstractController extends Tx_Extbase_MVC_Controller_ActionController {
/**
* @var integer
*/
const TIMEFRAME_THISWEEK = 0;
/**
* @var integer
*/
const TIMEFRAME_LASTWEEK = 1;
/**
* @var integer
*/
const TIMEFRAME_LASTSEVENDAYS = 2;
/**
* @var integer
*/
const TIMEFRAME_THISMONTH = 10;
/**
* @var integer
*/
const TIMEFRAME_LASTMONTH = 11;
/**
* @var integer
*/
const TIMEFRAME_LAST31DAYS = 12;
/**
* @var integer
*/
const TIMEFRAME_CUSTOM = 30;
/**
* whether plugin is running in page context (sub module of Web > Info)
*
* @var boolean
*/
protected $isInPageContext = FALSE;
/**
* page ID in page context
*
* @var integer
*/
protected $pageId = 0;
/**
* @var Tx_Belog_Domain_Repository_LogEntryRepository
*/
protected $logEntryRepository = NULL;
/**
* Injects the log entry repository.
*
* @param Tx_Belog_Domain_Repository_LogEntryRepository $logEntryRepository
* @return void
*/
public function injectLogEntryRepository(Tx_Belog_Domain_Repository_LogEntryRepository $logEntryRepository) {
$this->logEntryRepository = $logEntryRepository;
}
/**
* Initialize index action
*
* @return void
*/
public function initializeIndexAction() {
// @TODO: Extbase backend modules rely on frontend TypoScript for view, persistence
// and settings. Thus, we need a TypoScript root template, that then loads the
// ext_typoscript_setup.txt file of this module. This is nasty, but can not be
// circumvented until there is a better solution in extbase.
// For now we throw an exception if no settings are detected.
if (empty($this->settings)) {
throw new RuntimeException(
'No settings detected. This usually happens if there is no frontend TypoScript template with root flag set. ' .
'Please create one.',
1333650506
);
}
if (!isset($this->settings['dateFormat'])) {
$this->settings['dateFormat'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
}
if (!isset($this->settings['timeFormat'])) {
$this->settings['timeFormat'] = $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
}
// @TODO: The dateTime property mapper throws exceptions that cannot be caught
// if the property is not given in the expected format. This is documented with
// issue http://forge.typo3.org/issues/33861. Depending on the outcome of the
// ticket, the code below might have to be adapted again.
// @TODO: There is a second solution to hint the property mapper with fluid on the expected
// format: <f:form.hidden property="manualDateStart.dateFormat" value="..." />. This
// could make the method below obsolete.
$this->configurePropertyMapperForDateTimeFormat($this->arguments['constraint']->getPropertyMappingConfiguration()->forProperty('manualDateStart'));
$this->configurePropertyMapperForDateTimeFormat($this->arguments['constraint']->getPropertyMappingConfiguration()->forProperty('manualDateStop'));
}
/**
* Show general information and the installed modules
*
* @param Tx_Belog_Domain_Model_Constraint $constraint
* @return void
*/
public function indexAction(Tx_Belog_Domain_Model_Constraint $constraint = NULL) {
// Constraint object handling:
// If there is none from GET, try to get it from BE user data, else create new
if ($constraint === NULL) {
$constraint = $this->getConstraintFromBeUserData();
if ($constraint === NULL) {
$constraint = $this->objectManager->create('Tx_Belog_Domain_Model_Constraint');
}
} else {
$this->persistConstraintInBeUserData($constraint);
}
$constraint->setIsInPageContext($this->isInPageContext);
$constraint->setPageId($this->pageId);
$this->setStartAndEndTimeFromTimeSelector($constraint);
$this->forceWorkspaceSelectionIfInWorkspace($constraint);
$logEntries = $this->logEntryRepository->findByConstraint($constraint);
$groupedLogEntries = $this->groupLogEntriesByPageAndDay($logEntries, $constraint->getGroupByPage());
$this->view
->assign('groupedLogEntries', $groupedLogEntries)
->assign('constraint', $constraint)
->assign('userGroups', $this->createUserAndGroupListForSelectOptions())
->assign('workspaces', $this->createWorkspaceListForSelectOptions())
->assign('pageDepths', $this->createPageDepthOptions());
}
/**
* Get module states (the constraint object) from user data
*
* @return Tx_Belog_Domain_Model_Constraint|NULL
*/
protected function getConstraintFromBeUserData() {
$serializedConstraint = $GLOBALS['BE_USER']->getModuleData(get_class($this));
if (!is_string($serializedConstraint) || empty($serializedConstraint)) {
return NULL;
}
return @unserialize($serializedConstraint);
}
/**
* Save current constraint object in be user settings (uC)
*
* @param Tx_Belog_Domain_Model_Constraint $constraint
* @return void
*/
protected function persistConstraintInBeUserData(Tx_Belog_Domain_Model_Constraint $constraint) {
$GLOBALS['BE_USER']->pushModuleData(get_class($this), serialize($constraint));
}
/**
* Create a sorted array for day and page view from
* the query result of the sys log repository.
*
* If group by page is FALSE, pid is always -1 (will render a flat list),
* otherwise the output is splitted by pages.
* '12345' is a sub array to split entries by day, number is first second of day
*
* [pid][dayTimestamp][items]
*
* @param Tx_Extbase_Persistence_QueryResult<Tx_Belog_Domain_Model_LogEntry> $logEntries
* @param boolean $groupByPage Wether or not log entries should be grouped by page
* @return array
*/
protected function groupLogEntriesByPageAndDay(Tx_Extbase_Persistence_QueryResult $logEntries, $groupByPage = FALSE) {
$targetStructure = array();
/** @var $entry Tx_Belog_Domain_Model_LogEntry */
foreach ($logEntries as $entry) {
// Create page split list or flat list
if ($groupByPage) {
$pid = $entry->getEventPid();
} else {
$pid = -1;
}
// Create array if it is not defined yet
if (!is_array($targetStructure[$pid])) {
$targetStructure[$pid] = array();
}
// Get day timestamp of log entry and create sub array if needed
$timestampDay = strtotime(strftime('%d.%m.%Y', $entry->getTstamp()));
if (!is_array($targetStructure[$pid][$timestampDay])) {
$targetStructure[$pid][$timestampDay] = array();
}
// Add row
$targetStructure[$pid][$timestampDay][] = $entry;
}
ksort($targetStructure);
return $targetStructure;
}
/**
* Configure the property mapper to expect date strings in configured BE format
*
* @param Tx_Extbase_Property_PropertyMappingConfiguration $propertyMapperDate
* @return void
*/
protected function configurePropertyMapperForDateTimeFormat(Tx_Extbase_Property_PropertyMappingConfiguration $propertyMapperDate) {
$propertyMapperDate->setTypeConverterOption(
'Tx_Extbase_Property_TypeConverter_DateTimeConverter',
Tx_Extbase_Property_TypeConverter_DateTimeConverter::CONFIGURATION_DATE_FORMAT,
$this->settings['dateFormat'] . ' ' . $this->settings['timeFormat']
);
}
/**
* Create options for the user / group drop down.
* This is not moved to a repository by intention to not mix up this 'meta' data
* with real repository work
*
* @return array Key is the option name, value its label
*/
protected function createUserAndGroupListForSelectOptions() {
$userGroupArray = array();
// Two meta entries: 'all' and 'self'
$userGroupArray[0] = Tx_Extbase_Utility_Localization::translate('allUsers', 'Belog');
$userGroupArray[-1] = Tx_Extbase_Utility_Localization::translate('self', 'Belog');
// List of groups, key is gr-'uid'
$groups = t3lib_BEfunc::getGroupNames();
foreach ($groups as $group) {
$userGroupArray['gr-' . $group['uid']] = Tx_Extbase_Utility_Localization::translate('group', 'Belog') . ' ' . $group['title'];
}
// List of users, key is us-'uid'
$users = t3lib_BEfunc::getUserNames();
foreach ($users as $user) {
$userGroupArray['us-' . $user['uid']] = Tx_Extbase_Utility_Localization::translate('user', 'Belog') . ' ' . $user['username'];
}
return $userGroupArray;
}
/**
* Create options for the workspace selector
*
* @return array Key is uid of workspace, value its label
*/
protected function createWorkspaceListForSelectOptions() {
if (!t3lib_extMgm::isLoaded('workspaces')) {
return array();
}
$workspaceArray = array();
// Two meta entries: 'all' and 'live'
$workspaceArray[-99] = Tx_Extbase_Utility_Localization::translate('any', 'Belog');
$workspaceArray[0] = Tx_Extbase_Utility_Localization::translate('live', 'Belog');
$workspaces = $this->objectManager->get('Tx_Belog_Domain_Repository_WorkspaceRepository')->findAll();
/** @var $workspace Tx_Belog_Domain_Model_Workspace */
foreach ($workspaces as $workspace) {
$workspaceArray[$workspace->getUid()] = $workspace->getUid() . ': ' . $workspace->getTitle();
}
return $workspaceArray;
}
/**
* If the user is in a workspace different than LIVE,
* we force to show only log entries from the selected workspace,
* and the workspace selector is not shown.
*
* @param Tx_Belog_Domain_Model_Constraint $constraint
* @return void
*/
protected function forceWorkspaceSelectionIfInWorkspace(Tx_Belog_Domain_Model_Constraint $constraint) {
if ($GLOBALS['BE_USER']->workspace !== 0) {
$constraint->setWorkspaceUid($GLOBALS['BE_USER']->workspace);
$this->view->assign('showWorkspaceSelector', FALSE);
} else {
$this->view->assign('showWorkspaceSelector', TRUE);
}
}
/**
* Create options for the 'depth of page levels' selector.
* This is shown if the module is displayed in page -> info
*
* @return array Key is depth identifier (1 = One level), value the localized select option label
*/
protected function createPageDepthOptions() {
$options = array(
0 => Tx_Extbase_Utility_Localization::translate(