3
3
4
4
namespace DWenzel \T3events \Update ;
5
5
6
+ use TYPO3 \CMS \Core \Database \Query \QueryBuilder ;
6
7
use TYPO3 \CMS \Core \Configuration \FlexForm \FlexFormTools ;
8
+ use TYPO3 \CMS \Core \Database \ConnectionPool ;
7
9
use TYPO3 \CMS \Core \Messaging \FlashMessage ;
8
10
use TYPO3 \CMS \Core \Utility \GeneralUtility ;
9
- use TYPO3 \CMS \Core \Utility \VersionNumberUtility ;
10
- use TYPO3 \CMS \Extbase \Utility \DebuggerUtility ;
11
11
use TYPO3 \CMS \Install \Updates \AbstractUpdate ;
12
12
13
13
/**
14
14
* Class MigratePluginRecords
15
15
* Updates flex form settings in events plugins
16
+ * @codeCoverageIgnore
16
17
*/
17
18
class MigratePluginRecords extends AbstractUpdate
18
19
{
19
20
const CONTENT_TABLE = 'tt_content ' ;
20
21
const FLEX_FORM_FIELD = 'pi_flexform ' ;
21
- const DEPRECATED_PLUGIN_WHERE_CLAUSE = "list_type='t3events_events' AND pi_flexform REGEXP 'settings.sortBy|Event->calendar' " ;
22
- const MESSAGE_UPDATE_REQUIRED = 'Found %s Plugin records which need to be updated ' ;
23
- const TITLE_UPDATE_REQUIRED = 'Update required ' ;
22
+ const LIST_TYPE_FIELD = 'list_type ' ;
23
+ const PLUGIN_TYPE_EVENTS = 't3events_events ' ;
24
+ const ID_FIELD = 'uid ' ;
25
+ const DEPRECATED_FLEX_KEY = 'settings.cache.makeNonCacheable ' ;
26
+ const REPLACEMENT_FLEX_KEY = 'settings.cache.notCacheable ' ;
27
+ const MESSAGE_UPDATE_REQUIRED = 'Found %s plugin records which need to be updated (t3events) ' ;
28
+ const WIZARD_TITLE = 'Migrate Event Plugin Records ' ;
29
+ const TITLE_UPDATE_REQUIRED = 'Migrate Event Plugin Records ' ;
30
+ const IDENTIFIER = 'T3eventsMigratePluginRecords ' ;
24
31
const MESSAGE_UPDATED = '%s Plugin records updated. ' ;
25
32
const TITLE_UPDATED = 'Update success ' ;
26
33
34
+ protected $ identifier = '' ;
35
+ protected $ title = self ::WIZARD_TITLE ;
36
+
37
+
27
38
/**
28
39
* @var \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools
29
40
*/
@@ -36,17 +47,14 @@ class MigratePluginRecords extends AbstractUpdate
36
47
*/
37
48
public function checkForUpdate (&$ description )
38
49
{
39
- $ versionNumber = VersionNumberUtility::convertVersionNumberToInteger (TYPO3_version);
40
- if ($ versionNumber >= 8000000 ) {
41
- return false ;
42
- }
50
+ $ count = $ this ->countPluginRecordsWithDeprecatedSettings ();
43
51
44
- $ updateRequired = false ;
45
- if ( $ this -> countPluginRecordsWithDeprecatedSettings ()) {
46
- $ updateRequired = true ;
52
+ if ( $ count ) {
53
+ $ description = sprintf ( self :: MESSAGE_UPDATE_REQUIRED , $ count );
54
+ return true ;
47
55
}
48
56
49
- return $ updateRequired ;
57
+ return false ;
50
58
}
51
59
52
60
/**
@@ -55,7 +63,7 @@ public function checkForUpdate(&$description)
55
63
*/
56
64
protected function getFlexFormTools ()
57
65
{
58
- if (!$ this ->flexFormTools instanceof FlexFormTools) {
66
+ if (!$ this ->flexFormTools instanceof FlexFormTools) {
59
67
/** @var FlexFormTools flexFormTools */
60
68
$ this ->flexFormTools = GeneralUtility::makeInstance (FlexFormTools::class);
61
69
}
@@ -72,90 +80,109 @@ protected function getFlexFormTools()
72
80
*/
73
81
public function performUpdate (array &$ dbQueries , &$ customMessages )
74
82
{
75
- $ success = false ;
76
83
$ pluginRecords = $ this ->getPluginRecordsWithDeprecatedSettings ();
77
84
$ pluginCount = count ($ pluginRecords );
78
85
79
86
if ($ pluginCount ) {
87
+ if (!is_array ($ customMessages )) {
88
+ $ customMessages = [$ customMessages ];
89
+ }
80
90
$ customMessages [] = [
81
91
FlashMessage::INFO ,
82
92
self ::TITLE_UPDATE_REQUIRED ,
83
93
sprintf (self ::MESSAGE_UPDATE_REQUIRED , $ pluginCount )
84
94
];
85
95
$ updatedCount = 0 ;
96
+ $ builder = $ this ->getQueryBuilder ();
86
97
87
98
foreach ($ pluginRecords as $ record ) {
88
- $ sortDirectionSettings = 'asc ' ;
89
- $ flexFormSettings = $ this ->getFlexFormSettings ($ record );
90
- $ switchableControllerActionChanged = false ;
91
-
92
- if ($ flexFormSettings ['data ' ]['sDEF ' ]['lDEF ' ]['switchableControllerActions ' ]['vDEF ' ] == 'Event->calendar ' ) {
93
- $ flexFormSettings ['data ' ]['sDEF ' ]['lDEF ' ]['switchableControllerActions ' ]['vDEF ' ] = 'Performance->calendar ' ;
94
- $ switchableControllerActionChanged = true ;
95
- }
96
- if (isset ($ flexFormSettings ['data ' ]['sDEF ' ]['lDEF ' ]['settings.sortBy ' ]['vDEF ' ])) {
97
- $ sortBySettings = $ flexFormSettings ['data ' ]['sDEF ' ]['lDEF ' ]['settings.sortBy ' ]['vDEF ' ];
98
- }
99
- if (isset ($ flexFormSettings ['data ' ]['sDEF ' ]['lDEF ' ]['settings.sortDirection ' ]['vDEF ' ])) {
100
- $ sortDirectionSettings = $ flexFormSettings ['data ' ]['sDEF ' ]['lDEF ' ]['settings.sortDirection ' ]['vDEF ' ];
101
- }
102
- if (!empty ($ sortBySettings || $ switchableControllerActionChanged )) {
103
- $ flexFormSettings ['data ' ]['sDEF ' ]['lDEF ' ]['settings.order ' ]['vDEF ' ] = $ sortBySettings . '| ' . $ sortDirectionSettings . ',performances.begin|asc ' ;
104
- unset($ flexFormSettings ['data ' ]['sDEF ' ]['lDEF ' ]['settings.sortBy ' ]);
105
- unset($ flexFormSettings ['data ' ]['sDEF ' ]['lDEF ' ]['settings.sortDirection ' ]);
106
-
99
+ $ changed = 0 ;
100
+
101
+ $ updatedFlexXml = str_replace (
102
+ self ::DEPRECATED_FLEX_KEY ,
103
+ self ::REPLACEMENT_FLEX_KEY ,
104
+ $ record [self ::FLEX_FORM_FIELD ],
105
+ $ changed
106
+ );
107
+
108
+ if ($ changed ) {
109
+ $ builder ->update (self ::CONTENT_TABLE )
110
+ ->where (
111
+ $ builder ->expr ()->eq (
112
+ self ::ID_FIELD ,
113
+ $ builder ->createNamedParameter (
114
+ $ record [self ::ID_FIELD ], \PDO ::PARAM_INT )
115
+ )
116
+ )
117
+ ->set (self ::FLEX_FORM_FIELD , $ updatedFlexXml )
118
+ ->execute ();
107
119
$ updatedCount ++;
108
- $ updatedXml = $ this ->getFlexFormTools ()->flexArray2Xml ($ flexFormSettings , true );
109
-
110
- $ this ->getDatabaseConnection ()->exec_UPDATEquery (
111
- self ::CONTENT_TABLE ,
112
- 'uid= ' . $ record ['uid ' ],
113
- [
114
- self ::FLEX_FORM_FIELD => $ updatedXml ,
115
- ]
116
- );
117
120
}
118
121
}
119
122
120
- if ($ updatedCount > 0 ) {
123
+ if (0 !== $ updatedCount ) {
121
124
$ customMessages [] = [
122
125
FlashMessage::INFO ,
123
126
self ::TITLE_UPDATED ,
124
127
sprintf (self ::MESSAGE_UPDATED , $ updatedCount )
125
128
];
126
129
}
127
130
}
128
- return $ success ;
131
+ return true ;
129
132
}
130
133
131
134
/**
132
135
* Counts plugin records with deprecated settings
133
136
*
134
137
* @return mixed
138
+ * @codeCoverageIgnore
135
139
*/
136
140
public function countPluginRecordsWithDeprecatedSettings ()
137
141
{
138
- return $ this ->getDatabaseConnection ()
139
- ->exec_SELECTcountRows (
140
- '* ' ,
141
- self ::CONTENT_TABLE ,
142
- self ::DEPRECATED_PLUGIN_WHERE_CLAUSE
143
- );
142
+ $ builder = $ this ->getQueryBuilder ();
143
+
144
+
145
+ return $ builder
146
+ ->count (self ::ID_FIELD )
147
+ ->from (self ::CONTENT_TABLE )
148
+ ->where (
149
+ $ builder ->expr ()->eq (
150
+ self ::LIST_TYPE_FIELD ,
151
+ $ builder ->createNamedParameter (self ::PLUGIN_TYPE_EVENTS )
152
+ ))
153
+ ->andWhere (
154
+ $ builder ->expr ()->like (
155
+ self ::FLEX_FORM_FIELD ,
156
+ $ builder ->createNamedParameter ('% ' . self ::DEPRECATED_FLEX_KEY . '% ' ))
157
+ )
158
+ ->execute ()->fetchColumn (0 );
144
159
}
145
160
146
161
/**
147
162
* Gets plugin records with deprecated settings
148
163
*
149
- * @return array | null
164
+ * @return array
165
+ * @codeCoverageIgnore
150
166
*/
151
167
public function getPluginRecordsWithDeprecatedSettings ()
152
168
{
153
- return $ this ->getDatabaseConnection ()
154
- ->exec_SELECTgetRows (
155
- 'uid, ' . self ::FLEX_FORM_FIELD ,
156
- self ::CONTENT_TABLE ,
157
- self ::DEPRECATED_PLUGIN_WHERE_CLAUSE
158
- );
169
+ $ builder = $ this ->getQueryBuilder ();
170
+
171
+
172
+ return $ builder
173
+ ->select (self ::ID_FIELD , self ::FLEX_FORM_FIELD )
174
+ ->from (self ::CONTENT_TABLE )
175
+ ->where (
176
+ $ builder ->expr ()->eq (
177
+ self ::LIST_TYPE_FIELD ,
178
+ $ builder ->createNamedParameter (self ::PLUGIN_TYPE_EVENTS )
179
+ ))
180
+ ->andWhere (
181
+ $ builder ->expr ()->like (
182
+ self ::FLEX_FORM_FIELD ,
183
+ $ builder ->createNamedParameter ('% ' . self ::DEPRECATED_FLEX_KEY . '% ' ))
184
+ )
185
+ ->execute ()->fetchAll ();
159
186
}
160
187
161
188
/**
@@ -172,4 +199,10 @@ protected function getFlexFormSettings($record)
172
199
173
200
return $ settings ;
174
201
}
202
+
203
+ public function getQueryBuilder (): QueryBuilder
204
+ {
205
+ return GeneralUtility::makeInstance (ConnectionPool::class)
206
+ ->getQueryBuilderForTable (self ::CONTENT_TABLE );
207
+ }
175
208
}
0 commit comments