[TASK] Doctrine: Migrate DataHandler last pieces 57/49557/5
authorChristian Kuhn <lolli@schwarzbu.ch>
Tue, 23 Aug 2016 15:25:14 +0000 (17:25 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Tue, 23 Aug 2016 15:49:21 +0000 (17:49 +0200)
Change-Id: I19caa14ddd2d0402f8b1ee79dbd4fdc9d6963f96
Resolves: #77609
Releases: master
Reviewed-on: https://review.typo3.org/49557
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/DataHandling/DataHandler.php

index 2f3edb4..d5df979 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\DataHandling;
 
 use Doctrine\DBAL\DBALException;
 use Doctrine\DBAL\Driver\Statement;
+use Doctrine\DBAL\Types\IntegerType;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
 use TYPO3\CMS\Core\Cache\CacheManager;
@@ -7228,20 +7229,25 @@ class DataHandler
      */
     public function compareFieldArrayWithCurrentAndUnset($table, $id, $fieldArray)
     {
-        // Fetch the original record:
-        $res = $this->databaseConnection->exec_SELECTquery('*', $table, 'uid=' . (int)$id);
-        $currentRecord = $this->databaseConnection->sql_fetch_assoc($res);
+        $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
+        $queryBuilder = $connection->createQueryBuilder();
+        $queryBuilder->getRestrictions()->removeAll();
+        $currentRecord = $queryBuilder->select('*')
+            ->from($table)
+            ->where($queryBuilder->expr()->eq('uid', (int)$id))
+            ->execute()
+            ->fetch();
         // If the current record exists (which it should...), begin comparison:
         if (is_array($currentRecord)) {
-            // Read all field types:
-            $c = 0;
-            $cRecTypes = array();
-            foreach ($currentRecord as $col => $val) {
-                $cRecTypes[$col] = $this->databaseConnection->sql_field_type($res, $c);
-                $c++;
-            }
-            // Free result:
-            $this->databaseConnection->sql_free_result($res);
+            $tableDetails = $connection->getSchemaManager()->listTableDetails($table);
+            $columnRecordTypes = array();
+            foreach ($currentRecord as $columnName => $_) {
+                $columnRecordTypes[$columnName] = '';
+                $type = $tableDetails->getColumn($columnName)->getType();
+                if ($type instanceof IntegerType) {
+                    $columnRecordTypes[$columnName] = 'int';
+                }
+            }
             // Unset the fields which are similar:
             foreach ($fieldArray as $col => $val) {
                 $fieldConfiguration = $GLOBALS['TCA'][$table]['columns'][$col]['config'];
@@ -7249,7 +7255,7 @@ class DataHandler
 
                 // Unset fields if stored and submitted values are equal - except the current field holds MM relations.
                 // In general this avoids to store superfluous data which also will be visualized in the editing history.
-                if (!$fieldConfiguration['MM'] && $this->isSubmittedValueEqualToStoredValue($val, $currentRecord[$col], $cRecTypes[$col], $isNullField)) {
+                if (!$fieldConfiguration['MM'] && $this->isSubmittedValueEqualToStoredValue($val, $currentRecord[$col], $columnRecordTypes[$col], $isNullField)) {
                     unset($fieldArray[$col]);
                 } else {
                     if (!isset($this->mmHistoryRecords[$table . ':' . $id]['oldRecord'][$col])) {