/**
* A class that implements the Slony 1.0.x support plugin
*
- * $Id: Slony.php,v 1.1.2.8 2005/06/01 15:11:44 chriskl Exp $
+ * $Id: Slony.php,v 1.1.2.9 2005/06/02 14:51:46 chriskl Exp $
*/
include_once('./classes/plugins/Plugin.php');
var $slony_version;
var $slony_schema;
var $slony_cluster;
+ var $slony_owner;
/**
* 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, SUBSTRING(pn.nspname FROM 2) AS cluster FROM pg_proc pp, pg_namespace pn
+ $sql = "SELECT pn.nspname AS schema, pu.usename AS owner, SUBSTRING(pn.nspname FROM 2) AS cluster
+ 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
AND pp.proname='slonyversion'
AND pn.nspname LIKE '\\\\_%'
ORDER BY pn.nspname LIMIT 1";
if ($rs->recordCount() == 1) {
$schema = $rs->f['schema'];
$this->slony_schema = $schema;
+ $this->slony_owner = $rs->f['owner'];
// Cluster name is schema minus "_" prefix.
$this->slony_cluster = $rs->f['cluster'];
$data->fieldClean($schema);
);
}
+ // CLUSTER
+
+ /**
+ * Gets a single cluster
+ */
+ function getCluster() {
+ global $data;
+
+ $schema = $this->slony_schema;
+ $data->fieldClean($schema);
+ $data->clean($no_id);
+
+ $sql = "SELECT no_id, no_comment, \"{$schema}\".slonyversion() AS version
+ FROM \"{$schema}\".sl_local_node_id, \"{$schema}\".sl_node
+ WHERE no_id=last_value";
+
+
+ return $data->selectSet($sql);
+ }
+
// NODES
/**
$data->fieldClean($schema);
$data->clean($set_id);
- $sql = "SELECT * FROM \"{$schema}\".sl_set WHERE set_id='{$set_id}'";
+ $sql = "SELECT *, (SELECT COUNT(*) FROM \"{$schema}\".sl_subscribe ssub WHERE ssub.sub_set=ss.set_id) AS subscriptions
+ FROM \"{$schema}\".sl_set ss, \"{$schema}\".sl_node sn
+ WHERE ss.set_origin=sn.no_id
+ AND set_id='{$set_id}'";
return $data->selectSet($sql);
}
$data->fieldClean($schema);
$data->clean($set_id);
- $sql = "SELECT sn.*
+ $sql = "SELECT sn.*, ss.sub_set
FROM \"{$schema}\".sl_subscribe ss, \"{$schema}\".sl_node sn
WHERE ss.sub_set='{$set_id}'
AND ss.sub_receiver = sn.no_id
return $data->selectSet($sql);
}
+ /**
+ * Gets all nodes subscribing to a set
+ * @param $set_id The ID of the replication set
+ * @return Nodes subscribing to this set
+ */
+ function getSubscription($set_id, $no_id) {
+ global $data;
+
+ $schema = $this->slony_schema;
+ $data->fieldClean($schema);
+ $data->clean($set_id);
+ $data->clean($no_id);
+
+ $sql = "SELECT ss.*, sn.no_comment AS receiver, sn2.no_comment AS provider
+ FROM \"{$schema}\".sl_subscribe ss, \"{$schema}\".sl_node sn, \"{$schema}\".sl_node sn2
+ WHERE ss.sub_set='{$set_id}'
+ AND ss.sub_receiver = sn.no_id
+ AND ss.sub_provider = sn2.no_id
+ AND sn.no_id='{$no_id}'";
+
+ return $data->selectSet($sql);
+ }
+
// NODES
/**
/**
* Slony database tab plugin
*
- * $Id: plugin_slony.php,v 1.1.2.7 2005/06/01 15:11:44 chriskl Exp $
+ * $Id: plugin_slony.php,v 1.1.2.8 2005/06/02 14:51:45 chriskl Exp $
*/
// Include application functions
'icon' => field('icon', 'folder'),
'action' => url(field('url'),
$reqvars,
- field('urlvars', array())
+ array(
+ 'action' => 'cluster_properties'
+ )
),
'branch' => url(field('url'),
$reqvars,
$attrs = array(
'text' => field('set_comment'),
'icon' => 'folder',
- 'action' => url('redirect.php',
+ 'action' => url('plugin_slony.php',
$reqvars,
array(
'action' => 'set_properties',
'icon' => field('icon', 'folder'),
'action' => url(field('url'),
$reqvars,
- field('urlvars', array())
+ field('urlvars', array()),
+ array('action' => 'subscriptions_properties', 'set_id' => $_REQUEST['set_id'])
),
'branch' => url(field('url'),
$reqvars,
'icon' => field('icon', 'folder'),
'action' => url('plugin_slony.php',
$reqvars,
- array('no_id' => field('no_id'))
+ array('set_id' => field('sub_set'), 'no_id' => field('no_id'), 'action' => 'subscription_properties')
)
);
exit;
}
+ /**
+ * Display the properties of a slony cluster
+ */
+ function doCluster($msg = '') {
+ global $data, $slony, $misc, $PHP_SELF;
+ global $lang;
+
+ $misc->printTrail('slony_cluster');
+ $misc->printTitle($lang['strproperties']);
+ $misc->printMsg($msg);
+
+ // Fetch the cluster information
+ $cluster = &$slony->getCluster();
+
+ if (is_object($cluster) && $cluster->recordCount() > 0) {
+ // Display domain info
+ echo "<table>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">{$lang['strname']}</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($slony->slony_cluster), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Local Node ID</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($cluster->f['no_id']), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Local Node</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($cluster->f['no_comment']), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Version</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($cluster->f['version']), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">{$lang['strowner']}</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($slony->slony_owner), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">{$lang['strcomment']}</th>\n";
+ echo "<td class=\"data1\"></td></tr>\n";
+ echo "</table>\n";
+ }
+ else echo "<p>{$lang['strnodata']}</p>\n";
+ }
+
/**
* List all the nodes
*/
echo "<td class=\"data1\">", $misc->printVal($set->f['set_comment']), "</td></tr>\n";
echo "<tr><th class=\"data left\" width=\"70\">ID</th>\n";
echo "<td class=\"data1\">", $misc->printVal($set->f['set_id']), "</td></tr>\n";
- echo "<tr><th class=\"data left\" width=\"70\">Locked</th>\n";
- echo "<td class=\"data1\">", $misc->printVal($set->f['set_locked']), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Origin ID</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($set->f['set_origin']), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Origin Node</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($set->f['no_comment']), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Subscriptions</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($set->f['subscriptions']), "</td></tr>\n";
echo "<tr><th class=\"data left\" width=\"70\">{$lang['strcomment']}</th>\n";
echo "<td class=\"data1\">", $misc->printVal($set->f['set_comment']), "</td></tr>\n";
echo "</table>\n";
else echo "<p>{$lang['strnodata']}</p>\n";
}
+ /**
+ * List all the subscriptions
+ */
+ function doSubscriptions($msg = '') {
+ global $slony, $misc;
+ global $lang;
+
+ $misc->printTrail('database');
+ $misc->printMsg($msg);
+
+ $subscriptions = $slony->getSubscribedNodes($_REQUEST['set_id']);
+
+ $columns = array(
+ 'no_name' => array(
+ 'title' => $lang['strname'],
+ 'field' => 'no_comment'
+ ),
+ 'actions' => array(
+ 'title' => $lang['stractions'],
+ ),
+ 'no_comment' => array(
+ 'title' => $lang['strcomment'],
+ 'field' => 'no_comment'
+ )
+ );
+
+ $actions = array (
+ 'detail' => array(
+ 'title' => $lang['strproperties'],
+ 'url' => "plugin_slony.php?{$misc->href}&action=subscription_properties&",
+ 'vars' => array('set_id' => 'sub_set', 'no_id' => 'no_id')
+ )
+ );
+
+ $misc->printTable($subscriptions, $columns, $actions, 'No subscriptions found.');
+ }
+
+ /**
+ * Display the properties of a subscription
+ */
+ function doSubscription($msg = '') {
+ global $data, $slony, $misc, $PHP_SELF;
+ global $lang;
+
+ $misc->printTrail('slony_subscription');
+ $misc->printTitle($lang['strproperties']);
+ $misc->printMsg($msg);
+
+ // Fetch the subscription information
+ $subscription = &$slony->getSubscription($_REQUEST['set_id'], $_REQUEST['no_id']);
+
+ if (is_object($subscription) && $subscription->recordCount() > 0) {
+ // Show comment if any
+ if ($subscription->f['receiver'] !== null)
+ echo "<p class=\"comment\">", $misc->printVal($subscription->f['receiver']), "</p>\n";
+
+ // Display domain info
+ echo "<table>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Provider ID</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($subscription->f['sub_provider']), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Provider Name</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($subscription->f['provider']), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Receiver ID</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($subscription->f['sub_receiver']), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Receiver Name</th>\n";
+ echo "<td class=\"data1\">", $misc->printVal($subscription->f['receiver']), "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">Active</th>\n";
+ echo "<td class=\"data1\">", ($data->phpBool($subscription->f['sub_active'])) ? $lang['stryes'] : $lang['strno'], "</td></tr>\n";
+ echo "<tr><th class=\"data left\" width=\"70\">May Forward</th>\n";
+ echo "<td class=\"data1\">", ($data->phpBool($subscription->f['sub_forward'])) ? $lang['stryes'] : $lang['strno'], "</td></tr>\n";
+ echo "</table>\n";
+ }
+ else echo "<p>{$lang['strnodata']}</p>\n";
+ }
+
// Tree actions
if ($action == 'tree') doTree('clusters');
elseif ($action == 'clusters_top') doTree('clusters_top');
case 'set_properties':
doReplicationSet();
break;
+ case 'subscriptions_properties':
+ doSubscriptions();
+ break;
+ case 'subscription_properties':
+ doSubscription();
+ break;
+ case 'cluster_properties':
+ doCluster();
+ break;
default:
// Shouldn't happen
}