From df8a359cffaba9ca2f86fff7509e1f4d1ed5a212 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Thu, 24 Dec 2009 12:33:04 +0000 Subject: [PATCH] code cleanup --- libraries/replication.inc.php | 86 ++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 51 deletions(-) diff --git a/libraries/replication.inc.php b/libraries/replication.inc.php index 1215e9e3b9..05044285d5 100644 --- a/libraries/replication.inc.php +++ b/libraries/replication.inc.php @@ -94,24 +94,24 @@ $serverid = time(); // check which replication is available and set $server_{master/slave}_status and assign values foreach ($replication_types as $type) { - if (count(${"server_{$type}_replication"}) > 0) + if (count(${"server_{$type}_replication"}) > 0) { ${"server_{$type}_status"} = true; - else + } else { ${"server_{$type}_status"} = false; - + } if (${"server_{$type}_status"}) { if ($type == "master") { - ${"server_{$type}_Do_DB"} = explode (",", $server_master_replication[0]["Binlog_Do_DB"]); - ${"server_{$type}_Ignore_DB"} = explode (",", $server_master_replication[0]["Binlog_Ignore_DB"]); + ${"server_{$type}_Do_DB"} = explode(",", $server_master_replication[0]["Binlog_Do_DB"]); + ${"server_{$type}_Ignore_DB"} = explode(",", $server_master_replication[0]["Binlog_Ignore_DB"]); } elseif ($type == "slave") { - ${"server_{$type}_Do_DB"} = explode (",", $server_slave_replication[0]["Replicate_Do_DB"]); - ${"server_{$type}_Ignore_DB"} = explode (",", $server_slave_replication[0]["Replicate_Ignore_DB"]); + ${"server_{$type}_Do_DB"} = explode(",", $server_slave_replication[0]["Replicate_Do_DB"]); + ${"server_{$type}_Ignore_DB"} = explode(",", $server_slave_replication[0]["Replicate_Ignore_DB"]); - ${"server_{$type}_Do_Table"} = explode (",", $server_slave_replication[0]["Replicate_Do_Table"]); - ${"server_{$type}_Ignore_Table"} = explode (",", $server_slave_replication[0]["Replicate_Ignore_Table"]); + ${"server_{$type}_Do_Table"} = explode(",", $server_slave_replication[0]["Replicate_Do_Table"]); + ${"server_{$type}_Ignore_Table"} = explode(",", $server_slave_replication[0]["Replicate_Ignore_Table"]); - ${"server_{$type}_Wild_Do_Table"} = explode (",", $server_slave_replication[0]["Replicate_Wild_Do_Table"]); - ${"server_{$type}_Wild_Ignore_Table"} = explode (",", $server_slave_replication[0]["Replicate_Wild_Ignore_Table"]); + ${"server_{$type}_Wild_Do_Table"} = explode(",", $server_slave_replication[0]["Replicate_Wild_Do_Table"]); + ${"server_{$type}_Wild_Ignore_Table"} = explode(",", $server_slave_replication[0]["Replicate_Wild_Ignore_Table"]); } } } @@ -134,12 +134,10 @@ function PMA_replication_strout($string, $table = false) { * * @return mixed output of PMA_DBI_try_query */ -function PMA_replication_slave_control ($action, $control = null, $link = null) -{ +function PMA_replication_slave_control($action, $control = null, $link = null) { $action = strtoupper($action); $control = strtoupper($control); - if ($action != "START" && $action != "STOP") { return -1; } @@ -147,7 +145,7 @@ function PMA_replication_slave_control ($action, $control = null, $link = null) return -1; } - return PMA_DBI_try_query($action." SLAVE ".$control.";", $link); + return PMA_DBI_try_query($action . " SLAVE " . $control . ";", $link); } /** * @param String $user - replication user on master @@ -161,19 +159,18 @@ function PMA_replication_slave_control ($action, $control = null, $link = null) * * @return output of CHANGE MASTER mysql command */ -function PMA_replication_slave_change_master($user, $password, $host, $port, $pos, $stop = true, $start = true, $link = null) -{ +function PMA_replication_slave_change_master($user, $password, $host, $port, $pos, $stop = true, $start = true, $link = null) { if ($stop) { PMA_replication_slave_control("STOP", null, $link); } - $out = PMA_DBI_try_query('CHANGE MASTER TO '. - 'MASTER_HOST=\''.$host.'\','. - 'MASTER_PORT='.($port*1).','. - 'MASTER_USER=\''.$user.'\','. - 'MASTER_PASSWORD=\''.$password.'\','. - 'MASTER_LOG_FILE=\''.$pos["File"].'\','. - 'MASTER_LOG_POS='.$pos["Position"].';', $link); + $out = PMA_DBI_try_query('CHANGE MASTER TO ' . + 'MASTER_HOST=\'' . $host . '\',' . + 'MASTER_PORT=' . ($port * 1) . ',' . + 'MASTER_USER=\'' . $user . '\',' . + 'MASTER_PASSWORD=\'' . $password . '\',' . + 'MASTER_LOG_FILE=\'' . $pos["File"] . '\',' . + 'MASTER_LOG_POS=' . $pos["Position"] . ';', $link); if ($start) { PMA_replication_slave_control("START", null, $link); @@ -193,8 +190,7 @@ function PMA_replication_slave_change_master($user, $password, $host, $port, $po * * @return mixed $link mysql link on success */ -function PMA_replication_connect_to_master($user, $password, $host = null, $port = null, $socket = null) -{ +function PMA_replication_connect_to_master($user, $password, $host = null, $port = null, $socket = null) { $server = array(); $server["host"] = $host; $server["port"] = $port; @@ -209,12 +205,11 @@ function PMA_replication_connect_to_master($user, $password, $host = null, $port * * @return array - containing File and Position in MySQL replication on master server, useful for PMA_replication_slave_change_master */ -function PMA_replication_slave_bin_log_master($link = null) -{ +function PMA_replication_slave_bin_log_master($link = null) { $data = PMA_DBI_fetch_result('SHOW MASTER STATUS', null, null, $link); $output = array(); - if (!empty($data)) { + if (! empty($data)) { $output["File"] = $data[0]["File"]; $output["Position"] = $data[0]["Position"]; } @@ -229,17 +224,16 @@ function PMA_replication_slave_bin_log_master($link = null) * @return array array of replicated databases */ -function PMA_replication_master_replicated_dbs($link = null) -{ +function PMA_replication_master_replicated_dbs($link = null) { $data = PMA_DBI_fetch_result('SHOW MASTER STATUS', null, null, $link); // let's find out, which databases are replicated $do_db = array(); $ignore_db = array(); - if (!empty($data[0]['Binlog_Do_DB'])) { + if (! empty($data[0]['Binlog_Do_DB'])) { $do_db = explode(',', $data[0]['Binlog_Do_DB']); } - if (!empty($data[0]['Binlog_Ignore_DB'])) { + if (! empty($data[0]['Binlog_Ignore_DB'])) { $ignore_db = explode(',', $data[0]['Binlog_Ignore_DB']); } @@ -272,8 +266,7 @@ function PMA_replication_master_replicated_dbs($link = null) * @param boolean $data - if true, then data will be copied as well */ -function PMA_replication_synchronize_db($db, $src_link, $trg_link, $data = true) -{ +function PMA_replication_synchronize_db($db, $src_link, $trg_link, $data = true) { $src_db = $trg_db = $db; $src_connection = PMA_DBI_select_db($src_db, $src_link); @@ -310,8 +303,9 @@ function PMA_replication_synchronize_db($db, $src_link, $trg_link, $data = true) /** * - * ********************************************* Comparing Data In the Matching Tables ****************************************** - * *********************It is assumed that the matching tables are structurally and typely exactly the same ********************* + * Comparing Data In the Matching Tables + * It is assumed that the matching tables are structurally + * and typely exactly the same */ $fields_num = array(); $matching_tables_fields = array(); @@ -323,13 +317,11 @@ function PMA_replication_synchronize_db($db, $src_link, $trg_link, $data = true) $uncommon_tables_fields = array(); $matching_tables_num = sizeof($matching_tables); - for ($i=0; $i< sizeof($matching_tables); $i++) - { + for ($i = 0; $i < sizeof($matching_tables); $i++) { 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); } - for ($j=0; $j< sizeof($source_tables_uncommon); $j++) - { + for ($j = 0; $j < sizeof($source_tables_uncommon); $j++) { PMA_dataDiffInUncommonTables($source_tables_uncommon, $src_db, $src_link, $j, $row_count); } @@ -349,14 +341,7 @@ function PMA_replication_synchronize_db($db, $src_link, $trg_link, $data = true) $remove_indexes_array = array(); $criteria = array('Field', 'Type', 'Null', 'Collation', 'Key', 'Default', 'Comment'); - for ($counter = 0; $counter < $matching_tables_num; $counter++) - { - // 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, $matching_tables_keys, - // $target_tables_keys, $matching_tables_fields, $counter); - // - // PMA_indexesDiffInTables($src_db, $trg_db, $src_link, $trg_link, $matching_tables, $source_indexes, $target_indexes, - // $add_indexes_array, $remove_indexes_array, $counter); + for ($counter = 0; $counter < $matching_tables_num; $counter++) { 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, $counter); @@ -373,8 +358,7 @@ function PMA_replication_synchronize_db($db, $src_link, $trg_link, $data = true) /** * Generating Create Table query for all the non-matching tables present in Source but not in Target and populating tables. */ - for($q = 0; $q < sizeof($source_tables_uncommon); $q++) - { + for($q = 0; $q < sizeof($source_tables_uncommon); $q++) { if (isset($uncommon_tables[$q])) { PMA_createTargetTables($src_db, $trg_db, $src_link, $trg_link, $source_tables_uncommon, $q, $uncommon_tables_fields, false); } -- 2.11.4.GIT