X-Git-Url: http://git.home-dn.net/?p=manu%2FRT-Extension-SearchResults-ODS.git;a=blobdiff_plain;f=inc%2FModule%2FInstall%2FRTx%2FFactory.pm;fp=inc%2FModule%2FInstall%2FRTx%2FFactory.pm;h=6776688ee18528eb366792806bced1ff43c16e7a;hp=0000000000000000000000000000000000000000;hb=8c7186545d13b38783caf887a92871536aa01d18;hpb=d4074b22b5c51361a938461b25bbc68acb6d31f2 diff --git a/inc/Module/Install/RTx/Factory.pm b/inc/Module/Install/RTx/Factory.pm new file mode 100644 index 0000000..6776688 --- /dev/null +++ b/inc/Module/Install/RTx/Factory.pm @@ -0,0 +1,53 @@ +#line 1 +package Module::Install::RTx::Factory; +use Module::Install::Base; @ISA = qw(Module::Install::Base); + +use strict; +use File::Basename (); + +sub RTxInitDB { + my ($self, $action, $name, $version) = @_; + + unshift @INC, substr(delete($INC{'RT.pm'}), 0, -5) if $INC{'RT.pm'}; + + require RT; + unshift @INC, "$RT::LocalPath/lib" if $RT::LocalPath; + + $RT::SbinPath ||= $RT::LocalPath; + $RT::SbinPath =~ s/local$/sbin/; + + foreach my $file ($RT::CORE_CONFIG_FILE, $RT::SITE_CONFIG_FILE) { + next if !-e $file or -r $file; + die "No permission to read $file\n-- please re-run $0 with suitable privileges.\n"; + } + + RT::LoadConfig(); + + require RT::System; + + my $lib_path = File::Basename::dirname($INC{'RT.pm'}); + my @args = ("-Ilib"); + push @args, "-I$RT::LocalPath/lib" if $RT::LocalPath; + push @args, ( + "-I$lib_path", + "$RT::SbinPath/rt-setup-database", + "--action" => $action, + ($action eq 'upgrade' ? () : ("--datadir" => "etc")), + (($action eq 'insert') ? ("--datafile" => "etc/initialdata") : ()), + "--dba" => $RT::DatabaseAdmin || $RT::DatabaseUser, + "--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; + } + + print "$^X @args\n"; + (system($^X, @args) == 0) or die "...returned with error: $?\n"; +} + +1;