Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
weblate committed Apr 27, 2012
2 parents 34bd74e + 784ab67 commit fad15b0
Showing 1 changed file with 151 additions and 56 deletions.
207 changes: 151 additions & 56 deletions server_synchronize.php
Expand Up @@ -115,14 +115,27 @@
if (${"{$con}_connection"} != null) { if (${"{$con}_connection"} != null) {
${"{$con}_link"} = PMA_DBI_connect( ${"{$con}_link"} = PMA_DBI_connect(
${"{$con}_username"}, ${"{$con}_username"},
${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"} ${"{$con}_password"},
$is_controluser = false,
${"{$con}_server"}
); );
} else { } else {
${"{$con}_link"} = null; ${"{$con}_link"} = null;
} }
${"{$con}_db_selected"} = PMA_DBI_select_db(${"{$con}_db"}, ${"{$con}_link"}); ${"{$con}_db_selected"} = PMA_DBI_select_db(
${"{$con}_version"} = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, ${"{$con}_link"}); ${"{$con}_db"},
${"{$con}_is_drizzle"} = (bool)preg_match('/\d{4}\./', ${"{$con}_version"}); ${"{$con}_link"}
);
${"{$con}_version"} = PMA_DBI_fetch_value(
'SELECT VERSION()',
0,
0,
${"{$con}_link"}
);
${"{$con}_is_drizzle"} = (bool)preg_match(
'/\d{4}\./',
${"{$con}_version"}
);
} // end foreach ($cons as $con) } // end foreach ($cons as $con)


if (($src_db_selected != 1) || ($trg_db_selected != 1)) { if (($src_db_selected != 1) || ($trg_db_selected != 1)) {
Expand All @@ -131,10 +144,16 @@
*/ */
echo '<div class="error">'; echo '<div class="error">';
if ($src_db_selected != 1) { if ($src_db_selected != 1) {
echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($src_db)); echo sprintf(
__('\'%s\' database does not exist.'),
htmlspecialchars($src_db)
);
} }
if ($trg_db_selected != 1) { if ($trg_db_selected != 1) {
echo sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($trg_db)); echo sprintf(
__('\'%s\' database does not exist.'),
htmlspecialchars($trg_db)
);
} }
echo '</div>'; echo '</div>';
unset($_REQUEST['submit_connect']); unset($_REQUEST['submit_connect']);
Expand Down Expand Up @@ -166,43 +185,91 @@
* Using PMA_getMatchingTables to find which of the tables' names match * Using PMA_getMatchingTables to find which of the tables' names match
* in target and source database. * in target and source database.
*/ */
PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon); PMA_getMatchingTables(
$trg_tables,
$src_tables,
$matching_tables,
$source_tables_uncommon
);
/** /**
* Finding the uncommon tables for the target database * Finding the uncommon tables for the target database
* using function PMA_getNonMatchingTargetTables() * using function PMA_getNonMatchingTargetTables()
*/ */
PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon); PMA_getNonMatchingTargetTables(
$trg_tables,
$matching_tables,
$target_tables_uncommon
);


/** /**
* Initializing several arrays to save the data and structure * Initializing several arrays to save the data and structure
* difference between the source and target databases. * difference between the source and target databases.
*/ */
$row_count = array(); //number of rows in source table that needs to be created in target database // number of rows in source table that needs to be created in target
$fields_num = array(); //number of fields in each matching table // database
$delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables. $row_count = array();
$insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables. // number of fields in each matching table
$update_array = array(array(array())); //stores the primary key values, name of field to be updated, value of the field to be updated for $fields_num = array();
// each row of matching table. // stores the primary key values for target tables that have
$matching_tables_fields = array(); //contains the fields' names for each matching table // excessive rows than corresponding source tables.
$matching_tables_keys = array(); //contains the primary keys' names for each matching table $delete_array = array();
$uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target // stores the primary key values for the rows in each source table
// that are not present in target tables.
$insert_array = array(array(array()));
// stores the primary key values, name of field to be updated,
// value of the field to be updated for each row of matching table.
$update_array = array(array(array()));

// contains the fields' names for each matching table
$matching_tables_fields = array();
// contains the primary keys' names for each matching table
$matching_tables_keys = array();
// coantains the fields for all the source tables that are not
// present in target
$uncommon_tables_fields = array();
$matching_tables_num = sizeof($matching_tables); $matching_tables_num = sizeof($matching_tables);


