Create module helper and refactor all the code that creates, updates

and deletes modules into it.
This commit is contained in:
Bharat Mediratta
2008-11-13 10:38:28 +00:00
parent 6d7130bffc
commit 0fe8d44472
4 changed files with 59 additions and 43 deletions
+5 -17
View File
@@ -21,19 +21,10 @@ class comment_installer {
public static function install() {
Kohana::log("debug", "comment_installer::install");
$db = Database::instance();
try {
$base_version = ORM::factory("module")->where("name", "comment")->find()->version;
} catch (Exception $e) {
if ($e->getCode() == E_DATABASE_ERROR) {
$base_version = 0;
} else {
Kohana::log("error", $e);
throw $e;
}
}
Kohana::log("debug", "base_version: $base_version");
$version = module::get_version("comment");
Kohana::log("debug", "version: $version");
if ($base_version == 0) {
if ($version == 0) {
$db->query("CREATE TABLE IF NOT EXISTS `comments` (
`id` int(9) NOT NULL auto_increment,
`author` varchar(255) default NULL,
@@ -44,16 +35,13 @@ class comment_installer {
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$comment_module = ORM::factory("module")->where("name", "comment")->find();
$comment_module->name = "comment";
$comment_module->version = 1;
$comment_module->save();
module::set_version("comment", 1);
}
}
public static function uninstall() {
$db = Database::instance();
$db->query("DROP TABLE IF EXISTS `comments`;");
ORM::factory("module")->where("name", "comment")->find()->delete();
module::delete("comment");
}
}