Skip to content

Commit 880afc9

Browse files
Merge pull request #18718 from kamil-tekiela/deletebookmark60
Fix bookmark delete
2 parents 89835fb + 76278cd commit 880afc9

3 files changed

Lines changed: 17 additions & 14 deletions

File tree

src/Bookmark.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -267,20 +267,19 @@ public static function getList(
267267
/**
268268
* Retrieve a specific bookmark
269269
*
270-
* @param string $user Current user
271-
* @param DatabaseName $db the current database name
272-
* @param int|string $id an identifier of the bookmark to get
273-
* @param string $idField which field to look up the identifier
274-
* @param bool $actionBookmarkAll true: get all bookmarks regardless
275-
* of the owning user
276-
* @param bool $exactUserMatch whether to ignore bookmarks with no user
270+
* @param string $user Current user
271+
* @param DatabaseName|null $db the current database name
272+
* @param int|string $id an identifier of the bookmark to get
273+
* @param string $idField which field to look up the identifier
274+
* @param bool $actionBookmarkAll true: get all bookmarks regardless of the owning user
275+
* @param bool $exactUserMatch whether to ignore bookmarks with no user
277276
*
278277
* @return Bookmark|null the bookmark
279278
*/
280279
public static function get(
281280
DatabaseInterface $dbi,
282281
string $user,
283-
DatabaseName $db,
282+
DatabaseName|null $db,
284283
int|string $id,
285284
string $idField = 'id',
286285
bool $actionBookmarkAll = false,
@@ -298,7 +297,12 @@ public static function get(
298297

299298
$query = 'SELECT * FROM ' . Util::backquote($bookmarkFeature->database)
300299
. '.' . Util::backquote($bookmarkFeature->bookmark)
301-
. ' WHERE dbase = ' . $dbi->quoteString($db->getName());
300+
. ' WHERE ' . Util::backquote($idField)
301+
. ' = ' . $dbi->quoteString((string) $id);
302+
if ($db !== null) {
303+
$query .= ' AND dbase = ' . $dbi->quoteString($db->getName());
304+
}
305+
302306
if (! $actionBookmarkAll) {
303307
$query .= ' AND (user = ' . $dbi->quoteString($user);
304308
if (! $exactUserMatch) {
@@ -308,8 +312,7 @@ public static function get(
308312
$query .= ')';
309313
}
310314

311-
$query .= ' AND ' . Util::backquote($idField)
312-
. ' = ' . $dbi->quoteString((string) $id) . ' LIMIT 1';
315+
$query .= ' LIMIT 1';
313316

314317
$result = $dbi->fetchSingleRow($query, DatabaseInterface::FETCH_ASSOC, Connection::TYPE_CONTROL);
315318
if ($result !== null) {

src/Controllers/Import/ImportController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ public function __invoke(ServerRequest $request): void
377377
$bookmark = Bookmark::get(
378378
$this->dbi,
379379
$config->selectedServer['user'],
380-
DatabaseName::from($GLOBALS['db']),
380+
DatabaseName::tryFrom($GLOBALS['db']),
381381
$idBookmark,
382382
);
383383
if (! $bookmark instanceof Bookmark) {

test/classes/Stubs/DbiDummy.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,8 +1745,8 @@ private function init(): void
17451745
['query' => 'SELECT LAST_INSERT_ID();', 'result' => []],
17461746
['query' => 'SHOW WARNINGS', 'result' => []],
17471747
[
1748-
'query' => 'SELECT * FROM `information_schema`.`bookmark` WHERE dbase = \'my_db\''
1749-
. ' AND (user = \'user\') AND `label` = \'test_tbl\' LIMIT 1',
1748+
'query' => 'SELECT * FROM `information_schema`.`bookmark` WHERE `label` = \'test_tbl\''
1749+
. ' AND dbase = \'my_db\' AND (user = \'user\') LIMIT 1',
17501750
'result' => [],
17511751
],
17521752
[

0 commit comments

Comments
 (0)