No Code Attached Yet bug
avatar Septdir
Septdir
29 Nov 2023

In 2017, Joomla added support for download mirrors. The reason for this addition was the inability to update Joomla in some countries due to Amazon's blockade. #18543

Since then, mirrors have been added to the Joomla update server manifest, including on GitHub.

Unfortunately, this feature has not been working for a long time. Probably there was no urgent need to fix it.

Today, I had time to figure this out. At first, I thought the problem was just that when this feature was made, we forgot to write a timeout into it. But on closer inspection, I noticed that the mirrors don't even get into the update object, meaning part of the code is simply not used.

To start fixing this function, which has long needed fixing, I need to find out when and for what reason this line was added:

https://github.com/joomla/joomla-cms/blob/5.0-dev/libraries/src/Updater/Update.php#L415

avatar Septdir Septdir - open - 29 Nov 2023
avatar joomla-cms-bot joomla-cms-bot - change - 29 Nov 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 29 Nov 2023
avatar brianteeman
brianteeman - comment - 29 Nov 2023

I need to find out when and for what reason this line was added

#39446

avatar brianteeman
brianteeman - comment - 29 Nov 2023

Unfortunately, this feature has not been working for a long time. Probably there was no urgent need to fix it.

was this reported anywhere?

avatar Septdir
Septdir - comment - 29 Nov 2023

was this reported anywhere?
Most likely, this remained in the chats and forums of the Russian-speaking community. No one wrote about it on GitHub.

avatar brianteeman
brianteeman - comment - 29 Nov 2023

hard to fix something if no one knows it is broken :)

avatar zero-24
zero-24 - comment - 29 Nov 2023

hmm this is the method that takes care of the additional download sources:

Can you please send us the update server XML you are using?
What error messages do you got?
And what is the status of the primary update URL?

avatar Septdir
Septdir - comment - 29 Nov 2023

hard to fix something if no one knows it is broken :)

Most likely, this remained in the chats and forums of the Russian-speaking community. No one wrote about it on GitHub.

Can you please send us the update server XML you are using?

Joomla Standard update server

$sources = $updateInfo['object']->get('downloadSources', []);

Try debug this line sources is empty.

And newer used if this line go to timeout

$head = HttpFactory::getHttp($httpOptions)->head($packageURL);

avatar Septdir
Septdir - comment - 29 Nov 2023

And what is the status of the primary update URL?

Timeout
Initially, I thought it would be enough to simply add a timeout here.

I already have a solution to the problem, but I need to find out why the mirrors were removed.
And also rewrite the download method.

avatar Septdir
Septdir - comment - 29 Nov 2023

Hot fix lock like this.

  1. We collect an array of download links.
  2. We get the final page and check the response.
  3. The download occurs.

P.S. Please don't judge this code too harshly, I wrote it over breakfast.

	public function download()
	{
		$updateInfo  = $this->getUpdateInformation();
		$sources     = $updateInfo['object']->get('downloadSources', []);
		$packageURLs = [
			trim($updateInfo['object']->downloadurl->_data),
		];

		if (count($sources) > 0)
		{
			foreach ($sources as $source)
			{
				$url = trim($source->url);
				if (!empty($url))
				{
					$packageURLs[] = $url;
				}
			}
		}
		$packageURLs = array_unique($packageURLs);

		// We have to manually follow the redirects here so we set the option to false.
		$httpOptions = new Registry();
		$httpOptions->set('follow_location', false);

		// Follow the Location headers until the actual download URL is known
		$packageURL = null;
		foreach ($packageURLs as $mirrorUrl)
		{
			try
			{
				$head = HttpFactory::getHttp($httpOptions)->head($mirrorUrl, [], 10);
			}
			catch (\RuntimeException $e)
			{
				continue;
			}

			while (isset($head->headers['location']))
			{
				$packageURL = (string) $head->headers['location'][0];
				try
				{
					$head = HttpFactory::getHttp($httpOptions)->head($packageURL, [], 10);
				}
				catch (\RuntimeException $e)
				{
					$packageURL = null;
					break;
				}
			}

			if ($packageURL)
			{
				break;
			}
		}

		if ($packageURL === null)
		{
			// Passing false here -> download failed message
			$response['basename'] = false;

			return $response;
		}
``
avatar zero-24
zero-24 - comment - 29 Nov 2023

Looks good on a quick look from here. Needs to be tested now ofc.

avatar Septdir
Septdir - comment - 29 Nov 2023

Looks good on a quick look from here. Needs to be tested now ofc.

And optimize.
There you also need to remove the while for the download cycle from mirrors, it is rudimentary with this approach.
Plus we need to decide what to do with the case described in #39446 mb check 404 response?

And my question is, if I make a PR for Joomla 4, will it be accepted?

avatar zero-24
zero-24 - comment - 29 Nov 2023

Feel free to do the PR with test instructions. Everyone is allowed to create PRs ;⁠-⁠)

avatar Septdir
Septdir - comment - 29 Nov 2023

Feel free to do the PR with test instructions. Everyone is allowed to create PRs ;⁠-⁠)

The question is whether Fix will accept j4 and j5 into the branch or make it only for j5

avatar zero-24
zero-24 - comment - 29 Nov 2023

Well i personally would classify this as a bug fix and therefore send the PR against 4.4 after that the change should be merged up to 5 too.

avatar Septdir
Septdir - comment - 29 Nov 2023

Ok I'll do PR one of these days

avatar Quy Quy - change - 29 Nov 2023
Labels Added: bug
avatar Quy Quy - labeled - 29 Nov 2023
avatar alikon alikon - close - 30 Nov 2023
avatar alikon
alikon - comment - 30 Nov 2023

closing as there is a pr #42431

avatar alikon alikon - change - 30 Nov 2023
Status New Closed
Closed_Date 0000-00-00 00:00:00 2023-11-30 17:40:42
Closed_By alikon

Add a Comment

Login with GitHub to post a comment