From d038e9237a4c582e4b12071a8218e25b35356706 Mon Sep 17 00:00:00 2001 From: xzilla Date: Sat, 30 Sep 2006 17:30:56 +0000 Subject: [PATCH] Allow basic editing of existing rows of pg_autovacuum from the admin section. Also display whether autovacuum is turned on. --- classes/database/Postgres73.php | 14 +++- database.php | 126 +++++++++++++++++++++++++++----- lang/english.php | 4 +- lang/recoded/english.php | 4 +- 4 files changed, 125 insertions(+), 23 deletions(-) diff --git a/classes/database/Postgres73.php b/classes/database/Postgres73.php index f142bc8e..0db00e4a 100644 --- a/classes/database/Postgres73.php +++ b/classes/database/Postgres73.php @@ -4,7 +4,7 @@ * A class that implements the DB interface for Postgres * Note: This class uses ADODB and returns RecordSets. * - * $Id: Postgres73.php,v 1.159 2006/09/24 23:42:41 xzilla Exp $ + * $Id: Postgres73.php,v 1.160 2006/09/30 17:30:56 xzilla Exp $ */ // @@@ THOUGHT: What about inherits? ie. use of ONLY??? @@ -248,6 +248,16 @@ class Postgres73 extends Postgres72 { return $this->endTransaction(); } + /** + * Returns the specified variable information. + * @return the field + */ + function getVariable($setting) { + $sql = "SHOW $setting"; + + return $this->selectSet($sql); + } + /** * Returns all available variable information. * @return A recordset @@ -257,7 +267,7 @@ class Postgres73 extends Postgres72 { return $this->selectSet($sql); } - + /** * Returns all available process information. * @param $database (optional) Find only connections to specified database diff --git a/database.php b/database.php index 52377bdc..a660bb30 100755 --- a/database.php +++ b/database.php @@ -3,7 +3,7 @@ /** * Manage schemas within a database * - * $Id: database.php,v 1.87 2006/09/28 13:04:00 xzilla Exp $ + * $Id: database.php,v 1.88 2006/09/30 17:30:56 xzilla Exp $ */ // Include application functions @@ -332,8 +332,7 @@ global $lang; // Fetch the variables from the database - $variables = $data->getVariables(); - + $variables = $data->getVariables(); $misc->printTrail('database'); $misc->printTabs('database','variables'); @@ -583,7 +582,8 @@ echo "
"; if($data->hasAutovacuum()) { - echo "

{$lang['strautovacuum']}

"; + $enabled = $data->getVariable('autovacuum'); + echo "

{$lang['strautovacuum']} ". (($enabled->f['autovacuum'] == 'on') ? $lang['strturnedon'] : $lang['strturnedoff'] ) ."

