From bfca0c79030d5b8a18e41e8b80f5560ebaf6f202 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Jun 2009 12:00:49 -0700 Subject: 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. --- modules/comment/helpers/comment_installer.php | 60 +++++++++++++-------------- 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'modules/comment/helpers') diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php index b1cfcdc0..2bfb7330 100644 --- a/modules/comment/helpers/comment_installer.php +++ b/modules/comment/helpers/comment_installer.php @@ -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() { -- cgit v1.2.3 From e49c4a2459fd94d7df167b68432920ca95420767 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Jun 2009 13:25:14 -0700 Subject: Upgrade to version 2 and change the state column to a varchar for Postgres compatibility. --- modules/comment/helpers/comment_installer.php | 8 ++++++++ modules/comment/module.info | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'modules/comment/helpers') diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php index 2bfb7330..f5a7542b 100644 --- a/modules/comment/helpers/comment_installer.php +++ b/modules/comment/helpers/comment_installer.php @@ -51,6 +51,14 @@ class comment_installer { module::set_version("comment", 1); } + static function upgrade($version) { + if ($version == 1) { + $db = Database::instance(); + $db->query("ALTER TABLE {comments} CHANGE `state` `state` varchar(15) default 'unpublished'"); + module::set_version("comment", 2); + } + } + static function uninstall() { $db = Database::instance(); $sql = "SELECT `item_id` FROM {comments}"; diff --git a/modules/comment/module.info b/modules/comment/module.info index 08a800a6..946f1d39 100644 --- a/modules/comment/module.info +++ b/modules/comment/module.info @@ -1,3 +1,3 @@ name = Comments description = Allows users and guests to leave comments on photos and albums. -version = 1 +version = 2 -- cgit v1.2.3 From 3b0baa827150e457c630052d6ef87853aaad8bdc Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 23 Jun 2009 13:45:16 -0700 Subject: Replay change from Romain DE LISEZ to change the state column to be a varchar --- modules/comment/helpers/comment_installer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/comment/helpers') diff --git a/modules/comment/helpers/comment_installer.php b/modules/comment/helpers/comment_installer.php index f5a7542b..f54913c3 100644 --- a/modules/comment/helpers/comment_installer.php +++ b/modules/comment/helpers/comment_installer.php @@ -40,7 +40,7 @@ class comment_installer { `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', + `state` varchar(15) default 'unpublished', `text` text, `updated` int(9) NOT NULL, PRIMARY KEY (`id`)) @@ -48,7 +48,7 @@ class comment_installer { block_manager::add("dashboard_center", "comment", "recent_comments"); module::set_var("comment", "spam_caught", 0); - module::set_version("comment", 1); + module::set_version("comment", 2); } static function upgrade($version) { -- cgit v1.2.3 From 4cec0201637d21f8e88c264bb1befff4e891ce3e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 26 Jun 2009 14:37:15 -0700 Subject: Create a theme_view function script which allows modules in the head or admin_head functions to specify javascript files that are required for this page. In this commit, these script files are expressed at the end of the head or admin_head calls and appended to the beginning of the block stack. In a future commit these will be combined and gzipped for download. --- modules/comment/helpers/comment_theme.php | 4 +-- modules/gallery/helpers/gallery_theme.php | 50 +++++++++++++++---------------- modules/gallery/libraries/Theme_View.php | 19 ++++++++++++ 3 files changed, 46 insertions(+), 27 deletions(-) (limited to 'modules/comment/helpers') diff --git a/modules/comment/helpers/comment_theme.php b/modules/comment/helpers/comment_theme.php index d9f1acf4..89b2f57c 100644 --- a/modules/comment/helpers/comment_theme.php +++ b/modules/comment/helpers/comment_theme.php @@ -19,8 +19,8 @@ */ class comment_theme_Core { static function head($theme) { - $url = url::file("modules/comment/js/comment.js"); - return "\n"; + $theme->script("modules/comment/js/comment.js"); + return ""; } static function photo_bottom($theme) { diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index 0679087e..b6b24b27 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -21,22 +21,22 @@ class gallery_theme_Core { static function head($theme) { $session = Session::instance(); $buf = ""; - $buf .= html::script("lib/jquery.js"); - $buf .= html::script("lib/jquery.form.js"); - $buf .= html::script("lib/jquery-ui.js"); - $buf .= html::script("lib/gallery.common.js"); - $buf .= html::script("lib/gallery.dialog.js"); - $buf .= html::script("lib/gallery.form.js"); - $buf .= html::script("lib/superfish/js/superfish.js"); + $theme->script("lib/jquery.js"); + $theme->script("lib/jquery.form.js"); + $theme->script("lib/jquery-ui.js"); + $theme->script("lib/gallery.common.js"); + $theme->script("lib/gallery.dialog.js"); + $theme->script("lib/gallery.form.js"); + $theme->script("lib/superfish/js/superfish.js"); if ($theme->page_type == 'photo') { - $buf .= html::script("lib/jquery.scrollTo.js"); - $buf .= html::script("lib/jquery.localscroll.js"); - $buf .= html::script("lib/gallery.show_full_size.js"); + $theme->script("lib/jquery.scrollTo.js"); + $theme->script("lib/jquery.localscroll.js"); + $theme->script("lib/gallery.show_full_size.js"); } if ($theme->page_type == 'movie') { - $buf .= html::script("lib/flowplayer.js"); + $theme->script("lib/flowplayer.js"); } - $buf .= html::script($theme->url("js/ui.init.js", false, true)); + $theme->script($theme->url("js/ui.init.js", false, true)); if ($session->get("debug")) { $buf .= ""; @@ -45,7 +45,7 @@ class gallery_theme_Core { && access::can("edit", $theme->item())) { $buf .= ""; - $buf .= html::script("modules/gallery/js/quick.js"); + $theme->script("modules/gallery/js/quick.js"); } if (module::is_active("rss")) { @@ -59,8 +59,8 @@ class gallery_theme_Core { if ($session->get("l10n_mode", false)) { $buf .= ""; - $buf .= html::script("lib/jquery.cookie.js"); - $buf .= html::script("modules/gallery/js/l10n_client.js"); + $theme->script("lib/jquery.cookie.js"); + $theme->script("modules/gallery/js/l10n_client.js"); } return $buf; @@ -95,14 +95,14 @@ class gallery_theme_Core { static function admin_head($theme) { $session = Session::instance(); $buf = ""; - $buf .= html::script("lib/jquery.js"); - $buf .= html::script("lib/jquery.form.js"); - $buf .= html::script("lib/jquery-ui.js"); - $buf .= html::script("lib/gallery.common.js"); - $buf .= html::script("lib/gallery.dialog.js"); - $buf .= html::script("lib/superfish/js/superfish.js"); - $buf .= html::script($theme->url("js/jquery.dropshadow.js", false, true)); - $buf .= html::script($theme->url("js/ui.init.js", false, true)); + $theme->script("lib/jquery.js"); + $theme->script("lib/jquery.form.js"); + $theme->script("lib/jquery-ui.js"); + $theme->script("lib/gallery.common.js"); + $theme->script("lib/gallery.dialog.js"); + $theme->script("lib/superfish/js/superfish.js"); + $theme->script($theme->url("js/jquery.dropshadow.js", false, true)); + $theme->script($theme->url("js/ui.init.js", false, true)); if ($session->get("debug")) { $buf .= ""; @@ -111,8 +111,8 @@ class gallery_theme_Core { if ($session->get("l10n_mode", false)) { $buf .= ""; - $buf .= html::script("lib/jquery.cookie.js"); - $buf .= html::script("modules/gallery/js/l10n_client.js"); + $theme->script("lib/jquery.cookie.js"); + $theme->script("modules/gallery/js/l10n_client.js"); } return $buf; diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 5235fabb..7696f3b0 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -19,6 +19,7 @@ */ class Theme_View_Core extends View { private $theme_name = null; + private $scripts = array(); /** * Attempts to load a view and pre-load view data. @@ -163,6 +164,19 @@ class Theme_View_Core extends View { return message::get(); } + public function script($file) { + $this->scripts[$file] = 1; + } + + private function _combine_script() { + $links = array(); + Kohana::log("error", Kohana::debug($this->scripts)); + foreach (array_keys($this->scripts) as $file) { + $links[] = html::script($file); + } + return empty($links) ? "" : implode("\n", $links); + } + /** * Handle all theme functions that insert module content. */ @@ -221,6 +235,11 @@ class Theme_View_Core extends View { array_merge(array($this), $args)); } } + + if ($function == "head" || $function == "admin_head") { + array_unshift($blocks, $this->_combine_script()); + } + if (Session::instance()->get("debug")) { if ($function != "head") { array_unshift( -- cgit v1.2.3