From 1044df611a3f3d7cb33a2e57171610b29328f456 Mon Sep 17 00:00:00 2001 From: xmujay Date: Thu, 20 Jun 2013 01:10:24 +0800 Subject: [PATCH 1/3] refactor server_replication.php 1. render HTML at once 2. split long functions --- libraries/replication.inc.php | 2 +- libraries/replication_gui.lib.php | 645 +++++++++++++++++++++++------- libraries/server_common.lib.php | 3 + server_replication.php | 229 ++--------- server_status.php | 2 +- 5 files changed, 534 insertions(+), 347 deletions(-) diff --git a/libraries/replication.inc.php b/libraries/replication.inc.php index cfaf0a6207..4a3dec65b3 100644 --- a/libraries/replication.inc.php +++ b/libraries/replication.inc.php @@ -78,7 +78,7 @@ $slave_variables = array( * define important variables, which need to be watched for * correct running of replication in slave mode * - * @usedby PMA_replication_print_status_table() + * @usedby PMA_getHtmlForReplication_status_table() */ // TODO change to regexp or something, to allow for negative match. // To e.g. highlight 'Last_Error' diff --git a/libraries/replication_gui.lib.php b/libraries/replication_gui.lib.php index 720751ebdc..602f29fc9e 100644 --- a/libraries/replication_gui.lib.php +++ b/libraries/replication_gui.lib.php @@ -9,14 +9,299 @@ if (! defined('PHPMYADMIN')) { } /** - * returns code for selecting databases + * returns HTML for error message * * @return String HTML code */ -function PMA_replication_db_multibox() +function PMA_getHtmlForErrorMessage() +{ + $html = ''; + if (isset($_SESSION['replication']['sr_action_status']) + && isset($_SESSION['replication']['sr_action_info']) + ) { + if ($_SESSION['replication']['sr_action_status'] == 'error') { + $error_message = $_SESSION['replication']['sr_action_info']; + $html .= PMA_Message::error($error_message)->getDisplay(); + $_SESSION['replication']['sr_action_status'] = 'unknown'; + } elseif ($_SESSION['replication']['sr_action_status'] == 'success') { + $success_message = $_SESSION['replication']['sr_action_info']; + $html .= PMA_Message::success($success_message)->getDisplay(); + $_SESSION['replication']['sr_action_status'] = 'unknown'; + } + } + return $html; +} + +/** + * returns HTML for master replication + * + * @return String HTML code + */ +function PMA_getHtmlForMasterReplication() +{ + $html = ''; + if (! isset($GLOBALS['repl_clear_scr'])) { + $html .= '
'; + $html .= '' . __('Master replication') . ''; + $html .= __('This server is configured as master in a replication process.'); + $html .= '"; + $html .= "
"; + } + + return $html; +} + +/** + * returns HTML for master replication configuration + * + * @return String HTML code + */ +function PMA_getHtmlForMasterConfiguration() +{ + $html = '
'; + $html .= '' . __('Master configuration') . ''; + $html .= __('This server is not configured as master server in a replication process. ' + . 'You can choose from either replicating all databases and ignoring certain ' + . '(useful if you want to replicate majority of databases) or you can choose to ignore ' + . 'all databases by default and allow only certain databases to be replicated. Please select the mode:') + . '

'; + + $html .= ''; + $html .= '

'; + $html .= __('Please select databases:') . '
'; + $html .= PMA_getHtmlForReplication_db_multibox(); + $html .= '

'; + $html .= __('Now, add the following lines at the end of [mysqld] section in your my.cnf and ' + . 'please restart the MySQL server afterwards.') . '
'; + $html .= '
';
+    $html .= __('Once you restarted MySQL server, please click on Go button. ' 
+        . 'Afterwards, you should see a message informing you, that this server is configured as master.');
+    $html .= '
'; + $html .= '
'; + $html .= '
'; + $html .= PMA_generate_common_hidden_inputs('', ''); + $html .= ' '; + $html .= '
'; + $html .= '
'; + + return $html; +} + +/** + * returns HTML for slave replication configuration + * + * @param bool $server_slave_status Whether it is Master or Slave + * @param Array $server_slave_replication Slave replication + * + * @return String HTML code + */ +function PMA_getHtmlForSlaveConfiguration($server_slave_status, $server_slave_replication) +{ + $html = '
'; + $html .= '' . __('Slave replication') . ''; + if ($server_slave_status) { + $html .= '
'; + + $_url_params = $GLOBALS['url_params']; + $_url_params['sr_take_action'] = true; + $_url_params['sr_slave_server_control'] = true; + + if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') { + $_url_params['sr_slave_action'] = 'start'; + } else { + $_url_params['sr_slave_action'] = 'stop'; + } + + $_url_params['sr_slave_control_parm'] = 'IO_THREAD'; + $slave_control_io_link = 'server_replication.php' + . PMA_generate_common_url($_url_params); + + if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') { + $_url_params['sr_slave_action'] = 'start'; + } else { + $_url_params['sr_slave_action'] = 'stop'; + } + + $_url_params['sr_slave_control_parm'] = 'SQL_THREAD'; + $slave_control_sql_link = 'server_replication.php' + . PMA_generate_common_url($_url_params); + + if ($server_slave_replication[0]['Slave_IO_Running'] == 'No' + || $server_slave_replication[0]['Slave_SQL_Running'] == 'No' + ) { + $_url_params['sr_slave_action'] = 'start'; + } else { + $_url_params['sr_slave_action'] = 'stop'; + } + + $_url_params['sr_slave_control_parm'] = null; + $slave_control_full_link = 'server_replication.php' + . PMA_generate_common_url($_url_params); + + $_url_params['sr_slave_action'] = 'reset'; + $slave_control_reset_link = 'server_replication.php' + . PMA_generate_common_url($_url_params); + + $_url_params = $GLOBALS['url_params']; + $_url_params['sr_slave_skip_error'] = true; + $slave_skip_error_link = 'server_replication.php' + . PMA_generate_common_url($_url_params); + + if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') { + $html .= PMA_Message::error(__('Slave SQL Thread not running!'))->getDisplay(); + } + if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') { + $html .= PMA_Message::error(__('Slave IO Thread not running!'))->getDisplay(); + } + + $_url_params = $GLOBALS['url_params']; + $_url_params['sl_configure'] = true; + $_url_params['repl_clear_scr'] = true; + + $reconfiguremaster_link = 'server_replication.php' . PMA_generate_common_url($_url_params); + + $html .= __('Server is configured as slave in a replication process. Would you like to:'); + $html .= '
'; + $html .= ''; + $html .= '
'; + + } elseif (! isset($GLOBALS['sl_configure'])) { + $_url_params = $GLOBALS['url_params']; + $_url_params['sl_configure'] = true; + $_url_params['repl_clear_scr'] = true; + + $html .= sprintf(__('This server is not configured as slave in a replication process. ' + . 'Would you like to configure it?'), 'server_replication.php' + . PMA_generate_common_url($_url_params)); + } + $html .= '
'; + + return $html; +} + +/** + * returns HTML for Slave Error Management + * + * @param String $slave_skip_error_link error link + * + * @return String HTML code + */ +function PMA_getHtmlForSlaveErrorManagement($slave_skip_error_link) +{ + $html = ''; + $html .= __('Error management:') . ''; + $html .= ' '; + return $html; +} + +/** + * returns HTML for not configure for a server replication + * + * @return String HTML code + */ +function PMA_getHtmlForNotServerReplication() +{ + $_url_params = $GLOBALS['url_params']; + $_url_params['mr_configure'] = true; + + $html = '
'; + $html .= '' . __('Master replication') . ''; + $html .= sprintf(__('This server is not configured as master in a replication process. ' + . 'Would you like to configure it?'), 'server_replication.php' + . PMA_generate_common_url($_url_params)); + $html .= '
'; + return $html; +} + +/** + * returns HTML code for selecting databases + * + * @return String HTML code + */ +function PMA_getHtmlForReplication_db_multibox() { $multi_values = ''; - $multi_values .= ''; foreach ($GLOBALS['pma']->databases as $current_db) { if ($GLOBALS['dbi']->isSystemSchema($current_db)) { @@ -28,7 +313,8 @@ function PMA_replication_db_multibox() $is_selected = ''; } $current_db = htmlspecialchars($current_db); - $multi_values .= ' '; + $multi_values .= ' '; } // end while $multi_values .= ''; @@ -38,65 +324,74 @@ function PMA_replication_db_multibox() } /** - * prints out code for changing master + * returns HTML for changing master * * @param String $submitname - submit button name * - * @return void + * @return String HTML code */ -function PMA_replication_gui_changemaster($submitname) +function PMA_getHtmlForReplication_changemaster($submitname) { - + $html = ''; list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length(); - echo '
'; - echo PMA_generate_common_hidden_inputs('', ''); - echo '
'; - echo ' ' . __('Slave configuration') . ' - ' . __('Change or reconfigure master server') . ''; - echo __('Make sure, you have unique server-id in your configuration file (my.cnf). If not, please add the following line into [mysqld] section:') . '
'; - echo '
server-id=' . time() . '
'; - echo '
'; - echo ' '; - echo ' '; - echo '
'; - echo '
'; - echo ' '; - echo ' '; - echo '
'; - echo '
'; - echo ' '; - echo ' '; - echo '
'; - echo '
'; - echo ' '; - echo ' '; - echo '
'; - echo '
'; - echo ' '; - echo '
'; + $html .= '
'; + $html .= PMA_generate_common_hidden_inputs('', ''); + $html .= '
'; + $html .= ' ' . __('Slave configuration'); + $html .= ' - ' . __('Change or reconfigure master server') . ''; + $html .= __('Make sure, you have unique server-id in your configuration file (my.cnf). ' + . 'If not, please add the following line into [mysqld] section:') . '
'; + $html .= '
server-id=' . time() . '
'; + $html .= '
'; + $html .= ' '; + $html .= ' '; + $html .= '
'; + $html .= '
'; + $html .= ' '; + $html .= ' '; + $html .= '
'; + $html .= '
'; + $html .= ' '; + $html .= ' '; + $html .= '
'; + $html .= '
'; + $html .= ' '; + $html .= ' '; + $html .= '
'; + $html .= '
'; + $html .= ' '; + $html .= '
'; + + return $html; } /** - * This function prints out table with replication status. + * This function returns html code for table with replication status. * * @param string $type either master or slave * @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 * - * @return void + * @return String HTML code */ -function PMA_replication_print_status_table($type, $hidden = false, $title = true) +function PMA_getHtmlForReplication_status_table($type, $hidden = false, $title = true) { global ${"{$type}_variables"}; global ${"{$type}_variables_alerts"}; global ${"{$type}_variables_oks"}; global ${"server_{$type}_replication"}; global ${"strReplicationStatus_{$type}"}; + + $html = ''; // TODO check the Masters server id? // seems to default to '1' when queried via SHOW VARIABLES , but resulted in error on the master when slave connects @@ -105,48 +400,51 @@ function PMA_replication_print_status_table($type, $hidden = false, $title = tru // //$server_id = $GLOBALS['dbi']->fetchValue("SHOW VARIABLES LIKE 'server_id'", 0, 1); - echo '
'; + $html .= '
'; if ($title) { if ($type == 'master') { - echo '

