From 7f2fe465b07c149a7131943215103d9ae0f21b69 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 27 Feb 2021 19:14:13 +0300 Subject: add plugin updates checker into normal updates checker --- classes/pref/prefs.php | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) (limited to 'classes/pref') diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index d5a6dde76..8746aa1e0 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -1093,7 +1093,28 @@ class Pref_Prefs extends Handler_Protected { set_pref(Prefs::_ENABLED_PLUGINS, $plugins); } - private function _plugin_needs_update($root_dir, $plugin_name) { + static function _get_updated_plugins() { + $root_dir = dirname(dirname(__DIR__)); # we're in classes/pref/ + $plugin_dirs = array_filter(glob("$root_dir/plugins.local/*"), "is_dir"); + + $rv = []; + + foreach ($plugin_dirs as $dir) { + if (is_dir("$dir/.git")) { + $plugin_name = basename($dir); + + array_push($rv, ["plugin" => $plugin_name, "rv" => self::_plugin_needs_update($root_dir, $plugin_name)]); + } + } + + $rv = array_values(array_filter($rv, function ($item) { + return !empty($item["rv"]["o"]); + })); + + return $rv; + } + + private static function _plugin_needs_update($root_dir, $plugin_name) { $plugin_dir = "$root_dir/plugins.local/" . basename($plugin_name); $rv = []; @@ -1150,23 +1171,12 @@ class Pref_Prefs extends Handler_Protected { if ($_SESSION["access_level"] >= 10) { $plugin_name = $_REQUEST["name"] ?? ""; - # we're in classes/pref/ - $root_dir = dirname(dirname(__DIR__)); - - $rv = []; + $root_dir = dirname(dirname(__DIR__)); # we're in classes/pref/ if (!empty($plugin_name)) { - array_push($rv, ["plugin" => $plugin_name, "rv" => $this->_plugin_needs_update($root_dir, $plugin_name)]); + $rv = ["plugin" => $plugin_name, "rv" => self::_plugin_needs_update($root_dir, $plugin_name)]; } else { - $plugin_dirs = array_filter(glob("$root_dir/plugins.local/*"), "is_dir"); - - foreach ($plugin_dirs as $dir) { - if (is_dir("$dir/.git")) { - $plugin_name = basename($dir); - - array_push($rv, ["plugin" => $plugin_name, "rv" => $this->_plugin_needs_update($root_dir, $plugin_name)]); - } - } + $rv = self::_get_updated_plugins(); } print json_encode($rv); @@ -1191,7 +1201,7 @@ class Pref_Prefs extends Handler_Protected { if (is_dir("$dir/.git")) { $plugin_name = basename($dir); - $test = $this->_plugin_needs_update($root_dir, $plugin_name); + $test = self::_plugin_needs_update($root_dir, $plugin_name); if (!empty($test["o"])) array_push($rv, ["plugin" => $plugin_name, "rv" => $this->_update_plugin($root_dir, $plugin_name)]); -- cgit v1.2.3