mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-02-07 06:54:15 +01:00
Prevent rename tag failing on uniq violation
This commit is contained in:
parent
e75a0174a7
commit
f88a1a1673
@ -131,13 +131,16 @@ class OC_Bookmarks_Bookmarks{
|
|||||||
public static function renameTag($old, $new)
|
public static function renameTag($old, $new)
|
||||||
{
|
{
|
||||||
$user_id = OCP\USER::getUser();
|
$user_id = OCP\USER::getUser();
|
||||||
|
$CONFIG_DBTYPE = OCP\Config::getSystemValue( 'dbtype', 'sqlite' );
|
||||||
|
|
||||||
// Update the record
|
|
||||||
|
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
|
||||||
|
// Update tags to the new label unless it already exists a tag like this
|
||||||
$query = OCP\DB::prepare("
|
$query = OCP\DB::prepare("
|
||||||
UPDATE *PREFIX*bookmarks_tags SET
|
UPDATE OR REPLACE *PREFIX*bookmarks_tags
|
||||||
tag = ?
|
SET tag = ?
|
||||||
WHERE tag = ?
|
WHERE tag = ?
|
||||||
AND exists( select id from *PREFIX*bookmarks where user_id = ? and bookmark_id = id)
|
AND exists( select b.id from *PREFIX*bookmarks b where b.user_id = ? and bookmark_id = b.id)
|
||||||
");
|
");
|
||||||
|
|
||||||
$params=array(
|
$params=array(
|
||||||
@ -147,6 +150,41 @@ class OC_Bookmarks_Bookmarks{
|
|||||||
);
|
);
|
||||||
|
|
||||||
$result = $query->execute($params);
|
$result = $query->execute($params);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Remove potentialy duplicated tags
|
||||||
|
$query = OCP\DB::prepare("
|
||||||
|
DELETE FROM *PREFIX*bookmarks_tags as tgs where tgs.tag = ?
|
||||||
|
AND exists( select id from *PREFIX*bookmarks where user_id = ? and tgs.bookmark_id = id)
|
||||||
|
AND exists( select t.tag from *PREFIX*bookmarks_tags t where t.tag=? and tgs.bookmark_id = tbookmark_id");
|
||||||
|
|
||||||
|
$params=array(
|
||||||
|
$new,
|
||||||
|
$user_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $query->execute($params);
|
||||||
|
|
||||||
|
|
||||||
|
// Update tags to the new label unless it already exists a tag like this
|
||||||
|
$query = OCP\DB::prepare("
|
||||||
|
UPDATE *PREFIX*bookmarks_tags
|
||||||
|
SET tag = ?
|
||||||
|
WHERE tag = ?
|
||||||
|
AND exists( select b.id from *PREFIX*bookmarks b where b.user_id = ? and bookmark_id = b.id)
|
||||||
|
");
|
||||||
|
|
||||||
|
$params=array(
|
||||||
|
$new,
|
||||||
|
$old,
|
||||||
|
$user_id,
|
||||||
|
$old,
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $query->execute($params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user