[!!!][TASK] Deprecate FormEngine::getTSCpid() 97/35497/4
authorFrank Nägler <typo3@naegler.net>
Mon, 15 Dec 2014 19:37:34 +0000 (20:37 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Mon, 15 Dec 2014 20:12:01 +0000 (21:12 +0100)
Move the caching getTSCpid() method from FormEngine to
BackendUtility as getTSCpidCached, creating a general
purpose method for this case to save some db queries
if that is OK with calling code. Adapt usages and
deprecate old method within FormEngine.

Resolves: #63889
Releases: master
Change-Id: I4037a9635c8814a3db869d532ebc9f2826128157
Reviewed-on: http://review.typo3.org/35497
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Frank Nägler <typo3@naegler.net>
Tested-by: Frank Nägler <typo3@naegler.net>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/backend/Classes/Form/Element/TextElement.php
typo3/sysext/backend/Classes/Form/FormEngine.php
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-63889-FormEngine-getTSCpid.rst [new file with mode: 0644]

index fc5e6dc..cb4577f 100644 (file)
@@ -85,7 +85,7 @@ class TextElement extends AbstractFormElement {
                        // If the field is configured for RTE and if any flag-field is not set to disable it.
                        if (isset($specialConfiguration['richtext']) && (!$parameters['flag'] || !$row[$parameters['flag']])) {
                                BackendUtility::fixVersioningPid($table, $row);
-                               list($recordPid, $tsConfigPid) = $this->formEngine->getTSCpid($table, $row['uid'], $row['pid']);
+                               list($recordPid, $tsConfigPid) = BackendUtility::getTSCpidCached($table, $row['uid'], $row['pid']);
                                // If the pid-value is not negative (that is, a pid could NOT be fetched)
                                if ($tsConfigPid >= 0) {
                                        $rteSetup = $this->getBackendUserAuthentication()->getTSConfig('RTE', BackendUtility::getPagesTSconfig($recordPid));
index cfdde0d..2a5d551 100644 (file)
@@ -91,14 +91,6 @@ class FormEngine {
        public $cachedAdditionalPreviewLanguages = NULL;
 
        /**
-        * Cache for the real PID of a record. The array key consists for a combined string "<table>:<uid>:<pid>".
-        * The value is an array with two values: first is the real PID of a record, second is the PID value for TSconfig.
-        *
-        * @var array
-        */
-       protected $cache_getTSCpid = array();
-
-       /**
         * @var array
         */
        public $transformedRow = array();
@@ -4201,7 +4193,7 @@ class FormEngine {
         */
        public function getRecordPath($table, $rec) {
                BackendUtility::fixVersioningPid($table, $rec);
-               list($tscPID, $thePidValue) = $this->getTSCpid($table, $rec['uid'], $rec['pid']);
+               list($tscPID, $thePidValue) = BackendUtility::getTSCpidCached($table, $rec['uid'], $rec['pid']);
                if ($thePidValue >= 0) {
                        return BackendUtility::getRecordPath($tscPID, $this->readPerms(), 15);
                }
@@ -4287,13 +4279,11 @@ class FormEngine {
         * @param string $pid PID value
         * @return array Array of two integers; first is the real PID of a record, second is the PID value for TSconfig.
         * @see BackendUtility::getTSCpid()
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8
         */
        public function getTSCpid($table, $uid, $pid) {
-               $key = $table . ':' . $uid . ':' . $pid;
-               if (!isset($this->cache_getTSCpid[$key])) {
-                       $this->cache_getTSCpid[$key] = BackendUtility::getTSCpid($table, $uid, $pid);
-               }
-               return $this->cache_getTSCpid[$key];
+               GeneralUtility::logDeprecatedFunction();
+               return BackendUtility::getTSCpidCached($table, $uid, $pid);
        }
 
        /**
@@ -4360,7 +4350,7 @@ class FormEngine {
                $mainKey = $table . ':' . $row['uid'];
                if (!isset($this->cachedLanguageFlag[$mainKey])) {
                        BackendUtility::fixVersioningPid($table, $row);
-                       list($tscPID) = $this->getTSCpid($table, $row['uid'], $row['pid']);
+                       list($tscPID) = BackendUtility::getTSCpidCached($table, $row['uid'], $row['pid']);
                        /** @var $t8Tools \TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider */
                        $t8Tools = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Configuration\TranslationConfigurationProvider::class);
                        $this->cachedLanguageFlag[$mainKey] = $t8Tools->getSystemLanguages($tscPID, $this->backPath);
index 5a9b9b0..9b5177e 100644 (file)
@@ -3483,7 +3483,6 @@ class BackendUtility {
         * @param int $pid Record pid
         * @return int
         * @internal
-        * @see \TYPO3\CMS\Backend\Form\FormEngine::getTSCpid()
         */
        static public function getPidForModTSconfig($table, $uid, $pid) {
                $retVal = $table == 'pages' && MathUtility::canBeInterpretedAsInteger($uid) ? $uid : $pid;
@@ -3491,6 +3490,33 @@ class BackendUtility {
        }
 
        /**
+        * Return the real pid of a record and caches the result.
+        * The non-cached method needs database queries to do the job, so this method
+        * can be used if code sometimes calls the same record multiple times to save
+        * some queries. This should not be done if the calling code may change the
+        * same record meanwhile.
+        *
+        * @param string $table Tablename
+        * @param string $uid UID value
+        * @param string $pid PID value
+        * @return array Array of two integers; first is the real PID of a record, second is the PID value for TSconfig.
+        */
+       static public function getTSCpidCached($table, $uid, $pid) {
+               // A local first level cache
+               static $firstLevelCache;
+
+               if (!is_array($firstLevelCache)) {
+                       $firstLevelCache = array();
+               }
+
+               $key = $table . ':' . $uid . ':' . $pid;
+               if (!isset($firstLevelCache[$key])) {
+                       $firstLevelCache[$key] = static::getTSCpid($table, $uid, $pid);
+               }
+               return $firstLevelCache[$key];
+       }
+
+       /**
         * Returns the REAL pid of the record, if possible. If both $uid and $pid is strings, then pid=-1 is returned as an error indication.
         *
         * @param string $table Table name
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-63889-FormEngine-getTSCpid.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-63889-FormEngine-getTSCpid.rst
new file mode 100644 (file)
index 0000000..caf6c6d
--- /dev/null
@@ -0,0 +1,26 @@
+=====================================================
+Deprecation: #63889 - Deprecate FormEngine::getTSCpid
+=====================================================
+
+Description
+===========
+
+:php:`FormEngine::getTSCpid()` has been deprecated.
+
+
+Impact
+======
+
+Using :php:`FormEngine::getTSCpid()` of FormEngine class will trigger a deprecation log message.
+
+
+Affected installations
+======================
+
+Instances which use custom form elements, which make use of :php:`FormEngine::getTSCpid()`.
+
+
+Migration
+=========
+
+Use :php:`BackendUtility::getTSCpidCached()` instead.