[Rt-commit] [rtir] 03/05: Upgrade and use Module::Install::RTx::rt_too_new
Kevin Falcone
falcone at bestpractical.com
Tue Jan 14 22:21:36 EST 2014
This is an automated email from the git hooks/post-receive script.
falcone pushed a commit to branch 3.0-trunk
in repository rtir.
commit 5da584f90f242f509e0b34c15d405e0a6a2ed8c0
Author: Kevin Falcone <falcone at bestpractical.com>
Date: Wed Jan 8 16:17:44 2014 -0500
Upgrade and use Module::Install::RTx::rt_too_new
Allows us to explode nicely when people try to install on RT 4.2.x
---
Makefile.PL | 1 +
inc/Module/Install/RTx.pm | 60 +++++++++++++++++++++------------------
inc/Module/Install/RTx/Factory.pm | 3 ++
3 files changed, 36 insertions(+), 28 deletions(-)
diff --git a/Makefile.PL b/Makefile.PL
index b9d1cfc..11bf791 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -7,6 +7,7 @@ all_from('lib/RT/IR.pm');
# update README and docs/UPGRADING
requires_rt('4.0.14');
+rt_too_new('4.2.0',"\nRTIR 3.0.x is only compatible with RT 4.0.x and you are using RT %s\n");
# XXX: This should be reported by M::I::RTx
my ($lib_path) = $INC{'RT.pm'} =~ /^(.*)[\\\/]/;
diff --git a/inc/Module/Install/RTx.pm b/inc/Module/Install/RTx.pm
index e5558d4..b2c1e0c 100644
--- a/inc/Module/Install/RTx.pm
+++ b/inc/Module/Install/RTx.pm
@@ -8,7 +8,7 @@ no warnings 'once';
use Module::Install::Base;
use base 'Module::Install::Base';
-our $VERSION = '0.31';
+our $VERSION = '0.32_01';
use FindBin;
use File::Glob ();
@@ -174,46 +174,50 @@ install ::
}
}
-# stolen from RT::Handle so we work on 3.6 (cmp_versions came in with 3.8)
-{ my %word = (
- a => -4,
- alpha => -4,
- b => -3,
- beta => -3,
- pre => -2,
- rc => -1,
- head => 9999,
-);
-sub cmp_version($$) {
- my ($a, $b) = (@_);
- my @a = grep defined, map { /^[0-9]+$/? $_ : /^[a-zA-Z]+$/? $word{$_}|| -10 : undef }
- split /([^0-9]+)/, $a;
- my @b = grep defined, map { /^[0-9]+$/? $_ : /^[a-zA-Z]+$/? $word{$_}|| -10 : undef }
- split /([^0-9]+)/, $b;
- @a > @b
- ? push @b, (0) x (@a- at b)
- : push @a, (0) x (@b- at a);
- for ( my $i = 0; $i < @a; $i++ ) {
- return $a[$i] <=> $b[$i] if $a[$i] <=> $b[$i];
- }
- return 0;
-}}
sub requires_rt {
my ($self,$version) = @_;
# if we're exactly the same version as what we want, silently return
return if ($version eq $RT::VERSION);
- my @sorted = sort cmp_version $version,$RT::VERSION;
+ _load_rt_handle();
+ my @sorted = sort RT::Handle::cmp_version $version,$RT::VERSION;
if ($sorted[-1] eq $version) {
# should we die?
- warn "\nWarning: prerequisite RT $version not found. Your installed version of RT ($RT::VERSION) is too old.\n\n";
+ die "\nWarning: prerequisite RT $version not found. Your installed version of RT ($RT::VERSION) is too old.\n\n";
+ }
+}
+
+sub rt_too_new {
+ my ($self,$version,$msg) = @_;
+ $msg ||= "Your version %s is too new, this extension requires a release of RT older than %s";
+
+ _load_rt_handle();
+ my @sorted = sort RT::Handle::cmp_version $version,$RT::VERSION;
+
+ if ($sorted[0] eq $version) {
+ die sprintf($msg,$RT::VERSION,$version);
+ }
+}
+
+# RT::Handle runs FinalizeDatabaseType which calls RT->Config->Get
+# On 3.8, this dies. On 4.0/4.2 ->Config transparently runs LoadConfig.
+# LoadConfig requires being able to read RT_SiteConfig.pm (root) so we'd
+# like to avoid pushing that on users.
+# Fake up just enough Config to let FinalizeDatabaseType finish, and
+# anyone later calling LoadConfig will overwrite our shenanigans.
+sub _load_rt_handle {
+ unless ($RT::Config) {
+ require RT::Config;
+ $RT::Config = RT::Config->new;
+ RT->Config->Set('DatabaseType','mysql');
}
+ require RT::Handle;
}
1;
__END__
-#line 336
+#line 360
diff --git a/inc/Module/Install/RTx/Factory.pm b/inc/Module/Install/RTx/Factory.pm
index 8015792..6776688 100644
--- a/inc/Module/Install/RTx/Factory.pm
+++ b/inc/Module/Install/RTx/Factory.pm
@@ -38,6 +38,9 @@ sub RTxInitDB {
"--prompt-for-dba-password" => '',
(RT::System->can('AddUpgradeHistory') ? ("--package" => $name, "--ext-version" => $version) : ()),
);
+ # If we're upgrading against an RT which isn't at least 4.2 (has
+ # AddUpgradeHistory) then pass --package. Upgrades against later RT
+ # releases will pick up --package from AddUpgradeHistory.
if ($action eq 'upgrade' and
not RT::System->can('AddUpgradeHistory')) {
push @args, "--package" => $name;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the rt-commit
mailing list