1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/freshrss_ynh.git synced 2024-09-03 18:36:33 +02:00
freshrss_ynh/sources/app/Controllers/updateController.php

162 lines
4.4 KiB
PHP
Raw Normal View History

2014-09-27 10:10:43 +02:00
<?php
class FreshRSS_update_Controller extends Minz_ActionController {
2015-02-08 18:55:48 +01:00
2014-09-27 10:10:43 +02:00
public function firstAction() {
2015-02-08 18:55:48 +01:00
if (!FreshRSS_Auth::hasAccess('admin')) {
Minz_Error::error(403);
2014-09-27 10:10:43 +02:00
}
invalidateHttpCache();
$this->view->update_to_apply = false;
$this->view->last_update_time = 'unknown';
2015-02-08 18:55:48 +01:00
$timestamp = @filemtime(join_path(DATA_PATH, 'last_update.txt'));
if ($timestamp !== false) {
2014-09-27 10:10:43 +02:00
$this->view->last_update_time = timestamptodate($timestamp);
}
}
public function indexAction() {
2015-02-08 18:55:48 +01:00
Minz_View::prependTitle(_t('admin.update.title') . ' · ');
2014-09-27 10:10:43 +02:00
if (file_exists(UPDATE_FILENAME) && !is_writable(FRESHRSS_PATH)) {
$this->view->message = array(
'status' => 'bad',
2015-02-08 18:55:48 +01:00
'title' => _t('gen.short.damn'),
'body' => _t('feedback.update.file_is_nok', FRESHRSS_PATH)
2014-09-27 10:10:43 +02:00
);
} elseif (file_exists(UPDATE_FILENAME)) {
// There is an update file to apply!
2015-02-08 18:55:48 +01:00
$version = @file_get_contents(join_path(DATA_PATH, 'last_update.txt'));
if (empty($version)) {
$version = 'unknown';
}
2014-09-27 10:10:43 +02:00
$this->view->update_to_apply = true;
$this->view->message = array(
'status' => 'good',
2015-02-08 18:55:48 +01:00
'title' => _t('gen.short.ok'),
'body' => _t('feedback.update.can_apply', $version)
2014-09-27 10:10:43 +02:00
);
}
}
public function checkAction() {
$this->view->change_view('update', 'index');
2015-02-08 18:55:48 +01:00
if (file_exists(UPDATE_FILENAME)) {
2014-09-27 10:10:43 +02:00
// 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.
2015-02-08 18:55:48 +01:00
Minz_Request::forward(array('c' => 'update'), true);
2014-09-27 10:10:43 +02:00
return;
}
2015-11-06 16:54:20 +01:00
$auto_update_url = FreshRSS_Context::$system_conf->auto_update_url . '?v=' . FRESHRSS_VERSION;
$c = curl_init($auto_update_url);
2014-09-27 10:10:43 +02:00
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($c);
$c_status = curl_getinfo($c, CURLINFO_HTTP_CODE);
$c_error = curl_error($c);
curl_close($c);
if ($c_status !== 200) {
2015-11-06 16:54:20 +01:00
Minz_Log::warning(
2014-09-27 10:10:43 +02:00
'Error during update (HTTP code ' . $c_status . '): ' . $c_error
);
$this->view->message = array(
'status' => 'bad',
2015-02-08 18:55:48 +01:00
'title' => _t('gen.short.damn'),
2015-11-06 16:54:20 +01:00
'body' => _t('feedback.update.server_not_found', $auto_update_url)
2014-09-27 10:10:43 +02:00
);
return;
}
$res_array = explode("\n", $result, 2);
$status = $res_array[0];
if (strpos($status, 'UPDATE') !== 0) {
$this->view->message = array(
'status' => 'bad',
2015-02-08 18:55:48 +01:00
'title' => _t('gen.short.damn'),
'body' => _t('feedback.update.none')
2014-09-27 10:10:43 +02:00
);
2015-02-08 18:55:48 +01:00
@touch(join_path(DATA_PATH, 'last_update.txt'));
2014-09-27 10:10:43 +02:00
return;
}
$script = $res_array[1];
if (file_put_contents(UPDATE_FILENAME, $script) !== false) {
2015-02-08 18:55:48 +01:00
$version = explode(' ', $status, 2);
$version = $version[1];
@file_put_contents(join_path(DATA_PATH, 'last_update.txt'), $version);
Minz_Request::forward(array('c' => 'update'), true);
2014-09-27 10:10:43 +02:00
} else {
$this->view->message = array(
'status' => 'bad',
2015-02-08 18:55:48 +01:00
'title' => _t('gen.short.damn'),
'body' => _t('feedback.update.error', 'Cannot save the update script')
2014-09-27 10:10:43 +02:00
);
}
}
public function applyAction() {
if (!file_exists(UPDATE_FILENAME) || !is_writable(FRESHRSS_PATH)) {
Minz_Request::forward(array('c' => 'update'), true);
}
require(UPDATE_FILENAME);
2015-02-08 18:55:48 +01:00
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'), '');
Minz_Request::good(_t('feedback.update.finished'));
} else {
Minz_Request::bad(_t('feedback.update.error', $res),
array('c' => 'update', 'a' => 'index'));
}
}
2014-09-27 10:10:43 +02:00
if (Minz_Request::isPost()) {
save_info_update();
}
if (!need_info_update()) {
$res = apply_update();
if ($res === true) {
2015-02-08 18:55:48 +01:00
Minz_Request::forward(array(
'c' => 'update',
'a' => 'apply',
'params' => array('post_conf' => true)
), true);
2014-09-27 10:10:43 +02:00
} else {
2015-02-08 18:55:48 +01:00
Minz_Request::bad(_t('feedback.update.error', $res),
2014-09-27 10:10:43 +02:00
array('c' => 'update', 'a' => 'index'));
}
}
}
2015-02-08 18:55:48 +01:00
/**
* This action displays information about installation.
*/
public function checkInstallAction() {
Minz_View::prependTitle(_t('admin.check_install.title') . ' · ');
$this->view->status_php = check_install_php();
$this->view->status_files = check_install_files();
$this->view->status_database = check_install_database();
}
2014-09-27 10:10:43 +02:00
}