Fix adding / removing photo tags + tagrm delete via GET + Item::update / add Term::deleteAllTags
This commit is contained in:
@@ -816,7 +816,7 @@ class Item extends BaseObject
|
||||
$tags = $fields['tag'];
|
||||
$fields['tag'] = null;
|
||||
} else {
|
||||
$tags = '';
|
||||
$tags = null;
|
||||
}
|
||||
|
||||
if (array_key_exists('file', $fields)) {
|
||||
@@ -895,10 +895,14 @@ class Item extends BaseObject
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($tags)) {
|
||||
Term::insertFromTagFieldByItemId($item['id'], $tags);
|
||||
if (!empty($item['tag'])) {
|
||||
DBA::update('item', ['tag' => ''], ['id' => $item['id']]);
|
||||
if (!is_null($tags)) {
|
||||
Term::deleteAllTags($item['id']);
|
||||
|
||||
if ($tags) {
|
||||
Term::insertFromTagFieldByItemId($item['id'], $tags);
|
||||
if (!empty($item['tag'])) {
|
||||
DBA::update('item', ['tag' => ''], ['id' => $item['id']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -290,4 +290,19 @@ class Term
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Deletes all Tags from an item
|
||||
*/
|
||||
public static function deleteAllTags($itemid)
|
||||
{
|
||||
$message = Item::selectFirst(['id'], ['id' => $itemid]);
|
||||
if (!DBA::isResult($message)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean up all tags
|
||||
DBA::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user