' . __('Master status') . '

'; + $html .= '

'; + $html .= __('Master status') . '

'; } else { - echo '

' . __('Slave status') . '

'; + $html .= '

'; + $html .= __('Slave status') . '

'; } } else { - echo '
'; + $html .= '
'; } - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; + $html .= '
' . __('Variable') . '' . __('Value') . '
'; + $html .= ' '; + $html .= ' '; + $html .= ' '; + $html .= ' '; + $html .= ' '; + $html .= ' '; + $html .= ' '; $odd_row = true; foreach (${"{$type}_variables"} as $variable) { - echo ' '; - echo ' '; - echo ' '; + $html .= ' '; + $html .= ' '; - echo ' '; + $html .= ' '; + $html .= ' '; $odd_row = ! $odd_row; } - echo ' '; - echo '
' . __('Variable') . '' . __('Value') . '
'; - echo $variable; - echo ' '; + $html .= '
'; + $html .= $variable; + $html .= ' '; // TODO change to regexp or something, to allow for negative match if (isset(${"{$type}_variables_alerts"}[$variable]) && ${"{$type}_variables_alerts"}[$variable] == ${"server_{$type}_replication"}[0][$variable] ) { - echo ''; + $html .= ''; } elseif (isset(${"{$type}_variables_oks"}[$variable]) && ${"{$type}_variables_oks"}[$variable] == ${"server_{$type}_replication"}[0][$variable] ) { - echo ''; + $html .= ''; } else { - echo ''; + $html .= ''; } // allow wrapping long table lists into multiple lines static $variables_wrap = array( @@ -154,65 +452,70 @@ function PMA_replication_print_status_table($type, $hidden = false, $title = tru 'Replicate_Do_Table', 'Replicate_Ignore_Table', 'Replicate_Wild_Do_Table', 'Replicate_Wild_Ignore_Table'); if (in_array($variable, $variables_wrap)) { - echo str_replace(',', ', ', ${"server_{$type}_replication"}[0][$variable]); + $html .= str_replace(',', ', ', ${"server_{$type}_replication"}[0][$variable]); } else { - echo ${"server_{$type}_replication"}[0][$variable]; + $html .= ${"server_{$type}_replication"}[0][$variable]; } - echo ''; + $html .= ''; - echo '
'; - echo '
'; - echo '
'; - + $html .= ' '; + $html .= ' '; + $html .= '
'; + $html .= '
'; + + return $html; } /** - * Prints table with slave users connected to this master + * returns html code for table with slave users connected to this master * * @param boolean $hidden - if true, then default style is set to hidden, default value false * * @return void */ -function PMA_replication_print_slaves_table($hidden = false) +function PMA_getHtmlForReplication_slaves_table($hidden = false) { - + $html = ''; // Fetch data $data = $GLOBALS['dbi']->fetchResult('SHOW SLAVE HOSTS', null, null); - echo '
'; - echo '
'; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; + $html .= '
'; + $html .= '
'; + $html .= '
' . __('Server ID') . '' . __('Host') . '
'; + $html .= ' '; + $html .= ' '; + $html .= ' '; + $html .= ' '; + $html .= ' '; + $html .= ' '; + $html .= ' '; $odd_row = true; foreach ($data as $slave) { - echo ' '; - echo ' '; - echo ' '; - echo ' '; + $html .= ' '; + $html .= ' '; + $html .= ' '; + $html .= ' '; $odd_row = ! $odd_row; } - echo ' '; - echo '
' . __('Server ID') . '' . __('Host') . '
' . $slave['Server_id'] . '' . $slave['Host'] . '
' . $slave['Server_id'] . '' . $slave['Host'] . '
'; - echo '
'; - PMA_Message::notice(__('Only slaves started with the --report-host=host_name option are visible in this list.'))->display(); - echo '
'; - echo '
'; + $html .= ' '; + $html .= ' '; + $html .= '
'; + $html .= PMA_Message::notice(__('Only slaves started with the ' + . '--report-host=host_name option are visible in this list.'))->getDisplay(); + $html .= '
'; + $html .= ' '; + + return $html; } /** @@ -245,65 +548,52 @@ function PMA_replication_get_username_hostname_length() } /** - * Print code to add a replication slave user to the master + * returns html code to add a replication slave user to the master * - * @return void + * @return String HTML code */ -function PMA_replication_gui_master_addslaveuser() +function PMA_getHtmlForReplication_master_addslaveuser() { - + $html = ''; list($username_length, $hostname_length) = PMA_replication_get_username_hostname_length(); if (isset($GLOBALS['username']) && strlen($GLOBALS['username']) === 0) { $GLOBALS['pred_username'] = 'any'; } - echo '
'; - echo '
'; - echo PMA_generate_common_hidden_inputs('', ''); - echo '
' - . ''.__('Add slave replication user').'' - . '' - . '' - . '' - . '' - . '' - . '' - . '
' - . '' - . '' - . ' ' - . '' - . '' - . '
' + $html .= '
'; + $html .= '' . __('Add slave replication user') . '' + . PMA_getHtmlForAddUserLoginForm() . '
' . '' . '' - . ' ' + . ' ' + . '' + . '
' + . '' + . '' + . ' ' + . '' + . '' + . '
'; + + return $html; +} + +/** + * returns HTML for TableInfoForm + * + * @param bool $hostname_length Selected hostname length + * + * @return String HTML code + */ +function PMA_getHtmlForTableInfoForm($hostname_length) +{ + $html = ' ' @@ -363,39 +710,45 @@ function PMA_replication_gui_master_addslaveuser() . '' . ' ' . '' - . '' + . '' . '
' . '
' . '' . ' ' - . '' + . '' . '
' . '
' . '' . '' - . ' ' + . ' ' . '' . '' . '
' . '
'; - echo '
'; + return $html; } + ?> diff --git a/libraries/server_common.lib.php b/libraries/server_common.lib.php index b686c65ef3..3128a59893 100644 --- a/libraries/server_common.lib.php +++ b/libraries/server_common.lib.php @@ -29,6 +29,9 @@ function PMA_getSubPageHeader($type) $res['collations']['icon'] = 's_asci.png'; $res['collations']['text'] = __('Character Sets and Collations'); + $res['replication']['icon'] = 's_replication.png'; + $res['replication']['text'] = __('Replication'); + $html = '

