From ac44e9c930ec83545b37e1e31381919fbd849d26 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sun, 16 Jan 2011 15:49:34 -0800
Subject: First step in setting up version checking.
We now have two types of packages (release, git). Instead of using
constants, we now have gallery::version_string() which returns the
current version string. If you're on a release package, then the
version string looks like:
3.0 (Santa Fe)
If you're on a git package, then the version string looks like this:
3.0.1 (branch 3.0.x build 3)
We track the build number in a new file in the gallery3 root called
BUILD_NUMBER which we will update periodically with the latest
build number for each branch.
---
modules/gallery/views/admin_block_stats.html.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'modules/gallery/views')
diff --git a/modules/gallery/views/admin_block_stats.html.php b/modules/gallery/views/admin_block_stats.html.php
index 1dec8ccd..c8c54765 100644
--- a/modules/gallery/views/admin_block_stats.html.php
+++ b/modules/gallery/views/admin_block_stats.html.php
@@ -1,7 +1,7 @@
-
- = t("Version: %version", array("version" => gallery::VERSION)) ?>
+ = t("Version: %version", array("version" => gallery::version_string())) ?>
-
= t("Albums: %count", array("count" => $album_count)) ?>
--
cgit v1.2.3
From 70abfb2a20734802c922c0e9917d2a1778aef3f2 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sun, 16 Jan 2011 22:16:09 -0800
Subject: Upgrade checking code is now here, along with a bump of the Gallery
module to v46. There's a new block in the admin dashboard which controls
whether automatic checking happens, and lets you check immediately. If a
newer version is detected, a site status message appears for admins providing
upgrade instructions.
Automatic checking is not yet implemented (even though the UI claims
that it exists). This is all for #1605.
---
.../gallery/controllers/admin_upgrade_checker.php | 49 ++++++++++++
modules/gallery/helpers/gallery_block.php | 12 ++-
modules/gallery/helpers/gallery_installer.php | 16 +++-
modules/gallery/helpers/upgrade_checker.php | 91 ++++++++++++++++++++++
modules/gallery/module.info | 2 +-
.../gallery/views/upgrade_checker_block.html.php | 45 +++++++++++
6 files changed, 212 insertions(+), 3 deletions(-)
create mode 100644 modules/gallery/controllers/admin_upgrade_checker.php
create mode 100644 modules/gallery/helpers/upgrade_checker.php
create mode 100644 modules/gallery/views/upgrade_checker_block.html.php
(limited to 'modules/gallery/views')
diff --git a/modules/gallery/controllers/admin_upgrade_checker.php b/modules/gallery/controllers/admin_upgrade_checker.php
new file mode 100644
index 00000000..4b1467cd
--- /dev/null
+++ b/modules/gallery/controllers/admin_upgrade_checker.php
@@ -0,0 +1,49 @@
+server("HTTP_REFERER")) {
+ url::redirect($referer);
+ } else {
+ url::redirect(item::root()->abs_url());
+ }
+ }
+
+ function set_auto($val) {
+ access::verify_csrf();
+ module::set_var("gallery", "upgrade_checker_auto_enabled", (bool)$val);
+
+ if ((bool)$val) {
+ message::success(t("Automatic upgrade checking is enabled."));
+ } else {
+ message::success(t("Automatic upgrade checking is disabled."));
+ }
+ url::redirect("admin/dashboard");
+ }
+}
diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php
index 1d92d66d..2189a710 100644
--- a/modules/gallery/helpers/gallery_block.php
+++ b/modules/gallery/helpers/gallery_block.php
@@ -25,7 +25,9 @@ class gallery_block_Core {
"log_entries" => t("Log entries"),
"stats" => t("Gallery stats"),
"platform_info" => t("Platform information"),
- "project_news" => t("Gallery project news"));
+ "project_news" => t("Gallery project news"),
+ "upgrade_checker" => t("Check for Gallery upgrades")
+ );
}
static function get_site_list() {
@@ -101,6 +103,14 @@ class gallery_block_Core {
$block = "";
}
break;
+
+ case "upgrade_checker":
+ $block = new Block();
+ $block->css_id = "g-upgrade-available-block";
+ $block->title = t("Check for Gallery upgrades");
+ $block->content = new View("upgrade_checker_block.html");
+ $block->content->version_info = upgrade_checker::version_info();
+ $block->content->auto_check_enabled = upgrade_checker::auto_check_enabled();
}
return $block;
}
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index 92e5b7b8..1ffe9bae 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -259,6 +259,7 @@ class gallery_installer {
module::set_var("gallery", "default_locale", "en_US");
module::set_var("gallery", "image_quality", 75);
module::set_var("gallery", "image_sharpen", 15);
+ module::set_var("gallery", "upgrade_checker_auto_enabled", true);
// Add rules for generating our thumbnails and resizes
graphics::add_rule(
@@ -285,6 +286,7 @@ class gallery_installer {
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", "upgrade_checker");
block_manager::add("dashboard_center", "gallery", "photo_stream");
block_manager::add("dashboard_center", "gallery", "log_entries");
@@ -309,7 +311,7 @@ class gallery_installer {
module::set_var("gallery", "show_user_profiles_to", "registered_users");
module::set_var("gallery", "extra_binary_paths", "/usr/local/bin:/opt/local/bin:/opt/bin");
- module::set_version("gallery", 45);
+ module::set_version("gallery", 46);
}
static function upgrade($version) {
@@ -663,6 +665,18 @@ class gallery_installer {
$db->query("ALTER TABLE {messages} CHANGE `value` `value` text default NULL");
module::set_version("gallery", $version = 45);
}
+
+ if ($version == 45) {
+ // Splice the upgrade_checker block into the admin dashboard at the top
+ // of the page, but under the welcome block if it's in the first position.
+ $blocks = block_manager::get_active("dashboard_center");
+ $index = count($blocks) && current($blocks) == array("gallery", "welcome") ? 1 : 0;
+ array_splice($blocks, $index, 0, array(random::int() => array("gallery", "upgrade_checker")));
+ block_manager::set_active("dashboard_center", $blocks);
+
+ module::set_var("gallery", "upgrade_checker_auto_enabled", true);
+ module::set_version("gallery", $version = 46);
+ }
}
static function uninstall() {
diff --git a/modules/gallery/helpers/upgrade_checker.php b/modules/gallery/helpers/upgrade_checker.php
new file mode 100644
index 00000000..9311cf4a
--- /dev/null
+++ b/modules/gallery/helpers/upgrade_checker.php
@@ -0,0 +1,91 @@
+get("upgrade_checker_version_info"));
+ }
+
+ static function auto_check_enabled() {
+ return (bool)module::get_var("gallery", "upgrade_checker_auto_enabled");
+ }
+
+ static function fetch_version_info() {
+ $result = new stdClass();
+ try {
+ list ($status, $headers, $body) = remote::do_request(upgrade_checker::CHECK_URL);
+ if ($status == "HTTP/1.1 200 OK") {
+ $result->status = "success";
+ foreach (explode("\n", $body) as $line) {
+ if ($line) {
+ list($key, $val) = explode("=", $line, 2);
+ $result->data[$key] = $val;
+ }
+ }
+ } else {
+ $result->status = "error";
+ }
+ } catch (Exception $e) {
+ Kohana_Log::add("error",
+ sprintf("%s in %s at line %s:\n%s", $e->getMessage(), $e->getFile(),
+ $e->getLine(), $e->getTraceAsString()));
+ }
+ $result->timestamp = time();
+ Cache::instance()->set("upgrade_checker_version_info", serialize($result), null, 86400 * 365);
+ }
+
+ static function check_for_upgrade() {
+ $version_info = upgrade_checker::version_info();
+ $upgrade_available = false;
+ if ($version_info) {
+ if (gallery::RELEASE_CHANNEL == "release") {
+ if (version_compare($version_info->data["release_version"], gallery::VERSION, ">")) {
+ site_status::warning(
+ t("A newer version of Gallery is available! Upgrade now to version %version or wait until later.",
+ array("version" => $version_info->data["release_version"],
+ "upgrade-url" => $version_info->data["release_upgrade_url"],
+ "hide-url" => url::site("admin/upgrade_checker/remind_me_later?csrf=__CSRF__"))),
+ "upgrade_checker");
+ $upgrade_available = true;
+ }
+ } else {
+ $branch = gallery::RELEASE_BRANCH;
+ if (isset($version_info->data["{$branch}_build_number"]) &&
+ version_compare($version_info->data["{$branch}_build_number"],
+ gallery::build_number(), ">")) {
+ site_status::warning(
+ t("A newer version of Gallery is available! Upgrade now to version %version (build %build on branch %branch) or wait until later.",
+ array("version" => $version_info->data["{$branch}_version"],
+ "upgrade-url" => $version_info->data["{$branch}_upgrade_url"],
+ "build" => $version_info->data["{$branch}_build_number"],
+ "branch" => $branch,
+ "hide-url" => url::site("admin/upgrade_checker/remind_me_later?csrf=__CSRF__"))),
+ "upgrade_checker");
+ $upgrade_available = true;
+ }
+ }
+ }
+
+ if (!$upgrade_available) {
+ site_status::clear("upgrade_checker");
+ }
+ }
+}
diff --git a/modules/gallery/module.info b/modules/gallery/module.info
index b79df7be..4c0c8866 100644
--- a/modules/gallery/module.info
+++ b/modules/gallery/module.info
@@ -1,3 +1,3 @@
name = "Gallery 3"
description = "Gallery core application"
-version = 45
+version = 46
diff --git a/modules/gallery/views/upgrade_checker_block.html.php b/modules/gallery/views/upgrade_checker_block.html.php
new file mode 100644
index 00000000..30e18305
--- /dev/null
+++ b/modules/gallery/views/upgrade_checker_block.html.php
@@ -0,0 +1,45 @@
+
+
+ = t("Gallery can check to see if there is a new version available for you to use. It is a good idea to upgrade your Gallery to get the latest features and security fixes. Your privacy is important so no information about your Gallery is shared during this process. You can disable this feature below.") ?>
+
+
+
+ if (gallery::RELEASE_CHANNEL == "release"): ?>
+ = t("You are using the official Gallery %version release, code named %code_name.", array("version" => gallery::VERSION, "code_name" => gallery::CODE_NAME)) ?>
+ else: ?>
+ = t("You are using an experimental snapshot of Gallery %version (build %build_number on branch %branch).", array("version" => gallery::VERSION, "branch" => gallery::RELEASE_BRANCH, "build_number" => gallery::build_number())) ?>
+ endif ?>
+
+
+
+ ">
+ = t("Check now") ?>
+
+ if ($auto_check_enabled): ?>
+ ">
+ = t("Disable automatic checking") ?>
+
+ else: ?>
+ ">
+ = t("Enable automatic checking") ?>
+
+ endif ?>
+
+
+
+ if ($auto_check_enabled): ?>
+ = t("Automatic upgrade checking is enabled.") ?>
+ else: ?>
+ = t("Automatic upgrade checking is disabled.") ?>
+ endif ?>
+ if (!$version_info): ?>
+ = t("No upgrade checks have been made yet.") ?>
+ else: ?>
+ = t("The last upgrade check was made on %date.",
+ array("date" => gallery::date_time($version_info->timestamp))) ?>
+ endif ?>
+
+
--
cgit v1.2.3
From 20ae106c22b9528d34fb85d09a7ab542e6c6c880 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Mon, 17 Jan 2011 21:15:33 -0800
Subject: Display a message in the "Check for Gallery upgrades" block when
there's a newer version available, even if the user has dismissed the site
status message. #1605.
---
.../gallery/controllers/admin_upgrade_checker.php | 9 ++++++-
modules/gallery/helpers/gallery_block.php | 1 +
modules/gallery/helpers/upgrade_checker.php | 31 +++++++---------------
.../gallery/views/upgrade_checker_block.html.php | 8 ++++++
themes/admin_wind/css/screen.css | 2 +-
5 files changed, 27 insertions(+), 24 deletions(-)
(limited to 'modules/gallery/views')
diff --git a/modules/gallery/controllers/admin_upgrade_checker.php b/modules/gallery/controllers/admin_upgrade_checker.php
index 4b1467cd..456a982c 100644
--- a/modules/gallery/controllers/admin_upgrade_checker.php
+++ b/modules/gallery/controllers/admin_upgrade_checker.php
@@ -21,7 +21,14 @@ class Admin_Upgrade_Checker_Controller extends Admin_Controller {
function check_now() {
access::verify_csrf();
upgrade_checker::fetch_version_info();
- upgrade_checker::check_for_upgrade();
+ $message = upgrade_checker::get_upgrade_message();
+ if ($message) {
+ $message .= " [x]";
+ site_status::info($message, "upgrade_checker");
+ } else {
+ site_status::clear("upgrade_checker");
+ }
url::redirect("admin/dashboard");
}
diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php
index 2189a710..fed786cc 100644
--- a/modules/gallery/helpers/gallery_block.php
+++ b/modules/gallery/helpers/gallery_block.php
@@ -111,6 +111,7 @@ class gallery_block_Core {
$block->content = new View("upgrade_checker_block.html");
$block->content->version_info = upgrade_checker::version_info();
$block->content->auto_check_enabled = upgrade_checker::auto_check_enabled();
+ $block->content->new_version = upgrade_checker::get_upgrade_message();
}
return $block;
}
diff --git a/modules/gallery/helpers/upgrade_checker.php b/modules/gallery/helpers/upgrade_checker.php
index 0e72bb94..f92203c8 100644
--- a/modules/gallery/helpers/upgrade_checker.php
+++ b/modules/gallery/helpers/upgrade_checker.php
@@ -77,40 +77,27 @@ class upgrade_checker_Core {
/**
* Check the latest version info blob to see if it's time for an upgrade.
*/
- static function check_for_upgrade() {
+ static function get_upgrade_message() {
$version_info = upgrade_checker::version_info();
- $upgrade_available = false;
if ($version_info) {
if (gallery::RELEASE_CHANNEL == "release") {
if (version_compare($version_info->data["release_version"], gallery::VERSION, ">")) {
- site_status::warning(
- t("A newer version of Gallery is available! Upgrade now to version %version or wait until later.",
- array("version" => $version_info->data["release_version"],
- "upgrade-url" => $version_info->data["release_upgrade_url"],
- "hide-url" => url::site("admin/upgrade_checker/remind_me_later?csrf=__CSRF__"))),
- "upgrade_checker");
- $upgrade_available = true;
+ return t("A newer version of Gallery is available! Upgrade now to version %version",
+ array("version" => $version_info->data["release_version"],
+ "upgrade-url" => $version_info->data["release_upgrade_url"]));
}
} else {
$branch = gallery::RELEASE_BRANCH;
if (isset($version_info->data["branch_{$branch}_build_number"]) &&
version_compare($version_info->data["branch_{$branch}_build_number"],
gallery::build_number(), ">")) {
- site_status::warning(
- t("A newer version of Gallery is available! Upgrade now to version %version (build %build on branch %branch) or wait until later.",
- array("version" => $version_info->data["branch_{$branch}_version"],
- "upgrade-url" => $version_info->data["branch_{$branch}_upgrade_url"],
- "build" => $version_info->data["branch_{$branch}_build_number"],
- "branch" => $branch,
- "hide-url" => url::site("admin/upgrade_checker/remind_me_later?csrf=__CSRF__"))),
- "upgrade_checker");
- $upgrade_available = true;
+ return t("A newer version of Gallery is available! Upgrade now to version %version (build %build on branch %branch)",
+ array("version" => $version_info->data["branch_{$branch}_version"],
+ "upgrade-url" => $version_info->data["branch_{$branch}_upgrade_url"],
+ "build" => $version_info->data["branch_{$branch}_build_number"],
+ "branch" => $branch));
}
}
}
-
- if (!$upgrade_available) {
- site_status::clear("upgrade_checker");
- }
}
}
diff --git a/modules/gallery/views/upgrade_checker_block.html.php b/modules/gallery/views/upgrade_checker_block.html.php
index 30e18305..b04887b2 100644
--- a/modules/gallery/views/upgrade_checker_block.html.php
+++ b/modules/gallery/views/upgrade_checker_block.html.php
@@ -11,6 +11,14 @@
endif ?>
+ if ($new_version): ?>
+
+ -
+ = $new_version ?>
+
+
+ endif ?>
+
">
diff --git a/themes/admin_wind/css/screen.css b/themes/admin_wind/css/screen.css
index 7d491cb7..a5376ff6 100644
--- a/themes/admin_wind/css/screen.css
+++ b/themes/admin_wind/css/screen.css
@@ -888,10 +888,10 @@ button {
background-position: .4em .3em;
border: 1px solid #ccc;
padding: 0;
+ margin-bottom: 1em;
}
#g-action-status {
- margin-bottom: 1em;
}
#g-action-status li,
--
cgit v1.2.3