2626 *
2727 * @package TYPO3\CMS\Extbase\Command
2828 */
29- class LinkMigrationCommandController extends CommandController {
29+ class LinkMigrationCommandController extends CommandController
30+ {
3031 /**
3132 * Default list of fields where to search for record references to migrate
3233 */
@@ -90,20 +91,14 @@ public function migrateCommand($fields = '')
9091 $ this ->setFields ($ fields );
9192 // Loop on all tables and fields
9293 foreach ($ this ->tablesAndFields as $ table => $ listOfFields ) {
93- $ this ->gatherRecordsToMigrate (
94- $ table ,
95- $ listOfFields
96- );
94+ $ this ->gatherRecordsToMigrate ($ table , $ listOfFields );
9795 }
9896 // Ask the user for configuration key for each table
9997 $ this ->getConfigurationKeys ();
10098 // Replace in fields and save modified data
10199 $ 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 () . ') ' );
107102 $ this ->quit (1 );
108103 }
109104 }
@@ -122,11 +117,8 @@ protected function setFields($fields)
122117 list ($ table , $ field ) = explode ('. ' , $ aField );
123118 if (empty ($ table ) || empty ($ field )) {
124119 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
130122 );
131123 } else {
132124 if (!array_key_exists ($ table , $ this ->tablesAndFields )) {
@@ -150,22 +142,15 @@ protected function setFields($fields)
150142 protected function gatherRecordsToMigrate ($ table , $ listOfFields )
151143 {
152144 try {
153- $ records = $ this ->genericRepository ->findByRecordLink (
154- $ table ,
155- $ listOfFields
156- );
145+ $ records = $ this ->genericRepository ->findByRecordLink ($ table , $ listOfFields );
157146 foreach ($ records as $ record ) {
158147 $ id = (int )$ record ['uid ' ];
159148 foreach ($ listOfFields as $ field ) {
160149 $ matches = array ();
161150 // Find all element that have a syntax like "record:string:string(:string)"
162151 // The last string is optional. If it exists, it is already a 4-part record reference,
163152 // 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 );
169154 foreach ($ matches as $ index => $ match ) {
170155 // Consider only matches that have 3 parts (i.e. 4th part is empty)
171156 // NOTE: although not captured, the first part is "record:"
@@ -186,23 +171,16 @@ protected function gatherRecordsToMigrate($table, $listOfFields)
186171 if (!array_key_exists ($ field , $ this ->recordsForMigration [$ table ][$ id ])) {
187172 $ this ->recordsForMigration [$ table ][$ id ][$ field ] = array (
188173 'content ' => $ record [$ field ],
189- 'matches ' => array ()
174+ 'matches ' => array (),
190175 );
191176 }
192177 $ this ->recordsForMigration [$ table ][$ id ][$ field ]['matches ' ][] = $ matches [0 ][$ index ];
193178 }
194179 }
195180 }
196181 }
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 ()));
206184 }
207185 }
208186
@@ -211,19 +189,16 @@ protected function gatherRecordsToMigrate($table, $listOfFields)
211189 *
212190 * @return void
213191 */
214- protected function getConfigurationKeys () {
192+ protected function getConfigurationKeys ()
193+ {
215194 foreach ($ this ->tablesForMigration as $ table => &$ dummy ) {
216195 $ key = null ;
217196 do {
218197 try {
219198 $ 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 )
224200 );
225- }
226- catch (\Exception $ e ) {
201+ } catch (\Exception $ e ) {
227202 // Do nothing, just let it try again
228203 }
229204 } while ($ key === null );
@@ -246,27 +221,17 @@ protected function migrateRecords()
246221 foreach ($ fieldInformation ['matches ' ] as $ link ) {
247222 $ linkParts = explode (': ' , $ link );
248223 $ 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 );
254225 }
255226 if (!array_key_exists ($ id , $ recordsForTable )) {
256227 $ recordsForTable [$ id ] = array ();
257228 }
258229 $ recordsForTable [$ id ][$ field ] = $ updatedField ;
259230 }
260231 }
261- $ result = $ this ->genericRepository ->massUpdate (
262- $ table ,
263- $ recordsForTable
264- );
232+ $ result = $ this ->genericRepository ->massUpdate ($ table , $ recordsForTable );
265233 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 );
270235 }
271236 }
272237 }
0 commit comments