Clean up Tag::resetIdAsset

This commit is contained in:
Aaron van Geffen 2023-03-11 21:41:23 +01:00
parent aa3a54f237
commit 1b7e745f11

View File

@ -313,8 +313,7 @@ class Tag
public function resetIdAsset() public function resetIdAsset()
{ {
$db = Registry::get('db'); $db = Registry::get('db');
$new_id = $db->queryValue('
$row = $db->query('
SELECT MAX(id_asset) as new_id SELECT MAX(id_asset) as new_id
FROM assets_tags FROM assets_tags
WHERE id_tag = {int:id_tag}', WHERE id_tag = {int:id_tag}',
@ -322,18 +321,12 @@ class Tag
'id_tag' => $this->id_tag, 'id_tag' => $this->id_tag,
]); ]);
$new_id = 0;
if(!empty($row))
{
$new_id = $row->fetch_assoc()['new_id'];
}
return $db->query(' return $db->query('
UPDATE tags UPDATE tags
SET id_asset_thumb = {int:new_id} SET id_asset_thumb = {int:new_id}
WHERE id_tag = {int:id_tag}', WHERE id_tag = {int:id_tag}',
[ [
'new_id' => $new_id, 'new_id' => $new_id ?? 0,
'id_tag' => $this->id_tag, 'id_tag' => $this->id_tag,
]); ]);
} }