‪TYPO3CMS  10.4
BackendUserConfigurationUpdate.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
22 
28 {
32  public function ‪getIdentifier(): string
33  {
34  return 'backendUsersConfiguration';
35  }
36 
40  public function ‪getTitle(): string
41  {
42  return 'Update backend user configuration array';
43  }
44 
48  public function ‪getDescription(): string
49  {
50  return 'The backend user "uc" array, which is persisted in the db, now only allows for'
51  . ' arrays inside its structure instead of stdClass objects.'
52  . ' Update the uc structure for all backend users.';
53  }
54 
60  public function ‪updateNecessary(): bool
61  {
62  $needsExecution = false;
63 
64  foreach ($this->‪getAffectedBackendUsers() as $backendUser) {
65  $userConfig = $this->‪unserializeUserConfig($backendUser['uc']);
66 
67  if (!is_array($userConfig)) {
68  continue;
69  }
70 
71  array_walk_recursive($userConfig, function (&$item) use (&$needsExecution) {
72  if ($item instanceof \stdClass) {
73  $needsExecution = true;
74  }
75  });
76 
77  if ($needsExecution) {
78  break;
79  }
80  }
81 
82  return $needsExecution;
83  }
84 
88  public function ‪getPrerequisites(): array
89  {
90  return [
91  DatabaseUpdatedPrerequisite::class
92  ];
93  }
94 
100  public function ‪executeUpdate(): bool
101  {
102  foreach ($this->‪getAffectedBackendUsers() as $backendUser) {
103  $userConfig = $this->‪unserializeUserConfig($backendUser['uc']);
104 
105  if (!is_array($userConfig)) {
106  continue;
107  }
108 
109  array_walk_recursive($userConfig, function (&$item) {
110  if ($item instanceof \stdClass) {
111  $item = json_decode(json_encode($item), true);
112  }
113  });
114 
115  $this->‪updateBackendUser((int)$backendUser['uid'], $userConfig);
116  }
117 
118  return true;
119  }
120 
121  private function ‪unserializeUserConfig(string $userConfig)
122  {
123  return unserialize($userConfig, ['allowed_classes' => [\stdClass::class]]);
124  }
125 
126  private function ‪getAffectedBackendUsers(): iterable
127  {
128  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
129  ->getQueryBuilderForTable('be_users');
130  $queryBuilder->getRestrictions()->removeAll();
131  $statement = $queryBuilder
132  ->select('uid', 'uc')
133  ->from('be_users')
134  ->where(
135  $queryBuilder->expr()->like(
136  'uc',
137  $queryBuilder->createNamedParameter(
138  '%"stdClass"%'
139  )
140  )
141  );
142 
143  return $statement->execute();
144  }
145 
146  private function ‪updateBackendUser(int $userId, array $userConfig): void
147  {
148  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('be_users');
149  $connection->update('be_users', ['uc' => serialize($userConfig)], ['uid' => $userId], [\PDO::PARAM_LOB, \PDO::PARAM_INT]);
150  }
151 }
‪TYPO3\CMS\Install\Updates\BackendUserConfigurationUpdate\unserializeUserConfig
‪unserializeUserConfig(string $userConfig)
Definition: BackendUserConfigurationUpdate.php:121
‪TYPO3\CMS\Install\Updates\BackendUserConfigurationUpdate\executeUpdate
‪bool executeUpdate()
Definition: BackendUserConfigurationUpdate.php:100
‪TYPO3\CMS\Install\Updates\BackendUserConfigurationUpdate\getTitle
‪string getTitle()
Definition: BackendUserConfigurationUpdate.php:40
‪TYPO3\CMS\Install\Updates\BackendUserConfigurationUpdate\getPrerequisites
‪string[] getPrerequisites()
Definition: BackendUserConfigurationUpdate.php:88
‪TYPO3\CMS\Install\Updates\BackendUserConfigurationUpdate
Definition: BackendUserConfigurationUpdate.php:28
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:16
‪TYPO3\CMS\Install\Updates\BackendUserConfigurationUpdate\getIdentifier
‪string getIdentifier()
Definition: BackendUserConfigurationUpdate.php:32
‪TYPO3\CMS\Install\Updates\BackendUserConfigurationUpdate\getDescription
‪string getDescription()
Definition: BackendUserConfigurationUpdate.php:48
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Install\Updates\BackendUserConfigurationUpdate\updateBackendUser
‪updateBackendUser(int $userId, array $userConfig)
Definition: BackendUserConfigurationUpdate.php:146
‪TYPO3\CMS\Install\Updates\BackendUserConfigurationUpdate\getAffectedBackendUsers
‪getAffectedBackendUsers()
Definition: BackendUserConfigurationUpdate.php:126
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Install\Updates\BackendUserConfigurationUpdate\updateNecessary
‪bool updateNecessary()
Definition: BackendUserConfigurationUpdate.php:60