2727use function __ ;
2828use function count ;
2929use function implode ;
30+ use function is_array ;
31+ use function is_string ;
3032use function mb_strstr ;
3133use function mb_strtolower ;
3234use function mb_strtoupper ;
@@ -161,7 +163,7 @@ public function __invoke(ServerRequest $request): void
161163 /**
162164 * If the table has to be moved to some other database
163165 */
164- if (isset ( $ _POST [ 'submit_move ' ] ) || isset ( $ _POST [ 'submit_copy ' ] )) {
166+ if ($ request -> hasBodyParam ( 'submit_move ' ) || $ request -> hasBodyParam ( 'submit_copy ' )) {
165167 $ message = $ this ->operations ->moveOrCopyTable ($ GLOBALS ['db ' ], $ GLOBALS ['table ' ]);
166168
167169 if (! $ this ->response ->isAjax ()) {
@@ -171,8 +173,10 @@ public function __invoke(ServerRequest $request): void
171173 $ this ->response ->addJSON ('message ' , $ message );
172174
173175 if ($ message ->isSuccess ()) {
174- if (isset ($ _POST ['submit_move ' ], $ _POST ['target_db ' ])) {
175- $ GLOBALS ['db ' ] = $ _POST ['target_db ' ];// Used in Header::getJsParams()
176+ /** @var mixed $targetDbParam */
177+ $ targetDbParam = $ request ->getParsedBodyParam ('target_db ' );
178+ if ($ request ->hasBodyParam ('submit_move ' ) && is_string ($ targetDbParam )) {
179+ $ GLOBALS ['db ' ] = $ targetDbParam ; // Used in Header::getJsParams()
176180 }
177181
178182 $ this ->response ->addJSON ('db ' , $ GLOBALS ['db ' ]);
@@ -188,27 +192,31 @@ public function __invoke(ServerRequest $request): void
188192 /**
189193 * Updates table comment, type and options if required
190194 */
191- if (isset ( $ _POST [ 'submitoptions ' ] )) {
195+ if ($ request -> hasBodyParam ( 'submitoptions ' )) {
192196 $ _message = '' ;
193197 $ GLOBALS ['warning_messages ' ] = [];
194198
195- if (isset ($ _POST ['new_name ' ])) {
199+ /** @var mixed $newName */
200+ $ newName = $ request ->getParsedBodyParam ('new_name ' );
201+ if (is_string ($ newName )) {
196202 // lower_case_table_names=1 `DB` becomes `db`
197203 if ($ GLOBALS ['lowerCaseNames ' ]) {
198- $ _POST [ ' new_name ' ] = mb_strtolower ($ _POST [ ' new_name ' ] );
204+ $ newName = mb_strtolower ($ newName );
199205 }
200206
201207 // Get original names before rename operation
202208 $ oldTable = $ pma_table ->getName ();
203209 $ oldDb = $ pma_table ->getDbName ();
204210
205- if ($ pma_table ->rename ($ _POST ['new_name ' ])) {
206- if (isset ($ _POST ['adjust_privileges ' ]) && ! empty ($ _POST ['adjust_privileges ' ])) {
211+ if ($ pma_table ->rename ($ newName )) {
212+ if ($ request ->getParsedBodyParam ('adjust_privileges ' )) {
213+ /** @var mixed $dbParam */
214+ $ dbParam = $ request ->getParsedBodyParam ('db ' );
207215 $ this ->operations ->adjustPrivilegesRenameOrMoveTable (
208216 $ oldDb ,
209217 $ oldTable ,
210- $ _POST [ ' db ' ] ,
211- $ _POST [ ' new_name ' ]
218+ is_string ( $ dbParam ) ? $ dbParam : '' ,
219+ $ newName
212220 );
213221 }
214222
@@ -226,11 +234,13 @@ public function __invoke(ServerRequest $request): void
226234 }
227235 }
228236
237+ /** @var mixed $newTableStorageEngine */
238+ $ newTableStorageEngine = $ request ->getParsedBodyParam ('new_tbl_storage_engine ' );
229239 if (
230- ! empty ( $ _POST [ ' new_tbl_storage_engine ' ])
231- && mb_strtoupper ($ _POST [ ' new_tbl_storage_engine ' ] ) !== $ GLOBALS ['tbl_storage_engine ' ]
240+ is_string ( $ newTableStorageEngine ) && $ newTableStorageEngine !== ''
241+ && mb_strtoupper ($ newTableStorageEngine ) !== $ GLOBALS ['tbl_storage_engine ' ]
232242 ) {
233- $ GLOBALS ['new_tbl_storage_engine ' ] = mb_strtoupper ($ _POST [ ' new_tbl_storage_engine ' ] );
243+ $ GLOBALS ['new_tbl_storage_engine ' ] = mb_strtoupper ($ newTableStorageEngine );
234244
235245 if ($ pma_table ->isEngine ('ARIA ' )) {
236246 $ GLOBALS ['create_options ' ]['transactional ' ] = ($ GLOBALS ['create_options ' ]['transactional ' ] ?? '' )
@@ -267,15 +277,20 @@ public function __invoke(ServerRequest $request): void
267277 $ GLOBALS ['warning_messages ' ] = $ this ->operations ->getWarningMessagesArray ();
268278 }
269279
270- if (! empty ($ _POST ['tbl_collation ' ]) && ! empty ($ _POST ['change_all_collations ' ])) {
280+ /** @var mixed $tableCollationParam */
281+ $ tableCollationParam = $ request ->getParsedBodyParam ('tbl_collation ' );
282+ if (
283+ is_string ($ tableCollationParam ) && $ tableCollationParam !== ''
284+ && $ request ->getParsedBodyParam ('change_all_collations ' )
285+ ) {
271286 $ this ->operations ->changeAllColumnsCollation (
272287 $ GLOBALS ['db ' ],
273288 $ GLOBALS ['table ' ],
274- $ _POST [ ' tbl_collation ' ]
289+ $ tableCollationParam
275290 );
276291 }
277292
278- if (isset ( $ _POST [ ' tbl_collation ' ]) && empty ( $ _POST [ ' tbl_collation ' ] )) {
293+ if ($ tableCollationParam !== null && (! is_string ( $ tableCollationParam ) || $ tableCollationParam === '' )) {
279294 if ($ this ->response ->isAjax ()) {
280295 $ this ->response ->setRequestStatus (false );
281296 $ this ->response ->addJSON (
@@ -288,26 +303,38 @@ public function __invoke(ServerRequest $request): void
288303 }
289304 }
290305
306+ /** @var mixed $orderField */
307+ $ orderField = $ request ->getParsedBodyParam ('order_field ' );
308+
291309 /**
292310 * Reordering the table has been requested by the user
293311 */
294- if (isset ($ _POST ['submitorderby ' ]) && ! empty ($ _POST ['order_field ' ])) {
312+ if ($ request ->hasBodyParam ('submitorderby ' ) && is_string ($ orderField ) && $ orderField !== '' ) {
313+ /** @var mixed $orderOrder */
314+ $ orderOrder = $ request ->getParsedBodyParam ('order_order ' );
295315 $ GLOBALS ['sql_query ' ] = QueryGenerator::getQueryForReorderingTable (
296316 $ GLOBALS ['table ' ],
297- urldecode ($ _POST [ ' order_field ' ] ),
298- $ _POST [ ' order_order ' ] ?? null
317+ urldecode ($ orderField ),
318+ is_string ( $ orderOrder ) ? $ orderOrder : ''
299319 );
300320 $ GLOBALS ['result ' ] = $ this ->dbi ->query ($ GLOBALS ['sql_query ' ]);
301321 }
302322
323+ /** @var mixed $partitionOperation */
324+ $ partitionOperation = $ request ->getParsedBodyParam ('partition_operation ' );
325+
303326 /**
304327 * A partition operation has been requested by the user
305328 */
306- if (isset ($ _POST ['submit_partition ' ]) && ! empty ($ _POST ['partition_operation ' ])) {
329+ if (
330+ $ request ->hasBodyParam ('submit_partition ' ) && is_string ($ partitionOperation ) && $ partitionOperation !== ''
331+ ) {
332+ /** @var mixed $partitionNames */
333+ $ partitionNames = $ request ->getParsedBodyParam ('partition_name ' );
307334 $ GLOBALS ['sql_query ' ] = QueryGenerator::getQueryForPartitioningTable (
308335 $ GLOBALS ['table ' ],
309- $ _POST [ ' partition_operation ' ] ,
310- $ _POST [ ' partition_name ' ]
336+ $ partitionOperation ,
337+ is_array ( $ partitionNames ) ? $ partitionNames : [ ]
311338 );
312339 $ GLOBALS ['result ' ] = $ this ->dbi ->query ($ GLOBALS ['sql_query ' ]);
313340 }
0 commit comments