Fix indentation for gsoc replication code

make it match the included modeline, and fixed some other spacing issues
This commit is contained in:
Herman van Rink
2009-09-07 15:00:22 +00:00
parent ff994aea3f
commit d972ed5d03
6 changed files with 909 additions and 882 deletions

View File

@@ -341,7 +341,10 @@ foreach ($tables as $keyname => $each_table) {
if ($server_slave_status) {
////////////////////////////////////////////////////////////////
if ((strlen(array_search($truename, $server_slave_Do_Table))>0) || (strlen(array_search($db, $server_slave_Do_DB))>0) || (count($server_slave_Do_DB)==1 && count($server_slave_Ignore_DB)==1)) {
if ((strlen(array_search($truename, $server_slave_Do_Table)) > 0)
|| (strlen(array_search($db, $server_slave_Do_DB))>0)
|| (count($server_slave_Do_DB)==1 && count($server_slave_Ignore_DB)==1)
) {
$do = true;
}
foreach ($server_slave_Wild_Do_Table as $table) {

View File

@@ -80,11 +80,11 @@ $slave_variables = array(
$slave_variables_alerts = array(
'Slave_IO_Running' => 'No',
'Slave_SQL_Running' => 'No'
);
);
$slave_variables_oks = array(
'Slave_IO_Running' => 'Yes',
'Slave_SQL_Running' => 'Yes'
);
);
$serverid = time();
@@ -96,10 +96,10 @@ foreach ($replication_types as $type) {
${"server_{$type}_status"} = false;
if (${"server_{$type}_status"}) {
if ($type=="master") {
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"]);
} elseif ($type=="slave") {
} 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"]);
@@ -118,7 +118,7 @@ foreach ($replication_types as $type) {
* @param $table -
* @return
*/
function PMA_replication_strout($string, $table=false) {
function PMA_replication_strout($string, $table = false) {
$list = explode(".", $string);
return $list[(int)$table];
@@ -130,16 +130,19 @@ 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")
if ($action != "START" && $action != "STOP") {
return -1;
if ($control!="SQL_THREAD" && $control!="IO_THREAD" && $control!=null)
}
if ($control != "SQL_THREAD" && $control != "IO_THREAD" && $control != null) {
return -1;
}
return PMA_DBI_try_query($action." SLAVE ".$control.";", $link);
}
/**
@@ -154,10 +157,11 @@ 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)
if ($stop) {
PMA_replication_slave_control("STOP", null, $link);
}
$out = PMA_DBI_try_query('CHANGE MASTER TO '.
'MASTER_HOST=\''.$host.'\','.
@@ -184,7 +188,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;
@@ -198,7 +202,7 @@ function PMA_replication_connect_to_master($user, $password, $host=null, $port=n
*
* @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);
@@ -217,30 +221,32 @@ 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'], ',');
}
$tmp_alldbs = PMA_DBI_query('SHOW DATABASES;', $link);
while ($tmp_row = PMA_DBI_fetch_row($tmp_alldbs)) {
if ($tmp_row[0] == 'information_schema')
continue;
if (count($do_db)==0) {
if (array_search($tmp_row[0], $ignore_db)!==false) {
if (count($do_db) == 0) {
if (array_search($tmp_row[0], $ignore_db) !== false) {
continue;
}
$dblist[] = $tmp_row[0];
} else {
if (array_search($tmp_row[0], $do_db)!==false) {
if (array_search($tmp_row[0], $do_db) !== false) {
$dblist[] = $tmp_row[0];
}
}
@@ -258,7 +264,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 = $db;
$trg_db = $db;
@@ -270,6 +276,7 @@ function PMA_replication_synchronize_DB($db, $src_link, $trg_link, $data=true)
$trg_tables = PMA_DBI_get_tables($trg_db, $trg_link);
$target_tables_num = sizeof($trg_tables);
/**
* initializing arrays to save table names
*/
@@ -308,12 +315,12 @@ 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);
}
@@ -333,14 +340,14 @@ 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++)
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);
// 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);
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);
@@ -348,8 +355,6 @@ function PMA_replication_synchronize_DB($db, $src_link, $trg_link, $data=true)
$add_indexes_array, $alter_indexes_array,$remove_indexes_array, $counter);
}
$matching_table_data_diff = array();
$matching_table_structure_diff = array();
$uncommon_table_structure_diff = array();
@@ -359,7 +364,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);

View File

