2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Responsible for retrieving version information and notifiying about latest version
8 namespace PMA\libraries
;
10 use PMA\libraries\Util
;
13 if (!defined('PHPMYADMIN')) {
18 * Responsible for retrieving version information and notifiying about latest version
23 class VersionInformation
26 * Returns information with latest version from phpmyadmin.net
28 * @return object JSON decoded object with the data
30 public function getLatestVersion()
32 if (!$GLOBALS['cfg']['VersionCheck']) {
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 $response = Util
::httpRequest($file, "GET");
48 $response = $response ?
$response : '{}';
50 $data = json_decode($response);
52 /* Basic sanity checking */
53 if (! is_object($data)
54 ||
empty($data->version
)
55 ||
empty($data->releases
)
62 $_SESSION['cache']['version_check'] = array(
63 'response' => $response,
71 * Calculates numerical equivalent of phpMyAdmin version string
73 * @param string $version version
75 * @return mixed false on failure, integer on success
77 public function versionToInt($version)
79 $parts = explode('-', $version);
80 if (count($parts) > 1) {
85 $parts = explode('.', $parts[0]);
89 if (count($parts) >= 1 && is_numeric($parts[0])) {
90 $result +
= 1000000 * $parts[0];
93 if (count($parts) >= 2 && is_numeric($parts[1])) {
94 $result +
= 10000 * $parts[1];
97 if (count($parts) >= 3 && is_numeric($parts[2])) {
98 $result +
= 100 * $parts[2];
101 if (count($parts) >= 4 && is_numeric($parts[3])) {
102 $result +
= 1 * $parts[3];
105 if (!empty($suffix)) {
107 if (preg_match('/^(\D+)(\d+)$/', $suffix, $matches)) {
108 $suffix = $matches[1];
109 $result +
= intval($matches[2]);
129 $result +
= 50; // for final
136 * Returns the version and date of the latest phpMyAdmin version compatible
137 * with the available PHP and MySQL versions
139 * @param array $releases array of information related to each version
141 * @return array containing the version and date of latest compatible version
143 public function getLatestCompatibleVersion($releases)
145 foreach ($releases as $release) {
146 $phpVersions = $release->php_versions
;
147 $phpConditions = explode(",", $phpVersions);
148 foreach ($phpConditions as $phpCondition) {
149 if (! $this->evaluateVersionCondition("PHP", $phpCondition)) {
154 // We evalute MySQL version constraint if there are only
155 // one server configured.
156 if (count($GLOBALS['cfg']['Servers']) == 1) {
157 $mysqlVersions = $release->mysql_versions
;
158 $mysqlConditions = explode(",", $mysqlVersions);
159 foreach ($mysqlConditions as $mysqlCondition) {
160 if (!$this->evaluateVersionCondition('MySQL', $mysqlCondition)) {
167 'version' => $release->version
,
168 'date' => $release->date
,
172 // no compatible version
177 * Checks whether PHP or MySQL version meets supplied version condition
179 * @param string $type PHP or MySQL
180 * @param string $condition version condition
182 * @return boolean whether the condition is met
184 public function evaluateVersionCondition($type, $condition)
187 $operators = array("<=", ">=", "!=", "<>", "<", ">", "="); // preserve order
188 foreach ($operators as $oneOperator) {
189 if (strpos($condition, $oneOperator) === 0) {
190 $operator = $oneOperator;
191 $version = substr($condition, strlen($oneOperator));
197 if ($type == 'PHP') {
198 $myVersion = $this->getPHPVersion();
199 } elseif ($type == 'MySQL') {
200 $myVersion = $this->getMySQLVersion();
203 if ($myVersion != null && $operator != null) {
204 return version_compare($myVersion, $version, $operator);
210 * Returns the PHP version
212 * @return string PHP version
214 protected function getPHPVersion()
220 * Returns the MySQL version
222 * @return string MySQL version
224 protected function getMySQLVersion()
226 return PMA_MYSQL_STR_VERSION
;