Skip to content

Commit

Permalink
[5.1] Merge update parameter and improve contrain checker (#43147)
Browse files Browse the repository at this point in the history
* Update ConstraintChecker.php
* Update UpdateModel.php
* [CMS PR 43147] Use the right minimum stability (#133)
* Deprecate language string
* Validate customurl for URL type
* Remove filter as we only want valid URLs
  • Loading branch information
bembelimen authored Mar 27, 2024
1 parent b421b33 commit a9950a7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 41 deletions.
5 changes: 2 additions & 3 deletions administrator/components/com_joomlaupdate/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<!-- All invalid/unsupported/obsolete options equated to default in code with 3.4.0 -->
<option value="default">COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT</option>
<option value="next">COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT</option>
<option value="testing">COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_TESTING</option>
<option value="custom">COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_CUSTOM</option>
</field>

Expand All @@ -29,7 +28,6 @@
label="COM_JOOMLAUPDATE_MINIMUM_STABILITY_LABEL"
description="COM_JOOMLAUPDATE_MINIMUM_STABILITY_DESC"
default="4"
showon="updatesource:testing[OR]updatesource:custom"
validate="options"
>
<option value="0">COM_JOOMLAUPDATE_MINIMUM_STABILITY_DEV</option>
Expand All @@ -41,11 +39,12 @@

<field
name="customurl"
type="text"
type="url"
label="COM_JOOMLAUPDATE_CONFIG_CUSTOMURL_LABEL"
default=""
length="50"
showon="updatesource:custom"
validate="url"
/>

<field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ public function applyUpdateSite()
$params = ComponentHelper::getParams('com_joomlaupdate');

switch ($params->get('updatesource', 'default')) {
case 'testing':
// "Testing"
$updateURL = 'https://update.joomla.org/core/test/list_test.xml';
break;

case 'custom':
// "Custom"
// @todo: check if the customurl is valid and not just "not empty".
Expand All @@ -115,6 +110,7 @@ public function applyUpdateSite()
* case 'lts':
* case 'sts': (It's shown as "Default" because that option does not exist any more)
* case 'nochange':
* case 'testing':
*/
$updateURL = 'https://update.joomla.org/cms/';
}
Expand Down Expand Up @@ -173,13 +169,9 @@ public function refreshUpdates($force = false)
}

$updater = Updater::getInstance();
$minimumStability = Updater::STABILITY_STABLE;
$comJoomlaupdateParams = ComponentHelper::getParams('com_joomlaupdate');

if (\in_array($comJoomlaupdateParams->get('updatesource', 'default'), ['testing', 'custom'])) {
$minimumStability = $comJoomlaupdateParams->get('minimum_stability', Updater::STABILITY_STABLE);
}

$minimumStability = $comJoomlaupdateParams->get('minimum_stability', Updater::STABILITY_STABLE);
$reflection = new \ReflectionObject($updater);
$reflectionMethod = $reflection->getMethod('findUpdates');
$methodParameters = $reflectionMethod->getParameters();
Expand Down Expand Up @@ -296,13 +288,9 @@ public function getUpdateInformation()
return $this->updateInformation;
}

$minimumStability = Updater::STABILITY_STABLE;
$comJoomlaupdateParams = ComponentHelper::getParams('com_joomlaupdate');
$channel = $comJoomlaupdateParams->get('updatesource', 'default');

if (\in_array($channel, ['testing', 'custom'])) {
$minimumStability = $comJoomlaupdateParams->get('minimum_stability', Updater::STABILITY_STABLE);
}
$minimumStability = $comJoomlaupdateParams->get('minimum_stability', Updater::STABILITY_STABLE);

$update = new Update();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,6 @@ public function display($tpl = null)
$this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT');
break;

case 'testing':
// "Testing"
$this->langKey = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_TESTING';
$this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_TESTING');
break;

case 'custom':
// "Custom"
$this->langKey = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_CUSTOM';
Expand All @@ -259,6 +253,7 @@ public function display($tpl = null)
* case 'sts':
* case 'lts':
* case 'nochange':
* case 'testing':
*/
$this->langKey = 'COM_JOOMLAUPDATE_VIEW_DEFAULT_UPDATES_INFO_DEFAULT';
$this->updateSourceKey = Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT');
Expand Down
1 change: 1 addition & 0 deletions administrator/language/en-GB/com_joomlaupdate.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_CUSTOM_ERROR="The custom URL field is empty
COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT="Default"
COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_LABEL="Update Channel"
COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT="Joomla Next"
; Deprecated, will be removed with 6.0
COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_TESTING="Testing"
COM_JOOMLAUPDATE_CONFIG_VERSIONCHECK_DESC="Shows the checkbox in the pre–update check if any of the extensions installed on your site is potentially incompatible with the version of Joomla you are upgrading to. Note: the checkbox is displayed when upgrading to a new Joomla version family (minor or major version)."
COM_JOOMLAUPDATE_CONFIG_VERSIONCHECK_LABEL="Potentially incompatible extensions checkbox"
Expand Down
7 changes: 4 additions & 3 deletions libraries/src/Updater/Adapter/TufAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Joomla\CMS\TUF\TufFetcher;
use Joomla\CMS\Updater\ConstraintChecker;
use Joomla\CMS\Updater\UpdateAdapter;
use Joomla\CMS\Updater\Updater;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Tuf\Exception\MetadataException;

Expand Down Expand Up @@ -81,11 +82,11 @@ public function getUpdateTargets($options)

$metaData = json_decode((string) $metaData, true);

if (!isset($metaData["signed"]["targets"])) {
if (!isset($metaData['signed']['targets'])) {
return false;
}

foreach ($metaData["signed"]["targets"] as $filename => $target) {
foreach ($metaData['signed']['targets'] as $filename => $target) {
$version = $this->processTufTarget($filename, $target);

if (!$version) {
Expand All @@ -108,7 +109,7 @@ public function getUpdateTargets($options)
// Return the version as a match if either all constraints are matched
// or "only" env related constraints fail - the later one is the existing behavior of the XML updater
if (
$constraintChecker->check($version) === true
$constraintChecker->check($version, $options['minimum_stability'] ?? Updater::STABILITY_STABLE) === true
|| !empty((array) $constraintChecker->getFailedEnvironmentConstraints())
) {
return [$version];
Expand Down
21 changes: 8 additions & 13 deletions libraries/src/Updater/ConstraintChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Version;
Expand Down Expand Up @@ -50,13 +49,14 @@ public function __construct()
/**
* Checks whether the passed constraints are matched
*
* @param array $candidate The provided constraints to be checked
* @param array $candidate The provided constraints to be checked
* @param int $minimumStability The minimum stability required for updating
*
* @return boolean
*
* @since 5.1.0
*/
public function check(array $candidate)
public function check(array $candidate, $minimumStability = Updater::STABILITY_STABLE)
{
if (!isset($candidate['targetplatform'])) {
// targetplatform is required
Expand Down Expand Up @@ -89,7 +89,7 @@ public function check(array $candidate)
// Check stability, assume true when not set
if (
isset($candidate['stability'])
&& !$this->checkStability($candidate['stability'])
&& !$this->checkStability($candidate['stability'], $minimumStability)
) {
$result = false;
}
Expand Down Expand Up @@ -208,23 +208,18 @@ protected function checkSupportedDatabases(array $supportedDatabases)
/**
* Check the stability
*
* @param string $stability Stability to check
* @param string $stability Stability to check
* @param int $minimumStability The minimum stability required for updating
*
* @return boolean
*
* @since 5.1.0
*/
protected function checkStability(string $stability)
protected function checkStability(string $stability, $minimumStability = Updater::STABILITY_STABLE)
{
$minimumStability = ComponentHelper::getParams('com_installer')->get('minimum_stability', Updater::STABILITY_STABLE);

$stabilityInt = $this->stabilityToInteger($stability);

if (($stabilityInt < $minimumStability)) {
$this->failedEnvironmentConstraints->stability = new \stdClass();
$this->failedEnvironmentConstraints->stability->required = $stability;
$this->failedEnvironmentConstraints->stability->used = $minimumStability;

if ($stabilityInt < $minimumStability) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Updater/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public function loadFromTuf(TufMetadata $metadataTable, string $url, $minimumSta
continue;
}

if (!$constraintChecker->check($target['custom'])) {
if (!$constraintChecker->check($target['custom'], $minimumStability)) {
$this->otherUpdateInfo = $constraintChecker->getFailedEnvironmentConstraints();

continue;
Expand Down

0 comments on commit a9950a7

Please sign in to comment.