]> source.dussan.org Git - nextcloud-server.git/commitdiff
move sqlite database into the data folder, makes it easier to set the correct permissions
authorRobin Appelman <icewind1991@gmail.com>
Thu, 28 Apr 2011 14:54:10 +0000 (16:54 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Thu, 28 Apr 2011 14:54:10 +0000 (16:54 +0200)
3dparty/MDB2/Driver/Manager/sqlite.php
3dparty/MDB2/Driver/sqlite.php
lib/base.php
lib/database.php
lib/installer.php

index 3a5d266280e7f7dcd5a32d6c6756971782ca5842..5258cff891d1131c1d11a71b271cc488347a360f 100644 (file)
@@ -71,6 +71,8 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
      */
     function createDatabase($name, $options = array())
     {
+               global $SERVERROOT;
+               $datadir=OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );
         $db =$this->getDBInstance();
         if (PEAR::isError($db)) {
             return $db;
@@ -82,7 +84,8 @@ class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
                 'database already exists', __FUNCTION__);
         }
         $php_errormsg = '';
-        $handle = @sqlite_open($database_file, $db->dsn['mode'], $php_errormsg);
+        $database_file="$datadir/$database_file.db";
+        $handle = sqlite_open($database_file, $db->dsn['mode'], $php_errormsg);
         if (!$handle) {
             return $db->raiseError(MDB2_ERROR_CANNOT_CREATE, null, null,
                 (isset($php_errormsg) ? $php_errormsg : 'could not create the database file'), __FUNCTION__);
index 061b9c67aaa4d02d7b7e32ffd1373fff7dc9430e..49a8cbdfbc245cdac811026f8965cb290578aa16 100644 (file)
@@ -347,6 +347,8 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
      **/
     function connect()
     {
+               global $SERVERROOT;
+               $datadir=OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );
         $database_file = $this->_getDatabaseFile($this->database_name);
         if (is_resource($this->connection)) {
             //if (count(array_diff($this->connected_dsn, $this->dsn)) == 0
@@ -370,6 +372,9 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
         }
 
         if ($database_file !== ':memory:') {
+                       if(!strpos($database_file,'.db')){
+                               $database_file="$datadir/$database_file.db";
+                       }
             if (!file_exists($database_file)) {
                 if (!touch($database_file)) {
                     return $this->raiseError(MDB2_ERROR_NOT_FOUND, null, null,
@@ -405,7 +410,9 @@ class MDB2_Driver_sqlite extends MDB2_Driver_Common
         $php_errormsg = '';
         if (version_compare('5.1.0', PHP_VERSION, '>')) {
             @ini_set('track_errors', true);
+            echo 1;
             $connection = @$connect_function($database_file);
+            echo 2;
             @ini_restore('track_errors');
         } else {
             $connection = @$connect_function($database_file, 0666, $php_errormsg);
index 10d59a9d0d624bbdc0dc8fe92fd2714fa126684d..ab8d0d056b179de494255dd863ad4e81383926fe 100644 (file)
@@ -302,20 +302,6 @@ class OC_UTIL {
                
                //check for correct file permissions
                if(!stristr(PHP_OS, 'WIN')){
-                       if($CONFIG_DBTYPE=='sqlite'){
-                               $file=$SERVERROOT.'/'.$CONFIG_DBNAME;
-                               if(file_exists($file)){
-                                       $prems=substr(decoct(fileperms($file)),-3);
-                                       if(substr($prems,2,1)!='0'){
-                                               @chmod($file,0660);
-                                               clearstatcache();
-                                               $prems=substr(decoct(fileperms($file)),-3);
-                                               if(substr($prems,2,1)!='0'){
-                                                       $errors[]=array('error'=>'SQLite database file ('.$file.') is readable from the web<br/>','hint'=>$permissionsHint);
-                                               }
-                                       }
-                               }
-                       }
                        $prems=substr(decoct(fileperms($CONFIG_DATADIRECTORY_ROOT)),-3);
                        if(substr($prems,-1)!='0'){
                                OC_HELPER::chmodr($CONFIG_DATADIRECTORY_ROOT,0770);
index 97651ccf50ad6567f3a8a093fc8cd66c29c909b5..3c2480c8b6defb54be532ae4b417b1737c09569b 100644 (file)
@@ -43,8 +43,8 @@ class OC_DB {
                $CONFIG_DBUSER = OC_CONFIG::getValue( "dbuser", "" );;
                $CONFIG_DBPASSWORD = OC_CONFIG::getValue( "dbpassword", "" );;
                $CONFIG_DBTYPE = OC_CONFIG::getValue( "dbtype", "sqlite" );;
-               global $DOCUMENTROOT;
                global $SERVERROOT;
+               $datadir=OC_CONFIG::getValue( "datadirectory", "$SERVERROOT/data" );
 
                // do nothing if the connection already has been established
                if(!self::$DBConnection){
@@ -64,7 +64,7 @@ class OC_DB {
                                // sqlite
                                $dsn = array(
                                  'phptype'  => 'sqlite',
-                                 'database' => "$SERVERROOT/$CONFIG_DBNAME",
+                                 'database' => "$datadir/$CONFIG_DBNAME.db",
                                  'mode' => '0644' );
                        }
                        elseif( $CONFIG_DBTYPE == 'mysql' ){
@@ -256,9 +256,9 @@ class OC_DB {
                if( $definition instanceof MDB2_Schema_Error ){
                        die( $definition->getMessage().': '.$definition->getUserInfo());
                }
-               if(OC_CONFIG::getValue('dbtype','sqlite')=='sqlite'){
-                       $definition['overwrite']=true;//always overwrite for sqlite
-               }
+//             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
index 1222a22e71c206da3852d21a59ed3a8c61163de8..0646ef8e0ea52f56f8e67f667087b5f329025f7e 100644 (file)
@@ -136,7 +136,7 @@ class OC_INSTALLER{
                global $SERVERROOT;
                global $WEBROOT;
                $content="ErrorDocument 404 /$WEBROOT/templates/404.php\n";
-               file_put_contents($SERVERROOT.'/.htaccess',$content);
+               @file_put_contents($SERVERROOT.'/.htaccess',$content); //supress errors in case we don't have permissions for it
                
                $content="deny from all";
                file_put_contents(OC_CONFIG::getValue('datadirectory',$SERVERROOT.'/data').'/.htaccess',$content);