improve error handeling for first run dialog
This commit is contained in:
parent
fda445ab05
commit
ab155de14f
3 changed files with 39 additions and 35 deletions
|
@ -1338,15 +1338,15 @@ class MDB2_Schema extends PEAR
|
||||||
|
|
||||||
if ($dbExists) {
|
if ($dbExists) {
|
||||||
$this->db->debug('Database already exists: ' . $db_name, __FUNCTION__);
|
$this->db->debug('Database already exists: ' . $db_name, __FUNCTION__);
|
||||||
if (!empty($dbOptions)) {
|
// if (!empty($dbOptions)) {
|
||||||
$errorcodes = array(MDB2_ERROR_UNSUPPORTED, MDB2_ERROR_NO_PERMISSION);
|
// $errorcodes = array(MDB2_ERROR_UNSUPPORTED, MDB2_ERROR_NO_PERMISSION);
|
||||||
$this->db->expectError($errorcodes);
|
// $this->db->expectError($errorcodes);
|
||||||
$result = $this->db->manager->alterDatabase($db_name, $dbOptions);
|
// $result = $this->db->manager->alterDatabase($db_name, $dbOptions);
|
||||||
$this->db->popExpect();
|
// $this->db->popExpect();
|
||||||
if (PEAR::isError($result) && !MDB2::isError($result, $errorcodes)) {
|
// if (PEAR::isError($result) && !MDB2::isError($result, $errorcodes)) {
|
||||||
return $result;
|
// return $result;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
$create = false;
|
$create = false;
|
||||||
} else {
|
} else {
|
||||||
$this->db->expectError(MDB2_ERROR_UNSUPPORTED);
|
$this->db->expectError(MDB2_ERROR_UNSUPPORTED);
|
||||||
|
|
|
@ -239,7 +239,7 @@ class OC_DB {
|
||||||
|
|
||||||
// read file
|
// read file
|
||||||
$content = file_get_contents( $file );
|
$content = file_get_contents( $file );
|
||||||
|
|
||||||
// Make changes and save them to a temporary file
|
// Make changes and save them to a temporary file
|
||||||
$file2 = tempnam( sys_get_temp_dir(), 'oc_db_scheme_' );
|
$file2 = tempnam( sys_get_temp_dir(), 'oc_db_scheme_' );
|
||||||
$content = str_replace( '*dbname*', $CONFIG_DBNAME, $content );
|
$content = str_replace( '*dbname*', $CONFIG_DBNAME, $content );
|
||||||
|
@ -247,8 +247,8 @@ class OC_DB {
|
||||||
file_put_contents( $file2, $content );
|
file_put_contents( $file2, $content );
|
||||||
|
|
||||||
// Try to create tables
|
// Try to create tables
|
||||||
$definition = @self::$schema->parseDatabaseDefinitionFile( $file2 );
|
$definition = self::$schema->parseDatabaseDefinitionFile( $file2 );
|
||||||
|
|
||||||
// Delete our temporary file
|
// Delete our temporary file
|
||||||
unlink( $file2 );
|
unlink( $file2 );
|
||||||
|
|
||||||
|
@ -256,7 +256,10 @@ class OC_DB {
|
||||||
if( $definition instanceof MDB2_Schema_Error ){
|
if( $definition instanceof MDB2_Schema_Error ){
|
||||||
die( $definition->getMessage().': '.$definition->getUserInfo());
|
die( $definition->getMessage().': '.$definition->getUserInfo());
|
||||||
}
|
}
|
||||||
$ret=@self::$schema->createDatabase( $definition );
|
if(OC_CONFIG::getValue('dbtype','sqlite')=='sqlite'){
|
||||||
|
$definition['overwrite']=true;//always overwrite for sqlite
|
||||||
|
}
|
||||||
|
$ret=self::$schema->createDatabase( $definition );
|
||||||
|
|
||||||
// Die in case something went wrong
|
// Die in case something went wrong
|
||||||
if( $ret instanceof MDB2_Error ){
|
if( $ret instanceof MDB2_Error ){
|
||||||
|
|
|
@ -25,19 +25,19 @@ class OC_INSTALLER{
|
||||||
};
|
};
|
||||||
if($dbtype=='mysql'){//mysql needs more config options
|
if($dbtype=='mysql'){//mysql needs more config options
|
||||||
if(empty($options['dbuser'])){
|
if(empty($options['dbuser'])){
|
||||||
$error[]=array('error'=>'database user directory not set');
|
$error[]=array('error'=>'database user not set');
|
||||||
};
|
};
|
||||||
if(empty($options['dbpass'])){
|
if(empty($options['dbpass'])){
|
||||||
$error[]=array('error'=>'database password directory not set');
|
$error[]=array('error'=>'database password not set');
|
||||||
};
|
};
|
||||||
if(empty($options['dbname'])){
|
if(empty($options['dbname'])){
|
||||||
$error[]=array('error'=>'database name directory not set');
|
$error[]=array('error'=>'database name not set');
|
||||||
};
|
};
|
||||||
if(empty($options['dbhost'])){
|
if(empty($options['dbhost'])){
|
||||||
$error[]=array('error'=>'database host directory not set');
|
$error[]=array('error'=>'database host not set');
|
||||||
};
|
};
|
||||||
if(!isset($options['dbtableprefix'])){
|
if(!isset($options['dbtableprefix'])){
|
||||||
$error[]=array('error'=>'database table prefix directory not set');
|
$error[]=array('error'=>'database table prefix not set');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if(count($error)==0){ //no errors, good
|
if(count($error)==0){ //no errors, good
|
||||||
|
@ -59,9 +59,9 @@ class OC_INSTALLER{
|
||||||
OC_CONFIG::setValue('dbtableprefix',$dbtableprefix);
|
OC_CONFIG::setValue('dbtableprefix',$dbtableprefix);
|
||||||
|
|
||||||
//check if the database user has admin right
|
//check if the database user has admin right
|
||||||
$connection=mysql_connect($dbhost, $dbuser, $dbpass);
|
$connection=@mysql_connect($dbhost, $dbuser, $dbpass);
|
||||||
if(!$connection) {
|
if(!$connection) {
|
||||||
$error[]=array('error'=>'mysql username and/or password not valid','you need to enter either an existing account, or the administrative account if you wish to create a new user for ownCloud');
|
$error[]=array('error'=>'mysql username and/or password not valid','hint'=>'you need to enter either an existing account, or the administrative account if you wish to create a new user for ownCloud');
|
||||||
}else{
|
}else{
|
||||||
$query="SELECT user FROM mysql.user WHERE user='$dbuser'";//this should be enough to check for admin rights in mysql
|
$query="SELECT user FROM mysql.user WHERE user='$dbuser'";//this should be enough to check for admin rights in mysql
|
||||||
if(mysql_query($query,$connection)){
|
if(mysql_query($query,$connection)){
|
||||||
|
@ -79,26 +79,27 @@ class OC_INSTALLER{
|
||||||
//create the database
|
//create the database
|
||||||
self::createDatabase($dbname,$dbuser,$connection);
|
self::createDatabase($dbname,$dbuser,$connection);
|
||||||
}
|
}
|
||||||
|
//fill the database if needed
|
||||||
|
$query="SELECT * FROM $dbname.{$dbtableprefix}users";
|
||||||
|
$result = mysql_query($query,$connection);
|
||||||
|
if (!$result) {
|
||||||
|
OC_DB::createDbFromStructure('db_structure.xml');
|
||||||
|
}
|
||||||
|
mysql_close($connection);
|
||||||
}
|
}
|
||||||
//fill the database if needed
|
|
||||||
$query="SELECT * FROM $dbname.{$dbtableprefix}users";
|
|
||||||
$result = mysql_query($query,$connection);
|
|
||||||
if (!$result) {
|
|
||||||
OC_DB::createDbFromStructure('db_structure.xml');
|
|
||||||
}
|
|
||||||
mysql_close($connection);
|
|
||||||
}else{
|
}else{
|
||||||
//in case of sqlite, we can always fill the database
|
//in case of sqlite, we can always fill the database
|
||||||
OC_DB::createDbFromStructure('db_structure.xml');
|
OC_DB::createDbFromStructure('db_structure.xml');
|
||||||
}
|
}
|
||||||
|
if(count($error)==0){
|
||||||
//create the user and group
|
//create the user and group
|
||||||
OC_USER::createUser($username,$password);
|
OC_USER::createUser($username,$password);
|
||||||
OC_GROUP::createGroup('admin');
|
OC_GROUP::createGroup('admin');
|
||||||
OC_GROUP::addToGroup($username,'admin');
|
OC_GROUP::addToGroup($username,'admin');
|
||||||
|
|
||||||
//and we are done
|
//and we are done
|
||||||
OC_CONFIG::setValue('installed',true);
|
OC_CONFIG::setValue('installed',true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return $error;
|
return $error;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue