Skip to content

Commit

Permalink
Send an event before an update site is downloaded (#44516)
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo authored Dec 15, 2024
1 parent 7042ea5 commit f257ff6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
23 changes: 23 additions & 0 deletions libraries/src/Event/Installer/BeforeUpdateSiteDownloadEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Installer;

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

/**
* Class for update site events
*
* @since __DEPLOY_VERSION__
*/
class BeforeUpdateSiteDownloadEvent extends BeforePackageDownloadEvent
{
}
17 changes: 15 additions & 2 deletions libraries/src/Updater/UpdateAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
namespace Joomla\CMS\Updater;

use Joomla\CMS\Adapter\AdapterInstance;
use Joomla\CMS\Event\Installer\BeforeUpdateSiteDownloadEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Http\HttpFactory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Version;
use Joomla\Database\ParameterType;
use Joomla\Registry\Registry;
Expand Down Expand Up @@ -245,10 +247,21 @@ protected function getUpdateSiteResponse($options = [])
$httpOption = new Registry();
$httpOption->set('userAgent', $version->getUserAgent('Joomla', true, false));

// JHttp transport throws an exception when there's no response.
$headers = [];
$dispatcher = Factory::getApplication()->getDispatcher();
PluginHelper::importPlugin('installer', null, true, $dispatcher);
$event = new BeforeUpdateSiteDownloadEvent('onInstallerBeforeUpdateSiteDownload', [
'url' => $url,
'headers' => $headers,
]);
$dispatcher->dispatch('onInstallerBeforeUpdateSiteDownload', $event);
$url = $event->getArgument('url', $url);
$headers = $event->getArgument('headers', $headers);

// Http transport throws an exception when there's no response.
try {
$http = HttpFactory::getHttp($httpOption);
$response = $http->get($url, [], 20);
$response = $http->get($url, $headers, 20);
} catch (\RuntimeException $e) {
$response = null;
}
Expand Down

0 comments on commit f257ff6

Please sign in to comment.