Skip to content

Commit

Permalink
[com_joomlaupdate] Check for minimum supported database type and vers…
Browse files Browse the repository at this point in the history
…ion (#12355)

* initial support supported_databases

* fixes. Thanks Michael

* fix some typos

* oh inconsistencies where you look ... great updater code

* en-GB thanks @brianteeman

* you -> your

* one line to much thanks @yvesh
  • Loading branch information
zero-24 authored and rdeutz committed Oct 18, 2016
1 parent e101128 commit 0af7caf
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.lib_joomla.ini
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ JLIB_INSTALLER_ABORT_TPL_INSTALL_FAILED_CREATE_DIRECTORY="Template Install: Fail
JLIB_INSTALLER_ABORT_TPL_INSTALL_ROLLBACK="Template Install: %s"
JLIB_INSTALLER_ABORT_TPL_INSTALL_UNKNOWN_CLIENT="Template Install: Unknown client type [%s]"
JLIB_INSTALLER_AVAILABLE_UPDATE_PHP_VERSION="For the extension %1$s version %2$s is available, but it requires at least PHP version %3$s while your system only has %4$s"
JLIB_INSTALLER_AVAILABLE_UPDATE_DB_MINIMUM="For the extension %1$s version %2$s is available, but your current database %3$s is version %4$s and is not supported. Please contact your web host to update your Database version to at least version %5$s."
JLIB_INSTALLER_AVAILABLE_UPDATE_DB_TYPE="For the extension %1$s version %2$s is available, but your current database %3$s is not supported anymore."
JLIB_INSTALLER_PURGED_UPDATES="Cleared updates"
JLIB_INSTALLER_FAILED_TO_PURGE_UPDATES="Failed to clear updates."
JLIB_INSTALLER_DEFAULT_STYLE="%s - Default"
Expand Down
62 changes: 61 additions & 1 deletion libraries/joomla/updater/adapters/extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ protected function _startElement($parser, $name, $attrs = array())
{
$this->currentUpdate->php_minimum = '';
}

if ($name == 'SUPPORTED_DATABASES')
{
$this->currentUpdate->supported_databases = $attrs;
}
break;
}
}
Expand Down Expand Up @@ -137,6 +142,56 @@ protected function _endElement($parser, $name)
$phpMatch = false;
}

$dbMatch = false;

// Check if DB & version is supported via <supported_databases> tag, assume supported if tag isn't present
if (isset($this->currentUpdate->supported_databases))
{
$db = JFactory::getDbo();
$dbType = strtoupper($db->getServerType());
$dbVersion = $db->getVersion();
$supportedDbs = $this->currentUpdate->supported_databases;

// Do we have a entry for the database?
if (array_key_exists($dbType, $supportedDbs))
{
$minumumVersion = $supportedDbs[$dbType];
$dbMatch = version_compare($dbVersion, $minumumVersion, '>=');

if (!$dbMatch)
{
// Notify the user of the potential update
$dbMsg = JText::sprintf(
'JLIB_INSTALLER_AVAILABLE_UPDATE_DB_MINIMUM',
$this->currentUpdate->name,
$this->currentUpdate->version,
JText::_($db->name),
$dbVersion,
$minumumVersion
);

JFactory::getApplication()->enqueueMessage($dbMsg, 'warning');
}
}
else
{
// Notify the user of the potential update
$dbMsg = JText::sprintf(
'JLIB_INSTALLER_AVAILABLE_UPDATE_DB_TYPE',
$this->currentUpdate->name,
$this->currentUpdate->version,
JText::_($db->name)
);

JFactory::getApplication()->enqueueMessage($dbMsg, 'warning');
}
}
else
{
// Set to true if the <supported_databases> tag is not set
$dbMatch = true;
}

// Check minimum stability
$stabilityMatch = true;

Expand All @@ -153,13 +208,18 @@ protected function _endElement($parser, $name)
unset($this->currentUpdate->php_minimum);
}

if (isset($this->currentUpdate->supported_databases))
{
unset($this->currentUpdate->supported_databases);
}

if (isset($this->currentUpdate->stability))
{
unset($this->currentUpdate->stability);
}

// If the PHP version and minimum stability checks pass, consider this version as a possible update
if ($phpMatch && $stabilityMatch)
if ($phpMatch && $stabilityMatch && $dbMatch)
{
if (isset($this->latest))
{
Expand Down
25 changes: 23 additions & 2 deletions libraries/joomla/updater/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,35 @@ public function _endElement($parser, $name)
&& ((!isset($this->currentUpdate->targetplatform->min_dev_level)) || JVersion::DEV_LEVEL >= $this->currentUpdate->targetplatform->min_dev_level)
&& ((!isset($this->currentUpdate->targetplatform->max_dev_level)) || JVersion::DEV_LEVEL <= $this->currentUpdate->targetplatform->max_dev_level))
{
$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;
}

$dbMatch = false;

// Check if DB & version is supported via <supported_databases> tag, assume supported if tag isn't present
if (isset($this->currentUpdate->supported_databases))
{
$db = JFactory::getDbo();
$dbType = strtolower($db->getServerType());
$dbVersion = $db->getVersion();
$supportedDbs = $this->currentUpdate->supported_databases;

// Do we have a entry for the database?
if (isset($supportedDbs->$dbType))
{
$minumumVersion = $supportedDbs->$dbType;
$dbMatch = version_compare($dbVersion, $minumumVersion, '>=');
}
}
else
{
$phpMatch = false;
// Set to true if the <supported_databases> tag is not set
$dbMatch = true;
}

// Check minimum stability
Expand All @@ -339,7 +360,7 @@ public function _endElement($parser, $name)
$stabilityMatch = false;
}

if ($phpMatch && $stabilityMatch)
if ($phpMatch && $stabilityMatch && $dbMatch)
{
if (isset($this->latest))
{
Expand Down

0 comments on commit 0af7caf

Please sign in to comment.