where("name", "core")->find()->version; } catch (Exception $e) { if ($e->getMessage() == "Table modules does not exist in your database.") { $base_version = 0; } else { throw $e; } } if ($base_version == 0) { $db->query("CREATE TABLE `modules` ( `id` int(9) NOT NULL auto_increment, `name` char(255) default NULL, `version` int(9) default NULL, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE `items` ( `id` int(9) NOT NULL auto_increment, `type` char(32) NOT NULL, `title` char(255) default NULL, `description` char(255) default NULL, `name` char(255) default NULL, `left` int(9) NOT NULL, `right` int(9) NOT NULL, `parent_id` int(9) NOT NULL, `level` int(9) NOT NULL, `thumbnail_width` int(9) default NULL, `thumbnail_height` int(9) default NULL, `resize_width` int(9) default NULL, `resize_height` int(9) default NULL, PRIMARY KEY (`id`), KEY `parent_id` (`parent_id`), KEY `type` (`type`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); foreach (array("albums", "resizes") as $dir) { @mkdir(VARPATH . $dir); } $core = ORM::factory("module")->where("name", "core")->find(); $core->name = "core"; $core->version = 1; $core->save(); $root = ORM::factory("item"); $root->type = 'album'; $root->title = "Gallery"; $root->description = "Welcome to your Gallery3"; $root->left = 1; $root->right = 2; $root->parent_id = 0; $root->level = 1; $root->save(); } } public static function uninstall() { $db = Database::instance(); $db->query("DROP TABLE IF EXISTS `items`;"); $db->query("DROP TABLE IF EXISTS `modules`;"); system("/bin/rm -rf " . VARPATH . "albums"); system("/bin/rm -rf " . VARPATH . "resizes"); } }