Commit 3f9855a2 authored by chealer's avatar chealer

[FIX] Strange message "A new major release branch is available." mentioning...

[FIX] Strange message "A new major release branch is available." mentioning current version as if it was new
go a long way towards properly encapsulating TWVersion
parent 2b6c8224
......@@ -6,41 +6,41 @@
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for
// details.
// Class written by Mike Kerr (kerrnel22, tiki-kerrnel@kerris.com)
// March 2008
// This script may only be included - so its better to die if called directly.
// Should generally be instatiated from tiki-setup.php
// Should generally be instantiated from tiki-setup.php
class TWVersion {
var $branch; // Development cycle
var $version; // This version
var $release; // Current release in same version tree
private $latestMinorRelease; // Latest release in the same major version release series
private $latestRelease; // Latest release
private $isLatestMajorVersion; // Whether or not the current major version is the latest
var $releases; // Array of all releases from website
var $ridx; // Associative array pointing versions to release index
var $vidx; // Index where this version appears in releases array
var $star; // Star being used for this version tree
var $svn; // Is this a Subversion version or a package?
function TWVersion() {
// Set the development branch. Valid are:
// stable : Represents officially supported releases.
// stable : Represents stable releases.
// unstable : Represents candidate and test/development releases.
// head : Represents next generation development version.
$this->branch = 'stable';
// Set everything else, including defaults.
$this->version = '4.0';
$this->version = '3.2';
$this->star = 'Aldebaran';
$this->release = $this->version;
$this->releases = array();
$this->ridx = array();
$this->vidx = 0;
// Check for Subversion or not
$this->svn = is_dir('.svn') ? 'y' : 'n';
}
// Returns the latest minor release in the same major version release series.
function getLatestMinorRelease()
{
$this->pollVersion();
return $this->latestMinorRelease;
}
function getBaseVersion()
{
return preg_replace( "/^(\d+\.\d+).*$/", '$1', $this->version );
......@@ -119,76 +119,50 @@ class TWVersion {
// Determines the currently-running version of Tikiwiki.
function getVersion() {
$versions = $this->tikiVersions();
$version = $versions[count($versions)];
return $version;
}
// Pulls the list of releases in the current branch of Tikiwiki from
// a central site.
function pollVersion() {
$fp = fsockopen("tikiwiki.org", 80, $errno, $errstr, 10);
if ($fp) {
$send = "GET /" . $this->branch . ".version HTTP/1.1\r\n";
$send .= "Host: tikiwiki.org\r\n";
$send .= "Connection: Close\r\n\r\n";
fputs ($fp, $send);
// The last line of response will be the version.
$payload = 0;
while ($instr = rtrim(fgets($fp))) {
// Get to the text of the file, and ignoring the blank line
// between the content-type coding and the actual payload data.
if (substr($instr, 14, 10) == 'text/plain') {
$instr = fgets($fp);
$instr = fgets($fp);
$payload = 1;
}
// If we've reached the actual text of the file we're
// trying to retrieve, then proceed.
if ($payload) {
$count = array_push($this->releases, $instr);
$this->ridx[$instr] = $count - 1;
if ($instr == $this->version) {
$this->vidx = $this->ridx[$instr];
}
private function pollVersion() {
static $done = false;
if ($done) {
return;
}
global $tikilib;
$upgrade = 0;
$major = 0;
$velements = explode('.', $this->version);
$body = $tikilib->httprequest("tikiwiki.org/" . $this->branch . '.version'); // .version contains an ordered list of release numbers, one per line. All minor releases from a same major release are grouped.
$lines = explode("\n", $body);
$this->isLatestMajorVersion = true;
foreach ($lines as $line) {
$relements = explode('.', $line);
if (isset($relements[0]) && is_numeric($relements[0])) { // Avoid issues with empty lines
$line = rtrim($line);
$count = array_push($this->releases, $line);
if ($relements[0] == $velements[0]) {
$this->latestMinorRelease = $line;
} elseif ($relements[0] > $velements[0]) {
$this->isLatestMajorVersion = false;
}
$this->latestRelease = $line;
}
}
$done = true;
}
// Returns true if the current major version is the latest, false otherwise.
function isLatestMajorVersion()
{
$this->pollVersion();
return $this->isLatestMajorVersion;
}
// Compare this version to the list and see if there are any releases after
// it. Distinguish between upgrades and major releases and return flags
// for both.
function newVersionAvailable() {
if (count($this->releases) == 0) {
$upgrade = 0;
$major = 0;
} else {
// Start at the VIDX index, and go through the rest of the
// ->releases. Ignore releases that have a bigger a or b
// number (eg. A.B.C = 1.9.3; ignore 1.10 or 2.x)
// Store the newest version in the tree in ->release.
$upgrade = 0;
$major = 0;
$velements = explode('.', $this->version);
for ($idx = $this->vidx + 1; $idx < count($this->releases); $idx++) {
$relements = explode('.', $this->releases[$idx]);
if ($relements[0] > $velements[0]) {
$major = 1;
} else if ($relements[0] == $velements[0]) {
$this->release = $this->releases[$idx];
$upgrade = 1;
}
}
}
return array($upgrade, $major);
// Returns true if the current version is the latest in its major version release series, false otherwise.
function isLatestMinorRelease()
{
$this->pollVersion();
return $this->latestMinorRelease == $this->version || version_compare($this->version, $this->latestRelease) == 1;
}
}
......@@ -379,10 +379,8 @@ if (isset($admintitle)) {
// VERSION TRACKING
// If the user elected to force a check.
if (!empty($_GET['forcecheck'])) {
$TWV->pollVersion();
$upgrades = $TWV->newVersionAvailable();
$smarty->assign('tiki_release', $TWV->release);
if ($upgrades[0]) {
$smarty->assign('tiki_release', $TWV->getLatestMinorRelease());
if (!$TWV->isLatestMinorRelease()) {
$prefs['tiki_needs_upgrade'] = 'y';
} else {
$prefs['tiki_needs_upgrade'] = 'n';
......@@ -390,8 +388,8 @@ if (!empty($_GET['forcecheck'])) {
}
$smarty->assign('tiki_needs_upgrade', $prefs['tiki_needs_upgrade']);
// See if a major release is available.
if ($upgrades[1]) {
add_feedback( null, tr('A new %0 major release branch is available.', $TWV->version ), 3 );
if (!$TWV->isLatestMajorVersion()) {
add_feedback( null, tr('A new major release branch is available.'), 3 );
}
// If the versioning feature has been enabled, then store the current
// findings in the database as preferences so that each visit to the page
......@@ -399,7 +397,7 @@ if (!empty($_GET['forcecheck'])) {
// check on every page load.
if ($prefs['feature_version_checks'] == 'y') {
$tikilib->set_preference('tiki_needs_upgrade', $prefs['tiki_needs_upgrade']);
$tikilib->set_preference('tiki_release', $TWV->release);
$tikilib->set_preference('tiki_release', $TWV->getLatestMinorRelease());
}
}
// Versioning feature has been enabled, so if the time is right, do a live
......@@ -411,14 +409,12 @@ if ($prefs['feature_version_checks'] == 'y') {
// Time for a version check!
if ($tikilib->now > ($prefs['tiki_version_last_check'] + $prefs['tiki_version_check_frequency'])) {
$tikilib->set_preference('tiki_version_last_check', $tikilib->now);
$TWV->pollVersion();
$smarty->assign('tiki_version', $TWV->version);
$upgrades = $TWV->newVersionAvailable();
if ($upgrades[0]) {
if (!$TWV->isLatestMinorRelease()) {
$prefs['tiki_needs_upgrade'] = 'y';
$tikilib->set_preference('tiki_release', $TWV->release);
$smarty->assign('tiki_release', $TWV->release);
if ($upgrades[1]) {
$tikilib->set_preference('tiki_release', $TWV->getLatestMinorRelease());
$smarty->assign('tiki_release', $TWV->getLatestMinorRelease());
if (!$TWV->isLatestMajorVersion()) {
add_feedback( null, tr('A new %0 major release branch is available.', $TWV->branch), 3, 1);
}
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment