Implement moving a sequence to another replication set.
authorchriskl <chriskl>
Sat, 11 Jun 2005 09:38:14 +0000 (09:38 +0000)
committerchriskl <chriskl>
Sat, 11 Jun 2005 09:38:14 +0000 (09:38 +0000)
classes/plugins/Slony.php
plugin_slony.php

index cdca3545a2c01047600efefc4b9d744d0f1294c7..1c7a70c25275e153d7e9d48db057cb763ab43930 100755 (executable)
@@ -3,7 +3,7 @@
 /**
  * A class that implements the Slony 1.0.x support plugin
  *
- * $Id: Slony.php,v 1.1.2.18 2005/06/11 08:20:08 chriskl Exp $
+ * $Id: Slony.php,v 1.1.2.19 2005/06/11 09:38:15 chriskl Exp $
  */
 
 include_once('./classes/plugins/Plugin.php');
@@ -420,6 +420,22 @@ class Slony extends Plugin {
                return $data->execute($sql);
        }               
 
+       /**
+        * Moves a sequence to another replication set
+        */
+       function moveSequence($seq_id, $new_set_id) {
+               global $data;
+
+               $schema = $this->slony_schema;
+               $data->fieldClean($schema);
+               $data->clean($seq_id);
+               $data->clean($new_set_id);
+
+               $sql = "SELECT \"{$schema}\".setmovesequence('{$seq_id}', '{$new_set_id}')";
+
+               return $data->execute($sql);
+       }               
+       
        // SUBSCRIPTIONS
        
        /**
index 653ec01c1ff89bcfcfbc37bce786192754061481..c5d5599ef27aedecddf38c646aee3a64def89515 100755 (executable)
@@ -3,7 +3,7 @@
        /**
         * Slony database tab plugin
         *
-        * $Id: plugin_slony.php,v 1.1.2.18 2005/06/11 08:20:08 chriskl Exp $
+        * $Id: plugin_slony.php,v 1.1.2.19 2005/06/11 09:38:14 chriskl Exp $
         */
 
        // Include application functions
                                'title' => 'Remove',
                                'url'   => "plugin_slony.php?{$misc->href}&amp;action=confirm_drop_sequence&amp;set_id={$_REQUEST['set_id']}&amp;",
                                'vars'  => array('seq_id' => 'seq_id', 'qualname' => 'qualname'),
+                       ),
+                       'move' => array(
+                               'title' => $lang['strmove'],
+                               'url'   => "plugin_slony.php?{$misc->href}&amp;action=move_sequence&amp;set_id={$_REQUEST['set_id']}&amp;stage=1&amp;",
+                               'vars'  => array('seq_id' => 'seq_id'),
                        )
                );
                
                                doSequences('Failed to remove sequence from replication set.');
                }
        }
-                       
+
+       /**
+        * Displays a screen where they can move a sequence to a 
+        * replication set.
+        */
+       function doMoveSequence($stage, $msg = '') {
+               global $data, $slony, $misc;
+               global $PHP_SELF, $lang;
+               
+               switch ($stage) {
+                       case 1:
+                               if (!isset($_POST['new_set_id'])) $_POST['new_set_id'] = '';
+                               
+                               $sets = &$slony->getReplicationSets();
+               
+                               $misc->printTrail('slony_sets');
+                               $misc->printTitle($lang['strmove']);
+                               $misc->printMsg($msg);
+               
+                               echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                               echo $misc->form;
+                               echo "<sequence>\n";
+                               echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strnewrepset']}</th>\n";
+                               echo "<td class=\"data1\" colspan=\"3\"><select name=\"new_set_id\">";
+                               while (!$sets->EOF) {
+                                       if ($sets->f['set_id'] != $_REQUEST['set_id']) {
+                                               echo "<option value=\"{$sets->f['set_id']}\">";
+                                               echo htmlspecialchars($sets->f['set_comment']), "</option>\n";
+                                       }
+                                       $sets->moveNext();      
+                               }
+                               echo "</select></td></tr>\n";
+                               echo "</sequence>\n";
+                               echo "<p>\n";
+                               echo "<input type=\"hidden\" name=\"action\" value=\"move_sequence\" />\n";
+                               echo "<input type=\"hidden\" name=\"set_id\" value=\"", htmlspecialchars($_REQUEST['set_id']), "\" />\n";
+                               echo "<input type=\"hidden\" name=\"seq_id\" value=\"", htmlspecialchars($_REQUEST['seq_id']), "\" />\n";
+                               echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
+                               echo "<input type=\"submit\" value=\"{$lang['strmove']}\" />\n";
+                               echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
+                               echo "</p>\n";
+                               echo "</form>\n";
+                               break;
+                       case 2:
+                               $status = $slony->moveSequence($_REQUEST['seq_id'], $_REQUEST['new_set_id']);
+                               if ($status == 0)
+                                       doSequences('Sequence moved to replication set.');
+                               else
+                                       doMoveSequence(1, 'Failed moving sequence to replication set.');
+                               break;
+               }
+       }
+                               
        // SUBSCRIPTIONS
        
        /**
                case 'confirm_drop_sequence':
                        doRemoveSequence(true);
                        break;
+               case 'move_sequence':
+                       if (isset($_REQUEST['cancel'])) doSequences();
+                       else doMoveSequence($_REQUEST['stage']);
+                       break;
                case 'subscriptions_properties':
                        doSubscriptions();
                        break;