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:
parent
e338363331
commit
1b7781c866
8 changed files with 116 additions and 7 deletions
|
@ -91,6 +91,7 @@ else
|
|||
|
||||
$page['errors'] = array();
|
||||
$page['infos'] = array();
|
||||
$page['warnings'] = array();
|
||||
|
||||
if (isset($_SESSION['page_infos']))
|
||||
{
|
||||
|
@ -176,6 +177,11 @@ if (count($page['infos']) != 0)
|
|||
$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() );
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -55,6 +55,11 @@ switch ($action)
|
|||
update_average_rate();
|
||||
break;
|
||||
}
|
||||
case 'delete_orphan_tags' :
|
||||
{
|
||||
delete_orphan_tags();
|
||||
break;
|
||||
}
|
||||
case 'history_detail' :
|
||||
{
|
||||
$query = '
|
||||
|
@ -133,13 +138,14 @@ $template->assign(
|
|||
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',
|
||||
)
|
||||
|
|
|
@ -137,6 +137,19 @@ DELETE
|
|||
);
|
||||
}
|
||||
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | 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 |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
@ -199,6 +212,31 @@ $template->assign(
|
|||
)
|
||||
);
|
||||
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | 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&action=delete_orphans&pwg_token='.get_pwg_token()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | form creation |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -214,6 +214,7 @@ $lang['Default user does not exist'] = "The default user does not exist";
|
|||
$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";
|
||||
|
@ -470,6 +471,7 @@ $lang['Options'] = "Options";
|
|||
$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";
|
||||
|
@ -761,6 +763,7 @@ $lang['You are running on development sources, no check possible.'] = "You are r
|
|||
$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.";
|
||||
|
|
|
@ -559,6 +559,7 @@ $lang['Extend for templates'] = "Etendre les templates";
|
|||
$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.";
|
||||
|
@ -781,4 +782,6 @@ $lang['remove creation date'] = 'supprimer la date de création';
|
|||
$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';
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue