Skip to content

Commit

Permalink
Dev: Move method fetchVersions() to parent abstract class
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Oct 8, 2018
1 parent f264c39 commit 0271c87
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 61 deletions.
4 changes: 4 additions & 0 deletions application/core/plugins/UpdateCheck/UpdateCheck.php
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
61 changes: 55 additions & 6 deletions application/libraries/ExtensionInstaller/ExtensionUpdater.php
Expand Up @@ -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.
Expand Down
55 changes: 0 additions & 55 deletions application/libraries/ExtensionInstaller/PluginUpdater.php
Expand Up @@ -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
*/
Expand Down

0 comments on commit 0271c87

Please sign in to comment.