PMA\libraries\VersionInformation::getLatestCompatibleVersion PHP Method

getLatestCompatibleVersion() public method

Returns the version and date of the latest phpMyAdmin version compatible with the available PHP and MySQL versions
public getLatestCompatibleVersion ( array $releases ) : array
$releases array array of information related to each version
return array containing the version and date of latest compatible version
    public function getLatestCompatibleVersion($releases)
    {
        foreach ($releases as $release) {
            $phpVersions = $release->php_versions;
            $phpConditions = explode(",", $phpVersions);
            foreach ($phpConditions as $phpCondition) {
                if (!$this->evaluateVersionCondition("PHP", $phpCondition)) {
                    continue 2;
                }
            }
            // We evalute MySQL version constraint if there are only
            // one server configured.
            if (count($GLOBALS['cfg']['Servers']) == 1) {
                $mysqlVersions = $release->mysql_versions;
                $mysqlConditions = explode(",", $mysqlVersions);
                foreach ($mysqlConditions as $mysqlCondition) {
                    if (!$this->evaluateVersionCondition('MySQL', $mysqlCondition)) {
                        continue 2;
                    }
                }
            }
            return array('version' => $release->version, 'date' => $release->date);
        }
        // no compatible version
        return null;
    }

Usage Example

Example #1
0
/**
 * Checks for newest phpMyAdmin version and sets result as a new notice
 *
 * @return void
 */
function PMA_versionCheck()
{
    // version check messages should always be visible so let's make
    // a unique message id each time we run it
    $message_id = uniqid('version_check');
    // Fetch data
    $versionInformation = new VersionInformation();
    $version_data = $versionInformation->getLatestVersion();
    if (empty($version_data)) {
        PMA_messagesSet('error', $message_id, __('Version check'), __('Reading of version failed. ' . 'Maybe you\'re offline or the upgrade server does not respond.'));
        return;
    }
    $releases = $version_data->releases;
    $latestCompatible = $versionInformation->getLatestCompatibleVersion($releases);
    if ($latestCompatible != null) {
        $version = $latestCompatible['version'];
        $date = $latestCompatible['date'];
    } else {
        return;
    }
    $version_upstream = $versionInformation->versionToInt($version);
    if ($version_upstream === false) {
        PMA_messagesSet('error', $message_id, __('Version check'), __('Got invalid version string from server'));
        return;
    }
    $version_local = $versionInformation->versionToInt($GLOBALS['PMA_Config']->get('PMA_VERSION'));
    if ($version_local === false) {
        PMA_messagesSet('error', $message_id, __('Version check'), __('Unparsable version string'));
        return;
    }
    if ($version_upstream > $version_local) {
        $version = htmlspecialchars($version);
        $date = htmlspecialchars($date);
        PMA_messagesSet('notice', $message_id, __('Version check'), sprintf(__('A newer version of phpMyAdmin is available and you should consider upgrading. The newest version is %s, released on %s.'), $version, $date));
    } else {
        if ($version_local % 100 == 0) {
            PMA_messagesSet('notice', $message_id, __('Version check'), PMA_sanitize(sprintf(__('You are using Git version, run [kbd]git pull[/kbd] :-)[br]The latest stable version is %s, released on %s.'), $version, $date)));
        } else {
            PMA_messagesSet('notice', $message_id, __('Version check'), __('No newer stable version is available'));
        }
    }
}
All Usage Examples Of PMA\libraries\VersionInformation::getLatestCompatibleVersion