Changeset 8762


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.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin.php

    r8756 r8762  
    9292$page['errors'] = array();
    9393$page['infos']  = array();
     94$page['warnings']  = array();
    9495
    9596if (isset($_SESSION['page_infos']))
     
    177178}
    178179
     180if (count($page['warnings']) != 0)
     181{
     182  $template->assign('warnings', $page['warnings']);
     183}
     184
    179185// Add the Piwigo Official menu
    180186  $template->assign( 'pwgmenu', pwg_URL() );
  • 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
  • trunk/admin/maintenance.php

    r8728 r8762  
    5454    update_path();
    5555    update_average_rate();
     56    break;
     57  }
     58  case 'delete_orphan_tags' :
     59  {
     60    delete_orphan_tags();
    5661    break;
    5762  }
     
    134139    'U_MAINT_CATEGORIES' => $start_url.'categories',
    135140    'U_MAINT_IMAGES' => $start_url.'images',
     141    'U_MAINT_ORPHAN_TAGS' => $start_url.'delete_orphan_tags',
    136142    'U_MAINT_HISTORY_DETAIL' => $start_url.'history_detail',
    137143    'U_MAINT_HISTORY_SUMMARY' => $start_url.'history_summary',
     
    140146    'U_MAINT_DATABASE' => $start_url.'database',
    141147    'U_MAINT_C13Y' => $start_url.'c13y',
    142         'U_MAINT_SEARCH' => $start_url.'search',
     148    'U_MAINT_SEARCH' => $start_url.'search',
    143149    'U_MAINT_COMPILED_TEMPLATES' => $start_url.'compiled-templates',
    144150    'U_HELP' => get_root_url().'admin/popuphelp.php?page=maintenance',
  • trunk/admin/tags.php

    r8728 r8762  
    139139
    140140// +-----------------------------------------------------------------------+
     141// |                           delete orphan tags                          |
     142// +-----------------------------------------------------------------------+
     143
     144if (isset($_GET['action']) and 'delete_orphans' == $_GET['action'])
     145{
     146  check_pwg_token();
     147 
     148  delete_orphan_tags();
     149  $_SESSION['page_infos'] = array(l10n('Orphan tags deleted'));
     150  redirect(get_root_url().'admin.php?page=tags');
     151}
     152
     153// +-----------------------------------------------------------------------+
    141154// |                               add a tag                               |
    142155// +-----------------------------------------------------------------------+
     
    201214
    202215// +-----------------------------------------------------------------------+
     216// |                              orphan tags                              |
     217// +-----------------------------------------------------------------------+
     218
     219$orphan_tags = get_orphan_tags();
     220
     221$orphan_tag_names = array();
     222foreach ($orphan_tags as $tag)
     223{
     224  array_push($orphan_tag_names, $tag['name']);
     225}
     226
     227if (count($orphan_tag_names) > 0)
     228{
     229  array_push(
     230    $page['warnings'],
     231    sprintf(
     232      l10n('You have %d orphan tags: %s.').' <a href="%s">'.l10n('Delete orphan tags').'</a>',
     233      count($orphan_tag_names),
     234      implode(', ', $orphan_tag_names),
     235      get_root_url().'admin.php?page=tags&amp;action=delete_orphans&amp;pwg_token='.get_pwg_token()
     236      )
     237    );
     238}
     239
     240// +-----------------------------------------------------------------------+
    203241// |                             form creation                             |
    204242// +-----------------------------------------------------------------------+
  • trunk/admin/themes/default/template/admin.tpl

    r8665 r8762  
    127127  {/if}
    128128
     129  {if isset($warnings)}
     130  <div class="warnings">
     131    <ul>
     132      {foreach from=$warnings item=warning}
     133      <li>{$warning}</li>
     134      {/foreach}
     135    </ul>
     136  </div>
     137  {/if}
     138
    129139  {$ADMIN_CONTENT}
    130140</div>
  • trunk/admin/themes/default/template/maintenance.tpl

    r8723 r8762  
    1212  <li><a href="{$U_MAINT_CATEGORIES}">{'Update albums informations'|@translate}</a></li>
    1313  <li><a href="{$U_MAINT_IMAGES}">{'Update photos information'|@translate}</a></li>
     14  <li><a href="{$U_MAINT_ORPHAN_TAGS}">{'Delete orphan tags'|@translate}</a></li>
    1415  <li><a href="{$U_MAINT_DATABASE}">{'Repair and optimize database'|@translate}</a></li>
    15 </ul>
    16 
    17 <ul>
    1816  <li><a href="{$U_MAINT_HISTORY_DETAIL}" onclick="return confirm('{'Purge history detail'|@translate}');">{'Purge history detail'|@translate}</a></li>
    1917  <li><a href="{$U_MAINT_HISTORY_SUMMARY}" onclick="return confirm('{'Purge history summary'|@translate}');">{'Purge history summary'|@translate}</a></li>
     
    2220  <li><a href="{$U_MAINT_SEARCH}"onclick="return confirm('{'Purge search history'|@translate}');">{'Purge search history'|@translate}</a></li>
    2321  <li><a href="{$U_MAINT_COMPILED_TEMPLATES}">{'Purge compiled templates'|@translate}</a></li>
    24 </ul>
    25 
    26 <ul>
    2722  <li><a href="{$U_MAINT_C13Y}">{'Reinitialize check integrity'|@translate}</a></li>
    2823</ul>
  • trunk/language/en_UK/admin.lang.php

    r8728 r8762  
    215215$lang['default'] = "default";
    216216$lang['delete album'] = "delete album";
     217$lang['Delete orphan tags'] = 'Delete orphan tags';
    217218$lang['Delete Representant'] = "Delete Representant";
    218219$lang['Delete selected photos'] = "Delete selected photos";
     
    471472$lang['Order of menubar items has been updated successfully.'] = 'Order of menubar items has been updated successfully.';
    472473$lang['Original templates'] = "Original templates";
     474$lang['Orphan tags deleted'] = 'Orphan tags deleted';
    473475$lang['Other plugins'] = "Other plugins available";
    474476$lang['Other private albums'] = "Other private albums";
     
    762764$lang['You cannot delete your account'] = "You cannot delete your account";
    763765$lang['You cannot move an album in its own sub album'] = "You cannot move an album in its own sub album";
     766$lang['You have %d orphan tags: %s.'] = 'You have %d orphan tags: %s.';
    764767$lang['You have subscribed to receiving notifications by mail.'] = "You have subscribed to receive notifications by mail.";
    765768$lang['You have unsubscribed from receiving notifications by mail.'] = "You have unsubscribed from being notified by mail.";
  • trunk/language/fr_FR/admin.lang.php

    r8728 r8762  
    560560$lang['Replacers (customized templates)'] = "Remplaçants (templates modifiés)";
    561561$lang['Original templates'] = "Templates d'origine";
     562$lang['Orphan tags deleted'] = 'Tags orphelins supprimés';
    562563$lang['Optional URL keyword'] = "Paramètre facultatif de l'URL";
    563564$lang['Templates configuration has been recorded.'] = "La configuration des templates a été enregistrée.";
     
    782783$lang['with no tag'] = 'sans tag';
    783784$lang['Week starts on'] = 'La semaine commence le';
     785$lang['You have %d orphan tags: %s.'] = 'Vous avez %d tags orphelins: %s.';
     786$lang['Delete orphan tags'] = 'Supprimer les tags orphelins';
    784787?>
Note: See TracChangeset for help on using the changeset viewer.