2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Responsile for retrieving version information and notifiying about latest version
8 if (! defined('PHPMYADMIN')) {
13 * Responsile for retrieving version information and notifiying about latest version
18 class VersionInformation
21 * Returns information with latest version from phpmyadmin.net
23 * @return object JSON decoded object with the data
25 public function getLatestVersion()
27 if (!$GLOBALS['cfg']['VersionCheck']) {
31 // wait 3s at most for server response, it's enough to get information
32 // from a working server
33 $connection_timeout = 3;
36 // Get response text from phpmyadmin.net or from the session
37 // Update cache every 6 hours
38 if (isset($_SESSION['cache']['version_check'])
39 && time() < $_SESSION['cache']['version_check']['timestamp'] +
3600 * 6
42 $response = $_SESSION['cache']['version_check']['response'];
45 $file = 'https://www.phpmyadmin.net/home_page/version.json';
46 if (ini_get('allow_url_fopen')) {
49 'request_fulluri' => true,
50 'timeout' => $connection_timeout,
53 $context = PMA_Util
::handleContext($context);
54 if (! defined('TESTSUITE')) {
55 session_write_close();
57 $response = file_get_contents(
60 stream_context_create($context)
62 } else if (function_exists('curl_init')) {
63 $curl_handle = curl_init($file);
64 if ($curl_handle === false) {
67 $curl_handle = PMA_Util
::configureCurl($curl_handle);
75 CURLOPT_RETURNTRANSFER
,
83 if (! defined('TESTSUITE')) {
84 session_write_close();
86 $response = curl_exec($curl_handle);
90 $data = json_decode($response);
92 && ! empty($data->version
)
93 && ! empty($data->date
)
96 if (! isset($_SESSION) && ! defined('TESTSUITE')) {
97 ini_set('session.use_only_cookies', 'false');
98 ini_set('session.use_cookies', 'false');
99 ini_set('session.use_trans_sid', 'false');
100 ini_set('session.cache_limiter', 'nocache');
103 $_SESSION['cache']['version_check'] = array(
104 'response' => $response,
105 'timestamp' => time()
112 * Calculates numerical equivalent of phpMyAdmin version string
114 * @param string $version version
116 * @return mixed false on failure, integer on success
118 public function versionToInt($version)
120 $parts = explode('-', $version);
121 if (count($parts) > 1) {
126 $parts = explode('.', $parts[0]);
130 if (count($parts) >= 1 && is_numeric($parts[0])) {
131 $result +
= 1000000 * $parts[0];
134 if (count($parts) >= 2 && is_numeric($parts[1])) {
135 $result +
= 10000 * $parts[1];
138 if (count($parts) >= 3 && is_numeric($parts[2])) {
139 $result +
= 100 * $parts[2];
142 if (count($parts) >= 4 && is_numeric($parts[3])) {
143 $result +
= 1 * $parts[3];
146 if (!empty($suffix)) {
148 if (preg_match('/^(\D+)(\d+)$/', $suffix, $matches)) {
149 $suffix = $matches[1];
150 $result +
= intval($matches[2]);
170 $result +
= 50; // for final
177 * Returns the version and date of the latest phpMyAdmin version compatible
178 * with avilable PHP and MySQL versions
180 * @param array $releases array of information related to each version
182 * @return array containing the version and date of latest compatibel version
184 public function getLatestCompatibleVersion($releases)
186 foreach ($releases as $release) {
187 $phpVersions = $release->php_versions
;
188 $phpConditions = explode(",", $phpVersions);
189 foreach ($phpConditions as $phpCondition) {
190 if (! $this->evaluateVersionCondition("PHP", $phpCondition)) {
195 // We evalute MySQL version constraint if there are only
196 // one server configured.
197 if (count($GLOBALS['cfg']['Servers']) == 1) {
198 $mysqlVersions = $release->mysql_versions
;
199 $mysqlConditions = explode(",", $mysqlVersions);
200 foreach ($mysqlConditions as $mysqlCondition) {
201 if (! $this->evaluateVersionCondition('MySQL', $mysqlCondition)) {
208 'version' => $release->version
,
209 'date' => $release->date
,
213 // no compatible version
218 * Checks whether PHP or MySQL version meets supplied version condition
220 * @param string $type PHP or MySQL
221 * @param string $condition version condition
223 * @return boolean whether the condition is met
225 public function evaluateVersionCondition($type, $condition)
228 $operators = array("<=", ">=", "!=", "<>", "<", ">", "="); // preserve order
229 foreach ($operators as $oneOperator) {
230 if (strpos($condition, $oneOperator) === 0) {
231 $operator = $oneOperator;
232 $version = substr($condition, strlen($oneOperator));
238 if ($type == 'PHP') {
239 $myVersion = $this->getPHPVersion();
240 } elseif ($type == 'MySQL') {
241 $myVersion = $this->getMySQLVersion();
244 if ($myVersion != null && $operator != null) {
245 return version_compare($myVersion, $version, $operator);
251 * Returns the PHP version
253 * @return string PHP version
255 protected function getPHPVersion()
261 * Returns the MySQL version
263 * @return string MySQL version
265 protected function getMySQLVersion()
267 return PMA_Util
::cacheGet('PMA_MYSQL_STR_VERSION');