From b2261c31eb3a7d45a0aacad90459b924503c8dac Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sat, 9 Feb 2013 19:23:36 +0100 Subject: [PATCH 1/3] added l10n for db error messages --- lib/setup.php | 124 +++++++++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 52 deletions(-) diff --git a/lib/setup.php b/lib/setup.php index f342142c95..01aa9eb019 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -19,18 +19,25 @@ class DatabaseSetupException extends Exception } class OC_Setup { + + public static function getTrans(){ + return OC_L10N::get('lib'); + } + public static function install($options) { + $l = self::getTrans(); + $error = array(); $dbtype = $options['dbtype']; if(empty($options['adminlogin'])) { - $error[] = 'Set an admin username.'; + $error[] = $l->t('Set an admin username.'); } if(empty($options['adminpass'])) { - $error[] = 'Set an admin password.'; + $error[] = $l->t('Set an admin password.'); } if(empty($options['directory'])) { - $error[] = 'Specify a data folder.'; + $error[] = $l->t('Specify a data folder.'); } if($dbtype=='mysql' or $dbtype == 'pgsql' or $dbtype == 'oci') { //mysql and postgresql needs more config options @@ -43,16 +50,16 @@ class OC_Setup { if(empty($options['dbuser'])) { - $error[] = "$dbprettyname enter the database username."; + $error[] = $l->t("$dbprettyname enter the database username."); } if(empty($options['dbname'])) { - $error[] = "$dbprettyname enter the database name."; + $error[] = $l->t("$dbprettyname enter the database name."); } if(substr_count($options['dbname'], '.') >= 1) { - $error[] = "$dbprettyname you may not use dots in the database name"; + $error[] = $l->t("$dbprettyname you may not use dots in the database name"); } if($dbtype != 'oci' && empty($options['dbhost'])) { - $error[] = "$dbprettyname set the database host."; + $error[] = $l->t("$dbprettyname set the database host."); } } @@ -116,8 +123,8 @@ class OC_Setup { self::setupPostgreSQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username); } catch (Exception $e) { $error[] = array( - 'error' => 'PostgreSQL username and/or password not valid', - 'hint' => 'You need to enter either an existing account or the administrator.' + 'error' => $l->t('PostgreSQL username and/or password not valid'), + 'hint' => $l->t('You need to enter either an existing account or the administrator.') ); return $error; } @@ -139,8 +146,8 @@ class OC_Setup { self::setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username); } catch (Exception $e) { $error[] = array( - 'error' => 'Oracle username and/or password not valid', - 'hint' => 'You need to enter either an existing account or the administrator.' + 'error' => $l->t('Oracle username and/or password not valid'), + 'hint' => $l->t('You need to enter either an existing account or the administrator.') ); return $error; } @@ -190,9 +197,11 @@ class OC_Setup { private static function setupMySQLDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $username) { //check if the database user has admin right + $l = self::getTrans(); $connection = @mysql_connect($dbhost, $dbuser, $dbpass); if(!$connection) { - throw new DatabaseSetupException('MySQL username and/or password not valid','You need to enter either an existing account or the administrator.'); + throw new DatabaseSetupException($l->t('MySQL username and/or password not valid'), + $l->t('You need to enter either an existing account or the administrator.')); } $oldUser=OC_Config::getValue('dbuser', false); @@ -239,11 +248,12 @@ class OC_Setup { private static function createMySQLDatabase($name, $user, $connection) { //we cant use OC_BD functions here because we need to connect as the administrative user. + $l = self::getTrans(); $query = "CREATE DATABASE IF NOT EXISTS `$name`"; $result = mysql_query($query, $connection); if(!$result) { - $entry='DB Error: "'.mysql_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(mysql_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } $query="GRANT ALL PRIVILEGES ON `$name` . * TO '$user'"; @@ -253,15 +263,18 @@ class OC_Setup { private static function createDBUser($name, $password, $connection) { // we need to create 2 accounts, one for global use and one for local user. if we don't specify the local one, // the anonymous user would take precedence when there is one. + $l = self::getTrans(); $query = "CREATE USER '$name'@'localhost' IDENTIFIED BY '$password'"; $result = mysql_query($query, $connection); if (!$result) { - throw new DatabaseSetupException("MySQL user '" . "$name" . "'@'localhost' already exists","Delete this user from MySQL."); + throw new DatabaseSetupException($l->t("MySQL user '%s'@'localhost' exists already.", + array($name)), $l->t("Drop this user from MySQL", array($name))); } $query = "CREATE USER '$name'@'%' IDENTIFIED BY '$password'"; $result = mysql_query($query, $connection); if (!$result) { - throw new DatabaseSetupException("MySQL user '" . "$name" . "'@'%' already exists","Delete this user from MySQL."); + throw new DatabaseSetupException($l->t("MySQL user '%s'@'%%' already exists", array($name)), + $l->t("Drop this user from MySQL.")); } } @@ -269,12 +282,13 @@ class OC_Setup { $e_host = addslashes($dbhost); $e_user = addslashes($dbuser); $e_password = addslashes($dbpass); + $l = self::getTrans(); //check if the database user has admin rights $connection_string = "host='$e_host' dbname=postgres user='$e_user' password='$e_password'"; $connection = @pg_connect($connection_string); if(!$connection) { - throw new Exception('PostgreSQL username and/or password not valid'); + throw new Exception($l->t('PostgreSQL username and/or password not valid')); } $e_user = pg_escape_string($dbuser); //check for roles creation rights in postgresql @@ -319,7 +333,7 @@ class OC_Setup { $connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'"; $connection = @pg_connect($connection_string); if(!$connection) { - throw new Exception('PostgreSQL username and/or password not valid'); + throw new Exception($l->t('PostgreSQL username and/or password not valid')); } $query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1"; $result = pg_query($connection, $query); @@ -332,14 +346,16 @@ class OC_Setup { } private static function pg_createDatabase($name, $user, $connection) { + //we cant use OC_BD functions here because we need to connect as the administrative user. + $l = self::getTrans(); $e_name = pg_escape_string($name); $e_user = pg_escape_string($user); $query = "select datname from pg_database where datname = '$e_name'"; $result = pg_query($connection, $query); if(!$result) { - $entry='DB Error: "'.pg_last_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } if(! pg_fetch_row($result)) { @@ -347,8 +363,8 @@ class OC_Setup { $query = "CREATE DATABASE \"$e_name\" OWNER \"$e_user\""; $result = pg_query($connection, $query); if(!$result) { - $entry='DB Error: "'.pg_last_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } else { @@ -359,13 +375,14 @@ class OC_Setup { } private static function pg_createDBUser($name, $password, $connection) { + $l = self::getTrans(); $e_name = pg_escape_string($name); $e_password = pg_escape_string($password); $query = "select * from pg_roles where rolname='$e_name';"; $result = pg_query($connection, $query); if(!$result) { - $entry='DB Error: "'.pg_last_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } @@ -374,8 +391,8 @@ class OC_Setup { $query = "CREATE USER \"$e_name\" CREATEDB PASSWORD '$e_password';"; $result = pg_query($connection, $query); if(!$result) { - $entry='DB Error: "'.pg_last_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } } @@ -383,14 +400,15 @@ class OC_Setup { $query = "ALTER ROLE \"$e_name\" WITH PASSWORD '$e_password';"; $result = pg_query($connection, $query); if(!$result) { - $entry='DB Error: "'.pg_last_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } } } private static function setupOCIDatabase($dbhost, $dbuser, $dbpass, $dbname, $dbtableprefix, $dbtablespace, $username) { + $l = self::getTrans(); $e_host = addslashes($dbhost); $e_dbname = addslashes($dbname); //check if the database user has admin right @@ -402,15 +420,15 @@ class OC_Setup { $connection = @oci_connect($dbuser, $dbpass, $easy_connect_string); if(!$connection) { $e = oci_error(); - throw new Exception('Oracle username and/or password not valid'); + throw new Exception($l->t('Oracle username and/or password not valid')); } //check for roles creation rights in oracle $query="SELECT count(*) FROM user_role_privs, role_sys_privs WHERE user_role_privs.granted_role = role_sys_privs.role AND privilege = 'CREATE ROLE'"; $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry='DB Error: "'.oci_last_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(oci_last_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } $result = oci_execute($stmt); @@ -468,15 +486,15 @@ class OC_Setup { } $connection = @oci_connect($dbuser, $dbpass, $easy_connect_string); if(!$connection) { - throw new Exception('Oracle username and/or password not valid'); + throw new Exception($l->t('Oracle username and/or password not valid')); } $query = "SELECT count(*) FROM user_tables WHERE table_name = :un"; $stmt = oci_parse($connection, $query); $un = $dbtableprefix.'users'; oci_bind_by_name($stmt, ':un', $un); if (!$stmt) { - $entry='DB Error: "'.oci_last_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(oci_last_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } $result = oci_execute($stmt); @@ -497,19 +515,19 @@ class OC_Setup { * @param resource $connection */ private static function oci_createDBUser($name, $password, $tablespace, $connection) { - + $l = self::getTrans(); $query = "SELECT * FROM all_users WHERE USERNAME = :un"; $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry='DB Error: "'.oci_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } oci_bind_by_name($stmt, ':un', $name); $result = oci_execute($stmt); if(!$result) { - $entry='DB Error: "'.oci_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } @@ -519,31 +537,32 @@ class OC_Setup { $query = 'CREATE USER '.$name.' IDENTIFIED BY "'.$password.'" DEFAULT TABLESPACE '.$tablespace; //TODO set default tablespace $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry='DB Error: "'.oci_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } //oci_bind_by_name($stmt, ':un', $name); $result = oci_execute($stmt); if(!$result) { - $entry='DB Error: "'.oci_error($connection).'"
'; - $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'
'; + $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s", name: %s, password: %s', + array($query, $name, $password)) . '
'; echo($entry); } } else { // change password of the existing role $query = "ALTER USER :un IDENTIFIED BY :pw"; $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry='DB Error: "'.oci_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } oci_bind_by_name($stmt, ':un', $name); oci_bind_by_name($stmt, ':pw', $password); $result = oci_execute($stmt); if(!$result) { - $entry='DB Error: "'.oci_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } } @@ -551,14 +570,15 @@ class OC_Setup { $query = 'GRANT CREATE SESSION, CREATE TABLE, CREATE SEQUENCE, CREATE TRIGGER, UNLIMITED TABLESPACE TO '.$name; $stmt = oci_parse($connection, $query); if (!$stmt) { - $entry='DB Error: "'.oci_error($connection).'"
'; - $entry.='Offending command was: '.$query.'
'; + $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } $result = oci_execute($stmt); if(!$result) { - $entry='DB Error: "'.oci_error($connection).'"
'; - $entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'
'; + $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; + $entry .= $l->t('Offending command was: "%s", name: %s, password: %s', + array($query, $name, $password)) . '
'; echo($entry); } } @@ -616,10 +636,10 @@ class OC_Setup { */ public static function postSetupCheck($params) { // setup was successful -> webdav testing now + $l = self::getTrans(); if (OC_Util::isWebDAVWorking()) { header("Location: ".OC::$WEBROOT.'/'); } else { - $l=OC_L10N::get('lib'); $error = $l->t('Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken.'); $hint = $l->t('Please double check the installation guides.', 'http://doc.owncloud.org/server/5.0/admin_manual/installation.html'); From 36df2fbdfedd6bdf9429fb11f516913c8afe7229 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 11 Feb 2013 13:11:43 +0100 Subject: [PATCH 2/3] fixed argument for translation --- lib/setup.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/setup.php b/lib/setup.php index 01aa9eb019..035f1b6b8e 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -50,16 +50,16 @@ class OC_Setup { if(empty($options['dbuser'])) { - $error[] = $l->t("$dbprettyname enter the database username."); + $error[] = $l->t("%s enter the database username.", array($dbprettyname)); } if(empty($options['dbname'])) { - $error[] = $l->t("$dbprettyname enter the database name."); + $error[] = $l->t("%s enter the database name.", array($dbprettyname)); } if(substr_count($options['dbname'], '.') >= 1) { - $error[] = $l->t("$dbprettyname you may not use dots in the database name"); + $error[] = $l->t("%s you may not use dots in the database name", array($dbprettyname)); } if($dbtype != 'oci' && empty($options['dbhost'])) { - $error[] = $l->t("$dbprettyname set the database host."); + $error[] = $l->t("%s set the database host.", array($dbprettyname)); } } From c544a631d52c9750fb4342577b68303245abc9ee Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 11 Feb 2013 14:14:37 +0100 Subject: [PATCH 3/3] fixing indent --- lib/setup.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/setup.php b/lib/setup.php index 035f1b6b8e..cfaf728866 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -382,7 +382,7 @@ class OC_Setup { $result = pg_query($connection, $query); if(!$result) { $entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '
'; - $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } @@ -520,14 +520,14 @@ class OC_Setup { $stmt = oci_parse($connection, $query); if (!$stmt) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; - $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); } oci_bind_by_name($stmt, ':un', $name); $result = oci_execute($stmt); if(!$result) { $entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '
'; - $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; + $entry .= $l->t('Offending command was: "%s"', array($query)) . '
'; echo($entry); }