diff --git a/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php b/administrator/components/com_joomlaupdate/src/Model/UpdateModel.php index 337195d7639..e45d57696dd 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('installer'); + + $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..b0bba9bed97 --- /dev/null +++ b/libraries/src/Event/Extension/BeforeJoomlaAutoupdateEvent.php @@ -0,0 +1,67 @@ + + * @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 + * + * @return void + * + * @since __DEPLOY_VERSION__ + */ + public function setStopUpdate() + { + $this->arguments['stopUpdate'] = 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; + } +}