Refactor the install/upgrade code to be more flexible.

Add xxx_installer::upgrade($version) method so that upgrade stanzas
are separate from install stanzas.  In the old code, to do an upgrade
meant that you had to re-evolve everything from the initial install
because we'd step through each version's changes.  But what we really
want is for the initial install to start off in the perfect initial
state, and the upgrades to do the work behind the scenes.  So now the
install() function gets things set up properly the first time, and the
upgrade() function does any work to catch you up to the latest code.
See gallery_installer.php for a good example.
This commit is contained in:
Bharat Mediratta
2009-06-23 12:00:49 -07:00
parent 342d5e1186
commit bfca0c7903
21 changed files with 429 additions and 449 deletions

View File

@@ -335,4 +335,4 @@ CREATE TABLE {vars} (
UNIQUE KEY `module_name` (`module_name`,`name`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
INSERT INTO {vars} VALUES (1,'gallery','active_site_theme','default'),(2,'gallery','active_admin_theme','admin_default'),(3,'gallery','page_size','9'),(4,'gallery','thumb_size','200'),(5,'gallery','resize_size','640'),(6,'gallery','default_locale','en_US'),(7,'gallery','image_quality','75'),(9,'gallery','blocks_dashboard_sidebar','a:4:{i:2;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"block_adder\";}i:3;a:2:{i:0;s:7:\"gallery\";i:1;s:5:\"stats\";}i:4;a:2:{i:0;s:7:\"gallery\";i:1;s:13:\"platform_info\";}i:5;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"project_news\";}}'),(14,'gallery','blocks_dashboard_center','a:4:{i:6;a:2:{i:0;s:7:\"gallery\";i:1;s:7:\"welcome\";}i:7;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"photo_stream\";}i:8;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"log_entries\";}i:9;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(17,'gallery','version','3.0 pre beta 2 (git)'),(18,'gallery','choose_default_tookit','1'),(19,'gallery','credits','Powered by <a href=\"%url\">Gallery %version</a>'),(20,'gallery','date_format','Y-M-d'),(21,'gallery','date_time_format','Y-M-d H:i:s'),(22,'gallery','time_format','H:i:s'),(24,'comment','spam_caught','0');
INSERT INTO {vars} VALUES (1,'gallery','active_site_theme','default'),(2,'gallery','active_admin_theme','admin_default'),(3,'gallery','page_size','9'),(4,'gallery','thumb_size','200'),(5,'gallery','resize_size','640'),(6,'gallery','default_locale','en_US'),(7,'gallery','image_quality','75'),(9,'gallery','blocks_dashboard_sidebar','a:4:{i:2;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"block_adder\";}i:3;a:2:{i:0;s:7:\"gallery\";i:1;s:5:\"stats\";}i:4;a:2:{i:0;s:7:\"gallery\";i:1;s:13:\"platform_info\";}i:5;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"project_news\";}}'),(14,'gallery','blocks_dashboard_center','a:4:{i:6;a:2:{i:0;s:7:\"gallery\";i:1;s:7:\"welcome\";}i:7;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"photo_stream\";}i:8;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"log_entries\";}i:9;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(17,'gallery','version','3.0 pre beta 2 (git)'),(18,'gallery','choose_default_tookit','1'),(19,'gallery','date_format','Y-M-d'),(20,'gallery','date_time_format','Y-M-d H:i:s'),(21,'gallery','time_format','H:i:s'),(22,'gallery','credits','Powered by <a href=\"%url\">Gallery %version</a>'),(24,'comment','spam_caught','0');

View File

@@ -19,10 +19,7 @@
*/
class akismet_installer {
static function install() {
$version = module::get_version("akismet");
if ($version == 0) {
module::set_version("akismet", 1);
}
module::set_version("akismet", 1);
}
static function activate() {

View File

@@ -20,39 +20,35 @@
class comment_installer {
static function install() {
$db = Database::instance();
$version = module::get_version("comment");
$db->query("CREATE TABLE IF NOT EXISTS {comments} (
`author_id` int(9) default NULL,
`created` int(9) NOT NULL,
`guest_email` varchar(128) default NULL,
`guest_name` varchar(128) default NULL,
`guest_url` varchar(255) default NULL,
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) NOT NULL,
`server_http_accept_charset` varchar(64) default NULL,
`server_http_accept_encoding` varchar(64) default NULL,
`server_http_accept_language` varchar(64) default NULL,
`server_http_accept` varchar(128) default NULL,
`server_http_connection` varchar(64) default NULL,
`server_http_host` varchar(64) default NULL,
`server_http_referer` varchar(255) default NULL,
`server_http_user_agent` varchar(128) default NULL,
`server_query_string` varchar(64) default NULL,
`server_remote_addr` varchar(32) default NULL,
`server_remote_host` varchar(64) default NULL,
`server_remote_port` varchar(16) default NULL,
`state` char(15) default 'unpublished',
`text` text,
`updated` int(9) NOT NULL,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
if ($version == 0) {
$db->query("CREATE TABLE IF NOT EXISTS {comments} (
`author_id` int(9) default NULL,
`created` int(9) NOT NULL,
`guest_email` varchar(128) default NULL,
`guest_name` varchar(128) default NULL,
`guest_url` varchar(255) default NULL,
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) NOT NULL,
`server_http_accept_charset` varchar(64) default NULL,
`server_http_accept_encoding` varchar(64) default NULL,
`server_http_accept_language` varchar(64) default NULL,
`server_http_accept` varchar(128) default NULL,
`server_http_connection` varchar(64) default NULL,
`server_http_host` varchar(64) default NULL,
`server_http_referer` varchar(255) default NULL,
`server_http_user_agent` varchar(128) default NULL,
`server_query_string` varchar(64) default NULL,
`server_remote_addr` varchar(32) default NULL,
`server_remote_host` varchar(64) default NULL,
`server_remote_port` varchar(16) default NULL,
`state` char(15) default 'unpublished',
`text` text,
`updated` int(9) NOT NULL,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
block_manager::add("dashboard_center", "comment", "recent_comments");
module::set_var("comment", "spam_caught", 0);
module::set_version("comment", 1);
}
block_manager::add("dashboard_center", "comment", "recent_comments");
module::set_var("comment", "spam_caught", 0);
module::set_version("comment", 1);
}
static function uninstall() {

View File

@@ -19,21 +19,17 @@
*/
class exif_installer {
static function install() {
$version = module::get_version("exif");
if ($version == 0) {
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {exif_records} (
`id` int(9) NOT NULL auto_increment,
`item_id` INTEGER(9) NOT NULL,
`key_count` INTEGER(9) default 0,
`data` TEXT,
`dirty` BOOLEAN default 1,
PRIMARY KEY (`id`),
KEY(`item_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
module::set_version("exif", 1);
}
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {exif_records} (
`id` int(9) NOT NULL auto_increment,
`item_id` INTEGER(9) NOT NULL,
`key_count` INTEGER(9) default 0,
`data` TEXT,
`dirty` BOOLEAN default 1,
PRIMARY KEY (`id`),
KEY(`item_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
module::set_version("exif", 1);
}
static function activate() {

View File

@@ -20,19 +20,16 @@
class g2_import_installer {
static function install() {
$db = Database::instance();
$version = module::get_version("g2_import");
if ($version == 0) {
$db->query("CREATE TABLE IF NOT EXISTS {g2_maps} (
`id` int(9) NOT NULL auto_increment,
`g2_id` int(9) NOT NULL,
`g3_id` int(9) NOT NULL,
PRIMARY KEY (`id`),
KEY (`g2_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {g2_maps} (
`id` int(9) NOT NULL auto_increment,
`g2_id` int(9) NOT NULL,
`g3_id` int(9) NOT NULL,
PRIMARY KEY (`id`),
KEY (`g2_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
module::set_version("g2_import", 1);
mkdir(VARPATH . "modules/g2_import");
}
module::set_version("g2_import", 1);
mkdir(VARPATH . "modules/g2_import");
}
static function uninstall() {

View File

@@ -45,7 +45,11 @@ class Admin_Modules_Controller extends Admin_Controller {
} else if (!$info->active && $desired && !module::is_active($module_name)) {
$changes->activate[] = $module_name;
$activated_names[] = $info->name;
module::install($module_name);
if (module::is_installed($module_name)) {
module::upgrade($module_name);
} else {
module::install($module_name);
}
module::activate($module_name);
}
}

View File

@@ -50,8 +50,8 @@ class Upgrader_Controller extends Controller {
}
// Upgrade gallery and user first
module::install("gallery");
module::install("user");
module::upgrade("gallery");
module::upgrade("user");
// Then upgrade the rest
foreach (module::available() as $id => $module) {
@@ -60,7 +60,7 @@ class Upgrader_Controller extends Controller {
}
if ($module->active && $module->code_version != $module->version) {
module::install($id);
module::upgrade($id);
}
}

View File

@@ -18,244 +18,240 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class gallery_installer {
static function install($initial_install=false) {
static function install() {
$db = Database::instance();
if ($initial_install) {
$version = 0;
} else {
$version = module::get_version("gallery");
$db->query("CREATE TABLE {access_caches} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {access_intents} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {graphics_rules} (
`id` int(9) NOT NULL auto_increment,
`active` BOOLEAN default 0,
`args` varchar(255) default NULL,
`module_name` varchar(64) NOT NULL,
`operation` varchar(64) NOT NULL,
`priority` int(9) NOT NULL,
`target` varchar(32) NOT NULL,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {incoming_translations} (
`id` int(9) NOT NULL auto_increment,
`key` char(32) NOT NULL,
`locale` char(10) NOT NULL,
`message` text NOT NULL,
`revision` int(9) DEFAULT NULL,
`translation` text,
PRIMARY KEY (`id`),
UNIQUE KEY(`key`, `locale`),
KEY `locale_key` (`locale`, `key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {items} (
`id` int(9) NOT NULL auto_increment,
`album_cover_item_id` int(9) default NULL,
`captured` int(9) default NULL,
`created` int(9) default NULL,
`description` varchar(2048) default NULL,
`height` int(9) default NULL,
`left` int(9) NOT NULL,
`level` int(9) NOT NULL,
`mime_type` varchar(64) default NULL,
`name` varchar(255) default NULL,
`owner_id` int(9) default NULL,
`parent_id` int(9) NOT NULL,
`rand_key` float default NULL,
`relative_path_cache` varchar(255) default NULL,
`resize_dirty` boolean default 1,
`resize_height` int(9) default NULL,
`resize_width` int(9) default NULL,
`right` int(9) NOT NULL,
`sort_column` varchar(64) default NULL,
`sort_order` char(4) default 'ASC',
`thumb_dirty` boolean default 1,
`thumb_height` int(9) default NULL,
`thumb_width` int(9) default NULL,
`title` varchar(255) default NULL,
`type` varchar(32) NOT NULL,
`updated` int(9) default NULL,
`view_count` int(9) default 0,
`weight` int(9) NOT NULL default 0,
`width` int(9) default NULL,
PRIMARY KEY (`id`),
KEY `parent_id` (`parent_id`),
KEY `type` (`type`),
KEY `random` (`rand_key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {logs} (
`id` int(9) NOT NULL auto_increment,
`category` varchar(64) default NULL,
`html` varchar(255) default NULL,
`message` text default NULL,
`referer` varchar(255) default NULL,
`severity` int(9) default 0,
`timestamp` int(9) default 0,
`url` varchar(255) default NULL,
`user_id` int(9) default 0,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {messages} (
`id` int(9) NOT NULL auto_increment,
`key` varchar(255) default NULL,
`severity` varchar(32) default NULL,
`value` varchar(255) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {modules} (
`id` int(9) NOT NULL auto_increment,
`active` BOOLEAN default 0,
`name` varchar(64) default NULL,
`version` int(9) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {outgoing_translations} (
`id` int(9) NOT NULL auto_increment,
`base_revision` int(9) DEFAULT NULL,
`key` char(32) NOT NULL,
`locale` char(10) NOT NULL,
`message` text NOT NULL,
`translation` text,
PRIMARY KEY (`id`),
UNIQUE KEY(`key`, `locale`),
KEY `locale_key` (`locale`, `key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {permissions} (
`id` int(9) NOT NULL auto_increment,
`display_name` varchar(64) default NULL,
`name` varchar(64) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {sessions} (
`session_id` varchar(127) NOT NULL,
`data` text NOT NULL,
`last_activity` int(10) UNSIGNED NOT NULL,
PRIMARY KEY (`session_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {tasks} (
`id` int(9) NOT NULL auto_increment,
`callback` varchar(128) default NULL,
`context` text NOT NULL,
`done` boolean default 0,
`name` varchar(128) default NULL,
`owner_id` int(9) default NULL,
`percent_complete` int(9) default 0,
`state` varchar(32) default NULL,
`status` varchar(255) default NULL,
`updated` int(9) default NULL,
PRIMARY KEY (`id`),
KEY (`owner_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {themes} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(64) default NULL,
`version` int(9) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {vars} (
`id` int(9) NOT NULL auto_increment,
`module_name` varchar(64) NOT NULL,
`name` varchar(64) NOT NULL,
`value` text,
PRIMARY KEY (`id`),
UNIQUE KEY(`module_name`, `name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
foreach (array("albums", "logs", "modules", "resizes", "thumbs", "tmp", "uploads") as $dir) {
@mkdir(VARPATH . $dir);
}
if ($version == 0) {
$db->query("CREATE TABLE {access_caches} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
access::register_permission("view", "View");
access::register_permission("view_full", "View Full Size");
access::register_permission("edit", "Edit");
access::register_permission("add", "Add");
$db->query("CREATE TABLE {access_intents} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$root = ORM::factory("item");
$root->type = "album";
$root->title = "Gallery";
$root->description = "";
$root->left = 1;
$root->right = 2;
$root->parent_id = 0;
$root->level = 1;
$root->thumb_dirty = 1;
$root->resize_dirty = 1;
$root->sort_column = "weight";
$root->sort_order = "ASC";
$root->save();
access::add_item($root);
$db->query("CREATE TABLE {graphics_rules} (
`id` int(9) NOT NULL auto_increment,
`active` BOOLEAN default 0,
`args` varchar(255) default NULL,
`module_name` varchar(64) NOT NULL,
`operation` varchar(64) NOT NULL,
`priority` int(9) NOT NULL,
`target` varchar(32) NOT NULL,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
module::set_var("gallery", "active_site_theme", "default");
module::set_var("gallery", "active_admin_theme", "admin_default");
module::set_var("gallery", "page_size", 9);
module::set_var("gallery", "thumb_size", 200);
module::set_var("gallery", "resize_size", 640);
module::set_var("gallery", "default_locale", "en_US");
module::set_var("gallery", "image_quality", 75);
$db->query("CREATE TABLE {incoming_translations} (
`id` int(9) NOT NULL auto_increment,
`key` char(32) NOT NULL,
`locale` char(10) NOT NULL,
`message` text NOT NULL,
`revision` int(9) DEFAULT NULL,
`translation` text,
PRIMARY KEY (`id`),
UNIQUE KEY(`key`, `locale`),
KEY `locale_key` (`locale`, `key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
// Add rules for generating our thumbnails and resizes
graphics::add_rule(
"gallery", "thumb", "resize",
array("width" => 200, "height" => 200, "master" => Image::AUTO),
100);
graphics::add_rule(
"gallery", "resize", "resize",
array("width" => 640, "height" => 480, "master" => Image::AUTO),
100);
$db->query("CREATE TABLE {items} (
`id` int(9) NOT NULL auto_increment,
`album_cover_item_id` int(9) default NULL,
`captured` int(9) default NULL,
`created` int(9) default NULL,
`description` varchar(2048) default NULL,
`height` int(9) default NULL,
`left` int(9) NOT NULL,
`level` int(9) NOT NULL,
`mime_type` varchar(64) default NULL,
`name` varchar(255) default NULL,
`owner_id` int(9) default NULL,
`parent_id` int(9) NOT NULL,
`rand_key` float default NULL,
`relative_path_cache` varchar(255) default NULL,
`resize_dirty` boolean default 1,
`resize_height` int(9) default NULL,
`resize_width` int(9) default NULL,
`right` int(9) NOT NULL,
`sort_column` varchar(64) default NULL,
`sort_order` char(4) default 'ASC',
`thumb_dirty` boolean default 1,
`thumb_height` int(9) default NULL,
`thumb_width` int(9) default NULL,
`title` varchar(255) default NULL,
`type` varchar(32) NOT NULL,
`updated` int(9) default NULL,
`view_count` int(9) default 0,
`weight` int(9) NOT NULL default 0,
`width` int(9) default NULL,
PRIMARY KEY (`id`),
KEY `parent_id` (`parent_id`),
KEY `type` (`type`),
KEY `random` (`rand_key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {logs} (
`id` int(9) NOT NULL auto_increment,
`category` varchar(64) default NULL,
`html` varchar(255) default NULL,
`message` text default NULL,
`referer` varchar(255) default NULL,
`severity` int(9) default 0,
`timestamp` int(9) default 0,
`url` varchar(255) default NULL,
`user_id` int(9) default 0,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {messages} (
`id` int(9) NOT NULL auto_increment,
`key` varchar(255) default NULL,
`severity` varchar(32) default NULL,
`value` varchar(255) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {modules} (
`id` int(9) NOT NULL auto_increment,
`active` BOOLEAN default 0,
`name` varchar(64) default NULL,
`version` int(9) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {outgoing_translations} (
`id` int(9) NOT NULL auto_increment,
`base_revision` int(9) DEFAULT NULL,
`key` char(32) NOT NULL,
`locale` char(10) NOT NULL,
`message` text NOT NULL,
`translation` text,
PRIMARY KEY (`id`),
UNIQUE KEY(`key`, `locale`),
KEY `locale_key` (`locale`, `key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {permissions} (
`id` int(9) NOT NULL auto_increment,
`display_name` varchar(64) default NULL,
`name` varchar(64) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {sessions} (
`session_id` varchar(127) NOT NULL,
`data` text NOT NULL,
`last_activity` int(10) UNSIGNED NOT NULL,
PRIMARY KEY (`session_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {tasks} (
`id` int(9) NOT NULL auto_increment,
`callback` varchar(128) default NULL,
`context` text NOT NULL,
`done` boolean default 0,
`name` varchar(128) default NULL,
`owner_id` int(9) default NULL,
`percent_complete` int(9) default 0,
`state` varchar(32) default NULL,
`status` varchar(255) default NULL,
`updated` int(9) default NULL,
PRIMARY KEY (`id`),
KEY (`owner_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {themes} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(64) default NULL,
`version` int(9) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE {vars} (
`id` int(9) NOT NULL auto_increment,
`module_name` varchar(64) NOT NULL,
`name` varchar(64) NOT NULL,
`value` text,
PRIMARY KEY (`id`),
UNIQUE KEY(`module_name`, `name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
foreach (array("albums", "logs", "modules", "resizes", "thumbs", "tmp", "uploads") as $dir) {
@mkdir(VARPATH . $dir);
}
access::register_permission("view", "View");
access::register_permission("view_full", "View Full Size");
access::register_permission("edit", "Edit");
access::register_permission("add", "Add");
$root = ORM::factory("item");
$root->type = "album";
$root->title = "Gallery";
$root->description = "";
$root->left = 1;
$root->right = 2;
$root->parent_id = 0;
$root->level = 1;
$root->thumb_dirty = 1;
$root->resize_dirty = 1;
$root->sort_column = "weight";
$root->sort_order = "ASC";
$root->save();
access::add_item($root);
module::set_var("gallery", "active_site_theme", "default");
module::set_var("gallery", "active_admin_theme", "admin_default");
module::set_var("gallery", "page_size", 9);
module::set_var("gallery", "thumb_size", 200);
module::set_var("gallery", "resize_size", 640);
module::set_var("gallery", "default_locale", "en_US");
module::set_var("gallery", "image_quality", 75);
// Add rules for generating our thumbnails and resizes
graphics::add_rule(
"gallery", "thumb", "resize",
array("width" => 200, "height" => 200, "master" => Image::AUTO),
100);
graphics::add_rule(
"gallery", "resize", "resize",
array("width" => 640, "height" => 480, "master" => Image::AUTO),
100);
// Instantiate default themes (site and admin)
foreach (array("default", "admin_default") as $theme_name) {
$theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"),
ArrayObject::ARRAY_AS_PROPS);
$theme = ORM::factory("theme");
$theme->name = $theme_name;
$theme->version = $theme_info->version;
$theme->save();
}
block_manager::add("dashboard_sidebar", "gallery", "block_adder");
block_manager::add("dashboard_sidebar", "gallery", "stats");
block_manager::add("dashboard_sidebar", "gallery", "platform_info");
block_manager::add("dashboard_sidebar", "gallery", "project_news");
block_manager::add("dashboard_center", "gallery", "welcome");
block_manager::add("dashboard_center", "gallery", "photo_stream");
block_manager::add("dashboard_center", "gallery", "log_entries");
module::set_version("gallery", $version = 1);
module::set_var("gallery", "version", "3.0 beta 1");
module::set_var("gallery", "choose_default_tookit", 1);
// @todo this string needs to be picked up by l10n_scanner
module::set_var("gallery", "credits", "Powered by <a href=\"%url\">Gallery %version</a>");
// Instantiate default themes (site and admin)
foreach (array("default", "admin_default") as $theme_name) {
$theme_info = new ArrayObject(parse_ini_file(THEMEPATH . $theme_name . "/theme.info"),
ArrayObject::ARRAY_AS_PROPS);
$theme = ORM::factory("theme");
$theme->name = $theme_name;
$theme->version = $theme_info->version;
$theme->save();
}
block_manager::add("dashboard_sidebar", "gallery", "block_adder");
block_manager::add("dashboard_sidebar", "gallery", "stats");
block_manager::add("dashboard_sidebar", "gallery", "platform_info");
block_manager::add("dashboard_sidebar", "gallery", "project_news");
block_manager::add("dashboard_center", "gallery", "welcome");
block_manager::add("dashboard_center", "gallery", "photo_stream");
block_manager::add("dashboard_center", "gallery", "log_entries");
module::set_var("gallery", "version", "3.0 pre beta 2 (git)");
module::set_var("gallery", "choose_default_tookit", 1);
module::set_var("gallery", "date_format", "Y-M-d");
module::set_var("gallery", "date_time_format", "Y-M-d H:i:s");
module::set_var("gallery", "time_format", "H:i:s");
// @todo this string needs to be picked up by l10n_scanner
module::set_var("gallery", "credits", "Powered by <a href=\"%url\">Gallery %version</a>");
module::set_version("gallery", 2);
}
static function upgrade($version) {
if ($version == 1) {
module::set_var("gallery", "date_format", "Y-M-d");
module::set_var("gallery", "date_time_format", "Y-M-d H:i:s");

View File

@@ -107,7 +107,7 @@ class module_Core {
/**
* Install a module. This will call <module>_installer::install(), which is responsible for
* creating database tables, setting module variables and and calling module::set_version().
* creating database tables, setting module variables and calling module::set_version().
* Note that after installing, the module must be activated before it is available for use.
* @param string $module_name
*/
@@ -130,6 +130,38 @@ class module_Core {
"module", t("Installed module %module_name", array("module_name" => $module_name)));
}
/**
* Upgrade a module. This will call <module>_installer::upgrade(), which is responsible for
* modifying database tables, changing module variables and calling module::set_version().
* Note that after upgrading, the module must be activated before it is available for use.
* @param string $module_name
*/
static function upgrade($module_name) {
$kohana_modules = Kohana::config("core.modules");
array_unshift($kohana_modules, MODPATH . $module_name);
Kohana::config_set("core.modules", $kohana_modules);
$version_before = module::get_version($module_name);
$installer_class = "{$module_name}_installer";
if (method_exists($installer_class, "upgrade")) {
call_user_func_array(array($installer_class, "upgrade"), array($version_before));
}
module::load_modules();
// Now the module is upgraded but inactive, so don't leave it in the active path
array_shift($kohana_modules);
Kohana::config_set("core.modules", $kohana_modules);
$version_after = module::get_version($module_name);
if ($version_before != $version_after) {
log::success(
"module", t("Upgraded module %module_name from %version_before to %version_after",
array("module_name" => $module_name,
"version_before" => $version_before,
"version_after" => $version_after)));
}
}
/**
* Activate an installed module. This will call <module>_installer::activate() which should take
* any steps to make sure that the module is ready for use. This will also activate any

View File

@@ -19,8 +19,6 @@
*/
class image_block_installer {
static function install() {
if (module::get_version("image_block") == 0) {
module::set_version("image_block", 1);
}
module::set_version("image_block", 1);
}
}

View File

@@ -19,9 +19,6 @@
*/
class info_installer {
static function install() {
$version = module::get_version("info");
if ($version == 0) {
module::set_version("info", 1);
}
module::set_version("info", 1);
}
}

View File

@@ -20,27 +20,23 @@
class notification_installer {
static function install() {
$db = Database::instance();
$version = module::get_version("notification");
$db->query("CREATE TABLE IF NOT EXISTS {subscriptions} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) NOT NULL,
`user_id` int(9) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY (`item_id`, `user_id`),
UNIQUE KEY (`user_id`, `item_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {pending_notifications} (
`id` int(9) NOT NULL auto_increment,
`email` varchar(128) NOT NULL,
`subject` varchar(255) NOT NULL,
`text` text,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
if ($version == 0) {
$db->query("CREATE TABLE IF NOT EXISTS {subscriptions} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) NOT NULL,
`user_id` int(9) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY (`item_id`, `user_id`),
UNIQUE KEY (`user_id`, `item_id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {pending_notifications} (
`id` int(9) NOT NULL auto_increment,
`email` varchar(128) NOT NULL,
`subject` varchar(255) NOT NULL,
`text` text,
PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
module::set_version("notification", 1);
}
module::set_version("notification", 1);
}
static function uninstall() {

View File

@@ -19,9 +19,6 @@
*/
class organize_installer {
static function install() {
$version = module::get_version("organize");
if ($version == 0) {
module::set_version("organize", 1);
}
module::set_version("organize", 1);
}
}

View File

@@ -19,10 +19,7 @@
*/
class recaptcha_installer {
static function install() {
$version = module::get_version("recaptcha");
if ($version == 0) {
module::set_version("recaptcha", 1);
}
module::set_version("recaptcha", 1);
}
static function activate() {

View File

@@ -19,9 +19,6 @@
*/
class rss_installer {
static function install() {
$version = module::get_version("rss");
if ($version == 0) {
module::set_version("rss", 1);
}
module::set_version("rss", 1);
}
}

View File

@@ -19,20 +19,17 @@
*/
class search_installer {
static function install() {
$version = module::get_version("search");
$db = Database::instance();
if ($version == 0) {
$db->query("CREATE TABLE {search_records} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
`dirty` boolean default 1,
`data` LONGTEXT default NULL,
PRIMARY KEY (`id`),
KEY(`item_id`),
FULLTEXT INDEX (`data`))
ENGINE=MyISAM DEFAULT CHARSET=utf8;");
module::set_version("search", 1);
}
$db->query("CREATE TABLE {search_records} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9),
`dirty` boolean default 1,
`data` LONGTEXT default NULL,
PRIMARY KEY (`id`),
KEY(`item_id`),
FULLTEXT INDEX (`data`))
ENGINE=MyISAM DEFAULT CHARSET=utf8;");
module::set_version("search", 1);
}
static function activate() {

View File

@@ -19,11 +19,7 @@
*/
class server_add_installer {
static function install() {
$db = Database::instance();
$version = module::get_version("server_add");
if ($version == 0) {
module::set_version("server_add", 1);
}
module::set_version("server_add", 1);
server_add::check_config();
}

View File

@@ -19,10 +19,7 @@
*/
class slideshow_installer {
static function install() {
$version = module::get_version("slideshow");
if ($version == 0) {
module::set_version("slideshow", 1);
}
module::set_version("slideshow", 1);
}
static function deactivate() {

View File

@@ -20,26 +20,23 @@
class tag_installer {
static function install() {
$db = Database::instance();
$version = module::get_version("tag");
if ($version == 0) {
$db->query("CREATE TABLE IF NOT EXISTS {tags} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(64) NOT NULL,
`count` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {tags} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(64) NOT NULL,
`count` int(10) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {items_tags} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) NOT NULL,
`tag_id` int(9) NOT NULL,
PRIMARY KEY (`id`),
KEY(`tag_id`, `id`),
KEY(`item_id`, `id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
module::set_version("tag", 1);
}
$db->query("CREATE TABLE IF NOT EXISTS {items_tags} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) NOT NULL,
`tag_id` int(9) NOT NULL,
PRIMARY KEY (`id`),
KEY(`tag_id`, `id`),
KEY(`item_id`, `id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
module::set_version("tag", 1);
}
static function uninstall() {

View File

@@ -20,70 +20,66 @@
class user_installer {
static function install() {
$db = Database::instance();
$version = module::get_version("user");
$db->query("CREATE TABLE IF NOT EXISTS {users} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
`full_name` varchar(255) NOT NULL,
`password` varchar(64) NOT NULL,
`login_count` int(10) unsigned NOT NULL DEFAULT 0,
`last_login` int(10) unsigned NOT NULL DEFAULT 0,
`email` varchar(64) default NULL,
`admin` BOOLEAN default 0,
`guest` BOOLEAN default 0,
`hash` char(32) default NULL,
`url` varchar(255) default NULL,
`locale` char(10) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`hash`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
if ($version == 0) {
$db->query("CREATE TABLE IF NOT EXISTS {users} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
`full_name` varchar(255) NOT NULL,
`password` varchar(64) NOT NULL,
`login_count` int(10) unsigned NOT NULL DEFAULT 0,
`last_login` int(10) unsigned NOT NULL DEFAULT 0,
`email` varchar(64) default NULL,
`admin` BOOLEAN default 0,
`guest` BOOLEAN default 0,
`hash` char(32) default NULL,
`url` varchar(255) default NULL,
`locale` char(10) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`hash`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {groups} (
`id` int(9) NOT NULL auto_increment,
`name` char(64) default NULL,
`special` BOOLEAN default 0,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {groups} (
`id` int(9) NOT NULL auto_increment,
`name` char(64) default NULL,
`special` BOOLEAN default 0,
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;");
$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;");
$everybody = group::create("Everybody");
$everybody->special = true;
$everybody->save();
$everybody = group::create("Everybody");
$everybody->special = true;
$everybody->save();
$registered = group::create("Registered Users");
$registered->special = true;
$registered->save();
$registered = group::create("Registered Users");
$registered->special = true;
$registered->save();
$guest = user::create("guest", "Guest User", "");
$guest->guest = true;
$guest->remove($registered);
$guest->save();
$guest = user::create("guest", "Guest User", "");
$guest->guest = true;
$guest->remove($registered);
$guest->save();
$admin = user::create("admin", "Gallery Administrator", "admin");
$admin->admin = true;
$admin->save();
$admin = user::create("admin", "Gallery Administrator", "admin");
$admin->admin = true;
$admin->save();
// Let the admin own everything
$db->update("items", array("owner_id" => $admin->id), array("owner_id" => "IS NULL"));
module::set_version("user", 1);
// Let the admin own everything
$db->update("items", array("owner_id" => $admin->id), array("owner_id" => "IS NULL"));
module::set_version("user", 1);
$root = ORM::factory("item", 1);
access::allow($everybody, "view", $root);
access::allow($everybody, "view_full", $root);
$root = ORM::factory("item", 1);
access::allow($everybody, "view", $root);
access::allow($everybody, "view_full", $root);
access::allow($registered, "view", $root);
access::allow($registered, "view_full", $root);
}
access::allow($registered, "view", $root);
access::allow($registered, "view_full", $root);
}
static function uninstall() {

View File

@@ -20,23 +20,20 @@
class watermark_installer {
static function install() {
$db = Database::instance();
$version = module::get_version("watermark");
if ($version == 0) {
$db->query("CREATE TABLE IF NOT EXISTS {watermarks} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
`width` int(9) NOT NULL,
`height` int(9) NOT NULL,
`active` boolean default 0,
`position` boolean default 0,
`mime_type` varchar(64) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE IF NOT EXISTS {watermarks} (
`id` int(9) NOT NULL auto_increment,
`name` varchar(32) NOT NULL,
`width` int(9) NOT NULL,
`height` int(9) NOT NULL,
`active` boolean default 0,
`position` boolean default 0,
`mime_type` varchar(64) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
@mkdir(VARPATH . "modules/watermark");
module::set_version("watermark", 1);
}
@mkdir(VARPATH . "modules/watermark");
module::set_version("watermark", 1);
}
static function uninstall() {