From 6b937f34b3da32fcbd30026edb2f79b048f5fc85 Mon Sep 17 00:00:00 2001
From: Wouter Wolters <typo3@wouterwolters.nl>
Date: Tue, 9 Sep 2014 19:13:19 +0200
Subject: [PATCH] [BUGFIX] Add upgrade wizard for backend user setting
 startModule

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>
---
 .../Updates/BackendUserStartModuleUpdate.php  | 86 +++++++++++++++++++
 typo3/sysext/install/ext_localconf.php        |  2 +
 2 files changed, 88 insertions(+)
 create mode 100644 typo3/sysext/install/Classes/Updates/BackendUserStartModuleUpdate.php

diff --git a/typo3/sysext/install/Classes/Updates/BackendUserStartModuleUpdate.php b/typo3/sysext/install/Classes/Updates/BackendUserStartModuleUpdate.php
new file mode 100644
index 000000000000..dc6b8a71842c
--- /dev/null
+++ b/typo3/sysext/install/Classes/Updates/BackendUserStartModuleUpdate.php
@@ -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'];
+	}
+}
diff --git a/typo3/sysext/install/ext_localconf.php b/typo3/sysext/install/ext_localconf.php
index 13cdf8de47c1..2f9bc88e4176 100644
--- a/typo3/sysext/install/ext_localconf.php
+++ b/typo3/sysext/install/ext_localconf.php
@@ -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';
 
-- 
GitLab