Skip to content

Commit 123b0e2

Browse files
authored
[5.4] Improve autoupdate UX for local site (#45547)
1 parent e84a232 commit 123b0e2

File tree

13 files changed

+100
-27
lines changed

13 files changed

+100
-27
lines changed

administrator/components/com_joomlaupdate/src/Controller/UpdateController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ public function healthstatus()
747747

748748
$result = [
749749
'active' => true,
750-
'healthy' => $result,
750+
'healthy' => $result->value,
751751
];
752752

753753
echo json_encode($result);
@@ -764,7 +764,7 @@ public function healthstatus()
764764
&& $params->get('updatesource', 'default') === 'default'
765765
&& (int) $params->get('minimum_stability', Updater::STABILITY_STABLE) === Updater::STABILITY_STABLE
766766
),
767-
'healthy' => $lastCheck !== false && $lastCheck->diff(new \DateTime())->days < 4,
767+
'healthy' => (int) ($lastCheck !== false && $lastCheck->diff(new \DateTime())->days < 4),
768768
];
769769

770770
echo json_encode($result);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.Administrator
5+
* @subpackage com_joomlaupdate
6+
*
7+
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
namespace Joomla\Component\Joomlaupdate\Administrator\Enum;
12+
13+
// phpcs:disable PSR1.Files.SideEffects
14+
\defined('_JEXEC') or die;
15+
// phpcs:enable PSR1.Files.SideEffects
16+
17+
/**
18+
* Autoupdate State Enum
19+
*/
20+
enum AutoupdateRegisterResultState: int
21+
{
22+
case Failed = -1;
23+
case Unavailable = 0;
24+
case Success = 1;
25+
}

administrator/components/com_joomlaupdate/src/Model/UpdateModel.php

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Joomla\CMS\Uri\Uri;
3434
use Joomla\CMS\User\UserHelper;
3535
use Joomla\CMS\Version;
36+
use Joomla\Component\Joomlaupdate\Administrator\Enum\AutoupdateRegisterResultState;
3637
use Joomla\Component\Joomlaupdate\Administrator\Enum\AutoupdateRegisterState;
3738
use Joomla\Database\ParameterType;
3839
use Joomla\Filesystem\Exception\FilesystemException;
@@ -548,17 +549,18 @@ public function prepareAutoUpdate(string $targetVersion): array
548549
return [
549550
'password' => $app->getUserState('com_joomlaupdate.password'),
550551
'filesize' => $app->getUserState('com_joomlaupdate.filesize'),
552+
'filename' => $app->getUserState('com_joomlaupdate.file'),
551553
];
552554
}
553555

554556
/**
555557
* Change the registration state of a site in the update service
556558
*
557-
* @return bool
559+
* @return AutoupdateRegisterResultState
558560
*
559561
* @since 5.4.0
560562
*/
561-
public function changeAutoUpdateRegistration(AutoupdateRegisterState $targetState)
563+
public function changeAutoUpdateRegistration(AutoupdateRegisterState $targetState): AutoupdateRegisterResultState
562564
{
563565
// Purge cache - this makes sure that the changed status will already be available if the health check is performed
564566
$this->cleanCache('_system');
@@ -583,47 +585,82 @@ public function changeAutoUpdateRegistration(AutoupdateRegisterState $targetStat
583585
} catch (\RuntimeException $e) {
584586
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
585587

586-
return false;
588+
return AutoupdateRegisterResultState::Failed;
587589
}
588590

589591
// Decode response
590592
$result = json_decode((string)$response->getBody(), true);
591593

592-
// Handle non-success response
594+
// Handle validation issue
595+
if ($response->getStatusCode() === 422) {
596+
// Append message
597+
Factory::getApplication()->enqueueMessage(
598+
Text::sprintf(
599+
'COM_JOOMLAUPDATE_AUTOUPDATE_REGISTER_UNAVAILABLE',
600+
),
601+
'warning'
602+
);
603+
604+
$this->updateAutoUpdateParams(
605+
AutoupdateRegisterState::Unsubscribed,
606+
false
607+
);
608+
609+
return AutoupdateRegisterResultState::Unavailable;
610+
}
611+
612+
// Handle other non-success response
593613
if ($response->getStatusCode() !== 200) {
594614
Factory::getApplication()->enqueueMessage(
595615
Text::sprintf(
596616
'COM_JOOMLAUPDATE_AUTOUPDATE_REGISTER_ERROR',
597-
$result['message'],
598-
$result['status']
617+
$result['message'] ?: '',
618+
$result['status'] ?: ''
599619
),
600620
'error'
601621
);
602622

603-
return false;
623+
$this->updateAutoUpdateParams(
624+
AutoupdateRegisterState::Unsubscribed,
625+
false
626+
);
627+
628+
return AutoupdateRegisterResultState::Failed;
604629
}
605630

631+
$this->updateAutoUpdateParams(
632+
($targetState === AutoupdateRegisterState::Subscribe)
633+
? AutoupdateRegisterState::Subscribed
634+
: AutoupdateRegisterState::Unsubscribed,
635+
($targetState === AutoupdateRegisterState::Unsubscribed)
636+
);
637+
638+
return AutoupdateRegisterResultState::Success;
639+
}
640+
641+
/**
642+
* Update the autoupdate activation and registration states
643+
*
644+
* @since __DEPLOY_VERSION__
645+
*/
646+
protected function updateAutoUpdateParams(AutoupdateRegisterState $registrationState, bool $enableUpdate): void
647+
{
606648
// Get extension row
607649
$extension = new Extension($this->getDatabase());
608650
$extensionId = $extension->find(['element' => 'com_joomlaupdate']);
609651
$extension->load($extensionId);
610652

611653
// Set new update registration state
612654
$params = new Registry($extension->params);
613-
$params->set(
614-
'autoupdate_status',
615-
($targetState === AutoupdateRegisterState::Subscribe)
616-
? AutoupdateRegisterState::Subscribed->value
617-
: AutoupdateRegisterState::Unsubscribed->value
618-
);
655+
656+
$params->set('autoupdate_status', $registrationState->value);
657+
$params->set('autoupdate', (int) $enableUpdate);
619658

620659
$extension->params = $params->toString();
621660

622661
if (!$extension->store()) {
623662
throw new \RuntimeException($extension->getError());
624663
}
625-
626-
return true;
627664
}
628665

