From e7c24b5d41c293fa13e4d92efb2aee7778ddcab4 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Tue, 13 Jan 2015 12:02:35 +0100 Subject: Show the version number during update process. Number is stored inside the data/last_update.txt file and shown if there is an update script. See https://github.com/FreshRSS/FreshRSS/issues/699 --- app/Controllers/updateController.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'app/Controllers/updateController.php') diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index 1b44a739c..4bdd96f6d 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -1,8 +1,8 @@ view->update_to_apply = false; $this->view->last_update_time = 'unknown'; $this->view->check_last_hour = false; - $timestamp = (int)@file_get_contents(DATA_PATH . '/last_update.txt'); - if (is_numeric($timestamp) && $timestamp > 0) { + $timestamp = @filemtime(join_path(DATA_PATH, 'last_update.txt')); + if ($timestamp !== false) { $this->view->last_update_time = timestamptodate($timestamp); $this->view->check_last_hour = (time() - 3600) <= $timestamp; } @@ -30,11 +30,12 @@ class FreshRSS_update_Controller extends Minz_ActionController { ); } elseif (file_exists(UPDATE_FILENAME)) { // There is an update file to apply! + $version = file_get_contents(join_path(DATA_PATH, 'last_update.txt')); $this->view->update_to_apply = true; $this->view->message = array( 'status' => 'good', 'title' => _t('gen.short.ok'), - 'body' => _t('feedback.update.can_apply') + 'body' => _t('feedback.update.can_apply', $version) ); } } @@ -82,13 +83,17 @@ class FreshRSS_update_Controller extends Minz_ActionController { 'body' => _t('feedback.update.none') ); - @file_put_contents(DATA_PATH . '/last_update.txt', time()); + @touch(join_path(DATA_PATH, 'last_update.txt')); return; } $script = $res_array[1]; if (file_put_contents(UPDATE_FILENAME, $script) !== false) { + $version = explode(' ', $status, 2); + $version = $version[1]; + @file_put_contents(join_path(DATA_PATH, 'last_update.txt'), $version); + Minz_Request::forward(array('c' => 'update')); } else { $this->view->message = array( @@ -111,7 +116,7 @@ class FreshRSS_update_Controller extends Minz_ActionController { if ($res === true) { @unlink(UPDATE_FILENAME); - @file_put_contents(DATA_PATH . '/last_update.txt', time()); + @file_put_contents(join_path(DATA_PATH, 'last_update.txt'), ''); Minz_Request::good(_t('feedback.update.finished')); } else { Minz_Request::bad(_t('feedback.update.error', $res), -- cgit v1.2.3 From 556f4ad4bfa722e3350f20ab91a08f0af1d11f9e Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 15 Jan 2015 11:20:16 +0100 Subject: Remove restriction of 1h for update checking --- app/Controllers/updateController.php | 8 +++----- app/views/update/index.phtml | 8 +------- 2 files changed, 4 insertions(+), 12 deletions(-) (limited to 'app/Controllers/updateController.php') diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index 4bdd96f6d..1ea5816da 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -11,11 +11,9 @@ class FreshRSS_update_Controller extends Minz_ActionController { $this->view->update_to_apply = false; $this->view->last_update_time = 'unknown'; - $this->view->check_last_hour = false; $timestamp = @filemtime(join_path(DATA_PATH, 'last_update.txt')); if ($timestamp !== false) { $this->view->last_update_time = timestamptodate($timestamp); - $this->view->check_last_hour = (time() - 3600) <= $timestamp; } } @@ -43,11 +41,11 @@ class FreshRSS_update_Controller extends Minz_ActionController { public function checkAction() { $this->view->change_view('update', 'index'); - if (file_exists(UPDATE_FILENAME) || $this->view->check_last_hour) { + if (file_exists(UPDATE_FILENAME)) { // There is already an update file to apply: we don't need to check // the webserver! // Or if already check during the last hour, do nothing. - Minz_Request::forward(array('c' => 'update')); + Minz_Request::forward(array('c' => 'update'), true); return; } @@ -94,7 +92,7 @@ class FreshRSS_update_Controller extends Minz_ActionController { $version = $version[1]; @file_put_contents(join_path(DATA_PATH, 'last_update.txt'), $version); - Minz_Request::forward(array('c' => 'update')); + Minz_Request::forward(array('c' => 'update'), true); } else { $this->view->message = array( 'status' => 'bad', diff --git a/app/views/update/index.phtml b/app/views/update/index.phtml index 4c88a0d18..da1bc7ef5 100644 --- a/app/views/update/index.phtml +++ b/app/views/update/index.phtml @@ -18,16 +18,10 @@ message['title']; ?> message['body']; ?>

