From ef23d1b987e76072b4f2715b79aedc17c293209f Mon Sep 17 00:00:00 2001 From: David Jardin Date: Mon, 19 May 2025 17:44:59 +0200 Subject: [PATCH 1/5] implement support for autoupdate preparation event --- .../src/Model/UpdateModel.php | 20 +++++- .../language/en-GB/com_joomlaupdate.ini | 1 + .../src/View/Updates/JsonapiView.php | 2 +- .../Extension/BeforeJoomlaAutoupdateEvent.php | 72 +++++++++++++++++++ 4 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 libraries/src/Event/Extension/BeforeJoomlaAutoupdateEvent.php diff --git a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php index 337195d7639..bd7858c084c 100644 --- a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php @@ -13,6 +13,7 @@ use Joomla\CMS\Authentication\Authentication; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Event\Extension\AfterJoomlaUpdateEvent; +use Joomla\CMS\Event\Extension\BeforeJoomlaAutoupdateEvent; use Joomla\CMS\Event\Extension\BeforeJoomlaUpdateEvent; use Joomla\CMS\Extension\ExtensionHelper; use Joomla\CMS\Factory; @@ -545,9 +546,24 @@ public function prepareAutoUpdate(string $targetVersion): array $app = Factory::getApplication(); + // Run preparation plugin trigger + PluginHelper::importPlugin('system'); + + $eventResult = $app->getDispatcher()->dispatch( + 'onBeforeJoomlaAutoupdate', + new BeforeJoomlaAutoupdateEvent( + 'onBeforeJoomlaAutoupdate' + ) + ); + + if ($eventResult->getArgument('stopUpdate')) { + throw new \Exception(Text::_('COM_JOOMLAUPDATE_VIEW_UPDATE_STOPPED_BY_PLUGIN'), 503); + } + return [ - 'password' => $app->getUserState('com_joomlaupdate.password'), - 'filesize' => $app->getUserState('com_joomlaupdate.filesize'), + 'password' => $app->getUserState('com_joomlaupdate.password'), + 'filesize' => $app->getUserState('com_joomlaupdate.filesize'), + 'preparationUrls' => $eventResult->getArgument('preparationUrls') ]; } diff --git a/administrator/language/en-GB/com_joomlaupdate.ini b/administrator/language/en-GB/com_joomlaupdate.ini index 0d0e09e0377..177b5703703 100644 --- a/administrator/language/en-GB/com_joomlaupdate.ini +++ b/administrator/language/en-GB/com_joomlaupdate.ini @@ -206,6 +206,7 @@ COM_JOOMLAUPDATE_VIEW_UPDATE_CHECKSUM_WRONG="File Checksum Failed" COM_JOOMLAUPDATE_VIEW_UPDATE_VERSION_WRONG="The version of the update package and the requested version do not match, try to refresh the update information." COM_JOOMLAUPDATE_VIEW_UPDATE_DOWNLOADFAILED="Download of update package failed." COM_JOOMLAUPDATE_VIEW_UPDATE_ITEMS="items" +COM_JOOMLAUPDATE_VIEW_UPDATE_STOPPED_BY_PLUGIN="Update stopped by plugin." COM_JOOMLAUPDATE_VIEW_UPDATE_FILESEXTRACTED="Files extracted" COM_JOOMLAUPDATE_VIEW_UPDATE_FINALISE_CONFIRM_AND_CONTINUE="Confirm & Continue" COM_JOOMLAUPDATE_VIEW_UPDATE_FINALISE_HEAD="Joomla Update is finishing and cleaning up" diff --git a/api/components/com_joomlaupdate/src/View/Updates/JsonapiView.php b/api/components/com_joomlaupdate/src/View/Updates/JsonapiView.php index 782ce99b420..7293b49647e 100644 --- a/api/components/com_joomlaupdate/src/View/Updates/JsonapiView.php +++ b/api/components/com_joomlaupdate/src/View/Updates/JsonapiView.php @@ -86,7 +86,7 @@ public function prepareUpdate(string $targetVersion): string $fileinformation['id'] = 'prepareUpdate'; $element = (new Resource((object) $fileinformation, $this->serializer)) - ->fields(['updates' => ['password', 'filesize']]); + ->fields(['updates' => ['password', 'filesize', 'preparationUrls']]); $this->getDocument()->setData($element); $this->getDocument()->addLink('self', Uri::current()); diff --git a/libraries/src/Event/Extension/BeforeJoomlaAutoupdateEvent.php b/libraries/src/Event/Extension/BeforeJoomlaAutoupdateEvent.php new file mode 100644 index 00000000000..2f8eecb6ae9 --- /dev/null +++ b/libraries/src/Event/Extension/BeforeJoomlaAutoupdateEvent.php @@ -0,0 +1,72 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace Joomla\CMS\Event\Extension; + +// phpcs:disable PSR1.Files.SideEffects +\defined('_JEXEC') or die; +// phpcs:enable PSR1.Files.SideEffects + +/** + * Class for Joomla Auto Update events + * + * @since __DEPLOY_VERSION__ + */ +class BeforeJoomlaAutoupdateEvent extends AbstractJoomlaUpdateEvent +{ + /** + * Constructor. + * + * @param string $name The event name. + * @param array $arguments The event arguments. + * + * @throws \BadMethodCallException + * + * @since __DEPLOY_VERSION__ + */ + public function __construct($name, array $arguments = []) + { + $arguments['stopUpdate'] = false; + $arguments['preparationUrls'] = []; + + parent::__construct($name, $arguments); + } + + /** + * Set stop parameter to true + * + * @param bool $value The value to set + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function setStopUpdate($value = true) + { + $this->arguments['stopUpdate'] = $value; + + if ($value === true) { + $this->stopPropagation(); + } + } + + /** + * Appends a preparation url to the url queue + * + * @param string $preparationUrl + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function addPreparationUrl(string $preparationUrl) + { + $this->arguments['preparationUrls'][] = $preparationUrl; + } +} From 8dd615583c21e10999c279e7bf628f094cbae143 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Mon, 19 May 2025 17:57:51 +0200 Subject: [PATCH 2/5] remove useless helper call --- .../components/com_joomlaupdate/src/Model/UpdateModel.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php index bd7858c084c..10aca2d130b 100644 --- a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php @@ -547,8 +547,6 @@ public function prepareAutoUpdate(string $targetVersion): array $app = Factory::getApplication(); // Run preparation plugin trigger - PluginHelper::importPlugin('system'); - $eventResult = $app->getDispatcher()->dispatch( 'onBeforeJoomlaAutoupdate', new BeforeJoomlaAutoupdateEvent( From 2f3dd85977d7ca68e77ace9a3eb88d1e534ade65 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 20 May 2025 09:08:10 +0200 Subject: [PATCH 3/5] import extension plugins --- .../components/com_joomlaupdate/src/Model/UpdateModel.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php index 10aca2d130b..572b6c5fd20 100644 --- a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php @@ -547,6 +547,8 @@ public function prepareAutoUpdate(string $targetVersion): array $app = Factory::getApplication(); // Run preparation plugin trigger + PluginHelper::importPlugin('extension'); + $eventResult = $app->getDispatcher()->dispatch( 'onBeforeJoomlaAutoupdate', new BeforeJoomlaAutoupdateEvent( From 60b5b8f3c6c749010b437443cc35f5d8ead8f32d Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 20 May 2025 09:11:47 +0200 Subject: [PATCH 4/5] fix plugin group --- .../components/com_joomlaupdate/src/Model/UpdateModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php index 572b6c5fd20..e45d57696dd 100644 --- a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php +++ b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php @@ -547,7 +547,7 @@ public function prepareAutoUpdate(string $targetVersion): array $app = Factory::getApplication(); // Run preparation plugin trigger - PluginHelper::importPlugin('extension'); + PluginHelper::importPlugin('installer'); $eventResult = $app->getDispatcher()->dispatch( 'onBeforeJoomlaAutoupdate', From 911ba4b6f31bb0f4be69063c718af50d35d8b975 Mon Sep 17 00:00:00 2001 From: David Jardin Date: Tue, 20 May 2025 09:20:52 +0200 Subject: [PATCH 5/5] remove useless argument --- .../Event/Extension/BeforeJoomlaAutoupdateEvent.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/libraries/src/Event/Extension/BeforeJoomlaAutoupdateEvent.php b/libraries/src/Event/Extension/BeforeJoomlaAutoupdateEvent.php index 2f8eecb6ae9..b0bba9bed97 100644 --- a/libraries/src/Event/Extension/BeforeJoomlaAutoupdateEvent.php +++ b/libraries/src/Event/Extension/BeforeJoomlaAutoupdateEvent.php @@ -41,19 +41,14 @@ public function __construct($name, array $arguments = []) /** * Set stop parameter to true * - * @param bool $value The value to set - * * @return void * * @since __DEPLOY_VERSION__ */ - public function setStopUpdate($value = true) + public function setStopUpdate() { - $this->arguments['stopUpdate'] = $value; - - if ($value === true) { - $this->stopPropagation(); - } + $this->arguments['stopUpdate'] = true; + $this->stopPropagation(); } /**