[TASK] dbal: Ignore MySQL UNSIGNED/ZEROFILL in database schema compare 37/40137/3
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Tue, 9 Jun 2015 17:47:03 +0000 (19:47 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 25 Jun 2015 22:29:40 +0000 (00:29 +0200)
Avoid suggestions for database alterations in the install tool
that can not be implemented on DBMS other than MySQL due to
usage of non-standard attributes.

Resolves: #67335
Releases: master
Change-Id: I749563e0b0abc9b42236f2951222cb2771507a79
Reviewed-on: http://review.typo3.org/40137
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/install/Classes/Service/SqlSchemaMigrationService.php
typo3/sysext/install/Tests/Unit/Service/SqlSchemaMigrationServiceTest.php

index e383e9f..3fce9c7 100644 (file)
@@ -284,6 +284,11 @@ class SqlSchemaMigrationService {
                                                                                        $fieldC
                                                                                );
 
+                                                                               // Ignore nonstandard MySQL numeric field attributes UNSIGNED and ZEROFILL
+                                                                               if ($this->isDbalEnabled() && preg_match('/^(TINYINT|SMALLINT|MEDIUMINT|INT|INTEGER|BIGINT|REAL|DOUBLE|FLOAT|DECIMAL|NUMERIC)\([^\)]+\)\s+(UNSIGNED|ZEROFILL)/i', $fieldC)) {
+                                                                                       $fieldC = str_ireplace(array(' UNSIGNED', ' ZEROFILL'), '', $fieldC);
+                                                                                       $FDcomp[$table][$theKey][$fieldN] = str_ireplace(array(' UNSIGNED', ' ZEROFILL'), '', $FDcomp[$table][$theKey][$fieldN]);
+                                                                               }
                                                                                if ($ignoreNotNullWhenComparing) {
                                                                                        $fieldC = str_replace(' NOT NULL', '', $fieldC);
                                                                                        $FDcomp[$table][$theKey][$fieldN] = str_replace(' NOT NULL', '', $FDcomp[$table][$theKey][$fieldN]);
index cfb86fc..528ebf9 100644 (file)
@@ -437,4 +437,93 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                );
        }
 
+       /**
+        * @test
+        */
+       public function getDatabaseExtraIncludesUnsignedAttributeIfMySQLIsUsed() {
+               $subject = $this->getAccessibleMock(SqlSchemaMigrationService::class, array('isDbalEnabled'), array(), '', FALSE);
+               $subject->expects($this->any())->method('isDbalEnabled')->will($this->returnValue(FALSE));
+               $differenceArray = $subject->getDatabaseExtra(
+                       array(
+                               'tx_foo' => array(
+                                       'fields' => array(
+                                               'foo' => 'INT(11) UNSIGNED DEFAULT \'0\' NOT NULL',
+                                       ),
+                                       'extra' => array(
+                                               'ENGINE' => 'InnoDB'
+                                       )
+                               )
+                       ),
+                       array(
+                               'tx_foo' => array(
+                                       'fields' => array(
+                                               'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
+                                       ),
+                                       'extra' => array(
+                                               'ENGINE' => 'InnoDB'
+                                       )
+                               )
+                       )
+               );
+
+               $this->assertSame(
+                       $differenceArray,
+                       array(
+                               'extra' => array(),
+                               'diff' => array(
+                                       'tx_foo' => array(
+                                               'fields' => array(
+                                                       'foo' => 'int(11) UNSIGNED DEFAULT \'0\' NOT NULL',
+                                               ),
+                                       )
+                               ),
+                               'diff_currentValues' => array(
+                                       'tx_foo' => array(
+                                               'fields' => array(
+                                                       'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
+                                               ),
+                                       )
+                               )
+                       )
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getDatabaseExtraExcludesUnsignedAttributeIfDbalIsUsed() {
+               $subject = $this->getAccessibleMock(SqlSchemaMigrationService::class, array('isDbalEnabled'), array(), '', FALSE);
+               $subject->expects($this->any())->method('isDbalEnabled')->will($this->returnValue(TRUE));
+               $differenceArray = $subject->getDatabaseExtra(
+                       array(
+                               'tx_foo' => array(
+                                       'fields' => array(
+                                               'foo' => 'INT(11) UNSIGNED DEFAULT \'0\' NOT NULL',
+                                       ),
+                                       'extra' => array(
+                                               'ENGINE' => 'InnoDB'
+                                       )
+                               )
+                       ),
+                       array(
+                               'tx_foo' => array(
+                                       'fields' => array(
+                                               'foo' => 'int(11) DEFAULT \'0\' NOT NULL',
+                                       ),
+                                       'extra' => array(
+                                               'ENGINE' => 'InnoDB'
+                                       )
+                               )
+                       )
+               );
+
+               $this->assertSame(
+                       $differenceArray,
+                       array(
+                               'extra' => array(),
+                               'diff' => array(),
+                               'diff_currentValues' => NULL
+                       )
+               );
+       }
 }