Skip to content

Commit

Permalink
Merge pull request #17806 from sivadasrajan/refactoring-db-table
Browse files Browse the repository at this point in the history
Refactored Bookmark::get() for DatabaseName
  • Loading branch information
MauricioFauth committed Oct 21, 2022
2 parents ada0151 + 1265614 commit b25dc24
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
7 changes: 4 additions & 3 deletions libraries/classes/Bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use PhpMyAdmin\ConfigStorage\Features\BookmarkFeature;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Dbal\DatabaseName;

use function count;
use function preg_match_all;
Expand Down Expand Up @@ -275,7 +276,7 @@ public static function getList(
*
* @param DatabaseInterface $dbi DatabaseInterface object
* @param string $user Current user
* @param string $db the current database name
* @param DatabaseName $db the current database name
* @param int|string $id an identifier of the bookmark to get
* @param string $id_field which field to look up the identifier
* @param bool $action_bookmark_all true: get all bookmarks regardless
Expand All @@ -287,7 +288,7 @@ public static function getList(
public static function get(
DatabaseInterface $dbi,
string $user,
string $db,
DatabaseName $db,
$id,
string $id_field = 'id',
bool $action_bookmark_all = false,
Expand All @@ -301,7 +302,7 @@ public static function get(

$query = 'SELECT * FROM ' . Util::backquote($bookmarkFeature->database)
. '.' . Util::backquote($bookmarkFeature->bookmark)
. " WHERE dbase = '" . $dbi->escapeString($db) . "'";
. " WHERE dbase = '" . $dbi->escapeString($db->getName()) . "'";
if (! $action_bookmark_all) {
$query .= " AND (user = '"
. $dbi->escapeString($user) . "'";
Expand Down
7 changes: 4 additions & 3 deletions libraries/classes/Controllers/Import/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\DatabaseName;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\File;
use PhpMyAdmin\Html\Generator;
Expand Down Expand Up @@ -332,7 +333,7 @@ public function __invoke(ServerRequest $request): void
$bookmark = Bookmark::get(
$this->dbi,
$GLOBALS['cfg']['Server']['user'],
$GLOBALS['db'],
DatabaseName::fromValue($GLOBALS['db']),
$id_bookmark,
'id',
isset($_POST['action_bookmark_all'])
Expand Down Expand Up @@ -363,7 +364,7 @@ public function __invoke(ServerRequest $request): void
$bookmark = Bookmark::get(
$this->dbi,
$GLOBALS['cfg']['Server']['user'],
$GLOBALS['db'],
DatabaseName::fromValue($GLOBALS['db']),
$id_bookmark
);
if (! $bookmark instanceof Bookmark) {
Expand All @@ -388,7 +389,7 @@ public function __invoke(ServerRequest $request): void
$bookmark = Bookmark::get(
$this->dbi,
$GLOBALS['cfg']['Server']['user'],
$GLOBALS['db'],
DatabaseName::fromValue($GLOBALS['db']),
$id_bookmark
);
if (! $bookmark instanceof Bookmark) {
Expand Down
3 changes: 2 additions & 1 deletion libraries/classes/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpMyAdmin\ConfigStorage\Features\BookmarkFeature;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\ConfigStorage\RelationCleanup;
use PhpMyAdmin\Dbal\DatabaseName;
use PhpMyAdmin\Dbal\ResultInterface;
use PhpMyAdmin\Display\DisplayParts;
use PhpMyAdmin\Display\Results as DisplayResults;
Expand Down Expand Up @@ -481,7 +482,7 @@ public function findRealEndOfRows($db, $table)
*/
public function getDefaultSqlQueryForBrowse($db, $table): string
{
$bookmark = Bookmark::get($this->dbi, $GLOBALS['cfg']['Server']['user'], $db, $table, 'label', false, true);
$bookmark = Bookmark::get($this->dbi, $GLOBALS['cfg']['Server']['user'], DatabaseName::fromValue($db), $table, 'label', false, true);

if ($bookmark !== null && $bookmark->getQuery() !== '') {
$GLOBALS['using_bookmark_message'] = Message::notice(
Expand Down
2 changes: 1 addition & 1 deletion test/classes/BookmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testGet(): void
Bookmark::get(
$GLOBALS['dbi'],
$GLOBALS['cfg']['Server']['user'],
'phpmyadmin',
DatabaseName::fromValue('phpmyadmin'),
'1'
)
);
Expand Down

0 comments on commit b25dc24

Please sign in to comment.