[BUGFIX] Add upgrade wizard for backend user setting startModule 92/32692/4
authorWouter Wolters <typo3@wouterwolters.nl>
Tue, 9 Sep 2014 17:13:19 +0000 (19:13 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Tue, 9 Sep 2014 20:30:22 +0000 (22:30 +0200)
In #60633 the rewrite of the module menu was done but can lead
to an error if the backend user startModule is set
to help_aboutmodules. Check all backend users and update the
setting if needed.

Resolves: #61485
Releases: 6.3
Change-Id: Ib6f21c4bd4d4315e76cc7d51bebf08c9fa01b924
Reviewed-on: http://review.typo3.org/32692
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/install/Classes/Updates/BackendUserStartModuleUpdate.php [new file with mode: 0644]
typo3/sysext/install/ext_localconf.php

diff --git a/typo3/sysext/install/Classes/Updates/BackendUserStartModuleUpdate.php b/typo3/sysext/install/Classes/Updates/BackendUserStartModuleUpdate.php
new file mode 100644 (file)
index 0000000..dc6b8a7
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+namespace TYPO3\CMS\Install\Updates;
+
+/**
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Update backend user setting startModule if set to "help_aboutmodules"
+ *
+ * @author Wouter Wolters <typo3@wouterwolters.nl>
+ */
+class BackendUserStartModuleUpdate extends AbstractUpdate {
+
+       /**
+        * @var string
+        */
+       protected $title = 'Update backend user setting "startModule"';
+
+       /**
+        * Checks if an update is needed
+        *
+        * @param string &$description The description for the update
+        * @return boolean Whether an update is needed (TRUE) or not (FALSE)
+        */
+       public function checkForUpdate(&$description) {
+               $backendUsersCount = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'be_users');
+               if ($this->isWizardDone() || $backendUsersCount === 0) {
+                       return FALSE;
+               }
+
+               $description = 'The backend user setting startModule is changed for the extension aboutmodules. Update all backend users that use ext:aboutmodules as startModule.';
+
+               return TRUE;
+       }
+
+       /**
+        * Performs the database update if backend user's startmodule is help_aboutmodules
+        *
+        * @param array &$databaseQueries Queries done in this update
+        * @param mixed &$customMessages Custom messages
+        * @return boolean
+        */
+       public function performUpdate(array &$databaseQueries, &$customMessages) {
+               $backendUsers = $this->getDatabaseConnection()->exec_SELECTgetRows('uid,uc', 'be_users', '1=1');
+               if (!empty($backendUsers)) {
+                       foreach ($backendUsers as $backendUser) {
+                               if ($backendUser['uc'] !== NULL) {
+                                       $userConfig = unserialize($backendUser['uc']);
+                                       if ($userConfig['startModule'] === 'help_aboutmodules') {
+                                               $userConfig['startModule'] = 'help_AboutmodulesAboutmodules';
+                                               $this->getDatabaseConnection()->exec_UPDATEquery(
+                                                       'be_users',
+                                                       'uid=' . (int)$backendUser['uid'],
+                                                       array(
+                                                               'uc' => serialize($userConfig),
+                                                       )
+                                               );
+                                               $databaseQueries[] = $this->getDatabaseConnection()->debug_lastBuiltQuery;
+                                       }
+                               }
+                       }
+               }
+
+               $this->markWizardAsDone();
+               return TRUE;
+       }
+
+       /**
+        * Get database connection
+        *
+        * @return \TYPO3\CMS\Core\Database\DatabaseConnection
+        */
+       protected function getDatabaseConnection() {
+               return $GLOBALS['TYPO3_DB'];
+       }
+}
index 13cdf8d..2f9bc88 100644 (file)
@@ -22,6 +22,8 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['fal_identifi
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['sysext_file_rtemagicimages'] = 'TYPO3\\CMS\\Install\\Updates\\RteMagicImagesUpdateWizard';
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['sysext_file_rtefilelinks'] = 'TYPO3\\CMS\\Install\\Updates\\RteFileLinksUpdateWizard';
 
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['backendUserStartModule'] = 'TYPO3\\CMS\\Install\\Updates\\BackendUserStartModuleUpdate';
+
 // Version 4.7: Migrate the flexforms of MediaElement
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['mediaElementFlexform'] = 'TYPO3\\CMS\\Install\\Updates\\MediaFlexformUpdate';