‪TYPO3CMS  10.4
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 
26 
31 {
35  protected static ‪$flexFormFields = [
36  'showForgotPassword',
37  'showPermaLogin',
38  'showLogoutFormAfterLogin',
39  'pages',
40  'recursive',
41  'redirectMode',
42  'redirectFirstMethod',
43  'redirectPageLogin',
44  'redirectPageLoginError',
45  'redirectPageLogout',
46  'redirectDisable',
47  'welcome_header',
48  'welcome_message',
49  'success_header',
50  'success_message',
51  'error_header',
52  'error_message',
53  'status_header',
54  'status_message',
55  'logout_header',
56  'logout_message',
57  'forgot_header',
58  'forgot_reset_message'
59  ];
60 
67  public function ‪getIdentifier(): string
68  {
69  return self::class;
70  }
71 
77  public function ‪getTitle(): string
78  {
79  return 'Migrate felogin plugins to use prefixed flexform keys';
80  }
81 
87  public function ‪getDescription(): string
88  {
89  return 'This wizard migrates existing front end plugins of the extension felogin to' .
90  ' make use of the streamlined flexform keys. Therefore it updates the field values' .
91  ' "pi_flexform" within the tt_content table';
92  }
93 
101  public function ‪executeUpdate(): bool
102  {
103  // Get all tt_content data for login plugins and update their flexforms settings
104  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('tt_content');
105 
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  )
114  ->execute();
115 
116  // Update the found record sets
117  while ($record = $statement->fetch()) {
118  $queryBuilder = $connection->createQueryBuilder();
119  $updateResult = $queryBuilder->update('tt_content')
120  ->where(
121  $queryBuilder->expr()->eq(
122  'uid',
123  $queryBuilder->createNamedParameter($record['uid'], \PDO::PARAM_INT)
124  )
125  )
126  ->set('pi_flexform', $this->‪migrateFlexformSettings($record['pi_flexform']))
127  ->execute();
128 
129  //exit if at least one update statement is not successful
130  if (!((bool)$updateResult)) {
131  return false;
132  }
133  }
134 
135  return true;
136  }
137 
145  public function ‪updateNecessary(): bool
146  {
147  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
148  ->getConnectionForTable('tt_content')
149  ->createQueryBuilder();
150 
151  $queryBuilder->select('pi_flexform')
152  ->from('tt_content')
153  ->where(
154  $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('login')),
155  $this->getFlexformConstraints($queryBuilder)
156  );
157 
158  return (bool)$queryBuilder->execute()->fetchColumn();
159  }
160 
169  public function ‪getPrerequisites(): array
170  {
171  return [
172  DatabaseUpdatedPrerequisite::class
173  ];
174  }
175 
180  protected function ‪migrateFlexformSettings(string $oldValue): string
181  {
182  $fieldNames = implode('|', static::$flexFormFields);
183  $pattern = '/<field index="(' . $fieldNames . ')">/';
184  $replacement = '<field index="settings.$1">';
185 
186  return preg_replace($pattern, $replacement, $oldValue);
187  }
188 
195  protected function ‪getFlexformConstraints(‪QueryBuilder $queryBuilder): ‪CompositeExpression
196  {
197  $constraints = [];
198 
199  foreach (static::$flexFormFields as $flexFormField) {
200  $value = '%<field index="' . $flexFormField . '">%';
201  $constraints[] = $queryBuilder->‪expr()->‪like('pi_flexform', $queryBuilder->‪createNamedParameter($value));
202  }
203 
204  return $queryBuilder->‪expr()->‪orX(...$constraints);
205  }
206 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\like
‪string like(string $fieldName, $value)
Definition: ExpressionBuilder.php:217
‪TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\getFlexformConstraints
‪CompositeExpression getFlexformConstraints(QueryBuilder $queryBuilder)
Definition: MigrateFeloginPlugins.php:194
‪TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\getDescription
‪string getDescription()
Definition: MigrateFeloginPlugins.php:86
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\createNamedParameter
‪string createNamedParameter($value, int $type=\PDO::PARAM_STR, string $placeHolder=null)
Definition: QueryBuilder.php:941
‪TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins
Definition: MigrateFeloginPlugins.php:31
‪TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\executeUpdate
‪bool executeUpdate()
Definition: MigrateFeloginPlugins.php:100
‪TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\getPrerequisites
‪string[] getPrerequisites()
Definition: MigrateFeloginPlugins.php:168
‪TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\getTitle
‪string getTitle()
Definition: MigrateFeloginPlugins.php:76
‪TYPO3\CMS\Install\Updates\DatabaseUpdatedPrerequisite
Definition: DatabaseUpdatedPrerequisite.php:29
‪TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\$flexFormFields
‪static array $flexFormFields
Definition: MigrateFeloginPlugins.php:34
‪TYPO3\CMS\Felogin\Updates
Definition: MigrateFeloginPlugins.php:18
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:52
‪TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\migrateFlexformSettings
‪string migrateFlexformSettings(string $oldValue)
Definition: MigrateFeloginPlugins.php:179
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:25
‪TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\updateNecessary
‪bool updateNecessary()
Definition: MigrateFeloginPlugins.php:144
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\orX
‪CompositeExpression orX(... $expressions)
Definition: ExpressionBuilder.php:82
‪TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\getIdentifier
‪string getIdentifier()
Definition: MigrateFeloginPlugins.php:66
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Database\Query\QueryBuilder\expr
‪ExpressionBuilder expr()
Definition: QueryBuilder.php:151