' . "\n" . PMA_Util::getImage($res[$type]['icon']) . ' ' . $res[$type]['text'] . "\n" diff --git a/server_replication.php b/server_replication.php index 3ac2c4da20..7694126f4a 100644 --- a/server_replication.php +++ b/server_replication.php @@ -6,9 +6,13 @@ */ /** - * + * include files */ require_once 'libraries/common.inc.php'; +require_once 'libraries/server_common.inc.php'; + +require_once 'libraries/replication.inc.php'; +require_once 'libraries/replication_gui.lib.php'; /** * Does the common work @@ -19,19 +23,13 @@ $scripts = $header->getScripts(); $scripts->addFile('server_privileges.js'); $scripts->addFile('replication.js'); -require 'libraries/server_common.inc.php'; -require 'libraries/replication.inc.php'; -require 'libraries/replication_gui.lib.php'; - /** * Checks if the user is allowed to do what he tries to... */ if (! $is_superuser) { - echo '

' . "\n" - . PMA_Util::getIcon('s_replication.png') - . __('Replication') . "\n" - . '

' . "\n"; - PMA_Message::error(__('No Privileges'))->display(); + $html = PMA_getSubPageHeader('replication'); + $html .= PMA_Message::error(__('No Privileges'))->getDisplay(); + $response->addHTML($html); exit; } @@ -95,11 +93,19 @@ if (isset($GLOBALS['sr_take_action'])) { if (empty($position)) { $_SESSION['replication']['sr_action_status'] = 'error'; - $_SESSION['replication']['sr_action_info'] = __('Unable to read master log position. Possible privilege problem on master.'); + $_SESSION['replication']['sr_action_info'] = + __('Unable to read master log position. Possible privilege problem on master.'); } else { $_SESSION['replication']['m_correct'] = true; - if (! PMA_Replication_Slave_changeMaster($sr['username'], $sr['pma_pw'], $sr['hostname'], $sr['port'], $position, true, false)) { + if (! PMA_Replication_Slave_changeMaster( + $sr['username'], + $sr['pma_pw'], + $sr['hostname'], + $sr['port'], + $position, + true, + false)) { $_SESSION['replication']['sr_action_status'] = 'error'; $_SESSION['replication']['sr_action_info'] = __('Unable to change master'); } else { @@ -141,209 +147,34 @@ if (isset($GLOBALS['sr_take_action'])) { unset($refresh); } - -echo '
'; -echo '

