Allow altering name (for >= 7.4) and owner (for >= 8.0) of a database from Bryan...
authorsoranzo <soranzo>
Sat, 30 Apr 2005 18:01:50 +0000 (18:01 +0000)
committersoranzo <soranzo>
Sat, 30 Apr 2005 18:01:50 +0000 (18:01 +0000)
HISTORY
all_db.php
classes/database/Postgres.php
classes/database/Postgres74.php
classes/database/Postgres80.php
help/PostgresDoc73.php
lang/english.php
lang/italian.php
lang/recoded/english.php
lang/recoded/italian.php

diff --git a/HISTORY b/HISTORY
index 3f9da87776d041efb9d3b4b57215980cf901aafd..9c4f1d4270667948216bb1b03a9f466d5b30760e 100644 (file)
--- a/HISTORY
+++ b/HISTORY
@@ -14,6 +14,7 @@ Features
 * Add support for PostgreSQL 8.1devel
 * primary key and unique key at table creation (Andreas Huber)
 * Add row|statement level options to create trigger for >= 7.4 (Robert Treat)
+* Allow altering name (for >= 7.4) and owner (for >= 8.0) of a database (Bryan Encina)
   
 Bugs
 * Tree Icons are displayed middle instead of top
@@ -26,18 +27,27 @@ Bugs
 * Fix timeouts on long running operations (Adrian Nida)
 * Allow Multiline character and character varying editing and inserting
 * Add automatic browser language selection for all languages
-* Fix using schema enabled dump on non-schema enabled backend
-* Reload browser after executing arbitrary SQL
-* Fix inability to drop database using the drop link
 * Stop duplicate insert on re-POST of data
-* Correct last internal oid value for PostgreSQL 8.0
 * Fix bug with exporting schema for servers < 7.3
-* Fix dumping on v8 for windows, exclude dumping some objects.
 
 Translations
 * Japanese from Tadashi Jokagi
 * Danish from Arne Eckmann
 * Arabic from Zaki
+
+Version 3.5.3
+-------------
+
+Bugs
+* Fix using schema enabled dump on non-schema enabled backend
+* Don't try setting no timeout when in safe mode
+* Reload browser after executing arbitrary SQL
+* Fix browser in RTL languages
+* Fix inability to drop database using the drop link
+* Fix last internal oid value for PostgreSQL 8.0
+* Fix (again) dumping on v8 for windows, exclude dumping some objects.
+
+Translations
 * Portuguese from Francisco
 
 Version 3.5.2
index 2b41764dfeb52bd4e3edeac2bbc9938d416685e3..fe7632402785b87489aa13a582daecd2c5a13fb9 100644 (file)
@@ -3,7 +3,7 @@
        /**
         * Manage databases within a server
         *
-        * $Id: all_db.php,v 1.36 2005/03/05 06:53:49 mr-russ Exp $
+        * $Id: all_db.php,v 1.37 2005/04/30 18:01:58 soranzo Exp $
         */
 
        // Include application functions
        if (!isset($msg)) $msg = '';
        $PHP_SELF = $_SERVER['PHP_SELF'];
 
+       /**
+        * Display a form for alter and perform actual alter
+        */
+       function doAlter($confirm) {
+               global $data, $misc, $_reload_browser;
+               global $PHP_SELF, $lang;
+       
+               if ($confirm) {
+                       $misc->printTrail('database');
+                       $misc->printTitle($lang['stralter'], 'pg.database.alter');
+                       
+                       echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
+                       echo "<table>\n";
+                       echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
+                       echo "<td class=\"data1\">";
+                       echo "<input name=\"newname\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", 
+                               htmlspecialchars($_REQUEST['alterdatabase']), "\" /></td></tr>\n";
+                       
+                       if ($data->hasAlterDatabaseOwner() && $data->isSuperUser($_SESSION['webdbUsername'])) {
+                               // Fetch all users
+                               
+                               $rs = $data->getDatabaseOwner($_REQUEST['alterdatabase']);
+                               $owner = isset($rs->fields['usename']) ? $rs->fields['usename'] : '';
+                               $users = &$data->getUsers();
+                               
+                               echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n";
+                               echo "<td class=\"data1\"><select name=\"owner\">";
+                               while (!$users->EOF) {
+                                       $uname = $users->f['usename'];
+                                       echo "<option value=\"", htmlspecialchars($uname), "\"",
+                                               ($uname == $owner) ? ' selected="selected"' : '', ">", htmlspecialchars($uname), "</option>\n";
+                                       $users->moveNext();
+                               }
+                               echo "</select></td></tr>\n";
+                       }
+                       echo "</table>\n";
+                       echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
+                       echo "<input type=\"hidden\" name=\"oldname\" value=\"", 
+                               htmlspecialchars($_REQUEST['alterdatabase']), "\" />\n";
+                       echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
+                       echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
+                       echo "</form>\n";
+               }
+               else {
+                       //all versions that support the alter database functionality (starting 7.4) support renaming a db
+                       $newOwner = isset($_POST['owner']) ? $_POST['owner'] : '';
+                       if ($data->AlterDatabase($_POST['oldname'], $_POST['newname'], $newOwner) == 0) {
+                               $_reload_browser = true;
+                               doDefault($lang['strdatabasealtered']);
+                       }
+                       else
+                               doDefault($lang['strdatabasealteredbad']);
+               }
+       }
+       
        /**
         * Show confirmation of drop and perform actual drop
         */
