Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bestpractical/rt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Brandt <jbrandt@bestpractical.com>2022-07-22 22:02:02 +0300
committerJim Brandt <jbrandt@bestpractical.com>2022-07-22 22:02:02 +0300
commit503b397a79942f20a6ba5a2abb3fc64721ae3e31 (patch)
tree25386b4bc898c6eae1e7be49d82b9d6d92dbcf41
parentc3ae9627d609d40a492962093b2c6a4ecf4396e9 (diff)
parente0accff2f43bb3f8a8052d87f7758ed8533dc3ca (diff)
Merge branch '4.4/importer-no-auto-commit-handle-originalid' into 4.4-trunk
-rw-r--r--lib/RT/Migrate/Importer/File.pm16
-rw-r--r--sbin/rt-importer.in2
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/RT/Migrate/Importer/File.pm b/lib/RT/Migrate/Importer/File.pm
index 9be70cc449..52e6294565 100644
--- a/lib/RT/Migrate/Importer/File.pm
+++ b/lib/RT/Migrate/Importer/File.pm
@@ -106,6 +106,7 @@ sub Import {
or die "Can't seek to $self->{Seek} in $self->{Filename}";
$self->{Seek} = undef;
}
+ $RT::Handle->BeginTransaction() unless $self->{AutoCommit};
while (not eof($fh)) {
$self->{Position} = tell($fh);
@@ -114,7 +115,7 @@ sub Import {
$self->ReadStream( $fh );
}
- RT->DatabaseHandle->dbh->commit unless $self->{AutoCommit};
+ $RT::Handle->Commit() unless $self->{AutoCommit};
}
$self->CloseStream;
@@ -184,6 +185,19 @@ sub RestoreState {
sub SaveState {
my $self = shift;
+ unless ( $self->{AutoCommit} ) {
+ for my $depth ( reverse 1 .. ( $RT::Handle->TransactionDepth || 0 ) ) {
+ if ( $depth == 1 ) {
+ # This is the transaction we added for AutoCommit
+ $RT::Handle->Commit;
+ }
+ else {
+ # If there are nested transactions unfinished yet, roll them back.
+ $RT::Handle->Rollback;
+ }
+ }
+ }
+
RT->DatabaseHandle->dbh->commit unless $self->{AutoCommit};
my %data;
diff --git a/sbin/rt-importer.in b/sbin/rt-importer.in
index 7263e78d70..219e34534e 100644
--- a/sbin/rt-importer.in
+++ b/sbin/rt-importer.in
@@ -144,8 +144,6 @@ elsif ($OPT{'ignore-errors'}) {
};
}
-RT->DatabaseHandle->AutoCommit(0) unless $OPT{'auto-commit'};
-
my $import = RT::Migrate::Importer::File->new(
Directory => $dir,
OriginalId => $OPT{originalid},