diff options
Diffstat (limited to '')
-rw-r--r-- | admin.php | 6 | ||||
-rw-r--r-- | admin/include/functions.php | 48 | ||||
-rw-r--r-- | admin/maintenance.php | 8 | ||||
-rw-r--r-- | admin/tags.php | 38 | ||||
-rw-r--r-- | admin/themes/default/template/admin.tpl | 10 | ||||
-rw-r--r-- | admin/themes/default/template/maintenance.tpl | 7 |
6 files changed, 110 insertions, 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() ); 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&action=delete_orphans&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> |