@@ -42,7 +97,6 @@
                        else
                                doDefault($lang['strdatabasedroppedbad']);
                }
-               
        }
        
        /**
                                'vars'  => array('database' => 'datname'),
                        )
                );
+               if ($data->hasAlterDatabase() ) {
+                       $actions['alter'] = array(
+                               'title' => $lang['stralter'],
+                               'url'   => "{$PHP_SELF}?action=confirm_alter&amp;subject=database&amp;",
+                               'vars'  => array('alterdatabase' => 'datname')
+                       );
+               }
                
                if (!$data->hasTablespaces()) unset($columns['tablespace']);
                if (!isset($data->privlist['database'])) unset($actions['privileges']);
                        break;
                case 'confirm_drop':
                        doDrop(true);
+                       break;
+               case 'alter':
+                       if (isset($_POST['oldname']) && isset($_POST['newname']) && !isset($_POST['cancel']) ) doAlter(false);
+                       else doDefault();
                        break;                  
+               case 'confirm_alter':
+                       doAlter(true);
+                       break;
                default:
                        doDefault();
                        break;
index 4d8f03d692ec3f596e3589e160529e4bedab94c4..30cf2da1a1ae194a08b088684e17eada02518360 100755 (executable)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres.php,v 1.259 2005/04/14 18:20:12 xzilla Exp $
+ * $Id: Postgres.php,v 1.260 2005/04/30 18:01:59 soranzo Exp $
  */
 
 // @@@ THOUGHT: What about inherits? ie. use of ONLY???
@@ -437,6 +437,17 @@ class Postgres extends ADODB_base {
                return $this->selectSet($sql);
        }
 
+       /**
+        * Return the database owner of a db
+        * @param string $database the name of the database to get the owner for
+        * @return recordset of the db owner info
+        */
+       function &getDatabaseOwner($database) {
+               $this->clean($database);
+               $sql = "SELECT usename FROM pg_user, pg_database WHERE pg_user.usesysid = pg_database.datdba AND pg_database.datname = '{$database}' ";
+               return $this->selectSet($sql);
+       }
+
        /**
         * Return all information about a particular database
         * @param $database The name of the database to retrieve
@@ -4396,6 +4407,9 @@ class Postgres extends ADODB_base {
        }
 
        // Capabilities
+       function hasAlterDatabaseOwner() { return false; }
+       function hasAlterDatabaseRename() { return false; }
+       function hasAlterDatabase() { return $this->hasAlterDatabaseRename(); }
        function hasSchemas() { return false; }
        function hasConversions() { return false; }     
        function hasGrantOption() { return false; }
index 394f9a258d4b6363285f03492305d1bd0a371f8a..94c010bf12673ae67ce236d9d736c8e6f79ca9ca 100644 (file)
@@ -4,7 +4,7 @@
  * A class that implements the DB interface for Postgres
  * Note: This class uses ADODB and returns RecordSets.
  *
- * $Id: Postgres74.php,v 1.43 2005/04/15 03:56:48 xzilla Exp $
+ * $Id: Postgres74.php,v 1.44 2005/04/30 18:02:01 soranzo Exp $
  */
 
 include_once('./classes/database/Postgres73.php');
@@ -35,6 +35,49 @@ class Postgres74 extends Postgres73 {
                return $this->help_page;
        }
 
