From b979097f5f1965ede0d1d577fea1bd035cd6ba28 Mon Sep 17 00:00:00 2001 From: Dieter Adriaenssens Date: Fri, 6 Apr 2012 16:27:08 +0200 Subject: [PATCH 1/5] fix typo, improve coding style --- test/selenium/Helper.php | 53 +++++++------ test/selenium/PmaSeleniumLoginTest.php | 48 ++++++------ test/selenium/PmaSeleniumPrivilegesTest.php | 86 ++++++++++---------- test/selenium/PmaSeleniumTestCase.php | 62 ++++++++------- test/selenium/PmaSeleniumXssTest.php | 39 +++++---- test/selenium/README | 9 +-- test/selenium/TestConfig.php | 87 +++++++++++---------- 7 files changed, 198 insertions(+), 186 deletions(-) diff --git a/test/selenium/Helper.php b/test/selenium/Helper.php index 0d016532cd..81a6f11d14 100644 --- a/test/selenium/Helper.php +++ b/test/selenium/Helper.php @@ -1,32 +1,39 @@ isElementPresent('//*[@id="serverinfo"]/a[1]'); + } - public static function isLoggedIn($selenium) { - return $selenium->isElementPresent('//*[@id="serverinfo"]/a[1]'); - } - - public static function logOutIfLoggedIn($selenium) { - if (self::isLoggedIn($selenium)) { - $selenium->selectFrame("frame_navigation"); - $selenium->clickAndWait("css=img.icon.ic_b_home"); - } - } - - public static function getBrowserString() { - $browserString = self::$config->getCurrentBrowser(); - return $browserString; - } + public static function logOutIfLoggedIn($selenium) + { + if (self::isLoggedIn($selenium)) { + $selenium->selectFrame("frame_navigation"); + $selenium->clickAndWait("css=img.icon.ic_b_home"); + } + } + public static function getBrowserString() { + $browserString = self::$config->getCurrentBrowser(); + return $browserString; + } } - ?> diff --git a/test/selenium/PmaSeleniumLoginTest.php b/test/selenium/PmaSeleniumLoginTest.php index 7728e2d862..e5e438ddc8 100644 --- a/test/selenium/PmaSeleniumLoginTest.php +++ b/test/selenium/PmaSeleniumLoginTest.php @@ -1,37 +1,37 @@ setBrowser(Helper::getBrowserString()); + $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); + } - public function setUp() { - $helper = new Helper(); - $this->setBrowser(Helper::getBrowserString()); - $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); - } - - public function testSuccessfulLogin() { - $log = new PmaSeleniumTestCase($this); - $log->login(TESTSUITE_USER, TESTSUITE_PASSWORD); - $this->assertTrue($log->isSuccessLogin()); - Helper::logOutIfLoggedIn($this); - } - - public function testLoginWithWrongPassword() { - $log = new PmaSeleniumTestCase($this); - $log->login("Admin", "Admin"); - $this->assertTrue($log->isUnsuccessLogin()); - Helper::logOutIfLoggedIn($this); - } + public function testSuccessfulLogin() + { + $log = new PmaSeleniumTestCase($this); + $log->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->assertTrue($log->isSuccessLogin()); + Helper::logOutIfLoggedIn($this); + } + public function testLoginWithWrongPassword() + { + $log = new PmaSeleniumTestCase($this); + $log->login("Admin", "Admin"); + $this->assertTrue($log->isUnsuccessLogin()); + Helper::logOutIfLoggedIn($this); + } } - ?> diff --git a/test/selenium/PmaSeleniumPrivilegesTest.php b/test/selenium/PmaSeleniumPrivilegesTest.php index 92fb890915..2e0816f59e 100644 --- a/test/selenium/PmaSeleniumPrivilegesTest.php +++ b/test/selenium/PmaSeleniumPrivilegesTest.php @@ -1,57 +1,55 @@ setBrowser(Helper::getBrowserString()); - $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); - } - - public function testChangePassword() { - $log = new PmaSeleniumTestCase($this); - $log->login(TESTSUITE_USER, TESTSUITE_PASSWORD); - $this->selectFrame("frame_content"); - $this->click("link=Change password"); - $this->waitForPageToLoad("20000"); - try { - $this->assertEquals("", $this->getValue("text_pma_pw")); - } catch (PHPUnit_Framework_AssertionFailedError $e) { - array_push($this->verificationErrors, $e->toString()); - } - try { - $this->assertEquals("", $this->getValue("text_pma_pw2")); - } catch (PHPUnit_Framework_AssertionFailedError $e) { - array_push($this->verificationErrors, $e->toString()); - } - try { - $this->assertEquals("", $this->getValue("generated_pw")); - } catch (PHPUnit_Framework_AssertionFailedError $e) { - array_push($this->verificationErrors, $e->toString()); - } - $this->click("button_generate_password"); - $this->assertNotEquals("", $this->getValue("text_pma_pw")); - $this->assertNotEquals("", $this->getValue("text_pma_pw2")); - $this->assertNotEquals("", $this->getValue("generated_pw")); - $this->type("text_pma_pw", TESTSUITE_PASSWORD); - $this->type("text_pma_pw2", TESTSUITE_PASSWORD); - $this->click("//button[@type='button']"); - $this->waitForPageToLoad("20000"); - $this->assertTrue($this->isTextPresent("")); - $this->assertTrue($this->isTextPresent("")); - - } +class PmaSeleniumPrivilegesTest extends PHPUnit_Extensions_SeleniumTestCase +{ + public function setUp() + { + $helper = new Helper(); + $this->setBrowser(Helper::getBrowserString()); + $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); + } + public function testChangePassword() + { + $log = new PmaSeleniumTestCase($this); + $log->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->selectFrame("frame_content"); + $this->click("link=Change password"); + $this->waitForPageToLoad("20000"); + try { + $this->assertEquals("", $this->getValue("text_pma_pw")); + } catch (PHPUnit_Framework_AssertionFailedError $e) { + array_push($this->verificationErrors, $e->toString()); + } + try { + $this->assertEquals("", $this->getValue("text_pma_pw2")); + } catch (PHPUnit_Framework_AssertionFailedError $e) { + array_push($this->verificationErrors, $e->toString()); + } + try { + $this->assertEquals("", $this->getValue("generated_pw")); + } catch (PHPUnit_Framework_AssertionFailedError $e) { + array_push($this->verificationErrors, $e->toString()); + } + $this->click("button_generate_password"); + $this->assertNotEquals("", $this->getValue("text_pma_pw")); + $this->assertNotEquals("", $this->getValue("text_pma_pw2")); + $this->assertNotEquals("", $this->getValue("generated_pw")); + $this->type("text_pma_pw", TESTSUITE_PASSWORD); + $this->type("text_pma_pw2", TESTSUITE_PASSWORD); + $this->click("//button[@type='button']"); + $this->waitForPageToLoad("20000"); + $this->assertTrue($this->isTextPresent("")); + $this->assertTrue($this->isTextPresent("")); + } } - ?> diff --git a/test/selenium/PmaSeleniumTestCase.php b/test/selenium/PmaSeleniumTestCase.php index 9b6b982c81..06b404f86d 100644 --- a/test/selenium/PmaSeleniumTestCase.php +++ b/test/selenium/PmaSeleniumTestCase.php @@ -4,7 +4,7 @@ * Selenium parent class for TestCases * * @package PhpMyAdmin-test - * @group Selenium + * @subpackage Selenium */ class PmaSeleniumTestCase @@ -15,55 +15,57 @@ class PmaSeleniumTestCase private $selenium; private $config; - public function __construct($selenium) { + public function __construct($selenium) + { $this->txtUsername = 'input_username'; $this->txtPassword = 'input_password'; $this->btnLogin = 'input_go'; - $this->config = new TestConfig(); + $this->config = new TestConfig(); $this->selenium = $selenium; - } - /** + /** * perform a login - * @param $username - * @param $password + * + * @param string $username Username + * @param string $password Password + * + * @return void */ - public function login($username, $password) { - + public function login($username, $password) + { $this->selenium->open($this->config->getLoginURL()); $this->selenium->type($this->txtUsername, $username); $this->selenium->type($this->txtPassword, $password); $this->selenium->click($this->btnLogin); $this->selenium->waitForPageToLoad($this->config->getTimeoutValue()); - } /** * * @return boolean */ - public function isSuccessLogin() { - if($this->selenium->isElementPresent("//*[@id=\"serverinfo\"]")){ - return true; - } else { - return false; - } - } - - /** - * - * @return boolean - */ - public function isUnsuccessLogin() { - $val = $this->selenium->getValue('input_go'); - if($this->selenium->isElementPresent("//html/body/div/div[@class='error']")){ - return true; - } else { - return false; - } + public function isSuccessLogin() + { + if ($this->selenium->isElementPresent("//*[@id=\"serverinfo\"]")) { + return true; + } else { + return false; + } } + /** + * + * @return boolean + */ + public function isUnsuccessLogin() + { + $val = $this->selenium->getValue('input_go'); + if ($this->selenium->isElementPresent("//html/body/div/div[@class='error']")) { + return true; + } else { + return false; + } + } } - ?> diff --git a/test/selenium/PmaSeleniumXssTest.php b/test/selenium/PmaSeleniumXssTest.php index 62ba65a945..1c880185f0 100644 --- a/test/selenium/PmaSeleniumXssTest.php +++ b/test/selenium/PmaSeleniumXssTest.php @@ -1,33 +1,32 @@ setBrowser(Helper::getBrowserString()); - $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); - } - - public function testQueryTabWithNullValue() { - $log = new PmaSeleniumTestCase($this); - $log->login(TESTSUITE_USER, TESTSUITE_PASSWORD); - $this->selectFrame("frame_content"); - $this->click("link=SQL"); - $this->waitForPageToLoad("30000"); - $this->click("button_submit_query"); - $this->assertAlert("Missing value in the form!"); - } +class PmaSeleniumXSSTest extends PHPUnit_Extensions_SeleniumTestCase +{ + public function setUp() + { + $helper = new Helper(); + $this->setBrowser(Helper::getBrowserString()); + $this->setBrowserUrl(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); + } + public function testQueryTabWithNullValue() + { + $log = new PmaSeleniumTestCase($this); + $log->login(TESTSUITE_USER, TESTSUITE_PASSWORD); + $this->selectFrame("frame_content"); + $this->click("link=SQL"); + $this->waitForPageToLoad("30000"); + $this->click("button_submit_query"); + $this->assertAlert("Missing value in the form!"); + } } - ?> diff --git a/test/selenium/README b/test/selenium/README index c13ee55e22..f28a8b54b8 100644 --- a/test/selenium/README +++ b/test/selenium/README @@ -1,8 +1,9 @@ Guide to run the AllSeleniumTests.php (Yasitha Pandithawatta) -===================================== +============================================================= 1. Tested with version 4.0 -2. Configure the testing environment - Browser and the following feilds in phpunit.xml.dist +2. Configure the testing environment - Browser and add the following fields to + phpunit.xml.dist @@ -12,8 +13,6 @@ Guide to run the AllSeleniumTests.php (Yasitha Pandithawatta) 3. Start the selenium server -4. run $ phpunit test/AllSeleniumTests.php +4. Run $ phpunit test/AllSeleniumTests.php Note: Only PmaSeleniumLoginTest.php is fixed and added to the test suit. - - diff --git a/test/selenium/TestConfig.php b/test/selenium/TestConfig.php index 4d2963c1ff..f6cd965655 100644 --- a/test/selenium/TestConfig.php +++ b/test/selenium/TestConfig.php @@ -1,52 +1,59 @@ load('phpunit.xml.dist'); + $searchNode = $xmlDoc->getElementsByTagName("browser"); + foreach ($searchNode as $searchNode) { + $this->setCurrentBrowser($searchNode->getAttribute('browser')); + $this->setTimeoutValue($searchNode->getAttribute('timeout')); + } + $this->setLoginURL(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); + } - public function __construct() { - $xml = simplexml_load_file("phpunit.xml.dist"); - $xmlDoc = new DOMDocument(); - $xmlDoc->load('phpunit.xml.dist'); - $searchNode = $xmlDoc->getElementsByTagName("browser"); - foreach ($searchNode as $searchNode) { - $this->setCurrentBrowser($searchNode->getAttribute('browser')); - $this->setTimeoutValue($searchNode->getAttribute('timeout')); - } - $this->setLoginURL(TESTSUITE_PHPMYADMIN_HOST . TESTSUITE_PHPMYADMIN_URL); - } + public function setLoginURL($value) + { + $this->loginURL = $value; + } - public function setLoginURL($value) { + public function getLoginURL() + { + return $this->loginURL; + } - $this->loginURL = $value; - } + public function setTimeoutValue($value) + { + $this->timeoutValue = $value; + } - public function getLoginURL() { + public function getTimeoutValue() + { + return $this->timeoutValue; + } - return $this->loginURL; - } - - public function setTimeoutValue($value) { - - $this->timeoutValue = $value; - } - - public function getTimeoutValue() { - - return $this->timeoutValue; - } - - public function setCurrentBrowser($value) { - - $this->currentBrowser = $value; - } - - public function getCurrentBrowser() { - - return $this->currentBrowser; - } + public function setCurrentBrowser($value) + { + $this->currentBrowser = $value; + } + public function getCurrentBrowser() + { + return $this->currentBrowser; + } } ?> From bc97f0665da14425559aed16acfaf9529a733fa8 Mon Sep 17 00:00:00 2001 From: Dieter Adriaenssens Date: Fri, 6 Apr 2012 17:44:49 +0200 Subject: [PATCH 2/5] wrap long lines --- server_status.php | 73 +++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/server_status.php b/server_status.php index ef663ce509..edeeade150 100644 --- a/server_status.php +++ b/server_status.php @@ -26,7 +26,9 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { switch($_REQUEST['type']) { // Process and Connections realtime chart case 'proc': - $c = PMA_DBI_fetch_result("SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1); + $c = PMA_DBI_fetch_result( + "SHOW GLOBAL STATUS WHERE Variable_name = 'Connections'", 0, 1 + ); $result = PMA_DBI_query('SHOW PROCESSLIST'); $num_procs = PMA_DBI_num_rows($result); @@ -106,7 +108,8 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { switch ($dataPoint['type']) { /* We only collect the status and server variables here to - * read them all in one query, and only afterwards assign them. + * read them all in one query, + * and only afterwards assign them. * Also do some white list filtering on the names */ case 'servervar': @@ -123,7 +126,8 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { case 'proc': $result = PMA_DBI_query('SHOW PROCESSLIST'); - $ret[$chart_id][$node_id][$point_id]['value'] = PMA_DBI_num_rows($result); + $ret[$chart_id][$node_id][$point_id]['value'] + = PMA_DBI_num_rows($result); break; case 'cpu': @@ -136,10 +140,13 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { } if (PHP_OS == 'Linux') { - $ret[$chart_id][$node_id][$point_id]['idle'] = $cpuload['idle']; - $ret[$chart_id][$node_id][$point_id]['busy'] = $cpuload['busy']; + $ret[$chart_id][$node_id][$point_id]['idle'] + = $cpuload['idle']; + $ret[$chart_id][$node_id][$point_id]['busy'] + = $cpuload['busy']; } else - $ret[$chart_id][$node_id][$point_id]['value'] = $cpuload['loadavg']; + $ret[$chart_id][$node_id][$point_id]['value'] + = $cpuload['loadavg']; break; @@ -152,7 +159,8 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $memory = $sysinfo->memory(); } - $ret[$chart_id][$node_id][$point_id]['value'] = $memory[$pName]; + $ret[$chart_id][$node_id][$point_id]['value'] + = $memory[$pName]; break; } /* switch */ } /* foreach */ @@ -185,10 +193,12 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { foreach ($nodeDataPoints as $point_id => $dataPoint) { switch($dataPoint['type']) { case 'statusvar': - $ret[$chart_id][$node_id][$point_id]['value'] = $statusVarValues[$dataPoint['name']]; + $ret[$chart_id][$node_id][$point_id]['value'] + = $statusVarValues[$dataPoint['name']]; break; case 'servervar': - $ret[$chart_id][$node_id][$point_id]['value'] = $serverVarValues[$dataPoint['name']]; + $ret[$chart_id][$node_id][$point_id]['value'] + = $serverVarValues[$dataPoint['name']]; break; } } @@ -211,10 +221,15 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $end = intval($_REQUEST['time_end']); if ($_REQUEST['type'] == 'slow') { - $q = 'SELECT start_time, user_host, Sec_to_Time(Sum(Time_to_Sec(query_time))) as query_time, Sec_to_Time(Sum(Time_to_Sec(lock_time))) as lock_time, '. - 'SUM(rows_sent) AS rows_sent, SUM(rows_examined) AS rows_examined, db, sql_text, COUNT(sql_text) AS \'#\' '. - 'FROM `mysql`.`slow_log` WHERE start_time > FROM_UNIXTIME(' . $start . ') '. - 'AND start_time < FROM_UNIXTIME(' . $end . ') GROUP BY sql_text'; + $q = 'SELECT start_time, user_host, '; + $q .= 'Sec_to_Time(Sum(Time_to_Sec(query_time))) as query_time, '; + $q .= 'Sec_to_Time(Sum(Time_to_Sec(lock_time))) as lock_time, '; + $q .= 'SUM(rows_sent) AS rows_sent, '; + $q .= 'SUM(rows_examined) AS rows_examined, db, sql_text, '; + $q .= 'COUNT(sql_text) AS \'#\' '; + $q .= 'FROM `mysql`.`slow_log` '; + $q .= 'WHERE start_time > FROM_UNIXTIME(' . $start . ') '; + $q .= 'AND start_time < FROM_UNIXTIME(' . $end . ') GROUP BY sql_text'; $result = PMA_DBI_try_query($q); @@ -222,17 +237,20 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $type = ''; while ($row = PMA_DBI_fetch_assoc($result)) { - $type = strtolower(substr($row['sql_text'], 0, strpos($row['sql_text'], ' '))); + $type = strtolower( + substr($row['sql_text'], 0, strpos($row['sql_text'], ' ')) + ); switch($type) { case 'insert': case 'update': - // Cut off big inserts and updates, but append byte count therefor + //Cut off big inserts and updates, but append byte count instead if (strlen($row['sql_text']) > 220) { + $implode_sql_text = implode( + ' ', PMA_formatByteDown(strlen($row['sql_text']), 2, 2) + ); $row['sql_text'] = substr($row['sql_text'], 0, 200) - . '... [' - . implode(' ', PMA_formatByteDown(strlen($row['sql_text']), 2, 2)) - . ']'; + . '... [' . $implode_sql_text . ']'; } break; default: @@ -256,12 +274,15 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { if ($_REQUEST['type'] == 'general') { $limitTypes = (isset($_REQUEST['limitTypes']) && $_REQUEST['limitTypes']) - ? 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ' : ''; + ? 'AND argument REGEXP \'^(INSERT|SELECT|UPDATE|DELETE)\' ' : ''; - $q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, server_id, argument, count(argument) as \'#\' '. - 'FROM `mysql`.`general_log` WHERE command_type=\'Query\' '. - 'AND event_time > FROM_UNIXTIME(' . $start . ') AND event_time < FROM_UNIXTIME(' . $end . ') '. - $limitTypes . 'GROUP by argument'; // HAVING count > 1'; + $q = 'SELECT TIME(event_time) as event_time, user_host, thread_id, '; + $q .= 'server_id, argument, count(argument) as \'#\' '; + $q .= 'FROM `mysql`.`general_log` '; + $q .= 'WHERE command_type=\'Query\' '; + $q .= 'AND event_time > FROM_UNIXTIME(' . $start . ') '; + $q .= 'AND event_time < FROM_UNIXTIME(' . $end . ') '; + $q .= $limitTypes . 'GROUP by argument'; // HAVING count > 1'; $result = PMA_DBI_try_query($q); @@ -270,7 +291,8 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { $insertTables = array(); $insertTablesFirst = -1; $i = 0; - $removeVars = isset($_REQUEST['removeVariables']) && $_REQUEST['removeVariables']; + $removeVars = isset($_REQUEST['removeVariables']) + && $_REQUEST['removeVariables']; while ($row = PMA_DBI_fetch_assoc($result)) { preg_match('/^(\w+)\s/', $row['argument'], $match); @@ -287,7 +309,8 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { if ($removeVars && preg_match('/^INSERT INTO (`|\'|"|)([^\s\\1]+)\\1/i', $row['argument'], $matches)) { $insertTables[$matches[2]]++; if ($insertTables[$matches[2]] > 1) { - $return['rows'][$insertTablesFirst]['#'] = $insertTables[$matches[2]]; + $return['rows'][$insertTablesFirst]['#'] + = $insertTables[$matches[2]]; // Add a ... to the end of this query to indicate that there's been other queries if ($return['rows'][$insertTablesFirst]['argument'][strlen($return['rows'][$insertTablesFirst]['argument'])-1] != '.') { From 193ea6e5bf02155db358a845adb93bdc6d3ef5b5 Mon Sep 17 00:00:00 2001 From: Dieter Adriaenssens Date: Fri, 6 Apr 2012 17:46:16 +0200 Subject: [PATCH 3/5] improve coding style --- server_status.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server_status.php b/server_status.php index edeeade150..ef395563e2 100644 --- a/server_status.php +++ b/server_status.php @@ -1507,7 +1507,7 @@ function printVariablesTable() From 76ce88555c2dbdfd4aecdc4929ac9b504f12d142 Mon Sep 17 00:00:00 2001 From: Dieter Adriaenssens Date: Fri, 6 Apr 2012 18:01:57 +0200 Subject: [PATCH 4/5] improve coding style --- tbl_alter.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tbl_alter.php b/tbl_alter.php index 8d219825bf..e1103abbc8 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -100,7 +100,9 @@ if (isset($_REQUEST['do_save_data'])) { $result = PMA_DBI_try_query($sql_query); if ($result !== false) { - $message = PMA_Message::success(__('Table %1$s has been altered successfully')); + $message = PMA_Message::success( + __('Table %1$s has been altered successfully') + ); $message->addParam($table); $btnDrop = 'Fake'; @@ -113,8 +115,10 @@ if (isset($_REQUEST['do_save_data'])) { if (isset($_REQUEST['field_orig']) && is_array($_REQUEST['field_orig'])) { foreach ($_REQUEST['field_orig'] as $fieldindex => $fieldcontent) { if ($_REQUEST['field_name'][$fieldindex] != $fieldcontent) { - PMA_REL_renameField($db, $table, $fieldcontent, - $_REQUEST['field_name'][$fieldindex]); + PMA_REL_renameField( + $db, $table, $fieldcontent, + $_REQUEST['field_name'][$fieldindex] + ); } } } @@ -125,11 +129,14 @@ if (isset($_REQUEST['do_save_data'])) { && $cfg['BrowseMIME']) { foreach ($_REQUEST['field_mimetype'] as $fieldindex => $mimetype) { if (isset($_REQUEST['field_name'][$fieldindex]) - && strlen($_REQUEST['field_name'][$fieldindex])) { - PMA_setMIME($db, $table, $_REQUEST['field_name'][$fieldindex], + && strlen($_REQUEST['field_name'][$fieldindex]) + ) { + PMA_setMIME( + $db, $table, $_REQUEST['field_name'][$fieldindex], $mimetype, $_REQUEST['field_transformation'][$fieldindex], - $_REQUEST['field_transformation_options'][$fieldindex]); + $_REQUEST['field_transformation_options'][$fieldindex] + ); } } } @@ -195,7 +202,10 @@ if ($abort == false) { // SHOW FULL COLUMNS says NULL and SHOW CREATE TABLE says NOT NULL (tested // in MySQL 4.0.25). - $show_create_table = PMA_DBI_fetch_value('SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), 0, 1); + $show_create_table = PMA_DBI_fetch_value( + 'SHOW CREATE TABLE ' . PMA_backquote($db) . '.' . PMA_backquote($table), + 0, 1 + ); $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); unset($show_create_table); /** From 091daa394466d40ea13ad8b9059e8c74cb5a04c5 Mon Sep 17 00:00:00 2001 From: Dieter Adriaenssens Date: Fri, 6 Apr 2012 18:08:43 +0200 Subject: [PATCH 5/5] clarify code --- tbl_alter.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tbl_alter.php b/tbl_alter.php index e1103abbc8..961a5a5e00 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -95,8 +95,16 @@ if (isset($_REQUEST['do_save_data'])) { // To allow replication, we first select the db to use and then run queries // on this db. - PMA_DBI_select_db($db) or PMA_mysqlDie(PMA_DBI_getError(), 'USE ' . PMA_backquote($db) . ';', '', $err_url); - $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ' . implode(', ', $changes) . $key_query; + if (! PMA_DBI_select_db($db)) { + PMA_mysqlDie( + PMA_DBI_getError(), + 'USE ' . PMA_backquote($db) . ';', + '', + $err_url + ); + } + $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' '; + $sql_query .= implode(', ', $changes) . $key_query; $result = PMA_DBI_try_query($sql_query); if ($result !== false) {