diff options
author | Robin Appelman <icewind1991@gmail.com> | 2011-06-12 17:51:31 +0200 |
---|---|---|
committer | Robin Appelman <icewind1991@gmail.com> | 2011-06-12 17:51:31 +0200 |
commit | 964b51879eaffed13287a1e450e6f37171be2e62 (patch) | |
tree | ff0f48df0c38f256bdab2b916169cd869bba1ad0 /lib | |
parent | e179ef5547a19153ee285d9866b8bf3af91a8eca (diff) | |
download | nextcloud-server-964b51879eaffed13287a1e450e6f37171be2e62.tar.gz nextcloud-server-964b51879eaffed13287a1e450e6f37171be2e62.zip |
add option to remove tables install from database structure
Diffstat (limited to 'lib')
-rw-r--r-- | lib/database.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/database.php b/lib/database.php index 728e7359040..0f0950d05ad 100644 --- a/lib/database.php +++ b/lib/database.php @@ -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 |