Skip to content

Commit 7ed8976

Browse files
committed
Get the installed version from the config table.
Show update available only when the installed version is lower than the latest version.
1 parent 273034d commit 7ed8976

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

index.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ public function availableUpdate()
8383
*/
8484
public function getCurrentVersion()
8585
{
86-
$version = file_get_contents('../admin/init.php');
87-
$matches = array();
88-
preg_match_all('/define\(\"VERSION\",\"(.*)\"\);/', $version, $matches);
86+
$table_name = $this->table_prefix . 'config';
87+
$prepStmt = $this->getConnection()->prepare("SELECT value FROM {$table_name} WHERE item=?");
88+
$prepStmt->execute(['version']);
89+
$result = $prepStmt->fetch(PDO::FETCH_ASSOC);
8990

90-
if (isset($matches[1][0])) {
91-
return $matches[1][0];
91+
if ($result === false) {
92+
throw new UpdateException('No production version found.');
9293
}
9394

94-
throw new UpdateException('No production version found.');
95-
95+
return $result['value'];
9696
}
9797

9898
/**
@@ -103,18 +103,25 @@ public function getCurrentVersion()
103103
function checkIfThereIsAnUpdate()
104104
{
105105
$serverResponse = $this->getResponseFromServer();
106-
$version = isset($serverResponse['version']) ? $serverResponse['version'] : '';
107106

108-
$versionString = isset($serverResponse['versionstring']) ? $serverResponse['versionstring'] : '';
109-
if ($version !== '' && $version !== $this->getCurrentVersion() && version_compare($this->getCurrentVersion(), $version)) {
110-
$this->availableUpdate = true;
111-
$updateMessage = 'Update to ' . htmlentities($versionString) . ' is available. ';
107+
if (isset($serverResponse['version']) && isset($serverResponse['versionstring'])) {
108+
$version = $serverResponse['version'];
109+
$versionString = $serverResponse['versionstring'];
110+
111+
if (version_compare($this->getCurrentVersion(), $version) < 0) {
112+
$this->availableUpdate = true;
113+
$updateMessage = 'Update to ' . htmlentities($versionString) . ' is available. ';
114+
115+
if (isset($serverResponse['autoupdater'])
116+
&& !($serverResponse['autoupdater'] === 1 || $serverResponse['autoupdater'] === '1')) {
117+
$this->availableUpdate = false;
118+
$updateMessage .= '<br />The automatic updater is disabled for this update.';
119+
}
120+
} else {
121+
$updateMessage = 'phpList is up-to-date.';
122+
}
112123
} else {
113-
$updateMessage = 'phpList is up-to-date.';
114-
}
115-
if ($this->availableUpdate && isset($serverResponse['autoupdater']) && !($serverResponse['autoupdater'] === 1 || $serverResponse['autoupdater'] === '1')) {
116-
$this->availableUpdate = false;
117-
$updateMessage .= '<br />The automatic updater is disabled for this update.';
124+
$updateMessage = 'Unable to identify new version';
118125
}
119126

120127
return $updateMessage;
@@ -802,7 +809,6 @@ function replaceNewUpdater()
802809
echo json_encode(array('status' => $statusJson, 'autocontinue' => true));
803810
break;
804811
case 1:
805-
$currentVersion = $update->getCurrentVersion();
806812
$updateMessage = $update->checkIfThereIsAnUpdate();
807813
$isThereAnUpdate = $update->availableUpdate();
808814
if ($isThereAnUpdate === false) {

0 commit comments

Comments
 (0)