aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Controllers/updateController.php47
-rw-r--r--tests/phpstan-next.txt1
2 files changed, 32 insertions, 16 deletions
diff --git a/app/Controllers/updateController.php b/app/Controllers/updateController.php
index 7538c58ce..a9cc8c334 100644
--- a/app/Controllers/updateController.php
+++ b/app/Controllers/updateController.php
@@ -2,7 +2,7 @@
class FreshRSS_update_Controller extends FreshRSS_ActionController {
- const LASTUPDATEFILE = 'last_update.txt';
+ private const LASTUPDATEFILE = 'last_update.txt';
public static function isGit(): bool {
return is_dir(FRESHRSS_PATH . '/.git/');
@@ -46,8 +46,12 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
public static function hasGitUpdate(): bool {
$cwd = getcwd();
+ if ($cwd === false) {
+ Minz_Log::warning('getcwd() failed');
+ return false;
+ }
chdir(FRESHRSS_PATH);
- $output = array();
+ $output = [];
try {
exec('git fetch --prune', $output, $return);
if ($return == 0) {
@@ -69,6 +73,10 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
/** @return string|true */
public static function gitPull() {
$cwd = getcwd();
+ if ($cwd === false) {
+ Minz_Log::warning('getcwd() failed');
+ return 'getcwd() failed';
+ }
chdir(FRESHRSS_PATH);
$output = [];
$return = 1;
@@ -149,7 +157,6 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
}
$script = '';
- $version = '';
if (self::isGit()) {
if (self::hasGitUpdate()) {
@@ -166,18 +173,28 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
} else {
$auto_update_url = FreshRSS_Context::$system_conf->auto_update_url . '/?v=' . FRESHRSS_VERSION;
Minz_Log::debug('HTTP GET ' . $auto_update_url);
- $c = curl_init($auto_update_url);
- 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) {
+ $curlResource = curl_init($auto_update_url);
+
+ if ($curlResource === false) {
+ Minz_Log::warning('curl_init() failed');
+ $this->view->message = [
+ 'status' => 'bad',
+ 'title' => _t('gen.short.damn'),
+ 'body' => _t('feedback.update.server_not_found', $auto_update_url)
+ ];
+ return;
+ }
+ curl_setopt($curlResource, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curlResource, CURLOPT_SSL_VERIFYPEER, true);
+ curl_setopt($curlResource, CURLOPT_SSL_VERIFYHOST, 2);
+ $result = curl_exec($curlResource);
+ $curlGetinfo = curl_getinfo($curlResource, CURLINFO_HTTP_CODE);
+ $curlError = curl_error($curlResource);
+ curl_close($curlResource);
+
+ if ($curlGetinfo !== 200) {
Minz_Log::warning(
- 'Error during update (HTTP code ' . $c_status . '): ' . $c_error
+ 'Error during update (HTTP code ' . $curlGetinfo . '): ' . $curlError
);
$this->view->message = array(
@@ -188,7 +205,7 @@ class FreshRSS_update_Controller extends FreshRSS_ActionController {
return;
}
- $res_array = explode("\n", $result, 2);
+ $res_array = explode("\n", (string)$result, 2);
$status = $res_array[0];
if (strpos($status, 'UPDATE') !== 0) {
$this->view->message = array(
diff --git a/tests/phpstan-next.txt b/tests/phpstan-next.txt
index cfcbedf0a..84953b10a 100644
--- a/tests/phpstan-next.txt
+++ b/tests/phpstan-next.txt
@@ -4,7 +4,6 @@
# find . -type d -name 'vendor' -prune -o -name '*.php' -exec sh -c 'vendor/bin/phpstan analyse --level 7 --memory-limit 512M {} >/dev/null 2>/dev/null || echo {}' \;
./app/Controllers/indexController.php
-./app/Controllers/updateController.php
./app/Controllers/userController.php
./app/Models/Feed.php
./app/Models/Share.php