}
}
- if (!empty($target) && !empty($tag['url']) && empty($tag['type'])) {
+ if (!empty($target) && !empty($tag['url']) && ($tag['type'] != $target)) {
DBA::update('tag', ['type' => $target], ['url' => $url]);
}
{
$fields = ['name' => substr($name, 0, 96), 'url' => $url];
- if (!empty($type)) {
- $fields['type'] = $type;
- }
-
- $tag = DBA::selectFirst('tag', ['id'], $fields);
+ $tag = DBA::selectFirst('tag', ['id', 'type'], $fields);
if (DBA::isResult($tag)) {
+ if (empty($tag['type']) && !empty($type)) {
+ DBA::update('tag', ['type' => $type], $fields);
+ }
return $tag['id'];
}
+ if (!empty($type)) {
+ $fields['type'] = $type;
+ }
+
DBA::insert('tag', $fields, Database::INSERT_IGNORE);
$tid = DBA::lastInsertId();
if (!empty($tid)) {