Skip to content

Commit f2581cc

Browse files
authored
[3.10] Fix misleading "Update Required" in the pre-update checker (#35510)
* Fix pre-update check wrong update required information * Fix wrong code comment * Simplify code * Revert unrelated change for collection URLs * Optimize code * Use array_values for the intersect * PHPCS
1 parent 742de2e commit f2581cc

File tree

3 files changed

+80
-47
lines changed

3 files changed

+80
-47
lines changed

administrator/components/com_joomlaupdate/controllers/update.php

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -509,34 +509,59 @@ public function fetchExtensionCompatibility()
509509

510510
/** @var JoomlaupdateModelDefault $model */
511511
$model = $this->getModel('default');
512-
$upgradeCompatibilityStatus = $model->fetchCompatibility($extensionID, $joomlaTargetVersion);
513-
$currentCompatibilityStatus = $model->fetchCompatibility($extensionID, $joomlaCurrentVersion);
512+
$upgradeCompatibilityStatus = $model->fetchCompatibility($extensionID, $joomlaTargetVersion);
513+
$currentCompatibilityStatus = $model->fetchCompatibility($extensionID, $joomlaCurrentVersion);
514+
$upgradeUpdateVersion = false;
515+
$currentUpdateVersion = false;
514516

515517
$upgradeWarning = 0;
516-
517-
if ($upgradeCompatibilityStatus->state == 1 && $upgradeCompatibilityStatus->compatibleVersion !== false)
518+
519+
if ($upgradeCompatibilityStatus->state == 1 && !empty($upgradeCompatibilityStatus->compatibleVersions))
520+
{
521+
$upgradeUpdateVersion = end($upgradeCompatibilityStatus->compatibleVersions);
522+
}
523+
524+
if ($currentCompatibilityStatus->state == 1 && !empty($currentCompatibilityStatus->compatibleVersions))
518525
{
519-
if (version_compare($upgradeCompatibilityStatus->compatibleVersion, $extensionVersion, 'gt'))
526+
$currentUpdateVersion = end($currentCompatibilityStatus->compatibleVersions);
527+
}
528+
529+
if ($upgradeUpdateVersion !== false)
530+
{
531+
$upgradeOldestVersion = $upgradeCompatibilityStatus->compatibleVersions[0];
532+
533+
if ($currentUpdateVersion !== false)
520534
{
521-
// Extension needs upgrade before upgrading Joomla
535+
// If there are updates compatible with both CMS versions use these
536+
$bothCompatibleVersions = array_values(
537+
array_intersect($upgradeCompatibilityStatus->compatibleVersions, $currentCompatibilityStatus->compatibleVersions)
538+
);
539+
540+
if (!empty($bothCompatibleVersions))
541+
{
542+
$upgradeOldestVersion = $bothCompatibleVersions[0];
543+
$upgradeUpdateVersion = end($bothCompatibleVersions);
544+
}
545+
}
546+
547+
if (version_compare($upgradeOldestVersion, $extensionVersion, '>'))
548+
{
549+
// Installed version is empty or older than the oldest compatible update: Update required
522550
$resultGroup = 2;
523551
}
524552
else
525553
{
526-
// Current version is up to date and compatible
554+
// Current version is compatible
527555
$resultGroup = 3;
528556
}
529557

530-
if ($currentCompatibilityStatus->state == 1)
558+
if ($currentUpdateVersion !== false && version_compare($upgradeUpdateVersion, $currentUpdateVersion, '<'))
531559
{
532-
if (version_compare($upgradeCompatibilityStatus->compatibleVersion, $currentCompatibilityStatus->compatibleVersion, 'lt'))
533-
{
534-
// Special case warning when version compatible with target is lower than current
535-
$upgradeWarning = 2;
536-
}
560+
// Special case warning when version compatible with target is lower than current
561+
$upgradeWarning = 2;
537562
}
538563
}
539-
elseif ($currentCompatibilityStatus->state == 1)
564+
elseif ($currentUpdateVersion !== false)
540565
{
541566
// No compatible version for target version but there is a compatible version for current version
542567
$resultGroup = 1;
@@ -549,8 +574,14 @@ public function fetchExtensionCompatibility()
549574

550575
// Do we need to capture
551576
$combinedCompatibilityStatus = array(
552-
'upgradeCompatibilityStatus' => $upgradeCompatibilityStatus,
553-
'currentCompatibilityStatus' => $currentCompatibilityStatus,
577+
'upgradeCompatibilityStatus' => (object) array(
578+
'state' => $upgradeCompatibilityStatus->state,
579+
'compatibleVersion' => $upgradeUpdateVersion
580+
),
581+
'currentCompatibilityStatus' => (object) array(
582+
'state' => $currentCompatibilityStatus->state,
583+
'compatibleVersion' => $currentUpdateVersion
584+
),
554585
'resultGroup' => $resultGroup,
555586
'upgradeWarning' => $upgradeWarning,
556587
);

administrator/components/com_joomlaupdate/models/default.php

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,34 +1594,18 @@ public function fetchCompatibility($extensionID, $joomlaTargetVersion)
15941594

15951595
foreach ($updateFileUrls as $updateFileUrl)
15961596
{
1597-
$compatibleVersion = $this->checkCompatibility($updateFileUrl, $joomlaTargetVersion);
1597+
$compatibleVersions = $this->checkCompatibility($updateFileUrl, $joomlaTargetVersion);
15981598

1599-
if ($compatibleVersion)
1600-
{
1601-
// Return the compatible version
1602-
return (object) array('state' => 1, 'compatibleVersion' => $compatibleVersion->_data);
1603-
}
1604-
else
1605-
{
1606-
// Return the compatible version as false so we can say update server is supported but no compatible version found
1607-
return (object) array('state' => 1, 'compatibleVersion' => false);
1608-
}
1599+
// Return the compatible versions
1600+
return (object) array('state' => 1, 'compatibleVersions' => $compatibleVersions);
16091601
}
16101602
}
16111603
else
16121604
{
1613-
$compatibleVersion = $this->checkCompatibility($updateSite['location'], $joomlaTargetVersion);
1605+
$compatibleVersions = $this->checkCompatibility($updateSite['location'], $joomlaTargetVersion);
16141606

1615-
if ($compatibleVersion)
1616-
{
1617-
// Return the compatible version
1618-
return (object) array('state' => 1, 'compatibleVersion' => $compatibleVersion->_data);
1619-
}
1620-
else
1621-
{
1622-
// Return the compatible version as false so we can say update server is supported but no compatible version found
1623-
return (object) array('state' => 1, 'compatibleVersion' => false);
1624-
}
1607+
// Return the compatible versions
1608+
return (object) array('state' => 1, 'compatibleVersions' => $compatibleVersions);
16251609
}
16261610
}
16271611