+       // Database functions
+       
+       /**
+        * Alters a database
+        * the multiple return vals are for postgres 8+ which support more functionality in alter database
+        * @param $dbName The name of the database
+        * @param $newName new name for the database
+        * @param $newOwner The new owner for the database
+        * @return 0 success
+        * @return -1 transaction error
+        * @return -2 owner error
+        * @return -3 rename error
+        */
+       function alterDatabase($dbName, $newName, $newOwner = '')
+       {
+               //ignore $newowner, not supported pre 8.0
+               $this->clean($dbName);
+               $this->clean($newName);
+               
+               $status = $this->alterDatabaseRename($dbName, $newName);
+               if ($status != 0) return -3;
+               else return 0;
+       }
+       
+       /**
+        * Renames a database, note that this operation cannot be 
+        * performed on a database that is currently being connected to
+        * @param string $oldName name of database to rename
+        * @param string $newName new name of database
+        * @return int 0 on success
+        */
+       function alterDatabaseRename($oldName, $newName) {
+               $this->clean($oldName);
+               $this->clean($newName);
+               
+               if ($oldName != $newName) {
+                       $sql = "ALTER DATABASE \"{$oldName}\" RENAME TO \"{$newName}\"";
+                       return $this->execute($sql);
+               }
+               else //just return success, we're not going to do anything
+                       return 0;
+       }
+       
        // Table functions
        
        /**
@@ -491,6 +534,7 @@ class Postgres74 extends Postgres73 {
        }
        
        // Capabilities
+       function hasAlterDatabaseRename() { return true; }
        function hasGrantOption() { return true; }
        function hasDomainConstraints() { return true; }
        function hasUserRename() { return true; }
index 98df38f99140e9183596a6ece1bbe6dd4f2debc8..9d9855fc46e32de47a834d263f8fdef13d91d454 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * PostgreSQL 8.0 support
  *
- * $Id: Postgres80.php,v 1.11 2005/03/15 02:55:45 chriskl Exp $
+ * $Id: Postgres80.php,v 1.12 2005/04/30 18:02:01 soranzo Exp $
  */
 
 include_once('./classes/database/Postgres74.php');
@@ -79,6 +79,58 @@ class Postgres80 extends Postgres74 {
                return $this->selectSet($sql);
        }
 
+       /**
+        * Alters a database
+        * the multiple return vals are for postgres 8+ which support more functionality in alter database
+        * @param $dbName The name of the database
+        * @param $newName new name for the database
+        * @param $newOwner The new owner for the database
+        * @return 0 success
+        * @return -1 transaction error
+        * @return -2 owner error
+        * @return -3 rename error
+        */
+       function alterDatabase($dbName, $newName, $newOwner = '')
+       {
+               $this->clean($dbName);
+               $this->clean($newName);
+               $this->clean($newOwner);
+               
+               $status = $this->beginTransaction();
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -1;
+               }
+               
+               if ($dbName != $newName) {
+                       $status = $this->alterDatabaseRename($dbName, $newName);
+                       if ($status != 0) {
+                               $this->rollbackTransaction();
+                               return -3;
+                       }
+               }
+               
+               $status = $this->alterDatabaseOwner($newName, $newOwner);
+               if ($status != 0) {
+                       $this->rollbackTransaction();
+                       return -2;
+               }
+               return $this->endTransaction();
+       }
+       /**
+        * Changes ownership of a database
+        * This can only be done by a superuser or the owner of the database
+        * @param string $dbName database to change ownership of
+        * @param string $newOwner user that will own the database
+        * @return int 0 on success
+        */
+       function alterDatabaseOwner($dbName, $newOwner) {
+               $this->clean($dbName);
+               $this->clean($newOwner);
+               
+               $sql = "ALTER DATABASE \"{$dbName}\" OWNER TO \"{$newOwner}\"";
+               return $this->execute($sql);
+       }
        // Schema functions
 
        /**
@@ -449,6 +501,8 @@ class Postgres80 extends Postgres74 {
                return $this->selectSet($sql);
        }
                
+       // Capabilities
+       function hasAlterDatabaseOwner() { return true; }
        function hasAlterColumnType() { return true; }
        function hasTablespaces() { return true; }
        function hasSignals() { return true; }
index 6ae50889199899d7d639eefe6acb2dc4a94bab2e..2d4ba088d44c5b05c1f652d94e5c542e9d4cbbdb 100644 (file)
@@ -3,7 +3,7 @@
 /**
  * Help links for PostgreSQL 7.3 documentation
  *
- * $Id: PostgresDoc73.php,v 1.3 2005/02/16 10:27:44 jollytoad Exp $
+ * $Id: PostgresDoc73.php,v 1.4 2005/04/30 18:02:01 soranzo Exp $
  */
 
 include('./help/PostgresDoc72.php');