$source_columns = array(); //contains the full columns' information for all the source tables' columns // contains the full columns' information for all the source
$target_columns = array(); //contains the full columns' information for all the target tables' columns // tables' columns
$uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table $source_columns = array();
$source_indexes = array(); //contains indexes on all the source tables // contains the full columns' information for all the target
$target_indexes = array(); //contains indexes on all the target tables // tables' columns
$add_indexes_array = array(); //contains the indexes name present in source but absent from target tables $target_columns = array();
$target_tables_keys = array(); //contains the keys of all the target tables // contains names of columns present in source table but absent from
$alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database // the corresponding target table
$remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables $uncommon_columns = array();
$alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables // contains indexes on all the source tables
$add_column_array = array(array()); //contains the name of columns that need to be added in target tables $source_indexes = array();
// contains indexes on all the target tables
$target_indexes = array();
// contains the indexes name present in source but absent from
// target tables
$add_indexes_array = array();
// contains the keys of all the target tables
$target_tables_keys = array();
// contains the names of all the indexes for each table that need
// to be altered in target database
$alter_indexes_array = array();
// contains the names of indexes that are excessive in target tables
$remove_indexes_array = array();
// contains the criteria for each column that needs to be altered
// in target tables
$alter_str_array = array(array());
// contains the name of columns that need to be added in target tables
$add_column_array = array(array());
/** /**
* The criteria array contains all the criteria against which columns are compared for differences. * The criteria array contains all the criteria against which columns
*/ * are compared for differences.
$criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment'); */
$criteria = array(
'Field',
'Type',
'Null',
'Collation',
'Key',
'Default',
'Comment'
);


