[TASK] Move csh handling to backend extension
[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" or "help_CshmanualCshmanual"
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'], ['allowed_classes' => false]);
45 if ($userConfig['startModule'] === 'help_aboutmodules'
46 || $userConfig['startModule'] === 'help_AboutmodulesAboutmodules'
47 || $userConfig['startModule'] === 'help_AboutAboutmodules'
48 || $userConfig['startModule'] === 'help_CshmanualCshmanual'
49 || $userConfig['startModule'] === 'help_DocumentationCshmanual'
50 ) {
51 $needsExecution = true;
52 break;
53 }
54 }
55 }
56 if ($needsExecution) {
57 $description = 'The backend user setting startModule is changed for the extensions about/aboutmodules and help/cshmanual. Update all'
58 . ' backend users that use EXT:aboutmodules and EXT:cshmanual as startModule.';
59 }
60 return $needsExecution;
61 }
62
63 /**
64 * Performs the database update if backend user's startmodule is
65 * "help_aboutmodules" or "help_AboutmodulesAboutmodules" or "help_CshmanualCshmanual"
66 *
67 * @param array &$databaseQueries Queries done in this update
68 * @param string &$customMessage Custom message
69 * @return bool
70 */
71 public function performUpdate(array &$databaseQueries, &$customMessage)
72 {
73 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
74 $statement = $queryBuilder->select('uid', 'uc')->from('be_users')->execute();
75 while ($backendUser = $statement->fetch()) {
76 if ($backendUser['uc'] !== null) {
77 $userConfig = unserialize($backendUser['uc'], ['allowed_classes' => false]);
78 if ($userConfig['startModule'] === 'help_aboutmodules'
79 || $userConfig['startModule'] === 'help_AboutmodulesAboutmodules'
80 || $userConfig['startModule'] === 'help_AboutAboutmodules'
81 || $userConfig['startModule'] === 'help_CshmanualCshmanual'
82 || $userConfig['startModule'] === 'help_DocumentationCshmanual'
83 ) {
84 $userConfig['startModule'] = 'help_AboutAbout';
85 if ($userConfig['startModule'] === 'help_CshmanualCshmanual' || $userConfig['startModule'] === 'help_DocumentationCshmanual') {
86 $userConfig['startModule'] = 'help_BackendCshmanual';
87 }
88 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
89 $queryBuilder->update('be_users')
90 ->where(
91 $queryBuilder->expr()->eq(
92 'uid',
93 $queryBuilder->createNamedParameter($backendUser['uid'], \PDO::PARAM_INT)
94 )
95 )
96 // Manual quoting and false as third parameter to have the final
97 // value in $databaseQueries and not a statement placeholder
98 ->set('uc', serialize($userConfig));
99 $databaseQueries[] = $queryBuilder->getSQL();
100 $queryBuilder->execute();
101 }
102 }
103 }
104 return true;
105 }
106 }