Initial release
[manu/RT-Extension-AttachmentFilter.git] / inc / Module / Install / RTx / Factory.pm
1 #line 1
2 package Module::Install::RTx::Factory;
3 use Module::Install::Base; @ISA = qw(Module::Install::Base);
4
5 use strict;
6 use File::Basename ();
7
8 sub RTxInitDB {
9     my ($self, $action, $name, $version) = @_;
10
11     unshift @INC, substr(delete($INC{'RT.pm'}), 0, -5) if $INC{'RT.pm'};
12
13     require RT;
14     unshift @INC, "$RT::LocalPath/lib" if $RT::LocalPath;
15
16     $RT::SbinPath ||= $RT::LocalPath;
17     $RT::SbinPath =~ s/local$/sbin/;
18
19     foreach my $file ($RT::CORE_CONFIG_FILE, $RT::SITE_CONFIG_FILE) {
20         next if !-e $file or -r $file;
21         die "No permission to read $file\n-- please re-run $0 with suitable privileges.\n";
22     }
23
24     RT::LoadConfig();
25
26     require RT::System;
27
28     my $lib_path = File::Basename::dirname($INC{'RT.pm'});
29     my @args = ("-Ilib");
30     push @args, "-I$RT::LocalPath/lib" if $RT::LocalPath;
31     push @args, (
32         "-I$lib_path",
33         "$RT::SbinPath/rt-setup-database",
34         "--action"      => $action,
35         ($action eq 'upgrade' ? () : ("--datadir"     => "etc")),
36         (($action eq 'insert') ? ("--datafile"    => "etc/initialdata") : ()),
37         "--dba"         => $RT::DatabaseAdmin || $RT::DatabaseUser,
38         "--prompt-for-dba-password" => '',
39         (RT::System->can('AddUpgradeHistory') ? ("--package" => $name, "--ext-version" => $version) : ()),
40     );
41     # If we're upgrading against an RT which isn't at least 4.2 (has
42     # AddUpgradeHistory) then pass --package.  Upgrades against later RT
43     # releases will pick up --package from AddUpgradeHistory.
44     if ($action eq 'upgrade' and
45         not RT::System->can('AddUpgradeHistory')) {
46         push @args, "--package" => $name;
47     }
48
49     print "$^X @args\n";
50     (system($^X, @args) == 0) or die "...returned with error: $?\n";
51 }
52
53 1;