php synchronize,server_synchronize.php

/* vim: set expandtab sw=4 ts=4 sts=4: */

/**

*

* @version $Id$

* @package phpMyAdmin

*/

/**

*

*/

require_once './libraries/common.inc.php';

/**

* Does the common work

*/

$GLOBALS['js_include'][] = 'functions.js';

$GLOBALS['js_include'][] = 'mootools.js';

require_once './libraries/server_common.inc.php';

/**

* Contains all the functions specific to synchronization

*/

require './libraries/server_synchronize.lib.php';

/**

* Increases the time limit up to the configured maximum

*/

@set_time_limit($cfg['ExecTimeLimit']);

/**

* Displays the links

*/

require './libraries/server_links.inc.php';

/**

* Enables warnings on the page

*/

//$cfg['Error_Handler']['display'] = true;

//$cfg['Error_Handler']['gather'] = true;

/**

* Save the value of token generated for this page

*/

if (isset($_REQUEST['token'])) {

$_SESSION['token'] = $_REQUEST['token'];

}

// variable for code saving

$cons = array ("src", "trg");

/**

* Displays the page when 'Go' is pressed

*/

if ((isset($_REQUEST['submit_connect']))) {

foreach ($cons as $con) {

${"{$con}_host"} = $_REQUEST[$con . '_host'];

${"{$con}_username"} = $_REQUEST[$con . '_username'];

${"{$con}_password"} = $_REQUEST[$con . '_pass'];

${"{$con}_port"} = $_REQUEST[$con . '_port'];

${"{$con}_socket"} = $_REQUEST[$con . '_socket'];

${"{$con}_db"} = $_REQUEST[$con . '_db'];

${"{$con}_type"} = $_REQUEST[$con . '_type'];

if (${"{$con}_type"} == 'cur') {

${"{$con}_connection"} = null;

${"{$con}_server"} = null;

${"{$con}_db"} = $_REQUEST[$con . '_db_sel'];

continue;

}

if (isset(${"{$con}_socket"}) && ! empty(${"{$con}_socket"})) {

${"{$con}_server"}['socket'] = ${"{$con}_socket"};

} else {

${"{$con}_server"}['host'] = ${"{$con}_host"};

if (isset(${"{$con}_port"}) && ! empty(${"{$con}_port"}) && ((int)${"{$con}_port"} * 1) > 0) {

${"{$con}_server"}['port'] = ${"{$con}_port"};

}

}

${"{$con}_connection"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"}, $auxiliary_connection = true);

} // end foreach ($cons as $con)

if ((! $src_connection && $src_type == 'rmt') || (! $trg_connection && $trg_type == 'rmt')) {

/**

* Displays the connection error string if

* connections are not established

*/

echo '

';

if(! $src_connection && $src_type == 'rmt') {

echo $GLOBALS['strCouldNotConnectSource'] . '
';

}

if(! $trg_connection && $trg_type == 'rmt'){

echo $GLOBALS['strCouldNotConnectTarget'];

}

echo '

';

unset($_REQUEST['submit_connect']);

} else {

/**

* Creating the link object for both source and target databases and

* selecting the source and target databases using these links

*/

foreach ($cons as $con) {

if (${"{$con}_connection"} != null) {

${"{$con}_link"} = PMA_DBI_connect(${"{$con}_username"}, ${"{$con}_password"}, $is_controluser = false, ${"{$con}_server"});

} else {

${"{$con}_link"} = null;

}

${"{$con}_db_selected"} = PMA_DBI_select_db(${"{$con}_db"}, ${"{$con}_link"});

} // end foreach ($cons as $con)

if (($src_db_selected != 1) || ($trg_db_selected != 1)) {

/**

* Displays error string if the database(s) did not exist

*/

echo '

';

if ($src_db_selected != 1) {

echo sprintf($GLOBALS['strDatabaseNotExisting'], htmlspecialchars($src_db));

}

if ($trg_db_selected != 1) {

echo sprintf($GLOBALS['strDatabaseNotExisting'], htmlspecialchars($trg_db));

}

echo '

';

unset($_REQUEST['submit_connect']);

} else if (($src_db_selected == 1) && ($trg_db_selected == 1)) {

/**

* Using PMA_DBI_get_tables() to get all the tables

* from target and source databases.

*/

$src_tables = PMA_DBI_get_tables($src_db, $src_link);

$source_tables_num = sizeof($src_tables);

$trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);

$target_tables_num = sizeof($trg_tables);

/**

* initializing arrays to save matching and non-matching

* table names from target and source databases.

*/

$unmatched_num_src = 0;

$source_tables_uncommon = array();

$unmatched_num_trg = 0;

$target_tables_uncommon = array();

$matching_tables = array();

$matching_tables_num = 0;

/**

* Using PMA_getMatchingTables to find which of the tables' names match

* in target and source database.

*/

PMA_getMatchingTables($trg_tables, $src_tables, $matching_tables, $source_tables_uncommon);

/**

* Finding the uncommon tables for the target database

* using function PMA_getNonMatchingTargetTables()

*/

PMA_getNonMatchingTargetTables($trg_tables, $matching_tables, $target_tables_uncommon);

/**

* Initializing several arrays to save the data and structure

* difference between the source and target databases.

*/

$row_count = array(); //number of rows in source table that needs to be created in target database

$fields_num = array(); //number of fields in each matching table

$delete_array = array(); //stores the primary key values for target tables that have excessive rows than corresponding source tables.

$insert_array = array(array(array()));// stores the primary key values for the rows in each source table that are not present in target tables.

$update_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.

$matching_tables_fields = array(); //contains the fields' names for each matching table

$matching_tables_keys = array(); //contains the primary keys' names for each matching table

$uncommon_tables_fields = array(); //coantains the fields for all the source tables that are not present in target

$matching_tables_num = sizeof($matching_tables);

$source_columns = array(); //contains the full columns' information for all the source tables' columns

$target_columns = array(); //contains the full columns' information for all the target tables' columns

$uncommon_columns = array(); //contains names of columns present in source table but absent from the corresponding target table

$source_indexes = array(); //contains indexes on all the source tables

$target_indexes = array(); //contains indexes on all the target tables

$add_indexes_array = array(); //contains the indexes name present in source but absent from target tables

$target_tables_keys = array(); //contains the keys of all the target tables

$alter_indexes_array = array(); //contains the names of all the indexes for each table that need to be altered in target database

$remove_indexes_array = array(); //contains the names of indexes that are excessive in target tables

$alter_str_array = array(array()); //contains the criteria for each column that needs to be altered in target tables

$add_column_array = array(array()); //contains the name of columns that need to be added in target tables

/**

* The criteria array contains all the criteria against which columns are compared for differences.

*/

$criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment');

for($i = 0; $i < sizeof($matching_tables); $i++) {

/**

* Finding out all the differences structure, data and index diff for all the matching tables only

*/

PMA_dataDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $matching_tables_fields, $update_array, $insert_array,

$delete_array, $fields_num, $i, $matching_tables_keys);

PMA_structureDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_columns,

$target_columns, $alter_str_array, $add_column_array, $uncommon_columns, $criteria, $target_tables_keys, $i);

PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes,

$add_indexes_array, $alter_indexes_array, $remove_indexes_array, $i);

}

