Skip to content

Commit

Permalink
feature 1289 added: easy "delete orphan tags" function. On the "tags"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
plegall committed Jan 19, 2011
1 parent e338363 commit 1b7781c
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 7 deletions.
6 changes: 6 additions & 0 deletions admin.php
Expand Up @@ -91,6 +91,7 @@

$page['errors'] = array();
$page['infos'] = array();
$page['warnings'] = array();

if (isset($_SESSION['page_infos']))
{
Expand Down Expand Up @@ -176,6 +177,11 @@ function UC_name_compare($a, $b)
$template->assign('infos', $page['infos']);
}

if (count($page['warnings']) != 0)
{
$template->assign('warnings', $page['warnings']);
}

// Add the Piwigo Official menu
$template->assign( 'pwgmenu', pwg_URL() );

Expand Down
48 changes: 48 additions & 0 deletions admin/include/functions.php
Expand Up @@ -363,6 +363,54 @@ function delete_user($user_id)
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.
Expand Down
8 changes: 7 additions & 1 deletion admin/maintenance.php
Expand Up @@ -55,6 +55,11 @@
update_average_rate();
break;
}
case 'delete_orphan_tags' :
{
delete_orphan_tags();
break;
}
case 'history_detail' :
{
$query = '
Expand Down Expand Up @@ -133,13 +138,14 @@
array(
'U_MAINT_CATEGORIES' => $start_url.'categories',
'U_MAINT_IMAGES' => $start_url.'images',
'U_MAINT_ORPHAN_TAGS' => $start_url.'delete_orphan_tags',
'U_MAINT_HISTORY_DETAIL' => $start_url.'history_detail',
'U_MAINT_HISTORY_SUMMARY' => $start_url.'history_summary',
'U_MAINT_SESSIONS' => $start_url.'sessions',
'U_MAINT_FEEDS' => $start_url.'feeds',
'U_MAINT_DATABASE' => $start_url.'database',
'U_MAINT_C13Y' => $start_url.'c13y',
'U_MAINT_SEARCH' => $start_url.'search',
'U_MAINT_SEARCH' => $start_url.'search',
'U_MAINT_COMPILED_TEMPLATES' => $start_url.'compiled-templates',
'U_HELP' => get_root_url().'admin/popuphelp.php?page=maintenance',
)
Expand Down
38 changes: 38 additions & 0 deletions admin/tags.php
Expand Up @@ -137,6 +137,19 @@
);
}

// +-----------------------------------------------------------------------+
// | delete orphan tags |
// +-----------------------------------------------------------------------+

if (isset($_GET['action']) and 'delete_orphans' == $_GET['action'])
{
check_pwg_token();

delete_orphan_tags();
$_SESSION['page_infos'] = array(l10n('Orphan tags deleted'));
redirect(get_root_url().'admin.php?page=tags');
}

// +-----------------------------------------------------------------------+
// | add a tag |
// +-----------------------------------------------------------------------+
Expand Down Expand Up @@ -199,6 +212,31 @@
)
);

// +-----------------------------------------------------------------------+
// | orphan tags |
// +-----------------------------------------------------------------------+

$orphan_tags = get_orphan_tags();

$orphan_tag_names = array();
foreach ($orphan_tags as $tag)
{
array_push($orphan_tag_names, $tag['name']);
}

if (count($orphan_tag_names) > 0)
{
array_push(
$page['warnings'],
sprintf(
l10n('You have %d orphan tags: %s.').' <a href="%s">'.l10n('Delete orphan tags').'</a>',
count($orphan_tag_names),
implode(', ', $orphan_tag_names),
get_root_url().'admin.php?page=tags&amp;action=delete_orphans&amp;pwg_token='.get_pwg_token()
)
);
}

