/**
* A class that implements the Slony 1.0.x support plugin
*
- * $Id: Slony.php,v 1.1.2.1 2005/05/11 15:48:03 chriskl Exp $
+ * $Id: Slony.php,v 1.1.2.2 2005/05/15 14:27:16 chriskl Exp $
*/
include_once('./classes/plugins/Plugin.php');
class Slony extends Plugin {
var $config = 'slony.inc.php';
+ var $category = 'Replication';
+ var $slony_version;
+ var $slony_schema;
+ var $slony_cluster;
/**
* Constructor
$this->Plugin('slony');
}
+ /**
+ * Determines whether or not Slony is installed in the current
+ * database.
+ * @post Will populate version and schema fields, etc.
+ * @return True if Slony is installed, false otherwise.
+ */
+ function isEnabled() {
+ global $data;
+
+ // Slony needs schemas
+ if (!$data->hasSchemas()) return false;
+
+ // Check for the slonyversion() function and find the schema
+ // it's in.
+ $sql = "SELECT pn.nspname AS schema, SUBSTRING(pn.nspname FROM 2) AS cluster FROM pg_proc pp, pg_namespace pn
+ WHERE pp.pronamespace=pn.oid
+ AND pp.proname='slonyversion'
+ AND pn.nspname LIKE '\\\\_%'";
+ $rs = $data->selectSet($sql);
+ if ($rs->recordCount() == 1) {
+ $schema = $rs->f['schema'];
+ $this->slony_schema = $schema;
+ // Cluster name is schema minus "_" prefix.
+ $this->slony_cluster = $rs->f['cluster'];
+ $data->fieldClean($schema);
+ $sql = "SELECT \"{$schema}\".slonyversion() AS version";
+ $version = $data->selectField($sql, 'version');
+ if ($version === -1) return false;
+ else {
+ $this->slony_version = $version;
+ return true;
+ }
+ }
+ else return false;
+ }
+
/**
* Gets the database tab details
* @return array The array of tab details, null for none
function getNodes() {
global $data;
- $sql = "SELECT * FROM sl_node ORDER BY no_id";
+ $schema = $this->slony_schema;
+ $data->fieldClean($schema);
+
+ $sql = "SELECT * FROM \"{$schema}\".sl_node ORDER BY no_id";
return $data->selectSet($sql);
}
function getNode($no_id) {
global $data;
$data->clean($no_id);
+
+ $schema = $this->slony_schema;
+ $data->fieldClean($schema);
- $sql = "SELECT * FROM sl_node WHERE no_id='{$no_id}'";
+ $sql = "SELECT * FROM \"{$schema}\".sl_node WHERE no_id='{$no_id}'";
return $data->selectSet($sql);
}
function getNodeClients($no_id) {
global $data;
$data->clean($no_id);
+
+ $schema = $this->slony_schema;
+ $data->fieldClean($schema);
- $sql = "SELECT * FROM sl_path sp, sl_node sn
+ $sql = "SELECT * FROM \"{$schema}\".sl_path sp, \"{$schema}\".sl_node sn
WHERE sp.pa_client=sn.no_id
AND pa_server='{$no_id}'
ORDER BY sn.no_id";
/**
* Manage schemas within a database
*
- * $Id: database.php,v 1.66 2005/05/02 15:47:23 chriskl Exp $
+ * $Id: database.php,v 1.66.2.1 2005/05/15 14:27:16 chriskl Exp $
*/
// Include application functions
}
function doSubTree() {
- global $misc, $data, $lang;
+ global $misc, $data, $lang, $slony;
include_once('classes/ArrayRecordSet.php');
$tabs = $misc->getNavTabs('schema');
if (isset($tab['hide']) && $tab['hide'] === true)
unset($tabs[$i]);
}
+
+ $tabs['slony'] = array (
+ 'title' => 'Slony',
+ 'url' => 'plugin_slony.php',
+ 'urlvars' => array('subject' => 'slony'),
+ 'hide' => (!$slony->isEnabled()),
+ 'help' => ''
+ );
+
+
$items =& new ArrayRecordSet($tabs);
$reqvars = $misc->getRequestVars('schema');
/**
* Function library read in upon startup
*
- * $Id: lib.inc.php,v 1.94.2.1 2005/05/11 15:48:03 chriskl Exp $
+ * $Id: lib.inc.php,v 1.94.2.2 2005/05/15 14:27:16 chriskl Exp $
*/
include_once('decorator.inc.php');
include_once('./lang/translations.php');
else
$lang['appcharset'] = $dbEncoding;
}
+
+ // XXX: THIS IS A TEMPORARY HACK TO GET SLONY OBJECT LOADED
+ include('./classes/plugins/Slony.php');
+ $slony = new Slony();
+ if ($slony->isEnabled()) {
+ $plugins = array(&$slony);
+ }
+ else $plugins = array();
+
}
- // XXX: THIS IS A TEMPORARY HACK TO GET SLONY OBJECT LOADED
- include('./classes/plugins/Slony.php');
- $slony = new Slony();
- $plugins = array(&$slony);
-
?>