for ($i = 0; $i < sizeof($matching_tables); $i++) { for ($i = 0; $i < sizeof($matching_tables); $i++) {
/** /**
Expand All @@ -226,7 +293,8 @@
PMA_indexesDiffInTables( PMA_indexesDiffInTables(
$src_db, $trg_db, $src_link, $trg_link, $src_db, $trg_db, $src_link, $trg_link,
$matching_tables, $source_indexes, $target_indexes, $matching_tables, $source_indexes, $target_indexes,
$add_indexes_array, $alter_indexes_array, $remove_indexes_array, $i $add_indexes_array, $alter_indexes_array,
$remove_indexes_array, $i
); );
} }


Expand Down Expand Up @@ -378,8 +446,14 @@
|| ($num_add_index > 0) || ($num_add_index > 0)
|| ($num_remove_index > 0) || ($num_remove_index > 0)
) { ) {
$btn_structure_params = array($i, $num_alter_cols, $num_insert_cols, $btn_structure_params = array(
$num_remove_cols, $num_add_index, $num_remove_index); $i,
$num_alter_cols,
$num_insert_cols,
$num_remove_cols,
$num_add_index,
$num_remove_index
);
} }


/** /**
Expand Down Expand Up @@ -467,8 +541,9 @@
</table> </table>
</div></fieldset>'; </div></fieldset>';
/** /**
* This fieldset displays the checkbox to confirm deletion of previous rows from target tables * This fieldset displays the checkbox to confirm deletion of previous
*/ * rows from target tables
*/
echo '<fieldset> echo '<fieldset>
<p><input type= "checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">' <p><input type= "checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">'
. __('Would you like to delete all the previous rows from target tables?') . __('Would you like to delete all the previous rows from target tables?')
Expand Down Expand Up @@ -551,12 +626,17 @@
} // end foreach ($cons as $con) } // end foreach ($cons as $con)


/** /**
* Initializing arrays to save the table ids whose data and structure difference is to be applied * Initializing arrays to save the table ids whose data and structure
*/ * difference is to be applied
$matching_table_data_diff = array(); //stores id of matching table having data difference */
$matching_table_structure_diff = array(); //stores id of matching tables having structure difference // stores id of matching table having data difference
$uncommon_table_structure_diff = array(); //stores id of uncommon tables having structure difference $matching_table_data_diff = array();
$uncommon_table_data_diff = array(); //stores id of uncommon tables having data difference // stores id of matching tables having structure difference
$matching_table_structure_diff = array();
// stores id of uncommon tables having structure difference
$uncommon_table_structure_diff = array();
// stores id of uncommon tables having data difference
$uncommon_table_data_diff = array();


for ($i = 0; isset($_REQUEST[$i]); $i++ ) { for ($i = 0; isset($_REQUEST[$i]); $i++ ) {
if (isset($_REQUEST[$i])) { if (isset($_REQUEST[$i])) {
Expand Down Expand Up @@ -644,9 +724,10 @@
} }
} }
/** /**
* Applying the data difference. First checks if structure diff is applied or not. * Applying the data difference. First checks if structure diff is applied
* If not, then apply structure difference first then apply data difference. * or not. If not, then apply structure difference first then apply data
*/ * difference.
*/
for ($p = 0; $p < sizeof($matching_table_data_diff); $p++) { for ($p = 0; $p < sizeof($matching_table_data_diff); $p++) {
if ($_REQUEST['checked'] == 'true') { if ($_REQUEST['checked'] == 'true') {
PMA_findDeleteRowsFromTargetTables( PMA_findDeleteRowsFromTargetTables(
Expand Down Expand Up @@ -798,9 +879,10 @@
unset($row_count[$uncommon_table_data_diff[$r]]); unset($row_count[$uncommon_table_data_diff[$r]]);
} }
/** /**
* Again all the tables from source and target database are displayed with their differences. * Again all the tables from source and target database are displayed with
* The differences have been removed from tables that have been synchronized * their differences. The differences have been removed from tables that
*/ * have been synchronized
*/
echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">' echo '<form name="applied_difference" id="synchronize_form" method="post" action="server_synchronize.php">'
. PMA_generate_common_hidden_inputs('', ''); . PMA_generate_common_hidden_inputs('', '');


Expand Down Expand Up @@ -980,8 +1062,9 @@
</div></fieldset>'; </div></fieldset>';


/** /**
* This fieldset displays the checkbox to confirm deletion of previous rows from target tables * This fieldset displays the checkbox to confirm deletion of previous
*/ * rows from target tables
*/
echo '<fieldset> echo '<fieldset>
<p><input type="checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">' <p><input type="checkbox" name="delete_rows" id ="delete_rows" /><label for="delete_rows">'
. __('Would you like to delete all the previous rows from target tables?') . '</label> </p> . __('Would you like to delete all the previous rows from target tables?') . '</label> </p>
Expand Down Expand Up @@ -1071,7 +1154,12 @@
* connecting the source and target servers * connecting the source and target servers
*/ */
if ('cur' != $_SESSION['src_type']) { if ('cur' != $_SESSION['src_type']) {
$src_link = PMA_DBI_connect($src_username, $src_password, $is_controluser = false, $_SESSION['src_server']); $src_link = PMA_DBI_connect(
$src_username,
$src_password,
$is_controluser = false,
$_SESSION['src_server']
);
$src_version = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, $src_link); $src_version = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, $src_link);
$src_is_drizzle = (bool)preg_match('/\d{4}\./', $src_version); $src_is_drizzle = (bool)preg_match('/\d{4}\./', $src_version);
} else { } else {
Expand All @@ -1083,7 +1171,12 @@
$GLOBALS['db'] = $_SESSION['src_db']; $GLOBALS['db'] = $_SESSION['src_db'];
} }
if ('cur' != $_SESSION['trg_type']) { if ('cur' != $_SESSION['trg_type']) {
$trg_link = PMA_DBI_connect($trg_username, $trg_password, $is_controluser = false, $_SESSION['trg_server']); $trg_link = PMA_DBI_connect(
$trg_username,
$trg_password,
$is_controluser = false,
$_SESSION['trg_server']
);
$trg_version = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, $trg_link); $trg_version = PMA_DBI_fetch_value('SELECT VERSION()', 0, 0, $trg_link);
$trg_is_drizzle = (bool)preg_match('/\d{4}\./', $trg_version); $trg_is_drizzle = (bool)preg_match('/\d{4}\./', $trg_version);
} else { } else {
Expand All @@ -1103,9 +1196,10 @@
*/ */
for ($p = 0; $p < sizeof($matching_tables); $p++) { for ($p = 0; $p < sizeof($matching_tables); $p++) {
/** /**
* If the check box is checked for deleting previous rows from the target database tables then * If the check box is checked for deleting previous rows from the
* first find out rows to be deleted and then delete the rows. * target database tables then first find out rows to be deleted
*/ * and then delete the rows.
*/
if (isset($_REQUEST['delete_rows'])) { if (isset($_REQUEST['delete_rows'])) {
PMA_findDeleteRowsFromTargetTables( PMA_findDeleteRowsFromTargetTables(
$delete_array, $matching_tables, $p, $delete_array, $matching_tables, $p,
Expand Down Expand Up @@ -1186,7 +1280,8 @@
$trg_link, $matching_tables_fields, $insert_array, $p, $trg_link, $matching_tables_fields, $insert_array, $p,
$matching_tables_keys, $matching_tables_keys, $source_columns, $matching_tables_keys, $matching_tables_keys, $source_columns,
$add_column_array, $criteria, $target_tables_keys, $uncommon_tables, $add_column_array, $criteria, $target_tables_keys, $uncommon_tables,
$uncommon_tables_fields, $uncommon_cols, $alter_str_array, $source_indexes, $uncommon_tables_fields, $uncommon_cols, $alter_str_array,
$source_indexes,
$target_indexes, $add_indexes_array, $target_indexes, $add_indexes_array,
$alter_indexes_array, $delete_array, $update_array, true $alter_indexes_array, $delete_array, $update_array, true
); );
Expand Down

0 comments on commit fad15b0

Please sign in to comment.