'; -echo ' ' . PMA_Util::getImage('s_replication.png'); -echo __('Replication'); -echo '

'; +/** + * start output + */ +$response->addHTML('
'); +$response->addHTML(PMA_getSubPageHeader('replication')); // Display error messages -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') { - PMA_Message::success($_SESSION['replication']['sr_action_info'])->display(); - $_SESSION['replication']['sr_action_status'] = 'unknown'; - } -} +$response->addHTML(PMA_getHtmlForErrorMessage()); if ($server_master_status) { - if (! isset($GLOBALS['repl_clear_scr'])) { - echo '
'; - echo '' . __('Master replication') . ''; - echo __('This server is configured as master in a replication process.'); - echo '
    '; - echo '
  • ' . __('Show master status') . ''; - PMA_replication_print_status_table('master', true, false); - echo '
  • '; - - echo '
  • ' . __('Show connected slaves') . ''; - PMA_replication_print_slaves_table(true); - echo '
  • '; - - $_url_params = $GLOBALS['url_params']; - $_url_params['mr_adduser'] = true; - $_url_params['repl_clear_scr'] = true; - - echo '
  • '; - echo __('Add slave replication user') . '
  • '; - } - - // Display 'Add replication slave user' form - if (isset($GLOBALS['mr_adduser'])) { - PMA_replication_gui_master_addslaveuser(); - } elseif (! isset($GLOBALS['repl_clear_scr'])) { - echo "
"; - echo "
"; - } + $response->addHTML(PMA_getHtmlForMasterReplication()); } elseif (! isset($GLOBALS['mr_configure']) && ! isset($GLOBALS['repl_clear_scr'])) { - $_url_params = $GLOBALS['url_params']; - $_url_params['mr_configure'] = true; - - echo '
'; - echo '' . __('Master replication') . ''; - echo sprintf(__('This server is not configured as master in a replication process. Would you like to configure it?'), 'server_replication.php' . PMA_generate_common_url($_url_params)); - echo '
'; + $response->addHTML(PMA_getHtmlForNotServerReplication()); } if (isset($GLOBALS['mr_configure'])) { // Render the 'Master configuration' section - echo '
'; - echo '' . __('Master configuration') . ''; - echo __('This server is not configured as master server in a replication process. You can choose from either replicating all databases and ignoring certain (useful if you want to replicate majority of databases) or you can choose to ignore all databases by default and allow only certain databases to be replicated. Please select the mode:') . '

'; - - echo ''; - echo '

'; - echo __('Please select databases:') . '
'; - echo PMA_replication_db_multibox(); - echo '

'; - echo __('Now, add the following lines at the end of [mysqld] section in your my.cnf and please restart the MySQL server afterwards.') . '
'; - echo '
';
-    echo __('Once you restarted MySQL server, please click on Go button. Afterwards, you should see a message informing you, that this server is configured as master.');
-    echo '
'; - echo '
'; - echo '
'; - echo PMA_generate_common_hidden_inputs('', ''); - echo ' '; - echo '
'; - echo '
'; - + $response->addHTML(PMA_getHtmlForMasterConfiguration()); exit; } -echo '
'; +$response->addHTML('
'); if (! isset($GLOBALS['repl_clear_scr'])) { // Render the 'Slave configuration' section - echo '
'; - echo '' . __('Slave replication') . ''; - if ($server_slave_status) { - echo '
'; - - $_url_params = $GLOBALS['url_params']; - $_url_params['sr_take_action'] = true; - $_url_params['sr_slave_server_control'] = true; - - if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') { - $_url_params['sr_slave_action'] = 'start'; - } else { - $_url_params['sr_slave_action'] = 'stop'; - } - - $_url_params['sr_slave_control_parm'] = 'IO_THREAD'; - $slave_control_io_link = 'server_replication.php' . PMA_generate_common_url($_url_params); - - if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') { - $_url_params['sr_slave_action'] = 'start'; - } else { - $_url_params['sr_slave_action'] = 'stop'; - } - - $_url_params['sr_slave_control_parm'] = 'SQL_THREAD'; - $slave_control_sql_link = 'server_replication.php' . PMA_generate_common_url($_url_params); - - if ($server_slave_replication[0]['Slave_IO_Running'] == 'No' - || $server_slave_replication[0]['Slave_SQL_Running'] == 'No' - ) { - $_url_params['sr_slave_action'] = 'start'; - } else { - $_url_params['sr_slave_action'] = 'stop'; - } - - $_url_params['sr_slave_control_parm'] = null; - $slave_control_full_link = 'server_replication.php' . PMA_generate_common_url($_url_params); - - $_url_params['sr_slave_action'] = 'reset'; - $slave_control_reset_link = 'server_replication.php' . PMA_generate_common_url($_url_params); - - $_url_params = $GLOBALS['url_params']; - $_url_params['sr_slave_skip_error'] = true; - $slave_skip_error_link = 'server_replication.php' . PMA_generate_common_url($_url_params); - - if ($server_slave_replication[0]['Slave_SQL_Running'] == 'No') { - PMA_Message::error(__('Slave SQL Thread not running!'))->display(); - } - if ($server_slave_replication[0]['Slave_IO_Running'] == 'No') { - PMA_Message::error(__('Slave IO Thread not running!'))->display(); - } - - $_url_params = $GLOBALS['url_params']; - $_url_params['sl_configure'] = true; - $_url_params['repl_clear_scr'] = true; - - $reconfiguremaster_link = 'server_replication.php' . PMA_generate_common_url($_url_params); - - echo __('Server is configured as slave in a replication process. Would you like to:'); - echo '
'; - echo ''; - echo '
'; - - } elseif (! isset($GLOBALS['sl_configure'])) { - $_url_params = $GLOBALS['url_params']; - $_url_params['sl_configure'] = true; - $_url_params['repl_clear_scr'] = true; - - echo sprintf(__('This server is not configured as slave in a replication process. Would you like to configure it?'), 'server_replication.php' . PMA_generate_common_url($_url_params)); - } - echo '
'; + $response->addHTML(PMA_getHtmlForSlaveConfiguration($server_slave_status, $server_slave_replication)); } if (isset($GLOBALS['sl_configure'])) { - PMA_replication_gui_changemaster("slave_changemaster"); + $response->addHTML(PMA_GetHtmlForReplication_changemaster("slave_changemaster")); } ?> diff --git a/server_status.php b/server_status.php index 690432e74e..f166b8aa85 100644 --- a/server_status.php +++ b/server_status.php @@ -141,7 +141,7 @@ function PMA_getServerStateGeneralInfoHtml($ServerStatusData) $retval .= ''; foreach ($GLOBALS['replication_types'] as $type) { if (isset(${"server_{$type}_status"}) && ${"server_{$type}_status"}) { - PMA_replication_print_status_table($type); + $retval .= PMA_getHtmlForReplication_status_table($type); } } } From cad22421ae07cf245659b024e2db042f4396884a Mon Sep 17 00:00:00 2001 From: xmujay Date: Fri, 21 Jun 2013 00:20:50 +0800 Subject: [PATCH 2/3] 1. fix the undefine error 2. add function to render same html tags --- libraries/replication_gui.lib.php | 77 ++++++++++++++++++++++--------- server_replication.php | 2 +- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/libraries/replication_gui.lib.php b/libraries/replication_gui.lib.php index 602f29fc9e..0d33e829b2 100644 --- a/libraries/replication_gui.lib.php +++ b/libraries/replication_gui.lib.php @@ -344,25 +344,34 @@ function PMA_getHtmlForReplication_changemaster($submitname) $html .= __('Make sure, you have unique server-id in your configuration file (my.cnf). ' . 'If not, please add the following line into [mysqld] section:') . '
'; $html .= '
server-id=' . time() . '
'; - $html .= '
'; - $html .= ' '; - $html .= ' '; - $html .= '
'; - $html .= '
'; - $html .= ' '; - $html .= ' '; - $html .= '
'; - $html .= '
'; - $html .= ' '; - $html .= ' '; - $html .= '
'; - $html .= '
'; - $html .= ' '; - $html .= ' '; - $html .= '
'; + + $label_array = array('text'=>__('User name:'), 'for'=>"text_username"); + $input_array = array('type'=>'text', 'name'=>'username', + 'id'=>'text_username', 'maxlength'=>$username_length, + 'title'=>__('User name') + ); + $html .= PMA_getHtmlForAddUser_input_div($label_array, $input_array); + + $label_array = array('text'=>__('Password:'), 'for'=>"text_pma_pw"); + $input_array = array('type'=>'password', 'name'=>'pma_pw', + 'id'=>'text_pma_pw', 'title'=>__('Password') + ); + $html .= PMA_getHtmlForAddUser_input_div($label_array, $input_array); + + $label_array = array('text'=>__('Host:'), 'for'=>"text_hostname"); + $input_array = array('type'=>'text', 'name'=>'hostname', + 'id'=>'text_hostname', 'maxlength'=>$hostname_length, + 'value'=>'' + ); + $html .= PMA_getHtmlForAddUser_input_div($label_array, $input_array); + + $label_array = array('text'=>__('Port:'), 'for'=>"text_port"); + $input_array = array('type'=>'text', 'name'=>'text_port', + 'id'=>'text_port', 'maxlength'=>6, + 'value'=>'3306' + ); + $html .= PMA_getHtmlForAddUser_input_div($label_array, $input_array); + $html .= ' '; $html .= ' '; $html .= ''; + return $html; +} + +/** + * returns HTML code for Add user input div + * + * @param Array $label_array label tag elements + * @param Array $input_array input tag elements + * + * @return String HTML code + */ +function PMA_getHtmlForAddUser_input_div($label_array, $input_array) +{ + $html = '
'; + $html .= ' '; + + $html .= ' $value) + $html .= ' ' . $key . '="' . $value. '" '; + $html .= ' />'; + $html .= '
'; return $html; } @@ -566,7 +597,7 @@ function PMA_getHtmlForReplication_master_addslaveuser() $html .= PMA_generate_common_hidden_inputs('', ''); $html .= '
' . '' . __('Add slave replication user') . '' - . PMA_getHtmlForAddUserLoginForm() + . PMA_getHtmlForAddUserLoginForm($username_length) . '
' . '
'; - } elseif (! isset($GLOBALS['sl_configure'])) { + } elseif (! isset($_REQUEST['sl_configure'])) { $_url_params = $GLOBALS['url_params']; $_url_params['sl_configure'] = true; $_url_params['repl_clear_scr'] = true; @@ -297,7 +297,7 @@ function PMA_getHtmlForNotServerReplication() * * @return String HTML code */ -function PMA_getHtmlForReplication_db_multibox() +function PMA_getHtmlForReplicationDbMultibox() { $multi_values = ''; $multi_values .= '' . ''; @@ -729,7 +737,7 @@ function PMA_getHtmlForTableInfoForm($hostname_length) . '' . '' . PMA_Util::showHint( @@ -746,12 +754,12 @@ function PMA_getHtmlForTableInfoForm($hostname_length) . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } ' . 'else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . ' ' . ' ' . '' diff --git a/server_replication.php b/server_replication.php index 69de5604f8..f1e196da03 100644 --- a/server_replication.php +++ b/server_replication.php @@ -33,45 +33,20 @@ if (! $is_superuser) { exit; } -/** - * Sets globals from $_REQUEST - */ -$request_params = array( - 'hostname', - 'mr_adduser', - 'mr_configure', - 'pma_pw', - 'port', - 'repl_clear_scr', - 'repl_data', - 'sl_configure', - 'slave_changemaster', - 'sr_skip_errors_count', - 'sr_slave_action', - 'sr_slave_control_parm', - 'sr_slave_server_control', - 'sr_slave_skip_error', - 'sr_take_action', - 'url_params', - 'username' -); - -foreach ($request_params as $one_request_param) { - if (isset($_REQUEST[$one_request_param])) { - $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param]; - } +//change $GLOBALS['url_params'] with $_REQUEST['url_params'] +if (isset($_REQUEST['url_params'])) { + $GLOBALS['url_params'] = $_REQUEST['url_params']; } - /** * Handling control requests */ -if (isset($GLOBALS['sr_take_action'])) { +if (isset($_REQUEST['sr_take_action'])) { $refresh = false; - if (isset($GLOBALS['slave_changemaster'])) { - $_SESSION['replication']['m_username'] = $sr['username'] = PMA_Util::sqlAddSlashes($GLOBALS['username']); - $_SESSION['replication']['m_password'] = $sr['pma_pw'] = PMA_Util::sqlAddSlashes($GLOBALS['pma_pw']); - $_SESSION['replication']['m_hostname'] = $sr['hostname'] = PMA_Util::sqlAddSlashes($GLOBALS['hostname']); - $_SESSION['replication']['m_port'] = $sr['port'] = PMA_Util::sqlAddSlashes($GLOBALS['port']); + if (isset($_REQUEST['slave_changemaster'])) { + $_SESSION['replication']['m_username'] = $sr['username'] = PMA_Util::sqlAddSlashes($_REQUEST['username']); + $_SESSION['replication']['m_password'] = $sr['pma_pw'] = PMA_Util::sqlAddSlashes($_REQUEST['pma_pw']); + $_SESSION['replication']['m_hostname'] = $sr['hostname'] = PMA_Util::sqlAddSlashes($_REQUEST['hostname']); + $_SESSION['replication']['m_port'] = $sr['port'] = PMA_Util::sqlAddSlashes($_REQUEST['port']); $_SESSION['replication']['m_correct'] = ''; $_SESSION['replication']['sr_action_status'] = 'error'; $_SESSION['replication']['sr_action_info'] = __('Unknown error'); @@ -117,23 +92,23 @@ if (isset($GLOBALS['sr_take_action'])) { } } } - } elseif (isset($GLOBALS['sr_slave_server_control'])) { - if ($GLOBALS['sr_slave_action'] == 'reset') { + } elseif (isset($_REQUEST['sr_slave_server_control'])) { + if ($_REQUEST['sr_slave_action'] == 'reset') { PMA_Replication_Slave_control("STOP"); $GLOBALS['dbi']->tryQuery("RESET SLAVE;"); PMA_Replication_Slave_control("START"); } else { PMA_Replication_Slave_control( - $GLOBALS['sr_slave_action'], - $GLOBALS['sr_slave_control_parm'] + $_REQUEST['sr_slave_action'], + $_REQUEST['sr_slave_control_parm'] ); } $refresh = true; - } elseif (isset($GLOBALS['sr_slave_skip_error'])) { + } elseif (isset($_REQUEST['sr_slave_skip_error'])) { $count = 1; - if (isset($GLOBALS['sr_skip_errors_count'])) { - $count = $GLOBALS['sr_skip_errors_count'] * 1; + if (isset($_REQUEST['sr_skip_errors_count'])) { + $count = $_REQUEST['sr_skip_errors_count'] * 1; } PMA_Replication_Slave_control("STOP"); $GLOBALS['dbi']->tryQuery("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";"); @@ -158,11 +133,11 @@ $response->addHTML(PMA_getHtmlForErrorMessage()); if ($server_master_status) { $response->addHTML(PMA_getHtmlForMasterReplication()); -} elseif (! isset($GLOBALS['mr_configure']) && ! isset($GLOBALS['repl_clear_scr'])) { +} elseif (! isset($_REQUEST['mr_configure']) && ! isset($_REQUEST['repl_clear_scr'])) { $response->addHTML(PMA_getHtmlForNotServerReplication()); } -if (isset($GLOBALS['mr_configure'])) { +if (isset($_REQUEST['mr_configure'])) { // Render the 'Master configuration' section $response->addHTML(PMA_getHtmlForMasterConfiguration()); exit; @@ -170,11 +145,11 @@ if (isset($GLOBALS['mr_configure'])) { $response->addHTML(''); -if (! isset($GLOBALS['repl_clear_scr'])) { +if (! isset($_REQUEST['repl_clear_scr'])) { // Render the 'Slave configuration' section $response->addHTML(PMA_getHtmlForSlaveConfiguration($server_slave_status, $server_slave_replication)); } -if (isset($GLOBALS['sl_configure'])) { - $response->addHTML(PMA_getHtmlForReplication_changemaster("slave_changemaster")); +if (isset($_REQUEST['sl_configure'])) { + $response->addHTML(PMA_getHtmlForReplicationChangeMaster("slave_changemaster")); } ?> diff --git a/server_status.php b/server_status.php index f166b8aa85..68562e308a 100644 --- a/server_status.php +++ b/server_status.php @@ -141,7 +141,7 @@ function PMA_getServerStateGeneralInfoHtml($ServerStatusData) $retval .= ''; foreach ($GLOBALS['replication_types'] as $type) { if (isset(${"server_{$type}_status"}) && ${"server_{$type}_status"}) { - $retval .= PMA_getHtmlForReplication_status_table($type); + $retval .= PMA_getHtmlForReplicationStatusTable($type); } } }