query("CREATE TABLE IF NOT EXISTS `users` ( `id` int(9) NOT NULL auto_increment, `name` varchar(32) NOT NULL, `display_name` varchar(255) NOT NULL, `password` varchar(128) NOT NULL, `login_count` int(10) unsigned NOT NULL DEFAULT 0, `last_login` int(10) unsigned NOT NULL DEFAULT 0, `email` varchar(255) default NULL, `admin` BOOLEAN default 0, PRIMARY KEY (`id`), UNIQUE KEY(`display_name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE IF NOT EXISTS `groups` ( `id` int(9) NOT NULL auto_increment, `name` char(255) default NULL, PRIMARY KEY (`id`), UNIQUE KEY(`name`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); $db->query("CREATE TABLE IF NOT EXISTS `groups_users` ( `group_id` int(9) NOT NULL, `user_id` int(9) NOT NULL, PRIMARY KEY (`group_id`, `user_id`), UNIQUE KEY(`user_id`, `group_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); module::set_version("user", 1); $registered = group::create("Registered Users"); // @todo: get this info from the installer $admin = user::create("admin", "Gallery Administrator", "admin"); $user = user::create("joe", "Joe User", "joe"); group::add_user($registered->id, $admin->id); group::add_user($registered->id, $user->id); // Let the admin own everything $db->query("UPDATE `items` SET `owner_id` = {$admin->id} WHERE `owner_id` IS NULL"); } } public static function uninstall() { // Remove all our groups so that we clean up the items table foreach (ORM::factory("group")->find_all() as $group) { try { group::delete($group->id); } catch (Kohana_Database_Exception $e) { // We may get errors when we try to remove the view columns from the items table. // Ignore those for now. } } try { Session::instance()->destroy(); } catch (Exception $e) { } $db = Database::instance(); $db->query("DROP TABLE IF EXISTS `users`;"); $db->query("DROP TABLE IF EXISTS `groups`;"); $db->query("DROP TABLE IF EXISTS `groups_users`;"); module::delete("user"); } }