From e7dba0ce7cfaf5e84687593a8b0d58d89fbff302 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 9 Aug 2014 23:29:13 +0200 Subject: Add basic system of update - Check on update.freshrss.org for new updates - Download script - Apply script - Need translations and verifications NOTE: current script on server indicates version 0.7.3 is an update of 0.8-dev ==> IT'S ONLY FOR MY TESTS! Script just does a backup of ./data actually... See https://github.com/marienfressinaud/FreshRSS/issues/411 --- app/Controllers/updateController.php | 106 +++++++++++++++++++++++++++++++++++ app/i18n/en.php | 2 + app/i18n/fr.php | 2 + app/layout/aside_configure.phtml | 38 ++++++++----- app/layout/header.phtml | 6 ++ app/views/update/index.phtml | 19 +++++++ 6 files changed, 158 insertions(+), 15 deletions(-) create mode 100644 app/Controllers/updateController.php create mode 100644 app/views/update/index.phtml (limited to 'app') diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php new file mode 100644 index 000000000..a15cb9fd5 --- /dev/null +++ b/app/Controllers/updateController.php @@ -0,0 +1,106 @@ +view->loginOk && Minz_Configuration::isAdmin($current_user)) { + Minz_Error::error( + 403, + array('error' => array(_t('access_denied'))) + ); + } + + Minz_View::prependTitle(_t('update_system') . ' · '); + } + + public function indexAction() { + if (file_exists(UPDATE_FILENAME)) { + // There is an update file to apply! + $this->view->message = array( + 'status' => 'good', + 'title' => _t('ok'), + 'body' => _t('update_can_apply', _url('update', 'apply')) + ); + + return; + } + } + + public function checkAction() { + $this->view->change_view('update', 'index'); + + if (file_exists(UPDATE_FILENAME)) { + // There is already an update file to apply: we don't need to check + // the webserver! + $this->view->message = array( + 'status' => 'good', + 'title' => _t('ok'), + 'body' => _t('update_can_apply', _url('update', 'apply')) + ); + + return; + } + + $c = curl_init(FRESHRSS_UPDATE_WEBSITE); + curl_setopt($c, CURLOPT_RETURNTRANSFER, true); + $result = curl_exec($c); + + if (curl_getinfo($c, CURLINFO_HTTP_CODE) == 200) { + $res_array = explode("\n", $result, 2); + $status = $res_array[0]; + + if (strpos($status, 'UPDATE') === 0) { + $script = $res_array[1]; + if (file_put_contents(UPDATE_FILENAME, $script) !== false) { + $this->view->message = array( + 'status' => 'good', + 'title' => _t('ok'), + 'body' => _t('update_can_apply', _url('update', 'apply')) + ); + } else { + $this->view->message = array( + 'status' => 'bad', + 'title' => _t('damn'), + 'body' => _t('update_problem') + ); + } + } else { + $this->view->message = array( + 'status' => 'bad', + 'title' => _t('damn'), + 'body' => _t('no_update') + ); + } + } else { + $this->view->message = array( + 'status' => 'bad', + 'title' => _t('damn'), + 'body' => _t('update_server_not_found', FRESHRSS_UPDATE_WEBSITE) + ); + } + curl_close($c); + } + + public function applyAction() { + require(UPDATE_FILENAME); + $res = apply_update(); + + if ($res === true) { + @unlink(UPDATE_FILENAME); + + Minz_Session::_param('notification', array( + 'type' => 'good', + 'content' => Minz_Translate::t('update_finished') + )); + + Minz_Request::forward(array(), true); + } else { + Minz_Session::_param('notification', array( + 'type' => 'bad', + 'content' => Minz_Translate::t('update_failed', $res) + )); + + Minz_Request::forward(array('c' => 'update'), true); + } + } +} \ No newline at end of file diff --git a/app/i18n/en.php b/app/i18n/en.php index d80299b10..6110ccb11 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -408,4 +408,6 @@ return array ( 'stats_entry_per_category' => 'Entries per category', 'stats_top_feed' => 'Top ten feeds', 'stats_entry_count' => 'Entry count', + + 'update_can_apply' => 'There is an available update. Apply', ); diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 4be028ac3..5f88aa069 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -408,4 +408,6 @@ return array ( 'stats_entry_per_category' => 'Articles par catégorie', 'stats_top_feed' => 'Les dix plus gros flux', 'stats_entry_count' => 'Nombre d’articles', + + 'update_can_apply' => 'Il y’a une mise à jour à appliquer. Appliquer', ); diff --git a/app/layout/aside_configure.phtml b/app/layout/aside_configure.phtml index e66f2f64c..03bea4836 100644 --- a/app/layout/aside_configure.phtml +++ b/app/layout/aside_configure.phtml @@ -1,25 +1,33 @@ diff --git a/app/layout/header.phtml b/app/layout/header.phtml index 2e42bfdea..028e63d8a 100644 --- a/app/layout/header.phtml +++ b/app/layout/header.phtml @@ -75,6 +75,12 @@ if (Minz_Configuration::canLogIn()) {
  • + +
  • +
  • diff --git a/app/views/update/index.phtml b/app/views/update/index.phtml new file mode 100644 index 000000000..a1a872845 --- /dev/null +++ b/app/views/update/index.phtml @@ -0,0 +1,19 @@ +partial('aside_configure'); ?> + +
    +

    + + message)) { ?> +

    + message['title']; ?> + message['body']; ?> +

    + + + message) || $this->message['status'] !== 'good') { ?> +

    + + last_update_time); ?> +

    + +
    -- cgit v1.2.3