From 0e9d09f6fa39b5668def537b98b75dbe8128a6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 24 Sep 2012 08:41:22 +0200 Subject: [PATCH] Join to ifs to limit nesting --- libraries/server_synchronize.lib.php | 63 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/libraries/server_synchronize.lib.php b/libraries/server_synchronize.lib.php index b29d5c026f..be2bd22bf3 100644 --- a/libraries/server_synchronize.lib.php +++ b/libraries/server_synchronize.lib.php @@ -465,43 +465,42 @@ function PMA_updateTargetTables( $table, $update_array, $src_db, $trg_db, $trg_link, $matching_table_index, $matching_table_keys, $display ) { - if (isset($update_array[$matching_table_index])) { - if (count($update_array[$matching_table_index])) { + if (isset($update_array[$matching_table_index]) + && count($update_array[$matching_table_index]) + ) { + for ($update_row = 0; $update_row < count($update_array[$matching_table_index]); $update_row++) { - for ($update_row = 0; $update_row < count($update_array[$matching_table_index]); $update_row++) { + if (isset($update_array[$matching_table_index][$update_row])) { + $update_fields_num = count($update_array[$matching_table_index][$update_row]) - count($matching_table_keys[$matching_table_index]); + if ($update_fields_num > 0) { + $query = "UPDATE " . PMA_Util::backquote($trg_db) . "." + . PMA_Util::backquote($table[$matching_table_index]) + . " SET "; - if (isset($update_array[$matching_table_index][$update_row])) { - $update_fields_num = count($update_array[$matching_table_index][$update_row])-count($matching_table_keys[$matching_table_index]); - if ($update_fields_num > 0) { - $query = "UPDATE " . PMA_Util::backquote($trg_db) . "." - . PMA_Util::backquote($table[$matching_table_index]) - . " SET "; - - for ($update_field = 0; $update_field < $update_fields_num; $update_field = $update_field+2) { - if (isset($update_array[$matching_table_index][$update_row][$update_field]) && isset($update_array[$matching_table_index][$update_row][$update_field+1])) { - $query .= PMA_Util::backquote($update_array[$matching_table_index][$update_row][$update_field]) . "='" . $update_array[$matching_table_index][$update_row][$update_field+1] . "'"; - } - if ($update_field < ($update_fields_num - 2)) { - $query .= ", "; - } + for ($update_field = 0; $update_field < $update_fields_num; $update_field = $update_field+2) { + if (isset($update_array[$matching_table_index][$update_row][$update_field]) && isset($update_array[$matching_table_index][$update_row][$update_field+1])) { + $query .= PMA_Util::backquote($update_array[$matching_table_index][$update_row][$update_field]) . "='" . $update_array[$matching_table_index][$update_row][$update_field+1] . "'"; } - $query .= " WHERE "; - if (isset($matching_table_keys[$matching_table_index])) { - for ($key = 0; $key < count($matching_table_keys[$matching_table_index]); $key++) { - if (isset($matching_table_keys[$matching_table_index][$key])) { - $query .= PMA_Util::backquote($matching_table_keys[$matching_table_index][$key]) . "='" . $update_array[$matching_table_index][$update_row][$matching_table_keys[$matching_table_index][$key]] . "'"; - } - if ($key < (count($matching_table_keys[$matching_table_index]) - 1)) { - $query .= " AND "; - } - } + if ($update_field < ($update_fields_num - 2)) { + $query .= ", "; } - $query .= ';'; - if ($display == true) { - echo "

" . $query . "

"; - } - PMA_DBI_try_query($query, $trg_link, 0); } + $query .= " WHERE "; + if (isset($matching_table_keys[$matching_table_index])) { + for ($key = 0; $key < count($matching_table_keys[$matching_table_index]); $key++) { + if (isset($matching_table_keys[$matching_table_index][$key])) { + $query .= PMA_Util::backquote($matching_table_keys[$matching_table_index][$key]) . "='" . $update_array[$matching_table_index][$update_row][$matching_table_keys[$matching_table_index][$key]] . "'"; + } + if ($key < (count($matching_table_keys[$matching_table_index]) - 1)) { + $query .= " AND "; + } + } + } + $query .= ';'; + if ($display == true) { + echo "

" . $query . "

"; + } + PMA_DBI_try_query($query, $trg_link, 0); } } }