[TASK] Doctrine: Migrate a simple upgrade wizard
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Updates / BackendUserStartModuleUpdate.php
1 <?php
2 namespace TYPO3\CMS\Install\Updates;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Database\ConnectionPool;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Update backend user setting startModule if set to "help_aboutmodules"
22 */
23 class BackendUserStartModuleUpdate extends AbstractUpdate
24 {
25 /**
26 * @var string
27 */
28 protected $title = 'Update backend user setting "startModule"';
29
30 /**
31 * Checks if an update is needed
32 *
33 * @param string &$description The description for the update
34 * @return bool Whether an update is needed (TRUE) or not (FALSE)
35 */
36 public function checkForUpdate(&$description)
37 {
38 $statement = GeneralUtility::makeInstance(ConnectionPool::class)
39 ->getConnectionForTable('be_users')
40 ->select(['uid', 'uc'], 'be_users', []);
41 $needsExecution = false;
42 while ($backendUser = $statement->fetch()) {
43 if ($backendUser['uc'] !== null) {
44 $userConfig = unserialize($backendUser['uc']);
45 if ($userConfig['startModule'] === 'help_aboutmodules'
46 || $userConfig['startModule'] === 'help_AboutmodulesAboutmodules'
47 ) {
48 $needsExecution = true;
49 break;
50 }
51 }
52 }
53 if ($needsExecution) {
54 $description = 'The backend user setting startModule is changed for the extension aboutmodules. Update all'
55 . ' backend users that use ext:aboutmodules as startModule.';
56 }
57 return $needsExecution;
58 }
59
60 /**
61 * Performs the database update if backend user's startmodule is
62 * "help_aboutmodules" or "help_AboutmodulesAboutmodules"
63 *
64 * @param array &$databaseQueries Queries done in this update
65 * @param mixed &$customMessages Custom messages
66 * @return bool
67 */
68 public function performUpdate(array &$databaseQueries, &$customMessages)
69 {
70 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
71 $statement = $queryBuilder->select('uid', 'uc')->from('be_users')->execute();
72 while ($backendUser = $statement->fetch()) {
73 if ($backendUser['uc'] !== null) {
74 $userConfig = unserialize($backendUser['uc']);
75 if ($userConfig['startModule'] === 'help_aboutmodules'
76 || $userConfig['startModule'] === 'help_AboutmodulesAboutmodules'
77 ) {
78 $userConfig['startModule'] = 'help_AboutAboutmodules';
79 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
80 $queryBuilder->update('be_users')
81 ->where($queryBuilder->expr()->eq('uid', (int)$backendUser['uid']))
82 // Manual quoting and false as third parameter to have the final
83 // value in $databaseQueries and not a statement placeholder
84 ->set('uc', $queryBuilder->quote(serialize($userConfig)), false);
85 $databaseQueries[] = $queryBuilder->getSQL();
86 $queryBuilder->execute();
87 }
88 }
89 }
90 return true;
91 }
92 }