Skip to content

Commit

Permalink
bug 2825: add maintenance action to clean the database and avoid inte…
Browse files Browse the repository at this point in the history
…grity errors

git-svn-id: http://piwigo.org/svn/trunk@20544 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Feb 4, 2013
1 parent b39b4e0 commit b267aea
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
28 changes: 28 additions & 0 deletions admin/include/functions.php
Expand Up @@ -484,6 +484,34 @@ function update_category($ids = 'all')
}
}

/**
* check and repair images integrity
*
* TODO see delete_elements function to check all linked tables
*/
function images_integrity()
{
$query = '
SELECT
image_id
FROM '.IMAGE_CATEGORY_TABLE.'
LEFT JOIN '.IMAGES_TABLE.' ON id = image_id
WHERE id IS NULL
;';
$result = pwg_query($query);
$orphan_image_ids = array_from_query($query, 'image_id');

if (count($orphan_image_ids) > 0)
{
$query = '
DELETE
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE image_id IN ('.implode(',', $orphan_image_ids).')
;';
pwg_query($query);
}
}

/**
* returns an array containing sub-directories which can be a category,
* recursive by default
Expand Down
9 changes: 9 additions & 0 deletions admin/maintenance.php
Expand Up @@ -62,6 +62,7 @@
}
case 'categories' :
{
images_integrity();
update_uppercats();
update_category('all');
update_global_rank();
Expand All @@ -70,16 +71,23 @@
}
case 'images' :
{
images_integrity();
update_path();
include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
update_rating_score();
invalidate_user_cache();
break;
}
case 'delete_orphan_tags' :
{
delete_orphan_tags();
break;
}
case 'user_cache' :
{
invalidate_user_cache();
break;
}
case 'history_detail' :
{
$query = '
Expand Down Expand Up @@ -171,6 +179,7 @@
'U_MAINT_CATEGORIES' => sprintf($url_format, 'categories'),
'U_MAINT_IMAGES' => sprintf($url_format, 'images'),
'U_MAINT_ORPHAN_TAGS' => sprintf($url_format, 'delete_orphan_tags'),
'U_MAINT_USER_CACHE' => sprintf($url_format, 'user_cache'),
'U_MAINT_HISTORY_DETAIL' => sprintf($url_format, 'history_detail'),
'U_MAINT_HISTORY_SUMMARY' => sprintf($url_format, 'history_summary'),
'U_MAINT_SESSIONS' => sprintf($url_format, 'sessions'),
Expand Down
1 change: 1 addition & 0 deletions admin/themes/default/template/maintenance.tpl
Expand Up @@ -27,6 +27,7 @@
</ul>

<ul>
<li><a href="{$U_MAINT_USER_CACHE}">{'Purge user cache'|@translate}</a></li>
<li><a href="{$U_MAINT_ORPHAN_TAGS}">{'Delete orphan tags'|@translate}</a></li>
<li><a href="{$U_MAINT_HISTORY_DETAIL}" onclick="return confirm('{'Purge history detail'|@translate|@escape:'javascript'}');">{'Purge history detail'|@translate}</a></li>
<li><a href="{$U_MAINT_HISTORY_SUMMARY}" onclick="return confirm('{'Purge history summary'|@translate|@escape:'javascript'}');">{'Purge history summary'|@translate}</a></li>
Expand Down
1 change: 1 addition & 0 deletions language/en_UK/admin.lang.php
Expand Up @@ -947,4 +947,5 @@
$lang['Zoom'] = 'Zoom';
$lang['[%s] Visit album %s'] = "[%s] Visit album %s";
$lang['[NBM] Problems or questions'] = "[NBM] Problems or questions";
$lang['Purge user cache'] = 'Purge user cache';
?>
2 changes: 1 addition & 1 deletion language/fr_FR/admin.lang.php
Expand Up @@ -949,5 +949,5 @@
$lang['This group will be unset to default'] = "Ce groupe ne sera plus par défaut";
$lang['No members to manage'] = "Aucun membre à gérer";
$lang['Rename'] = 'Renommer';

$lang['Purge user cache'] = 'Purger le cache utilisateur';
?>

0 comments on commit b267aea

Please sign in to comment.