more work on slony - now we're starting to see something
authorchriskl <chriskl>
Sun, 22 May 2005 14:29:08 +0000 (14:29 +0000)
committerchriskl <chriskl>
Sun, 22 May 2005 14:29:08 +0000 (14:29 +0000)
classes/plugins/Slony.php
plugin_slony.php

index fd9254a892fcb06dcb20c4646b7c77d152025b3b..4193255f7f0d5a6c6cb51d7ab7af776c497b125e 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * A class that implements the Slony 1.0.x support plugin
  *
- * $Id: Slony.php,v 1.1.2.2 2005/05/15 14:27:16 chriskl Exp $
+ * $Id: Slony.php,v 1.1.2.3 2005/05/22 14:29:08 chriskl Exp $
  */
 
 include_once('./classes/plugins/Plugin.php');
@@ -73,6 +73,8 @@ class Slony extends Plugin {
                );                              
        }
 
+       // NODES
+
        /**
         * Gets the nodes in this database
         */
@@ -82,7 +84,7 @@ class Slony extends Plugin {
                $schema = $this->slony_schema;
                $data->fieldClean($schema);
                
-               $sql = "SELECT * FROM \"{$schema}\".sl_node ORDER BY no_id";
+               $sql = "SELECT *, 'Node ' || no_id AS no_name FROM \"{$schema}\".sl_node ORDER BY no_id";
                
                return $data->selectSet($sql);
        }
@@ -97,7 +99,7 @@ class Slony extends Plugin {
                $schema = $this->slony_schema;
                $data->fieldClean($schema);
                
-               $sql = "SELECT * FROM \"{$schema}\".sl_node WHERE no_id='{$no_id}'";
+               $sql = "SELECT *, 'Node ' || no_id AS no_name FROM \"{$schema}\".sl_node WHERE no_id='{$no_id}'";
                
                return $data->selectSet($sql);
        }
@@ -119,6 +121,44 @@ class Slony extends Plugin {
                
                return $data->selectSet($sql);
        }
+
+       // REPLICATION SETS
+       
+       /**
+        * Gets the replication sets in this database
+        */
+       function getReplicationSets() {
+               global $data;
+               
+               $schema = $this->slony_schema;
+               $data->fieldClean($schema);
+               
+               $sql = "SELECT *, 'Set ' || set_id AS set_name  FROM \"{$schema}\".sl_set ORDER BY set_id";
+               
+               return $data->selectSet($sql);
+       }
+
+       /**
+        * Return all tables in a replication set
+        * @param $set_id The ID of the replication set
+        * @return Tables in the replication set, sorted alphabetically 
+        */
+       function &getTables($set_id) {
+               global $data;
+
+               $schema = $this->slony_schema;
+               $data->fieldClean($schema);
+               $data->clean($set_id);          
+
+               $sql = "SELECT c.relname
+                                       FROM pg_catalog.pg_class c, \"{$schema}\".sl_table st
+                                       WHERE c.oid=st.tab_reloid
+                                       AND st.tab_set='{$set_id}'
+                                       ORDER BY c.relname";
+
+               return $data->selectSet($sql);
+       }
+
 }
 
 ?>
index 160cf8c90324ab935023ab1fcf720bf65ee4dd4a..a688d41f23359ffb7f58757f6fb557f7dbc19e5b 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Slony database tab plugin
         *
-        * $Id: plugin_slony.php,v 1.1.2.1 2005/05/11 15:48:03 chriskl Exp $
+        * $Id: plugin_slony.php,v 1.1.2.2 2005/05/22 14:29:08 chriskl Exp $
         */
 
        // Include application functions
                $misc->printTable($clients, $columns, $actions, 'No nodes found.');
        }
 
