More randomness. This is just so I can play with it at work.
authorchriskl <chriskl>
Sun, 15 May 2005 14:27:16 +0000 (14:27 +0000)
committerchriskl <chriskl>
Sun, 15 May 2005 14:27:16 +0000 (14:27 +0000)
classes/plugins/Slony.php
database.php
libraries/lib.inc.php

index c3223a4db31cde51548ed29d03e590b085cbc169..fd9254a892fcb06dcb20c4646b7c77d152025b3b 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * 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');
@@ -11,6 +11,10 @@ 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
@@ -19,6 +23,42 @@ class Slony extends Plugin {
                $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
@@ -39,7 +79,10 @@ class Slony extends Plugin {
        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);
        }
@@ -50,8 +93,11 @@ class Slony extends Plugin {
        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);
        }
@@ -62,8 +108,11 @@ class Slony extends Plugin {
        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";
index a3aee0cada3c6f1a7e6e4e3b93b1ebe9dcfbaf9e..870100b85943ee5b85d5a04d0b1289916c710532 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * 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');
index b299ded0bda2f0ec6157a1fc7205da19177ba8e1..1b63c8c870be68a5ef3b61183211a279db207b3b 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * 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);
-
 ?>