[BUGFIX] Respect TSconfig option showHistory 58/55658/3
authorTymoteusz Motylewski <t.motylewski@gmail.com>
Sat, 10 Feb 2018 21:39:48 +0000 (22:39 +0100)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Sat, 10 Feb 2018 22:19:10 +0000 (23:19 +0100)
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/55658
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
typo3/sysext/backend/Classes/ContextMenu/ItemProviders/RecordProvider.php
typo3/sysext/backend/Classes/Controller/EditDocumentController.php
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index 995c061..9609b84 100644 (file)
@@ -457,7 +457,9 @@ class RecordProvider extends AbstractProvider
      */
     protected function canShowHistory(): bool
     {
-        return true;
+        $showHistoryTS = $this->backendUser->getTSConfig('options.showHistory');
+        $showHistory = (bool)trim($showHistoryTS['properties'][$this->table] ?? $showHistoryTS['value'] ?? '1');
+        return $showHistory;
     }
 
     /**
index 7b5fede..842764b 100644 (file)
@@ -1323,28 +1323,29 @@ class EditDocumentController extends AbstractModule
                     $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)
+                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)
+                            )
                         )
-                    )
-                    ->orderBy('tstamp', 'DESC')
-                    ->setMaxResults(1)
-                    ->execute()
-                    ->fetch();
+                        ->orderBy('tstamp', 'DESC')
+                        ->setMaxResults(1)
+                        ->execute()
+                        ->fetch();
 
-                if ($undoButtonR !== false) {
-                    $aOnClick = 'window.location.href=' .
+                    if ($undoButtonR !== false) {
+                        $aOnClick = 'window.location.href=' .
                         GeneralUtility::quoteJSvalue(
                             BackendUtility::getModuleUrl(
                                 'record_history',
@@ -1356,23 +1357,24 @@ class EditDocumentController extends AbstractModule
                             )
                         ) . '; 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')
+                        $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=' .
index c61aa52..7118b93 100644 (file)
@@ -1500,12 +1500,16 @@ class DatabaseRecordList extends AbstractDatabaseRecordList
         // If the table is NOT a read-only table, then show these links:
         if ($this->isEditable($table)) {
             // "Revert" link (history/undo)
-            $moduleUrl = BackendUtility::getModuleUrl('record_history', ['element' => $table . ':' . $row['uid']]);
-            $onClick = 'return jumpExt(' . GeneralUtility::quoteJSvalue($moduleUrl) . ',\'#latest\');';
-            $historyAction = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
-                . htmlspecialchars($this->getLanguageService()->getLL('history')) . '">'
-                . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render() . '</a>';
-            $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 = '<a class="btn btn-default" href="#" onclick="' . htmlspecialchars($onClick) . '" title="'
+                    . htmlspecialchars($this->getLanguageService()->getLL('history')) . '">'
+                    . $this->iconFactory->getIcon('actions-document-history-open', Icon::SIZE_SMALL)->render() . '</a>';
+                $this->addActionToCellGroup($cells, $historyAction, 'history');
+            }
             // Versioning:
             if (ExtensionManagementUtility::isLoaded('version') && ExtensionManagementUtility::isLoaded('compatibility7') && !ExtensionManagementUtility::isLoaded('workspaces')) {
                 $vers = BackendUtility::selectVersionsOfRecord($table, $row['uid'], 'uid', $this->getBackendUserAuthentication()->workspace, false, $row);