Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] Add update channel reset to Joomla Update Component #43717

Open
wants to merge 9 commits into
base: 5.1-dev
Choose a base branch
from
Next Next commit
Add installer script to com_joomlaupdate
Add installer script to com_joomlaupdate for reset of the core update channel from "next" to "default" when updating the component.
  • Loading branch information
richard67 committed Jun 22, 2024
commit 5333db24e3214764742d1b04f9b254e6ad29cb69
5 changes: 3 additions & 2 deletions administrator/components/com_joomlaupdate/joomlaupdate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
<extension type="component" method="upgrade">
<name>com_joomlaupdate</name>
<author>Joomla! Project</author>
<creationDate>2021-08</creationDate>
<creationDate>2024-06</creationDate>
<copyright>(C) 2012 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>4.0.3</version>
<version>5.1.2</version>
<description>COM_JOOMLAUPDATE_XML_DESCRIPTION</description>
<scriptfile>admin/script.php</scriptfile>
<namespace path="src">Joomla\Component\Joomlaupdate</namespace>
<media destination="com_joomlaupdate" folder="media">
<folder>js</folder>
Expand Down
97 changes: 97 additions & 0 deletions administrator/components/com_joomlaupdate/script.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_joomlaupdate
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

use Joomla\CMS\Application\AdministratorApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Installer\InstallerScriptInterface;
use Joomla\CMS\Language\Text;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;

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

return new class () implements ServiceProviderInterface {
public function register(Container $container)
{
$container->set(
InstallerScriptInterface::class,
new class (
$container->get(AdministratorApplication::class),
$container->get(DatabaseInterface::class)
) implements InstallerScriptInterface {
private AdministratorApplication $app;
private DatabaseInterface $db;

public function __construct(AdministratorApplication $app, DatabaseInterface $db)
{
$this->app = $app;
$this->db = $db;
}

public function update(InstallerAdapter $parent): bool
{
// Reset update source from "next" to "default"
try {
$this->resetUpdateSource();
} catch (\Throwable $e) {
enqueueMessage(
Text::sprintf(
'COM_JOOMLAUPDATE_UPDATE_CHANGE_UPDATE_SOURCE_FAILED',
Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_NEXT'),
Text::_('COM_JOOMLAUPDATE_CONFIG_UPDATESOURCE_DEFAULT')
),
'warning'
);
}

return true;
}

/**
* Reset update source from "next" to "default"
*
* @return void
*
* @since __DEPLOY_VERSION__
* @throws \RuntimeException
*/
private function resetUpdateSource()
{
// Get current update source
$params = ComponentHelper::getParams('com_joomlaupdate');

// Do nothing if not "next"
if ($params->get('updatesource', 'default') !== 'next') {
return;
}

$params->set('updatesource', 'default');

$params = $params->toString();
$query = $this->db->getQuery(true)
->update($this->db->quoteName('#__extensions'))
->set($this->db->quoteName('params') . ' = :params')
->where($this->db->quoteName('type') . ' = ' . $this->db->quote('component'))
->where($this->db->quoteName('element') . ' = ' . $this->db->quote('com_joomlaupdate'))
->bind(':params', $params);

$this->db->setQuery($query);
$this->db->execute();
}
}
);
}
};
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 @@ -69,6 +69,7 @@ COM_JOOMLAUPDATE_SELF_EMPTYSTATE_CONTENT="You must update this component first b
COM_JOOMLAUPDATE_SELF_EMPTYSTATE_TITLE="A new version of the Joomla Update Component is available"
COM_JOOMLAUPDATE_SYSTEM_CHECK="System Check"
COM_JOOMLAUPDATE_TOOLBAR_CHECK="Check for Updates"
COM_JOOMLAUPDATE_UPDATE_CHANGE_UPDATE_SOURCE_FAILED="Failed to change the update channel from \"%1$s\" to \"%2$s\". Please change it in the Joomla Update Component's options so you don't miss future updates for your Joomla version."
COM_JOOMLAUPDATE_UPDATE_CHECK="Update Check"
COM_JOOMLAUPDATE_UPDATE_CONFIRM_BACKUP="I'm aware that a backup before any update is highly recommended."
COM_JOOMLAUPDATE_UPDATE_EMPTYSTATE_TITLE="Update your site to \"Joomla! %s\""
Expand Down