629666
/**

administrator/language/en-GB/com_joomlaupdate.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
COM_JOOMLAUPDATE_AUTOUPDATE_REGISTER_ERROR="Error while registering to automated update service: %s (%d)."
77
COM_JOOMLAUPDATE_AUTOUPDATE_REGISTER_SUCCESS="Registered to automated update service."
8+
COM_JOOMLAUPDATE_AUTOUPDATE_REGISTER_UNAVAILABLE="The automated update service is unavailable for your site as it's not accessible from the internet. Automated updates have been disabled."
89
COM_JOOMLAUPDATE_AUTOUPDATE_UNREGISTER_ERROR="Error while unregistering from automated update service: %s (%d)."
910
COM_JOOMLAUPDATE_AUTOUPDATE_UNREGISTER_SUCCESS="Unregistered from automated update service."
1011
COM_JOOMLAUPDATE_CAPTIVE_HEADLINE="Confirm your credentials"
1112
COM_JOOMLAUPDATE_CHECKED_UPDATES="Checked for updates."
1213
COM_JOOMLAUPDATE_CONFIG_AUTOMATED_UPDATES_DISABLED_LABEL="<span class=\"fa-fw me-2 fa fa-info-circle\"></span>Automated updates are only supported for the \"default\" channel and \"Minimum Stability\" \"Stable\"."
13-
COM_JOOMLAUPDATE_CONFIG_AUTOMATED_UPDATES_DESC="Automated updates are only available for sites that are publicly accessible on the internet. If your site is behind a firewall or not publicly accessible, such as a local test environment, you will need to update manually."
14+
COM_JOOMLAUPDATE_CONFIG_AUTOMATED_UPDATES_DESC="Automated updates are only available for sites that are publicly accessible on the internet. If your site is behind a firewall or not publicly accessible, such as a local test environment, you will need to update manually.<br><br><strong>Please note:</strong> enabling Automated Updates will register your site at the respective service provided by the Joomla! project.<br>The registration allows the Joomla project to access information about your site and server environment, specifically Site Url, PHP version, Database type and version, CMS version and Server OS type and version.<br>This information is only used to improve the service."
1415
COM_JOOMLAUPDATE_CONFIG_AUTOMATED_UPDATES_LABEL="Automated Updates"
1516
COM_JOOMLAUPDATE_CONFIG_AUTOUPDATE_DESC="Automatically update Joomla to the latest version when it is available."
1617
COM_JOOMLAUPDATE_CONFIG_AUTOUPDATE_LABEL="Automated Update"

administrator/language/en-GB/guidedtours.joomla_whatsnew_5_4.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
; License GNU General Public License version 2 or later; see LICENSE.txt
44
; Note : All ini files need to be saved as UTF-8
55

6-
COM_GUIDEDTOURS_TOUR_WHATSNEW_5_4_DESCRIPTION="<h1 class=\"fw-medium\">Welcome to Joomla 5.4!</h1><div class=\"row align-items-center border-top border-1 pt-4\"><div class=\"col-md-6 col-lg-5 text-center text-md-start mb-3 mb-md-0\"><img class=\"img-fluid\" src=\"media/com_guidedtours/images/5_4/automated-updates.jpg\" alt=\"Display the backend dashboard notification where you can see the new automated updates icon to enable automated updates\" width=\"774\" height=\"281\"></div><div class=\"col-md-6 col-lg-7 mb-3\"><h2 class=\"mb-3\">Automated Updates are here!</h2><p>Joomla! 5.4 now supports automated updates for better security and performance.</p><p><a href=\"index.php?option=com_config&view=component&component=com_joomlaupdate#automated-updates\" class=\"btn btn-warning\">Enable your automated updates now</a></p><p><strong>Stay safe and secure!</strong></p></div></div>"
6+
COM_GUIDEDTOURS_TOUR_WHATSNEW_5_4_DESCRIPTION="<h1 class=\"fw-medium\">Welcome to Joomla 5.4!</h1><div class=\"row align-items-center border-top border-1 pt-4\"><div class=\"col-md-6 col-lg-5 text-center text-md-start mb-3 mb-md-0\"><img class=\"img-fluid\" src=\"media/com_guidedtours/images/5_4/automated-updates.jpg\" alt=\"Display the backend dashboard notification where you can see the new automated updates icon to enable automated updates\" width=\"774\" height=\"281\"></div><div class=\"col-md-6 col-lg-7 mb-3\"><h2 class=\"mb-3\">Automated Updates are here!</h2><p>Joomla! 5.4 now supports automated updates for better security and performance.</p><p><strong>Stay safe and secure!</strong></p></div></div>"
77
COM_GUIDEDTOURS_TOUR_WHATSNEW_5_4_TITLE="What’s New in Joomla 5.4!"

administrator/language/en-GB/plg_quickicon_autoupdate.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ PLG_QUICKICON_AUTOUPDATE_GROUP_DESC="The group of this plugin (this value is com
1111
PLG_QUICKICON_AUTOUPDATE_GROUP_LABEL="Group"
1212
PLG_QUICKICON_AUTOUPDATE_OK="Automated Updates are enabled."
1313
PLG_QUICKICON_AUTOUPDATE_OUTDATED="Automated Updates connection broken."
14+
PLG_QUICKICON_AUTOUPDATE_UNAVAILABLE="Automated Updates unavailable."
1415
PLG_QUICKICON_AUTOUPDATE_XML_DESCRIPTION="Checks the health status of automated updates and notifies you when you visit the Home Dashboard page."

api/components/com_joomlaupdate/src/Controller/UpdatesController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ public function finalizeUpdate()
9696
{
9797
$this->validateUpdateToken();
9898

99-
$fromVersion = $this->input->json->getString('fromVersion', null);
99+
$fromVersion = $this->input->json->getString('fromVersion', null);
100+
$updateFileName = $this->input->json->getString('updateFileName', null);
100101

101102
$view = $this->prepareView();
102103

103-
$view->finalizeUpdate($fromVersion);
104+
$view->finalizeUpdate($fromVersion, $updateFileName);
104105

105106
return $this;
106107
}

api/components/com_joomlaupdate/src/View/Updates/JsonapiView.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,22 @@ public function prepareUpdate(string $targetVersion): string
9898
* Run the finalize update steps
9999
*
100100
* @param string $fromVersion The from version
101+
* @param string $updateFileName The name of the update file
101102
*
102103
* @return string The rendered data
103104
*
104105
* @since 5.4.0
105106
*/
106-
public function finalizeUpdate($fromVersion)
107+
public function finalizeUpdate($fromVersion, $updateFileName)
107108
{
108109
/**
109110
* @var UpdateModel $model
110111
*/
111112
$model = $this->getModel();
112113

113-
// Write old version to state for usage in model
114+
// Write old version and filename to state for usage in model
114115
Factory::getApplication()->setUserState('com_joomlaupdate.oldversion', $fromVersion);
116+
Factory::getApplication()->setUserState('com_joomlaupdate.file', $updateFileName);
115117

116118
try {
117119
// Perform the finalization action

build/media_source/plg_quickicon_autoupdate/js/healthcheck.es6.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ if (Joomla && Joomla.getOptions('js-auto-update')) {
3535
// Not active
3636
if (!healthStatus.active) {
3737
update('warning', Joomla.Text._('PLG_QUICKICON_AUTOUPDATE_DISABLED'));
38-
} else if (!healthStatus.healthy) {
38+
} else if (healthStatus.healthy === -1) {
3939
update('danger', Joomla.Text._('PLG_QUICKICON_AUTOUPDATE_OUTDATED'));
40+
} else if (healthStatus.healthy === 0) {
41+
update('warning', Joomla.Text._('PLG_QUICKICON_AUTOUPDATE_UNAVAILABLE'));
4042
} else {
4143
update('success', Joomla.Text._('PLG_QUICKICON_AUTOUPDATE_OK'));
4244
}

libraries/src/Console/AutomatedUpdatesRegisterCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Joomla\CMS\Console;
1111

1212
use Joomla\CMS\Application\ConsoleApplication;
13+
use Joomla\Component\Joomlaupdate\Administrator\Enum\AutoupdateRegisterResultState;
1314
use Joomla\Component\Joomlaupdate\Administrator\Enum\AutoupdateRegisterState;
1415
use Joomla\Component\Joomlaupdate\Administrator\Model\UpdateModel;
1516
use Joomla\Console\Command\AbstractCommand;
@@ -126,7 +127,7 @@ protected function doExecute(InputInterface $input, OutputInterface $output): in
126127

127128
$result = $updateModel->changeAutoUpdateRegistration(AutoupdateRegisterState::Subscribe);
128129

129-
if ($result === false) {
130+
if ($result !== AutoupdateRegisterResultState::Success) {
130131
return Command::FAILURE;
131132
}
132133

0 commit comments

Comments
 (0)