@@ -97,7 +97,47 @@ public function __invoke(ServerRequest $request): void
9797 }
9898
9999 // updates for foreign keys
100- $ this ->updateForForeignKeys ($ table , $ options , $ relationsForeign );
100+ $ multiEditColumnsName = $ _POST ['foreign_key_fields_name ' ] ?? null ;
101+ $ previewSqlData = '' ;
102+ $ seenError = false ;
103+
104+ // (for now, one index name only; we keep the definitions if the
105+ // foreign db is not the same)
106+ if (
107+ isset ($ _POST ['destination_foreign_db ' ], $ _POST ['destination_foreign_table ' ])
108+ && isset ($ _POST ['destination_foreign_column ' ])
109+ ) {
110+ [$ html , $ previewSqlData , $ displayQuery , $ seenError ] = $ table ->updateForeignKeys (
111+ $ _POST ['destination_foreign_db ' ],
112+ $ multiEditColumnsName ,
113+ $ _POST ['destination_foreign_table ' ],
114+ $ _POST ['destination_foreign_column ' ],
115+ $ options ,
116+ $ GLOBALS ['table ' ],
117+ array_key_exists ('foreign_keys_data ' , $ relationsForeign )
118+ ? $ relationsForeign ['foreign_keys_data ' ]
119+ : [],
120+ );
121+ $ this ->response ->addHTML ($ html );
122+ }
123+
124+ // If there is a request for SQL previewing.
125+ if (isset ($ _POST ['preview_sql ' ])) {
126+ Core::previewSQL ($ previewSqlData );
127+
128+ return ;
129+ }
130+
131+ if (! empty ($ displayQuery ) && ! $ seenError ) {
132+ $ GLOBALS ['display_query ' ] = $ displayQuery ;
133+ $ this ->response ->addHTML (
134+ Generator::getMessage (
135+ __ ('Your SQL query has been executed successfully. ' ),
136+ null ,
137+ 'success ' ,
138+ ),
139+ );
140+ }
101141
102142 // Updates for display field
103143 if ($ relationParameters ->displayFeature !== null && isset ($ _POST ['display_field ' ])) {
@@ -234,60 +274,6 @@ private function updateForDisplayField(Table $table, DisplayFeature $displayFeat
234274 );
235275 }
236276
237- /**
238- * Update for FK
239- *
240- * @param Table $table Table
241- * @param mixed[] $options Options
242- * @param mixed[] $relationsForeign External relations
243- */
244- private function updateForForeignKeys (Table $ table , array $ options , array $ relationsForeign ): void
245- {
246- $ multiEditColumnsName = $ _POST ['foreign_key_fields_name ' ] ?? null ;
247- $ previewSqlData = '' ;
248- $ seenError = false ;
249-
250- // (for now, one index name only; we keep the definitions if the
251- // foreign db is not the same)
252- if (
253- isset ($ _POST ['destination_foreign_db ' ], $ _POST ['destination_foreign_table ' ])
254- && isset ($ _POST ['destination_foreign_column ' ])
255- ) {
256- [$ html , $ previewSqlData , $ displayQuery , $ seenError ] = $ table ->updateForeignKeys (
257- $ _POST ['destination_foreign_db ' ],
258- $ multiEditColumnsName ,
259- $ _POST ['destination_foreign_table ' ],
260- $ _POST ['destination_foreign_column ' ],
261- $ options ,
262- $ GLOBALS ['table ' ],
263- array_key_exists ('foreign_keys_data ' , $ relationsForeign )
264- ? $ relationsForeign ['foreign_keys_data ' ]
265- : [],
266- );
267- $ this ->response ->addHTML ($ html );
268- }
269-
270- // If there is a request for SQL previewing.
271- if (isset ($ _POST ['preview_sql ' ])) {
272- Core::previewSQL ($ previewSqlData );
273-
274- $ this ->response ->callExit ();
275- }
276-
277- if (empty ($ displayQuery ) || $ seenError ) {
278- return ;
279- }
280-
281- $ GLOBALS ['display_query ' ] = $ displayQuery ;
282- $ this ->response ->addHTML (
283- Generator::getMessage (
284- __ ('Your SQL query has been executed successfully. ' ),
285- null ,
286- 'success ' ,
287- ),
288- );
289- }
290-
291277 /**
292278 * Update for internal relation
293279 *
0 commit comments