Add properties pages for nodes and replication sets.
authorchriskl <chriskl>
Sun, 29 May 2005 10:05:59 +0000 (10:05 +0000)
committerchriskl <chriskl>
Sun, 29 May 2005 10:05:59 +0000 (10:05 +0000)
classes/plugins/Slony.php
plugin_slony.php

index fbdd61591636c54f3af6b356eaeed66804d387b0..43b72162872f8f91382ddf1ac642cbf8da500c46 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * A class that implements the Slony 1.0.x support plugin
  *
- * $Id: Slony.php,v 1.1.2.5 2005/05/28 13:16:31 chriskl Exp $
+ * $Id: Slony.php,v 1.1.2.6 2005/05/29 10:06:00 chriskl Exp $
  */
 
 include_once('./classes/plugins/Plugin.php');
@@ -87,7 +87,7 @@ class Slony extends Plugin {
                $schema = $this->slony_schema;
                $data->fieldClean($schema);
                
-               $sql = "SELECT *, 'Node ' || no_id AS no_name FROM \"{$schema}\".sl_node ORDER BY no_comment";
+               $sql = "SELECT * FROM \"{$schema}\".sl_node ORDER BY no_comment";
                
                return $data->selectSet($sql);
        }
@@ -97,12 +97,12 @@ class Slony extends Plugin {
         */
        function getNode($no_id) {
                global $data;
-               $data->clean($no_id);
 
                $schema = $this->slony_schema;
                $data->fieldClean($schema);
+               $data->clean($no_id);
                
-               $sql = "SELECT *, 'Node ' || no_id AS no_name FROM \"{$schema}\".sl_node WHERE no_id='{$no_id}'";
+               $sql = "SELECT * FROM \"{$schema}\".sl_node WHERE no_id='{$no_id}'";
                
                return $data->selectSet($sql);
        }
@@ -136,7 +136,22 @@ class Slony extends Plugin {
                $schema = $this->slony_schema;
                $data->fieldClean($schema);
                
-               $sql = "SELECT *, 'Set ' || set_id AS set_name  FROM \"{$schema}\".sl_set ORDER BY set_id";
+               $sql = "SELECT * FROM \"{$schema}\".sl_set ORDER BY set_id";
+               
+               return $data->selectSet($sql);
+       }
+
+       /**
+        * Gets a particular replication set
+        */
+       function getReplicationSet($set_id) {
+               global $data;
+               
+               $schema = $this->slony_schema;
+               $data->fieldClean($schema);
+               $data->clean($set_id);
+               
+               $sql = "SELECT * FROM \"{$schema}\".sl_set WHERE set_id='{$set_id}'";
                
                return $data->selectSet($sql);
        }
@@ -158,7 +173,7 @@ class Slony extends Plugin {
                                        WHERE c.oid=st.tab_reloid
                                        AND c.relnamespace=n.oid
                                        AND st.tab_set='{$set_id}'
-                                       ORDER BY c.relname";
+                                       ORDER BY n.nspname, c.relname";
 
                return $data->selectSet($sql);
        }
@@ -180,7 +195,7 @@ class Slony extends Plugin {
                                        WHERE c.oid=ss.seq_reloid
                                        AND c.relnamespace=n.oid
                                        AND ss.seq_set='{$set_id}'
-                                       ORDER BY c.relname";
+                                       ORDER BY n.nspname, c.relname";
 
                return $data->selectSet($sql);
        }
index a2ccec13bb2b95f1f91adf624c65d9d8632e0688..d9b150b6fc92e0f1417b7d01f8b3c48a4542ba80 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Slony database tab plugin
         *
-        * $Id: plugin_slony.php,v 1.1.2.4 2005/05/28 13:16:31 chriskl Exp $
+        * $Id: plugin_slony.php,v 1.1.2.5 2005/05/29 10:05:59 chriskl Exp $
         */
 
        // Include application functions
        $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
        $PHP_SELF = $_SERVER['PHP_SELF'];
 
-       function doProperties() {
-               global $slony, $misc;
-               global $lang;
-
-               $misc->printTrail('database');
-               $misc->printTabs('database','slony');
-
-               $clients = $slony->getNodeClients($_REQUEST['no_id']);
-
-               echo "<h3>Clients</h3>\n";
-               
-               $columns = array(
-                       'no_id' => array(
-                               'title' => 'Node ID',
-                               'field' => 'no_id'
-                       ),
-                       'no_active' => array(
-                               'title' => 'Active',
-                               'field' => 'no_active'
-                       ),
-                       'no_spool' => array(
-                               'title' => 'Spool',
-                               'field' => 'no_spool'
-                       ),
-                       'pa_conninfo' => array(
-                               'title' => 'Connection',
-                               'field' => 'pa_conninfo'
-                       ),
-                       'pa_connretry' => array(
-                               'title' => 'Retry',
-                               'field' => 'pa_connretry'
-                       ),
-                       '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}&amp;action=properties&amp;",
-                               'vars'  => array('no_id' => 'no_id')
-                       )
-               );
-               
-               $misc->printTable($clients, $columns, $actions, 'No nodes found.');
-       }
-
+       /**
+        * Generate the somewhat complex Slony tree
+        * @param string $subject The tree node to return
+        */
        function doTree($subject) {
                global $misc, $data, $lang, $PHP_SELF, $slony;
 
                                        'icon'   => field('icon', 'folder'),
                                        'action' => url(field('url'),
                                                                        $reqvars,
-                                                                       field('urlvars', array())
+                                                                       field('urlvars', array()),
+                                                                       array('action' => 'nodes_properties')
                                                                ),
                                        'branch' => url(field('url'),
                                                                        $reqvars,
                                        'icon'   => field('icon', 'folder'),
                                        'action' => url(field('url'),
                                                                        $reqvars,
-                                                                       field('urlvars', array())
+                                                                       field('urlvars', array()),
+                                                                       array('action' => 'sets_properties')
                                                                ),
                                        'branch' => url(field('url'),
                                                                        $reqvars,
                                $attrs = array(
                                        'text'   => field('no_comment'),
                                        'icon'   => 'folder',
-                                       'action' => url('redirect.php',
+                                       'action' => url('plugin_slony.php',
                                                                        $reqvars,
                                                                        array(
+                                                                               'action'  => 'node_properties',
                                                                                'no_id' => field('no_id')
                                                                        )
                                                                ),
                                        'action' => url('redirect.php',
                                                                        $reqvars,
                                                                        array(
+                                                                               'action'  => 'set_properties',
                                                                                'set_id' => field('set_id')
                                                                        )
                                                                ),
        }
 
        /**
-        * List all the information on the table
+        * List all the nodes
         */
-       function doDefault($msg = '') {
+       function doNodes($msg = '') {
                global $slony, $misc;
                global $lang;
 
                $misc->printTrail('database');
-               $misc->printTabs('database','slony');
                $misc->printMsg($msg);
 
                $nodes = $slony->getNodes();
 
-               echo "<h3>Nodes</h3>\n";
-               
                $columns = array(
-                       'no_id' => array(
-                               'title' => 'Node ID',
-                               'field' => 'no_id'
-                       ),
-                       'no_active' => array(
-                               'title' => 'Active',
-                               'field' => 'no_active'
-                       ),
-                       'no_spool' => array(
-                               'title' => 'Spool',
-                               'field' => 'no_spool'
+                       'no_name' => array(
+                               'title' => $lang['strname'],
+                               'field' => 'no_comment'
                        ),
                        'actions' => array(
                                'title' => $lang['stractions'],
                $actions = array (
                        'detail' => array(
                                'title' => $lang['strproperties'],
-                               'url'   => "plugin_slony.php?{$misc->href}&amp;action=properties&amp;",
+                               'url'   => "plugin_slony.php?{$misc->href}&amp;action=node_properties&amp;",
                                'vars'  => array('no_id' => 'no_id')
                        )
                );
                
                $misc->printTable($nodes, $columns, $actions, 'No nodes found.');
        }
+       
+       /**
+        * Display the properties of a node
+        */      
+       function doNode($msg = '') {
+               global $data, $slony, $misc, $PHP_SELF;
+               global $lang;
+               
+               $misc->printTrail('slony_node');
+               $misc->printTitle($lang['strproperties']);
+               $misc->printMsg($msg);
+               
+               // Fetch the node information
+               $node = &$slony->getNode($_REQUEST['no_id']);           
+               
+               if (is_object($node) && $node->recordCount() > 0) {                     
+                       // Show comment if any
+                       if ($node->f['no_comment'] !== null)
+                               echo "<p class=\"comment\">", $misc->printVal($node->f['no_comment']), "</p>\n";
+
+                       // Display domain info
+                       echo "<table>\n";
+                       echo "<tr><th class=\"data left\" width=\"70\">{$lang['strname']}</th>\n";
+                       echo "<td class=\"data1\">", $misc->printVal($node->f['no_comment']), "</td></tr>\n";
+                       echo "<tr><th class=\"data left\" width=\"70\">ID</th>\n";
+                       echo "<td class=\"data1\">", $misc->printVal($node->f['no_id']), "</td></tr>\n";
+                       echo "<tr><th class=\"data left\" width=\"70\">Active</th>\n";
+                       echo "<td class=\"data1\">", ($data->phpBool($node->f['no_active'])) ? $lang['stryes'] : $lang['strno'], "</td></tr>\n";
+                       echo "<tr><th class=\"data left\" width=\"70\">{$lang['strcomment']}</th>\n";
+                       echo "<td class=\"data1\">", $misc->printVal($node->f['no_comment']), "</td></tr>\n";
+                       echo "</table>\n";
+               }
+               else echo "<p>{$lang['strnodata']}</p>\n";
+       }
 
+       /**
+        * List all the replication sets
+        */
+       function doReplicationSets($msg = '') {
+               global $slony, $misc;
+               global $lang;
+
+               $misc->printTrail('database');
+               $misc->printMsg($msg);
+
+               $sets = $slony->getReplicationSets();
+
+               $columns = array(
+                       'set_name' => array(
+                               'title' => $lang['strname'],
+                               'field' => 'set_comment'
+                       ),
+                       'actions' => array(
+                               'title' => $lang['stractions'],
+                       ),
+                       'set_comment' => array(
+                               'title' => $lang['strcomment'],
+                               'field' => 'set_comment'
+                       )
+               );
+               
+               $actions = array (
+                       'detail' => array(
+                               'title' => $lang['strproperties'],
+                               'url'   => "plugin_slony.php?{$misc->href}&amp;action=set_properties&amp;",
+                               'vars'  => array('set_id' => 'set_id')
+                       )
+               );
+               
+               $misc->printTable($sets, $columns, $actions, 'No sets found.');
+       }       
+
+       /**
+        * Display the properties of a replication set
+        */      
+       function doReplicationSet($msg = '') {
+               global $data, $slony, $misc, $PHP_SELF;
+               global $lang;
+               
+               $misc->printTrail('slony_set');
+               $misc->printTitle($lang['strproperties']);
+               $misc->printMsg($msg);
+               
+               // Fetch the set information
+               $set = &$slony->getReplicationSet($_REQUEST['set_id']);         
+               
+               if (is_object($set) && $set->recordCount() > 0) {                       
+                       // Show comment if any
+                       if ($set->f['set_comment'] !== null)
+                               echo "<p class=\"comment\">", $misc->printVal($set->f['set_comment']), "</p>\n";
+
+                       // Display domain info
+                       echo "<table>\n";
+                       echo "<tr><th class=\"data left\" width=\"70\">{$lang['strname']}</th>\n";
+                       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\">{$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";
+       }
+
+       // Tree actions
        if ($action == 'tree') doTree('clusters');
        elseif ($action == 'clusters_top') doTree('clusters_top');
        elseif ($action == 'nodes') doTree('nodes');
        $misc->printBody();
        
        switch ($action) {
-               case 'properties':
-                       doProperties();
+               case 'nodes_properties':
+                       doNodes();
                        break;
-               default:
-                       doDefault();
+               case 'node_properties':
+                       doNode();
+                       break;
+               case 'sets_properties':
+                       doReplicationSets();
                        break;
+               case 'set_properties':
+                       doReplicationSet();
+                       break;
+               default:
+                       // Shouldn't happen
        }
        
        $misc->printFooter();