public function getUpdates($sources = array(), $jVersion = null)
{
// Make sure we have a valid list of sources
if (empty($sources) || !is_array($sources)) {
$sources = array();
}
$defaultSources = array('lts' => true, 'sts' => true, 'test' => true, 'custom' => '');
$sources = array_merge($defaultSources, $sources);
// Use the current JVERSION if none is specified
if (empty($jVersion)) {
$jVersion = JVERSION;
}
// Get the current branch' min/max versions
$versionParts = explode('.', $jVersion, 4);
$currentMinVersion = $versionParts[0] . '.' . $versionParts[1];
$currentMaxVersion = $versionParts[0] . '.' . $versionParts[1] . '.9999';
// Retrieve all updates
$allUpdates = array();
foreach ($sources as $source => $value) {
if ($value === false || empty($value)) {
continue;
}
switch ($source) {
default:
case 'lts':
$url = self::$lts_url;
break;
case 'sts':
$url = self::$sts_url;
break;
case 'test':
$url = self::$test_url;
break;
case 'custom':
$url = $value;
break;
}
$url = $this->getUpdateSourceFromCollection($url, $jVersion);
if (!empty($url)) {
$updates = $this->getUpdatesFromExtension($url);
if (!empty($updates)) {
$applicableUpdates = $this->filterApplicableUpdates($updates, $jVersion);
if (!empty($applicableUpdates)) {
$allUpdates = array_merge($allUpdates, $applicableUpdates);
}
}
}
}
$ret = array('installed' => array('version' => '', 'package' => '', 'infourl' => ''), 'current' => array('version' => '', 'package' => '', 'infourl' => ''), 'sts' => array('version' => '', 'package' => '', 'infourl' => ''), 'lts' => array('version' => '', 'package' => '', 'infourl' => ''), 'test' => array('version' => '', 'package' => '', 'infourl' => ''));
foreach ($allUpdates as $update) {
$sections = array();
if ($update['upgrade'] == 'current') {
$sections[0] = 'installed';
} elseif (version_compare($update['version'], $currentMinVersion, 'ge') && version_compare($update['version'], $currentMaxVersion, 'le')) {
$sections[0] = 'current';
} else {
$sections[0] = '';
}
$sections[1] = $update['lts'] ? 'lts' : 'sts';
if ($update['testing']) {
$sections = array('test');
}
foreach ($sections as $section) {
if (empty($section)) {
continue;
}
$existingVersionForSection = $ret[$section]['version'];
if (empty($existingVersionForSection)) {
$existingVersionForSection = '0.0.0';
}
if (version_compare($update['version'], $existingVersionForSection, 'ge')) {
$ret[$section]['version'] = $update['version'];
$ret[$section]['package'] = $update['downloads'][0]['url'];
$ret[$section]['infourl'] = $update['infourl']['url'];
}
}
}
// Catch the case when the latest current branch version is the installed version (up to date site)
if (empty($ret['current']['version']) && !empty($ret['installed']['version'])) {
$ret['current'] = $ret['installed'];
}
return $ret;
}