aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2011-01-19 13:19:16 +0000
committerplegall <plg@piwigo.org>2011-01-19 13:19:16 +0000
commit1b7781c8669ac98d656b57f4b540ef0fa818a94a (patch)
tree47a7db98b607a4ee477b77df56e8d54576a8566a /admin/include
parente338363331de40ce04b70d7936cb901f52f88fe0 (diff)
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
Diffstat (limited to 'admin/include')
-rw-r--r--admin/include/functions.php48
1 files changed, 48 insertions, 0 deletions
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
@@ -364,6 +364,54 @@ DELETE FROM '.USERS_TABLE.'
}
/**
+ * 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.
*