diff options
author | Bharat Mediratta <bharat@menalto.com> | 2011-01-16 23:14:57 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2011-01-16 23:14:57 -0800 |
commit | 66bb496b6c2ad9c5341644b2e303e694078374d1 (patch) | |
tree | 7521d11a5eae53a2ea854e16588980ec91fa8447 | |
parent | 167f635a6ce5a71b35450844f9b5c647aa14bcc1 (diff) |
If the logged in user is an admin and it's been more than 7 days since
the last check and auto upgrade checking is enabled, fire off an XHR
to check for a possible upgrade. Finishes off #1605.
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 3 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_theme.php | 20 | ||||
-rw-r--r-- | modules/gallery/helpers/upgrade_checker.php | 25 |
3 files changed, 46 insertions, 2 deletions
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php index 1ffe9bae..41ed1c6e 100644 --- a/modules/gallery/helpers/gallery_installer.php +++ b/modules/gallery/helpers/gallery_installer.php @@ -677,6 +677,9 @@ class gallery_installer { module::set_var("gallery", "upgrade_checker_auto_enabled", true); module::set_version("gallery", $version = 46); } + + // Clear any upgrade check strings, we are probably up to date. + site_status::clear("upgrade_check"); } static function uninstall() { diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index d75c6fc6..a6ca5eb7 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -76,13 +76,22 @@ class gallery_theme_Core { $profiler = new Profiler(); $profiler->render(); } + $content = ""; if ($session->get("l10n_mode", false)) { - return L10n_Client_Controller::l10n_form(); + $content .= L10n_Client_Controller::l10n_form(); } if ($session->get_once("after_install")) { - return new View("welcome_message_loader.html"); + $content .= new View("welcome_message_loader.html"); } + + if (identity::active_user()->admin && upgrade_checker::should_auto_check()) { + $content .= '<script type="text/javascript"> + $.ajax({url: "' . url::site("admin/upgrade_checker/check_now?csrf=" . + access::csrf_token()) . '"}); + </script>'; + } + return $content; } static function admin_page_bottom($theme) { @@ -107,6 +116,13 @@ class gallery_theme_Core { setInterval("adminReauthCheck();", 60 * 1000); </script>'; + if (upgrade_checker::should_auto_check()) { + $content .= '<script type="text/javascript"> + $.ajax({url: "' . url::site("admin/upgrade_checker/check_now?csrf=" . + access::csrf_token()) . '"}); + </script>'; + } + if ($session->get("l10n_mode", false)) { $content .= "\n" . L10n_Client_Controller::l10n_form(); } diff --git a/modules/gallery/helpers/upgrade_checker.php b/modules/gallery/helpers/upgrade_checker.php index 9311cf4a..ef1308d7 100644 --- a/modules/gallery/helpers/upgrade_checker.php +++ b/modules/gallery/helpers/upgrade_checker.php @@ -19,15 +19,37 @@ */ class upgrade_checker_Core { const CHECK_URL = "http://gallery.menalto.com/versioncheck/gallery3"; + const AUTO_CHECK_INTERVAL = 604800; // 7 days in seconds + /** + * Return the last version info blob retrieved from the Gallery website or + * null if no checks have been performed. + */ static function version_info() { return unserialize(Cache::instance()->get("upgrade_checker_version_info")); } + /** + * Return true if auto checking is enabled. + */ static function auto_check_enabled() { return (bool)module::get_var("gallery", "upgrade_checker_auto_enabled"); } + /** + * Return true if it's time to auto check. + */ + static function should_auto_check() { + if (upgrade_checker::auto_check_enabled() && random::int(1, 100) == 1) { + $version_info = upgrade_checker::version_info(); + return (!$version_info || (time() - $version_info->timestamp) > AUTO_CHECK_INTERVAL); + } + return false; + } + + /** + * Fech version info from the Gallery website. + */ static function fetch_version_info() { $result = new stdClass(); try { @@ -52,6 +74,9 @@ class upgrade_checker_Core { Cache::instance()->set("upgrade_checker_version_info", serialize($result), null, 86400 * 365); } + /** + * Check the latest version info blob to see if it's time for an upgrade. + */ static function check_for_upgrade() { $version_info = upgrade_checker::version_info(); $upgrade_available = false; |