]> source.dussan.org Git - nextcloud-server.git/commitdiff
add option to remove tables install from database structure
authorRobin Appelman <icewind1991@gmail.com>
Sun, 12 Jun 2011 15:51:31 +0000 (17:51 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Sun, 12 Jun 2011 15:51:31 +0000 (17:51 +0200)
lib/database.php

index 728e73590407416e3d0586b8937c312ec319d064..0f0950d05adc1b80b55043a9cb6b01139e010488 100644 (file)
@@ -321,5 +321,43 @@ class OC_DB {
 
                return $query;
        }
+       
+       /**
+        * @brief drop a table
+        * @param string $tableNamme the table to drop
+        */
+       public static function dropTable($tableName){
+               self::connect();
+               self::$DBConnection->loadModule('Manager');
+               self::$DBConnection->dropTable($tableName);
+       }
+       
+       /**
+        * remove all tables defined in a database structure xml file
+        * @param string $file the xml file describing the tables
+        */
+       public static function removeDBStructure($file){
+               $CONFIG_DBNAME  = OC_CONFIG::getValue( "dbname", "owncloud" );
+               $CONFIG_DBTABLEPREFIX = OC_CONFIG::getValue( "dbtableprefix", "oc_" );
+               self::connectScheme();
+
+               // read file
+               $content = file_get_contents( $file );
+
+               // Make changes and save them to a temporary file
+               $file2 = tempnam( sys_get_temp_dir(), 'oc_db_scheme_' );
+               $content = str_replace( '*dbname*', $CONFIG_DBNAME, $content );
+               $content = str_replace( '*dbprefix*', $CONFIG_DBTABLEPREFIX, $content );
+               file_put_contents( $file2, $content );
+
+               // get the tables
+               $definition = self::$schema->parseDatabaseDefinitionFile( $file2 );
+               
+               // Delete our temporary file
+               unlink( $file2 );
+               foreach($definition['tables'] as $name=>$table){
+                       self::dropTable($name);
+               }
+       }
 }
 ?>
\ No newline at end of file