+       function doTree($subject) {
+               global $misc, $data, $lang, $PHP_SELF, $slony;
+
+               $reqvars = $misc->getRequestVars('database');
+
+               // Determine what actual tree we are building
+               switch ($subject) {                     
+                       case 'top':
+                               // Top level Nodes and Replication Sets folders
+                               $tabs = array('nodes' => array (
+                                                                               'title' => 'Nodes',
+                                                                               'url'   => 'plugin_slony.php',
+                                                                               'urlvars' => array('subject' => 'nodes')
+                                                                       ));
+                               
+                               $items =& $misc->adjustTabsForTree($tabs);
+                               
+                               $attrs = array(
+                                       'text'   => noEscape(field('title')),
+                                       'icon'   => field('icon', 'folder'),
+                                       'action' => url(field('url'),
+                                                                       $reqvars,
+                                                                       field('urlvars', array())
+                                                               ),
+                                       'branch' => url(field('url'),
+                                                                       $reqvars,
+                                                                       field('urlvars'),
+                                                                       array('action' => 'nodes')
+                                                               ),
+                                       'nofoot' => true
+                               );
+                               
+                               $misc->printTreeXML($items, $attrs);
+
+                               $tabs = array('sets' => array (
+                                                                               'title' => 'Replication Sets',
+                                                                               'url'   => 'plugin_slony.php',
+                                                                               'urlvars' => array('subject' => 'sets')
+                                                                       ));
+                               
+                               $items =& $misc->adjustTabsForTree($tabs);
+                               
+                               $attrs = array(
+                                       'text'   => noEscape(field('title')),
+                                       'icon'   => field('icon', 'folder'),
+                                       'action' => url(field('url'),
+                                                                       $reqvars,
+                                                                       field('urlvars', array())
+                                                               ),
+                                       'branch' => url(field('url'),
+                                                                       $reqvars,
+                                                                       field('urlvars'),
+                                                                       array('action' => 'sets')
+                                                               ),
+                                       'nohead' => true
+                               );
+                               
+                               $misc->printTreeXML($items, $attrs);
+                               
+                               break;
+                       case 'nodes':                   
+                               $nodes = &$slony->getNodes();
+                               
+                               $attrs = array(
+                                       'text'   => field('no_name'),
+                                       'icon'   => 'folder',
+                                       'toolTip'=> field('no_comment'),
+                                       'action' => url('redirect.php',
+                                                                       $reqvars,
+                                                                       array(
+                                                                               'subject' => 'slony_node'
+                                                                       )
+                                                               ),
+                                                               /*
+                                       'branch' => url('plugin_slony.php',
+                                                                       $reqvars,
+                                                                       array(
+                                                                               'action'  => 'subtree',
+                                                                               'schema'  => field('nspname')
+                                                                       )
+                                                               )*/
+                               );
+
+                               $misc->printTreeXML($nodes, $attrs);
+                               
+                               break;
+                       case 'sets':
+                               $sets = &$slony->getReplicationSets();
+                       
+                               $attrs = array(
+                                       'text'   => field('set_name'),
+                                       'icon'   => 'folder',
+                                       'toolTip'=> field('set_comment'),
+                                       'action' => url('redirect.php',
+                                                                       $reqvars,
+                                                                       array(
+                                                                               'subject' => 'slony_node'
+                                                                       )
+                                                               ),
+                                       'branch' => url('plugin_slony.php',
+                                                                       $reqvars,
+                                                                       array(
+                                                                               'action'  => 'sets_top'
+                                                                       )
+                                                               )
+                               );
+                               
+                               $misc->printTreeXML($sets, $attrs);
+                               break;
+                       case 'sets_top':
+                               // Top level Nodes and Replication Sets folders
+                               $tabs = array('subscriptions' => array (
+                                                                               'title' => 'Subscriptions',
+                                                                               'url'   => 'plugin_slony.php',
+                                                                               'urlvars' => array('subject' => 'subscriptions')
+                                                                       ));
+                               
+                               $items =& $misc->adjustTabsForTree($tabs);
+                               
+                               $attrs = array(
+                                       'text'   => noEscape(field('title')),
+                                       'icon'   => field('icon', 'folder'),
+                                       'action' => url(field('url'),
+                                                                       $reqvars,
+                                                                       field('urlvars', array())
+                                                               ),
+                                       'branch' => url(field('url'),
+                                                                       $reqvars,
+                                                                       field('urlvars'),
+                                                                       array('action' => 'subscriptions')
+                                                               ),
+                                       'nofoot' => true
+                               );
+                               
+                               $misc->printTreeXML($items, $attrs);
+
+                               $tabs = array('tables' => array (
+                                                                               'title' => $lang['strtables'],
+                                                                               'url'   => 'plugin_slony.php',
+                                                                               'urlvars' => array('subject' => 'tables')
+                                                                       ));
+                               
+                               $items =& $misc->adjustTabsForTree($tabs);
+                               
+                               $attrs = array(
+                                       'text'   => noEscape(field('title')),
+                                       'icon'   => field('icon', 'folder'),
+                                       'action' => url(field('url'),
+                                                                       $reqvars,
+                                                                       field('urlvars', array())
+                                                               ),
+                                       'branch' => url(field('url'),
+                                                                       $reqvars,
+                                                                       field('urlvars'),
+                                                                       array('action' => 'tables', 'set_id' => XXXXXXXXXHERE)
+                                                               ),
+                                       'nohead' => true,
+                                       'nofoot' => true
+                               );
+                               
+                               $misc->printTreeXML($items, $attrs);
+
+                               $tabs = array('sequencess' => array (
+                                                                               'title' => $lang['strsequences'],
+                                                                               'url'   => 'plugin_slony.php',
+                                                                               'urlvars' => array('subject' => 'sequences')
+                                                                       ));
+                               
+                               $items =& $misc->adjustTabsForTree($tabs);
+                               
+                               $attrs = array(
+                                       'text'   => noEscape(field('title')),
+                                       'icon'   => field('icon', 'folder'),
+                                       'action' => url(field('url'),
+                                                                       $reqvars,
+                                                                       field('urlvars', array())
+                                                               ),
+                                       'branch' => url(field('url'),
+                                                                       $reqvars,
+                                                                       field('urlvars'),
+                                                                       array('action' => 'sequences')
+                                                               ),
+                                       'nohead' => true
+                               );
+                               
+                               $misc->printTreeXML($items, $attrs);
+                               
+                               break;
+                       case 'tables':
+                               $tables = &$slony->getTables($_REQUEST['set_id']);
+                               
+                               $reqvars = $misc->getRequestVars('table');
+                               
+                               $attrs = array(
+                                       'text'   => field('relname'),
+                                       'icon'   => 'tables',
+                                       'toolTip'=> field('relcomment'),
+                                       'action' => url('redirect.php',
+                                                                       $reqvars,
+                                                                       array('table' => field('relname'))
+                                                               )
+                               );
+                               
+                               $misc->printTreeXML($tables, $attrs);
+                       
+                               break;
+               }
+                       
+               exit;
+       }
+
        /**
         * List all the information on the table
         */
                $misc->printTable($nodes, $columns, $actions, 'No nodes found.');
        }
 
+       if ($action == 'tree') doTree('top');
+       elseif ($action == 'nodes') doTree('nodes');
+       elseif ($action == 'sets') doTree('sets');
+       elseif ($action == 'sets_top') doTree('sets_top');
+       elseif ($action == 'subscriptions') doTree('subscriptions');
+       elseif ($action == 'sequences') doTree('sequences');
+       elseif ($action == 'tables') doTree('tables');
+
        $misc->printHeader('Slony');
        $misc->printBody();