for($j = 0; $j < sizeof($source_tables_uncommon); $j++) {

/**

* Finding out the number of rows to be added in tables that need to be added in target database

*/

PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $j, $row_count);

}

/**

* Storing all arrays in session for use when page is reloaded for each button press

*/

$_SESSION['matching_tables'] = $matching_tables;

$_SESSION['update_array'] = $update_array;

$_SESSION['insert_array'] = $insert_array;

$_SESSION['src_db'] = $src_db;

$_SESSION['trg_db'] = $trg_db;

$_SESSION['matching_fields'] = $matching_tables_fields;

$_SESSION['src_uncommon_tables'] = $source_tables_uncommon;

$_SESSION['src_username'] = $src_username ;

$_SESSION['trg_username'] = $trg_username;

$_SESSION['src_password'] = $src_password;

$_SESSION['trg_password'] = $trg_password;

$_SESSION['trg_password'] = $trg_password;

$_SESSION['src_server'] = $src_server;

$_SESSION['trg_server'] = $trg_server;

$_SESSION['src_type'] = $src_type;

$_SESSION['trg_type'] = $trg_type;

$_SESSION['matching_tables_keys'] = $matching_tables_keys;

$_SESSION['uncommon_tables_fields'] = $uncommon_tables_fields;

$_SESSION['uncommon_tables_row_count'] = $row_count;

