diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 16 | ||||
-rw-r--r-- | lib/db.php | 24 | ||||
-rw-r--r-- | lib/setup.php | 41 |
3 files changed, 56 insertions, 25 deletions
diff --git a/lib/base.php b/lib/base.php index 83b14f2b970..9ac6b6751a2 100644 --- a/lib/base.php +++ b/lib/base.php @@ -152,14 +152,16 @@ class OC{ } } - $installedVersion=OC_Config::getValue('version','0.0.0'); - $currentVersion=implode('.',OC_Util::getVersion()); - if (version_compare($currentVersion, $installedVersion, '>')) { - OC_DB::updateDbFromStructure('../db_structure.xml'); - OC_Config::setValue('version',implode('.',OC_Util::getVersion())); - } + if(OC_Config::getValue('installed', false)){ + $installedVersion=OC_Config::getValue('version','0.0.0'); + $currentVersion=implode('.',OC_Util::getVersion()); + if (version_compare($currentVersion, $installedVersion, '>')) { + OC_DB::updateDbFromStructure('../db_structure.xml'); + OC_Config::setValue('version',implode('.',OC_Util::getVersion())); + } - OC_App::updateApps(); + OC_App::updateApps(); + } ini_set('session.cookie_httponly','1;'); session_start(); diff --git a/lib/db.php b/lib/db.php index 05ed8398b7b..b901cc8b513 100644 --- a/lib/db.php +++ b/lib/db.php @@ -71,7 +71,14 @@ class OC_DB { /** * connect to the database using pdo */ - private static function connectPDO(){ + public static function connectPDO(){ + if(self::$connection){ + if(self::$backend==self::BACKEND_MDB2){ + self::disconnect(); + }else{ + return; + } + } // The global data we need $name = OC_Config::getValue( "dbname", "owncloud" ); $host = OC_Config::getValue( "dbhost", "" ); @@ -113,7 +120,14 @@ class OC_DB { /** * connect to the database using mdb2 */ - static private function connectMDB2(){ + public static function connectMDB2(){ + if(self::$connection){ + if(self::$backend==self::BACKEND_PDO){ + self::disconnect(); + }else{ + return; + } + } // The global data we need $name = OC_Config::getValue( "dbname", "owncloud" ); $host = OC_Config::getValue( "dbhost", "" ); @@ -255,8 +269,8 @@ class OC_DB { self::$connection->disconnect(); } self::$connection=false; - self::$mdb2=false; - self::$pdo=false; + self::$MDB2=false; + self::$PDO=false; } return true; @@ -374,6 +388,8 @@ class OC_DB { private static function connectScheme(){ // We need a mdb2 database connection self::connectMDB2(); + self::$MDB2->loadModule('Manager'); + self::$MDB2->loadModule('Reverse'); // Connect if this did not happen before if(!self::$schema){ diff --git a/lib/setup.php b/lib/setup.php index d454c17599d..1b74e945196 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -98,35 +98,45 @@ class OC_Setup { ); } else { + $oldUser=OC_Config::getValue('dbuser', false); + $oldPassword=OC_Config::getValue('dbpassword', false); + $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)) { //use the admin login data for the new database user //add prefix to the mysql user name to prevent collissions - $dbusername=substr('oc_mysql_'.$username,0,16); - //hash the password so we don't need to store the admin config in the config file - $dbpassword=md5(time().$password); - - self::createDBUser($dbusername, $dbpassword, $connection); - - OC_Config::setValue('dbuser', $dbusername); - OC_Config::setValue('dbpassword', $dbpassword); + $dbusername=substr('oc_'.$username,0,16); + if($dbusername!=$oldUser){ + //hash the password so we don't need to store the admin config in the config file + $dbpassword=md5(time().$password); + + self::createDBUser($dbusername, $dbpassword, $connection); + + OC_Config::setValue('dbuser', $dbusername); + OC_Config::setValue('dbpassword', $dbpassword); + } //create the database self::createDatabase($dbname, $dbusername, $connection); } else { - OC_Config::setValue('dbuser', $dbuser); - OC_Config::setValue('dbpassword', $dbpass); + if($dbuser!=$oldUser){ + OC_Config::setValue('dbuser', $dbuser); + OC_Config::setValue('dbpassword', $dbpass); + } //create the database self::createDatabase($dbname, $dbuser, $connection); } //fill the database if needed - $query="SELECT * FROM $dbname.{$dbtableprefix}users"; + $query="select count(*) from information_schema.tables where table_schema='$dbname' AND table_name = '{$dbtableprefix}users';"; $result = mysql_query($query,$connection); - if(!$result) { + if($result){ + $row=mysql_fetch_row($result); + } + if(!$result or $row[0]==0) { OC_DB::createDbFromStructure('db_structure.xml'); } mysql_close($connection); @@ -180,9 +190,12 @@ class OC_Setup { } //fill the database if needed - $query = "SELECT relname FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1"; + $query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1"; $result = pg_query($connection, $query); - if(!$result) { + if($result){ + $row = pg_fetch_row($result); + } + if(!$result or $row[0]==0) { OC_DB::createDbFromStructure('db_structure.xml'); } pg_close($connection); |