From: soranzo Date: Sat, 30 Apr 2005 18:01:50 +0000 (+0000) Subject: Allow altering name (for >= 7.4) and owner (for >= 8.0) of a database from Bryan... X-Git-Tag: REL_4-0-1~132 X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=08a01fa1ac80ed21f0cdae5db2d562e414db4509;p=phppgadmin.git Allow altering name (for >= 7.4) and owner (for >= 8.0) of a database from Bryan + 3.5.3 HISTORY integration --- diff --git a/HISTORY b/HISTORY index 3f9da877..9c4f1d42 100644 --- 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 diff --git a/all_db.php b/all_db.php index 2b41764d..fe763240 100644 --- a/all_db.php +++ b/all_db.php @@ -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 @@ -13,6 +13,61 @@ 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 "
\n"; + echo "\n"; + echo "\n"; + echo "\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 "\n"; + echo "\n"; + } + echo "
{$lang['strname']}"; + echo "_maxNameLen}\" value=\"", + htmlspecialchars($_REQUEST['alterdatabase']), "\" />
{$lang['strowner']}
\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\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']); } - } /** @@ -237,6 +291,13 @@ 'vars' => array('database' => 'datname'), ) ); + if ($data->hasAlterDatabase() ) { + $actions['alter'] = array( + 'title' => $lang['stralter'], + 'url' => "{$PHP_SELF}?action=confirm_alter&subject=database&", + 'vars' => array('alterdatabase' => 'datname') + ); + } if (!$data->hasTablespaces()) unset($columns['tablespace']); if (!isset($data->privlist['database'])) unset($actions['privileges']); @@ -267,7 +328,14 @@ 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; diff --git a/classes/database/Postgres.php b/classes/database/Postgres.php index 4d8f03d6..30cf2da1 100755 --- a/classes/database/Postgres.php +++ b/classes/database/Postgres.php @@ -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; } diff --git a/classes/database/Postgres74.php b/classes/database/Postgres74.php index 394f9a25..94c010bf 100644 --- a/classes/database/Postgres74.php +++ b/classes/database/Postgres74.php @@ -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; } diff --git a/classes/database/Postgres80.php b/classes/database/Postgres80.php index 98df38f9..9d9855fc 100644 --- a/classes/database/Postgres80.php +++ b/classes/database/Postgres80.php @@ -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; } diff --git a/help/PostgresDoc73.php b/help/PostgresDoc73.php index 6ae50889..2d4ba088 100644 --- a/help/PostgresDoc73.php +++ b/help/PostgresDoc73.php @@ -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'; ?> diff --git a/lang/english.php b/lang/english.php index c800bffd..b9ccfb0e 100755 --- a/lang/english.php +++ b/lang/english.php @@ -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 @@ -291,6 +291,8 @@ $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'; diff --git a/lang/italian.php b/lang/italian.php index de043660..af34b86a 100644 --- a/lang/italian.php +++ b/lang/italian.php @@ -4,7 +4,7 @@ * Italian language file, based on the english language file for phpPgAdmin. * Nicola Soranzo [nsoranzo@tiscali.it] * - * $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 @@ -289,6 +289,8 @@ $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'; diff --git a/lang/recoded/english.php b/lang/recoded/english.php index 2bb015c5..98e6e503 100644 --- a/lang/recoded/english.php +++ b/lang/recoded/english.php @@ -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 @@ -291,6 +291,8 @@ $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'; diff --git a/lang/recoded/italian.php b/lang/recoded/italian.php index 5ffdbdaf..3b577276 100644 --- a/lang/recoded/italian.php +++ b/lang/recoded/italian.php @@ -4,7 +4,7 @@ * Italian language file, based on the english language file for phpPgAdmin. * Nicola Soranzo [nsoranzo@tiscali.it] * - * $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 @@ -289,6 +289,8 @@ $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';