$_SESSION['target_tables_uncommon'] = $target_tables_uncommon;

$_SESSION['uncommon_tables'] = $source_tables_uncommon;

$_SESSION['delete_array'] = $delete_array;

$_SESSION['uncommon_columns'] = $uncommon_columns;

$_SESSION['source_columns'] = $source_columns;

$_SESSION['alter_str_array'] = $alter_str_array;

$_SESSION['target_tables_keys'] = $target_tables_keys;

$_SESSION['add_column_array'] = $add_column_array;

$_SESSION['criteria'] = $criteria;

$_SESSION['target_tables'] = $trg_tables;

$_SESSION['add_indexes_array'] = $add_indexes_array;

$_SESSION['alter_indexes_array'] = $alter_indexes_array;

$_SESSION['remove_indexes_array'] = $remove_indexes_array;

$_SESSION['source_indexes'] = $source_indexes;

$_SESSION['target_indexes'] = $target_indexes;

/**

* Displays the sub-heading and icons showing Structure Synchronization and Data Synchronization

*/

echo '

'

. PMA_generate_common_hidden_inputs('', '');

echo '

'

. ($GLOBALS['cfg']['MainPageIconic']

? ''%20.%20%24pmaThemeImage%20.%20'new_struct.jpg

. ' height="32" alt="" />'

: '')

. $strStructureSyn

.'' .'

echo '

'

. ($GLOBALS['cfg']['MainPageIconic']

? ''%20.%20%24pmaThemeImage%20.%20'new_data.jpg

. ' height="32" alt="" />'

: '')

. $strDataSyn

. '' .'

';

echo '

';

/**

* Displays the tables containing the source tables names, their difference with the target tables and target tables names

*/

PMA_syncDisplayHeaderSource($src_db);

$odd_row = false;

/**

* Display the matching tables' names and difference, first

*/

