Skip to content

Commit

Permalink
Dev: Move some code around (updater)
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Oct 2, 2018
1 parent 38c0f02 commit b5f64a8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 56 deletions.
55 changes: 34 additions & 21 deletions application/libraries/ExtensionInstaller/ExtensionUpdater.php
Expand Up @@ -57,28 +57,9 @@ public function __construct($model)
/**
* Uses the version fetcher to get info about available updates for
* this extension.
* @return ExtensionUpdateInfo[]
* @return ?
*/
public function getAvailableUpdates()
{
$this->setupVersionFetchers();

if (empty($this->versionFetchers)) {
// No fetchers, can't fetch remote version.
return [];
}

$versions = [];
foreach ($this->versionFetchers as $fetcher) {
$fetcher->setExtensionName($this->getExtensionName());
$fetcher->setExtensionType($this->getExtensionType());
$versions[] = $fetcher->getLatestVersion();
// TODO: Check if version is relevant.
// TODO: Stable or unstable?
}

return $versions;
}
abstract public function getAvailableUpdates();

/**
* @return void
Expand All @@ -102,6 +83,38 @@ public function setupVersionFetchers()
$this->versionFetchers = $config->getVersionFetchers();
}

/**
* Returns true if this extension update version is higher than $currentVersion.
* @param string $currentVersion
* @return int
*/
public function versionHigherThan($currentVersion)
{
return version_compare($this->version, $currentVersion, '>');
}

/**
* The version is stable IF it does not contain
* alpha, beta or rc suffixes.
* @return boolean
*/
public function versionIsStable($version)
{
$suffixes = [
'alpha',
'beta',
'rc',
];
$version = strtolower($version);
foreach ($suffixes as $suffix) {
if (strpos($version, $suffix) !== false) {
return false;
}
}
return true;
}


/**
* Create an updater object for every extension of corresponding type.
* @return array [ExtensionUpdater[] $updaters, string[] $errorMessages]
Expand Down
27 changes: 27 additions & 0 deletions application/libraries/ExtensionInstaller/PluginUpdater.php
Expand Up @@ -42,6 +42,33 @@ public static function createUpdaters() : array
return [$updaters, $errors];
}

/**
* @return
*/
public function getAvailableUpdates()
{
$this->setupVersionFetchers();

if (empty($this->versionFetchers)) {
// No fetchers, can't fetch remote version.
return [];
}

$versions = [];
foreach ($this->versionFetchers as $fetcher) {
$fetcher->setExtensionName($this->getExtensionName());
$fetcher->setExtensionType($this->getExtensionType());
$newVersion = $fetcher->getLatestVersion();
if (version_compare($newVersion, $this->model->version, '>')) {
} else {
// Ignore.
}
}
echo $this->model->version;

return $versions;
}

/**
* @return string
*/
Expand Down
42 changes: 7 additions & 35 deletions application/models/ExtensionUpdateInfo.php
Expand Up @@ -15,6 +15,9 @@
/**
* Thin wrapper around extension update info.
* Used by VersionFetcher to push around update info.
*
* @since 2018-10-01
* @author Olle Haerstedt
*/
class ExtensionUpdateInfo
{
Expand All @@ -24,9 +27,9 @@ class ExtensionUpdateInfo
protected $extensionType;

/**
* @var string
* @var array
*/
protected $version;
protected $versions;

/**
* @var boolean
Expand All @@ -38,44 +41,13 @@ class ExtensionUpdateInfo
* @param string $version
* @param boolean $security
*/
public function __construct($type, $version, $security = false)
public function __construct($type, $versions, $security = false)
{
$this->extensionType = $type;
$this->version = $version;
$this->versions = $versions;
$this->isSecurityUpdate = $security;
}

/**
* The version is stable IF it does not contain
* alpha, beta or rc suffixes.
* @return boolean
*/
public function versionIsStable()
{
$suffixes = [
'alpha',
'beta',
'rc',
];
$version = strtolower($this->version);
foreach ($suffixes as $suffix) {
if (strpos($version, $suffix) !== false) {
return false;
}
}
return true;
}

/**
* Returns true if this extension update version is higher than $currentVersion.
* @param string $currentVersion
* @return int
*/
public function versionHigherThan($currentVersion)
{
return version_compare($this->version, $currentVersion, '>');
}

/**
*
*/
Expand Down

0 comments on commit b5f64a8

Please sign in to comment.