Refactor admin page, adding it in table level, fixes and support for autovacuum per...
authorGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Mon, 5 Apr 2010 20:56:34 +0000 (22:56 +0200)
committerGuillaume (ioguix) de Rorthais <ioguix@free.fr>
Mon, 5 Apr 2010 20:56:34 +0000 (22:56 +0200)
admin.php [new file with mode: 0644]
classes/Misc.php
classes/database/Postgres.php
classes/database/Postgres73.php
classes/database/Postgres80.php
classes/database/Postgres83.php
database.php
lang/english.php
lang/recoded/english.php
tables.php

diff --git a/admin.php b/admin.php
new file mode 100644 (file)
index 0000000..60f546f
--- /dev/null
+++ b/admin.php
@@ -0,0 +1,638 @@
+<?php
+
+       $script = ''; // init global value script
+       
+       /**
+        * Show confirmation of reindex and perform reindex
+        */
+       function doReindex($type, $confirm=false) {
+               global $script, $data, $misc, $lang, $_reload_browser;
+
+               if (($type == 'table') && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) {
+                       doDefault($lang['strspecifytabletoreindex']);
+                       return;
+               }
+
+               if ($confirm) {
+                       if (isset($_REQUEST['ma'])) {
+                               $misc->printTrail('schema');
+                               $misc->printTitle($lang['strreindex'], 'pg.reindex');
+
+                               echo "<form action=\"{$script}\" method=\"post\">\n";
+                               foreach($_REQUEST['ma'] as $v) {
+                                       $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
+                                       echo "<p>", sprintf($lang['strconfreindextable'], $misc->printVal($a['table'])), "</p>\n";
+                                       echo "<input type=\"hidden\" name=\"table[]\" value=\"", htmlspecialchars($a['table']), "\" />\n";
+                               }
+                       } // END if multi reindex
+                       else {
+                               $misc->printTrail($type);
+                               $misc->printTitle($lang['strreindex'], 'pg.reindex');
+                               
+                               echo "<form action=\"{$script}\" method=\"post\">\n";
+                               
+                               if ($type == 'table') {
+                                       echo "<p>", sprintf($lang['strconfreindextable'], $misc->printVal($_REQUEST['object'])), "</p>\n";
+                                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['object']), "\" />\n";
+                               }
+                               else {
+                                       echo "<p>", sprintf($lang['strconfreindexdatabase'], $misc->printVal($_REQUEST['object'])), "</p>\n";
+                                       echo "<input type=\"hidden\" name=\"table\" value=\"\" />\n";
+                               }
+                       }
+                       echo "<input type=\"hidden\" name=\"action\" value=\"reindex\" />\n";
+                       
+                       if ($data->hasForceReindex())
+                               echo "<p><input type=\"checkbox\" id=\"reindex_force\" name=\"reindex_force\" /><label for=\"reindex_force\">{$lang['strforce']}</label></p>\n";
+                       
+                       echo $misc->form;
+
+                       echo "<input type=\"submit\" name=\"reindex\" value=\"{$lang['strreindex']}\" />\n"; //TODO
+                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
+                       echo "</form>\n";
+               } // END single reindex
+               else {
+                       //If multi table reindex
+                       if (($type == 'table') && is_array($_REQUEST['table'])) {
+                               $msg='';
+                               foreach($_REQUEST['table'] as $o) {
+                                       $status = $data->reindex(strtoupper($type), $o, isset($_REQUEST['reindex_force']));
+                                       if ($status == 0)
+                                               $msg.= sprintf('%s: %s<br />', htmlentities($o), $lang['strreindexgood']);
+                                       else {
+                                               doDefault($type, sprintf('%s%s: %s<br />', $msg, htmlentities($o), $lang['strreindexbad']));
+                                               return;
+                                       }
+                               }
+                                // Everything went fine, back to the Default page....
+                                $_reload_browser = true;
+                                doDefault($msg);
+                       }
+                       else {
+                               $status = $data->reindex(strtoupper($type), $_REQUEST['object'], isset($_REQUEST['reindex_force']));
+                               if ($status == 0) {
+                                       $_reload_browser = true;
+                                       doAdmin($type, $lang['strreindexgood']);
+                               }
+                               else
+                                       doAdmin($type, $lang['strreindexbad']);
+                       }
+               }
+       }
+       
+       /**
+        * Show confirmation of analyze and perform analyze
+        */
+       function doAnalyze($type, $confirm=false) {
+               global $script, $data, $misc, $lang, $_reload_browser;
+
+               if (($type == 'table') && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) {
+                       doDefault($lang['strspecifytabletoanalyze']);
+                       return;
+               }
+
+               if ($confirm) {
+                       if (isset($_REQUEST['ma'])) {
+                               $misc->printTrail('schema');
+                               $misc->printTitle($lang['stranalyze'], 'pg.analyze');
+
+                               echo "<form action=\"{$script}\" method=\"post\">\n";
+                               foreach($_REQUEST['ma'] as $v) {
+                                       $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
+                                       echo "<p>", sprintf($lang['strconfanalyzetable'], $misc->printVal($a['table'])), "</p>\n";
+                                       echo "<input type=\"hidden\" name=\"table[]\" value=\"", htmlspecialchars($a['table']), "\" />\n";
+                               }
+                       } // END if multi analyze
+                       else {
+                               $misc->printTrail($type);
+                               $misc->printTitle($lang['stranalyze'], 'pg.analyze');
+                               
+                               echo "<form action=\"{$script}\" method=\"post\">\n";
+                               
+                               if ($type == 'table') {
+                                       echo "<p>", sprintf($lang['strconfanalyzetable'], $misc->printVal($_REQUEST['object'])), "</p>\n";
+                                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['object']), "\" />\n";
+                               }
+                               else {
+                                       echo "<p>", sprintf($lang['strconfanalyzedatabase'], $misc->printVal($_REQUEST['object'])), "</p>\n";
+                                       echo "<input type=\"hidden\" name=\"table\" value=\"\" />\n";
+                               }
+                       }
+                       echo "<input type=\"hidden\" name=\"action\" value=\"analyze\" />\n";
+                       echo $misc->form;
+
+                       echo "<input type=\"submit\" name=\"analyze\" value=\"{$lang['stranalyze']}\" />\n"; //TODO
+                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
+                       echo "</form>\n";
+               } // END single analyze
+               else {
+                       //If multi table analyze
+                       if (($type == 'table') && is_array($_REQUEST['table'])) {
+                               $msg='';
+                               foreach($_REQUEST['table'] as $o) {
+                                       $status = $data->analyzeDB($o);
+                                       if ($status == 0)
+                                               $msg.= sprintf('%s: %s<br />', htmlentities($o), $lang['stranalyzegood']);
+                                       else {
+                                               doDefault($type, sprintf('%s%s: %s<br />', $msg, htmlentities($o), $lang['stranalyzebad']));
+                                               return;
+                                       }
+                               }
+                                // Everything went fine, back to the Default page....
+                                $_reload_browser = true;
+                                doDefault($msg);
+                       }
+                       else {
+                               //we must pass table here. When empty, analyze the whole db
+                               $status = $data->analyzeDB($_REQUEST['table']);
+                               if ($status == 0) {
+                                       $_reload_browser = true;
+                                       doAdmin($type, $lang['stranalyzegood']);
+                               }
+                               else
+                                       doAdmin($type, $lang['stranalyzebad']);
+                       }
+               }
+       }
+
+       /**
+        * Show confirmation of vacuum and perform actual vacuum
+        */
+       function doVacuum($type, $confirm = false) {
+               global $script, $data, $misc, $lang, $_reload_browser;
+
+               if (($type == 'table') && empty($_REQUEST['table']) && empty($_REQUEST['ma'])) {
+                       doDefault($lang['strspecifytabletovacuum']);
+                       return;
+               }
+
+               if ($confirm) {
+                       if (isset($_REQUEST['ma'])) {
+                               $misc->printTrail('schema');
+                               $misc->printTitle($lang['strvacuum'], 'pg.vacuum');
+
+                               echo "<form action=\"{$script}\" method=\"post\">\n";
+                               foreach($_REQUEST['ma'] as $v) {
+                                       $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
+                                       echo "<p>", sprintf($lang['strconfvacuumtable'], $misc->printVal($a['table'])), "</p>\n";
+                                       echo "<input type=\"hidden\" name=\"table[]\" value=\"", htmlspecialchars($a['table']), "\" />\n";
+                               }
+                       } // END if multi vacuum
+                       else {
+                               $misc->printTrail($type);
+                               $misc->printTitle($lang['strvacuum'], 'pg.vacuum');
+
+                               echo "<form action=\"{$script}\" method=\"post\">\n";
+                               
+                               if ($type == 'table') {
+                                       echo "<p>", sprintf($lang['strconfvacuumtable'], $misc->printVal($_REQUEST['object'])), "</p>\n";
+                                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['object']), "\" />\n";
+                               }
+                               else {
+                                       echo "<p>", sprintf($lang['strconfvacuumdatabase'], $misc->printVal($_REQUEST['object'])), "</p>\n";
+                                       echo "<input type=\"hidden\" name=\"table\" value=\"\" />\n";
+                               }
+                       }
+                       echo "<input type=\"hidden\" name=\"action\" value=\"vacuum\" />\n";
+                       echo $misc->form;
+                       echo "<p><input type=\"checkbox\" id=\"vacuum_full\" name=\"vacuum_full\" /> <label for=\"vacuum_full\">{$lang['strfull']}</label></p>\n";
+                       echo "<p><input type=\"checkbox\" id=\"vacuum_analyze\" name=\"vacuum_analyze\" /> <label for=\"vacuum_analyze\">{$lang['stranalyze']}</label></p>\n";
+                       echo "<p><input type=\"checkbox\" id=\"vacuum_freeze\" name=\"vacuum_freeze\" /><label for=\"vacuum_freeze\">{$lang['strfreeze']}</label></p>\n";
+                       echo "<input type=\"submit\" name=\"vacuum\" value=\"{$lang['strvacuum']}\" />\n";
+                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
+                       echo "</form>\n";
+               } // END single vacuum
+               else {
+                       //If multi drop
+                       if (is_array($_REQUEST['table'])) {
+                               $msg='';
+                               foreach($_REQUEST['table'] as $t) {
+                                       $status = $data->vacuumDB($t, isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), isset($_REQUEST['vacuum_freeze']));
+                                       if ($status == 0)
+                                               $msg.= sprintf('%s: %s<br />', htmlentities($t), $lang['strvacuumgood']);
+                                       else {
+                                               doDefault($type, sprintf('%s%s: %s<br />', $msg, htmlentities($t), $lang['strvacuumbad']));
+                                               return;
+                                       }
+                               }
+                                // Everything went fine, back to the Default page....
+                                $_reload_browser = true;
+                                doDefault($msg);
+                       }
+                       else {
+                               //we must pass table here. When empty, vacuum the whole db
+                               $status = $data->vacuumDB($_REQUEST['table'], isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), isset($_REQUEST['vacuum_freeze']));
+                               if ($status == 0) {
+                                       $_reload_browser = true;
+                                       doAdmin($type, $lang['strvacuumgood']);
+                               }
+                               else
+                                       doAdmin($type, $lang['strvacuumbad']);
+                       }
+               }
+       }
+
+       /**
+        * Add or Edit autovacuum params and save them
+        */
+       function doEditAutovacuum($type, $confirm, $msg='') {
+               global $script, $data, $misc, $lang;
+               
+               if (empty($_REQUEST['table'])) {
+                       doAdmin($type, '', $lang['strspecifyeditvacuumtable']);
+                       return;
+               }
+               
+               $script = ($type == 'database')? 'database.php' : 'tables.php';
+               
+               if ($confirm) {
+                       $misc->printTrail($type);
+                       $misc->printTitle(sprintf($lang['streditvacuumtable'], $misc->printVal($_REQUEST['table'])));
+                       $misc->printMsg(sprintf($msg, $misc->printVal($_REQUEST['table'])));
+
+                       if (empty($_REQUEST['table'])) {
+                               doAdmin($type, '', $lang['strspecifyeditvacuumtable']);
+                               return;
+                       }
+                       
+                       $old_val = $data->getTableAutovacuum($_REQUEST['table']);
+                       $defaults = $data->getAutovacuum();
+                       $old_val = $old_val->fields;
+
+                       if (isset($old_val['autovacuum_enabled']) and ($old_val['autovacuum_enabled'] == 'off')) {
+                               $enabled = '';
+                               $disabled = 'checked="checked"';
+                       }
+                       else {
+                               $enabled = 'checked="checked"';
+                               $disabled = '';
+                       }
+
+                       if (!isset($old_val['autovacuum_vacuum_threshold'])) $old_val['autovacuum_vacuum_threshold'] = '';
+                       if (!isset($old_val['autovacuum_vacuum_scale_factor'])) $old_val['autovacuum_vacuum_scale_factor'] = '';
+                       if (!isset($old_val['autovacuum_analyze_threshold'])) $old_val['autovacuum_analyze_threshold'] = '';
+                       if (!isset($old_val['autovacuum_analyze_scale_factor'])) $old_val['autovacuum_analyze_scale_factor'] = '';
+                       if (!isset($old_val['autovacuum_vacuum_cost_delay'])) $old_val['autovacuum_vacuum_cost_delay'] = '';
+                       if (!isset($old_val['autovacuum_vacuum_cost_limit'])) $old_val['autovacuum_vacuum_cost_limit'] = '';
+
+                       echo "<form action=\"{$script}\" method=\"post\">\n";
+                       echo $misc->form;
+                       echo "<input type=\"hidden\" name=\"action\" value=\"editautovac\" />\n";
+                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+
+                       echo "<br />\n<br />\n<table>\n";
+                       echo "\t<tr><td>&nbsp;</td>\n";
+                       echo "<th class=\"data\">{$lang['strnewvalues']}</th><th class=\"data\">{$lang['strdefaultvalues']}</th></tr>\n";
+                       echo "\t<tr><th class=\"data left\">{$lang['strenable']}</th>\n";
+                       echo "<td class=\"data1\">\n";
+                       echo "<label for=\"on\">on</label><input type=\"radio\" name=\"autovacuum_enabled\" id=\"on\" value=\"on\" {$enabled} />\n";
+                       echo "<label for=\"off\">off</label><input type=\"radio\" name=\"autovacuum_enabled\" id=\"off\" value=\"off\" {$disabled} /></td>\n";
+                       echo "<th class=\"data left\">{$defaults['autovacuum']}</th></tr>\n";
+                       echo "\t<tr><th class=\"data left\">{$lang['strvacuumbasethreshold']}</th>\n";
+                       echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_vacuum_threshold\" value=\"{$old_val['autovacuum_vacuum_threshold']}\" /></td>\n";
+                       echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_threshold']}</th></tr>\n";
+                       echo "\t<tr><th class=\"data left\">{$lang['strvacuumscalefactor']}</th>\n";
+                       echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_vacuum_scale_factor\" value=\"{$old_val['autovacuum_vacuum_scale_factor']}\" /></td>\n";
+                       echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_scale_factor']}</th></tr>\n";
+                       echo "\t<tr><th class=\"data left\">{$lang['stranalybasethreshold']}</th>\n";
+                       echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_analyze_threshold\" value=\"{$old_val['autovacuum_analyze_threshold']}\" /></td>\n";
+                       echo "<th class=\"data left\">{$defaults['autovacuum_analyze_threshold']}</th></tr>\n";
+                       echo "\t<tr><th class=\"data left\">{$lang['stranalyzescalefactor']}</th>\n";
+                       echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_analyze_scale_factor\" value=\"{$old_val['autovacuum_analyze_scale_factor']}\" /></td>\n";
+                       echo "<th class=\"data left\">{$defaults['autovacuum_analyze_scale_factor']}</th></tr>\n";
+                       echo "\t<tr><th class=\"data left\">{$lang['strvacuumcostdelay']}</th>\n";
+                       echo "<td class=\"data1\"><input type=\"text\" name=\"autovacuum_vacuum_cost_delay\" value=\"{$old_val['autovacuum_vacuum_cost_delay']}\" /></td>\n";
+                       echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_cost_delay']}</th></tr>\n";
+                       echo "\t<tr><th class=\"data left\">{$lang['strvacuumcostlimit']}</th>\n";
+                       echo "<td class=\"datat1\"><input type=\"text\" name=\"autovacuum_vacuum_cost_limit\" value=\"{$old_val['autovacuum_vacuum_cost_limit']}\" /></td>\n";
+                       echo "<th class=\"data left\">{$defaults['autovacuum_vacuum_cost_limit']}</th></tr>\n";
+                       echo "</table>\n";
+                       echo "<br />";
+                       echo "<br />";
+                       echo "<input type=\"submit\" name=\"save\" value=\"{$lang['strsave']}\" />\n";
+                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
+
+                       echo "</form>\n";
+               }
+               else {
+                       $status = $data->saveAutovacuum($_REQUEST['table'], $_POST['autovacuum_enabled'], $_POST['autovacuum_vacuum_threshold'], 
+                               $_POST['autovacuum_vacuum_scale_factor'], $_POST['autovacuum_analyze_threshold'], $_POST['autovacuum_analyze_scale_factor'],
+                               $_POST['autovacuum_vacuum_cost_delay'], $_POST['autovacuum_vacuum_cost_limit']);
+                       
+                       if ($status == 0)
+                               doAdmin($type, '', sprintf($lang['strsetvacuumtablesaved'], $_REQUEST['table']));
+                       else
+                               doEditAutovacuum($type, true, $lang['strsetvacuumtablefail']);
+               }
+       }
+       
+       /**
+        * confirm drop autovacuum params for a table and drop it
+        */
+       function doDropAutovacuum($type, $confirm) {
+               global $script, $data, $misc, $lang;
+
+               if (empty($_REQUEST['table'])) {
+                       doAdmin($type, '', $lang['strspecifydelvacuumtable']);
+                       return;
+               }
+               
+               if ($confirm) {
+                       $misc->printTrail($type);
+                       $misc->printTabs($type,'admin');
+                       
+                       $script = ($type == 'database')? 'database.php' : 'tables.php';
+
+                       printf("<p>{$lang['strdelvacuumtable']}</p>\n", 
+                               $misc->printVal("\"{$_GET['schema']}"."{$_GET['table']}\""));
+
+                       echo "<form style=\"float: left\" action=\"{$script}\" method=\"post\">\n";
+                       echo "<input type=\"hidden\" name=\"action\" value=\"delautovac\" />\n";
+                       echo $misc->form;
+                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+                       echo "<input type=\"hidden\" name=\"rel\" value=\"", htmlspecialchars(serialize(array($_REQUEST['schema'], $_REQUEST['table']))), "\" />\n";
+                       echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n";
+                       echo "</form>\n";
+                       
+                       echo "<form action=\"{$script}\" method=\"post\">\n";
+                       echo "<input type=\"hidden\" name=\"action\" value=\"admin\" />\n";
+                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
+                       echo $misc->form;
+                       echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n";
+                       echo "</form>\n";
+               }
+               else {
+                       
+                       $status = $data->dropAutovacuum($_POST['table']);
+                       
+                       if ($status == 0) {
+                               doAdmin($type, '', sprintf($lang['strvacuumtablereset'], $misc->printVal($_POST['table'])));
+                       }
+                       else
+                               doAdmin($type, '', sprintf($lang['strdelvacuumtablefail'], $misc->printVal($_POST['table'])));
+               }
+       }
+
+       /**
+        * database/table administration and tuning tasks
+        *
+        * $Id: admin.php
+        */
+       
+       function doAdmin($type, $msg = '') {
+               global $script, $data, $misc, $lang;    
+
+               $misc->printTrail($type);
+               $misc->printTabs($type,'admin');
+               $misc->printMsg($msg);
+               
+               if ($type == 'database')
+                       printf("<p>{$lang['stradminondatabase']}</p>\n", $misc->printVal($_REQUEST['object']));
+               else
+                       printf("<p>{$lang['stradminontable']}</p>\n", $misc->printVal($_REQUEST['object']));
+               
+               echo "<table style=\"width: 50%\">\n";
+               echo "<tr>\n";
+               echo "<th class=\"data\">";
+               $misc->printHelp($lang['strvacuum'],'pg.admin.vacuum')."</th>\n";
+               echo "</th>";
+               echo "<th class=\"data\">";
+               $misc->printHelp($lang['stranalyze'],'pg.admin.analyze');
+               echo "</th>";
+               if ($data->hasRecluster()){
+                       echo "<th class=\"data\">";
+                       $misc->printHelp($lang['strclusterindex'],'pg.index.cluster');
+                       echo "</th>";
+               }
+               echo "<th class=\"data\">";
+               $misc->printHelp($lang['strreindex'],'pg.index.reindex');
+               echo "</th>";
+               echo "</tr>";   
+
+               // Vacuum
+               echo "<tr>\n";
+               echo "<td class=\"data1\" style=\"text-align: center; vertical-align: bottom\">\n";
+               echo "<form action=\"{$script}\" method=\"post\">\n";
+               
+               echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_vacuum\" />\n";
+               echo $misc->form;
+               if ($type == 'table') {
+                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['object']), "\" />\n";
+                       echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n";
+               }
+               echo "<input type=\"submit\" value=\"{$lang['strvacuum']}\" /></p>\n";
+               echo "</form>\n";                                                               
+               echo "</td>\n";
+
+               // Analyze
+               echo "<td class=\"data1\" style=\"text-align: center; vertical-align: bottom\">\n";
+               echo "<form action=\"{$script}\" method=\"post\">\n";
+               echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_analyze\" />\n";
+               echo $misc->form;
+               if ($type == 'table') {
+                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['object']), "\" />\n";
+                       echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n";
+               }
+               echo "<input type=\"submit\" value=\"{$lang['stranalyze']}\" /></p>\n";
+               echo "</form>\n";
+               echo "</td>\n";
+               
+               // Recluster
+               if ($data->hasRecluster()){
+                       echo "<td class=\"data1\" style=\"text-align: center; vertical-align: bottom\">\n";
+                       echo "<form action=\"{$script}\" method=\"post\">\n";
+                       echo "<p><input type=\"hidden\" name=\"action\" value=\"recluster\" />\n";
+                       echo $misc->form;
+                       if ($type == 'table') {
+                               echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($table), "\" />\n";
+                               echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n";
+                       }
+                       echo "<input type=\"submit\" value=\"{$lang['strclusterindex']}\" /></p>\n";
+                       echo "</form>\n";
+                       echo "</td>\n";
+               }
+               
+               // Reindex
+               echo "<td class=\"data1\" style=\"text-align: center; vertical-align: bottom\">\n";
+               echo "<form action=\"{$script}\" method=\"post\">\n";
+               echo "<p><input type=\"hidden\" name=\"action\" value=\"confirm_reindex\" />\n";
+               echo $misc->form;
+               if ($type == 'table') {
+                       echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['object']), "\" />\n";
+                       echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n";
+               }
+               echo "<input type=\"submit\" value=\"{$lang['strreindex']}\" /></p>\n";
+               echo "</form>\n";
+               echo "</td>\n";
+               echo "</tr>\n";
+               echo "</table>\n";
+
+               // Autovacuum
+               if($data->hasAutovacuum()) {
+                       // get defaults values for autovacuum
+                       $defaults = $data->getAutovacuum();
+                       // Fetch the autovacuum properties from the database or table if != ''
+                       if ($type == 'table') $autovac = $data->getTableAutovacuum($_REQUEST['table']);
+                       else $autovac = $data->getTableAutovacuum();
+
+                       echo "<br /><br /><h2>{$lang['strvacuumpertable']}</h2>";
+                       echo '<p>' . (($defaults->fields['autovacuum'] == 'on') ? $lang['strturnedon'] : $lang['strturnedoff'] ) . '</p>';
+                       echo "<p class=\"message\">{$lang['strnotdefaultinred']}</p>";
+                       
+                       function enlight($f, $p) {
+                               if ( isset($f[$p[0]]) and ($f[$p[0]] != $p[1]))
+                                       return "<span style=\"color:#F33;font-weight:bold\">". htmlspecialchars($f[$p[0]]) ."</span>";
+                               return htmlspecialchars($p[1]);
+                       }
+                       
+                       $columns = array(
+                               'namespace' => array(
+                                       'title' => $lang['strschema'],
+                                       'field' => field('nspname'),
+                               ),      
+                               'relname' => array(
+                                       'title' => $lang['strtable'],
+                                       'field' => field('relname'),
+                               ),
+                               'autovacuum_enabled' => array(
+                                       'title' => $lang['strenabled'],
+                                       'field' => callback('enlight', array('autovacuum_enabled', $defaults['autovacuum'])),
+                                       'type' => 'verbatim'
+                               ),
+                               'autovacuum_vacuum_threshold' => array(
+                                       'title' => $lang['strvacuumbasethreshold'],
+                                       'field' => callback('enlight', array('autovacuum_vacuum_threshold', $defaults['autovacuum_vacuum_threshold'])),
+                                       'type' => 'verbatim'
+                               ),
+                               'autovacuum_vacuum_scale_factor' => array(
+                                       'title' => $lang['strvacuumscalefactor'],
+                                       'field' => callback('enlight', array('autovacuum_vacuum_scale_factor', $defaults['autovacuum_vacuum_scale_factor'])),
+                                       'type' => 'verbatim'
+                               ),
+                               'autovacuum_analyze_threshold' => array(
+                                       'title' => $lang['stranalybasethreshold'],
+                                       'field' => callback('enlight', array('autovacuum_analyze_threshold', $defaults['autovacuum_analyze_threshold'])),
+                                       'type' => 'verbatim'
+                               ),
+                               'autovacuum_analyze_scale_factor' => array(
+                                       'title' => $lang['stranalyzescalefactor'],
+                                       'field' => callback('enlight', array('autovacuum_analyze_scale_factor', $defaults['autovacuum_analyze_scale_factor'])),
+                                       'type' => 'verbatim'
+                               ),
+                               'autovacuum_vacuum_cost_delay' => array(
+                                       'title' => $lang['strvacuumcostdelay'],
+                                       'field' => concat(callback('enlight', array('autovacuum_vacuum_cost_delay', $defaults['autovacuum_vacuum_cost_delay'])), 'ms'),
+                                       'type' => 'verbatim'
+                               ),
+                               'autovacuum_vacuum_cost_limit' => array(
+                                       'title' => $lang['strvacuumcostlimit'],
+                                       'field' => callback('enlight', array('autovacuum_vacuum_cost_limit', $defaults['autovacuum_vacuum_cost_limit'])),
+                                       'type' => 'verbatim'
+                               ),
+                       );
+                       
+                       // Maybe we need to check permissions here?
+                       $columns['actions'] = array('title' => $lang['stractions']);
+
+                       $actions = array(
+                               'edit' => array(
+                                       'title' => $lang['stredit'],
+                                       'url'   => "{$script}?action=confeditautovac&amp;{$misc->href}&amp;subject={$type}&amp;",
+                                       'vars'  => array(
+                                               'schema' => 'nspname',
+                                               'table' => 'relname'
+                                       )
+                               ),
+                               'delete' => array(
+                                       'title' => $lang['strdelete'],
+                                       'url'   => "{$script}?action=confdelautovac&amp;{$misc->href}&amp;subject={$type}&amp;",
+                                       'vars'  => array(
+                                               'schema' => 'nspname',
+                                               'table' => 'relname'
+                                       )
+                               )
+                       );
+                       
+                       if ($type == 'table') {
+                               unset($actions['edit']['vars']['schema'], $actions['delete']['vars']['schema']);
+                       }
+
+                       $misc->printTable($autovac, $columns, $actions, $lang['strnovacuumconf']);
+                       
+                       if (($type == 'table') and ($autovac->recordCount() == 0)) {
+                               echo "<br />";
+                               echo "<a href=\"tables.php?action=confeditautovac&amp;{$misc->href}&amp;table=", htmlspecialchars($_REQUEST['table'])
+                                       ,"\">{$lang['straddvacuumtable']}</a>";
+                       }
+               }
+       }
+       
+       function adminActions($action, $type) {
+               global $script;
+               
+               if ($type == 'database') {
+                       $_REQUEST['object'] = $_REQUEST['database'];
+                       $script = 'database.php';
+               }
+               else {
+                       // $_REQUEST['table'] is no set if we are in the schema page
+                       $_REQUEST['object'] = (isset($_REQUEST['table']) ? $_REQUEST['table']:'');
+                       $script = 'tables.php';
+               }
+
+               switch ($action) {
+                       //case 'confirm_recluster':
+                       case 'confirm_reindex':
+                               doReindex($type, true);
+                               break;
+                       case 'confirm_analyze':
+                               doAnalyze($type, true);
+                               break;
+                       case 'confirm_vacuum':
+                               doVacuum($type, true);
+                               break;
+                       //case 'recluster':
+                       case 'reindex':
+                               if (isset($_POST['reindex'])) doReindex($type);
+                               // if multi-action from table canceled: back to the schema default page
+                               else if (($type == 'table') && is_array($_REQUEST['object']) ) doDefault();
+                               else doAdmin($type);
+                               break;
+                       case 'analyze':
+                               if (isset($_POST['analyze'])) doAnalyze($type);
+                               // if multi-action from table canceled: back to the schema default page
+                               else if (($type == 'table') && is_array($_REQUEST['object']) ) doDefault();
+                               else doAdmin($type);
+                               break;
+                       case 'vacuum':
+                               if (isset($_POST['vacuum'])) doVacuum($type);
+                               // if multi-action from table canceled: back to the schema default page
+                               else if (($type == 'table') && is_array($_REQUEST['object']) ) doDefault();
+                               else doAdmin($type);
+                               break;
+                       case 'admin':
+                               doAdmin($type);
+                               break;
+                       case 'confeditautovac':
+                               doEditAutovacuum($type, true);
+                               break;
+                       case 'confdelautovac':
+                               doDropAutovacuum($type, true);
+                               break;
+                       case 'confaddautovac':
+                               doAddAutovacuum(true);
+                               break;
+                       case 'editautovac':
+                               if (isset($_POST['save'])) doEditAutovacuum($type, false);
+                               else doAdmin($type);
+                               break;
+                       case 'delautovac':
+                               doDropAutovacuum($type, false);
+                               break;
+                       default:
+                               return false;
+               }
+               return true;
+       }
+
+?>
index 69688881daa14670fcd4c18b59ddda180cd50ed6..67323b8767c56d4107ea0a1d254fd91af1b21185 100644 (file)
                                                        'icon'  => 'Rules',
                                                        'branch'=> true,
                                                ),
