Skip to content

Commit

Permalink
Merge pull request #42556 from Razzo1987/5.1/upmerge/2023-12-21
Browse files Browse the repository at this point in the history
[5.1] upmerge 2023-12-21
  • Loading branch information
Razzo1987 authored Dec 21, 2023
2 parents 3067461 + 131504b commit f093ff9
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ class HtmlView extends BaseHtmlView
*/
protected $reasonNoDownload = '';

/**
* Details on failed PHP or DB version requirements to be shown in the emptystate layout when there is no download
*
* @var \stdClass PHP and database requirements from the update manifest
*
* @since __DEPLOY_VERSION__
*/
protected $detailsNoDownload;

/**
* List of non core critical plugins
*
Expand Down Expand Up @@ -199,8 +208,9 @@ public function display($tpl = null)
} else {
// No download available
if ($hasUpdate) {
$this->messagePrefix = '_NODOWNLOAD';
$this->reasonNoDownload = 'COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_REASON';
$this->messagePrefix = '_NODOWNLOAD';
$this->reasonNoDownload = 'COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_REASON';
$this->detailsNoDownload = $this->updateInfo['object']->get('otherUpdateInfo');
}

$this->setLayout('noupdate');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,35 @@
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Session\Session;

$uploadLink = 'index.php?option=com_joomlaupdate&view=upload';
$uploadLink = 'index.php?option=com_joomlaupdate&view=upload';
$reasonNoDownload = '';

if (!empty($this->reasonNoDownload)) {
$reasonNoDownload = Text::_($this->reasonNoDownload);

if (isset($this->detailsNoDownload->php)) {
$reasonNoDownload .= Text::sprintf(
'COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_REASON_PHP',
$this->detailsNoDownload->php->used,
$this->detailsNoDownload->php->required
);
}

if (isset($this->detailsNoDownload->db)) {
$reasonNoDownload .= Text::sprintf(
'COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_REASON_DATABASE',
Text::_('JLIB_DB_SERVER_TYPE_' . $this->detailsNoDownload->db->type),
$this->detailsNoDownload->db->used,
$this->detailsNoDownload->db->required
);
}

$reasonNoDownload .= Text::_('COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_REASON_ACTION');
}

$displayData = [
'textPrefix' => 'COM_JOOMLAUPDATE' . $this->messagePrefix,
'content' => Text::_($this->reasonNoDownload) . Text::sprintf($this->langKey, $this->updateSourceKey),
'content' => $reasonNoDownload . Text::sprintf($this->langKey, $this->updateSourceKey),
'formURL' => 'index.php?option=com_joomlaupdate&view=joomlaupdate',
'helpURL' => 'https://docs.joomla.org/Special:MyLanguage/Updating_from_an_existing_version',
'icon' => 'icon-loop joomlaupdate',
Expand Down
5 changes: 4 additions & 1 deletion administrator/language/en-GB/com_joomlaupdate.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ COM_JOOMLAUPDATE_MINIMUM_STABILITY_STABLE="Stable"
COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_APPEND="Upload and Update"
COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_BUTTON_ADD="Retry check for update"
COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_CONTENT="An update to Joomla %1$s was found, but it wasn't possible to fetch the download URL for that update. Either the update to Joomla %1$s is not available for your stability level or there is a problem with the Joomla Update Server.<br>Please try to download the update package from <a href=\"https://downloads.joomla.org/latest\">the official Joomla download page</a> and use the Upload and Update function."
COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_REASON="An update to Joomla %1$s was found but your web server doesn't meet the <a href=\"https://downloads.joomla.org/technical-requirements\" target=\"_blank\" rel=\"noopener noreferrer\">minimum requirements</a>. Please contact your web host to update your server.<br>"
COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_REASON="An update to Joomla %1$s was found but your web server doesn't meet the <a href=\"https://manual.joomla.org/docs/next/get-started/technical-requirements/\" target=\"_blank\" rel=\"noopener noreferrer\">minimum requirements</a>.<br>"
COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_REASON_ACTION="Please contact your web host to update your server.<br>"
COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_REASON_DATABASE="Your %1$s version \"%2$s\" is lower than \"%3$s\".<br>"
COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_REASON_PHP="Your PHP version \"%1$s\" is lower than \"%2$s\".<br>"
COM_JOOMLAUPDATE_NODOWNLOAD_EMPTYSTATE_TITLE="This site can't be updated to Joomla %1$s"
COM_JOOMLAUPDATE_OVERVIEW="Joomla Update"
COM_JOOMLAUPDATE_PREUPDATE_CHECK_CAPTION="Server settings to check before update."
Expand Down
11 changes: 9 additions & 2 deletions libraries/src/Installer/Adapter/FileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ protected function finaliseInstall()
*/
protected function finaliseUninstall(): bool
{
File::delete(JPATH_MANIFESTS . '/files/' . $this->extension->element . '.xml');
$manifest = JPATH_MANIFESTS . '/files/' . $this->extension->element . '.xml';

if (is_file($manifest)) {
File::delete($manifest);
}

$extensionId = $this->extension->extension_id;

Expand Down Expand Up @@ -283,7 +287,10 @@ protected function removeExtensionFiles()
$folderList[] = $targetFolder . '/' . $eFileName;
} else {
$fileName = $targetFolder . '/' . $eFileName;
File::delete($fileName);

if (is_file($fileName)) {
File::delete($fileName);
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion libraries/src/Installer/Adapter/LibraryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ public function prepareDiscoverInstall()
protected function removeExtensionFiles()
{
$this->parent->removeFiles($this->getManifest()->files, -1);
File::delete(JPATH_MANIFESTS . '/libraries/' . $this->extension->element . '.xml');
$manifest = JPATH_MANIFESTS . '/libraries/' . $this->extension->element . '.xml';

if (is_file($manifest)) {
File::delete($manifest);
}

// @todo: Change this so it walked up the path backwards so we clobber multiple empties
// If the folder is empty, let's delete it
Expand Down
6 changes: 5 additions & 1 deletion libraries/src/Installer/Adapter/PackageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,11 @@ protected function finaliseUninstall(): bool
$update->delete($uid);
}

File::delete(JPATH_MANIFESTS . '/packages/' . $this->extension->element . '.xml');
$file = JPATH_MANIFESTS . '/packages/' . $this->extension->element . '.xml';

if (is_file($file)) {
File::delete($file);
}

$folder = $this->parent->getPath('extension_root');

Expand Down
20 changes: 16 additions & 4 deletions libraries/src/Installer/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,16 @@ public function abort($msg = null, $type = null)
switch ($step['type']) {
case 'file':
// Remove the file
$stepval = File::delete($step['path']);
if (is_file($step['path']) && !($stepval = File::delete($step['path']))) {
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_FILE_FOLDER', $step['path']), Log::WARNING, 'jerror');
}
break;

case 'folder':
// Remove the folder
$stepval = Folder::delete($step['path']);
if (Folder::exists($step['path']) && !($stepval = Folder::delete($step['path']))) {
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_FILE_FOLDER', $step['path']), Log::WARNING, 'jerror');
}
break;

case 'query':
Expand Down Expand Up @@ -1437,11 +1441,19 @@ public function parseFiles(\SimpleXMLElement $element, $cid = 0, $oldFiles = nul
$deletions = $this->findDeletedFiles($oldEntries, $element->children());

foreach ($deletions['folders'] as $deleted_folder) {
Folder::delete($destination . '/' . $deleted_folder);
$folder = $destination . '/' . $deleted_folder;

if (Folder::exists($folder) && !Folder::delete($folder)) {
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_FILE_FOLDER', $folder), Log::WARNING, 'jerror');
}
}

foreach ($deletions['files'] as $deleted_file) {
File::delete($destination . '/' . $deleted_file);
$file = $destination . '/' . $deleted_file;

if (is_file($file) && !File::delete($file)) {
Log::add(Text::sprintf('JLIB_INSTALLER_ERROR_FILE_FOLDER', $file), Log::WARNING, 'jerror');
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Installer/InstallerScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function removeFiles()
{
if (!empty($this->deleteFiles)) {
foreach ($this->deleteFiles as $file) {
if (file_exists(JPATH_ROOT . $file) && !File::delete(JPATH_ROOT . $file)) {
if (is_file(JPATH_ROOT . $file) && !File::delete(JPATH_ROOT . $file)) {
echo Text::sprintf('JLIB_INSTALLER_ERROR_FILE_FOLDER', $file) . '<br>';
}
}
Expand Down
32 changes: 31 additions & 1 deletion libraries/src/Updater/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,21 @@ class Update
protected $currentUpdate;

/**
* Object containing the latest update data
* Object containing the latest update data which meets the PHP and DB version requirements
*
* @var \stdClass
* @since 3.0.0
*/
protected $latest;

/**
* Object containing details if the latest update does not meet the PHP and DB version requirements
*
* @var \stdClass
* @since __DEPLOY_VERSION__
*/
protected $otherUpdateInfo;

/**
* The minimum stability required for updates to be taken into account. The possible values are:
* 0 dev Development snapshots, nightly builds, pre-release versions and so on
Expand Down Expand Up @@ -355,13 +363,23 @@ public function _endElement($parser, $name)
&& $product == $this->currentUpdate->targetplatform->name
&& preg_match('/^' . $this->currentUpdate->targetplatform->version . '/', $this->get('jversion.full', JVERSION))
) {
// Collect information on updates which do not meet PHP and DB version requirements
$otherUpdateInfo = new \stdClass();
$otherUpdateInfo->version = $this->currentUpdate->version->_data;

$phpMatch = false;

// Check if PHP version supported via <php_minimum> tag, assume true if tag isn't present
if (!isset($this->currentUpdate->php_minimum) || version_compare(PHP_VERSION, $this->currentUpdate->php_minimum->_data, '>=')) {
$phpMatch = true;
}

if (!$phpMatch) {
$otherUpdateInfo->php = new \stdClass();
$otherUpdateInfo->php->required = $this->currentUpdate->php_minimum->_data;
$otherUpdateInfo->php->used = PHP_VERSION;
}

$dbMatch = false;

// Check if DB & version is supported via <supported_databases> tag, assume supported if tag isn't present
Expand All @@ -385,6 +403,13 @@ public function _endElement($parser, $name)
if (isset($supportedDbs->$dbType)) {
$minimumVersion = $supportedDbs->$dbType;
$dbMatch = version_compare($dbVersion, $minimumVersion, '>=');

if (!$dbMatch) {
$otherUpdateInfo->db = new \stdClass();
$otherUpdateInfo->db->type = $dbType;
$otherUpdateInfo->db->required = $minimumVersion;
$otherUpdateInfo->db->used = $dbVersion;
}
}
} else {
// Set to true if the <supported_databases> tag is not set
Expand All @@ -409,6 +434,11 @@ public function _endElement($parser, $name)
) {
$this->latest = $this->currentUpdate;
}
} elseif (
!isset($this->otherUpdateInfo)
|| version_compare($otherUpdateInfo->version, $this->otherUpdateInfo->version, '>')
) {
$this->otherUpdateInfo = $otherUpdateInfo;
}
}
break;
Expand Down

0 comments on commit f093ff9

Please sign in to comment.