@@ -1735,7 +1719,7 @@ private function getCollectionDetailsUrls($updateSiteInfo, $joomlaTargetVersion)
17351719
* @param string $updateFileUrl The items update XML url.
17361720
* @param string $joomlaTargetVersion The Joomla! version to test against
17371721
*
1738-
* @return mixed An array of data items or false.
1722+
* @return array An array of strings with compatible version numbers
17391723
*
17401724
* @since 3.10.0
17411725
*/
@@ -1748,9 +1732,20 @@ private function checkCompatibility($updateFileUrl, $joomlaTargetVersion)
17481732
$update->set('jversion.full', $joomlaTargetVersion);
17491733
$update->loadFromXML($updateFileUrl, $minimumStability);
17501734

1751-
$downloadUrl = $update->get('downloadurl');
1735+
$compatibleVersions = $update->get('compatibleVersions');
1736+
1737+
// Check if old version of the updater library
1738+
if (!isset($compatibleVersions))
1739+
{
1740+
$downloadUrl = $update->get('downloadurl');
1741+
$updateVersion = $update->get('version');
1742+
1743+
return empty($downloadUrl) || empty($downloadUrl->_data) || empty($updateVersion) ? array() : array($updateVersion->_data);
1744+
}
1745+
1746+
usort($compatibleVersions, 'version_compare');
17521747

1753-
return !empty($downloadUrl) && !empty($downloadUrl->_data) ? $update->get('version') : false;
1748+
return $compatibleVersions;
17541749
}
17551750

17561751
/**

libraries/src/Updater/Update.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ class Update extends \JObject
216216
*/
217217
protected $minimum_stability = Updater::STABILITY_STABLE;
218218

219+
/**
220+
* Array with compatible versions used by the pre-update check
221+
*
222+
* @var array
223+
* @since __DEPLOY_VERSION__
224+
*/
225+
protected $compatibleVersions = array();
226+
219227
/**
220228
* Gets the reference to the current direct parent
221229
*
@@ -411,14 +419,13 @@ public function _endElement($parser, $name)
411419

412420
if ($phpMatch && $stabilityMatch && $dbMatch)
413421
{
414-
if (isset($this->latest))
422+
if (!empty($this->currentUpdate->downloadurl) && !empty($this->currentUpdate->downloadurl->_data))
415423
{
416-
if (version_compare($this->currentUpdate->version->_data, $this->latest->version->_data, '>') == 1)
417-
{
418-
$this->latest = $this->currentUpdate;
419-
}
424+
$this->compatibleVersions[] = $this->currentUpdate->version->_data;
420425
}
421-
else
426+
427+
if (!isset($this->latest)
428+
|| version_compare($this->currentUpdate->version->_data, $this->latest->version->_data, '>'))
422429
{
423430
$this->latest = $this->currentUpdate;
424431
}

0 commit comments

Comments
 (0)