+                                               'admin' => array (
+                                                       'title' => $lang['stradmin'],
+                                                       'url'   => 'tables.php',
+                                                       'urlvars' => array('subject' => 'table', 'table' => field('table'), 'action' => 'admin'),
+                                                       'icon'  => 'Admin',
+                                               ),
                                                'info' => array (
                                                        'title' => $lang['strinfo'],
                                                        'url'   => 'info.php',
index e16cb0877e9d4d727465d2449bd3ca85722f7388..817bc51172577721b040b412ab8eadd684114b96 100755 (executable)
@@ -2370,6 +2370,66 @@ class Postgres extends ADODB_base {
 
                return $this->selectSet("SELECT {$oid_str}* FROM \"{$relation}\"");
        }
+       
+       /**
+        * Returns all available autovacuum per table information.
+        * @param $table if given, return autovacuum info for the given table or return all informations for all table
+        *   
+        * @return A recordset
+        */
+       function getTableAutovacuum($table='') {
+
+               $sql = '';
+
+               if ($table !== '') {
+                       $this->clean($table);
+                       $f_schema = $this->_schema;
+                       $this->fieldClean($f_schema);
+
+                       $sql = "SELECT c.oid, nspname, relname, pg_catalog.array_to_string(reloptions, E',') AS reloptions
+                               FROM pg_class c
+                                       LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
+                               WHERE c.relkind = 'r'::\"char\"
+                                       AND n.nspname NOT IN ('pg_catalog','information_schema')
+                                       AND c.reloptions IS NOT NULL
+                                       AND c.relname = '{$table}' AND n.nspname = '{$f_schema}'
+                               ORDER BY nspname, relname";
+               }
+               else {
+                       $sql = "SELECT c.oid, nspname, relname, pg_catalog.array_to_string(reloptions, E',') AS reloptions
+                               FROM pg_class c
+                                       LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
+                               WHERE c.relkind = 'r'::\"char\"
+                                       AND n.nspname NOT IN ('pg_catalog','information_schema')
+                                       AND c.reloptions IS NOT NULL
+                               ORDER BY nspname, relname";
+
+               }
+
+               /* tmp var to parse the results */
+               $_autovacs = $this->selectSet($sql);
+
+               /* result aray to return as RS */
+               $autovacs = array();
+               while (!$_autovacs->EOF) {
+                       $_ = array(
+                               'nspname' => $_autovacs->fields['nspname'],
+                               'relname' => $_autovacs->fields['relname']
+                       );
+
+                       foreach (explode(',', $_autovacs->fields['reloptions']) AS $var) {
+                               list($o, $v) = explode('=', $var);
+                               $_[$o] = $v; 
+                       }
+
+                       $autovacs[] = $_;
+                       
+                       $_autovacs->moveNext();
+               }
+
+               include_once('./classes/ArrayRecordSet.php');
+               return new ArrayRecordSet($autovacs);
+       }
 
        // Row functions
 
@@ -2548,7 +2608,7 @@ class Postgres extends ADODB_base {
         * @param $key An array mapping column => value to delete
         * @return 0 success
         */
-       function deleteRow($table, $key) {
+       function deleteRow($table, $key, $schema=false) {
                if (!is_array($key)) return -1;
                else {
                        // Begin transaction.  We do this so that we can ensure only one row is
@@ -2558,8 +2618,10 @@ class Postgres extends ADODB_base {
                                $this->rollbackTransaction();
                                return -1;
                        }
+                       
+                       if ($schema === false) $schema = $this->_schema;
 
-                       $status = $this->delete($table, $key, $this->_schema);
+                       $status = $this->delete($table, $key, $schema);
                        if ($status != 0 || $this->conn->Affected_Rows() != 1) {
                                $this->rollbackTransaction();
                                return -2;
@@ -3292,7 +3354,7 @@ class Postgres extends ADODB_base {
                $this->fieldClean($f_schema);
                $this->fieldClean($index);
                $this->fieldClean($table);
-
+               
                // We don't bother with a transaction here, as there's no point rolling
                // back an expensive cluster if a cheap analyze fails for whatever reason
                $sql = "CLUSTER \"{$f_schema}\".\"{$table}\" USING \"{$index}\"";
@@ -6929,7 +6991,6 @@ class Postgres extends ADODB_base {
 
        /**
         * Analyze a database
-        * @note PostgreSQL 7.2 finally had an independent ANALYZE command
         * @param $table (optional) The table to analyze
         */
        function analyzeDB($table = '') {
@@ -6950,8 +7011,8 @@ class Postgres extends ADODB_base {
         * Vacuums a database
         * @param $table The table to vacuum
         * @param $analyze If true, also does analyze
-        * @param $full If true, selects "full" vacuum (PostgreSQL >= 7.2)
-        * @param $freeze If true, selects aggressive "freezing" of tuples (PostgreSQL >= 7.2)
+        * @param $full If true, selects "full" vacuum
+        * @param $freeze If true, selects aggressive "freezing" of tuples
         */
        function vacuumDB($table = '', $analyze = false, $full = false, $freeze = false) {
 
@@ -6970,19 +7031,93 @@ class Postgres extends ADODB_base {
        }
 
        /**
-        * Returns all available process information.
-        * @return A recordset
+        * Returns all autovacuum global configuration
+        * @return associative array array( param => value, ...)
         */
        function getAutovacuum() {
-               $sql = "
-                       SELECT vacrelid, nspname, relname, enabled, vac_base_thresh,
-                               vac_scale_factor, anl_base_thresh, anl_scale_factor, vac_cost_delay, vac_cost_limit
-                       FROM pg_autovacuum
-                               join pg_class on (oid=vacrelid)
-                               join pg_namespace on (oid=relnamespace)
-                       ORDER BY nspname, relname";
 
-               return $this->selectSet($sql);
+               $_defaults = $this->selectSet("SELECT name, setting
+                       FROM pg_catalog.pg_settings
+                       WHERE 
+                               name = 'autovacuum' 
+                               OR name = 'autovacuum_vacuum_threshold'
+                               OR name = 'autovacuum_vacuum_scale_factor'
+                               OR name = 'autovacuum_analyze_threshold'
+                               OR name = 'autovacuum_analyze_scale_factor'
+                               OR name = 'autovacuum_vacuum_cost_delay'
+                               OR name = 'autovacuum_vacuum_cost_limit'
+                               OR name = 'vacuum_freeze_min_age'
+                               OR name = 'autovacuum_freeze_max_age'
+                       "
+               );
+
+               $ret = array();
+               while (!$_defaults->EOF) {
+                       $ret[$_defaults->fields['name']] = $_defaults->fields['setting'];
+                       $_defaults->moveNext();
+               }
+
+               return $ret;
+       }
+
+       /**
+        * Returns all available autovacuum per table information.
+        * @return A recordset
+        */
+       function saveAutovacuum($table, $vacenabled, $vacthreshold, $vacscalefactor, $anathresold,
+               $anascalefactor, $vaccostdelay, $vaccostlimit)
+       {       
+               $f_schema = $this->_schema;
+               $this->fieldClean($f_schema);
+               $this->fieldClean($table);
+
+               $sql = "ALTER TABLE \"{$f_schema}\".\"{$table}\" SET (";
+
+               if (!empty($vacenabled)) {
+                       $this->clean($vacenabled);
+                       $params[] = "autovacuum_enabled='{$vacenabled}'";
+               }
+               if (!empty($vacthreshold)) {
+                       $this->clean($vacthreshold);
+                       $params[] = "autovacuum_vacuum_threshold='{$vacthreshold}'";
+               }
+               if (!empty($vacscalefactor)) {
+                       $this->clean($vacscalefactor);
+                       $params[] = "autovacuum_vacuum_scale_factor='{$vacscalefactor}'";
+               }
+               if (!empty($anathresold)) {
+                       $this->clean($anathresold);
+                       $params[] = "autovacuum_analyze_threshold='{$anathresold}'";
+               }
+               if (!empty($anascalefactor)) {
+                       $this->clean($anascalefactor);
+                       $params[] = "autovacuum_analyze_scale_factor='{$anascalefactor}'";
+               }
+               if (!empty($vaccostdelay)) {
+                       $this->clean($vaccostdelay);
+                       $params[] = "autovacuum_vacuum_cost_delay='{$vaccostdelay}'";
+               }
+               if (!empty($vaccostlimit)) {
+                       $this->clean($vaccostlimit);
+                       $params[] = "autovacuum_vacuum_cost_limit='{$vaccostlimit}'";
+               }
+
+               $sql = $sql . implode(',', $params) . ');';
+
+               return $this->execute($sql);
+       }
+       
+       function dropAutovacuum($table) {
+               $c_schema = $this->_schema;
+               $this->clean($c_schema);
+               $this->clean($table);
+               
+               return $this->execute("
+                       ALTER TABLE \"{$c_schema}\".\"{$table}\" RESET (autovacuum_enabled, autovacuum_vacuum_threshold,
+                               autovacuum_vacuum_scale_factor, autovacuum_analyze_threshold, autovacuum_analyze_scale_factor,
+                               autovacuum_vacuum_cost_delay, autovacuum_vacuum_cost_limit
+                       );"
+               );
        }
 
        /**
@@ -7682,7 +7817,7 @@ class Postgres extends ADODB_base {
                $sql = "SELECT * FROM pg_stat_database WHERE datname='{$database}'";
 
                return $this->selectSet($sql);
-                                       }
+       }
 
        /**
         * Fetches tuple statistics for a table
@@ -7762,7 +7897,6 @@ class Postgres extends ADODB_base {
        function hasAlterSequenceSchema() { return true; }
        function hasAlterTableSchema() { return true; }
        function hasAutovacuum() { return true; }
-       function hasAutovacuumSysTable() { return false; }
        function hasCreateTableLike() { return true; }
        function hasCreateTableLikeWithConstraints() { return true; }
        function hasCreateTableLikeWithIndexes() { return true; }
@@ -7794,6 +7928,7 @@ class Postgres extends ADODB_base {
        function hasMagicTypes() { return true; }
        function hasQueryKill() { return true; }
        function hasConcurrentIndexBuild() { return true; }
+       function hasForceReindex() { return false; }
        
 }
 ?>
index 11e141c6c06f0f24d1f952dbd20c2b165552e7bd..dd806db1126600eb29566bfc9a35f9bd1a1342c0 100644 (file)
@@ -545,6 +545,7 @@ class Postgres73 extends Postgres74 {
        function hasReadOnlyQueries() { return false; }
        function hasRecluster() { return false; }
        function hasUserRename() { return false; }
+       function hasForceReindex() { return true; }
 }
 
 ?>
index c8da9f4379952e0a3a1e883e0590d609f002f56a..9e037c331e146fa0802615ac82c741189e815cfd 100644 (file)
@@ -317,7 +317,6 @@ class Postgres80 extends Postgres81 {
        function hasAggregateSortOp() { return false; }
        function hasAlterTableSchema() { return false; }
        function hasAutovacuum() { return false; }
-       function hasAutovacuumSysTable() { return false; }
        function hasDisableTriggers() { return false; }
        function hasFunctionAlterSchema() { return false; }
        function hasPreparedXacts() { return false; }
index 9f26ad75b704d97db6eda1ba26064e1700936e94..238d623e493447bb57bc531497dc856351ac7fc1 100644 (file)
@@ -100,7 +100,172 @@ class Postgres83 extends Postgres {
                return $this->selectSet($sql);
        }
 
-       function hasAutovacuumSysTable() { return true; }
+       // Administration functions
+
+       /**
+        * Returns all available autovacuum per table information.
+        * @return A recordset
+        */
+       function getTableAutovacuum($table='') {
+               $sql = '';
+
+               if ($table !== '') {
+                       $this->clean($table);
+                       $f_schema = $this->_schema;
+                       $this->fieldClean($f_schema);
+
+                       $sql = "
+                               SELECT vacrelid, nspname, relname, 
+                                       CASE enabled 
+                                               WHEN 't' THEN 'on' 
+                                               ELSE 'off' 
+                                       END AS autovacuum_enabled, vac_base_thresh AS autovacuum_vacuum_threshold,
+                                       vac_scale_factor AS autovacuum_vacuum_scale_factor, anl_base_thresh AS autovacuum_analyze_threshold, 
+                                       anl_scale_factor AS autovacuum_analyze_scale_factor, vac_cost_delay AS autovacuum_vacuum_cost_delay, 
+                                       vac_cost_limit AS autovacuum_vacuum_cost_limit
+                               FROM pg_autovacuum AS a
+                                       join pg_class AS c on (c.oid=a.vacrelid)
+                                       join pg_namespace AS n on (n.oid=c.relnamespace)
+                               WHERE c.relname = '{$table}' AND n.nspname = '{$f_schema}'
+                               ORDER BY nspname, relname
+                       ";
+               }
+               else {
+                       $sql = "
+                               SELECT vacrelid, nspname, relname, 
+                                       CASE enabled 
+                                               WHEN 't' THEN 'on' 
+                                               ELSE 'off' 
+                                       END AS autovacuum_enabled, vac_base_thresh AS autovacuum_vacuum_threshold,
+                                       vac_scale_factor AS autovacuum_vacuum_scale_factor, anl_base_thresh AS autovacuum_analyze_threshold, 
+                                       anl_scale_factor AS autovacuum_analyze_scale_factor, vac_cost_delay AS autovacuum_vacuum_cost_delay, 
+                                       vac_cost_limit AS autovacuum_vacuum_cost_limit
+                               FROM pg_autovacuum AS a
+                                       join pg_class AS c on (c.oid=a.vacrelid)
+                                       join pg_namespace AS n on (n.oid=c.relnamespace)
+                               ORDER BY nspname, relname
+                       ";
+               }
+
+               return $this->selectSet($sql);
+       }
+       
+       function saveAutovacuum($table, $vacenabled, $vacthreshold, $vacscalefactor, $anathresold, 
+               $anascalefactor, $vaccostdelay, $vaccostlimit) 
+       {
+               $defaults = $this->getAutovacuum();
+               $c_schema = $this->_schema;
+               $this->clean($c_schema);
+               
+               $rs = $this->selectSet("
+                       SELECT c.oid 
+                       FROM pg_catalog.pg_class AS c 
+                               LEFT JOIN pg_catalog.pg_namespace AS n ON (n.oid=c.relnamespace)
+                       WHERE 
+                               c.relname = '{$table}' AND n.nspname = '{$c_schema}'
+               ");
+               
+               if ($rs->EOF)
+                       return -1;
+                       
+               $toid = $rs->fields('oid');
+               unset ($rs);
+                       
+               if (empty($_POST['autovacuum_vacuum_threshold']))
+                       $_POST['autovacuum_vacuum_threshold'] = $defaults['autovacuum_vacuum_threshold'];
+               
+               if (empty($_POST['autovacuum_vacuum_scale_factor']))
+                       $_POST['autovacuum_vacuum_scale_factor'] = $defaults['autovacuum_vacuum_scale_factor'];
+               
+               if (empty($_POST['autovacuum_analyze_threshold']))
+                       $_POST['autovacuum_analyze_threshold'] = $defaults['autovacuum_analyze_threshold'];
+               
+               if (empty($_POST['autovacuum_analyze_scale_factor']))
+                       $_POST['autovacuum_analyze_scale_factor'] = $defaults['autovacuum_analyze_scale_factor'];
+               
+               if (empty($_POST['autovacuum_vacuum_cost_delay']))
+                       $_POST['autovacuum_vacuum_cost_delay'] = $defaults['autovacuum_vacuum_cost_delay'];
+               
+               if (empty($_POST['autovacuum_vacuum_cost_limit']))
+                       $_POST['autovacuum_vacuum_cost_limit'] = $defaults['autovacuum_vacuum_cost_limit'];
+               
+               if (empty($_POST['vacuum_freeze_min_age']))
+                       $_POST['vacuum_freeze_min_age'] = $defaults['vacuum_freeze_min_age'];
+               
+               if (empty($_POST['autovacuum_freeze_max_age']))
+                       $_POST['autovacuum_freeze_max_age'] = $defaults['autovacuum_freeze_max_age'];
+               
+
+               $rs = $this->selectSet("SELECT vacrelid 
+                       FROM \"pg_catalog\".\"pg_autovacuum\" 
+                       WHERE vacrelid = {$toid};");
+               
+               $status = -1; // ini
+               if (isset($rs->fields['vacrelid']) and ($rs->fields['vacrelid'] == $toid)) {
+                       // table exists in pg_autovacuum, UPDATE
+                       $sql = sprintf("UPDATE \"pg_catalog\".\"pg_autovacuum\" SET 
+                                               enabled = '%s',
+                                               vac_base_thresh = %s,
+                                               vac_scale_factor = %s,
+                                               anl_base_thresh = %s,
+                                               anl_scale_factor = %s,
+                                               vac_cost_delay = %s,
+                                               vac_cost_limit = %s,
+                                               freeze_min_age = %s,
+                                               freeze_max_age = %s
+                                       WHERE vacrelid = {$toid};
+                               ",
+                               ($_POST['autovacuum_enabled'] == 'on')? 't':'f',
+                               $_POST['autovacuum_vacuum_threshold'],
+                               $_POST['autovacuum_vacuum_scale_factor'],
+                               $_POST['autovacuum_analyze_threshold'],
+                               $_POST['autovacuum_analyze_scale_factor'],
+                               $_POST['autovacuum_vacuum_cost_delay'],
+                               $_POST['autovacuum_vacuum_cost_limit'],
+                               $_POST['vacuum_freeze_min_age'],
+                               $_POST['autovacuum_freeze_max_age']
+                       );
+                       $status = $this->execute($sql);
+               }
+               else {
+                       // table doesn't exists in pg_autovacuum, INSERT
+                       $sql = sprintf("INSERT INTO \"pg_catalog\".\"pg_autovacuum\" 
+                               VALUES (%s, '%s', %s, %s, %s, %s, %s, %s, %s, %s )
+                               WHERE 
+                                       c.relname = '{$table}' AND n.nspname = '{$c_schema}';",
+                               $toid,
+                               ($_POST['autovacuum_enabled'] == 'on')? 't':'f',
+                               $_POST['autovacuum_vacuum_threshold'],
+                               $_POST['autovacuum_vacuum_scale_factor'],
+                               $_POST['autovacuum_analyze_threshold'],
+                               $_POST['autovacuum_analyze_scale_factor'],
+                               $_POST['autovacuum_vacuum_cost_delay'],
+                               $_POST['autovacuum_vacuum_cost_limit'],
+                               $_POST['vacuum_freeze_min_age'],
+                               $_POST['autovacuum_freeze_max_age']
+                       );
+                       $status = $this->execute($sql);
+               }
+               
+               return $status;
+       }
+
+       function dropAutovacuum($table) {
+               $c_schema = $this->_schema;
+               $this->clean($c_schema);
+               $this->clean($table);
+               
+               $rs = $this->selectSet("
+                       SELECT c.oid 
+                       FROM pg_catalog.pg_class AS c 
+                               LEFT JOIN pg_catalog.pg_namespace AS n ON (n.oid=c.relnamespace)
+                       WHERE 
+                               c.relname = '{$table}' AND n.nspname = '{$c_schema}'
+               ");
+               
+               return $this->deleteRow('pg_autovacuum', array('vacrelid' => $rs->fields['oid']), 'pg_catalog');
+       }
+
        function hasQueryKill() { return false; }
        function hasDatabaseCollation() { return false; }
 
index 71d2f0e2fb24de03a66c3d59c7d518d4078a8952..8b4ced1f58712707c109efc4e58c463d6c39473e 100755 (executable)
                $misc->printTable($variables, $columns, $actions, $lang['strnodata']);
        }
 
-       /**
-        * Allow database administration and tuning tasks
-        */
-       function doAdmin($action = '', $msg = '') {
-               global $data, $misc;
-               global $lang;           
-               switch ($action) {
-                       case 'vacuum':                          
-                               $status = $data->vacuumDB('', isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), isset($_REQUEST['vacuum_freeze']) );
-                               if ($status == 0) doAdmin('', $lang['strvacuumgood']);
-                               else doAdmin('', $lang['strvacuumbad']);
-                               break;
-                       case 'analyze':
-                               $status = $data->analyzeDB();
-                               if ($status == 0) doAdmin('', $lang['stranalyzegood']);
-                               else doAdmin('', $lang['stranalyzebad']);
-                               break;
-                       case 'recluster':
-                               $status = $data->recluster();
-                               if ($status == 0) doAdmin('', $lang['strclusteredgood']);
-                               else doAdmin('', $lang['strclusteredbad']);
-                               break;
-                       case 'reindex';
-                               $status = $data->reindex('DATABASE', $_REQUEST['database'], isset($_REQUEST['reindex_force']));
-                               if ($status == 0) doAdmin('', $lang['strreindexgood']);
-                               else doAdmin('', $lang['strreindexbad']);
-                               break;
-                       default:
-                               $misc->printTrail('database');
-                               $misc->printTabs('database','admin');
-                               $misc->printMsg($msg);
-                               
-                               echo "<table style=\"width: 50%\">\n";
-                               echo "<tr>\n";
-                               echo "<th class=\"data\">";
-                               $misc->printHelp($lang['strvacuum'],'pg.admin.vacuum')."</th>\n";
-                               echo "</th>";
-                               echo "<th class=\"data\">";
-                               $misc->printHelp($lang['stranalyze'],'pg.admin.analyze');
-                               echo "</th>";
-                               if ($data->hasRecluster()){
-                                       echo "<th class=\"data\">";
-                                       $misc->printHelp($lang['strclusterindex'],'pg.index.cluster');
-                                       echo "</th>";
-                               }
-                               echo "<th class=\"data\">";
-                               $misc->printHelp($lang['strreindex'],'pg.index.reindex');
-                               echo "</th>";
-                               echo "</tr>";   
-
-                               // Vacuum
-                               echo "<tr>\n";
-                               echo "<td class=\"data1\" style=\"text-align: center; vertical-align: bottom\">\n";
-                               echo "<form action=\"database.php\" method=\"post\">\n";
-                               echo "<p><input type=\"checkbox\" id=\"vacuum_analyze\" name=\"vacuum_analyze\" /><label for=\"vacuum_analyze\">{$lang['stranalyze']}</label>\n";
-                               echo "<br /><input type=\"checkbox\" id=\"vacuum_full\" name=\"vacuum_full\" /><label for=\"vacuum_full\">{$lang['strfull']}</label>\n";                                
-                               echo "<br /><input type=\"checkbox\" id=\"vacuum_freeze\" name=\"vacuum_freeze\" /><label for=\"vacuum_freeze\">{$lang['strfreeze']}</label>\n";
-                               echo "<input type=\"hidden\" name=\"action\" value=\"vacuum\" />\n";
-                               echo $misc->form;
-                               echo "<br /><input type=\"submit\" value=\"{$lang['strvacuum']}\" /></p>\n";
-                               echo "</form>\n";                                                               
-                               echo "</td>\n";
-
-                               // Analyze
-                               echo "<td class=\"data1\" style=\"text-align: center; vertical-align: bottom\">\n";
-                               echo "<form action=\"database.php\" method=\"post\">\n";
-                               echo "<p><input type=\"hidden\" name=\"action\" value=\"analyze\" />\n";
-                               echo $misc->form;
-                               echo "<input type=\"submit\" value=\"{$lang['stranalyze']}\" /></p>\n";
-                               echo "</form>\n";
-                               echo "</td>\n";
-                               
-                               // Recluster
-                               if ($data->hasRecluster()){
-                                       echo "<td class=\"data1\" style=\"text-align: center; vertical-align: bottom\">\n";
-                                       echo "<form action=\"database.php\" method=\"post\">\n";
-                                       echo "<p><input type=\"hidden\" name=\"action\" value=\"recluster\" />\n";
-                                       echo $misc->form;
-                                       echo "<input type=\"submit\" value=\"{$lang['strclusterindex']}\" /></p>\n";
-                                       echo "</form>\n";
-                                       echo "</td>\n";
-                               }
-                               
-                               // Reindex
-                               echo "<td class=\"data1\" style=\"text-align: center; vertical-align: bottom\">\n";
-                               echo "<form action=\"database.php\" method=\"post\">\n";
-                               echo "<p><input type=\"checkbox\" id=\"reindex_force\" name=\"reindex_force\" /><label for=\"reindex_force\">{$lang['strforce']}</label><br />\n";
-                               echo "<input type=\"hidden\" name=\"action\" value=\"reindex\" />\n";
-                               echo $misc->form;
-                               echo "<input type=\"submit\" value=\"{$lang['strreindex']}\" /></p>\n";
-                               echo "</form>\n";
-                               echo "</td>\n";
-                               echo "</tr>\n";
-                               echo "</table>\n";
-
-                               // Autovacuum
-                               if($data->hasAutovacuum()) {
-                                       $enabled = $data->getVariable('autovacuum');
-                                       echo "<h3>{$lang['strautovacuum']}</h3>";
-                                       echo '<p>' . (($enabled->fields['autovacuum'] == 'on') ? $lang['strturnedon'] : $lang['strturnedoff'] ) . '</p>';
-
-                                       if($data->hasAutovacuumSysTable()) {
-
-                                               // Fetch the processes from the database
-                                               $autovac = $data->getAutovacuum();
-               
-                                               $columns = array(
-                                                       'namespace' => array(
-                                                               'title' => $lang['strschema'],
-                                                               'field' => field('nspname'),
-                                                       ),      
-                                                       'relname' => array(
-                                                               'title' => $lang['strtable'],
-                                                               'field' => field('relname'),
-                                                       ),
-                                                       'enabled' => array(
-                                                               'title' => $lang['strenabled'],
-                                                               'field' => field('enabled'),
-                                                       ),
-                                                       'vac_base_thresh' => array(
-                                                               'title' => $lang['strvacuumbasethreshold'],
-                                                               'field' => field('vac_base_thresh'),
-                                                       ),
-                                                       'vac_scale_factor' => array(
-                                                               'title' => $lang['strvacuumscalefactor'],
-                                                               'field' => field('vac_scale_factor'),
-                                                       ),
-                                                       'anl_base_thresh' => array(
-                                                               'title' => $lang['stranalybasethreshold'],
-                                                               'field' => field('anl_base_thresh'),
-                                                       ),
-                                                       'anl_scale_factor' => array(
-                                                               'title' => $lang['stranalyzescalefactor'],
-                                                               'field' => field('anl_scale_factor'),
-                                                       ),
-                                                       'vac_cost_delay' => array(
-                                                               'title' => $lang['strvacuumcostdelay'],
-                                                               'field' => field('vac_cost_delay'),
-                                                       ),
-                                                       'vac_cost_limit' => array(
-                                                               'title' => $lang['strvacuumcostlimit'],
-                                                               'field' => field('vac_cost_limit'),
-                                                       ),
-                                               );
-
-                                               // Maybe we need to check permissions here?
-                                               $columns['actions'] = array('title' => $lang['stractions']);
-
-                                               $actions = array(
-                                                       'edit' => array(
-                                                       'title' => $lang['stredit'],
-                                                       'url'   => "database.php?action=editautovac&amp;schema=pg_catalog&amp;{$misc->href}&amp;",
-                                                       'vars'  => array('key[vacrelid]' => 'vacrelid')
-                                                       ),
-                                                       'delete' => array(
-                                                       'title' => $lang['strdelete'],
-                                                       'url'   => "database.php?action=delautovac&amp;{$misc->href}&amp;",
-                                                       'vars'  => array('key[vacrelid]' => 'vacrelid')
-                                                       )
-                                               );
-
-                                               $misc->printTable($autovac, $columns, $actions, $lang['strnodata']);
-       
-                                       }
-
-                               }
-       
-                               break;
-               }
-       }
-
-       /**
-        * Show confirmation of edit and perform actual update of autovacuum entry
-        */
-       function doEditAutovacuum($confirm, $msg = '') {
-               global $data, $misc, $conf;
-               global $lang;
-
-               $key = $_REQUEST['key'];
-
-               if ($confirm) {
-                       $misc->printTrail('database');
-                       $misc->printTabs('database','admin');
-                       $misc->printMsg($msg);
-
-                       $attrs = $data->getTableAttributes('pg_autovacuum');
-                       $rs = $data->browseRow('pg_autovacuum', $key);
-                       
-                       echo "<form action=\"database.php\" method=\"post\" id=\"ac_form\">\n";
-                       $elements = 0;
-                       $error = true;                  
-                       if ($rs->recordCount() == 1 && $attrs->recordCount() > 0) {
-                               echo "<table>\n";
-
-                               // Output table header
-                               echo "<tr><th class=\"data\">{$lang['strcolumn']}</th><th class=\"data\">{$lang['strtype']}</th>";
-                               echo "<th class=\"data\">{$lang['strformat']}</th>\n";
-                               echo "<th class=\"data\">{$lang['strvalue']}</th></tr>";
-
-                               $i = 0;
-                               $nCC = 0;
-                               while (!$attrs->EOF) {
-                                       $szValueName = "values[{$attrs->fields['attname']}]";
-                                       $szEvents = "";
-                                       $szDivPH = "";
-                                       
-                                       $attrs->fields['attnotnull'] = $data->phpBool($attrs->fields['attnotnull']);
-                                       $id = (($i % 2) == 0 ? '1' : '2');
-                                       
-                                       // Initialise variables
-                                       if (!isset($_REQUEST['format'][$attrs->fields['attname']]))
-                                               $_REQUEST['format'][$attrs->fields['attname']] = 'VALUE';
-                                       
-                                       echo "<tr>\n";
-                                       echo "<td class=\"data{$id}\" style=\"white-space:nowrap;\">", $misc->printVal($attrs->fields['attname']), "</td>";
-                                       echo "<td class=\"data{$id}\" style=\"white-space:nowrap;\">\n";
-                                       echo $misc->printVal($data->formatType($attrs->fields['type'], $attrs->fields['atttypmod']));
-                                       echo "<input type=\"hidden\" name=\"types[", htmlspecialchars($attrs->fields['attname']), "]\" value=\"", 
-                                               htmlspecialchars($attrs->fields['type']), "\" /></td>";
-                                       $elements++;
-                                       echo "<td class=\"data{$id}\" style=\"white-space:nowrap;\">\n";
-                                       echo "<select name=\"format[", htmlspecialchars($attrs->fields['attname']), "]\">\n";
-                                       echo "<option value=\"VALUE\"", ($_REQUEST['format'][$attrs->fields['attname']] == 'VALUE') ? ' selected="selected"' : '', ">{$lang['strvalue']}</option>\n";
-                                       echo "<option value=\"EXPRESSION\"", ($_REQUEST['format'][$attrs->fields['attname']] == 'EXPRESSION') ? ' selected="selected"' : '', ">{$lang['strexpression']}</option>\n";
-                                       echo "</select>\n</td>\n";
-                                       $elements++;
-
-                                       echo "<td class=\"data{$id}\" id=\"aciwp{$i}\" style=\"white-space:nowrap;\">";
-                                       echo $data->printField($szValueName, $rs->fields[$attrs->fields['attname']], $attrs->fields['type'],array(),$szEvents) . $szDivPH;
-                                       echo "</td>";
-                                       $elements++;
-                                       echo "</tr>\n";
-                                       $i++;
-                                       $attrs->moveNext();
-                               }
-                               echo "</table>\n";
-                               $error = false;
-                       }
-                       elseif ($rs->recordCount() != 1) {
-                               echo "<p>{$lang['strrownotunique']}</p>\n";                             
-                       }
-                       else {
-                               echo "<p>{$lang['strinvalidparam']}</p>\n";
-                       }
-
-                       echo "<input type=\"hidden\" name=\"action\" value=\"confeditautovac\" />\n";
-                       echo $misc->form;
-                       echo "<input type=\"hidden\" name=\"table\" value=\"pg_autovacuum\" />\n";
-                       echo "<input type=\"hidden\" name=\"key\" value=\"", htmlspecialchars(serialize($key)), "\" />\n";
-                       echo "<p>";
-                       if (!$error) echo "<input type=\"submit\" name=\"save\" value=\"{$lang['strsave']}\" />\n";
-                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
-                       echo "</p>\n";
-                       echo "</form>\n";
-               }
-               else {
-                       if (!isset($_POST['values'])) $_POST['values'] = array();
-                       if (!isset($_POST['nulls'])) $_POST['nulls'] = array();
-                       
-                       $status = $data->editRow($_POST['table'], $_POST['values'], $_POST['nulls'], 
-                                                                                               $_POST['format'], $_POST['types'], unserialize($_POST['key']));
-                       if ($status == 0)
-                               doAdmin($lang['strrowupdated']);
-                       elseif ($status == -2)
-                               doEditAutovacuum(true, $lang['strrownotunique']);
-                       else
-                               doEditAutovacuum(true, $lang['strrowupdatedbad']);
-               }
-
-       }       
-
-
-       /**
-        * Delete rows from the autovacuum table
-     */
-       function doDelAutovacuum($confirm) {
-               global $data, $misc;
-               global $lang;
-
-               if ($confirm) {
-                       $misc->printTrail('database');
-                       $misc->printTabs('database','admin');
-                       $misc->printTitle($lang['strdeleterow']);
-
-                       echo "<p>{$lang['strconfdeleterow']}</p>\n";
-                       
-                       echo "<form action=\"database.php\" method=\"post\">\n";
-                       echo "<input type=\"hidden\" name=\"action\" value=\"confdelautovac\" />\n";
-                       echo $misc->form;
-                       echo "<input type=\"hidden\" name=\"table\" value=\"pg_autovacuum\" />\n";
-                       echo "<input type=\"hidden\" name=\"key\" value=\"", htmlspecialchars(serialize($_REQUEST['key'])), "\" />\n";
-                       echo "<input type=\"submit\" name=\"yes\" value=\"{$lang['stryes']}\" />\n";
-                       echo "<input type=\"submit\" name=\"no\" value=\"{$lang['strno']}\" />\n";
-                       echo "</form>\n";
-               }
-               else {
-                       $status = $data->deleteRow($_POST['table'], unserialize($_POST['key']));
-                       if ($status == 0)
-                               doAdmin('',$lang['strrowdeleted']);
-                       elseif ($status == -2)
-                               doAdmin('',$lang['strrownotunique']);
-                       else                    
-                               doAdmin('',$lang['strrowdeletedbad']);
-               }
-       }
-
        /**
         * Allow execution of arbitrary SQL statements on a database
         */
                echo "<p>{$lang['strsql']}<br />\n";
                echo "<textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"query\">",
                        htmlspecialchars($_SESSION['sqlquery']), "</textarea></p>\n";
-               
+
                // Check that file uploads are enabled
                if (ini_get('file_uploads')) {
                        // Don't show upload option if max size of uploads is zero
                $tabs = $misc->getNavTabs('database');
 
                $items = $misc->adjustTabsForTree($tabs);
-               
+
                $attrs = array(
                        'text'   => noEscape(field('title')),
                        'icon'   => field('icon'),
                exit;
        }
 
+       require('./admin.php');
+
        if ($action == 'tree') doTree();
        
        $misc->printHeader($lang['strschemas']);
        $misc->printBody();
-
+       
        switch ($action) {
                case 'find':
                        if (isset($_REQUEST['term'])) doFind(false);
                        else doFind(true);
                        break;
-               case 'recluster':
-               case 'reindex':
-               case 'analyze':
-               case 'vacuum':
-                       doAdmin($action);
-                       break;
-               case 'admin':
-                       doAdmin();
-                       break;
                case 'sql':
                        doSQL();
                        break;
                case 'signal':
                        doSignal();
                        break;
-               case 'editautovac':
-                       doEditAutovacuum(true);
-                       break;
-               case 'confeditautovac':
-                       if (isset($_POST['save'])) doEditAutovacuum(false);
-                       else doAdmin();
-                       break;
-               case 'delautovac':
-                       doDelAutovacuum(true);
-                       break;
-               case 'confdelautovac':
-                       if (isset($_POST['yes'])) doDelAutovacuum(false);
-                       else doAdmin();
-                       break;
                default:
-                       doSQL();
+                       if (adminActions($action, 'database') === false) doSQL();
                        break;
        }
 
index 2b48c931156dd43261f1d96088329aea56221d6d..76b268ad2ab1a2eb40ef4c4678864bb5a8cf62fb 100644 (file)
        $lang['strlocale'] = 'Locale';
        $lang['strcollation'] = 'Collation';
        $lang['strctype'] = 'Character Type';
-
+       $lang['strdefaultvalues'] = 'Default values';
+       $lang['strnewvalues'] = 'New values';
+       
+       // Admin
+       $lang['stradminondatabase'] = 'The following administrative tasks apply on the whole %s database.';
+       $lang['stradminontable'] = 'The following administrative tasks apply on the table %s.';
+       
        // User-supplied SQL history
        $lang['strhistory'] = 'History';
        $lang['strnohistory'] = 'No history.';
        $lang['strconfdelhistory'] = 'Really remove this request from history?';
        $lang['strconfclearhistory'] = 'Really clear history?';
        $lang['strnodatabaseselected'] = 'Please, select a database.';
+       
+       // Database
+       $lang['strconfanalyzedatabase'] = 'Are you sure you want to analyze all tables in database "%s"?';
+       $lang['strconfvacuumdatabase'] = 'Are you sure you want to vacuum all tables in database "%s"?';
+       $lang['strconfreindexdatabase'] = 'Are you sure you want to reindex all tables in database "%s"?';
 
        // Database sizes
        $lang['strnoaccess'] = 'No Access'; 
        $lang['strauto'] = 'Auto';
        $lang['strconfvacuumtable'] = 'Are you sure you want to vacuum "%s"?';
        $lang['strconfanalyzetable'] = 'Are you sure you want to analyze "%s"?';
+       $lang['strconfreindextable'] = 'Are you sure you want to reindex "%s"?';
        $lang['strestimatedrowcount'] = 'Estimated row count';
        $lang['strspecifytabletoanalyze'] = 'You must specify at least one table to analyze.';
        $lang['strspecifytabletoempty'] = 'You must specify at least one table to empty.';
        $lang['strspecifytabletodrop'] = 'You must specify at least one table to drop.';
        $lang['strspecifytabletovacuum'] = 'You must specify at least one table to vacuum.';
+       $lang['strspecifytabletoreindex'] = 'You must specify at least one table to reindex.';
        $lang['strnofieldsforinsert'] = 'You cannot insert a row into a table with no column.';
 
        // Columns
        $lang['strturnedon'] = 'Turned On';
        $lang['strturnedoff'] = 'Turned Off';
        $lang['strenabled'] = 'Enabled';
+       $lang['strnovacuumconf'] = 'No autovacuum configuration found.';
        $lang['strvacuumbasethreshold'] = 'Vacuum Base Threshold';
        $lang['strvacuumscalefactor'] = 'Vacuum Scale Factor';
        $lang['stranalybasethreshold'] = 'Analyze Base Threshold';
        $lang['stranalyzescalefactor'] = 'Analyze Scale Factor';
        $lang['strvacuumcostdelay'] = 'Vacuum Cost Delay';
        $lang['strvacuumcostlimit'] = 'Vacuum Cost Limit';
+       $lang['strvacuumpertable'] = 'Autovacuum setup per table';
+       $lang['straddvacuumtable'] = 'Add autovacuum setup for a table';
+       $lang['streditvacuumtable'] = 'Edit autovacuum setup for table %s';
+       $lang['strdelvacuumtable'] = 'Delete autovacuum setup for table %s ?';
+       $lang['strvacuumtablereset'] = 'Autovacuum setup for table %s reset to default values';
+       $lang['strdelvacuumtablefail'] = 'Fail to remove the autovacuum setup for table %s';
+       $lang['strsetvacuumtablesaved'] = 'Autovacuum setup for table %s saved.';
+       $lang['strsetvacuumtablefail'] = 'Autovacuum setup for table %s failed.';
+       $lang['strspecifydelvacuumtable'] = 'You must specify the table you want remove the autovacuum parameters from.';
+       $lang['strspecifyeditvacuumtable'] = 'You must specify the table you want to edit the autovacuum parameters from.';
+       $lang['strnotdefaultinred'] = 'Not default values are in red.';
 
        // Table-level Locks
        $lang['strlocks'] = 'Locks';
index fdb5ae41e89fc457d29c7ae391e419a771f888a7..b8f669150788e83b5a9820adc879a6f289e46ce6 100644 (file)
        $lang['strlocale'] = 'Locale';
        $lang['strcollation'] = 'Collation';
        $lang['strctype'] = 'Character Type';
-
+       $lang['strdefaultvalues'] = 'Default values';
+       $lang['strnewvalues'] = 'New values';
+       
+       // Admin
+       $lang['stradminondatabase'] = 'The following administrative tasks apply on the whole %s database.';
+       $lang['stradminontable'] = 'The following administrative tasks apply on the table %s.';
+       
        // User-supplied SQL history
        $lang['strhistory'] = 'History';
        $lang['strnohistory'] = 'No history.';
        $lang['strconfdelhistory'] = 'Really remove this request from history?';
        $lang['strconfclearhistory'] = 'Really clear history?';
        $lang['strnodatabaseselected'] = 'Please, select a database.';
+       
+       // Database
+       $lang['strconfanalyzedatabase'] = 'Are you sure you want to analyze all tables in database &quot;%s&quot;?';
+       $lang['strconfvacuumdatabase'] = 'Are you sure you want to vacuum all tables in database &quot;%s&quot;?';
+       $lang['strconfreindexdatabase'] = 'Are you sure you want to reindex all tables in database &quot;%s&quot;?';
 
        // Database sizes
        $lang['strnoaccess'] = 'No Access'; 
        $lang['strauto'] = 'Auto';
        $lang['strconfvacuumtable'] = 'Are you sure you want to vacuum &quot;%s&quot;?';
        $lang['strconfanalyzetable'] = 'Are you sure you want to analyze &quot;%s&quot;?';
+       $lang['strconfreindextable'] = 'Are you sure you want to reindex &quot;%s&quot;?';
        $lang['strestimatedrowcount'] = 'Estimated row count';
        $lang['strspecifytabletoanalyze'] = 'You must specify at least one table to analyze.';
        $lang['strspecifytabletoempty'] = 'You must specify at least one table to empty.';
        $lang['strspecifytabletodrop'] = 'You must specify at least one table to drop.';
        $lang['strspecifytabletovacuum'] = 'You must specify at least one table to vacuum.';
+       $lang['strspecifytabletoreindex'] = 'You must specify at least one table to reindex.';
        $lang['strnofieldsforinsert'] = 'You cannot insert a row into a table with no column.';
 
        // Columns
        $lang['strturnedon'] = 'Turned On';
        $lang['strturnedoff'] = 'Turned Off';
        $lang['strenabled'] = 'Enabled';
+       $lang['strnovacuumconf'] = 'No autovacuum configuration found.';
        $lang['strvacuumbasethreshold'] = 'Vacuum Base Threshold';
        $lang['strvacuumscalefactor'] = 'Vacuum Scale Factor';
        $lang['stranalybasethreshold'] = 'Analyze Base Threshold';
        $lang['stranalyzescalefactor'] = 'Analyze Scale Factor';
        $lang['strvacuumcostdelay'] = 'Vacuum Cost Delay';
        $lang['strvacuumcostlimit'] = 'Vacuum Cost Limit';
+       $lang['strvacuumpertable'] = 'Autovacuum setup per table';
+       $lang['straddvacuumtable'] = 'Add autovacuum setup for a table';
+       $lang['streditvacuumtable'] = 'Edit autovacuum setup for table %s';
+       $lang['strdelvacuumtable'] = 'Delete autovacuum setup for table %s ?';
+       $lang['strvacuumtablereset'] = 'Autovacuum setup for table %s reset to default values';
+       $lang['strdelvacuumtablefail'] = 'Fail to remove the autovacuum setup for table %s';
+       $lang['strsetvacuumtablesaved'] = 'Autovacuum setup for table %s saved.';
+       $lang['strsetvacuumtablefail'] = 'Autovacuum setup for table %s failed.';
+       $lang['strspecifydelvacuumtable'] = 'You must specify the table you want remove the autovacuum parameters from.';
+       $lang['strspecifyeditvacuumtable'] = 'You must specify the table you want to edit the autovacuum parameters from.';
+       $lang['strnotdefaultinred'] = 'Not default values are in red.';
 
        // Table-level Locks
        $lang['strlocks'] = 'Locks';
index af01e52a11782519715b1753aac8eb8183dcc985..ff6493ec3f75486fc842f80d55a582eae8ca8e19 100644 (file)
                                exit;
                        }
                }
-
        }
 
        /**
                } // END DROP
        }// END Function
 
-
-       /**
-        * Show confirmation of vacuum and perform actual vacuum
-        */
-       function doVacuum($confirm) {
-               global $data, $misc;
-               global $lang, $_reload_browser;
-
-               if (empty($_REQUEST['table']) && empty($_REQUEST['ma'])) {
-                       doDefault($lang['strspecifytabletovacuum']);
-                       exit();
-               }
-               if ($confirm) {
-                       if (isset($_REQUEST['ma'])) {
-                               $misc->printTrail('schema');
-                               $misc->printTitle($lang['strvacuum'], 'pg.vacuum');
-
-                               echo "<form action=\"tables.php\" method=\"post\">\n";
-                               foreach($_REQUEST['ma'] as $v) {
-                                       $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
-                                       echo "<p>", sprintf($lang['strconfvacuumtable'], $misc->printVal($a['table'])), "</p>\n";
-                                       echo "<input type=\"hidden\" name=\"table[]\" value=\"", htmlspecialchars($a['table']), "\" />\n";
-                               }
-                       } // END if multi vacuum
-                       else {
-                               $misc->printTrail('table');
-                               $misc->printTitle($lang['strvacuum'], 'pg.vacuum');
-
-                               echo "<p>", sprintf($lang['strconfvacuumtable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
-
-                               echo "<form action=\"tables.php\" method=\"post\">\n";
-                               echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
-                       }
-                       echo "<input type=\"hidden\" name=\"action\" value=\"vacuum\" />\n";
-                       echo $misc->form;
-                       echo "<p><input type=\"checkbox\" id=\"vacuum_full\" name=\"vacuum_full\" /> <label for=\"vacuum_full\">{$lang['strfull']}</label></p>\n";
-                       echo "<p><input type=\"checkbox\" id=\"vacuum_analyze\" name=\"vacuum_analyze\" /> <label for=\"vacuum_analyze\">{$lang['stranalyze']}</label></p>\n";
-                       echo "<input type=\"submit\" name=\"vacuum\" value=\"{$lang['strvacuum']}\" />\n";
-                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
-                       echo "</form>\n";
-               } // END single vacuum
-               else {
-                       //If multi drop
-                       if (is_array($_REQUEST['table'])) {
-                               $msg='';
-                               foreach($_REQUEST['table'] as $t) {
-                                       $status = $data->vacuumDB($t, isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), '');
-                                       if ($status == 0)
-                                               $msg.= sprintf('%s: %s<br />', htmlentities($t), $lang['strvacuumgood']);
-                                       else {
-                                               doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($t), $lang['strvacuumbad']));
-                                               return;
-                                       }
-                               }
-                                // Everything went fine, back to the Default page....
-                                $_reload_browser = true;
-                                doDefault($msg);
-                       }
-                       else {
-                               $status = $data->vacuumDB($_POST['table'], isset($_REQUEST['vacuum_analyze']), isset($_REQUEST['vacuum_full']), '');
-                               if ($status == 0) {
-                                       $_reload_browser = true;
-                                       doDefault($lang['strvacuumgood']);
-                               }
-                               else
-                                       doDefault($lang['strvacuumbad']);
-                       }
-               }
-       }
-
-       /**
-        * Show confirmation of analyze and perform analyze
-        */
-       function doAnalyze($confirm) {
-               global $data, $misc;
-               global $lang, $_reload_browser;
-
-               if (empty($_REQUEST['table']) && empty($_REQUEST['ma'])) {
-                       doDefault($lang['strspecifytabletoanalyze']);
-                       exit();
-               }
-               if ($confirm) {
-                       if (isset($_REQUEST['ma'])) {
-                               $misc->printTrail('schema');
-                               $misc->printTitle($lang['stranalyze'], 'pg.analyze'); //TODO
-
-                               echo "<form action=\"tables.php\" method=\"post\">\n";
-                               foreach($_REQUEST['ma'] as $v) {
-                                       $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
-                                       echo "<p>", sprintf($lang['strconfanalyzetable'], $misc->printVal($a['table'])), "</p>\n";
-                                       echo "<input type=\"hidden\" name=\"table[]\" value=\"", htmlspecialchars($a['table']), "\" />\n";
-                               }
-                       } // END if multi analyze
-                       else {
-                               $misc->printTrail('table');
-                               $misc->printTitle($lang['stranalyze'], 'pg.analyze'); //TODO
-
-                               echo "<p>", sprintf($lang['strconfanalyzetable'], $misc->printVal($_REQUEST['table'])), "</p>\n";
-
-                               echo "<form action=\"tables.php\" method=\"post\">\n";
-                               echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
-                       }
-                       echo "<input type=\"hidden\" name=\"action\" value=\"analyze\" />\n";
-                       echo $misc->form;
-
-                       echo "<input type=\"submit\" name=\"analyze\" value=\"{$lang['stranalyze']}\" />\n"; //TODO
-                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
-                       echo "</form>\n";
-               } // END single analyze
-               else {
-                       //If multi drop
-                       if (is_array($_REQUEST['table'])) {
-                               $msg='';
-                               foreach($_REQUEST['table'] as $t) {
-                                       $status = $data->analyzeDB($t);
-                                       if ($status == 0)
-                                               $msg.= sprintf('%s: %s<br />', htmlentities($t), $lang['stranalyzegood']);
-                                       else {
-                                               doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($t), $lang['stranalyzebad']));
-                                               return;
-                                       }
-                               }
-                                // Everything went fine, back to the Default page....
-                                $_reload_browser = true;
-                                doDefault($msg);
-                       }
-                       else {
-                               $status = $data->analyzeDB($_POST['table']);
-                               if ($status == 0) {
-                                       $_reload_browser = true;
-                                       doDefault($lang['stranalyzegood']);
-                               }
-                               else
-                                       doDefault($lang['stranalyzebad']);
-                       }
-               }
-       }
-
        /**
         * Show default list of tables in the database
         */
                                'vars'  => array('table' => 'relname'),
                                'multiaction' => 'confirm_analyze',
                        ),
+                       'reindex' => array(
+                               'title' => $lang['strreindex'],
+                               'url'   => "tables.php?action=confirm_reindex&amp;{$misc->href}&amp;",
+                               'vars'  => array('table' => 'relname'),
+                               'multiaction' => 'confirm_reindex',
+                       ),
                );
 
                if (!$data->hasTablespaces()) unset($columns['tablespace']);
                        echo "\t<li><a href=\"tables.php?action=createlike&amp;{$misc->href}\">{$lang['strcreatetablelike']}</a></li>\n";
                echo "</ul>\n";
        }
+       
+       require('./admin.php');
 
        /**
         * Generate XML for the browser tree.
                case 'confirm_drop':
                        doDrop(true);
                        break;
-               case 'vacuum':
-                       if (isset($_POST['vacuum'])) doVacuum(false);
-                       else doDefault();
-                       break;
-               case 'confirm_vacuum':
-                       doVacuum(true);
-                       break;
-               case 'analyze':
-                       if (isset($_POST['analyze'])) doAnalyze(false);
-                       else doDefault();
-                       break;
-               case 'confirm_analyze':
-                       doAnalyze(true);
-                       break;
                default:
-                       doDefault();
+                       if (adminActions($action, 'table') === false) doDefault();
                        break;
        }