Skip to content

Commit b25dc24

Browse files
Merge pull request #17806 from sivadasrajan/refactoring-db-table
Refactored Bookmark::get() for DatabaseName
2 parents ada0151 + 1265614 commit b25dc24

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

libraries/classes/Bookmark.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use PhpMyAdmin\ConfigStorage\Features\BookmarkFeature;
1111
use PhpMyAdmin\ConfigStorage\Relation;
12+
use PhpMyAdmin\Dbal\DatabaseName;
1213

1314
use function count;
1415
use function preg_match_all;
@@ -275,7 +276,7 @@ public static function getList(
275276
*
276277
* @param DatabaseInterface $dbi DatabaseInterface object
277278
* @param string $user Current user
278-
* @param string $db the current database name
279+
* @param DatabaseName $db the current database name
279280
* @param int|string $id an identifier of the bookmark to get
280281
* @param string $id_field which field to look up the identifier
281282
* @param bool $action_bookmark_all true: get all bookmarks regardless
@@ -287,7 +288,7 @@ public static function getList(
287288
public static function get(
288289
DatabaseInterface $dbi,
289290
string $user,
290-
string $db,
291+
DatabaseName $db,
291292
$id,
292293
string $id_field = 'id',
293294
bool $action_bookmark_all = false,
@@ -301,7 +302,7 @@ public static function get(
301302

302303
$query = 'SELECT * FROM ' . Util::backquote($bookmarkFeature->database)
303304
. '.' . Util::backquote($bookmarkFeature->bookmark)
304-
. " WHERE dbase = '" . $dbi->escapeString($db) . "'";
305+
. " WHERE dbase = '" . $dbi->escapeString($db->getName()) . "'";
305306
if (! $action_bookmark_all) {
306307
$query .= " AND (user = '"
307308
. $dbi->escapeString($user) . "'";

libraries/classes/Controllers/Import/ImportController.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PhpMyAdmin\Controllers\AbstractController;
1010
use PhpMyAdmin\Core;
1111
use PhpMyAdmin\DatabaseInterface;
12+
use PhpMyAdmin\Dbal\DatabaseName;
1213
use PhpMyAdmin\Encoding;
1314
use PhpMyAdmin\File;
1415
use PhpMyAdmin\Html\Generator;
@@ -332,7 +333,7 @@ public function __invoke(ServerRequest $request): void
332333
$bookmark = Bookmark::get(
333334
$this->dbi,
334335
$GLOBALS['cfg']['Server']['user'],
335-
$GLOBALS['db'],
336+
DatabaseName::fromValue($GLOBALS['db']),
336337
$id_bookmark,
337338
'id',
338339
isset($_POST['action_bookmark_all'])
@@ -363,7 +364,7 @@ public function __invoke(ServerRequest $request): void
363364
$bookmark = Bookmark::get(
364365
$this->dbi,
365366
$GLOBALS['cfg']['Server']['user'],
366-
$GLOBALS['db'],
367+
DatabaseName::fromValue($GLOBALS['db']),
367368
$id_bookmark
368369
);
369370
if (! $bookmark instanceof Bookmark) {
@@ -388,7 +389,7 @@ public function __invoke(ServerRequest $request): void
388389
$bookmark = Bookmark::get(
389390
$this->dbi,
390391
$GLOBALS['cfg']['Server']['user'],
391-
$GLOBALS['db'],
392+
DatabaseName::fromValue($GLOBALS['db']),
392393
$id_bookmark
393394
);
394395
if (! $bookmark instanceof Bookmark) {

libraries/classes/Sql.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpMyAdmin\ConfigStorage\Features\BookmarkFeature;
88
use PhpMyAdmin\ConfigStorage\Relation;
99
use PhpMyAdmin\ConfigStorage\RelationCleanup;
10+
use PhpMyAdmin\Dbal\DatabaseName;
1011
use PhpMyAdmin\Dbal\ResultInterface;
1112
use PhpMyAdmin\Display\DisplayParts;
1213
use PhpMyAdmin\Display\Results as DisplayResults;
@@ -481,7 +482,7 @@ public function findRealEndOfRows($db, $table)
481482
*/
482483
public function getDefaultSqlQueryForBrowse($db, $table): string
483484
{
484-
$bookmark = Bookmark::get($this->dbi, $GLOBALS['cfg']['Server']['user'], $db, $table, 'label', false, true);
485+
$bookmark = Bookmark::get($this->dbi, $GLOBALS['cfg']['Server']['user'], DatabaseName::fromValue($db), $table, 'label', false, true);
485486

486487
if ($bookmark !== null && $bookmark->getQuery() !== '') {
487488
$GLOBALS['using_bookmark_message'] = Message::notice(

test/classes/BookmarkTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testGet(): void
7171
Bookmark::get(
7272
$GLOBALS['dbi'],
7373
$GLOBALS['cfg']['Server']['user'],
74-
'phpmyadmin',
74+
DatabaseName::fromValue('phpmyadmin'),
7575
'1'
7676
)
7777
);

0 commit comments

Comments
 (0)