aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2011-01-19 13:19:16 +0000
committerplegall <plg@piwigo.org>2011-01-19 13:19:16 +0000
commit1b7781c8669ac98d656b57f4b540ef0fa818a94a (patch)
tree47a7db98b607a4ee477b77df56e8d54576a8566a
parente338363331de40ce04b70d7936cb901f52f88fe0 (diff)
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
Diffstat (limited to '')
-rw-r--r--admin.php6
-rw-r--r--admin/include/functions.php48
-rw-r--r--admin/maintenance.php8
-rw-r--r--admin/tags.php38
-rw-r--r--admin/themes/default/template/admin.tpl10
-rw-r--r--admin/themes/default/template/maintenance.tpl7
-rw-r--r--language/en_UK/admin.lang.php3
-rw-r--r--language/fr_FR/admin.lang.php3
8 files changed, 116 insertions, 7 deletions
diff --git a/admin.php b/admin.php
index 19c1661ed..a3d212164 100644
--- a/admin.php
+++ b/admin.php
@@ -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() );
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 6ad6bc7fe..91931cf4d 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -364,6 +364,54 @@ DELETE FROM '.USERS_TABLE.'
}
/**
+ * 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.
*
diff --git a/admin/maintenance.php b/admin/maintenance.php
index d6aacc843..d9e7b113d 100644
--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -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',
)
diff --git a/admin/tags.php b/admin/tags.php
index 412a57b14..16dea3661 100644
--- a/admin/tags.php
+++ b/admin/tags.php
@@ -138,6 +138,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 |
// +-----------------------------------------------------------------------+
@@ -200,6 +213,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&amp;action=delete_orphans&amp;pwg_token='.get_pwg_token()
+ )
+ );
+}
+
+// +-----------------------------------------------------------------------+
// | form creation |
// +-----------------------------------------------------------------------+
diff --git a/admin/themes/default/template/admin.tpl b/admin/themes/default/template/admin.tpl
index 9528bee79..4ff019b26 100644
--- a/admin/themes/default/template/admin.tpl
+++ b/admin/themes/default/template/admin.tpl
@@ -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>
diff --git a/admin/themes/default/template/maintenance.tpl b/admin/themes/default/template/maintenance.tpl
index 8469decab..dcde866bb 100644
--- a/admin/themes/default/template/maintenance.tpl
+++ b/admin/themes/default/template/maintenance.tpl
@@ -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>
diff --git a/language/en_UK/admin.lang.php b/language/en_UK/admin.lang.php
index 7d044e56e..b369624bd 100644
--- a/language/en_UK/admin.lang.php
+++ b/language/en_UK/admin.lang.php
@@ -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.";
diff --git a/language/fr_FR/admin.lang.php b/language/fr_FR/admin.lang.php
index a5341a661..c001c21e5 100644
--- a/language/fr_FR/admin.lang.php
+++ b/language/fr_FR/admin.lang.php
@@ -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';
?>