diff --git a/src/Model/Tag.php b/src/Model/Tag.php index 729ef0dd2b..0ea19f55d9 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -201,7 +201,7 @@ class Tag } } - 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]); } diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index 439024a4f6..0cf5e26323 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -112,6 +112,8 @@ class Cron Worker::add(PRIORITY_LOW, 'ExpireConversations'); + Worker::add(PRIORITY_LOW, 'RemoveUnusedTags'); + Worker::add(PRIORITY_LOW, 'RemoveUnusedContacts'); Worker::add(PRIORITY_LOW, 'RemoveUnusedAvatars'); diff --git a/src/Worker/RemoveUnusedTags.php b/src/Worker/RemoveUnusedTags.php new file mode 100644 index 0000000000..90ebd673fc --- /dev/null +++ b/src/Worker/RemoveUnusedTags.php @@ -0,0 +1,35 @@ +. + * + */ + +namespace Friendica\Worker; + +use Friendica\Database\DBA; + +class RemoveUnusedTags +{ + /** + * Delete tag entries that aren't used anymore + */ + public static function execute() + { + DBA::delete('tag', ["NOT `id` IN (SELECT `tid` FROM `post-category`) AND NOT `id` IN (SELECT `tid` FROM `post-tag`)"]); + } +}