@@ -343,42 +343,7 @@ public function __invoke(ServerRequest $request): void
343343 $ gotoInclude = '/table/change ' ;
344344 }
345345
346- $ GLOBALS ['active_page ' ] = $ gotoInclude ;
347-
348- if ($ gotoInclude === '/sql ' ) {
349- /** @var SqlController $controller */
350- $ controller = $ GLOBALS ['containerBuilder ' ]->get (SqlController::class);
351- $ controller ($ request );
352-
353- return ;
354- }
355-
356- if ($ gotoInclude === '/database/sql ' ) {
357- /** @var DatabaseSqlController $controller */
358- $ controller = $ GLOBALS ['containerBuilder ' ]->get (DatabaseSqlController::class);
359- $ controller ($ request );
360-
361- return ;
362- }
363-
364- if ($ gotoInclude === '/table/change ' ) {
365- /** @var ChangeController $controller */
366- $ controller = $ GLOBALS ['containerBuilder ' ]->get (ChangeController::class);
367- $ controller ($ request );
368-
369- return ;
370- }
371-
372- if ($ gotoInclude === '/table/sql ' ) {
373- /** @var TableSqlController $controller */
374- $ controller = $ GLOBALS ['containerBuilder ' ]->get (TableSqlController::class);
375- $ controller ($ request );
376-
377- return ;
378- }
379-
380- /** @psalm-suppress UnresolvableInclude */
381- include ROOT_PATH . Core::securePath ($ gotoInclude );
346+ $ this ->moveBackToCallingScript ($ gotoInclude , $ request );
382347
383348 return ;
384349 }
@@ -442,84 +407,7 @@ public function __invoke(ServerRequest $request): void
442407 * transformed fields, if they were edited. After that, output the correct
443408 * link/transformed value and exit
444409 */
445- if (isset ($ _POST ['rel_fields_list ' ]) && $ _POST ['rel_fields_list ' ] != '' ) {
446- $ map = $ this ->relation ->getForeigners ($ GLOBALS ['db ' ], $ GLOBALS ['table ' ]);
447-
448- /** @var array<int,array> $relation_fields */
449- $ relation_fields = [];
450- parse_str ($ _POST ['rel_fields_list ' ], $ relation_fields );
451-
452- // loop for each relation cell
453- foreach ($ relation_fields as $ cell_index => $ curr_rel_field ) {
454- foreach ($ curr_rel_field as $ relation_field => $ relation_field_value ) {
455- $ where_comparison = "=' " . $ relation_field_value . "' " ;
456- $ dispval = $ this ->insertEdit ->getDisplayValueForForeignTableColumn (
457- $ where_comparison ,
458- $ map ,
459- $ relation_field
460- );
461-
462- $ extra_data ['relations ' ][$ cell_index ] = $ this ->insertEdit ->getLinkForRelationalDisplayField (
463- $ map ,
464- $ relation_field ,
465- $ where_comparison ,
466- $ dispval ,
467- $ relation_field_value
468- );
469- }
470- }
471- }
472-
473- if (isset ($ _POST ['do_transformations ' ]) && $ _POST ['do_transformations ' ] == true ) {
474- $ edited_values = [];
475- parse_str ($ _POST ['transform_fields_list ' ], $ edited_values );
476-
477- if (! isset ($ extra_data )) {
478- $ extra_data = [];
479- }
480-
481- $ transformation_types = [
482- 'input_transformation ' ,
483- 'transformation ' ,
484- ];
485- foreach ($ mimeMap as $ transformation ) {
486- $ column_name = $ transformation ['column_name ' ];
487- foreach ($ transformation_types as $ type ) {
488- $ file = Core::securePath ($ transformation [$ type ]);
489- $ extra_data = $ this ->insertEdit ->transformEditedValues (
490- $ GLOBALS ['db ' ],
491- $ GLOBALS ['table ' ],
492- $ transformation ,
493- $ edited_values ,
494- $ file ,
495- $ column_name ,
496- $ extra_data ,
497- $ type
498- );
499- }
500- }
501- }
502-
503- // Need to check the inline edited value can be truncated by MySQL
504- // without informing while saving
505- $ column_name = $ _POST ['fields_name ' ]['multi_edit ' ][0 ][0 ];
506-
507- $ this ->insertEdit ->verifyWhetherValueCanBeTruncatedAndAppendExtraData (
508- $ GLOBALS ['db ' ],
509- $ GLOBALS ['table ' ],
510- $ column_name ,
511- $ extra_data
512- );
513-
514- /**Get the total row count of the table*/
515- $ _table = new Table ($ _POST ['table ' ], $ _POST ['db ' ]);
516- $ extra_data ['row_count ' ] = $ _table ->countRecords ();
517-
518- $ extra_data ['sql_query ' ] = Generator::getMessage ($ GLOBALS ['message ' ], $ GLOBALS ['display_query ' ]);
519-
520- $ this ->response ->setRequestStatus ($ GLOBALS ['message ' ]->isSuccess ());
521- $ this ->response ->addJSON ('message ' , $ GLOBALS ['message ' ]);
522- $ this ->response ->addJSON ($ extra_data );
410+ $ this ->doTransformations ($ mimeMap );
523411
524412 return ;
525413 }
@@ -533,8 +421,6 @@ public function __invoke(ServerRequest $request): void
533421
534422 $ this ->addScriptFiles (['vendor/jquery/additional-methods.js ' , 'table/change.js ' ]);
535423
536- $ GLOBALS ['active_page ' ] = $ gotoInclude ;
537-
538424 /**
539425 * If user asked for "and then Insert another new row" we have to remove
540426 * WHERE clause information so that /table/change does not go back
@@ -544,6 +430,98 @@ public function __invoke(ServerRequest $request): void
544430 unset($ _POST ['where_clause ' ]);
545431 }
546432
433+ $ this ->moveBackToCallingScript ($ gotoInclude , $ request );
434+ }
435+
436+ /**
437+ * @param string[][] $mimeMap
438+ */
439+ private function doTransformations (array $ mimeMap ): void
440+ {
441+ if (isset ($ _POST ['rel_fields_list ' ]) && $ _POST ['rel_fields_list ' ] != '' ) {
442+ $ map = $ this ->relation ->getForeigners ($ GLOBALS ['db ' ], $ GLOBALS ['table ' ]);
443+
444+ /** @var array<int,array> $relation_fields */
445+ $ relation_fields = [];
446+ parse_str ($ _POST ['rel_fields_list ' ], $ relation_fields );
447+
448+ // loop for each relation cell
449+ foreach ($ relation_fields as $ cell_index => $ curr_rel_field ) {
450+ foreach ($ curr_rel_field as $ relation_field => $ relation_field_value ) {
451+ $ where_comparison = "=' " . $ relation_field_value . "' " ;
452+ $ dispval = $ this ->insertEdit ->getDisplayValueForForeignTableColumn (
453+ $ where_comparison ,
454+ $ map ,
455+ $ relation_field
456+ );
457+
458+ $ extra_data ['relations ' ][$ cell_index ] = $ this ->insertEdit ->getLinkForRelationalDisplayField (
459+ $ map ,
460+ $ relation_field ,
461+ $ where_comparison ,
462+ $ dispval ,
463+ $ relation_field_value
464+ );
465+ }
466+ }
467+ }
468+
469+ if (isset ($ _POST ['do_transformations ' ]) && $ _POST ['do_transformations ' ] == true ) {
470+ $ edited_values = [];
471+ parse_str ($ _POST ['transform_fields_list ' ], $ edited_values );
472+
473+ if (! isset ($ extra_data )) {
474+ $ extra_data = [];
475+ }
476+
477+ $ transformation_types = [
478+ 'input_transformation ' ,
479+ 'transformation ' ,
480+ ];
481+ foreach ($ mimeMap as $ transformation ) {
482+ $ column_name = $ transformation ['column_name ' ];
483+ foreach ($ transformation_types as $ type ) {
484+ $ file = Core::securePath ($ transformation [$ type ]);
485+ $ extra_data = $ this ->insertEdit ->transformEditedValues (
486+ $ GLOBALS ['db ' ],
487+ $ GLOBALS ['table ' ],
488+ $ transformation ,
489+ $ edited_values ,
490+ $ file ,
491+ $ column_name ,
492+ $ extra_data ,
493+ $ type
494+ );
495+ }
496+ }
497+ }
498+
499+ // Need to check the inline edited value can be truncated by MySQL
500+ // without informing while saving
501+ $ column_name = $ _POST ['fields_name ' ]['multi_edit ' ][0 ][0 ];
502+
503+ $ this ->insertEdit ->verifyWhetherValueCanBeTruncatedAndAppendExtraData (
504+ $ GLOBALS ['db ' ],
505+ $ GLOBALS ['table ' ],
506+ $ column_name ,
507+ $ extra_data
508+ );
509+
510+ /**Get the total row count of the table*/
511+ $ _table = new Table ($ _POST ['table ' ], $ _POST ['db ' ]);
512+ $ extra_data ['row_count ' ] = $ _table ->countRecords ();
513+
514+ $ extra_data ['sql_query ' ] = Generator::getMessage ($ GLOBALS ['message ' ], $ GLOBALS ['display_query ' ]);
515+
516+ $ this ->response ->setRequestStatus ($ GLOBALS ['message ' ]->isSuccess ());
517+ $ this ->response ->addJSON ('message ' , $ GLOBALS ['message ' ]);
518+ $ this ->response ->addJSON ($ extra_data );
519+ }
520+
521+ private function moveBackToCallingScript (string $ gotoInclude , ServerRequest $ request ): void
522+ {
523+ $ GLOBALS ['active_page ' ] = $ gotoInclude ;
524+
547525 if ($ gotoInclude === '/sql ' ) {
548526 /** @var SqlController $controller */
549527 $ controller = $ GLOBALS ['containerBuilder ' ]->get (SqlController::class);
0 commit comments