Back to ExtensionAdapter class

Method _endElement

protected void
_endElement
(mixed $parser, mixed $name)
Character Parser Function
Parameters
  • object $parser Parser object.
  • object $name The name of the element.
Returns
  • void
Since
  • 1.7.0

Method _endElement - Source code

/**
 * Character Parser Function
 *
 * @param   object  $parser  Parser object.
 * @param   object  $name    The name of the element.
 *
 * @return  void
 *
 * @since   1.7.0
 */
protected function _endElement($parser, $name)
{
    array_pop($this->stack);
    switch ($name) {
        case 'UPDATE':
            // Lower case and remove the exclamation mark
            $product = strtolower(InputFilter::getInstance()->clean(Version::PRODUCT, 'cmd'));
            // Check that the product matches and that the version matches (optionally a regexp)
            if ($product == $this->currentUpdate->targetplatform['NAME'] && preg_match('/^' . $this->currentUpdate->targetplatform['VERSION'] . '/', JVERSION)) {
                // 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, '>=')) {
                    $phpMatch = true;
                } else {
                    // Notify the user of the potential update
                    $msg = Text::sprintf('JLIB_INSTALLER_AVAILABLE_UPDATE_PHP_VERSION', $this->currentUpdate->name, $this->currentUpdate->version, $this->currentUpdate->php_minimum, PHP_VERSION);
                    Factory::getApplication()->enqueueMessage($msg, 'warning');
                    $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 = Factory::getDbo();
                    $dbType = strtoupper($db->getServerType());
                    $dbVersion = $db->getVersion();
                    $supportedDbs = $this->currentUpdate->supported_databases;
                    // MySQL and MariaDB use the same database driver but not the same version numbers
                    if ($dbType === 'mysql') {
                        // Check whether we have a MariaDB version string and extract the proper version from it
                        if (stripos($dbVersion, 'mariadb') !== false) {
                            // MariaDB: Strip off any leading '5.5.5-', if present
                            $dbVersion = preg_replace('/^5\\.5\\.5-/', '', $dbVersion);
                            $dbType = 'mariadb';
                        }
                    }
                    // Do we have an entry for the database?
                    if (\array_key_exists($dbType, $supportedDbs)) {
                        $minimumVersion = $supportedDbs[$dbType];
                        $dbMatch = version_compare($dbVersion, $minimumVersion, '>=');
                        if (!$dbMatch) {
                            // Notify the user of the potential update
                            $dbMsg = Text::sprintf('JLIB_INSTALLER_AVAILABLE_UPDATE_DB_MINIMUM', $this->currentUpdate->name, $this->currentUpdate->version, Text::_($db->name), $dbVersion, $minimumVersion);
                            Factory::getApplication()->enqueueMessage($dbMsg, 'warning');
                        }
                    } else {
                        // Notify the user of the potential update
                        $dbMsg = Text::sprintf('JLIB_INSTALLER_AVAILABLE_UPDATE_DB_TYPE', $this->currentUpdate->name, $this->currentUpdate->version, Text::_($db->name));
                        Factory::getApplication()->enqueueMessage($dbMsg, 'warning');
                    }
                } else {
                    // Set to true if the <supported_databases> tag is not set
                    $dbMatch = true;
                }
                // Check minimum stability
                $stabilityMatch = true;
                if (isset($this->currentUpdate->stability) && $this->currentUpdate->stability < $this->minimum_stability) {
                    $stabilityMatch = false;
                }
                // Some properties aren't valid fields in the update table so unset them to prevent J! from trying to store them
                unset($this->currentUpdate->targetplatform);
                if (isset($this->currentUpdate->php_minimum)) {
                    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 && $dbMatch) {
                    if (isset($this->latest)) {
                        // We already have a possible update. Check the version.
                        if (version_compare($this->currentUpdate->version, $this->latest->version, '>') == 1) {
                            $this->latest = $this->currentUpdate;
                        }
                    } else {
                        // We don't have any possible updates yet, assume this is an available update.
                        $this->latest = $this->currentUpdate;
                    }
                }
            }
            break;
        case 'UPDATES':
            // :D
            break;
    }
}