From 39c2bfb3b1b8ad36af101b5aac7ab5d47f4d8ecb Mon Sep 17 00:00:00 2001
From: rub
Date: Tue, 28 Mar 2006 21:05:12 +0000
Subject: [PATCH] Improvement issue 0000319: Add new item on page
administration/maintenance. This item allow to repair and optimize database
Functionality tested with MySQL 4.1.9.
Please to report problem with previous version of MySql
git-svn-id: http://piwigo.org/svn/trunk@1111 68402e56-0260-453c-a942-63ccdbb3a9ee
---
admin/include/functions.php | 53 +++++++++++++++++++
admin/maintenance.php | 44 ++++++---------
language/en_UK.iso-8859-1/admin.lang.php | 1 +
.../en_UK.iso-8859-1/help/maintenance.html | 14 +++--
language/fr_FR.iso-8859-1/admin.lang.php | 1 +
.../fr_FR.iso-8859-1/help/maintenance.html | 10 ++--
template/yoga/admin/maintenance.tpl | 1 +
7 files changed, 89 insertions(+), 35 deletions(-)
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 4dd2869ef..7168e79d9 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -2092,4 +2092,57 @@ UPDATE
'id' => $inserted_id,
);
}
+
+/**
+ * Do maintenance on all PWG tables
+ *
+ * @return nono
+ */
+function do_maintenance_all_tables()
+{
+ global $prefixeTable;
+
+ $all_tables = array();
+
+ // List all tables
+ $query = 'SHOW TABLES LIKE \''.$prefixeTable.'%\';';
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_array($result))
+ {
+ array_push($all_tables, $row[0]);
+ }
+
+ // Repair all tables
+ $query = 'REPAIR TABLE '.implode(', ', $all_tables).';';
+ pwg_query($query);
+
+ // Re-Order all tables
+ foreach ($all_tables as $table_name)
+ {
+ $all_primary_key = array();
+
+ $query = 'DESC '.$table_name.';';
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_array($result))
+ {
+ if ($row['Key'] == 'PRI')
+ {
+ array_push($all_primary_key, $row['Field']);
+ }
+ }
+
+ if (count($all_primary_key) != 0)
+ {
+ $query = 'ALTER TABLE '.$table_name.' ORDER BY '.implode(', ', $all_primary_key).';';
+ pwg_query($query);
+ }
+ }
+
+ // Optimize all tables
+ $query = 'OPTIMIZE TABLE '.implode(', ', $all_tables).';';
+ pwg_query($query);
+
+}
+
+
?>
diff --git a/admin/maintenance.php b/admin/maintenance.php
index c7caf8e50..de6c2a4a1 100644
--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -41,7 +41,7 @@ check_status(ACCESS_ADMINISTRATOR);
// | actions |
// +-----------------------------------------------------------------------+
-$action = isset($_GET['action']) ? $_GET['action'] : '';
+$action = (isset($_GET['action']) and !is_adviser()) ? $_GET['action'] : '';
switch ($action)
{
@@ -84,6 +84,11 @@ DELETE
pwg_query($query);
break;
}
+ case 'database' :
+ {
+ do_maintenance_all_tables();
+ break;
+ }
default :
{
break;
@@ -98,32 +103,17 @@ $template->set_filenames(array('maintenance'=>'admin/maintenance.tpl'));
$start_url = PHPWG_ROOT_PATH.'admin.php?page=maintenance&action=';
-if (!is_adviser())
-{
- $template->assign_vars(
- array(
- 'U_MAINT_CATEGORIES' => $start_url.'categories',
- 'U_MAINT_IMAGES' => $start_url.'images',
- 'U_MAINT_HISTORY' => $start_url.'history',
- 'U_MAINT_SESSIONS' => $start_url.'sessions',
- 'U_MAINT_FEEDS' => $start_url.'feeds',
- 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=maintenance',
- )
- );
-}
-else
-{
- $template->assign_vars(
- array(
- 'U_MAINT_CATEGORIES' => $start_url,
- 'U_MAINT_IMAGES' => $start_url,
- 'U_MAINT_HISTORY' => $start_url,
- 'U_MAINT_SESSIONS' => $start_url,
- 'U_MAINT_FEEDS' => $start_url,
- 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=maintenance',
- )
- );
-}
+$template->assign_vars(
+ array(
+ 'U_MAINT_CATEGORIES' => $start_url.'categories',
+ 'U_MAINT_IMAGES' => $start_url.'images',
+ 'U_MAINT_HISTORY' => $start_url.'history',
+ 'U_MAINT_SESSIONS' => $start_url.'sessions',
+ 'U_MAINT_FEEDS' => $start_url.'feeds',
+ 'U_MAINT_DATABASE' => $start_url.'database',
+ 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=maintenance',
+ )
+ );
// +-----------------------------------------------------------------------+
// | sending html code |
diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php
index f4cd1c294..b5ed27c4c 100644
--- a/language/en_UK.iso-8859-1/admin.lang.php
+++ b/language/en_UK.iso-8859-1/admin.lang.php
@@ -293,6 +293,7 @@ $lang['private'] = 'private';
$lang['public'] = 'public';
$lang['purge history'] = 'purge history';
$lang['purge never used notification feeds'] = 'purge never used notification feeds';
+$lang['repair and optimize database'] = 'repair and optimize database';
$lang['purge sessions'] = 'purge sessions';
$lang['randomly represented'] = 'randomly represented';
$lang['registration_date'] = 'registration date';
diff --git a/language/en_UK.iso-8859-1/help/maintenance.html b/language/en_UK.iso-8859-1/help/maintenance.html
index c3ecbea46..1bc3978b3 100644
--- a/language/en_UK.iso-8859-1/help/maintenance.html
+++ b/language/en_UK.iso-8859-1/help/maintenance.html
@@ -11,13 +11,13 @@ information from database make you save disk space.
- - update categories informations. For each category,
+
- Update categories informations. For each category,
informations to update or control are the following : list of parent
categories, number of pictures, date of the last picture, position among
brother categories, position among all categories. This action also checks
the coherence of representative picture.
- - update images informations. For each picture,
+
- Update images informations. For each picture,
informations to update are : full path to file, average
rate. Warning: do not get confuse with metadata informations
which can be synchronized from Administration,
@@ -25,14 +25,18 @@ information from database make you save disk space.
single picture (through Picture for
example).
- - purge history. Delete all lines from
+
- Purge history. Delete all lines from
history table. Screen Administration,
General, History shows no informations anymore on past
history. Warning: all data will be lost and there is no way to
get informations back.
- - purge sessions. Delete expired user sessions.
+ - Purge sessions. Delete expired user sessions.
- - purge never used notification feeds
+ - Purge never used notification feeds
+
+ - Repair and optimize database
+ For each table, re-odrer, repair and optimize operations are done.
+
diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php
index a8ede8c34..58d85a647 100644
--- a/language/fr_FR.iso-8859-1/admin.lang.php
+++ b/language/fr_FR.iso-8859-1/admin.lang.php
@@ -293,6 +293,7 @@ $lang['private'] = 'priv
$lang['public'] = 'publique';
$lang['purge history'] = 'purger l\'historique';
$lang['purge never used notification feeds'] = 'purger les flux de notification jamais utilisés';
+$lang['repair and optimize database'] = 'réparer et optimiser la base de données';
$lang['purge sessions'] = 'purger les sessions';
$lang['randomly represented'] = 'représentant au hasard';
$lang['registration_date'] = 'date d\'enregistrement';
diff --git a/language/fr_FR.iso-8859-1/help/maintenance.html b/language/fr_FR.iso-8859-1/help/maintenance.html
index bd7a3aee1..7691e739d 100644
--- a/language/fr_FR.iso-8859-1/help/maintenance.html
+++ b/language/fr_FR.iso-8859-1/help/maintenance.html
@@ -28,15 +28,19 @@ l'
(accessible depuis la page de visualisation d'une image picture.php).
- purger l'historique. Supprime toutes les lignes de
+ Purger l'historique. Supprime toutes les lignes de
la table history. L'écran Administration, Général, Historique ne montre alors
plus aucune information sur le passé. Attention: toutes les données
seront perdues et il n'existe aucun moyen de les récupérer.
- purger les sessions. Supprimer les sessions
+ Purger les sessions. Supprimer les sessions
expirées..
- purger les flux de notification jamais utilisés
+ Purger les flux de notification jamais utilisés
+
+ Réparer et optimiser la base de données
+Pour chaque tables de la base de données PhpWegGallery, les opérations de ré-ordonnancement, de réparation et d'optimisation sont effectuées.
+
diff --git a/template/yoga/admin/maintenance.tpl b/template/yoga/admin/maintenance.tpl
index 63ba549c9..697e0954b 100644
--- a/template/yoga/admin/maintenance.tpl
+++ b/template/yoga/admin/maintenance.tpl
@@ -12,4 +12,5 @@
{lang:purge history}
{lang:purge sessions}
{lang:purge never used notification feeds}
+ {lang:repair and optimize database}