summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-12-20 08:53:48 +0100
committerAleksander Machniak <alec@alec.pl>2012-12-20 08:53:48 +0100
commita079269166d120bcbcb33d34f4b1c8f60d102e32 (patch)
treec3ae8596608e94e58ab1624ef78b8ef33c5323a0
parenta8ffab3f4ff54af41c9041a30eb989954d6ffc17 (diff)
Fix version comparisons with -stable suffix (#1488876)
-rw-r--r--CHANGELOG1
-rwxr-xr-xbin/installto.sh2
-rwxr-xr-xbin/update.sh4
-rw-r--r--installer/rcube_install.php6
-rw-r--r--program/lib/Roundcube/bootstrap.php16
-rw-r--r--tests/Framework/Bootstrap.php8
6 files changed, 31 insertions, 6 deletions
diff --git a/CHANGELOG b/CHANGELOG
index c4e63aaeb..02e20455c 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
CHANGELOG Roundcube Webmail
===========================
+- Fix version comparisons with -stable suffix (#1488876)
- Add unsupported alternative parts to attachments list (#1488870)
- Add Compose button on message view page (#1488747)
- Display 'Sender' header in message preview
diff --git a/bin/installto.sh b/bin/installto.sh
index de96bf004..e6cf79d7d 100755
--- a/bin/installto.sh
+++ b/bin/installto.sh
@@ -35,7 +35,7 @@ if (!preg_match('/define\(.RCMAIL_VERSION.,\s*.([0-9.]+[a-z-]*)/', $iniset, $m))
$oldversion = $m[1];
-if (version_compare($oldversion, RCMAIL_VERSION, '>='))
+if (version_compare(version_parse($oldversion), version_parse(RCMAIL_VERSION), '>='))
die("Installation at target location is up-to-date!\n");
echo "Upgrading from $oldversion. Do you want to continue? (y/N)\n";
diff --git a/bin/update.sh b/bin/update.sh
index 59aa596dd..2015aa904 100755
--- a/bin/update.sh
+++ b/bin/update.sh
@@ -34,7 +34,7 @@ if (!$opts['version']) {
$opts['version'] = $input;
}
-if ($opts['version'] && version_compare($opts['version'], RCMAIL_VERSION, '>'))
+if ($opts['version'] && version_compare(version_parse($opts['version']), version_parse(RCMAIL_VERSION), '>'))
die("Nothing to be done here. Bye!\n");
@@ -169,7 +169,7 @@ if ($RCI->configured) {
}
// index contacts for fulltext searching
- if (version_compare($opts['version'], '0.6', '<')) {
+ if (version_compare(version_parse($opts['version']), '0.6.0', '<')) {
system(INSTALL_PATH . 'bin/indexcontacts.sh');
}
diff --git a/installer/rcube_install.php b/installer/rcube_install.php
index dfd63562d..530be3ebe 100644
--- a/installer/rcube_install.php
+++ b/installer/rcube_install.php
@@ -633,8 +633,8 @@ class rcube_install
*/
function update_db($DB, $version)
{
- $version = strtolower($version);
- $engine = isset($this->db_map[$DB->db_provider]) ? $this->db_map[$DB->db_provider] : $DB->db_provider;
+ $version = version_parse(strtolower($version));
+ $engine = isset($this->db_map[$DB->db_provider]) ? $this->db_map[$DB->db_provider] : $DB->db_provider;
// read schema file from /SQL/*
$fname = INSTALL_PATH . "SQL/$engine.update.sql";
@@ -643,7 +643,7 @@ class rcube_install
foreach ($lines as $line) {
$is_comment = preg_match('/^--/', $line);
if (!$from && $is_comment && preg_match('/from version\s([0-9.]+[a-z-]*)/', $line, $m)) {
- $v = strtolower($m[1]);
+ $v = version_parse(strtolower($m[1]));
if ($v == $version || version_compare($version, $v, '<='))
$from = true;
}
diff --git a/program/lib/Roundcube/bootstrap.php b/program/lib/Roundcube/bootstrap.php
index 18c07ddab..530a7f855 100644
--- a/program/lib/Roundcube/bootstrap.php
+++ b/program/lib/Roundcube/bootstrap.php
@@ -358,6 +358,22 @@ function format_email($email)
/**
+ * Fix version number so it can be used correctly in version_compare()
+ *
+ * @param string $version Version number string
+ *
+ * @param return Version number string
+ */
+function version_parse($version)
+{
+ return str_replace(
+ array('-stable', '-git'),
+ array('.0', '.99'),
+ $version);
+}
+
+
+/**
* mbstring replacement functions
*/
if (!extension_loaded('mbstring'))
diff --git a/tests/Framework/Bootstrap.php b/tests/Framework/Bootstrap.php
index d18fd371b..904be7e3b 100644
--- a/tests/Framework/Bootstrap.php
+++ b/tests/Framework/Bootstrap.php
@@ -207,4 +207,12 @@ class Framework_Bootstrap extends PHPUnit_Framework_TestCase
$this->assertFalse($result, "Invalid ASCII (UTF-8 character [2])");
}
+ /**
+ * bootstrap.php: version_parse()
+ */
+ function test_version_parse()
+ {
+ $this->assertEquals('0.9.0', version_parse('0.9-stable'));
+ $this->assertEquals('0.9.99', version_parse('0.9-git'));
+ }
}