printTrail('schema');
$misc->printTitle($lang['strclusterindex'], 'pg.index.cluster');
echo "
\n";
} // END single cluster
else {
//If multi table cluster
if ($type == 'table') { // cluster one or more table
if (is_array($_REQUEST['table'])) {
$msg='';
foreach($_REQUEST['table'] as $o) {
$status = $data->clusterIndex($o);
if ($status == 0)
$msg.= sprintf('%s: %s
', htmlentities($o), $lang['strclusteredgood']);
else {
doDefault($type, sprintf('%s%s: %s
', $msg, htmlentities($o), $lang['strclusteredbad']));
return;
}
}
// Everything went fine, back to the Default page....
doDefault($msg);
}
else {
$status = $data->clusterIndex($_REQUEST['object']);
if ($status == 0) {
doAdmin($type, $lang['strclusteredgood']);
}
else
doAdmin($type, $lang['strclusteredbad']);
}
}
else { // Cluster all tables in database
$status = $data->clusterIndex();
if ($status == 0) {
doAdmin($type, $lang['strclusteredgood']);
}
else
doAdmin($type, $lang['strclusteredbad']);
}
}
}
/**
* 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 "\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
', htmlentities($o), $lang['strreindexgood']);
else {
doDefault($type, sprintf('%s%s: %s
', $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 "\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
', htmlentities($o), $lang['stranalyzegood']);
else {
doDefault($type, sprintf('%s%s: %s
', $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 "\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
', htmlentities($t), $lang['strvacuumgood']);
else {
doDefault($type, sprintf('%s%s: %s
', $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 "\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("{$lang['strdelvacuumtable']}
\n",
$misc->printVal("\"{$_GET['schema']}"."{$_GET['table']}\""));
echo "\n";
echo "\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("{$lang['stradminondatabase']}
\n", $misc->printVal($_REQUEST['object']));
else
printf("{$lang['stradminontable']}
\n", $misc->printVal($_REQUEST['object']));
echo "\n";
echo "\n";
echo "";
$misc->printHelp($lang['strvacuum'],'pg.admin.vacuum')." | \n";
echo "";
echo "";
$misc->printHelp($lang['stranalyze'],'pg.admin.analyze');
echo " | ";
if ($data->hasRecluster()){
echo "";
$misc->printHelp($lang['strclusterindex'],'pg.index.cluster');
echo " | ";
}
echo "";
$misc->printHelp($lang['strreindex'],'pg.index.reindex');
echo " | ";
echo "
";
// Vacuum
echo "\n";
echo "\n";
echo "\n";
echo " | \n";
// Analyze
echo "\n";
echo "\n";
echo " | \n";
// Cluster
if ($data->hasRecluster()){
$disabled = '';
echo "\n";
echo "\n";
echo " | \n";
}
// Reindex
echo "\n";
echo "\n";
echo " | \n";
echo "
\n";
echo "
\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 "
{$lang['strvacuumpertable']}
";
echo '' . (($defaults['autovacuum'] == 'on') ? $lang['strturnedon'] : $lang['strturnedoff'] ) . '
';
echo "{$lang['strnotdefaultinred']}
";
function enlight($f, $p) {
if ( isset($f[$p[0]]) and ($f[$p[0]] != $p[1]))
return "". htmlspecialchars($f[$p[0]]) ."";
return htmlspecialchars($p[1]);
}
$columns = array(
'namespace' => array(
'title' => $lang['strschema'],
'field' => field('nspname'),
'url' => "redirect.php?subject=schema&{$misc->href}&",
'vars' => array('schema' => 'nspname'),
),
'relname' => array(
'title' => $lang['strtable'],
'field' => field('relname'),
'url' => "redirect.php?subject=table&{$misc->href}&",
'vars' => array('table' => 'relname', 'schema' => 'nspname'),
),
'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&{$misc->href}&subject={$type}&",
'vars' => array(
'schema' => 'nspname',
'table' => 'relname'
)
),
'delete' => array(
'title' => $lang['strdelete'],
'url' => "{$script}?action=confdelautovac&{$misc->href}&subject={$type}&",
'vars' => array(
'schema' => 'nspname',
'table' => 'relname'
)
)
);
if ($type == 'table') {
unset($actions['edit']['vars']['schema'],
$actions['delete']['vars']['schema'],
$columns['namespace'],
$columns['relname']
);
}
$misc->printTable($autovac, $columns, $actions, $lang['strnovacuumconf']);
if (($type == 'table') and ($autovac->recordCount() == 0)) {
echo "
";
echo "href}&table=", htmlspecialchars($_REQUEST['table'])
,"\">{$lang['straddvacuumtable']}";
}
}
}
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_cluster':
doCluster($type, true);
break;
case 'confirm_reindex':
doReindex($type, true);
break;
case 'confirm_analyze':
doAnalyze($type, true);
break;
case 'confirm_vacuum':
doVacuum($type, true);
break;
case 'cluster':
if (isset($_POST['cluster'])) doCluster($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 '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;
}
?>