From 1b7781c8669ac98d656b57f4b540ef0fa818a94a Mon Sep 17 00:00:00 2001 From: plegall Date: Wed, 19 Jan 2011 13:19:16 +0000 Subject: feature 1289 added: easy "delete orphan tags" function. On the "tags" administration page, a warning message is displayed if you have at least one orphan tag + direct action to delete them. git-svn-id: http://piwigo.org/svn/trunk@8762 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/include/functions.php | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'admin/include/functions.php') diff --git a/admin/include/functions.php b/admin/include/functions.php index 6ad6bc7fe..91931cf4d 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -363,6 +363,54 @@ DELETE FROM '.USERS_TABLE.' trigger_action('delete_user', $user_id); } +/** + * Deletes all tags linked to no photo + */ +function delete_orphan_tags() +{ + $orphan_tags = get_orphan_tags(); + + if (count($orphan_tags) > 0) + { + $orphan_tag_ids = array(); + foreach ($orphan_tags as $tag) + { + array_push($orphan_tag_ids, $tag['id']); + } + + $query = ' +DELETE + FROM '.TAGS_TABLE.' + WHERE id IN ('.implode(',', $orphan_tag_ids).') +;'; + pwg_query($query); + } +} + +/** + * Get all tags (id + name) linked to no photo + */ +function get_orphan_tags() +{ + $orphan_tags = array(); + + $query = ' +SELECT + id, + name + FROM '.TAGS_TABLE.' + LEFT JOIN '.IMAGE_TAG_TABLE.' ON id = tag_id + WHERE tag_id IS NULL +;'; + $result = pwg_query($query); + while ($row = pwg_db_fetch_assoc($result)) + { + array_push($orphan_tags, $row); + } + + return $orphan_tags; +} + /** * Verifies that the representative picture really exists in the db and * picks up a random represantive if possible and based on config. -- cgit v1.2.3