Permalink
Browse files

Fix version comparisons with -stable suffix (#1488876)

  • Loading branch information...
1 parent a8ffab3 commit a079269166d120bcbcb33d34f4b1c8f60d102e32 @alecpl alecpl committed Dec 20, 2012
Showing with 31 additions and 6 deletions.
  1. +1 −0 CHANGELOG
  2. +1 −1 bin/installto.sh
  3. +2 −2 bin/update.sh
  4. +3 −3 installer/rcube_install.php
  5. +16 −0 program/lib/Roundcube/bootstrap.php
  6. +8 −0 tests/Framework/Bootstrap.php
View
@@ -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
View
@@ -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";
View
@@ -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');
}
@@ -633,8 +633,8 @@ function init_db($DB)
*/
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 @@ function update_db($DB, $version)
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;
}
@@ -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'))
@@ -207,4 +207,12 @@ function test_is_ascii()
$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'));
+ }
}

1 comment on commit a079269

nuxwin commented on a079269 Dec 20, 2012

Ok then, you fixed in hard way. I do that for my own perl roundcube installer:

...
$fromVersion =~ s/-stable/.0/; # stable is lower than beta and alpha

open my($file), '<', "$main::imscpConfig{'GUI_PUBLIC_DIR'}/tools/webmail/SQL/mysql.update.sql"
    or die "Couldn't found the Roundcube database schema update file : $!\n";

my $from = 0;
my $sql = '';

while(my $line = <$file>) {
    chomp($line);
    next if ! $line; # skip empty line
    my $isComment = (index($line, '--') == 0);

    if(! $from && $isComment && $line =~ /from version\s([0-9.]+[a-z-]*)/) {
        my $fileVersion = lc($1);
        $fileVersion =~ s/-stable/.0/;

        if(
            $fileVersion eq $fromVersion ||
            `$main::imscpConfig{'PHP_CMD'} -r "print (version_compare('$version', '$fileVersion', '<='));"`
        ) {
            $from = 1;
        }
    }

    if($from && ! $isComment) {
        $sql .= $line . "\n";
    }
}
...
Please sign in to comment.