[TASK] Add migration wizard for backend shortcuts 56/36756/4
authorWouter Wolters <typo3@wouterwolters.nl>
Sun, 8 Feb 2015 22:16:18 +0000 (23:16 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 9 Feb 2015 22:20:44 +0000 (23:20 +0100)
Resolves: #61477
Releases: master
Change-Id: Icafa17b2e2927273faf23ca115f632d9718e8ebe
Reviewed-on: http://review.typo3.org/36756
Reviewed-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/install/Classes/Updates/MigrateShortcutUrlsUpdate.php [new file with mode: 0644]
typo3/sysext/install/ext_localconf.php

diff --git a/typo3/sysext/install/Classes/Updates/MigrateShortcutUrlsUpdate.php b/typo3/sysext/install/Classes/Updates/MigrateShortcutUrlsUpdate.php
new file mode 100644 (file)
index 0000000..80503b2
--- /dev/null
@@ -0,0 +1,88 @@
+<?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!
+ */
+
+/**
+ * Migrate backend shorcut urls
+ *
+ * @author Wouter Wolters <typo3@wouterwolters.nl>
+ */
+class MigrateShortcutUrlsUpdate extends AbstractUpdate {
+
+       /**
+        * @var string
+        */
+       protected $title = 'Migrate backend shortcut urls';
+
+       /**
+        * Checks if an update is needed
+        *
+        * @param string &$description The description for the update
+        * @return bool Whether an update is needed (TRUE) or not (FALSE)
+        */
+       public function checkForUpdate(&$description) {
+               $shortcutsCount = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_be_shortcuts');
+               if ($this->isWizardDone() || $shortcutsCount === 0) {
+                       return FALSE;
+               }
+
+               $description = 'Migrate old shorcut urls to the new module urls.';
+
+               return TRUE;
+       }
+
+       /**
+        * Performs the database update if shorcuts are available
+        *
+        * @param array &$databaseQueries Queries done in this update
+        * @param mixed &$customMessages Custom messages
+        * @return bool
+        */
+       public function performUpdate(array &$databaseQueries, &$customMessages) {
+               $db = $this->getDatabaseConnection();
+               $shortcuts = $db->exec_SELECTgetRows('uid,url', 'sys_be_shortcuts', '1=1');
+               if (!empty($shortcuts)) {
+                       foreach ($shortcuts as $shortcut) {
+                               $decodedUrl = urldecode($shortcut['url']);
+                               $encodedUrl = str_replace(
+                                       array(
+                                               '/typo3/sysext/cms/layout/db_layout.php?&',
+                                               '/typo3/sysext/cms/layout/db_layout.php?',
+                                               '/typo3/file_edit.php?&',
+                                       ),
+                                       array(
+                                               '/typo3/mod.php?&M=web_layout&',
+                                               urlencode('/typo3/mod.php?&M=web_layout&'),
+                                               '/typo3/mod.php?&M=file_edit&',
+                                       ),
+                                       $decodedUrl
+                               );
+
+                               $db->exec_UPDATEquery(
+                                       'sys_be_shortcuts',
+                                       'uid=' . (int)$shortcut['uid'],
+                                       array(
+                                               'url' => $encodedUrl,
+                                       )
+                               );
+                               $databaseQueries[] = $db->debug_lastBuiltQuery;
+                       }
+               }
+
+               $this->markWizardAsDone();
+               return TRUE;
+       }
+
+}
index e7c460e..f346b80 100644 (file)
@@ -5,6 +5,7 @@ defined('TYPO3_MODE') or die();
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['backendUserStartModule'] = \TYPO3\CMS\Install\Updates\BackendUserStartModuleUpdate::class;
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['languageIsoCode'] = \TYPO3\CMS\Install\Updates\LanguageIsoCodeUpdate::class;
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['PageShortcutParent'] = \TYPO3\CMS\Install\Updates\PageShortcutParentUpdate::class;
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/install']['update']['backendShortcuts'] = \TYPO3\CMS\Install\Updates\MigrateShortcutUrlsUpdate::class;
 
 $signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher::class);
 $signalSlotDispatcher->connect(