diff options
author | Robin Appelman <icewind1991@gmail.com> | 2011-11-04 03:00:03 +0100 |
---|---|---|
committer | Robin Appelman <icewind1991@gmail.com> | 2011-11-04 03:00:03 +0100 |
commit | 2c68aab1983c912e52af6c0f62bc04850178894b (patch) | |
tree | 0cbf68f3be22624f2dbb8e1b752ad99e1679b625 /lib | |
parent | 0c890a501cc7c24fb7eb5a4e4bff35dd2bb56b6d (diff) | |
parent | ce2b39b398b1bf2143e1b16523de5325a766d24d (diff) | |
download | nextcloud-server-2c68aab1983c912e52af6c0f62bc04850178894b.tar.gz nextcloud-server-2c68aab1983c912e52af6c0f62bc04850178894b.zip |
Merge branch 'master' into newbutton
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 3 | ||||
-rw-r--r-- | lib/db.php | 62 | ||||
-rw-r--r-- | lib/filestorage/local.php | 5 | ||||
-rw-r--r-- | lib/setup.php | 4 |
4 files changed, 66 insertions, 8 deletions
diff --git a/lib/base.php b/lib/base.php index d5fff1e0a74..c52b4493e01 100644 --- a/lib/base.php +++ b/lib/base.php @@ -77,6 +77,9 @@ class OC{ // set some stuff //ob_start(); error_reporting(E_ALL | E_STRICT); + if (defined('DEBUG') && DEBUG){ + ini_set('display_errors', 1); + } date_default_timezone_set('Europe/Berlin'); ini_set('arg_separator.output','&'); diff --git a/lib/db.php b/lib/db.php index 44be619fde1..c059f5ab336 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; @@ -213,6 +224,7 @@ class OC_DB { /** * @brief gets last value of autoincrement + * @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix * @returns id * * MDB2 lastInsertID() @@ -220,9 +232,14 @@ class OC_DB { * Call this method right after the insert command or other functions may * cause trouble! */ - public static function insertid(){ + public static function insertid($table=null){ self::connect(); - return self::$connection->lastInsertId(); + if($table !== null){ + $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); + $suffix = OC_Config::getValue( "dbsequencesuffix", "_id_seq" ); + $table = str_replace( '*PREFIX*', $prefix, $table ); + } + return self::$connection->lastInsertId($table.$suffix); } /** @@ -252,7 +269,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 +305,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 +332,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 01523b6b0b3..9e29f85071a 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -84,6 +84,11 @@ class OC_Filestorage_Local extends OC_Filestorage{ return $return; } public function rename($path1,$path2){ + if(! $this->file_exists($path1)){ + OC_Log::write('core','unable to rename, file does not exists : '.$path1,OC_Log::ERROR); + return false; + } + if($return=rename($this->datadir.$path1,$this->datadir.$path2)){ $this->clearFolderSizeCache($path1); $this->clearFolderSizeCache($path2); diff --git a/lib/setup.php b/lib/setup.php index 2dcedb9b820..e2d56ddaf4a 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -82,7 +82,7 @@ class OC_Setup { $dbpass = $options['dbpass']; $dbname = $options['dbname']; $dbhost = $options['dbhost']; - $dbtableprefix = OC_Config::getValue('dbtableprefix','oc_'); + $dbtableprefix = $options['dbtableprefix']; OC_Config::setValue('dbname', $dbname); OC_Config::setValue('dbhost', $dbhost); OC_Config::setValue('dbtableprefix', $dbtableprefix); @@ -135,7 +135,7 @@ class OC_Setup { $dbpass = $options['dbpass']; $dbname = $options['dbname']; $dbhost = $options['dbhost']; - $dbtableprefix = OC_Config::getValue('dbtableprefix','oc_'); + $dbtableprefix = $options['dbtableprefix']; OC_CONFIG::setValue('dbname', $dbname); OC_CONFIG::setValue('dbhost', $dbhost); OC_CONFIG::setValue('dbtableprefix', $dbtableprefix); |