rfe #1650 Support a default page in designer
Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
This commit is contained in:
parent
cc14618310
commit
1c52bc2a81
@ -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
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user