From: Robin Appelman Date: Sun, 12 Jun 2011 15:51:31 +0000 (+0200) Subject: add option to remove tables install from database structure X-Git-Tag: v3.0~267^2~536 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=964b51879eaffed13287a1e450e6f37171be2e62;p=nextcloud-server.git add option to remove tables install from database structure --- 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