From ae6338feb44f5039c781dc13bc656e106128fa74 Mon Sep 17 00:00:00 2001 From: Tymoteusz Motylewski Date: Wed, 7 Feb 2018 12:02:22 +0100 Subject: [PATCH] [BUGFIX] Respect TSconfig option showHistory The TSconfig `options.showHistory` is not respected inside the core. Add checks for list view and context menu. Inside EditDocumentController the "Record History" button is being rendered twice but the TSconfig condition is only checked once. Resolves: #79128 Releases: master, 8.7 Change-Id: Ifa884be5882772e8c267a7eb8036c53cf987bcfb Reviewed-on: https://review.typo3.org/51090 Tested-by: TYPO3com Reviewed-by: Mathias Schreiber Tested-by: Mathias Schreiber Reviewed-by: Andreas Fernandez Reviewed-by: Tymoteusz Motylewski Tested-by: Tymoteusz Motylewski --- .../ItemProviders/RecordProvider.php | 4 +- .../Controller/EditDocumentController.php | 94 +++++++++---------- .../Classes/RecordList/DatabaseRecordList.php | 16 ++-- 3 files changed, 60 insertions(+), 54 deletions(-) diff --git a/typo3/sysext/backend/Classes/ContextMenu/ItemProviders/RecordProvider.php b/typo3/sysext/backend/Classes/ContextMenu/ItemProviders/RecordProvider.php index b369351c0f38..dde8349f2924 100644 --- a/typo3/sysext/backend/Classes/ContextMenu/ItemProviders/RecordProvider.php +++ b/typo3/sysext/backend/Classes/ContextMenu/ItemProviders/RecordProvider.php @@ -459,7 +459,9 @@ protected function canShowInfo(): bool */ protected function canShowHistory(): bool { - return true; + $showHistoryTS = $this->backendUser->getTSConfig('options.showHistory'); + $showHistory = (bool)trim($showHistoryTS['properties'][$this->table] ?? $showHistoryTS['value'] ?? '1'); + return $showHistory; } /** diff --git a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php index cf114983ff6f..c5e87b26ee18 100644 --- a/typo3/sysext/backend/Classes/Controller/EditDocumentController.php +++ b/typo3/sysext/backend/Classes/Controller/EditDocumentController.php @@ -1310,56 +1310,56 @@ protected function getButtons() $buttonBar->addButton($deleteButton, ButtonBar::BUTTON_POSITION_LEFT, 3); } // Undo: - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) - ->getQueryBuilderForTable('sys_history'); - - $undoButtonR = $queryBuilder->select('tstamp') - ->from('sys_history') - ->where( - $queryBuilder->expr()->eq( - 'tablename', - $queryBuilder->createNamedParameter($this->firstEl['table'], \PDO::PARAM_STR) - ), - $queryBuilder->expr()->eq( - 'recuid', - $queryBuilder->createNamedParameter($this->firstEl['uid'], \PDO::PARAM_INT) - ) - ) - ->orderBy('tstamp', 'DESC') - ->setMaxResults(1) - ->execute() - ->fetch(); - - if ($undoButtonR !== false) { - $aOnClick = 'window.location.href=' . - GeneralUtility::quoteJSvalue( - (string)$uriBuilder->buildUriFromRoute( - 'record_history', - [ - 'element' => $this->firstEl['table'] . ':' . $this->firstEl['uid'], - 'revert' => 'ALL_FIELDS', - 'returnUrl' => $this->R_URI, - ] + if ($this->getNewIconMode($this->firstEl['table'], 'showHistory')) { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('sys_history'); + $undoButtonR = $queryBuilder->select('tstamp') + ->from('sys_history') + ->where( + $queryBuilder->expr()->eq( + 'tablename', + $queryBuilder->createNamedParameter($this->firstEl['table'], \PDO::PARAM_STR) + ), + $queryBuilder->expr()->eq( + 'recuid', + $queryBuilder->createNamedParameter($this->firstEl['uid'], \PDO::PARAM_INT) ) - ) . '; return false;'; - - $undoButton = $buttonBar->makeLinkButton() - ->setHref('#') - ->setOnClick($aOnClick) - ->setTitle( - sprintf( - $lang->getLL('undoLastChange'), - BackendUtility::calcAge( - ($GLOBALS['EXEC_TIME'] - $undoButtonR['tstamp']), - $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears') + ) + ->orderBy('tstamp', 'DESC') + ->setMaxResults(1) + ->execute() + ->fetch(); + if ($undoButtonR !== false) { + $aOnClick = 'window.location.href=' . + GeneralUtility::quoteJSvalue( + (string)$uriBuilder->buildUriFromRoute( + 'record_history', + [ + 'element' => $this->firstEl['table'] . ':' . $this->firstEl['uid'], + 'revert' => 'ALL_FIELDS', + 'returnUrl' => $this->R_URI, + ] + ) + ) . '; return false;'; + + $undoButton = $buttonBar->makeLinkButton() + ->setHref('#') + ->setOnClick($aOnClick) + ->setTitle( + sprintf( + $lang->getLL('undoLastChange'), + BackendUtility::calcAge( + ($GLOBALS['EXEC_TIME'] - $undoButtonR['tstamp']), + $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears') + ) ) ) - ) - ->setIcon($this->moduleTemplate->getIconFactory()->getIcon( - 'actions-document-history-open', - Icon::SIZE_SMALL - )); - $buttonBar->addButton($undoButton, ButtonBar::BUTTON_POSITION_LEFT, 3); + ->setIcon($this->moduleTemplate->getIconFactory()->getIcon( + 'actions-document-history-open', + Icon::SIZE_SMALL + )); + $buttonBar->addButton($undoButton, ButtonBar::BUTTON_POSITION_LEFT, 3); + } } if ($this->getNewIconMode($this->firstEl['table'], 'showHistory')) { $aOnClick = 'window.location.href=' . diff --git a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php index 1b3a3d9775d8..ee2bca63a6f1 100644 --- a/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php +++ b/typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php @@ -1956,12 +1956,16 @@ public function makeControl($table, $row) // If the table is NOT a read-only table, then show these links: if ($this->isEditable($table)) { // "Revert" link (history/undo) - $moduleUrl = (string)$uriBuilder->buildUriFromRoute('record_history', ['element' => $table . ':' . $row['uid']]); - $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($moduleUrl) . ',\'#latest\');'; - $historyAction = '' - . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render() . ''; - $this->addActionToCellGroup($cells, $historyAction, 'history'); + $showHistoryTS = $this->getBackendUserAuthentication()->getTSConfig('options.showHistory'); + $showHistory = (bool)trim($showHistoryTS['properties'][$table] ?? $showHistoryTS['value'] ?? '1'); + if ($showHistory) { + $moduleUrl = BackendUtility::getModuleUrl('record_history', ['element' => $table . ':' . $row['uid']]); + $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($moduleUrl) . ',\'#latest\');'; + $historyAction = '' + . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render() . ''; + $this->addActionToCellGroup($cells, $historyAction, 'history'); + } // "Edit Perms" link: if ($table === 'pages' && $this->getBackendUserAuthentication()->check('modules', 'system_BeuserTxPermission') && ExtensionManagementUtility::isLoaded('beuser')) { if ($isL10nOverlay) {