/**
* A class that implements the Slony 1.0.x support plugin
*
- * $Id: Slony.php,v 1.1.2.10 2005/06/02 15:21:48 chriskl Exp $
+ * $Id: Slony.php,v 1.1.2.11 2005/06/05 14:13:20 chriskl Exp $
*/
include_once('./classes/plugins/Plugin.php');
var $slony_schema;
var $slony_cluster;
var $slony_owner;
+ var $slony_comment;
/**
* Constructor
// it's in. We put an order by and limit 1 in here to guarantee
// only finding the first one, even if there are somehow two
// Slony schemas.
- $sql = "SELECT pn.nspname AS schema, pu.usename AS owner, SUBSTRING(pn.nspname FROM 2) AS cluster
+ $sql = "SELECT pn.nspname AS schema, pu.usename AS owner, SUBSTRING(pn.nspname FROM 2) AS cluster,
+ pg_catalog.obj_description(pn.oid, 'pg_namespace') AS nspcomment
FROM pg_catalog.pg_proc pp, pg_catalog.pg_namespace pn, pg_catalog.pg_user pu
WHERE pp.pronamespace=pn.oid
AND pn.nspowner = pu.usesysid
$schema = $rs->f['schema'];
$this->slony_schema = $schema;
$this->slony_owner = $rs->f['owner'];
+ $this->slony_comment = $rs->f['nspcomment'];
// Cluster name is schema minus "_" prefix.
$this->slony_cluster = $rs->f['cluster'];
$data->fieldClean($schema);
else return false;
}
- // CLUSTER
+ // CLUSTERS
/**
* Gets the clusters in this database
function getClusters() {
include_once('classes/ArrayRecordSet.php');
- $clusters = array(array('cluster' => $this->slony_cluster, 'comment' => ''));
+ $clusters = array(array('cluster' => $this->slony_cluster, 'comment' => $this->slony_comment));
return new ArrayRecordSet($clusters);
}
return $data->selectSet($sql);
}
+ /**
+ * Drops an entire cluster.
+ */
+ function dropCluster() {
+ $schema = $this->slony_schema;
+ $data->fieldClean($schema);
+
+ $sql = "SELECT \"{$schema}\".uninstallnode(); DROP SCHEMA \"{$schema}\" CASCADE";
+
+ return $this->execute($sql);
+ }
+
// NODES
/**
return $data->selectSet($sql);
}
+ /**
+ * Creates a node
+ */
+ function createNode($no_id, $no_comment) {
+ global $data;
+
+ $schema = $this->slony_schema;
+ $data->fieldClean($schema);
+ $data->clean($no_comment);
+ $data->clean($no_id);
+
+ if ($no_id != '')
+ $sql = "SELECT \"{$schema}\".storenode('{$no_id}', '{$no_comment}')";
+ else
+ $sql = "SELECT \"{$schema}\".storenode((SELECT COALESCE(MAX(no_id), 0) + 1 FROM \"{$schema}\".sl_node), '{$no_comment}')";
+
+ return $data->execute($sql);
+ }
+
+ /**
+ * Drops a node
+ */
+ function dropNode($no_id) {
+ global $data;
+
+ $schema = $this->slony_schema;
+ $data->fieldClean($schema);
+ $data->clean($no_id);
+
+ $sql = "SELECT \"{$schema}\".dropnode('{$no_id}')";
+
+ return $data->execute($sql);
+ }
+
+ // LISTENS
+
/**
* Gets node listens
*/
return $data->selectSet($sql);
}
+ // ACTIONS
+
+
+
}
?>
/**
* Slony database tab plugin
*
- * $Id: plugin_slony.php,v 1.1.2.9 2005/06/02 15:21:47 chriskl Exp $
+ * $Id: plugin_slony.php,v 1.1.2.10 2005/06/05 14:13:20 chriskl Exp $
*/
// Include application functions
'title' => $lang['strproperties'],
'url' => "plugin_slony.php?{$misc->href}&action=cluster_properties&",
'vars' => array()
+ ),
+ 'drop' => array(
+ 'title' => $lang['strdrop'],
+ 'url' => "plugin_slony.php?{$misc->href}&action=confirm_drop_cluster&",
+ 'vars' => array()
)
);
$misc->printTable($clusters, $columns, $actions, 'No clusters found.');
}
+ // CLUSTERS
+
/**
* Display the properties of a slony cluster
*/
else echo "<p>{$lang['strnodata']}</p>\n";
}
+ /**
+ * Show confirmation of drop and perform actual drop of a cluster
+ */
+ function doDropCluster($confirm) {
+ global $slony, $misc;
+ global $PHP_SELF, $lang;
+
+ if ($confirm) {
+ $misc->printTrail('slony_cluster');
+ $misc->printTitle($lang['strdrop']);
+
+ // XXX: N
+ echo "<p>", sprintf('Are you sure you want to drop Slony cluster "%s"?', $misc->printVal($slony->clony_cluster)), "</p>\n";
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
+ echo $misc->form;
+ echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $slony->dropCluster();
+ if ($status == 0)
+ doDefault('Cluster dropped.');
+ else
+ doDefault('Failed dropping cluster.');
+ }
+ }
+
+ // NODES
+
/**
* List all the nodes
*/
function doNodes($msg = '') {
- global $slony, $misc;
+ global $PHP_SELF, $slony, $misc;
global $lang;
- $misc->printTrail('database');
+ $misc->printTrail('slony_nodes');
$misc->printMsg($msg);
$nodes = $slony->getNodes();
'title' => $lang['strproperties'],
'url' => "plugin_slony.php?{$misc->href}&action=node_properties&",
'vars' => array('no_id' => 'no_id')
+ ),
+ 'drop' => array(
+ 'title' => $lang['strdrop'],
+ 'url' => "plugin_slony.php?{$misc->href}&action=confirm_drop_node&",
+ 'vars' => array('no_id' => 'no_id')
)
);
$misc->printTable($nodes, $columns, $actions, 'No nodes found.');
+
+ echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=create_node&{$misc->href}\">Create Node</a></p>\n";
}
/**
echo "</table>\n";
}
else echo "<p>{$lang['strnodata']}</p>\n";
+
+ echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=confirm_drop_node&{$misc->href}&no_id={$_REQUEST['no_id']}\">Drop</a></p>\n";
+ }
+
+ /**
+ * Displays a screen where they can enter a new node
+ */
+ function doCreateNode($confirm, $msg = '') {
+ global $slony, $misc;
+ global $PHP_SELF, $lang;
+
+ if ($confirm) {
+ if (!isset($_POST['nodeid'])) $_POST['nodeid'] = '';
+ if (!isset($_POST['nodecomment'])) $_POST['nodecomment'] = '';
+
+ $misc->printTrail('slony_nodes');
+ $misc->printTitle('Create Node');
+ $misc->printMsg($msg);
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo $misc->form;
+ echo "<table width=\"100%\">\n";
+ echo "\t<tr>\n\t\t<th class=\"data left\">ID</th>\n";
+ echo "\t\t<td class=\"data1\"><input name=\"nodeid\" size=\"5\" value=\"",
+ htmlspecialchars($_POST['nodeid']), "\" /></td>\n\t</tr>\n";
+ echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
+ echo "\t\t<td class=\"data1\"><textarea name=\"nodecomment\" rows=\"3\" cols=\"32\" wrap=\"virtual\">",
+ htmlspecialchars($_POST['nodecomment']), "</textarea></td>\n\t</tr>\n";
+
+ echo "\t</tr>\n";
+ echo "</table>\n";
+ echo "<p>\n";
+ echo "<input type=\"hidden\" name=\"action\" value=\"save_create_node\" />\n";
+ echo $misc->form;
+ echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
+ echo "</p>\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $slony->createNode($_POST['nodeid'], $_POST['nodecomment']);
+ if ($status == 0)
+ doNodes('Node created.');
+ else
+ doCreateNode(true, 'Failed creating node.');
+ }
}
+ /**
+ * Show confirmation of drop and perform actual drop of a node
+ */
+ function doDropNode($confirm) {
+ global $slony, $misc;
+ global $PHP_SELF, $lang;
+
+ if ($confirm) {
+ $misc->printTrail('slony_cluster');
+ $misc->printTitle($lang['strdrop']);
+
+ echo "<p>", sprintf('Are you sure you want to drop node "%s"?', $misc->printVal($_REQUEST['no_id'])), "</p>\n";
+
+ echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+ echo "<input type=\"hidden\" name=\"action\" value=\"drop_node\" />\n";
+ echo "<input type=\"hidden\" name=\"no_id\" value=\"", htmlspecialchars($_REQUEST['no_id']), "\" />\n";
+ echo $misc->form;
+ echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
+ echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
+ echo "</form>\n";
+ }
+ else {
+ $status = $slony->dropNode($_REQUEST['no_id']);
+ if ($status == 0)
+ doNodes('Node dropped.');
+ else
+ doNodes('Failed dropping node.');
+ }
+ }
+
+ // PATHS
+
/**
* List all the paths
*/
case 'node_properties':
doNode();
break;
+ case 'save_create_node':
+ if (isset($_POST['cancel'])) doNodes();
+ else doCreateNode(false);
+ break;
+ case 'create_node':
+ doCreateNode(true);
+ break;
+ case 'drop_node':
+ if (isset($_POST['cancel'])) doNodes();
+ else doDropNode(false);
+ break;
+ case 'confirm_drop_node':
+ doDropNode(true);
+ break;
case 'paths_properties':
doPaths();
break;