Skip to content

Commit

Permalink
[5.3] Fix core update information retrieval after changing the update…
Browse files Browse the repository at this point in the history
… channel or stability options (#44954)
SniperSister authored Mar 1, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent ebaced4 commit 2c859aa
Showing 13 changed files with 205 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Add plg_extension_joomlaupdate plugin
INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES
(0, 'plg_extension_joomlaupdate', 'plugin', 'joomlaupdate', 'extension', 0, 1, 1, 0, 1, '', '', '', 0, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Add plg_extension_joomlaupdate module
INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES
(0, 'plg_extension_joomlaupdate', 'plugin', 'joomlaupdate', 'extension', 0, 1, 1, 0, 1, '', '', '', 0, 0);
Original file line number Diff line number Diff line change
@@ -76,8 +76,7 @@ public function display($cachable = false, $urlparams = false)
$state->set('log_file', $this->app->get('log_path') . '/joomla_update.php');
}

// Perform update source preference check and refresh update information.
$model->applyUpdateSite();
// Refresh update information.
$model->refreshUpdates();

// Push the model into the view (as default).
40 changes: 19 additions & 21 deletions administrator/components/com_joomlaupdate/src/Model/UpdateModel.php
Original file line number Diff line number Diff line change
@@ -85,18 +85,18 @@ public function __construct($config = [], ?MVCFactoryInterface $factory = null)
*
* @since 2.5.4
*/
public function applyUpdateSite()
public function applyUpdateSite(?string $updateSource = null, ?string $updateURL = null)
{
// Determine the intended update URL.
$params = ComponentHelper::getParams('com_joomlaupdate');
$params = ComponentHelper::getParams('com_joomlaupdate');
$updateSource = $updateSource ?: $params->get('updatesource', 'default');
$updateURL = trim($updateURL ?: $params->get('customurl', ''));

switch ($params->get('updatesource', 'default')) {
// Determine the intended update URL.
switch ($updateSource) {
case 'custom':
// "Custom"
// @todo: check if the customurl is valid and not just "not empty".
if (trim($params->get('customurl', '')) != '') {
$updateURL = trim($params->get('customurl', ''));
} else {
if ($updateURL === '') {
Factory::getApplication()->enqueueMessage(Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_CUSTOM_ERROR'), 'error');

return;
@@ -134,21 +134,19 @@ public function applyUpdateSite()
$db->setQuery($query);
$update_site = $db->loadObject();

if ($update_site->location !== $updateURL || $update_site->type !== $updateType) {
// Modify the database record.
$update_site->last_check_timestamp = 0;
$update_site->location = $updateURL;
$update_site->type = $updateType;
$db->updateObject('#__update_sites', $update_site, 'update_site_id');
// Modify the database record.
$update_site->last_check_timestamp = 0;
$update_site->location = $updateURL;
$update_site->type = $updateType;
$db->updateObject('#__update_sites', $update_site, 'update_site_id');

// Remove cached updates.
$query->clear()
->delete($db->quoteName('#__updates'))
->where($db->quoteName('extension_id') . ' = :id')
->bind(':id', $id, ParameterType::INTEGER);
$db->setQuery($query);
$db->execute();
}
// Remove cached updates.
$query->clear()
->delete($db->quoteName('#__updates'))
->where($db->quoteName('extension_id') . ' = :id')
->bind(':id', $id, ParameterType::INTEGER);
$db->setQuery($query);
$db->execute();
}

/**
7 changes: 7 additions & 0 deletions administrator/language/en-GB/plg_extension_joomlaupdate.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_EXTENSION_JOOMLAUPDATE="Extension - Joomla! Update"
PLG_EXTENSION_JOOMLAUPDATE_XML_DESCRIPTION="Purges the core updates after release channel changes."
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_EXTENSION_JOOMLAUPDATE="Extension - Joomla! Update"
PLG_EXTENSION_JOOMLAUPDATE_XML_DESCRIPTION="Purges the core updates after release channel changes."
3 changes: 2 additions & 1 deletion installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
@@ -288,7 +288,8 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
(0, 'plg_editors_tinymce', 'plugin', 'tinymce', 'editors', 0, 1, 1, 0, 1, '', '{"configuration":{"toolbars":{"2":{"toolbar1":["bold","underline","strikethrough","|","undo","redo","|","bullist","numlist","|","pastetext"]},"1":{"menu":["edit","insert","view","format","table","tools"],"toolbar1":["bold","italic","underline","strikethrough","|","alignleft","aligncenter","alignright","alignjustify","|","blocks","|","bullist","numlist","|","outdent","indent","|","undo","redo","|","link","unlink","anchor","code","|","hr","table","|","subscript","superscript","|","charmap","pastetext","preview"]},"0":{"menu":["edit","insert","view","format","table","tools"],"toolbar1":["bold","italic","underline","strikethrough","|","alignleft","aligncenter","alignright","alignjustify","|","styles","|","blocks","fontfamily","fontsize","|","searchreplace","|","bullist","numlist","|","outdent","indent","|","undo","redo","|","link","unlink","anchor","image","|","code","|","forecolor","backcolor","|","fullscreen","|","table","|","subscript","superscript","|","charmap","emoticons","media","hr","ltr","rtl","|","cut","copy","paste","pastetext","|","visualchars","visualblocks","nonbreaking","blockquote","jtemplate","|","print","preview","codesample","insertdatetime","removeformat"]}},"setoptions":{"2":{"access":["1"],"skin":"0","skin_admin":"0","mobile":"0","drag_drop":"1","path":"","entity_encoding":"raw","lang_mode":"1","text_direction":"ltr","content_css":"1","content_css_custom":"","relative_urls":"1","newlines":"0","use_config_textfilters":"0","invalid_elements":"script,applet,iframe","valid_elements":"","extended_elements":"","resizing":"1","resize_horizontal":"1","element_path":"1","wordcount":"1","image_advtab":"0","advlist":"1","autosave":"1","contextmenu":"1","custom_plugin":"","custom_button":""},"1":{"access":["6","2"],"skin":"0","skin_admin":"0","mobile":"0","drag_drop":"1","path":"","entity_encoding":"raw","lang_mode":"1","text_direction":"ltr","content_css":"1","content_css_custom":"","relative_urls":"1","newlines":"0","use_config_textfilters":"0","invalid_elements":"script,applet,iframe","valid_elements":"","extended_elements":"","resizing":"1","resize_horizontal":"1","element_path":"1","wordcount":"1","image_advtab":"0","advlist":"1","autosave":"1","contextmenu":"1","custom_plugin":"","custom_button":""},"0":{"access":["7","4","8"],"skin":"0","skin_admin":"0","mobile":"0","drag_drop":"1","path":"","entity_encoding":"raw","lang_mode":"1","text_direction":"ltr","content_css":"1","content_css_custom":"","relative_urls":"1","newlines":"0","use_config_textfilters":"0","invalid_elements":"script,applet,iframe","valid_elements":"","extended_elements":"","resizing":"1","resize_horizontal":"1","element_path":"1","wordcount":"1","image_advtab":"1","advlist":"1","autosave":"1","contextmenu":"1","custom_plugin":"","custom_button":""}}},"sets_amount":3,"html_height":"550","html_width":"750"}', '', 3, 0),
(0, 'plg_extension_finder', 'plugin', 'finder', 'extension', 0, 1, 1, 0, 1, '', '', '', 1, 0),
(0, 'plg_extension_joomla', 'plugin', 'joomla', 'extension', 0, 1, 1, 0, 1, '', '', '', 2, 0),
(0, 'plg_extension_namespacemap', 'plugin', 'namespacemap', 'extension', 0, 1, 1, 1, 1, '', '{}', '', 3, 0),
(0, 'plg_extension_joomlaupdate', 'plugin', 'joomlaupdate', 'extension', 0, 1, 1, 0, 1, '', '', '', 3, 0),
(0, 'plg_extension_namespacemap', 'plugin', 'namespacemap', 'extension', 0, 1, 1, 1, 1, '', '{}', '', 4, 0),
(0, 'plg_fields_calendar', 'plugin', 'calendar', 'fields', 0, 1, 1, 0, 1, '', '', '', 1, 0),
(0, 'plg_fields_checkboxes', 'plugin', 'checkboxes', 'fields', 0, 1, 1, 0, 1, '', '', '', 2, 0),
(0, 'plg_fields_color', 'plugin', 'color', 'fields', 0, 1, 1, 0, 1, '', '', '', 3, 0),
3 changes: 2 additions & 1 deletion installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
@@ -294,7 +294,8 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
(0, 'plg_editors_tinymce', 'plugin', 'tinymce', 'editors', 0, 1, 1, 0, 1, '', '{"configuration":{"toolbars":{"2":{"toolbar1":["bold","underline","strikethrough","|","undo","redo","|","bullist","numlist","|","pastetext"]},"1":{"menu":["edit","insert","view","format","table","tools"],"toolbar1":["bold","italic","underline","strikethrough","|","alignleft","aligncenter","alignright","alignjustify","|","blocks","|","bullist","numlist","|","outdent","indent","|","undo","redo","|","link","unlink","anchor","code","|","hr","table","|","subscript","superscript","|","charmap","pastetext","preview"]},"0":{"menu":["edit","insert","view","format","table","tools"],"toolbar1":["bold","italic","underline","strikethrough","|","alignleft","aligncenter","alignright","alignjustify","|","styles","|","blocks","fontfamily","fontsize","|","searchreplace","|","bullist","numlist","|","outdent","indent","|","undo","redo","|","link","unlink","anchor","image","|","code","|","forecolor","backcolor","|","fullscreen","|","table","|","subscript","superscript","|","charmap","emoticons","media","hr","ltr","rtl","|","cut","copy","paste","pastetext","|","visualchars","visualblocks","nonbreaking","blockquote","jtemplate","|","print","preview","codesample","insertdatetime","removeformat"]}},"setoptions":{"2":{"access":["1"],"skin":"0","skin_admin":"0","mobile":"0","drag_drop":"1","path":"","entity_encoding":"raw","lang_mode":"1","text_direction":"ltr","content_css":"1","content_css_custom":"","relative_urls":"1","newlines":"0","use_config_textfilters":"0","invalid_elements":"script,applet,iframe","valid_elements":"","extended_elements":"","resizing":"1","resize_horizontal":"1","element_path":"1","wordcount":"1","image_advtab":"0","advlist":"1","autosave":"1","contextmenu":"1","custom_plugin":"","custom_button":""},"1":{"access":["6","2"],"skin":"0","skin_admin":"0","mobile":"0","drag_drop":"1","path":"","entity_encoding":"raw","lang_mode":"1","text_direction":"ltr","content_css":"1","content_css_custom":"","relative_urls":"1","newlines":"0","use_config_textfilters":"0","invalid_elements":"script,applet,iframe","valid_elements":"","extended_elements":"","resizing":"1","resize_horizontal":"1","element_path":"1","wordcount":"1","image_advtab":"0","advlist":"1","autosave":"1","contextmenu":"1","custom_plugin":"","custom_button":""},"0":{"access":["7","4","8"],"skin":"0","skin_admin":"0","mobile":"0","drag_drop":"1","path":"","entity_encoding":"raw","lang_mode":"1","text_direction":"ltr","content_css":"1","content_css_custom":"","relative_urls":"1","newlines":"0","use_config_textfilters":"0","invalid_elements":"script,applet,iframe","valid_elements":"","extended_elements":"","resizing":"1","resize_horizontal":"1","element_path":"1","wordcount":"1","image_advtab":"1","advlist":"1","autosave":"1","contextmenu":"1","custom_plugin":"","custom_button":""}}},"sets_amount":3,"html_height":"550","html_width":"750"}', '', 3, 0),
(0, 'plg_extension_finder', 'plugin', 'finder', 'extension', 0, 1, 1, 0, 1, '', '', '', 1, 0),
(0, 'plg_extension_joomla', 'plugin', 'joomla', 'extension', 0, 1, 1, 0, 1, '', '', '', 2, 0),
(0, 'plg_extension_namespacemap', 'plugin', 'namespacemap', 'extension', 0, 1, 1, 1, 1, '', '{}', '', 3, 0),
(0, 'plg_extension_joomlaupdate', 'plugin', 'joomlaupdate', 'extension', 0, 1, 1, 0, 1, '', '', '', 3, 0),
(0, 'plg_extension_namespacemap', 'plugin', 'namespacemap', 'extension', 0, 1, 1, 1, 1, '', '{}', '', 4, 0),
(0, 'plg_fields_calendar', 'plugin', 'calendar', 'fields', 0, 1, 1, 0, 1, '', '', '', 1, 0),
(0, 'plg_fields_checkboxes', 'plugin', 'checkboxes', 'fields', 0, 1, 1, 0, 1, '', '', '', 2, 0),
(0, 'plg_fields_color', 'plugin', 'color', 'fields', 0, 1, 1, 0, 1, '', '', '', 3, 0),
2 changes: 1 addition & 1 deletion libraries/src/Console/CoreUpdateChannelCommand.php
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in
/** @var UpdateModel $updatemodel */
$app = $this->getApplication();
$updatemodel = $app->bootComponent('com_joomlaupdate')->getMVCFactory($app)->createModel('Update', 'Administrator');
$updatemodel->applyUpdateSite();
$updatemodel->applyUpdateSite($channel);

if ($channel == 'custom') {
$symfonyStyle->success('The update channel for this site has been set to the custom url "' . $params->get('customurl') . '".');
1 change: 1 addition & 0 deletions libraries/src/Extension/ExtensionHelper.php
Original file line number Diff line number Diff line change
@@ -206,6 +206,7 @@ class ExtensionHelper

// Core plugin extensions - extension
['plugin', 'joomla', 'extension', 0],
['plugin', 'joomlaupdate', 'extension', 0],
['plugin', 'namespacemap', 'extension', 0],
['plugin', 'finder', 'extension', 0],

21 changes: 21 additions & 0 deletions plugins/extension/joomlaupdate/joomlaupdate.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="extension" method="upgrade">
<name>plg_extension_joomlaupdate</name>
<author>Joomla! Project</author>
<creationDate>2025-02</creationDate>
<copyright>(C) 2025 Open Source Matters, Inc.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>1.0.0</version>
<description>PLG_EXTENSION_JOOMLAUPDATE_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\Extension\Joomlaupdate</namespace>
<files>
<folder plugin="joomlaupdate">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_extension_joomlaupdate.ini</language>
<language tag="en-GB">language/en-GB/plg_extension_joomlaupdate.sys.ini</language>
</languages>
</extension>
47 changes: 47 additions & 0 deletions plugins/extension/joomlaupdate/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Extension.joomla
*
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

\defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\Extension\Joomlaupdate\Extension\Joomlaupdate;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container)
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new Joomlaupdate(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('extension', 'joomlaupdate')
);

$plugin->setApplication(Factory::getApplication());

return $plugin;
}
);
}
};
91 changes: 91 additions & 0 deletions plugins/extension/joomlaupdate/src/Extension/Joomlaupdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Extension.joomla
*
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\Plugin\Extension\Joomlaupdate\Extension;

use Joomla\CMS\Event\Model\AfterSaveEvent;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel;
use Joomla\Event\SubscriberInterface;
use Joomla\Registry\Registry;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* The extension plugin for com_joomlaupdate
*
* @since __DEPLOY_VERSION__
*/
final class Joomlaupdate extends CMSPlugin implements SubscriberInterface
{
/**
* Load the language file on instantiation.
*
* @var boolean
*
* @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;

/**
* Returns an array of events this subscriber will listen to.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
return [
'onExtensionAfterSave' => 'onExtensionAfterSave',
];
}

/**
* After update of an extension
*
* @param AfterSaveEvent $event Event instance.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function onExtensionAfterSave(AfterSaveEvent $event): void
{
$context = $event->getContext();
$item = $event->getItem();

if ($context !== 'com_config.component') {
return;
}

if ($item->element !== 'com_joomlaupdate') {
return;
}

/** @var UpdateModel $updateModel */
$updateModel = $this->getApplication()->bootComponent('com_joomlaupdate')
->getMVCFactory()->createModel('Update', 'Administrator', ['ignore_request' => true]);

if (!$updateModel) {
return;
}

$params = new Registry($item->params);

// Apply updated config
$updateModel->applyUpdateSite(
$params->get('updatesource'),
$params->get('customurl'),
);
}
}

0 comments on commit 2c859aa

Please sign in to comment.