+sub action_indexes {
+ my %args = @_;
+ RT->ConnectToDatabase;
+ my $individual_id = Data::GUID->new->as_string();
+ my %upgrade_data = (
+ action => 'indexes',
+ filename => Cwd::abs_path($args{'datafile'} || $args{'datadir'} || ''),
+ stage => 'before',
+ full_id => $full_id,
+ individual_id => $individual_id,
+ );
+ $upgrade_data{'ext_version'} = $ext_version if $ext_version;
+ RT->System->AddUpgradeHistory($package => \%upgrade_data) if $log_actions;
+
+ my $dbh = get_admin_dbh();
+ $RT::Handle = RT::Handle->new;
+ $RT::Handle->dbh( $dbh );
+ RT::InitLogging();
+
+ print "Now inserting database indexes.\n";
+ my @ret = RT::Handle->InsertIndexes( $dbh, $args{'datafile'} || $args{'datadir'} );
+
+ $RT::Handle = RT::Handle->new;
+ $RT::Handle->dbh( undef );
+ RT->ConnectToDatabase;
+ %upgrade_data = (
+ stage => 'after',
+ individual_id => $individual_id,
+ return_value => [ @ret ],
+ );
+ RT->System->AddUpgradeHistory($package => \%upgrade_data) if $log_actions;
+
+ return @ret;
+}
+
+sub action_coredata {
+ my %args = @_;
+ $RT::Handle = RT::Handle->new;
+ $RT::Handle->dbh( undef );
+ RT::ConnectToDatabase();
+ my ($status, $msg) = RT::Handle->CheckCompatibility( $RT::Handle->dbh, 'coredata' );
+ return ($status, $msg) unless $status;
+
+ print "Now inserting RT core system objects.\n";
+ return $RT::Handle->InsertInitialData;
+}
+
+sub action_insert {
+ state $RAN_INIT;
+ my %args = @_;
+ unless ($RAN_INIT) {
+ $RT::Handle = RT::Handle->new;
+ RT::Init();
+ $RAN_INIT++;
+ }
+ $log_actions = 1;
+
+ my ($status, $msg) = RT::Handle->CheckCompatibility( $RT::Handle->dbh, 'insert' );
+ return ($status, $msg) unless $status;
+
+ print "Now inserting data.\n";
+ my $file = $args{'datafile'};
+ $file = $RT::EtcPath . "/initialdata" if $init && !$file;
+ $file ||= $args{'datadir'}."/content";
+
+ my $individual_id = Data::GUID->new->as_string();
+ my %upgrade_data = (
+ action => 'insert',
+ filename => Cwd::abs_path($file),
+ stage => 'before',
+ full_id => $full_id,
+ individual_id => $individual_id
+ );
+ $upgrade_data{'ext_version'} = $ext_version if $ext_version;
+
+ open my $handle, '<', $file or warn "Unable to open $file: $!";
+ $upgrade_data{content} = do {local $/; <$handle>} if $handle;
+
+ RT->System->AddUpgradeHistory($package => \%upgrade_data);
+
+ my @ret;
+
+ my $upgrade = sub { @ret = $RT::Handle->InsertData( $file, $root_password ) };
+
+ for my $file (@{$args{backcompat} || []}) {
+ my $lines = do {local $/; local @ARGV = ($file); <>};
+ my $sub = eval "sub {\n# line 1 $file\n$lines\n}";
+ unless ($sub) {
+ warn "Failed to load backcompat $file: $@";
+ next;
+ }
+ my $current = $upgrade;
+ $upgrade = sub { $sub->($current) };