summaryrefslogtreecommitdiffstats
path: root/lib/db.php
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2011-10-23 15:25:38 +0200
committerRobin Appelman <icewind1991@gmail.com>2011-10-23 15:25:38 +0200
commitf073041b0be22947d9790f46dd0d61b9695a3ae9 (patch)
tree6bda12c55b6fba75964fc233b78040632c829361 /lib/db.php
parent6592fbb948153e17dc90d1e167060a1d5c5bbe40 (diff)
downloadnextcloud-server-f073041b0be22947d9790f46dd0d61b9695a3ae9.tar.gz
nextcloud-server-f073041b0be22947d9790f46dd0d61b9695a3ae9.zip
provide function for updating the database scheme
Diffstat (limited to 'lib/db.php')
-rw-r--r--lib/db.php37
1 files changed, 35 insertions, 2 deletions
diff --git a/lib/db.php b/lib/db.php
index 58479bacfb9..421b08c2320 100644
--- a/lib/db.php
+++ b/lib/db.php
@@ -263,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
@@ -299,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 );
@@ -326,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