Merge pull request #17806 from sivadasrajan/refactoring-db-table

Refactored Bookmark::get() for DatabaseName
This commit is contained in:
Maurício Meneghini Fauth 2022-10-20 21:57:43 -03:00 committed by GitHub
commit b25dc2426e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 8 deletions

View File

@ -9,6 +9,7 @@ namespace PhpMyAdmin;
use PhpMyAdmin\ConfigStorage\Features\BookmarkFeature;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Dbal\DatabaseName;
use function count;
use function preg_match_all;
@ -275,7 +276,7 @@ class Bookmark
*
* @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
@ -287,7 +288,7 @@ class Bookmark
public static function get(
DatabaseInterface $dbi,
string $user,
string $db,
DatabaseName $db,
$id,
string $id_field = 'id',
bool $action_bookmark_all = false,
@ -301,7 +302,7 @@ class Bookmark
$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) . "'";

View File

@ -9,6 +9,7 @@ use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Core;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Dbal\DatabaseName;
use PhpMyAdmin\Encoding;
use PhpMyAdmin\File;
use PhpMyAdmin\Html\Generator;
@ -332,7 +333,7 @@ final class ImportController extends AbstractController
$bookmark = Bookmark::get(
$this->dbi,
$GLOBALS['cfg']['Server']['user'],
$GLOBALS['db'],
DatabaseName::fromValue($GLOBALS['db']),
$id_bookmark,
'id',
isset($_POST['action_bookmark_all'])
@ -363,7 +364,7 @@ final class ImportController extends AbstractController
$bookmark = Bookmark::get(
$this->dbi,
$GLOBALS['cfg']['Server']['user'],
$GLOBALS['db'],
DatabaseName::fromValue($GLOBALS['db']),
$id_bookmark
);
if (! $bookmark instanceof Bookmark) {
@ -388,7 +389,7 @@ final class ImportController extends AbstractController
$bookmark = Bookmark::get(
$this->dbi,
$GLOBALS['cfg']['Server']['user'],
$GLOBALS['db'],
DatabaseName::fromValue($GLOBALS['db']),
$id_bookmark
);
if (! $bookmark instanceof Bookmark) {

View File

@ -7,6 +7,7 @@ namespace PhpMyAdmin;
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;
@ -481,7 +482,7 @@ class Sql
*/
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(

View File

@ -71,7 +71,7 @@ class BookmarkTest extends AbstractTestCase
Bookmark::get(
$GLOBALS['dbi'],
$GLOBALS['cfg']['Server']['user'],
'phpmyadmin',
DatabaseName::fromValue('phpmyadmin'),
'1'
)
);