"; // Autovacuum // Fetch the processes from the database $autovac = $data->getAutovacuum(); @@ -633,8 +633,8 @@ $actions = array( 'edit' => array( 'title' => $lang['stredit'], - 'url' => "{$PHP_SELF}?action=autovacuum&{$misc->href}&", - 'vars' => array('key' => 'vacrelid') + 'url' => "{$PHP_SELF}?action=editautovac&schema=pg_catalog&{$misc->href}&", + 'vars' => array('key[vacrelid]' => 'vacrelid') ), 'delete' => array( 'title' => $lang['strdelete'], @@ -650,23 +650,107 @@ } } - /** - * Modify specific entries in the autovacuum table - */ - function doAutovacuum() { - global $PHP_SELF, $data, $misc; + * Show confirmation of edit and perform actual update of autovacuum entry + */ + function doEditAutovacuum($confirm, $msg = '') { + global $data, $misc, $conf; global $lang; + global $PHP_SELF; - if (!isset($_REQUEST['query'])) $_REQUEST['query'] = ''; + $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 "
\n"; + $elements = 0; + $error = true; + if ($rs->recordCount() == 1 && $attrs->recordCount() > 0) { + echo "\n"; + + // Output table header + echo ""; + echo "\n"; + echo ""; + + $i = 0; + $nCC = 0; + while (!$attrs->EOF) { + $szValueName = "values[{$attrs->f['attname']}]"; + $szEvents = ""; + $szDivPH = ""; + + $attrs->f['attnotnull'] = $data->phpBool($attrs->f['attnotnull']); + $id = (($i % 2) == 0 ? '1' : '2'); + + // Initialise variables + if (!isset($_REQUEST['format'][$attrs->f['attname']])) + $_REQUEST['format'][$attrs->f['attname']] = 'VALUE'; + + echo "\n"; + echo ""; + echo ""; + $elements++; + echo "\n"; + $elements++; + + echo ""; + $elements++; + echo "\n"; + $i++; + $attrs->moveNext(); + } + echo "
{$lang['strcolumn']}{$lang['strtype']}{$lang['strformat']}{$lang['strvalue']}
", $misc->printVal($attrs->f['attname']), "\n"; + echo $misc->printVal($data->formatType($attrs->f['type'], $attrs->f['atttypmod'])); + echo "f['attname']), "]\" value=\"", + htmlspecialchars($attrs->f['type']), "\" />\n"; + echo "\n"; + echo $data->printField($szValueName, $rs->f[$attrs->f['attname']], $attrs->f['type'],array(),$szEvents) . $szDivPH; + echo "
\n"; + $error = false; + } + elseif ($rs->recordCount() != 1) { + echo "

{$lang['strrownotunique']}

\n"; + } + else { + echo "

{$lang['strinvalidparam']}

\n"; + } - echo " editing a specific autovacuum row goes here "; + echo "\n"; + echo $misc->form; + echo "\n"; + echo "\n"; + echo "

"; + if (!$error) echo "\n"; + echo "\n"; + echo "

\n"; + echo "
\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']); + } - $misc->printTrail('database'); - $misc->printTabs('database','admin'); + } - } /** * Delete rows from the autovacuum table @@ -816,6 +900,13 @@ 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; @@ -823,9 +914,6 @@ if (isset($_POST['yes'])) doDelAutovacuum(false); else doAdmin(); break; - case 'autovacuum': - doAutovacuum(); - break; default: doSQL(); break; diff --git a/lang/english.php b/lang/english.php index a9251240..201f659d 100755 --- a/lang/english.php +++ b/lang/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.196 2006/09/14 20:54:27 xzilla Exp $ + * $Id: english.php,v 1.197 2006/09/30 17:30:56 xzilla Exp $ */ // Language and character set @@ -849,6 +849,8 @@ //Autovacuum $lang['strautovacuum'] = 'Autovacuum'; + $lang['strturnedon'] = 'Turned On'; + $lang['strturnedoff'] = 'Turned Off'; $lang['strenabled'] = 'Enabled'; $lang['strvacuumbasethreshold'] = 'Vacuum Base Threshold'; $lang['strvacuumscalefactor'] = 'Vacuum Scale Factor'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index 2d13005e..903e6fac 100644 --- a/lang/recoded/english.php +++ b/lang/recoded/english.php @@ -4,7 +4,7 @@ * English language file for phpPgAdmin. Use this as a basis * for new translations. * - * $Id: english.php,v 1.149 2006/09/14 20:54:27 xzilla Exp $ + * $Id: english.php,v 1.150 2006/09/30 17:30:56 xzilla Exp $ */ // Language and character set @@ -849,6 +849,8 @@ //Autovacuum $lang['strautovacuum'] = 'Autovacuum'; + $lang['strturnedon'] = 'Turned On'; + $lang['strturnedoff'] = 'Turned Off'; $lang['strenabled'] = 'Enabled'; $lang['strvacuumbasethreshold'] = 'Vacuum Base Threshold'; $lang['strvacuumscalefactor'] = 'Vacuum Scale Factor'; -- 2.39.5