diff options
author | Bart Visscher <bartv@thisnet.nl> | 2011-10-24 22:40:22 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2011-10-24 22:40:22 +0200 |
commit | 9832a0817dfe975dd768e24b1f51b0591bbfa3b3 (patch) | |
tree | 7252d1541e7b34ad1d04d7864f5ecd20b7154c4b /lib | |
parent | dc9c5f10f57bf3d3c375e6fe1f89a358ca1947a8 (diff) | |
parent | abf33d32b9987cc22cd42e6d65ac13720c7f1c7c (diff) | |
download | nextcloud-server-9832a0817dfe975dd768e24b1f51b0591bbfa3b3.tar.gz nextcloud-server-9832a0817dfe975dd768e24b1f51b0591bbfa3b3.zip |
Merge branch 'master' into fullcalendar
Conflicts:
apps/calendar/index.php
Diffstat (limited to 'lib')
-rw-r--r-- | lib/config.php | 2 | ||||
-rw-r--r-- | lib/db.php | 52 | ||||
-rw-r--r-- | lib/filestorage/local.php | 21 | ||||
-rw-r--r-- | lib/filesystem.php | 4 | ||||
-rw-r--r-- | lib/util.php | 4 |
5 files changed, 66 insertions, 17 deletions
diff --git a/lib/config.php b/lib/config.php index 3aa69327f56..2c82036257f 100644 --- a/lib/config.php +++ b/lib/config.php @@ -175,7 +175,7 @@ class OC_Config{ $result=@file_put_contents( OC::$SERVERROOT."/config/config.php", $content ); if(!$result) { $tmpl = new OC_Template( '', 'error', 'guest' ); - $tmpl->assign('errors',array(1=>array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by setting the owner of 'config' to the user that the web server uses (".OC_Util::checkWebserverUser().")"))); + $tmpl->assign('errors',array(1=>array('error'=>"Can't write into config directory 'config'",'hint'=>"You can usually fix this by giving the webserver use write access to the config directory in owncloud"))); $tmpl->printPage(); exit; } diff --git a/lib/db.php b/lib/db.php index 44be619fde1..421b08c2320 100644 --- a/lib/db.php +++ b/lib/db.php @@ -42,11 +42,22 @@ class OC_DB { * * Connects to the database as specified in config.php */ - public static function connect(){ + public static function connect($backend=null){ if(self::$connection){ return; } - if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2) + if(is_null($backend)){ + $backend=self::BACKEND_MDB2; + if(class_exists('PDO') && OC_Config::getValue('installed', false)){//check if we can use PDO, else use MDB2 (instalation always needs to be done my mdb2) + $type = OC_Config::getValue( "dbtype", "sqlite" ); + if($type=='sqlite3') $type='sqlite'; + $drivers=PDO::getAvailableDrivers(); + if(array_search($type,$drivers)!==false){ + $backend=self::BACKEND_PDO; + } + } + } + if($backend==self::BACKEND_PDO){ self::connectPDO(); self::$connection=self::$PDO; self::$backend=self::BACKEND_PDO; @@ -252,7 +263,7 @@ class OC_DB { * * TODO: write more documentation */ - public static function getDbStructure( $file ){ + public static function getDbStructure( $file ,$mode=MDB2_SCHEMA_DUMP_STRUCTURE){ self::connectScheme(); // write the scheme @@ -288,7 +299,7 @@ class OC_DB { $file2 = tempnam( get_temp_dir(), 'oc_db_scheme_' ); $content = str_replace( '*dbname*', $CONFIG_DBNAME, $content ); $content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content ); - if( $CONFIG_DBTYPE == 'pgsql' ){ //mysql support it too but sqlite don't + if( $CONFIG_DBTYPE == 'pgsql' ){ //mysql support it too but sqlite doesn't $content = str_replace( '<default>0000-00-00 00:00:00</default>', '<default>CURRENT_TIMESTAMP</default>', $content ); } file_put_contents( $file2, $content ); @@ -315,6 +326,39 @@ class OC_DB { return true; } + + /** + * @brief update the database scheme + * @param $file file to read structure from + */ + public static function updateDbFromStructure($file){ + $CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" ); + $CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" ); + $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); + + self::connectScheme(); + + // read file + $content = file_get_contents( $file ); + + // Make changes and save them to a temporary file + $file2 = tempnam( get_temp_dir(), 'oc_db_scheme_' ); + $content = str_replace( '*dbname*', $CONFIG_DBNAME, $content ); + $content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content ); + if( $CONFIG_DBTYPE == 'pgsql' ){ //mysql support it too but sqlite doesn't + $content = str_replace( '<default>0000-00-00 00:00:00</default>', '<default>CURRENT_TIMESTAMP</default>', $content ); + } + file_put_contents( $file2, $content ); + $previousSchema = self::$schema->getDefinitionFromDatabase(); + $op = $schema->updateDatabase($file2, $previousSchema, array(), false); + + if (PEAR::isError($op)) { + $error = $op->getMessage(); + OC_Log::write('core','Failed to update database structure ('.$error.')',OC_Log::FATAL); + return false; + } + return true; + } /** * @brief connects to a MDB2 database scheme diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 58c34e972de..01523b6b0b3 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -126,18 +126,21 @@ class OC_Filestorage_Local extends OC_Filestorage{ public function getMimeType($fspath){ if($this->is_readable($fspath)){ + $mimeType='application/octet-stream'; if (@is_dir($this->datadir.$fspath)) { // directories are easy return "httpd/unix-directory"; - }elseif (function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){ + } + if($mimeType=='application/octet-stream' and function_exists('finfo_open') and function_exists('finfo_file') and $finfo=finfo_open(FILEINFO_MIME)){ $mimeType =strtolower(finfo_file($finfo,$this->datadir.$fspath)); $mimeType=substr($mimeType,0,strpos($mimeType,';')); finfo_close($finfo); - return $mimeType; - } else if (function_exists("mime_content_type")) { + } + if ($mimeType=='application/octet-stream' && function_exists("mime_content_type")) { // use mime magic extension if available - $mime_type = mime_content_type($this->datadir.$fspath); - } else if (OC_Helper::canExecute("file")) { + $mimeType = mime_content_type($this->datadir.$fspath); + } + if ($mimeType=='application/octet-stream' && OC_Helper::canExecute("file")) { // it looks like we have a 'file' command, // lets see it it does have mime support $fspath=str_replace("'","\'",$fspath); @@ -146,18 +149,18 @@ class OC_Filestorage_Local extends OC_Filestorage{ pclose($fp); //trim the character set from the end of the response - $mime_type=substr($reply,0,strrpos($reply,' ')); + $mimeType=substr($reply,0,strrpos($reply,' ')); } - if (empty($mime_type)) { + if ($mimeType=='application/octet-stream') { // Fallback solution: (try to guess the type by the file extension if(!self::$mimetypes){ self::$mimetypes=include('mimetypes.list.php'); } $extention=strtolower(strrchr(basename($fspath), ".")); $extention=substr($extention,1);//remove leading . - $mime_type=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream'; + $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream'; } - return $mime_type; + return $mimeType; } } diff --git a/lib/filesystem.php b/lib/filesystem.php index 3497431f1ee..cae8ead5b16 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -366,9 +366,11 @@ class OC_Filesystem{ case 'a': $hooks[]='write'; break; + default: + OC_Log::write('core','invalid mode ('.$mode.') for '.$path,OC_Log::ERROR); } - return self::basicOperation('fopen',$path,$hooks); + return self::basicOperation('fopen',$path,$hooks,$mode); } static public function toTmpFile($path){ if(OC_FileProxy::runPreProxies('toTmpFile',$path) and self::canRead($path) and $storage=self::getStorage($path)){ diff --git a/lib/util.php b/lib/util.php index 90cc1f6123a..14313569a1d 100644 --- a/lib/util.php +++ b/lib/util.php @@ -24,7 +24,7 @@ class OC_Util { $success=@mkdir($CONFIG_DATADIRECTORY_ROOT); if(!$success) { $tmpl = new OC_Template( '', 'error', 'guest' ); - $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by setting the owner of '".OC::$SERVERROOT."' to the user that the web server uses (".OC_Util::checkWebserverUser().")"))); + $tmpl->assign('errors',array(1=>array('error'=>"Can't create data directory (".$CONFIG_DATADIRECTORY_ROOT.")",'hint'=>"You can usually fix this by giving the webserver write access to the ownCloud directory '".OC::$SERVERROOT."' "))); $tmpl->printPage(); exit; } @@ -183,7 +183,7 @@ class OC_Util { $serverUser=OC_Util::checkWebserverUser(); //common hint for all file permissons error messages - $permissionsHint="Permissions can usually be fixed by setting the owner of the file or directory to the user the web server runs as ($serverUser)"; + $permissionsHint="Permissions can usually be fixed by giving the webserver write access to the ownCloud directory"; //check for correct file permissions if(!stristr(PHP_OS, 'WIN')){ |