Skip to content

Commit

Permalink
Fix version comparisons with -stable suffix (#1488876)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecpl committed Dec 20, 2012
1 parent a8ffab3 commit a079269
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/installto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions bin/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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");


Expand Down Expand Up @@ -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');
}

Expand Down
6 changes: 3 additions & 3 deletions installer/rcube_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions program/lib/Roundcube/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,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
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Framework/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

@nuxwin nuxwin commented on a079269 Dec 20, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.