Skip to content

Commit 5bcc433

Browse files
authored
[5.1] Use update channel the correct way (#43190)
* Show updates only when version fits
1 parent 38b6c68 commit 5bcc433

File tree

6 files changed

+40
-2
lines changed

6 files changed

+40
-2
lines changed

libraries/src/TUF/DatabaseStorage.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
/**
2222
* @since 5.1.0
23+
*
24+
* @internal Currently this class is only used for Joomla! updates and will be extended in the future to support 3rd party updates
25+
* Don't extend this class in your own code, it is subject to change without notice.
2326
*/
2427
class DatabaseStorage extends StorageBase
2528
{

libraries/src/TUF/HttpLoader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
/**
1919
* @since 5.1.0
20+
*
21+
* @internal Currently this class is only used for Joomla! updates and will be extended in the future to support 3rd party updates
22+
* Don't extend this class in your own code, it is subject to change without notice.
2023
*/
2124
class HttpLoader implements LoaderInterface
2225
{

libraries/src/TUF/TufFetcher.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
/**
3030
* @since 5.1.0
31+
*
32+
* @internal Currently this class is only used for Joomla! updates and will be extended in the future to support 3rd party updates
33+
* Don't extend this class in your own code, it is subject to change without notice.
3134
*/
3235
class TufFetcher
3336
{

libraries/src/Updater/Adapter/TufAdapter.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
* TUF Update Adapter Class
3030
*
3131
* @since 5.1.0
32+
*
33+
* @internal Currently this class is only used for Joomla! updates and will be extended in the future to support 3rd party updates
34+
* Don't extend this class in your own code, it is subject to change without notice.
3235
*/
3336
class TufAdapter extends UpdateAdapter
3437
{

libraries/src/Updater/ConstraintChecker.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
\defined('_JEXEC') or die;
1414
// phpcs:enable PSR1.Files.SideEffects
1515

16+
use Joomla\CMS\Component\ComponentHelper;
1617
use Joomla\CMS\Factory;
1718
use Joomla\CMS\Filter\InputFilter;
1819
use Joomla\CMS\Version;
@@ -21,6 +22,8 @@
2122
* ConstraintChecker Class
2223
*
2324
* @since 5.1.0
25+
*
26+
* @internal Currently this class is only used for Joomla! updates and will be extended in the future to support 3rd party updates
2427
*/
2528
class ConstraintChecker
2629
{
@@ -34,16 +37,33 @@ class ConstraintChecker
3437
*/
3538
protected \stdClass $failedEnvironmentConstraints;
3639

40+
/**
41+
* The channel to check the contraints against
42+
*
43+
* @var string
44+
*/
45+
protected $channel;
46+
3747
/**
3848
* Constructor, used to populate the failed
3949
*
50+
* @param string|null $channel The channel to be used for updating
51+
*
4052
* @return void
4153
*
4254
* @since 5.1.0
4355
*/
44-
public function __construct()
56+
public function __construct($channel = null)
4557
{
4658
$this->failedEnvironmentConstraints = new \stdClass();
59+
60+
if (!isset($channel)) {
61+
$params = ComponentHelper::getParams('com_joomlaupdate');
62+
63+
$channel = (Version::MAJOR_VERSION + ($params->get('updatesource', 'default') == 'next' ? 1 : 0)) . '.x';
64+
}
65+
66+
$this->channel = $channel;
4767
}
4868

4969
/**
@@ -68,6 +88,11 @@ public function check(array $candidate, $minimumStability = Updater::STABILITY_S
6888
return false;
6989
}
7090

91+
// Check channel
92+
if (isset($candidate['channel']) && $candidate['channel'] !== $this->channel) {
93+
return false;
94+
}
95+
7196
$result = true;
7297

7398
// Check php_minimum, assume true when not set

tests/Unit/Libraries/Cms/Updater/ConstraintCheckerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Joomla\CMS\Factory;
1414
use Joomla\CMS\Updater\ConstraintChecker;
15+
use Joomla\CMS\Version;
1516
use Joomla\Database\DatabaseDriver;
1617
use Joomla\Tests\Unit\UnitTestCase;
1718

@@ -40,7 +41,7 @@ class ConstraintCheckerTest extends UnitTestCase
4041
*/
4142
protected function setUp(): void
4243
{
43-
$this->checker = new ConstraintChecker();
44+
$this->checker = new ConstraintChecker(Version::MAJOR_VERSION . '.x');
4445
}
4546

4647
/**

0 commit comments

Comments
 (0)