added l10n for db error messages
This commit is contained in:
parent
bb656ca2fb
commit
b2261c31eb
124
lib/setup.php
124
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(mysql_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(pg_last_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(oci_last_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(oci_last_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
echo($entry);
|
||||
}
|
||||
oci_bind_by_name($stmt, ':un', $name);
|
||||
$result = oci_execute($stmt);
|
||||
if(!$result) {
|
||||
$entry='DB Error: "'.oci_error($connection).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
echo($entry);
|
||||
}
|
||||
//oci_bind_by_name($stmt, ':un', $name);
|
||||
$result = oci_execute($stmt);
|
||||
if(!$result) {
|
||||
$entry='DB Error: "'.oci_error($connection).'"<br />';
|
||||
$entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s", name: %s, password: %s',
|
||||
array($query, $name, $password)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
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).'"<br />';
|
||||
$entry.='Offending command was: '.$query.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s"', array($query)) . '<br />';
|
||||
echo($entry);
|
||||
}
|
||||
$result = oci_execute($stmt);
|
||||
if(!$result) {
|
||||
$entry='DB Error: "'.oci_error($connection).'"<br />';
|
||||
$entry.='Offending command was: '.$query.', name:'.$name.', password:'.$password.'<br />';
|
||||
$entry = $l->t('DB Error: "%s"', array(oci_error($connection))) . '<br />';
|
||||
$entry .= $l->t('Offending command was: "%s", name: %s, password: %s',
|
||||
array($query, $name, $password)) . '<br />';
|
||||
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 <a href=\'%s\'>installation guides</a>.', 'http://doc.owncloud.org/server/5.0/admin_manual/installation.html');
|
||||
|
|
Loading…
Reference in New Issue