From cc79df9e8dfd7a51ee400360a2d05f1e7227a114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 29 May 2012 16:37:29 +0200 Subject: [PATCH 1/7] Wrap some comments --- libraries/server_synchronize.lib.php | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/libraries/server_synchronize.lib.php b/libraries/server_synchronize.lib.php index 1d17fbad41..a99dcf7944 100644 --- a/libraries/server_synchronize.lib.php +++ b/libraries/server_synchronize.lib.php @@ -1029,8 +1029,10 @@ function PMA_checkForeignKeys($src_db, $src_link, $trg_db, $trg_link, * altered for the targert table * @param array $matching_tables_fields name of the fields for the matching table * @param array $criteria criteria - * @param array &$matching_tables_keys field names which is key in the source table - * @param array &$target_tables_keys field names which is key in the target table + * @param array &$matching_tables_keys field names which is key in the source + * table + * @param array &$target_tables_keys field names which is key in the target + * table * @param int $matching_table_index number of the matching table * @param bool $display whether to display query * @@ -1163,8 +1165,10 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, * @param string $trg_db name of target database * @param mixed $trg_link connection established with target server * @param array $matching_tables names of matching tables - * @param array $uncommon_columns array containing the names of the column which are to be dropped from the target table - * @param int $table_counter index of the matching table as in $matchiing_tables array + * @param array $uncommon_columns array containing the names of the column which + * are to be dropped from the target table + * @param int $table_counter index of the matching table as in + * $matchiing_tables array * @param bool $display whether to display query * * @return nothing @@ -1214,9 +1218,11 @@ function PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, } /** - * PMA_indexesDiffInTables() compares the source table indexes with target table indexes and keep the indexes to be added in target table in $add_indexes_array - * indexes to be altered in $alter_indexes_array and indexes to be removed from target table in $remove_indexes_array. - * Only keyname and uniqueness characteristic of the indexes are altered. + * PMA_indexesDiffInTables() compares the source table indexes with target + * table indexes and keep the indexes to be added in target table in + * $add_indexes_array indexes to be altered in $alter_indexes_array and indexes + * to be removed from target table in $remove_indexes_array. Only keyname and + * uniqueness characteristic of the indexes are altered. * * @param string $src_db name of source database * @param string $trg_db name of target database @@ -1290,9 +1296,12 @@ function PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, * @param array $matching_tables matching tables name * @param array $source_indexes indexes of the source table * @param array $target_indexes indexes of the target table - * @param array $add_indexes_array column names on which indexes are to be created in target table - * @param array $alter_indexes_array column names for which indexes are to be altered - * @param array $remove_indexes_array key name of the indexes which are to be removed from the target table + * @param array $add_indexes_array column names on which indexes are to be + * created in target table + * @param array $alter_indexes_array column names for which indexes are to be + * altered + * @param array $remove_indexes_array key name of the indexes which are to be + * removed from the target table * @param int $table_counter number of the matching table * @param bool $display whether to display query * From 624d0b2fc01e7c492595deb9420fbea2cff9b151 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 29 May 2012 16:43:11 +0200 Subject: [PATCH 2/7] Wrap some long lines --- libraries/server_synchronize.lib.php | 109 ++++++++++++++++++--------- 1 file changed, 74 insertions(+), 35 deletions(-) diff --git a/libraries/server_synchronize.lib.php b/libraries/server_synchronize.lib.php index a99dcf7944..446117c8e3 100644 --- a/libraries/server_synchronize.lib.php +++ b/libraries/server_synchronize.lib.php @@ -158,10 +158,12 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, // Query the target server to see which rows already exist $trg_select_query = "SELECT * FROM " . PMA_backquote($trg_db) . "." - . PMA_backquote($matching_table[$matching_table_index]) . " WHERE "; + . PMA_backquote($matching_table[$matching_table_index]) + . " WHERE "; if (sizeof($is_key) == 1) { - $trg_select_query .= PMA_backquote($is_key[0]). "='" . $source_result_set[$j] . "'"; + $trg_select_query .= PMA_backquote($is_key[0]) + . "='" . $source_result_set[$j] . "'"; } elseif (sizeof($is_key) > 1) { for ($k=0; $k < sizeof($is_key); $k++) { $trg_select_query .= PMA_backquote($is_key[$k]) @@ -176,8 +178,10 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, if ($target_result_set) { // Fetch the row from the source server to do a comparison - $src_select_query = "SELECT * FROM " . PMA_backquote($src_db) . "." - . PMA_backquote($matching_table[$matching_table_index]) . " WHERE "; + $src_select_query = "SELECT * FROM " + . PMA_backquote($src_db) . "." + . PMA_backquote($matching_table[$matching_table_index]) + . " WHERE "; if (sizeof($is_key) == 1) { $src_select_query .= PMA_backquote($is_key[0]) @@ -195,9 +199,10 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $src_result_set = PMA_DBI_fetch_result($src_select_query, null, null, $src_link); /** - * Comparing each corresponding field of the source and target matching rows. - * Placing the primary key, value of primary key, field to be updated, and the - * new value of field to be updated in each row of the update array. + * Comparing each corresponding field of the source and target + * matching rows. Placing the primary key, value of primary + * key, field to be updated, and the new value of field to + * be updated in each row of the update array. */ for ($m = 0; ($m < $fields_num[$matching_table_index]) && ($starting_index == 0) ; $m++) { if (isset($src_result_set[0][$fld[$m]])) { @@ -277,7 +282,8 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, } } else { /** - * Placing the primary key, and the value of primary key of the row that is to be inserted in the target table + * Placing the primary key, and the value of primary key of the + * row that is to be inserted in the target table */ if (sizeof($is_key) == 1) { if (isset($source_result_set[$j])) { @@ -294,8 +300,10 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, } } else { /** - * Placing the primary key, and the value of primary key of the row that is to be inserted in the target table - * This condition is met when there is an additional column in the source table + * Placing the primary key, and the value of primary key of the + * row that is to be inserted in the target table. This + * condition is met when there is an additional column in the + * source table */ if (sizeof($is_key) == 1) { if (isset($source_result_set[$j])) { @@ -405,7 +413,8 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table, */ function PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $index, &$row_count) { - $query = "SELECT COUNT(*) FROM " . PMA_backquote($src_db) . "." . PMA_backquote($source_tables_uncommon[$index]); + $query = "SELECT COUNT(*) FROM " . PMA_backquote($src_db) . "." + . PMA_backquote($source_tables_uncommon[$index]); $rows = PMA_DBI_fetch_result($query, null, null, $src_link); $row_count[$index] = $rows[0]; } @@ -488,20 +497,32 @@ function PMA_updateTargetTables( * @param mixed $trg_link connection established with target server * @param array $table_fields field names of a table * @param array &$array_insert - * @param int $matching_table_index index of matching table in matching_table_array - * @param array $matching_tables_keys field names that are keys in the matching table + * @param int $matching_table_index index of matching table in + * matching_table_array + * @param array $matching_tables_keys field names that are keys in the matching + * table * @param array $source_columns source column information - * @param array &$add_column_array column names that are to be added in target table - * @param array $criteria criteria like type, null, collation, default etc - * @param array $target_tables_keys field names that are keys in the target table - * @param array $uncommon_tables table names that are present in source db but not in targt db + * @param array &$add_column_array column names that are to be added in + * target table + * @param array $criteria criteria like type, null, collation, + * default etc + * @param array $target_tables_keys field names that are keys in the target + * table + * @param array $uncommon_tables table names that are present in source db + * but not in targt db * @param array &$uncommon_tables_fields field names of the uncommon tables - * @param array $uncommon_cols column names that are present in target table and not in source table + * @param array $uncommon_cols column names that are present in target + * table and not in source table * @param array &$alter_str_array column names that are to be altered - * @param array &$source_indexes column names on which indexes are made in source table - * @param array &$target_indexes column names on which indexes are made in target table - * @param array &$add_indexes_array column names on which index is to be added in target table - * @param array &$alter_indexes_array column names whose indexes are to be altered. Only index name and uniqueness of an index can be changed + * @param array &$source_indexes column names on which indexes are made + * in source table + * @param array &$target_indexes column names on which indexes are made + * in target table + * @param array &$add_indexes_array column names on which index is to be + * added in target table + * @param array &$alter_indexes_array column names whose indexes are to be + * altered. Only index name and uniqueness + * of an index can be changed * @param array &$delete_array rows that are to be deleted * @param array &$update_array rows that are to be updated in target * @param bool $display whether to display query @@ -713,10 +734,17 @@ function PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, function PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, $uncommon_tables, $table_index, $uncommon_tables_fields, $display ) { - $display = false; // todo: maybe display some of the queries if they are not too numerous - $unbuffered_result = PMA_DBI_try_query('SELECT * FROM ' . PMA_backquote($src_db) . '.' . PMA_backquote($uncommon_tables[$table_index]), $src_link, PMA_DBI_QUERY_UNBUFFERED); + // @todo: maybe display some of the queries if they are not too numerous + $display = false; + $unbuffered_result = PMA_DBI_try_query( + 'SELECT * FROM ' . PMA_backquote($src_db) . '.' + . PMA_backquote($uncommon_tables[$table_index]), + $src_link, + PMA_DBI_QUERY_UNBUFFERED + ); if (false !== $unbuffered_result) { - $insert_query = 'INSERT INTO ' . PMA_backquote($trg_db) . '.' .PMA_backquote($uncommon_tables[$table_index]) . ' VALUES'; + $insert_query = 'INSERT INTO ' . PMA_backquote($trg_db) . '.' + . PMA_backquote($uncommon_tables[$table_index]) . ' VALUES'; while ($one_row = PMA_DBI_fetch_row($unbuffered_result)) { $insert_query .= '('; $key_of_last_value = count($one_row) - 1; @@ -750,9 +778,8 @@ function PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, * * @return nothing */ -function PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $table_index, - $target_tables_keys, $delete_array, $display -) { +function PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, +$table_index, $target_tables_keys, $delete_array, $display) { for ($i = 0; $i < sizeof($delete_array[$table_index]); $i++) { if (isset($target_tables_keys[$table_index])) { $delete_query = 'DELETE FROM ' . PMA_backquote($trg_db) . '.' .PMA_backquote($matching_tables[$table_index]) . ' WHERE '; @@ -776,7 +803,13 @@ function PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $table_ if ($result_size > 0) { for ($b = 0; $b < $result_size; $b++) { - $drop_pk_query = "DELETE FROM " . PMA_backquote($pk_query_result[$b]['TABLE_SCHEMA']) . "." . PMA_backquote($pk_query_result[$b]['TABLE_NAME']) . " WHERE " . PMA_backquote($pk_query_result[$b]['COLUMN_NAME']) . " = " . $target_tables_keys[$table_index][$y] . ";"; + $drop_pk_query = "DELETE FROM " + . PMA_backquote($pk_query_result[$b]['TABLE_SCHEMA']) + . "." + . PMA_backquote($pk_query_result[$b]['TABLE_NAME']) + . " WHERE " + . PMA_backquote($pk_query_result[$b]['COLUMN_NAME']) + . " = " . $target_tables_keys[$table_index][$y] . ";"; PMA_DBI_try_query($drop_pk_query, $trg_link, 0); } } @@ -1139,7 +1172,8 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, } } $check = false; - $query = "ALTER TABLE " . PMA_backquote($trg_db) . '.' . PMA_backquote($matching_tables[$matching_table_index]); + $query = "ALTER TABLE " . PMA_backquote($trg_db) . '.' + . PMA_backquote($matching_tables[$matching_table_index]); for ($p = 0; $p < sizeof($matching_tables_keys[$matching_table_index]); $p++) { if ((isset($alter_str_array[$matching_table_index][$matching_tables_keys[$matching_table_index][$p]]['Key']))) { $check = true; @@ -1177,7 +1211,8 @@ function PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $table_counter, $display ) { if (isset($uncommon_columns[$table_counter])) { - $drop_query = "ALTER TABLE " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_tables[$table_counter]); + $drop_query = "ALTER TABLE " . PMA_backquote($trg_db) . "." + . PMA_backquote($matching_tables[$table_counter]); for ($a = 0; $a < sizeof($uncommon_columns[$table_counter]); $a++) { //Checks if column to be removed is a foreign key in any table $pk_query = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . $trg_db . "' @@ -1411,19 +1446,23 @@ function PMA_syncDisplayHeaderCompare($src_db, $trg_db) echo ''; echo ''; - echo ''; echo ''; - echo ''; echo ''; From 00e21a04d9d3becd9bbd72194b2dc3a12b5822dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 29 May 2012 16:45:23 +0200 Subject: [PATCH 3/7] Wrap some more lines --- libraries/server_synchronize.lib.php | 50 ++++++++++++++++++---------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/libraries/server_synchronize.lib.php b/libraries/server_synchronize.lib.php index 446117c8e3..389ed150f0 100644 --- a/libraries/server_synchronize.lib.php +++ b/libraries/server_synchronize.lib.php @@ -26,7 +26,8 @@ if (! defined('PHPMYADMIN')) { * @return nothing */ function PMA_getMatchingTables($trg_tables, $src_tables, &$matching_tables, -&$uncommon_source_tables) { + &$uncommon_source_tables +) { for ($k=0; $k< sizeof($src_tables); $k++) { $present_in_target = false; for ($l=0; $l < sizeof($trg_tables); $l++) { @@ -54,7 +55,8 @@ function PMA_getMatchingTables($trg_tables, $src_tables, &$matching_tables, * @return nothing */ function PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, -&$uncommon_target_tables) { + &$uncommon_target_tables +) { for ($c=0; $c $each_column) { if (isset($target_columns[$matching_table_index][$column_name]['Field'])) { - //If column exists in target table then matches criteria like type, null, collation, key, default, comment of the column + //If column exists in target table then matches criteria like type, + // null, collation, key, default, comment of the column for ($i = 0; $i < sizeof($criteria); $i++) { if ($source_columns[$matching_table_index][$column_name][$criteria[$i]] != $target_columns[$matching_table_index][$column_name][$criteria[$i]]) { if (($criteria[$i] == 'Default') && ($source_columns[$matching_table_index][$column_name][$criteria[$i]] == '' )) { From 7736cad4efa27ec764365b17e214e3cb9f0b2e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 29 May 2012 16:47:01 +0200 Subject: [PATCH 4/7] Use count instead of sizeof --- libraries/server_synchronize.lib.php | 180 +++++++++++++-------------- 1 file changed, 90 insertions(+), 90 deletions(-) diff --git a/libraries/server_synchronize.lib.php b/libraries/server_synchronize.lib.php index 389ed150f0..0507177ead 100644 --- a/libraries/server_synchronize.lib.php +++ b/libraries/server_synchronize.lib.php @@ -28,9 +28,9 @@ if (! defined('PHPMYADMIN')) { function PMA_getMatchingTables($trg_tables, $src_tables, &$matching_tables, &$uncommon_source_tables ) { - for ($k=0; $k< sizeof($src_tables); $k++) { + for ($k=0; $k< count($src_tables); $k++) { $present_in_target = false; - for ($l=0; $l < sizeof($trg_tables); $l++) { + for ($l=0; $l < count($trg_tables); $l++) { if ($src_tables[$k] === $trg_tables[$l]) { $present_in_target = true; $matching_tables[] = $src_tables[$k]; @@ -57,9 +57,9 @@ function PMA_getMatchingTables($trg_tables, $src_tables, &$matching_tables, function PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, &$uncommon_target_tables ) { - for ($c=0; $c 1) { - for ($k=0; $k < sizeof($is_key); $k++) { + } elseif (count($is_key) > 1) { + for ($k=0; $k < count($is_key); $k++) { $trg_select_query .= PMA_backquote($is_key[$k]) . "='" . $source_result_set[$j][$is_key[$k]] . "'"; - if ($k < (sizeof($is_key)-1)) { + if ($k < (count($is_key)-1)) { $trg_select_query .= " AND "; } } @@ -185,14 +185,14 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, . PMA_backquote($matching_table[$matching_table_index]) . " WHERE "; - if (sizeof($is_key) == 1) { + if (count($is_key) == 1) { $src_select_query .= PMA_backquote($is_key[0]) . "='" . $source_result_set[$j] . "'"; - } elseif (sizeof($is_key) > 1) { - for ($k=0; $k< sizeof($is_key); $k++) { + } elseif (count($is_key) > 1) { + for ($k=0; $k< count($is_key); $k++) { $src_select_query .= PMA_backquote($is_key[$k]) . "='" . $source_result_set[$j][$is_key[$k]] . "'"; - if ($k < (sizeof($is_key) - 1)) { + if ($k < (count($is_key) - 1)) { $src_select_query .= " AND "; } } @@ -210,12 +210,12 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, if (isset($src_result_set[0][$fld[$m]])) { if (isset($target_result_set[0][$fld[$m]])) { if (($src_result_set[0][$fld[$m]] != $target_result_set[0][$fld[$m]]) && (! (in_array($fld[$m], $is_key)))) { - if (sizeof($is_key) == 1) { + if (count($is_key) == 1) { if ($source_result_set[$j]) { $update_array[$matching_table_index][$update_row][$is_key[0]] = $source_result_set[$j]; } - } elseif (sizeof($is_key) > 1) { - for ($n=0; $n < sizeof($is_key); $n++) { + } elseif (count($is_key) > 1) { + for ($n=0; $n < count($is_key); $n++) { if (isset($src_result_set[0][$is_key[$n]])) { $update_array[$matching_table_index][$update_row][$is_key[$n]] = $src_result_set[0][$is_key[$n]]; } @@ -233,12 +233,12 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $update_row++; } } else { - if (sizeof($is_key) == 1) { + if (count($is_key) == 1) { if ($source_result_set[$j]) { $update_array[$matching_table_index][$update_row][$is_key[0]] = $source_result_set[$j]; } - } elseif (sizeof($is_key) > 1) { - for ($n = 0; $n < sizeof($is_key); $n++) { + } elseif (count($is_key) > 1) { + for ($n = 0; $n < count($is_key); $n++) { if (isset($src_result_set[0][$is_key[$n]])) { $update_array[$matching_table_index][$update_row][$is_key[$n]] = $src_result_set[0][$is_key[$n]]; } @@ -287,12 +287,12 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, * Placing the primary key, and the value of primary key of the * row that is to be inserted in the target table */ - if (sizeof($is_key) == 1) { + if (count($is_key) == 1) { if (isset($source_result_set[$j])) { $insert_array[$matching_table_index][$insert_row][$is_key[0]] = $source_result_set[$j]; } - } elseif (sizeof($is_key) > 1) { - for ($l = 0; $l < sizeof($is_key); $l++) { + } elseif (count($is_key) > 1) { + for ($l = 0; $l < count($is_key); $l++) { if (isset($source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]])) { $insert_array[$matching_table_index][$insert_row][$is_key[$l]] = $source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]]; } @@ -307,12 +307,12 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, * condition is met when there is an additional column in the * source table */ - if (sizeof($is_key) == 1) { + if (count($is_key) == 1) { if (isset($source_result_set[$j])) { $insert_array[$matching_table_index][$insert_row][$is_key[0]] = $source_result_set[$j]; } - } elseif (sizeof($is_key) > 1) { - for ($l = 0; $l < sizeof($is_key); $l++) { + } elseif (count($is_key) > 1) { + for ($l = 0; $l < count($is_key); $l++) { if (isset($source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]])) { $insert_array[$matching_table_index][$insert_row][$is_key[$l]] = $source_result_set[$j][$matching_tables_fields[$matching_table_index][$l]]; } @@ -349,7 +349,7 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table, $source_key_values = PMA_getColumnValues($src_db, $matching_table[$matching_table_index], $src_keys[$matching_table_index], $src_link); } $all_keys_match = 1; - for ($a = 0; $a < sizeof($trg_keys[$matching_table_index]); $a++) { + for ($a = 0; $a < count($trg_keys[$matching_table_index]); $a++) { if (isset($trg_keys[$matching_table_index][$a])) { if (! (in_array($trg_keys[$matching_table_index][$a], $src_keys[$matching_table_index]))) { $all_keys_match = 0; @@ -362,24 +362,24 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table, } } if (isset($trg_keys[$matching_table_index])) { - if ((sizeof($trg_keys[$matching_table_index]) == 1) && $all_keys_match) { + if ((count($trg_keys[$matching_table_index]) == 1) && $all_keys_match) { $row = 0; if (isset($target_key_values)) { - for ($i = 0; $i < sizeof($target_key_values); $i++) { + for ($i = 0; $i < count($target_key_values); $i++) { if (! (in_array($target_key_values[$i], $source_key_values))) { $delete_array[$matching_table_index][$row] = $target_key_values[$i]; $row++; } } } - } elseif ((sizeof($trg_keys[$matching_table_index]) > 1) && $all_keys_match) { + } elseif ((count($trg_keys[$matching_table_index]) > 1) && $all_keys_match) { $row = 0; if (isset($target_key_values)) { - for ($i = 0; $i < sizeof($target_key_values); $i++) { + for ($i = 0; $i < count($target_key_values); $i++) { $is_present = false; - for ($j = 0; $j < sizeof($source_key_values) && ($is_present == false) ; $j++) { + for ($j = 0; $j < count($source_key_values) && ($is_present == false) ; $j++) { $check = true; - for ($k = 0; $k < sizeof($trg_keys[$matching_table_index]); $k++) { + for ($k = 0; $k < count($trg_keys[$matching_table_index]); $k++) { if ($target_key_values[$i][$trg_keys[$matching_table_index][$k]] != $source_key_values[$j][$trg_keys[$matching_table_index][$k]]) { $check = false; } @@ -389,7 +389,7 @@ function PMA_findDeleteRowsFromTargetTables(&$delete_array, $matching_table, } } if (! ($is_present)) { - for ($l = 0; $l < sizeof($trg_keys[$matching_table_index]); $l++) { + for ($l = 0; $l < count($trg_keys[$matching_table_index]); $l++) { $delete_array[$matching_table_index][$row][$trg_keys[$matching_table_index][$l]] = $target_key_values[$i][$trg_keys[$matching_table_index][$l]]; } $row++; @@ -444,12 +444,12 @@ function PMA_updateTargetTables( $trg_link, $matching_table_index, $matching_table_keys, $display ) { if (isset($update_array[$matching_table_index])) { - if (sizeof($update_array[$matching_table_index])) { + if (count($update_array[$matching_table_index])) { - for ($update_row = 0; $update_row < sizeof($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 = sizeof($update_array[$matching_table_index][$update_row])-sizeof($matching_table_keys[$matching_table_index]); + $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_backquote($trg_db) . "." .PMA_backquote($table[$matching_table_index]) . " SET "; @@ -463,11 +463,11 @@ function PMA_updateTargetTables( } $query .= " WHERE "; if (isset($matching_table_keys[$matching_table_index])) { - for ($key = 0; $key < sizeof($matching_table_keys[$matching_table_index]); $key++) { + for ($key = 0; $key < count($matching_table_keys[$matching_table_index]); $key++) { if (isset($matching_table_keys[$matching_table_index][$key])) { $query .= PMA_backquote($matching_table_keys[$matching_table_index][$key]) . "='" . $update_array[$matching_table_index][$update_row][$matching_table_keys[$matching_table_index][$key]] . "'"; } - if ($key < (sizeof($matching_table_keys[$matching_table_index]) - 1)) { + if ($key < (count($matching_table_keys[$matching_table_index]) - 1)) { $query .= " AND "; } } @@ -539,16 +539,16 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link, &$alter_indexes_array, &$delete_array, &$update_array, $display ) { if (isset($array_insert[$matching_table_index])) { - if (sizeof($array_insert[$matching_table_index])) { - for ($insert_row = 0; $insert_row< sizeof($array_insert[$matching_table_index]); $insert_row++) { + if (count($array_insert[$matching_table_index])) { + for ($insert_row = 0; $insert_row< count($array_insert[$matching_table_index]); $insert_row++) { if (isset($array_insert[$matching_table_index][$insert_row][$matching_tables_keys[$matching_table_index][0]])) { $select_query = "SELECT * FROM " . PMA_backquote($src_db) . "." . PMA_backquote($matching_table[$matching_table_index]) . " WHERE "; - for ($i = 0; $i < sizeof($matching_tables_keys[$matching_table_index]); $i++) { + for ($i = 0; $i < count($matching_tables_keys[$matching_table_index]); $i++) { $select_query .= $matching_tables_keys[$matching_table_index][$i] . "='"; $select_query .= $array_insert[$matching_table_index][$insert_row][$matching_tables_keys[$matching_table_index][$i]] . "'" ; - if ($i < (sizeof($matching_tables_keys[$matching_table_index]) - 1)) { + if ($i < (count($matching_tables_keys[$matching_table_index]) - 1)) { $select_query.= " AND "; } } @@ -556,7 +556,7 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link, $result = PMA_DBI_fetch_result($select_query, null, null, $src_link); $insert_query = "INSERT INTO " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_table[$matching_table_index]) ." ("; - for ($field_index = 0; $field_index < sizeof($table_fields[$matching_table_index]); $field_index++) { + for ($field_index = 0; $field_index < count($table_fields[$matching_table_index]); $field_index++) { $insert_query .= PMA_backquote($table_fields[$matching_table_index][$field_index]); $is_fk_query = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = '" . $trg_db ."' @@ -564,8 +564,8 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link, $table_fields[$matching_table_index][$field_index] . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;" ; $is_fk_result = PMA_DBI_fetch_result($is_fk_query, null, null, $trg_link); - if (sizeof($is_fk_result) > 0) { - for ($j = 0; $j < sizeof($is_fk_result); $j++) { + if (count($is_fk_result) > 0) { + for ($j = 0; $j < count($is_fk_result); $j++) { $table_index = array_keys($matching_table, $is_fk_result[$j]['REFERENCED_TABLE_NAME']); if (isset($alter_str_array[$table_index[0]])) { @@ -627,21 +627,21 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link, } } } - if ($field_index < sizeof($table_fields[$matching_table_index])-1) { + if ($field_index < count($table_fields[$matching_table_index])-1) { $insert_query .= ", "; } } $insert_query .= ") VALUES("; - if (sizeof($table_fields[$matching_table_index]) == 1) { + if (count($table_fields[$matching_table_index]) == 1) { $insert_query .= "'" . PMA_sqlAddSlashes($result[0]) . "'"; } else { - for ($field_index = 0; $field_index < sizeof($table_fields[$matching_table_index]); $field_index++) { + for ($field_index = 0; $field_index < count($table_fields[$matching_table_index]); $field_index++) { if (isset($result[0][$table_fields[$matching_table_index][$field_index]])) { $insert_query .= "'" . PMA_sqlAddSlashes($result[0][$table_fields[$matching_table_index][$field_index]]) . "'"; } else { $insert_query .= "'NULL'"; } - if ($field_index < (sizeof($table_fields[$matching_table_index])) - 1) { + if ($field_index < (count($table_fields[$matching_table_index])) - 1) { $insert_query .= " ," ; } } @@ -699,8 +699,8 @@ function PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, AND TABLE_NAME = '" . $uncommon_tables[$table_index] . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;" ; $is_fk_result = PMA_DBI_fetch_result($is_fk_query, null, null, $src_link); - if (sizeof($is_fk_result) > 0) { - for ($j = 0; $j < sizeof($is_fk_result); $j++) { + if (count($is_fk_result) > 0) { + for ($j = 0; $j < count($is_fk_result); $j++) { if (in_array($is_fk_result[$j]['REFERENCED_TABLE_NAME'], $uncommon_tables)) { $table_index = array_keys($uncommon_tables, $is_fk_result[$j]['REFERENCED_TABLE_NAME']); PMA_createTargetTables($src_db, $trg_db, $trg_link, $src_link, $uncommon_tables, $table_index[0], $uncommon_tables_fields, $display); @@ -783,18 +783,18 @@ function PMA_populateTargetTables($src_db, $trg_db, $src_link, $trg_link, function PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $table_index, $target_tables_keys, $delete_array, $display ) { - for ($i = 0; $i < sizeof($delete_array[$table_index]); $i++) { + for ($i = 0; $i < count($delete_array[$table_index]); $i++) { if (isset($target_tables_keys[$table_index])) { $delete_query = 'DELETE FROM ' . PMA_backquote($trg_db) . '.' .PMA_backquote($matching_tables[$table_index]) . ' WHERE '; - for ($y = 0; $y < sizeof($target_tables_keys[$table_index]); $y++) { + for ($y = 0; $y < count($target_tables_keys[$table_index]); $y++) { $delete_query .= PMA_backquote($target_tables_keys[$table_index][$y]) . " = '"; - if (sizeof($target_tables_keys[$table_index]) == 1) { + if (count($target_tables_keys[$table_index]) == 1) { $delete_query .= $delete_array[$table_index][$i] . "'"; - } elseif (sizeof($target_tables_keys[$table_index]) > 1) { + } elseif (count($target_tables_keys[$table_index]) > 1) { $delete_query .= $delete_array[$table_index][$i][$target_tables_keys[$table_index][$y]] . "'"; } - if ($y < (sizeof($target_tables_keys[$table_index]) - 1)) { + if ($y < (count($target_tables_keys[$table_index]) - 1)) { $delete_query .= ' AND '; } $pk_query = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . $trg_db . "' @@ -802,7 +802,7 @@ function PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, . $target_tables_keys[$table_index][$y] . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;"; $pk_query_result = PMA_DBI_fetch_result($pk_query, null, null, $trg_link); - $result_size = sizeof($pk_query_result); + $result_size = count($pk_query_result); if ($result_size > 0) { for ($b = 0; $b < $result_size; $b++) { @@ -890,7 +890,7 @@ function PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, if (isset($target_columns[$matching_table_index][$column_name]['Field'])) { //If column exists in target table then matches criteria like type, // null, collation, key, default, comment of the column - for ($i = 0; $i < sizeof($criteria); $i++) { + for ($i = 0; $i < count($criteria); $i++) { if ($source_columns[$matching_table_index][$column_name][$criteria[$i]] != $target_columns[$matching_table_index][$column_name][$criteria[$i]]) { if (($criteria[$i] == 'Default') && ($source_columns[$matching_table_index][$column_name][$criteria[$i]] == '' )) { $alter_str_array[$matching_table_index][$column_name][$criteria[$i]] = 'None'; @@ -956,7 +956,7 @@ function PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, &$uncommon_tables_fields, $table_counter, $uncommon_cols, $display ) { - for ($i = 0; $i < sizeof($matching_tables_fields[$table_counter]); $i++) { + for ($i = 0; $i < count($matching_tables_fields[$table_counter]); $i++) { if (isset($add_column_array[$table_counter][$matching_tables_fields[$table_counter][$i]])) { $query = "ALTER TABLE " . PMA_backquote($trg_db) . '.' . PMA_backquote($matching_tables[$table_counter]). " ADD COLUMN " . PMA_backquote($add_column_array[$table_counter][$matching_tables_fields[$table_counter][$i]]) . " " . $source_columns[$table_counter][$matching_tables_fields[$table_counter][$i]]['Type']; @@ -976,7 +976,7 @@ function PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, $query .= " COMMENT " . $source_columns[$table_counter][$matching_tables_fields[$table_counter][$i]]['Comment']; } if ($source_columns[$table_counter][$matching_tables_fields[$table_counter][$i]]['Key'] == 'PRI' ) { - $trg_key_size = sizeof($target_tables_keys[$table_counter]); + $trg_key_size = count($target_tables_keys[$table_counter]); if ($trg_key_size) { $check = true; for ($a = 0; ($a < $trg_key_size) && ($check); $a++) { @@ -989,9 +989,9 @@ function PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, } } $query .= " , ADD PRIMARY KEY ("; - for ($t = 0; $t < sizeof($matching_tables_keys[$table_counter]); $t++) { + for ($t = 0; $t < count($matching_tables_keys[$table_counter]); $t++) { $query .= PMA_backquote($matching_tables_keys[$table_counter][$t]); - if ($t < (sizeof($matching_tables_keys[$table_counter]) - 1)) { + if ($t < (count($matching_tables_keys[$table_counter]) - 1)) { $query .= " , " ; } } @@ -1053,8 +1053,8 @@ function PMA_checkForeignKeys($src_db, $src_link, $trg_db, $trg_link, AND TABLE_NAME = '" . $referenced_table . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;"; $is_fk_result = PMA_DBI_fetch_result($is_fk_query, null, null, $src_link); - if (sizeof($is_fk_result) > 0) { - for ($j = 0; $j < sizeof($is_fk_result); $j++) { + if (count($is_fk_result) > 0) { + for ($j = 0; $j < count($is_fk_result); $j++) { if (in_array($is_fk_result[$j]['REFERENCED_TABLE_NAME'], $uncommon_tables)) { $table_index = array_keys($uncommon_tables, $is_fk_result[$j]['REFERENCED_TABLE_NAME']); PMA_checkForeignKeys( @@ -1096,7 +1096,7 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $found = false; //Checks if the criteria to be altered is primary key - for ($v = 0; $v < sizeof($matching_tables_fields[$matching_table_index]); $v++) { + for ($v = 0; $v < count($matching_tables_fields[$matching_table_index]); $v++) { if (isset($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$v]]['Key'])) { if ($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$v]]['Key'] == 'PRI' ) { $check = false; @@ -1107,13 +1107,13 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $pri_query = null; if (! $check) { $pri_query = "ALTER TABLE " . PMA_backquote($trg_db) . '.' . PMA_backquote($matching_tables[$matching_table_index]); - if (sizeof($target_tables_keys[$matching_table_index]) > 0) { + if (count($target_tables_keys[$matching_table_index]) > 0) { $pri_query .= " DROP PRIMARY KEY ," ; } $pri_query .= " ADD PRIMARY KEY ("; - for ($z = 0; $z < sizeof($matching_tables_keys[$matching_table_index]); $z++) { + for ($z = 0; $z < count($matching_tables_keys[$matching_table_index]); $z++) { $pri_query .= PMA_backquote($matching_tables_keys[$matching_table_index][$z]); - if ($z < (sizeof($matching_tables_keys[$matching_table_index]) - 1)) { + if ($z < (count($matching_tables_keys[$matching_table_index]) - 1)) { $pri_query .= " , " ; } } @@ -1126,12 +1126,12 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, } PMA_DBI_try_query($pri_query, $trg_link, 0); } - for ($t = 0; $t < sizeof($matching_tables_fields[$matching_table_index]); $t++) { - if ((isset($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]])) && (sizeof($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]]) > 0)) { + for ($t = 0; $t < count($matching_tables_fields[$matching_table_index]); $t++) { + if ((isset($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]])) && (count($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]]) > 0)) { $sql_query = 'ALTER TABLE ' . PMA_backquote($trg_db) . '.' . PMA_backquote($matching_tables[$matching_table_index]) . ' MODIFY ' . PMA_backquote($matching_tables_fields[$matching_table_index][$t]) . ' ' . $source_columns[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]]['Type']; $found = false; - for ($i = 0; $i < sizeof($criteria); $i++) { + for ($i = 0; $i < count($criteria); $i++) { if (isset($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]][$criteria[$i]]) && $criteria[$i] != 'Key') { $found = true; if (($criteria[$i] == 'Type') && (! isset($alter_str_array[$matching_table_index][$matching_tables_fields[$matching_table_index][$t]][$criteria[$i+1]]))) { @@ -1190,12 +1190,12 @@ function PMA_alterTargetTableStructure($trg_db, $trg_link, $matching_tables, $check = false; $query = "ALTER TABLE " . PMA_backquote($trg_db) . '.' . PMA_backquote($matching_tables[$matching_table_index]); - for ($p = 0; $p < sizeof($matching_tables_keys[$matching_table_index]); $p++) { + for ($p = 0; $p < count($matching_tables_keys[$matching_table_index]); $p++) { if ((isset($alter_str_array[$matching_table_index][$matching_tables_keys[$matching_table_index][$p]]['Key']))) { $check = true; $query .= ' MODIFY ' . PMA_backquote($matching_tables_keys[$matching_table_index][$p]) . ' ' . $source_columns[$matching_table_index][$matching_tables_fields[$matching_table_index][$p]]['Type'] . ' Not Null '; - if ($p < (sizeof($matching_tables_keys[$matching_table_index]) - 1)) { + if ($p < (count($matching_tables_keys[$matching_table_index]) - 1)) { $query .= ', '; } } @@ -1229,14 +1229,14 @@ function PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, if (isset($uncommon_columns[$table_counter])) { $drop_query = "ALTER TABLE " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_tables[$table_counter]); - for ($a = 0; $a < sizeof($uncommon_columns[$table_counter]); $a++) { + for ($a = 0; $a < count($uncommon_columns[$table_counter]); $a++) { //Checks if column to be removed is a foreign key in any table $pk_query = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . $trg_db . "' AND REFERENCED_TABLE_NAME = '" . $matching_tables[$table_counter]."' AND REFERENCED_COLUMN_NAME = '" . $uncommon_columns[$table_counter][$a] . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;"; $pk_query_result = PMA_DBI_fetch_result($pk_query, null, null, $trg_link); - $result_size = sizeof($pk_query_result); + $result_size = count($pk_query_result); if ($result_size > 0) { for ($b = 0; $b < $result_size; $b++) { @@ -1251,11 +1251,11 @@ function PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $result = PMA_DBI_fetch_result($query, null, null, $trg_link); - if (sizeof($result) > 0) { + if (count($result) > 0) { $drop_query .= " DROP FOREIGN KEY " . PMA_backquote($result[0]['CONSTRAINT_NAME']) . ","; } $drop_query .= " DROP COLUMN " . PMA_backquote($uncommon_columns[$table_counter][$a]); - if ($a < (sizeof($uncommon_columns[$table_counter]) - 1)) { + if ($a < (count($uncommon_columns[$table_counter]) - 1)) { $drop_query .= " , " ; } } @@ -1298,14 +1298,14 @@ function PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, //Gets indexes information for source and target table $source_indexes[$table_counter] = PMA_DBI_get_table_indexes($src_db, $matching_tables[$table_counter], $src_link); $target_indexes[$table_counter] = PMA_DBI_get_table_indexes($trg_db, $matching_tables[$table_counter], $trg_link); - for ($a = 0; $a < sizeof($source_indexes[$table_counter]); $a++) { + for ($a = 0; $a < count($source_indexes[$table_counter]); $a++) { $found = false; $z = 0; //Compares key name and non_unique characteristic of source indexes with target indexes /* * @todo compare the length of each sub part */ - while (($z <= sizeof($target_indexes[$table_counter])) && ($found == false)) { + while (($z <= count($target_indexes[$table_counter])) && ($found == false)) { if (isset($source_indexes[$table_counter][$a]) && isset($target_indexes[$table_counter][$z]) && $source_indexes[$table_counter][$a]['Key_name'] == $target_indexes[$table_counter][$z]['Key_name']) { $found = true; if (($source_indexes[$table_counter][$a]['Column_name'] != $target_indexes[$table_counter][$z]['Column_name']) || ($source_indexes[$table_counter][$a]['Non_unique'] != $target_indexes[$table_counter][$z]['Non_unique'])) { @@ -1324,10 +1324,10 @@ function PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, } //Finds indexes that exist on target table but not on source table - for ($b = 0; $b < sizeof($target_indexes[$table_counter]); $b++) { + for ($b = 0; $b < count($target_indexes[$table_counter]); $b++) { $found = false; $c = 0; - while (($c <= sizeof($source_indexes[$table_counter])) && ($found == false)) { + while (($c <= count($source_indexes[$table_counter])) && ($found == false)) { if ($target_indexes[$table_counter][$b]['Column_name'] == $source_indexes[$table_counter][$c]['Column_name']) { $found = true; } @@ -1365,9 +1365,9 @@ function PMA_applyIndexesDiff($trg_db, $trg_link, $matching_tables, $source_inde //Adds indexes on target table if (isset($add_indexes_array[$table_counter])) { $sql = "ALTER TABLE " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_tables[$table_counter]) . " ADD" ; - for ($a = 0; $a < sizeof($source_indexes[$table_counter]); $a++) { + for ($a = 0; $a < count($source_indexes[$table_counter]); $a++) { if (isset($add_indexes_array[$table_counter][$a])) { - for ($b = 0; $b < sizeof($source_indexes[$table_counter]); $b++) { + for ($b = 0; $b < count($source_indexes[$table_counter]); $b++) { if ($source_indexes[$table_counter][$b]['Column_name'] == $add_indexes_array[$table_counter][$a]) { if ($source_indexes[$table_counter][$b]['Non_unique'] == '0') { $sql .= " UNIQUE "; @@ -1386,11 +1386,11 @@ function PMA_applyIndexesDiff($trg_db, $trg_link, $matching_tables, $source_inde if (isset($alter_indexes_array[$table_counter])) { $query = "ALTER TABLE " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_tables[$table_counter]); - for ($a = 0; $a < sizeof($alter_indexes_array[$table_counter]); $a++) { + for ($a = 0; $a < count($alter_indexes_array[$table_counter]); $a++) { if (isset($alter_indexes_array[$table_counter][$a])) { $query .= ' DROP INDEX ' . PMA_backquote($alter_indexes_array[$table_counter][$a]) . " , ADD "; $got_first_index_column = false; - for ($z = 0; $z < sizeof($source_indexes[$table_counter]); $z++) { + for ($z = 0; $z < count($source_indexes[$table_counter]); $z++) { if ($source_indexes[$table_counter][$z]['Key_name'] == $alter_indexes_array[$table_counter][$a]) { if (! $got_first_index_column) { if ($source_indexes[$table_counter][$z]['Non_unique'] == '0') { @@ -1416,11 +1416,11 @@ function PMA_applyIndexesDiff($trg_db, $trg_link, $matching_tables, $source_inde //Removes indexes from target table if (isset($remove_indexes_array[$table_counter])) { $drop_index_query = "ALTER TABLE " . PMA_backquote($trg_db) . "." . PMA_backquote($matching_tables[$table_counter]); - for ($a = 0; $a < sizeof($target_indexes[$table_counter]); $a++) { + for ($a = 0; $a < count($target_indexes[$table_counter]); $a++) { if (isset($remove_indexes_array[$table_counter][$a])) { $drop_index_query .= " DROP INDEX " . PMA_backquote($remove_indexes_array[$table_counter][$a]); } - if ($a < (sizeof($remove_indexes_array[$table_counter]) - 1)) { + if ($a < (count($remove_indexes_array[$table_counter]) - 1)) { $drop_index_query .= " , " ; } } @@ -1543,9 +1543,9 @@ function PMA_syncDisplayDataCompare($rows) function PMA_getColumnValues($database, $table, $column, $link = null) { $query = 'SELECT '; - for ($i=0; $i< sizeof($column); $i++) { + for ($i=0; $i< count($column); $i++) { $query.= PMA_backquote($column[$i]); - if ($i < (sizeof($column)-1)) { + if ($i < (count($column)-1)) { $query.= ', '; } } From d28ac79fc375a133149c009d19c97116b94423c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 29 May 2012 16:47:29 +0200 Subject: [PATCH 5/7] Coding style improvement --- libraries/server_synchronize.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/server_synchronize.lib.php b/libraries/server_synchronize.lib.php index 0507177ead..21d05fabb0 100644 --- a/libraries/server_synchronize.lib.php +++ b/libraries/server_synchronize.lib.php @@ -1543,7 +1543,7 @@ function PMA_syncDisplayDataCompare($rows) function PMA_getColumnValues($database, $table, $column, $link = null) { $query = 'SELECT '; - for ($i=0; $i< count($column); $i++) { + for ($i = 0; $i < count($column); $i++) { $query.= PMA_backquote($column[$i]); if ($i < (count($column)-1)) { $query.= ', '; From 234e432323dbc677e2fd6243db3cf226be5d056e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 29 May 2012 16:48:16 +0200 Subject: [PATCH 6/7] Reformat comments --- libraries/server_synchronize.lib.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/server_synchronize.lib.php b/libraries/server_synchronize.lib.php index 21d05fabb0..b3098ca781 100644 --- a/libraries/server_synchronize.lib.php +++ b/libraries/server_synchronize.lib.php @@ -1004,15 +1004,16 @@ function PMA_addColumnsInTargetTable($src_db, $trg_db, $src_link, $trg_link, } PMA_DBI_try_query($query, $trg_link, 0); - //Checks if column to be added is a foreign key or not + // Checks if column to be added is a foreign key or not $is_fk_query = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = '" . $trg_db . "' AND TABLE_NAME = '" . $matching_tables[$table_counter] . "' AND COLUMN_NAME ='" . $add_column_array[$table_counter][$matching_tables_fields[$table_counter][$i]] . "' AND TABLE_NAME <> REFERENCED_TABLE_NAME;"; $is_fk_result = PMA_DBI_fetch_result($is_fk_query, null, null, $src_link); - //If column is a foreign key then it is checked that referenced table exist in target db. If referenced table does not exist in target db then - //it is created first. + // If column is a foreign key then it is checked that referenced table + // exist in target db. If referenced table does not exist in target + // db then it is created first. if (isset($is_fk_result)) { if (in_array($is_fk_result[0]['REFERENCED_TABLE_NAME'], $uncommon_tables)) { $table_index = array_keys($uncommon_tables, $is_fk_result[0]['REFERENCED_TABLE_NAME']); From 5139585b6cf959eba075d25cc4ca9970790a8dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 29 May 2012 16:51:56 +0200 Subject: [PATCH 7/7] Wrap some function calls --- libraries/server_synchronize.lib.php | 93 +++++++++++++++++++++------- 1 file changed, 72 insertions(+), 21 deletions(-) diff --git a/libraries/server_synchronize.lib.php b/libraries/server_synchronize.lib.php index b3098ca781..c1349ef74c 100644 --- a/libraries/server_synchronize.lib.php +++ b/libraries/server_synchronize.lib.php @@ -176,7 +176,12 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, } } - $target_result_set = PMA_DBI_fetch_result($trg_select_query, null, null, $trg_link); + $target_result_set = PMA_DBI_fetch_result( + $trg_select_query, + null, + null, + $trg_link + ); if ($target_result_set) { // Fetch the row from the source server to do a comparison @@ -198,7 +203,12 @@ function PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, } } - $src_result_set = PMA_DBI_fetch_result($src_select_query, null, null, $src_link); + $src_result_set = PMA_DBI_fetch_result( + $src_select_query, + null, + null, + $src_link + ); /** * Comparing each corresponding field of the source and target @@ -570,29 +580,46 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link, if (isset($alter_str_array[$table_index[0]])) { PMA_alterTargetTableStructure( - $trg_db, $trg_link, $matching_tables, $source_columns, $alter_str_array, $matching_tables_fields, - $criteria, $matching_tables_keys, $target_tables_keys, $table_index[0], $display + $trg_db, $trg_link, $matching_tables, + $source_columns, $alter_str_array, + $matching_tables_fields, + $criteria, $matching_tables_keys, + $target_tables_keys, $table_index[0], + $display ); unset($alter_str_array[$table_index[0]]); } if (isset($uncommon_columns[$table_index[0]])) { - PMA_removeColumnsFromTargetTable($trg_db, $trg_link, $matching_tables, $uncommon_columns, $table_index[0], $display); + PMA_removeColumnsFromTargetTable( + $trg_db, $trg_link, $matching_tables, + $uncommon_columns, $table_index[0], $display + ); unset($uncommon_columns[$table_index[0]]); } if (isset($add_column_array[$table_index[0]])) { PMA_findDeleteRowsFromTargetTables( - $delete_array, $matching_tables, $table_index[0], $target_tables_keys, - $matching_tables_keys, $trg_db, $trg_link, $src_db, $src_link + $delete_array, $matching_tables, + $table_index[0], $target_tables_keys, + $matching_tables_keys, $trg_db, + $trg_link, $src_db, $src_link ); if (isset($delete_array[$table_index[0]])) { - PMA_deleteFromTargetTable($trg_db, $trg_link, $matching_tables, $table_index[0], $target_tables_keys, $delete_array, $display); + PMA_deleteFromTargetTable( + $trg_db, $trg_link, $matching_tables, + $table_index[0], $target_tables_keys, + $delete_array, $display + ); unset($delete_array[$table_index[0]]); } PMA_addColumnsInTargetTable( - $src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns, $add_column_array, - $matching_tables_fields, $criteria, $matching_tables_keys, $target_tables_keys, $uncommon_tables, - $uncommon_tables_fields, $table_index[0], $uncommon_cols, $display + $src_db, $trg_db, $src_link, $trg_link, + $matching_tables, $source_columns, + $add_column_array, $matching_tables_fields, + $criteria, $matching_tables_keys, + $target_tables_keys, $uncommon_tables, + $uncommon_tables_fields, $table_index[0], + $uncommon_cols, $display ); unset($add_column_array[$table_index[0]]); } @@ -601,8 +628,11 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link, || isset($alter_indexes_array[$table_index[0]]) ) { PMA_applyIndexesDiff( - $trg_db, $trg_link, $matching_tables, $source_indexes, $target_indexes, $add_indexes_array, - $alter_indexes_array, $remove_indexes_array, $table_index[0], $display + $trg_db, $trg_link, $matching_tables, + $source_indexes, $target_indexes, + $add_indexes_array, $alter_indexes_array, + $remove_indexes_array, $table_index[0], + $display ); unset($add_indexes_array[$table_index[0]]); @@ -611,17 +641,26 @@ function PMA_insertIntoTargetTable($matching_table, $src_db, $trg_db, $src_link, } if (isset($update_array[$table_index[0]])) { PMA_updateTargetTables( - $matching_tables, $update_array, $src_db, $trg_db, $trg_link, - $table_index[0], $matching_table_keys, $display + $matching_tables, $update_array, + $src_db, $trg_db, $trg_link, + $table_index[0], $matching_table_keys, + $display ); unset($update_array[$table_index[0]]); } if (isset($array_insert[$table_index[0]])) { PMA_insertIntoTargetTable( - $matching_table, $src_db, $trg_db, $src_link, $trg_link, $table_fields, $array_insert, $table_index[0], - $matching_tables_keys, $source_columns, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables, - $uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $target_indexes, $add_indexes_array, - $alter_indexes_array, $delete_array, $update_array, $display + $matching_table, $src_db, $trg_db, + $src_link, $trg_link, $table_fields, + $array_insert, $table_index[0], + $matching_tables_keys, $source_columns, + $add_column_array, $criteria, + $target_tables_keys, $uncommon_tables, + $uncommon_tables_fields, $uncommon_cols, + $alter_str_array, $source_indexes, + $target_indexes, $add_indexes_array, + $alter_indexes_array, $delete_array, + $update_array, $display ); unset($array_insert[$table_index[0]]); } @@ -677,7 +716,13 @@ function PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, &$uncommon_tables, $table_index, &$uncommon_tables_fields, $display ) { if (isset($uncommon_tables[$table_index])) { - $fields_result = PMA_DBI_get_columns($src_db, $uncommon_tables[$table_index], null, true, $src_link); + $fields_result = PMA_DBI_get_columns( + $src_db, + $uncommon_tables[$table_index], + null, + true, + $src_link + ); $fields = array(); foreach ($fields_result as $each_field) { $field_name = $each_field['Field']; @@ -685,7 +730,13 @@ function PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, } $uncommon_tables_fields[$table_index] = $fields; - $Create_Query = PMA_DBI_fetch_value("SHOW CREATE TABLE " . PMA_backquote($src_db) . '.' . PMA_backquote($uncommon_tables[$table_index]), 0, 1, $src_link); + $Create_Query = PMA_DBI_fetch_value( + "SHOW CREATE TABLE " . PMA_backquote($src_db) . '.' + . PMA_backquote($uncommon_tables[$table_index]), + 0, + 1, + $src_link + ); // Replace the src table name with a `dbname`.`tablename` $Create_Table_Query = preg_replace(
' . __('Source database') . ': ' . htmlspecialchars($src_db) . '
('; + echo '
' . __('Source database') . ': ' + . htmlspecialchars($src_db) . '
('; if ('cur' == $_SESSION['src_type']) { echo __('Current server'); } else { - echo __('Remote server') . ' ' . htmlspecialchars($_SESSION['src_server']['host']); + echo __('Remote server') . ' ' + . htmlspecialchars($_SESSION['src_server']['host']); } echo ')
' . __('Difference') . '' . __('Target database') . ': '. htmlspecialchars($trg_db) . '
('; + echo '
' . __('Target database') . ': ' + . htmlspecialchars($trg_db) . '
('; if ('cur' == $_SESSION['trg_type']) { echo __('Current server'); } else { - echo __('Remote server') . ' ' . htmlspecialchars($_SESSION['trg_server']['host']); + echo __('Remote server') . ' ' + . htmlspecialchars($_SESSION['trg_server']['host']); } echo ')