// +-----------------------------------------------------------------------+
// | form creation |
// +-----------------------------------------------------------------------+
Expand Down
10 changes: 10 additions & 0 deletions admin/themes/default/template/admin.tpl
Expand Up @@ -126,5 +126,15 @@ jQuery(document).ready(function(){ldelim}
</div>
{/if}

{if isset($warnings)}
<div class="warnings">
<ul>
{foreach from=$warnings item=warning}
<li>{$warning}</li>
{/foreach}
</ul>
</div>
{/if}

{$ADMIN_CONTENT}
</div>
7 changes: 1 addition & 6 deletions admin/themes/default/template/maintenance.tpl
Expand Up @@ -11,18 +11,13 @@
<ul>
<li><a href="{$U_MAINT_CATEGORIES}">{'Update albums informations'|@translate}</a></li>
<li><a href="{$U_MAINT_IMAGES}">{'Update photos information'|@translate}</a></li>
<li><a href="{$U_MAINT_ORPHAN_TAGS}">{'Delete orphan tags'|@translate}</a></li>
<li><a href="{$U_MAINT_DATABASE}">{'Repair and optimize database'|@translate}</a></li>
</ul>

<ul>
<li><a href="{$U_MAINT_HISTORY_DETAIL}" onclick="return confirm('{'Purge history detail'|@translate}');">{'Purge history detail'|@translate}</a></li>
<li><a href="{$U_MAINT_HISTORY_SUMMARY}" onclick="return confirm('{'Purge history summary'|@translate}');">{'Purge history summary'|@translate}</a></li>
<li><a href="{$U_MAINT_SESSIONS}">{'Purge sessions'|@translate}</a></li>
<li><a href="{$U_MAINT_FEEDS}">{'Purge never used notification feeds'|@translate}</a></li>
<li><a href="{$U_MAINT_SEARCH}"onclick="return confirm('{'Purge search history'|@translate}');">{'Purge search history'|@translate}</a></li>
<li><a href="{$U_MAINT_COMPILED_TEMPLATES}">{'Purge compiled templates'|@translate}</a></li>
</ul>

<ul>
<li><a href="{$U_MAINT_C13Y}">{'Reinitialize check integrity'|@translate}</a></li>
</ul>
3 changes: 3 additions & 0 deletions language/en_UK/admin.lang.php
Expand Up @@ -214,6 +214,7 @@
$lang['default values'] = "default values";
$lang['default'] = "default";
$lang['delete album'] = "delete album";
$lang['Delete orphan tags'] = 'Delete orphan tags';
$lang['Delete Representant'] = "Delete Representant";
$lang['Delete selected photos'] = "Delete selected photos";
$lang['Delete selected tags'] = "Delete selected tags";
Expand Down Expand Up @@ -470,6 +471,7 @@
$lang['Options'] = "Options";
$lang['Order of menubar items has been updated successfully.'] = 'Order of menubar items has been updated successfully.';
$lang['Original templates'] = "Original templates";
$lang['Orphan tags deleted'] = 'Orphan tags deleted';
$lang['Other plugins'] = "Other plugins available";
$lang['Other private albums'] = "Other private albums";
$lang['other'] = "other";
Expand Down Expand Up @@ -761,6 +763,7 @@
$lang['You are running the latest version of Piwigo.'] = "You are running Piwigo latest version.";
$lang['You cannot delete your account'] = "You cannot delete your account";
$lang['You cannot move an album in its own sub album'] = "You cannot move an album in its own sub album";
$lang['You have %d orphan tags: %s.'] = 'You have %d orphan tags: %s.';
$lang['You have subscribed to receiving notifications by mail.'] = "You have subscribed to receive notifications by mail.";
$lang['You have unsubscribed from receiving notifications by mail.'] = "You have unsubscribed from being notified by mail.";
$lang['You might go to plugin list to install and activate it.'] = "Go to the plugins list to install and activate it.";
Expand Down
3 changes: 3 additions & 0 deletions language/fr_FR/admin.lang.php
Expand Up @@ -559,6 +559,7 @@
$lang['Replacement of original templates by customized templates from template-extension subfolder'] = "Remplacement des templates d'origine par vos templates personnalisés issus du dossier template-extension";
$lang['Replacers (customized templates)'] = "Remplaçants (templates modifiés)";
$lang['Original templates'] = "Templates d'origine";
$lang['Orphan tags deleted'] = 'Tags orphelins supprimés';
$lang['Optional URL keyword'] = "Paramètre facultatif de l'URL";
$lang['Templates configuration has been recorded.'] = "La configuration des templates a été enregistrée.";
$lang['All optimizations have been successfully completed.'] = "Toutes les optimisations ont été réalisées avec succès.";
Expand Down Expand Up @@ -781,4 +782,6 @@
$lang['with no album'] = 'sans album';
$lang['with no tag'] = 'sans tag';
$lang['Week starts on'] = 'La semaine commence le';
$lang['You have %d orphan tags: %s.'] = 'Vous avez %d tags orphelins: %s.';
$lang['Delete orphan tags'] = 'Supprimer les tags orphelins';
?>

0 comments on commit 1b7781c

Please sign in to comment.