Skip to content

Commit f257ff6

Browse files
authored
Send an event before an update site is downloaded (joomla#44516)
1 parent 7042ea5 commit f257ff6

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
* Joomla! Content Management System
5+
*
6+
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
7+
* @license GNU General Public License version 2 or later; see LICENSE.txt
8+
*/
9+
10+
namespace Joomla\CMS\Event\Installer;
11+
12+
// phpcs:disable PSR1.Files.SideEffects
13+
\defined('_JEXEC') or die;
14+
// phpcs:enable PSR1.Files.SideEffects
15+
16+
/**
17+
* Class for update site events
18+
*
19+
* @since __DEPLOY_VERSION__
20+
*/
21+
class BeforeUpdateSiteDownloadEvent extends BeforePackageDownloadEvent
22+
{
23+
}

libraries/src/Updater/UpdateAdapter.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
namespace Joomla\CMS\Updater;
1111

1212
use Joomla\CMS\Adapter\AdapterInstance;
13+
use Joomla\CMS\Event\Installer\BeforeUpdateSiteDownloadEvent;
1314
use Joomla\CMS\Factory;
1415
use Joomla\CMS\Http\HttpFactory;
1516
use Joomla\CMS\Language\Text;
1617
use Joomla\CMS\Log\Log;
18+
use Joomla\CMS\Plugin\PluginHelper;
1719
use Joomla\CMS\Version;
1820
use Joomla\Database\ParameterType;
1921
use Joomla\Registry\Registry;
@@ -245,10 +247,21 @@ protected function getUpdateSiteResponse($options = [])
245247
$httpOption = new Registry();
246248
$httpOption->set('userAgent', $version->getUserAgent('Joomla', true, false));
247249

248-
// JHttp transport throws an exception when there's no response.
250+
$headers = [];
251+
$dispatcher = Factory::getApplication()->getDispatcher();
252+
PluginHelper::importPlugin('installer', null, true, $dispatcher);
253+
$event = new BeforeUpdateSiteDownloadEvent('onInstallerBeforeUpdateSiteDownload', [
254+
'url' => $url,
255+
'headers' => $headers,
256+
]);
257+
$dispatcher->dispatch('onInstallerBeforeUpdateSiteDownload', $event);
258+
$url = $event->getArgument('url', $url);
259+
$headers = $event->getArgument('headers', $headers);
260+
261+
// Http transport throws an exception when there's no response.
249262
try {
250263
$http = HttpFactory::getHttp($httpOption);
251-
$response = $http->get($url, [], 20);
264+
$response = $http->get($url, $headers, 20);
252265
} catch (\RuntimeException $e) {
253266
$response = null;
254267
}

0 commit comments

Comments
 (0)