26
26
*
27
27
* @package TYPO3\CMS\Extbase\Command
28
28
*/
29
- class LinkMigrationCommandController extends CommandController {
29
+ class LinkMigrationCommandController extends CommandController
30
+ {
30
31
/**
31
32
* Default list of fields where to search for record references to migrate
32
33
*/
@@ -90,20 +91,14 @@ public function migrateCommand($fields = '')
90
91
$ this ->setFields ($ fields );
91
92
// Loop on all tables and fields
92
93
foreach ($ this ->tablesAndFields as $ table => $ listOfFields ) {
93
- $ this ->gatherRecordsToMigrate (
94
- $ table ,
95
- $ listOfFields
96
- );
94
+ $ this ->gatherRecordsToMigrate ($ table , $ listOfFields );
97
95
}
98
96
// Ask the user for configuration key for each table
99
97
$ this ->getConfigurationKeys ();
100
98
// Replace in fields and save modified data
101
99
$ this ->migrateRecords ();
102
- }
103
- catch (\InvalidArgumentException $ e ) {
104
- $ this ->outputLine (
105
- $ e ->getMessage () . ' ( ' . $ e ->getCode () . ') '
106
- );
100
+ } catch (\InvalidArgumentException $ e ) {
101
+ $ this ->outputLine ($ e ->getMessage () . ' ( ' . $ e ->getCode () . ') ' );
107
102
$ this ->quit (1 );
108
103
}
109
104
}
@@ -122,11 +117,8 @@ protected function setFields($fields)
122
117
list ($ table , $ field ) = explode ('. ' , $ aField );
123
118
if (empty ($ table ) || empty ($ field )) {
124
119
throw new \InvalidArgumentException (
125
- sprintf (
126
- 'Invalid argument "%s". Use "table.field" syntax ' ,
127
- $ aField
128
- ),
129
- 1457434202
120
+ sprintf ('Invalid argument "%s". Use "table.field" syntax ' , $ aField ),
121
+ 1457434202
130
122
);
131
123
} else {
132
124
if (!array_key_exists ($ table , $ this ->tablesAndFields )) {
@@ -150,22 +142,15 @@ protected function setFields($fields)
150
142
protected function gatherRecordsToMigrate ($ table , $ listOfFields )
151
143
{
152
144
try {
153
- $ records = $ this ->genericRepository ->findByRecordLink (
154
- $ table ,
155
- $ listOfFields
156
- );
145
+ $ records = $ this ->genericRepository ->findByRecordLink ($ table , $ listOfFields );
157
146
foreach ($ records as $ record ) {
158
147
$ id = (int )$ record ['uid ' ];
159
148
foreach ($ listOfFields as $ field ) {
160
149
$ matches = array ();
161
150
// Find all element that have a syntax like "record:string:string(:string)"
162
151
// The last string is optional. If it exists, it is already a 4-part record reference,
163
152
// i.e. a reference using the new syntax and which does not need to be migrated.
164
- preg_match_all (
165
- '/record:(\w+):(\w+)(:\w+)?/ ' ,
166
- $ record [$ field ],
167
- $ matches
168
- );
153
+ preg_match_all ('/record:(\w+):(\w+)(:\w+)?/ ' , $ record [$ field ], $ matches );
169
154
foreach ($ matches as $ index => $ match ) {
170
155
// Consider only matches that have 3 parts (i.e. 4th part is empty)
171
156
// NOTE: although not captured, the first part is "record:"
@@ -186,23 +171,16 @@ protected function gatherRecordsToMigrate($table, $listOfFields)
186
171
if (!array_key_exists ($ field , $ this ->recordsForMigration [$ table ][$ id ])) {
187
172
$ this ->recordsForMigration [$ table ][$ id ][$ field ] = array (
188
173
'content ' => $ record [$ field ],
189
- 'matches ' => array ()
174
+ 'matches ' => array (),
190
175
);
191
176
}
192
177
$ this ->recordsForMigration [$ table ][$ id ][$ field ]['matches ' ][] = $ matches [0 ][$ index ];
193
178
}
194
179
}
195
180
}
196
181
}
197
- }
198
- catch (FailedQueryException $ e ) {
199
- $ this ->outputLine (
200
- sprintf (
201
- 'Table "%s" skipped. An error occurred: %s ' ,
202
- $ table ,
203
- $ e ->getMessage ()
204
- )
205
- );
182
+ } catch (FailedQueryException $ e ) {
183
+ $ this ->outputLine (sprintf ('Table "%s" skipped. An error occurred: %s ' , $ table , $ e ->getMessage ()));
206
184
}
207
185
}
208
186
@@ -211,19 +189,16 @@ protected function gatherRecordsToMigrate($table, $listOfFields)
211
189
*
212
190
* @return void
213
191
*/
214
- protected function getConfigurationKeys () {
192
+ protected function getConfigurationKeys ()
193
+ {
215
194
foreach ($ this ->tablesForMigration as $ table => &$ dummy ) {
216
195
$ key = null ;
217
196
do {
218
197
try {
219
198
$ key = $ this ->console ->ask (
220
- sprintf (
221
- 'Please enter the configuration key to use for table "%s": ' ,
222
- $ table
223
- )
199
+ sprintf ('Please enter the configuration key to use for table "%s": ' , $ table )
224
200
);
225
- }
226
- catch (\Exception $ e ) {
201
+ } catch (\Exception $ e ) {
227
202
// Do nothing, just let it try again
228
203
}
229
204
} while ($ key === null );
@@ -246,27 +221,17 @@ protected function migrateRecords()
246
221
foreach ($ fieldInformation ['matches ' ] as $ link ) {
247
222
$ linkParts = explode (': ' , $ link );
248
223
$ newLink = 'record: ' . $ this ->tablesForMigration [$ linkParts [1 ]] . ': ' . $ linkParts [1 ] . ': ' . $ linkParts [2 ];
249
- $ updatedField = str_replace (
250
- $ link ,
251
- $ newLink ,
252
- $ updatedField
253
- );
224
+ $ updatedField = str_replace ($ link , $ newLink , $ updatedField );
254
225
}
255
226
if (!array_key_exists ($ id , $ recordsForTable )) {
256
227
$ recordsForTable [$ id ] = array ();
257
228
}
258
229
$ recordsForTable [$ id ][$ field ] = $ updatedField ;
259
230
}
260
231
}
261
- $ result = $ this ->genericRepository ->massUpdate (
262
- $ table ,
263
- $ recordsForTable
264
- );
232
+ $ result = $ this ->genericRepository ->massUpdate ($ table , $ recordsForTable );
265
233
if (!$ result ) {
266
- $ this ->outputLine (
267
- 'Some database updates failed for table "%s" ' ,
268
- $ table
269
- );
234
+ $ this ->outputLine ('Some database updates failed for table "%s" ' , $ table );
270
235
}
271
236
}
272
237
}
0 commit comments