Revert "[BUGFIX] Check for incompatible SQL modes" 42/23242/2
authorStefan Neufeind <typo3.neufeind@speedpartner.de>
Thu, 22 Aug 2013 10:18:58 +0000 (12:18 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Thu, 22 Aug 2013 10:19:46 +0000 (12:19 +0200)
The sysenv-check is not the proper place for a check that needs a working db-connection. But we'll find a different place for this check shortly and then reintroduce it.

This reverts commit e727d5ff0b8ee93de38983555164b19f6bf87377

Change-Id: I117f38df6796bf04c285d6d5345a0829f32fbfc3
Reviewed-on: https://review.typo3.org/23242
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Classes/Database/DatabaseConnection.php
typo3/sysext/install/Classes/SystemEnvironment/Check.php

index 57e7a38..71032d4 100644 (file)
@@ -1204,6 +1204,7 @@ class DatabaseConnection {
                                        );
                                }
                        }
+                       $this->setSqlMode();
                } else {
                        // @TODO: This should raise an exception. Would be useful especially to work during installation.
                        $error_msg = $this->link->connect_error;
@@ -1218,6 +1219,28 @@ class DatabaseConnection {
        }
 
        /**
+        * Fixes the SQL mode by unsetting NO_BACKSLASH_ESCAPES if found.
+        *
+        * @return void
+        */
+       protected function setSqlMode() {
+               $resource = $this->sql_query('SELECT @@SESSION.sql_mode;');
+               if ($resource) {
+                       $result = $this->sql_fetch_row($resource);
+                       if (isset($result[0]) && $result[0] && strpos($result[0], 'NO_BACKSLASH_ESCAPES') !== FALSE) {
+                               $modes = array_diff(\TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $result[0]), array('NO_BACKSLASH_ESCAPES'));
+                               $query = 'SET sql_mode=\'' . $this->link->real_escape_string(implode(',', $modes)) . '\';';
+                               $this->sql_query($query);
+                               \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog(
+                                       'NO_BACKSLASH_ESCAPES could not be removed from SQL mode: ' . $this->sql_error(),
+                                       'Core',
+                                       \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR
+                               );
+                       }
+               }
+       }
+
+       /**
         * Select a SQL database
         *
         * @param string $TYPO3_db Deprecated since 6.1, will be removed in two versions. Database to connect to.
index 6ee439a..60c48ef 100644 (file)
@@ -89,19 +89,6 @@ class Check {
        }
 
        /**
-        * NO_BACKSLASH_ESCAPES  This mode disables the use of the backslash character as an escape character,
-        *                       but we depend on this for escaping.
-        * STRICT_ALL_TABLES     If a value has not the datatype that is expected by the column,
-        *                       mysql will throw an error in this mode.
-        *
-        * @var array<string>
-        */
-       protected $incompatibleSqlModes = array(
-               'NO_BACKSLASH_ESCAPES',
-               'STRICT_ALL_TABLES'
-       );
-
-       /**
         * Get all status information as array with status objects
         *
         * @return array<\TYPO3\CMS\Install\SystemEnvironment\StatusInterface>
@@ -128,7 +115,6 @@ class Check {
                $statusArray[] = $this->checkSuhosinExecutorIncludeWhitelistContainsPhar();
                $statusArray[] = $this->checkSuhosinExecutorIncludeWhitelistContainsVfs();
                $statusArray[] = $this->checkSomePhpOpcodeCacheIsLoaded();
-               $statusArray[] = $this->checkInvalidSqlModes();
                $statusArray[] = $this->checkReflectionDocComment();
                $statusArray[] = $this->checkWindowsApacheThreadStackSize();
                foreach ($this->requiredPhpExtensions as $extension) {
@@ -223,65 +209,6 @@ class Check {
        }
 
        /**
-        * Check if any SQL mode is set which is not compatible with TYPO3
-        *
-        * @return StatusInterface
-        */
-       public function checkInvalidSqlModes() {
-               try {
-                       $this->loadExtLocalconfDatabase();
-
-                       $sqlModes = $this->getSqlModes();
-               } catch (\RuntimeException $exception) {
-                       $status = new WarningStatus();
-                       $status->setTitle('Can\'t check SQL modes!');
-                       $status->setMessage(
-                               'There is a problem with your database connection.
-                               Error message: ' .
-                               $exception->getMessage()
-                       );
-
-                       return $status;
-               }
-
-               $detectedIncompatibleSqlModes = array_intersect($this->incompatibleSqlModes, $sqlModes);
-
-               if (count($detectedIncompatibleSqlModes)) {
-                       $status = new ErrorStatus();
-                       $status->setTitle('Incompatible SQL modes found!');
-                       $status->setMessage(
-                               'There have been incompatible SQL modes detected.' .
-                               ' The mode "' . implode('" and "', $detectedIncompatibleSqlModes) . '"' .
-                               ' is not compatible with TYPO3 CMS.' .
-                               ' You have to change that setting in your MySQL environment' .
-                               ' or in $TYPO3_CONF_VARS[\'SYS\'][\'setDBinit\']'
-                       );
-               } else {
-                       $status = new OkStatus();
-                       $status->setTitle('No incompatible SQL modes found.');
-               }
-
-               return $status;
-       }
-
-       /**
-        * Returns an array with the current sql mode settings
-        *
-        * @return array Contains all configured SQL modes for the current database connection
-        */
-       public function getSqlModes() {
-               $sqlModes = array();
-               $resource = $GLOBALS['TYPO3_DB']->sql_query('SELECT @@SESSION.sql_mode;');
-               if ($resource !== FALSE) {
-                       $result = $GLOBALS['TYPO3_DB']->sql_fetch_row($resource);
-                       if (isset($result[0])) {
-                               $sqlModes = explode(',', $result[0]);
-                       }
-               }
-               return $sqlModes;
-       }
-
-       /**
         * Check maximum post upload size correlates with maximum file upload
         *
         * @return ErrorStatus|OkStatus
@@ -1263,20 +1190,6 @@ class Check {
                return $bytes;
        }
 
-       /**
-        * Some actions like the database analyzer and the upgrade wizards need additional
-        * bootstrap actions performed.
-        *
-        * Those actions can potentially fatal if some old extension is loaded that triggers
-        * a fatal in ext_localconf or ext_tables code! Use only if really needed.
-        *
-        * @return void
-        */
-       protected function loadExtLocalconfDatabase() {
-               \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
-                       ->loadTypo3LoadedExtAndExtLocalconf(FALSE)
-                       ->applyAdditionalConfigurationSettings()
-                       ->initializeTypo3DbGlobal();
-       }
+
 }
-?>
\ No newline at end of file
+?>