@@ -12,6 +12,7 @@ include('./help/PostgresDoc72.php');
 
 $this->help_base = sprintf($GLOBALS['conf']['help_base'], '7.3');
 
+$this->help_page['pg.database.alter'] = 'sql-alterdatabase.html';
 $this->help_page['pg.database.create'][1] = 'manage-ag-createdb.html';
 
 ?>
index c800bffd66f5d1d8713946823690f5a030280908..b9ccfb0e1ca66773ff9f3712d8fe6ab4d8a3e23c 100755 (executable)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.173 2005/04/14 18:20:15 xzilla Exp $
+        * $Id: english.php,v 1.174 2005/04/30 18:02:02 soranzo Exp $
         */
 
        // Language and character set
        $lang['strsignalsent'] = 'Signal sent.';
        $lang['strsignalsentbad'] = 'Sending signal failed.';
        $lang['strallobjects'] = 'All objects';
+       $lang['strdatabasealtered'] = 'Database altered.';
+       $lang['strdatabasealteredbad'] = 'Database alter failed.';
 
        // Views
        $lang['strview'] = 'View';
index de043660a9fe78330ad4a6f4570f1266c9582ce3..af34b86aa665c2fecb04a01a5dd2f8ab11bca9e9 100644 (file)
@@ -4,7 +4,7 @@
         * Italian language file, based on the english language file for phpPgAdmin.
         * Nicola Soranzo [[email protected]]
          *
-        * $Id: italian.php,v 1.40 2005/01/04 23:49:20 soranzo Exp $
+        * $Id: italian.php,v 1.41 2005/04/30 18:02:02 soranzo Exp $
         */
 
        // Language and character set - Lingua e set di caratteri
        $lang['strsignalsent'] = 'Segnale inviato.';
        $lang['strsignalsentbad'] = 'Invio del segnale fallito.';
        $lang['strallobjects'] = 'Tutti gli oggetti';
+       $lang['strdatabasealtered'] = 'Database modificato.';
+       $lang['strdatabasealteredbad'] = 'Modifica del database fallita.';
 
        // Views - Viste
        $lang['strview'] = 'Vista';
index 2bb015c58778a3c3682945240db80c156578a880..98e6e503f84165848da7b7509320f7fd9f15a8b3 100644 (file)
@@ -4,7 +4,7 @@
         * English language file for phpPgAdmin.  Use this as a basis
         * for new translations.
         *
-        * $Id: english.php,v 1.125 2005/04/14 18:20:15 xzilla Exp $
+        * $Id: english.php,v 1.126 2005/04/30 18:02:03 soranzo Exp $
         */
 
        // Language and character set
        $lang['strsignalsent'] = 'Signal sent.';
        $lang['strsignalsentbad'] = 'Sending signal failed.';
        $lang['strallobjects'] = 'All objects';
+       $lang['strdatabasealtered'] = 'Database altered.';
+       $lang['strdatabasealteredbad'] = 'Database alter failed.';
 
        // Views
        $lang['strview'] = 'View';
index 5ffdbdafdd05e41afea070ebf91ea719478d1e44..3b577276ef1109c1614011c8398d6000a2c0294c 100644 (file)
@@ -4,7 +4,7 @@
         * Italian language file, based on the english language file for phpPgAdmin.
         * Nicola Soranzo [[email protected]]
          *
-        * $Id: italian.php,v 1.35 2005/01/04 23:49:38 soranzo Exp $
+        * $Id: italian.php,v 1.36 2005/04/30 18:02:03 soranzo Exp $
         */
 
        // Language and character set - Lingua e set di caratteri
        $lang['strsignalsent'] = 'Segnale inviato.';
        $lang['strsignalsentbad'] = 'Invio del segnale fallito.';
        $lang['strallobjects'] = 'Tutti gli oggetti';
+       $lang['strdatabasealtered'] = 'Database modificato.';
+       $lang['strdatabasealteredbad'] = 'Modifica del database fallita.';
 
        // Views - Viste
        $lang['strview'] = 'Vista';