for($i = 0; $i < count($matching_tables); $i++) {

$num_of_updates = 0;

$num_of_insertions = 0;

/**

* Calculating the number of updates for each matching table

*/

if (isset($update_array[$i])) {

if (isset($update_array[$i][0][$matching_tables_keys[$i][0]])) {

if (isset($update_array[$i])) {

$num_of_updates = sizeof($update_array[$i]);

} else {

$num_of_updates = 0;

}

} else {

$num_of_updates = 0;

}

}

/**

* Calculating the number of insertions for each matching table

*/

if (isset($insert_array[$i])) {

if (isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {

if (isset($insert_array[$i])) {

$num_of_insertions = sizeof($insert_array[$i]);

} else {

$num_of_insertions = 0;

}

} else {

$num_of_insertions = 0;

}

}

/**

* Displays the name of the matching table

*/

$odd_row = PMA_syncDisplayBeginTableRow($odd_row);

echo '

' . htmlspecialchars($matching_tables[$i]) . '';

/**

* Calculating the number of alter columns, number of columns to be added, number of columns to be removed,

* number of index to be added and removed.

*/

$num_alter_cols = 0;

$num_insert_cols = 0;

$num_remove_cols = 0;

$num_add_index = 0;

$num_remove_index = 0;

if (isset($alter_str_array[$i])) {

$num_alter_cols = sizeof($alter_str_array[$i]);

}

if (isset($add_column_array[$i])) {

$num_insert_cols = sizeof($add_column_array[$i]);

}

if (isset($uncommon_columns[$i])) {

$num_remove_cols = sizeof($uncommon_columns[$i]);

}

if (isset($add_indexes_array[$i])) {

$num_add_index = sizeof($add_indexes_array[$i]);

}

if (isset($remove_indexes_array[$i])) {

$num_remove_index = sizeof($remove_indexes_array[$i]);

}

if (isset($alter_indexes_array[$i])) {

$num_add_index += sizeof($alter_indexes_array[$i]);

$num_remove_index += sizeof($alter_indexes_array[$i]);

}

/**

* Display the red button of structure synchronization if there exists any structure difference or index difference.

*/

if (($num_alter_cols > 0) || ($num_insert_cols > 0) || ($num_remove_cols > 0) || ($num_add_index > 0) || ($num_remove_index > 0)) {

echo ''%20.%20%24pmaThemeImage%20.%20'new_struct.jpg

alt="' . $GLOBALS['strClickToSelect'] . '" οnmοuseοver="change_Image(this);" οnmοuseοut="change_Image(this);"

οnclick="showDetails(' . "'MS" . $i . "','" . $num_alter_cols . "','" .$num_insert_cols .

"','" . $num_remove_cols . "','" . $num_add_index . "','" . $num_remove_index . "'"

. ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')"/>';

}

/**

* Display the green button of data synchronization if there exists any data difference.

*/

if (isset($update_array[$i]) || isset($insert_array[$i])) {

if (isset($update_array[$i][0][$matching_tables_keys[$i][0]]) || isset($insert_array[$i][0][$matching_tables_keys[$i][0]])) {

echo ''%20.%20%24pmaThemeImage%20.%20'new_data.jpg

alt="' . $GLOBALS['strClickToSelect'] . '" οnmοuseοver="change_Image(this);" οnmοuseοut="change_Image(this);"

οnclick="showDetails('. "'MD" . $i . "','" . $num_of_updates . "','" . $num_of_insertions .

"','" . null . "','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($matching_tables[$i]) . "'" . ')" />';

}

}

echo '

';

}

/**

* Displays the tables' names present in source but missing from target

*/

for ($j = 0; $j < count($source_tables_uncommon); $j++) {

$odd_row = PMA_syncDisplayBeginTableRow($odd_row);

echo '

+ ' . htmlspecialchars($source_tables_uncommon[$j]) . ' ';

echo '

'%20.%20%24pmaThemeImage%20.%20%20'new_struct.jpg

alt="' . $GLOBALS['strClickToSelect'] . '" οnmοuseοver="change_Image(this);" οnmοuseοut="change_Image(this);"

οnclick="showDetails(' . "'US" . $j . "','" . null . "','" . null . "','" . null . "','" . null . "','" . null . "'" . ', this ,'

. "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')"/>';

if ($row_count[$j] > 0)

{

echo ''%20.%20%24pmaThemeImage%20.%20'new_data.jpg

alt="' . $GLOBALS['strClickToSelect'] . '" οnmοuseοver="change_Image(this);" οnmοuseοut="change_Image(this);"

οnclick="showDetails(' . "'UD" . $j . "','" . null . "','" . $row_count[$j] . "','" . null .

"','" . null . "','" . null . "'" . ', this ,' . "'" . htmlspecialchars($source_tables_uncommon[$j]) . "'" . ')" />';

}

echo '

';

}

foreach ($target_tables_uncommon as $tbl_nc_name) {

$odd_row = PMA_syncDisplayBeginTableRow($odd_row);

echo '

      ';

echo '';

}

/**

* Displays the target tables names

*/

echo '';

$odd_row = PMA_syncDisplayHeaderTargetAndMatchingTables($trg_db, $matching_tables);

foreach ($source_tables_uncommon as $tbl_nc_name) {

$odd_row = PMA_syncDisplayBeginTableRow($odd_row);

echo '

' . htmlspecialchars($tbl_nc_name) . ' (' . $GLOBALS['strNotPresent'] . ')

';

}

foreach ($target_tables_uncommon as $tbl_nc_name) {

$odd_row = PMA_syncDisplayBeginTableRow($odd_row);

echo '

- ' . htmlspecialchars($tbl_nc_name) . '';

echo '';

}

echo '';

echo '

';
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值