From 0271c87bb0045af88c661afbbb573058e9913969 Mon Sep 17 00:00:00 2001 From: Olle Haerstedt Date: Mon, 8 Oct 2018 17:36:26 +0200 Subject: [PATCH] Dev: Move method fetchVersions() to parent abstract class --- .../core/plugins/UpdateCheck/UpdateCheck.php | 4 ++ .../ExtensionInstaller/ExtensionUpdater.php | 61 +++++++++++++++++-- .../ExtensionInstaller/PluginUpdater.php | 55 ----------------- 3 files changed, 59 insertions(+), 61 deletions(-) diff --git a/application/core/plugins/UpdateCheck/UpdateCheck.php b/application/core/plugins/UpdateCheck/UpdateCheck.php index 45357d92969..3afc369c353 100644 --- a/application/core/plugins/UpdateCheck/UpdateCheck.php +++ b/application/core/plugins/UpdateCheck/UpdateCheck.php @@ -38,6 +38,7 @@ public function init() } /** + * After super admin log in, check date of next update check and set flag. * @return void */ public function afterSuccessfulLogin() @@ -55,6 +56,8 @@ public function afterSuccessfulLogin() } /** + * If we're in an admin controller and the flag is set, render the JavaScript that + * will Ajax the checkAll() URL and push a notification. * @return void */ public function beforeControllerAction() @@ -81,6 +84,7 @@ public function beforeControllerAction() * Used to check for available updates for all plugins. * This method should be run at super admin login, max once every day. * Run by Ajax to avoid increased page load time. + * This method can also be run manually for testing. * @return void */ public function checkAll() diff --git a/application/libraries/ExtensionInstaller/ExtensionUpdater.php b/application/libraries/ExtensionInstaller/ExtensionUpdater.php index 9e1e30331c4..c9b9f6d0ca7 100644 --- a/application/libraries/ExtensionInstaller/ExtensionUpdater.php +++ b/application/libraries/ExtensionInstaller/ExtensionUpdater.php @@ -181,16 +181,65 @@ public function getLatestVersion(array $versions) } /** - * Create an updater object for every extension of corresponding type. - * @return array [ExtensionUpdater[] $updaters, string[] $errorMessages] + * Fetch all new available version from each version fetcher. + * @return array $versions + * @todo Move to parent class? */ - abstract public static function createUpdaters(); + public function fetchVersions() + { + $config = $this->getExtensionConfig(); + $versionFetchers = $config->createVersionFetchers(); + + if (empty($versionFetchers)) { + // No fetchers, can't fetch remote version. + return []; + } + + $allowUnstable = getGlobalSetting('allow_unstable_extension_update'); + + $versions = []; + foreach ($versionFetchers as $fetcher) { + + // Setup fetcher. + $fetcher->setExtensionName($this->getExtensionName()); + $fetcher->setExtensionType($this->getExtensionType()); + + // Fetch versions. + $newVersion = $fetcher->getLatestVersion(); + $lastSecurityVersion = $fetcher->getLatestSecurityVersion(); + + if (version_compare($lastSecurityVersion, $this->getCurrentVersion(), '>')) { + $versions[] = [ + 'isSecurityVersion' => true, + 'version' => $lastSecurityVersion, + 'manualUpdateUrl' => $fetcher->getManualUpdateUrl() + ]; + } + + // If this version is unstable and we're not allowed to use it, continue. + if (!$allowUnstable && !$this->versionIsStable($newVersion)) { + continue; + } + + if (version_compare($newVersion, $this->getCurrentVersion(), '>')) { + $versions[] = [ + 'isSecurityVersion' => false, + 'version' => $newVersion, + 'manualUpdateUrl' => $fetcher->getManualUpdateUrl() + ]; + } else { + // Ignore. + } + } + + return $versions; + } /** - * Uses the version fetchers to fetch info about available updates for this extension. - * @return array + * Create an updater object for every extension of corresponding type. + * @return array [ExtensionUpdater[] $updaters, string[] $errorMessages] */ - abstract public function fetchVersions(); + abstract public static function createUpdaters(); /** * Fetch extension name from extension model. diff --git a/application/libraries/ExtensionInstaller/PluginUpdater.php b/application/libraries/ExtensionInstaller/PluginUpdater.php index d5ec5a9baa3..62d2928e418 100644 --- a/application/libraries/ExtensionInstaller/PluginUpdater.php +++ b/application/libraries/ExtensionInstaller/PluginUpdater.php @@ -42,61 +42,6 @@ public static function createUpdaters() : array return [$updaters, $errors]; } - /** - * Fetch all new available version from each version fetcher. - * @return array $versions - * @todo Move to parent class? - */ - public function fetchVersions() - { - $config = $this->getExtensionConfig(); - $versionFetchers = $config->createVersionFetchers(); - - if (empty($versionFetchers)) { - // No fetchers, can't fetch remote version. - return []; - } - - $allowUnstable = getGlobalSetting('allow_unstable_extension_update'); - - $versions = []; - foreach ($versionFetchers as $fetcher) { - - // Setup fetcher. - $fetcher->setExtensionName($this->getExtensionName()); - $fetcher->setExtensionType($this->getExtensionType()); - - // Fetch versions. - $newVersion = $fetcher->getLatestVersion(); - $lastSecurityVersion = $fetcher->getLatestSecurityVersion(); - - if (version_compare($lastSecurityVersion, $this->getCurrentVersion(), '>')) { - $versions[] = [ - 'isSecurityVersion' => true, - 'version' => $lastSecurityVersion, - 'manualUpdateUrl' => $fetcher->getManualUpdateUrl() - ]; - } - - // If this version is unstable and we're not allowed to use it, continue. - if (!$allowUnstable && !$this->versionIsStable($newVersion)) { - continue; - } - - if (version_compare($newVersion, $this->getCurrentVersion(), '>')) { - $versions[] = [ - 'isSecurityVersion' => false, - 'version' => $newVersion, - 'manualUpdateUrl' => $fetcher->getManualUpdateUrl() - ]; - } else { - // Ignore. - } - } - - return $versions; - } - /** * @return string */