2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Responsible for retrieving version information and notifiying about latest version
11 use PhpMyAdmin\Utils\HttpRequest
;
14 * Responsible for retrieving version information and notifiying about latest version
19 class VersionInformation
22 * Returns information with latest version from phpmyadmin.net
24 * @return object JSON decoded object with the data
26 public function getLatestVersion()
28 if (!$GLOBALS['cfg']['VersionCheck']) {
32 // Get response text from phpmyadmin.net or from the session
33 // Update cache every 6 hours
34 if (isset($_SESSION['cache']['version_check'])
35 && time() < $_SESSION['cache']['version_check']['timestamp'] +
3600 * 6
38 $response = $_SESSION['cache']['version_check']['response'];
41 $file = 'https://www.phpmyadmin.net/home_page/version.json';
42 $httpRequest = new HttpRequest();
43 $response = $httpRequest->create($file, 'GET');
45 $response = $response ?
$response : '{}';
47 $data = json_decode($response);
49 /* Basic sanity checking */
50 if (! is_object($data)
51 ||
empty($data->version
)
52 ||
empty($data->releases
)
59 $_SESSION['cache']['version_check'] = array(
60 'response' => $response,
68 * Calculates numerical equivalent of phpMyAdmin version string
70 * @param string $version version
72 * @return mixed false on failure, integer on success
74 public function versionToInt($version)
76 $parts = explode('-', $version);
77 if (count($parts) > 1) {
82 $parts = explode('.', $parts[0]);
86 if (count($parts) >= 1 && is_numeric($parts[0])) {
87 $result +
= 1000000 * $parts[0];
90 if (count($parts) >= 2 && is_numeric($parts[1])) {
91 $result +
= 10000 * $parts[1];
94 if (count($parts) >= 3 && is_numeric($parts[2])) {
95 $result +
= 100 * $parts[2];
98 if (count($parts) >= 4 && is_numeric($parts[3])) {
99 $result +
= 1 * $parts[3];
102 if (!empty($suffix)) {
104 if (preg_match('/^(\D+)(\d+)$/', $suffix, $matches)) {
105 $suffix = $matches[1];
106 $result +
= intval($matches[2]);
126 $result +
= 50; // for final
133 * Returns the version and date of the latest phpMyAdmin version compatible
134 * with the available PHP and MySQL versions
136 * @param array $releases array of information related to each version
138 * @return array containing the version and date of latest compatible version
140 public function getLatestCompatibleVersion(array $releases)
142 foreach ($releases as $release) {
143 $phpVersions = $release->php_versions
;
144 $phpConditions = explode(",", $phpVersions);
145 foreach ($phpConditions as $phpCondition) {
146 if (! $this->evaluateVersionCondition("PHP", $phpCondition)) {
151 // We evalute MySQL version constraint if there are only
152 // one server configured.
153 if (count($GLOBALS['cfg']['Servers']) == 1) {
154 $mysqlVersions = $release->mysql_versions
;
155 $mysqlConditions = explode(",", $mysqlVersions);
156 foreach ($mysqlConditions as $mysqlCondition) {
157 if (!$this->evaluateVersionCondition('MySQL', $mysqlCondition)) {
164 'version' => $release->version
,
165 'date' => $release->date
,
169 // no compatible version
174 * Checks whether PHP or MySQL version meets supplied version condition
176 * @param string $type PHP or MySQL
177 * @param string $condition version condition
179 * @return boolean whether the condition is met
181 public function evaluateVersionCondition($type, $condition)
184 $operators = array("<=", ">=", "!=", "<>", "<", ">", "="); // preserve order
185 foreach ($operators as $oneOperator) {
186 if (strpos($condition, $oneOperator) === 0) {
187 $operator = $oneOperator;
188 $version = substr($condition, strlen($oneOperator));
194 if ($type == 'PHP') {
195 $myVersion = $this->getPHPVersion();
196 } elseif ($type == 'MySQL') {
197 $myVersion = $this->getMySQLVersion();
200 if ($myVersion != null && $operator != null) {
201 return version_compare($myVersion, $version, $operator);
207 * Returns the PHP version
209 * @return string PHP version
211 protected function getPHPVersion()
217 * Returns the MySQL version if connected to a database
219 * @return string MySQL version
221 protected function getMySQLVersion()
223 if (isset($GLOBALS['dbi'])) {
224 return $GLOBALS['dbi']->getVersionString();