Changeset 8762 for trunk/admin/include


Ignore:
Timestamp:
Jan 19, 2011, 2:19:16 PM (13 years ago)
Author:
plg
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r8734 r8762  
    362362
    363363  trigger_action('delete_user', $user_id);
     364}
     365
     366/**
     367 * Deletes all tags linked to no photo
     368 */
     369function delete_orphan_tags()
     370{
     371  $orphan_tags = get_orphan_tags();
     372 
     373  if (count($orphan_tags) > 0)
     374  {
     375    $orphan_tag_ids = array();
     376    foreach ($orphan_tags as $tag)
     377    {
     378      array_push($orphan_tag_ids, $tag['id']);
     379    }
     380
     381    $query = '
     382DELETE
     383  FROM '.TAGS_TABLE.'
     384  WHERE id IN ('.implode(',', $orphan_tag_ids).')
     385;';
     386    pwg_query($query);
     387  }
     388}
     389
     390/**
     391 * Get all tags (id + name) linked to no photo
     392 */
     393function get_orphan_tags()
     394{
     395  $orphan_tags = array();
     396 
     397  $query = '
     398SELECT
     399    id,
     400    name
     401  FROM '.TAGS_TABLE.'
     402    LEFT JOIN '.IMAGE_TAG_TABLE.' ON id = tag_id
     403  WHERE tag_id IS NULL
     404;';
     405  $result = pwg_query($query);
     406  while ($row = pwg_db_fetch_assoc($result))
     407  {
     408    array_push($orphan_tags, $row);
     409  }
     410
     411  return $orphan_tags;
    364412}
    365413
Note: See TracChangeset for help on using the changeset viewer.