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