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
This commit is contained in:
plegall
2011-01-19 13:19:16 +00:00
parent e338363331
commit 1b7781c866
8 changed files with 116 additions and 7 deletions
+48
View File
@@ -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.