TYPO3 CMS  TYPO3_8-7
BackendUserStartModuleUpdate.php
Go to the documentation of this file.
1 <?php
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 
19 
24 {
28  protected $title = 'Update backend user setting "startModule"';
29 
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  ) {
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 
68  public function performUpdate(array &$databaseQueries, &$customMessage)
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'], ['allowed_classes' => false]);
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(
82  $queryBuilder->expr()->eq(
83  'uid',
84  $queryBuilder->createNamedParameter($backendUser['uid'], \PDO::PARAM_INT)
85  )
86  )
87  // Manual quoting and false as third parameter to have the final
88  // value in $databaseQueries and not a statement placeholder
89  ->set('uc', serialize($userConfig));
90  $databaseQueries[] = $queryBuilder->getSQL();
91  $queryBuilder->execute();
92  }
93  }
94  }
95  return true;
96  }
97 }
static makeInstance($className,... $constructorArguments)