[BUGFIX] Respect (NOT) NULL when comparing SQL field definitions 00/36400/4
authorStephan Großberndt <stephan@grossberndt.de>
Fri, 30 Jan 2015 10:23:17 +0000 (11:23 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 31 Jan 2015 16:00:45 +0000 (17:00 +0100)
When comparing the database or updating extensions the definitions for
NULL / NOT NULL in fields are now respected and updated.

Resolves: #64616
Releases: master, 6.2
Change-Id: I70c63339505b373023f24973313a2e673e8eaf86
Reviewed-on: http://review.typo3.org/36400
Tested-by: Ronny Vorpahl <vorpahl@artplan21.de>
Reviewed-by: Mateusz Wojtuła <matw88@gmail.com>
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 24fe8c8..3ca5509 100644 (file)
@@ -243,7 +243,7 @@ class SqlSchemaMigrationService {
         * @param bool $ignoreNotNullWhenComparing If set, this function ignores NOT NULL statements of the SQL file field definition when comparing current field definition from database with field definition from SQL file. This way, NOT NULL statements will be executed when the field is initially created, but the SQL parser will never complain about missing NOT NULL statements afterwards.
         * @return array Returns an array with 1) all elements from $FDsrc that is not in $FDcomp (in key 'extra') and 2) all elements from $FDsrc that is different from the ones in $FDcomp
         */
-       public function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList = '', $ignoreNotNullWhenComparing = TRUE) {
+       public function getDatabaseExtra($FDsrc, $FDcomp, $onlyTableList = '', $ignoreNotNullWhenComparing = FALSE) {
                $extraArr = array();
                $diffArr = array();
                if (is_array($FDsrc)) {
index b94e353..ca4eb9e 100644 (file)
@@ -31,6 +31,7 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                // Multiple whitespaces and tabs in field definition
                $inputString = 'CREATE table atable (' . LF . 'aFieldName   int(11)' . TAB . TAB . TAB . 'unsigned   DEFAULT \'0\'' . LF . ');';
                $result = $subject->getFieldDefinitions_fileContent($inputString);
+
                $this->assertEquals(
                        array(
                                'atable' => array(
@@ -68,7 +69,51 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                        )
                );
 
+               $this->assertEquals(
+                       $differenceArray,
+                       array(
+                               'extra' => array(),
+                               'diff' => array(
+                                       'tx_foo' => array(
+                                               'fields' => array(
+                                                       'foo' => 'varchar(999) DEFAULT \'0\' NOT NULL'
+                                               )
+                                       )
+                               ),
+                               'diff_currentValues' => array(
+                                       'tx_foo' => array(
+                                               'fields' => array(
+                                                       'foo' => 'varchar(255) DEFAULT \'0\' NOT NULL'
+                                               )
+                                       )
+                               )
+                       )
+               );
+       }
 
+       /**
+        * @test
+        */
+       public function getDatabaseExtraFindsChangedFieldsIgnoreNotNull() {
+               $subject = new SqlSchemaMigrationService();
+               $differenceArray = $subject->getDatabaseExtra(
+                       array(
+                               'tx_foo' => array(
+                                       'fields' => array(
+                                               'foo' => 'varchar(999) DEFAULT \'0\' NOT NULL'
+                                       )
+                               )
+                       ),
+                       array(
+                               'tx_foo' => array(
+                                       'fields' => array(
+                                               'foo' => 'varchar(255) DEFAULT \'0\' NOT NULL'
+                                       )
+                               )
+                       ),
+                       '',
+                       TRUE
+               );
 
                $this->assertEquals(
                        $differenceArray,