@@ -132,7 +132,7 @@ function PMA_replication_gui_changemaster($submitname) {
* @param boolean $hidden - if true, then default style is set to hidden, default value false
* @param boolen $title - if true, then title is displayed, default true
*/
function PMA_replication_print_status_table ($type, $hidden=false, $title=true) {
function PMA_replication_print_status_table ($type, $hidden = false, $title = true) {
global ${"{$type}_variables"};
global ${"{$type}_variables_alerts"};
global ${"{$type}_variables_oks"};
@@ -157,19 +157,26 @@ function PMA_replication_print_status_table ($type, $hidden=false, $title=true)
echo ' <tbody>'."\n";
$odd_row = true;
foreach(${"{$type}_variables"} as $variable) {
foreach (${"{$type}_variables"} as $variable) {
echo ' <tr class="'. ($odd_row ? 'odd' : 'even') .'">'."\n";
echo ' <td class="name">'."\n";
echo $variable."\n";
echo ' </td>'."\n";
echo ' <td class="value">'."\n";
if (isset(${"{$type}_variables_alerts"}[$variable]) && ${"{$type}_variables_alerts"}[$variable] == ${"server_{$type}_replication"}[0][$variable])
if (isset(${"{$type}_variables_alerts"}[$variable])
&& ${"{$type}_variables_alerts"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
) {
echo '<span class="attention">'."\n";
if (isset(${"{$type}_variables_oks"}[$variable]) && ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable])
}
if (isset(${"{$type}_variables_oks"}[$variable])
&& ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable]
) {
echo '<span class="allfine">'."\n";
else
} else {
echo '<span>'."\n";
}
echo ${"server_{$type}_replication"}[0][$variable];
echo '</span>'."\n";

View File

@@ -268,11 +268,13 @@ if ($databases_count > 0) {
} else {
$key = array_search($current["SCHEMA_NAME"], ${"server_{$type}_Do_DB"});
if (strlen($key)>0 || (${"server_{$type}_Do_DB"}[0]=="" && count(${"server_{$type}_Do_DB"})==1)) // if ($key != null) did not work for index "0"
if (strlen($key) > 0 || (${"server_{$type}_Do_DB"}[0] == "" && count(${"server_{$type}_Do_DB"}) == 1)) {
// if ($key != null) did not work for index "0"
echo '<img class="icon" src="' . $pmaThemeImage . 's_success.png" width="16" height="16" alt="REPLICATED" />' . "\n";
else
} else {
echo '';
}
}
echo '</td>';
}

View File

@@ -53,8 +53,9 @@ if (isset($GLOBALS['sr_take_action'])) {
$_SESSION['replication']['sr_action_info'] = $strReplicationUnknownError;
$url = $sr['hostname'];
if ($sr['port']!='')
$url .= ':'.$sr['port'];
if ($sr['port'] != '') {
$url .= ':' . $sr['port'];
}
$check_master = null;
error_reporting(0);
@@ -80,7 +81,7 @@ if (isset($GLOBALS['sr_take_action'])) {
}
}
} elseif (isset($GLOBALS['sr_slave_server_control'])) {
if ($GLOBALS['sr_slave_action']=='reset') {
if ($GLOBALS['sr_slave_action'] == 'reset') {
PMA_replication_slave_control("STOP");
PMA_DBI_try_query("RESET SLAVE;");
PMA_replication_slave_control("START");
@@ -91,7 +92,7 @@ if (isset($GLOBALS['sr_take_action'])) {
} elseif (isset($GLOBALS['sr_slave_skip_error'])) {
$count = 1;
if (isset($GLOBALS['sr_skip_errors_count'])) {
$count = $GLOBALS['sr_skip_errors_count']*1;
$count = $GLOBALS['sr_skip_errors_count'] * 1;
}
PMA_replication_slave_control("STOP");
PMA_DBI_try_query("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";");
@@ -114,24 +115,25 @@ if (isset($GLOBALS['sr_take_action'])) {
while ($tmp_row = PMA_DBI_fetch_row($tmp_alldbs)) {
if ($tmp_row[0] == 'information_schema')
continue;
if (count($do_db)==0) {
if (array_search($tmp_row[0], $ignore_db)!==false) {
if (count($do_db) == 0) {
if (array_search($tmp_row[0], $ignore_db) !== false) {
continue;
}
$dblist[] = $tmp_row[0];
PMA_DBI_query('CREATE DATABASE IF NOT EXISTS '.$tmp_row[0], $trg_link);
} else {
if (array_search($tmp_row[0], $do_db)!==false) {
if (array_search($tmp_row[0], $do_db) !== false) {
$dblist[] = $tmp_row[0];
PMA_DBI_query('CREATE DATABASE IF NOT EXISTS '.$tmp_row[0], $trg_link);
}
}
} // end while
if (isset($GLOBALS['repl_data']))
if (isset($GLOBALS['repl_data'])) {
$data = true;
else
} else {
$data = false;
}
foreach ($dblist as $db) {
PMA_replication_synchronize_db($db, $src_link, $trg_link, $data);
}
@@ -146,23 +148,23 @@ if (isset($GLOBALS['sr_take_action'])) {
*/
require './libraries/server_links.inc.php';
echo '<div id="replication">'."\n";
echo ' <h2>'."\n";
echo ' <img class="icon" src="'. $GLOBALS['pmaThemeImage'] .'s_replication.png" width="16" height="16" alt="" />'."\n";
echo $GLOBALS['strReplication']."\n";
echo ' </h2>'."\n";
echo '<div id="replication">'."\n";
echo ' <h2>'."\n";
echo ' <img class="icon" src="'. $GLOBALS['pmaThemeImage'] .'s_replication.png" width="16" height="16" alt="" />'."\n";
echo $GLOBALS['strReplication']."\n";
echo ' </h2>'."\n";
if (isset($_SESSION['replication']['sr_action_status']) && isset($_SESSION['replication']['sr_action_info'])) {
if ($_SESSION['replication']['sr_action_status']=='error') {
if (isset($_SESSION['replication']['sr_action_status']) && isset($_SESSION['replication']['sr_action_info'])) {
if ($_SESSION['replication']['sr_action_status'] == 'error') {
PMA_Message::error($_SESSION['replication']['sr_action_info'])->display();
$_SESSION['replication']['sr_action_status'] = 'unknown';
} elseif ($_SESSION['replication']['sr_action_status']=='success') {
} elseif ($_SESSION['replication']['sr_action_status'] == 'success') {
PMA_Message::success($_SESSION['replication']['sr_action_info'])->display();
$_SESSION['replication']['sr_action_status'] = 'unknown';
}
}
}
if ($server_master_status) {
if ($server_master_status) {
if (!isset($GLOBALS['repl_clear_scr'])) {
echo PMA_js_mootools_domready($jscode['master_replication']);
echo '<fieldset>'."\n";
@@ -389,24 +391,32 @@ if (!isset($GLOBALS['repl_clear_scr'])) {
$_url_params['sr_take_action'] = true;
$_url_params['sr_slave_server_control'] = true;
if ($server_slave_replication[0]['Slave_IO_Running']=='No')
if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') {
$_url_params['sr_slave_action'] = 'start';
else
} else {
$_url_params['sr_slave_action'] = 'stop';
}
$_url_params['sr_slave_control_parm'] = 'IO_THREAD';
$slave_control_io_link = PMA_generate_common_url($_url_params);
if ($server_slave_replication[0]['Slave_SQL_Running']=='No')
if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') {
$_url_params['sr_slave_action'] = 'start';
else
} else {
$_url_params['sr_slave_action'] = 'stop';
}
$_url_params['sr_slave_control_parm'] = 'SQL_THREAD';
$slave_control_sql_link = PMA_generate_common_url($_url_params);
if ($server_slave_replication[0]['Slave_IO_Running']=='No' || $server_slave_replication[0]['Slave_SQL_Running']=='No')
if ($server_slave_replication[0]['Slave_IO_Running'] == 'No'
|| $server_slave_replication[0]['Slave_SQL_Running'] == 'No'
) {
$_url_params['sr_slave_action'] = 'start';
else
} else {
$_url_params['sr_slave_action'] = 'stop';
}
$_url_params['sr_slave_control_parm'] = null;
$slave_control_full_link = PMA_generate_common_url($_url_params);
@@ -417,9 +427,9 @@ if (!isset($GLOBALS['repl_clear_scr'])) {
$_url_params['sr_slave_skip_error'] = true;
$slave_skip_error_link = PMA_generate_common_url($_url_params);
if ($server_slave_replication[0]['Slave_SQL_Running']=='No')
if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No')
PMA_Message::warning('Slave SQL Thread not running!')->display();
if ($server_slave_replication[0]['Slave_IO_Running']=='No')
if ($server_slave_replication[0]['Slave_IO_Running'] == 'No')
PMA_Message::warning('Slave IO Thread not running!')->display();
$_url_params = $GLOBALS['url_params'];
@@ -433,7 +443,7 @@ if (!isset($GLOBALS['repl_clear_scr'])) {
echo '<ul>'."\n";
echo ' <li><a href="#" id="slave_status_href">'. $GLOBALS['strReplicationSlaveSeeStatus'].'</a></li>'."\n";
echo PMA_replication_print_status_table('slave', true, false);
if (isset($_SESSION['replication']['m_correct']) && $_SESSION['replication']['m_correct']==true) {
if (isset($_SESSION['replication']['m_correct']) && $_SESSION['replication']['m_correct'] == true) {
echo PMA_js_mootools_domready($jscode['slave_control_sync']);
echo ' <li><a href="#" id="slave_synchronization_href">'.$GLOBALS['strReplicationSynchronize'].'</a></li>'."\n";
echo ' <div id="slave_synchronization_gui" style="display: none">'."\n";
@@ -449,10 +459,10 @@ if (!isset($GLOBALS['repl_clear_scr'])) {
echo ' <li><a href="#" id="slave_control_href">'. $GLOBALS['strReplicationControlSlave'] .'</li>'."\n";
echo ' <div id="slave_control_gui" style="display: none">'."\n";
echo ' <ul>'."\n";
echo ' <li><a a href="'. $slave_control_full_link .'">'. $GLOBALS['strFull'] . '&nbsp;' . (($server_slave_replication[0]['Slave_IO_Running']=='No' || $server_slave_replication[0]['Slave_SQL_Running']=='No') ? $GLOBALS['strStart'] : $GLOBALS['strStop']). ' </a></li>'."\n";
echo ' <li><a a href="'. $slave_control_full_link .'">'. $GLOBALS['strFull'] . '&nbsp;' . (($server_slave_replication[0]['Slave_IO_Running'] == 'No' || $server_slave_replication[0]['Slave_SQL_Running'] == 'No') ? $GLOBALS['strStart'] : $GLOBALS['strStop']). ' </a></li>'."\n";
echo ' <li><a a href="'. $slave_control_reset_link .'">'. $GLOBALS['strReplicationSlaveReset'] .'</li>'."\n";
echo ' <li><a a href="'. $slave_control_sql_link .'">'. sprintf($GLOBALS['strReplicationSlaveSQLThread'], ($server_slave_replication[0]['Slave_SQL_Running']=='No' ? $GLOBALS['strStart'] : $GLOBALS['strStop'])) .'</a></li>'."\n";
echo ' <li><a a href="'. $slave_control_io_link .'">'. sprintf($GLOBALS['strReplicationSlaveIOThread'], ($server_slave_replication[0]['Slave_IO_Running']=='No' ? $GLOBALS['strStart'] : $GLOBALS['strStop'])) .'</a></li>'."\n";
echo ' <li><a a href="'. $slave_control_sql_link .'">'. sprintf($GLOBALS['strReplicationSlaveSQLThread'], ($server_slave_replication[0]['Slave_SQL_Running'] == 'No' ? $GLOBALS['strStart'] : $GLOBALS['strStop'])) .'</a></li>'."\n";
echo ' <li><a a href="'. $slave_control_io_link .'">'. sprintf($GLOBALS['strReplicationSlaveIOThread'], ($server_slave_replication[0]['Slave_IO_Running'] == 'No' ? $GLOBALS['strStart'] : $GLOBALS['strStop'])) .'</a></li>'."\n";
echo ' </ul>'."\n";
echo ' </div>'."\n";
echo ' <li><a href="#" id="slave_errormanagement_href">'. $GLOBALS['strReplicationSlaveErrorManagement'] .'</a></li>'."\n";

View File

@@ -700,17 +700,17 @@ unset($section_name, $section, $sections, $server_status, $odd_row, $alerts);
/* if the server works as master or slave in replication process, display useful information */
if ($server_master_status || $server_slave_status)
{
?>
?>
<hr class="clearfloat" />
<h3><a name="replication"></a><?php echo $strReplicationStatus; ?></h3>
<?php
<?php
foreach ($replication_types as $type)
{
if (${"server_{$type}_status"})
if (${"server_{$type}_status"}) {
PMA_replication_print_status_table($type);
}
}
unset($types);
}