‪TYPO3CMS  11.5
MigrateFeloginPlugins.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 
23 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
27 
32 {
36  protected static ‪$flexFormFields = [
37  'showForgotPassword',
38  'showPermaLogin',
39  'showLogoutFormAfterLogin',
40  'pages',
41  'recursive',
42  'redirectMode',
43  'redirectFirstMethod',
44  'redirectPageLogin',
45  'redirectPageLoginError',
46  'redirectPageLogout',
47  'redirectDisable',
48  'welcome_header',
49  'welcome_message',
50  'success_header',
51  'success_message',
52  'error_header',
53  'error_message',
54  'status_header',
55  'status_message',
56  'logout_header',
57  'logout_message',
58  'forgot_header',
59  'forgot_reset_message',
60  ];
61 
68  public function ‪getIdentifier(): string
69  {
70  return 'TYPO3\\CMS\\Felogin\\Updates\\MigrateFeloginPlugins';
71  }
72 
78  public function ‪getTitle(): string
79  {
80  return 'Migrate felogin plugins to use prefixed flexform keys';
81  }
82 
88  public function ‪getDescription(): string
89  {
90  return 'This wizard migrates existing front end plugins of the extension felogin to' .
91  ' make use of the streamlined flexform keys. Therefore it updates the field values' .
92  ' "pi_flexform" within the tt_content table';
93  }
94 
102  public function ‪executeUpdate(): bool
103  {
104  // Get all tt_content data for login plugins and update their flexforms settings
105  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
106 
107  $queryBuilder = $connection->createQueryBuilder();
108  $statement = $queryBuilder->select('uid')
109  ->addSelect('pi_flexform')
110  ->from('tt_content')
111  ->where(
112  $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('login')),
113  $queryBuilder->expr()->isNotNull('pi_flexform')
114  )
115  ->execute();
116 
117  // Update the found record sets
118  while ($record = $statement->fetchAssociative()) {
119  $queryBuilder = $connection->createQueryBuilder();
120  $updateResult = $queryBuilder->update('tt_content')
121  ->where(
122  $queryBuilder->expr()->eq(
123  'uid',
124  $queryBuilder->createNamedParameter($record['uid'], ‪Connection::PARAM_INT)
125  )
126  )
127  ->set('pi_flexform', $this->‪migrateFlexformSettings($record['pi_flexform']))
128  ->execute();
129  }
130 
131  return true;
132  }
133 
141  public function ‪updateNecessary(): bool
142  {
143  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
144  ->getConnectionForTable('tt_content')
145  ->createQueryBuilder();
146 
147  $queryBuilder->select('pi_flexform')
148  ->from('tt_content')
149  ->where(
150  $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('login')),
151  $this->getFlexformConstraints($queryBuilder)
152  );
153 
154  return (bool)$queryBuilder->execute()->fetchOne();
155  }
156 
165  public function ‪getPrerequisites(): array
166  {
167  return [
168  DatabaseUpdatedPrerequisite::class,
169  ];
170  }
171 
176  protected function ‪migrateFlexformSettings(string $oldValue): string
177  {
178  $fieldNames = implode('|', self::$flexFormFields);
179  $pattern = '/<field index="(' . $fieldNames . ')">/';
180  $replacement = '<field index="settings.$1">';
181 
182  return preg_replace($pattern, $replacement, $oldValue);
183  }
184 
191  protected function ‪getFlexformConstraints(QueryBuilder $queryBuilder): ‪CompositeExpression
192  {
193  $constraints = [];
194 
195  foreach (self::$flexFormFields as $flexFormField) {
196  $value = '%<field index="' . $flexFormField . '">%';
197  $constraints[] = $queryBuilder->expr()->like('pi_flexform', $queryBuilder->createNamedParameter($value));
198  }
199 
200  return $queryBuilder->expr()->orX(...$constraints);
201  }
202 }
‪TYPO3\CMS\FrontendLogin\Updates\MigrateFeloginPlugins\getIdentifier
‪string getIdentifier()
Definition: MigrateFeloginPlugins.php:67
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:49
‪TYPO3\CMS\FrontendLogin\Updates\MigrateFeloginPlugins\getPrerequisites
‪string[] getPrerequisites()
Definition: MigrateFeloginPlugins.php:164
‪TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite
Definition: DatabaseUpdatedPrerequisite.php:29
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:25
‪TYPO3\CMS\FrontendLogin\Updates\MigrateFeloginPlugins\getTitle
‪string getTitle()
Definition: MigrateFeloginPlugins.php:77
‪TYPO3\CMS\FrontendLogin\Updates\MigrateFeloginPlugins\executeUpdate
‪bool executeUpdate()
Definition: MigrateFeloginPlugins.php:101
‪TYPO3\CMS\FrontendLogin\Updates\MigrateFeloginPlugins\updateNecessary
‪bool updateNecessary()
Definition: MigrateFeloginPlugins.php:140
‪TYPO3\CMS\FrontendLogin\Updates\MigrateFeloginPlugins
Definition: MigrateFeloginPlugins.php:32
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\FrontendLogin\Updates
Definition: MigrateFeloginPlugins.php:18
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\FrontendLogin\Updates\MigrateFeloginPlugins\$flexFormFields
‪static array $flexFormFields
Definition: MigrateFeloginPlugins.php:35
‪TYPO3\CMS\FrontendLogin\Updates\MigrateFeloginPlugins\getDescription
‪string getDescription()
Definition: MigrateFeloginPlugins.php:87
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\FrontendLogin\Updates\MigrateFeloginPlugins\migrateFlexformSettings
‪string migrateFlexformSettings(string $oldValue)
Definition: MigrateFeloginPlugins.php:175
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\FrontendLogin\Updates\MigrateFeloginPlugins\getFlexformConstraints
‪CompositeExpression getFlexformConstraints(QueryBuilder $queryBuilder)
Definition: MigrateFeloginPlugins.php:190