diff --git a/ChangeLog b/ChangeLog index cbc6d17255..01218e8194 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,7 @@ phpMyAdmin - ChangeLog + rfe #844 Structure in PDF export + rfe #1635 Have ZeroConf create phpmyadmin DB if possible + rfe #763 Warning before silent data conversion/truncation ++ rfe #1650 Support a default page in designer 4.4.2.0 (not yet released) - bug #4835 PMA_hideShowConnection not called after submit_num_fields diff --git a/db_designer.php b/db_designer.php index 93aa502495..23d5a3fb6c 100644 --- a/db_designer.php +++ b/db_designer.php @@ -97,7 +97,7 @@ if (! isset($_REQUEST['query'])) { if (! empty($_REQUEST['page'])) { $display_page = $_REQUEST['page']; } else { - $display_page = PMA_getFirstPage($_REQUEST['db']); + $display_page = PMA_getDefaultPage($_REQUEST['db']); } } if ($display_page != -1) { diff --git a/libraries/pmd_common.php b/libraries/pmd_common.php index 19f492c056..7829bf74ec 100644 --- a/libraries/pmd_common.php +++ b/libraries/pmd_common.php @@ -335,32 +335,57 @@ function PMA_deletePage($pg) } /** - * Returns the id of the first pdf page of the database + * Returns the id of the default pdf page of the database. + * Default page is the one which has the same name as the database. + * If no such exists, returns the id of the first page of the database. * * @param string $db database * * @return int id of the first pdf page, default is -1 */ -function PMA_getFirstPage($db) +function PMA_getDefaultPage($db) { $cfgRelation = PMA_getRelationsParam(); if (! $cfgRelation['pdfwork']) { return null; } - $query = "SELECT MIN(`page_nr`)" + $page_no = -1; + + $query = "SELECT `page_nr`" . " FROM " . PMA_Util::backquote($cfgRelation['db']) . "." . PMA_Util::backquote($cfgRelation['pdf_pages']) - . " WHERE `db_name` = '" . $db . "'"; + . " WHERE `db_name` = '" . PMA_Util::sqlAddSlashes($db) . "'" + . " AND `page_descr` = '" . PMA_Util::sqlAddSlashes($db) . "'"; - $min_page_no = $GLOBALS['dbi']->fetchResult( + $default_page_no = $GLOBALS['dbi']->fetchResult( $query, null, null, $GLOBALS['controllink'], PMA_DatabaseInterface::QUERY_STORE ); - return count($min_page_no[0]) ? $min_page_no[0] : -1; + + if (count($default_page_no)) { + $page_no = $default_page_no[0]; + } else { + $query = "SELECT MIN(`page_nr`)" + . " FROM " . PMA_Util::backquote($cfgRelation['db']) + . "." . PMA_Util::backquote($cfgRelation['pdf_pages']) + . " WHERE `db_name` = '" . PMA_Util::sqlAddSlashes($db) . "'"; + + $min_page_no = $GLOBALS['dbi']->fetchResult( + $query, + null, + null, + $GLOBALS['controllink'], + PMA_DatabaseInterface::QUERY_STORE + ); + if (count($min_page_no[0])) { + $page_no = $min_page_no[0]; + } + } + return $page_no; } /** diff --git a/test/libraries/PMA_PMD_common_test.php b/test/libraries/PMA_PMD_common_test.php index b8c1b440be..30994bf990 100644 --- a/test/libraries/PMA_PMD_common_test.php +++ b/test/libraries/PMA_PMD_common_test.php @@ -148,20 +148,66 @@ class PMA_PMD_CommonTest extends PHPUnit_Framework_TestCase } /** - * Test for PMA_getFirstPage() + * Test for testGetDefaultPage() when there is a default page + * (a page having the same name as database) * * @return void */ - public function testGetFirstPage() + public function testGetDefaultPage() { $db = 'db'; - $pg = '1'; + $default_pg = '2'; $dbi = $this->getMockBuilder('PMA_DatabaseInterface') ->disableOriginalConstructor() ->getMock(); $dbi->expects($this->at(0)) + ->method('fetchResult') + ->with( + "SELECT `page_nr` FROM `pmadb`.`pdf_pages`" + . " WHERE `db_name` = '" . $db . "'" + . " AND `page_descr` = '" . $db. "'", + null, + null, + 2, + PMA_DatabaseInterface::QUERY_STORE + ) + ->will($this->returnValue(array($default_pg))); + $GLOBALS['dbi'] = $dbi; + + $result = PMA_getDefaultPage($db); + $this->assertEquals($default_pg, $result); + } + + /** + * Test for testGetDefaultPage() when there is no default page + * + * @return void + */ + public function testGetDefaultPageWithNoDefaultPage() + { + $db = 'db'; + $first_pg = '1'; + + $dbi = $this->getMockBuilder('PMA_DatabaseInterface') + ->disableOriginalConstructor() + ->getMock(); + + $dbi->expects($this->at(0)) + ->method('fetchResult') + ->with( + "SELECT `page_nr` FROM `pmadb`.`pdf_pages`" + . " WHERE `db_name` = '" . $db . "'" + . " AND `page_descr` = '" . $db. "'", + null, + null, + 2, + PMA_DatabaseInterface::QUERY_STORE + ) + ->will($this->returnValue(array())); + + $dbi->expects($this->at(1)) ->method('fetchResult') ->with( "SELECT MIN(`page_nr`) FROM `pmadb`.`pdf_pages`" @@ -171,12 +217,11 @@ class PMA_PMD_CommonTest extends PHPUnit_Framework_TestCase 2, PMA_DatabaseInterface::QUERY_STORE ) - ->will($this->returnValue(array($pg))); + ->will($this->returnValue(array($first_pg))); $GLOBALS['dbi'] = $dbi; - $result = PMA_getFirstPage($db); - - $this->assertEquals($pg, $result); + $result = PMA_getDefaultPage($db); + $this->assertEquals($first_pg, $result); } } ?> \ No newline at end of file