diff --git a/src/Model/Tag.php b/src/Model/Tag.php index 729ef0dd2..0ea19f55d 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 439024a4f..0cf5e2632 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 000000000..90ebd673f --- /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`)"]); + } +}