mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-08-18 21:05:01 -04:00
Create module helper and refactor all the code that creates, updates
and deletes modules into it.
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user