[TASK] Use runtime cache for BackendUtility::isRecordLocked 32/51332/4
authorGeorg Ringer <georg.ringer@gmail.com>
Tue, 17 Jan 2017 06:49:22 +0000 (07:49 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Wed, 18 Jan 2017 11:58:19 +0000 (12:58 +0100)
Instead of using $GLOBALS a runtime cache is used.

Resolves: #79345
Releases: master
Change-Id: I2273051c2d52efff5fa578a82ff636748fe7fdf6
Reviewed-on: https://review.typo3.org/51332
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/backend/Tests/Unit/Tree/Pagetree/DataProviderTest.php

index 3b7bf8b..e6b468f 100644 (file)
@@ -3747,8 +3747,13 @@ class BackendUtility
      */
     public static function isRecordLocked($table, $uid)
     {
-        if (!is_array($GLOBALS['LOCKED_RECORDS'])) {
-            $GLOBALS['LOCKED_RECORDS'] = [];
+        $runtimeCache = self::getRuntimeCache();
+        $cacheId = 'backend-recordLocked-' . md5($table . '_' . $uid);
+        $recordLockedCache = $runtimeCache->get($cacheId);
+        if ($recordLockedCache !== false) {
+            $lockedRecords = $recordLockedCache;
+        } else {
+            $lockedRecords = [];
 
             $queryBuilder = static::getQueryBuilderForTable('sys_lockedrecords');
             $result = $queryBuilder
@@ -3772,6 +3777,7 @@ class BackendUtility
                 )
                 ->execute();
 
+            $lang = static::getLanguageService();
             while ($row = $result->fetch()) {
                 // Get the type of the user that locked this record:
                 if ($row['userid']) {
@@ -3781,7 +3787,6 @@ class BackendUtility
                 } else {
                     $userTypeLabel = 'user';
                 }
-                $lang = static::getLanguageService();
                 $userType = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.' . $userTypeLabel);
                 // Get the username (if available):
                 if ($row['username']) {
@@ -3789,8 +3794,8 @@ class BackendUtility
                 } else {
                     $userName = $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.unknownUser');
                 }
-                $GLOBALS['LOCKED_RECORDS'][$row['record_table'] . ':' . $row['record_uid']] = $row;
-                $GLOBALS['LOCKED_RECORDS'][$row['record_table'] . ':' . $row['record_uid']]['msg'] = sprintf(
+                $lockedRecords[$row['record_table'] . ':' . $row['record_uid']] = $row;
+                $lockedRecords[$row['record_table'] . ':' . $row['record_uid']]['msg'] = sprintf(
                     $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.lockedRecordUser'),
                     $userType,
                     $userName,
@@ -3799,8 +3804,8 @@ class BackendUtility
                         $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.minutesHoursDaysYears')
                     )
                 );
-                if ($row['record_pid'] && !isset($GLOBALS['LOCKED_RECORDS'][$row['record_table'] . ':' . $row['record_pid']])) {
-                    $GLOBALS['LOCKED_RECORDS']['pages:' . $row['record_pid']]['msg'] = sprintf(
+                if ($row['record_pid'] && !isset($lockedRecords[$row['record_table'] . ':' . $row['record_pid']])) {
+                    $lockedRecords['pages:' . $row['record_pid']]['msg'] = sprintf(
                         $lang->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.lockedRecordUser_content'),
                         $userType,
                         $userName,
@@ -3811,8 +3816,10 @@ class BackendUtility
                     );
                 }
             }
+            $runtimeCache->set($cacheId, $lockedRecords);
         }
-        return $GLOBALS['LOCKED_RECORDS'][$table . ':' . $uid];
+
+        return $lockedRecords[$table . ':' . $uid];
     }
 
     /**
index d74488e..60e97a7 100644 (file)
@@ -29,7 +29,6 @@ class DataProviderTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitT
     {
         $GLOBALS['TYPO3_CONF_VARS']['BE']['pageTree']['preloadLimit'] = 0;
         $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/tree/pagetree/class.t3lib_tree_pagetree_dataprovider.php']['postProcessCollections'] = [];
-        $GLOBALS['LOCKED_RECORDS'] = [];
         /** @var $backendUserMock \TYPO3\CMS\Core\Authentication\BackendUserAuthentication|\PHPUnit_Framework_MockObject_MockObject */
         $backendUserMock = $this->createMock(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::class);
         $GLOBALS['BE_USER'] = $backendUserMock;