automatically upgrade the main database on version number increase (doesnt work with sqlite for now)

This commit is contained in:
Robin Appelman 2011-11-13 16:16:21 +01:00
parent 9a4e37483b
commit ecf6f2ca2f
2 changed files with 12 additions and 7 deletions

View File

@ -152,6 +152,12 @@ 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');
}
ini_set('session.cookie_httponly','1;'); ini_set('session.cookie_httponly','1;');
session_start(); session_start();
@ -230,8 +236,6 @@ if( !isset( $RUNTIME_NOAPPS )){
$RUNTIME_NOAPPS = false; $RUNTIME_NOAPPS = false;
} }
OC::init();
if(!function_exists('get_temp_dir')) { if(!function_exists('get_temp_dir')) {
function get_temp_dir() { function get_temp_dir() {
if( $temp=ini_get('upload_tmp_dir') ) return $temp; if( $temp=ini_get('upload_tmp_dir') ) return $temp;
@ -247,6 +251,8 @@ if(!function_exists('get_temp_dir')) {
} }
} }
OC::init();
require_once('fakedirstream.php'); require_once('fakedirstream.php');

View File

@ -338,7 +338,6 @@ class OC_DB {
* @param $file file to read structure from * @param $file file to read structure from
*/ */
public static function updateDbFromStructure($file){ public static function updateDbFromStructure($file){
$CONFIG_DBNAME = OC_Config::getValue( "dbname", "owncloud" );
$CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" ); $CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" );
$CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" );
@ -347,17 +346,17 @@ class OC_DB {
// read file // read file
$content = file_get_contents( $file ); $content = file_get_contents( $file );
$previousSchema = self::$schema->getDefinitionFromDatabase();
// Make changes and save them to a temporary file // Make changes and save them to a temporary file
$file2 = tempnam( get_temp_dir(), 'oc_db_scheme_' ); $file2 = tempnam( get_temp_dir(), 'oc_db_scheme_' );
$content = str_replace( '*dbname*', $CONFIG_DBNAME, $content ); $content = str_replace( '*dbname*', $previousSchema['name'], $content );
$content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content ); $content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content );
if( $CONFIG_DBTYPE == 'pgsql' ){ //mysql support it too but sqlite doesn'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 ); $content = str_replace( '<default>0000-00-00 00:00:00</default>', '<default>CURRENT_TIMESTAMP</default>', $content );
} }
file_put_contents( $file2, $content ); file_put_contents( $file2, $content );
$previousSchema = self::$schema->getDefinitionFromDatabase(); $op = self::$schema->updateDatabase($file2, $previousSchema, array(), false);
$op = $schema->updateDatabase($file2, $previousSchema, array(), false);
if (PEAR::isError($op)) { if (PEAR::isError($op)) {
$error = $op->getMessage(); $error = $op->getMessage();
OC_Log::write('core','Failed to update database structure ('.$error.')',OC_Log::FATAL); OC_Log::write('core','Failed to update database structure ('.$error.')',OC_Log::FATAL);