[BUGFIX] dbal: return field type information from admin_get_fields() 41/39941/9
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Wed, 3 Jun 2015 22:31:19 +0000 (00:31 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Wed, 1 Jul 2015 07:29:06 +0000 (09:29 +0200)
Deprecate MetaType() which always returned an empty meta fieldtype
with DBAL and move function to getMetadata(). The signature for
getMetadata() includes the field information for the query so that
the cached field metatype can be used before resorting to querying
the DBMS.

Resolves: #67288
Releases: master
Change-Id: I57dbd7501c9e7a62f2164fb755f1d1a73da01a05
Reviewed-on: http://review.typo3.org/39941
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Reviewed-by: Stephan GroƟberndt <stephan@grossberndt.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/core/Documentation/Changelog/master/Deprecation-67288-DeprecateDbalMetaType.rst [new file with mode: 0644]
typo3/sysext/dbal/Classes/Database/DatabaseConnection.php

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-67288-DeprecateDbalMetaType.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-67288-DeprecateDbalMetaType.rst
new file mode 100644 (file)
index 0000000..fae39a5
--- /dev/null
@@ -0,0 +1,23 @@
+==========================================================================
+Deprecation: #67288 - Deprecate Dbal\DatabaseConnection::MetaType() method
+==========================================================================
+
+Description
+===========
+
+The following public functions have been marked for deprecation as the bugfix requires a signature change:
+
+* Dbal\DatabaseConnection->MetaType()
+
+
+Impact
+======
+
+Using this function will throw a deprecation message. Due to missing information the field type cache will
+be bypassed and the DBMS will be queried for the necessary information on each call.
+
+
+Migration
+=========
+
+Switch to ``getMetadata()``and the field name for which you need the ADOdb MetaType information.
index 936d61a..9c2f619 100644 (file)
@@ -1976,8 +1976,24 @@ class DatabaseConnection extends \TYPO3\CMS\Core\Database\DatabaseConnection {
         * @param int $maxLength
         * @throws \RuntimeException
         * @return string Meta type (currently ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype)
+        * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use getMetadata() instead
         */
        public function MetaType($type, $table, $maxLength = -1) {
+               GeneralUtility::logDeprecatedFunction();
+               return $this->getMetadata($type, $table, 'dummyFieldToBypassCache', $maxLength);
+       }
+
+       /**
+        * Return Metadata for native field type (ADOdb only!)
+        *
+        * @param string $type  Native type as reported by admin_get_fields()
+        * @param string $table Table name for which the type is queried. Important for detection of DBMS handler of the query!
+        * @param string $field Field name for which the type is queried. Important for accessing the field information cache.
+        * @param int    $maxLength
+        * @throws \RuntimeException
+        * @return string Meta type (currently ADOdb syntax only, http://phplens.com/lens/adodb/docs-adodb.htm#metatype)
+        */
+       public function getMetadata($type, $table, $field, $maxLength = -1) {
                $this->lastHandlerKey = $this->handler_getFromTableList($table);
                $str = '';
                switch ((string)$this->handlerCfg[$this->lastHandlerKey]['type']) {
@@ -1985,7 +2001,9 @@ class DatabaseConnection extends \TYPO3\CMS\Core\Database\DatabaseConnection {
                                $str = $type;
                                break;
                        case 'adodb':
-                               if (in_array($table, $this->cache_fieldType)) {
+                               if (!empty($this->cache_fieldType[$table][$field])) {
+                                       $str = $this->cache_fieldType[$table][$field]['metaType'];
+                               } else {
                                        $rs = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit('SELECT * FROM ' . $this->quoteFromTables($table), 1);
                                        $str = $rs->MetaType($type, $maxLength);
                                }
@@ -2640,7 +2658,7 @@ class DatabaseConnection extends \TYPO3\CMS\Core\Database\DatabaseConnection {
                                if (is_array($fieldRows)) {
                                        foreach ($fieldRows as $k => $fieldRow) {
                                                settype($fieldRow, 'array');
-                                               $metaType = $this->MetaType($fieldRow['type'], $tableName, $fieldRow['name']);
+                                               $metaType = $this->getMetadata($fieldRow['type'], $tableName, $fieldRow['name']);
                                                $output[$fieldRow['name']] = $this->dbmsSpecifics->transformFieldRowToMySQL($fieldRow, $metaType);
                                        }
                                }