- check_last_hour) { ?> -

- - -

check_last_hour && - (empty($this->message) || $this->message['status'] !== 'good')) { + if (empty($this->message) || $this->message['status'] !== 'good') { ?>

-- cgit v1.2.3 From 13cf8b5f9f22a50bba5d1223174407abb1c1d94c Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Thu, 15 Jan 2015 12:02:42 +0100 Subject: Improve hook calls and add post_update hook - To the hook is associated a method signature (OneToOne or NoneToNone for now) so it is easier to call hooks correctly - post_update hook is called during the post update moment. --- app/Controllers/updateController.php | 2 + lib/Minz/ExtensionManager.php | 74 +++++++++++++++++++++++++++++------- 2 files changed, 63 insertions(+), 13 deletions(-) (limited to 'app/Controllers/updateController.php') diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php index 1ea5816da..61b62773b 100644 --- a/app/Controllers/updateController.php +++ b/app/Controllers/updateController.php @@ -112,6 +112,8 @@ class FreshRSS_update_Controller extends Minz_ActionController { if (Minz_Request::param('post_conf', false)) { $res = do_post_update(); + Minz_ExtensionManager::callHook('post_update'); + if ($res === true) { @unlink(UPDATE_FILENAME); @file_put_contents(join_path(DATA_PATH, 'last_update.txt'), ''); diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php index 8369e242a..7edc7afaa 100644 --- a/lib/Minz/ExtensionManager.php +++ b/lib/Minz/ExtensionManager.php @@ -15,9 +15,22 @@ class Minz_ExtensionManager { // List of available hooks. Please keep this list sorted. private static $hook_list = array( - 'entry_before_display' => array(), // function($entry) -> Entry | null - 'entry_before_insert' => array(), // function($entry) -> Entry | null - 'feed_before_insert' => array(), // function($feed) -> Feed | null + 'entry_before_display' => array( // function($entry) -> Entry | null + 'list' => array(), + 'signature' => 'OneToOne', + ), + 'entry_before_insert' => array( // function($entry) -> Entry | null + 'list' => array(), + 'signature' => 'OneToOne', + ), + 'feed_before_insert' => array( // function($feed) -> Feed | null + 'list' => array(), + 'signature' => 'OneToOne', + ), + 'post_update' => array( // function(none) -> none + 'list' => array(), + 'signature' => 'NoneToNone', + ), ); private static $ext_to_hooks = array(); @@ -214,7 +227,7 @@ class Minz_ExtensionManager { */ public static function addHook($hook_name, $hook_function, $ext) { if (isset(self::$hook_list[$hook_name]) && is_callable($hook_function)) { - self::$hook_list[$hook_name][] = $hook_function; + self::$hook_list[$hook_name]['list'][] = $hook_function; self::$ext_to_hooks[$ext->getName()][] = $hook_name; } } @@ -226,25 +239,60 @@ class Minz_ExtensionManager { * array keys. * * @param $hook_name the hook to call. - * @param additionnal parameters (for signature, please see self::$hook_list comments) - * @todo hook functions will have different signatures. So the $res = func($args); - * $args = $res; will not work for all of them in the future. We must - * find a better way to call hooks. + * @param additionnal parameters (for signature, please see self::$hook_list). + * @return the final result of the called hook. */ public static function callHook($hook_name) { + if (!isset(self::$hook_list[$hook_name])) { + return; + } + + $signature = self::$hook_list[$hook_name]['signature']; + $signature = 'self::call' . $signature; $args = func_get_args(); - unset($args[0]); - $result = $args[1]; - foreach (self::$hook_list[$hook_name] as $function) { - $result = call_user_func_array($function, $args); + return call_user_func_array($signature, $args); + } + + /** + * Call a hook which takes one argument and return a result. + * + * The result is chained between the extension, for instance, first extension + * hook will receive the initial argument and return a result which will be + * passed as an argument to the next extension hook and so on. + * + * If a hook return a null value, the method is stopped and return null. + * + * @param $hook_name is the hook to call. + * @param $arg is the argument to pass to the first extension hook. + * @return the final chained result of the hooks. If nothing is changed, + * the initial argument is returned. + */ + private static function callOneToOne($hook_name, $arg) { + $result = $arg; + foreach (self::$hook_list[$hook_name]['list'] as $function) { + $result = call_user_func($function, $arg); if (is_null($result)) { break; } - $args = $result; + $arg = $result; } return $result; } + + /** + * Call a hook which takes no argument and returns nothing. + * + * This case is simpler than callOneToOne because hooks are called one by + * one, without any consideration of argument nor result. + * + * @param $hook_name is the hook to call. + */ + private static function callNoneToNone($hook_name) { + foreach (self::$hook_list[$hook_name]['list'] as $function) { + call_user_func($function); + } + } } -- cgit v1.2.3