- if ( $export_svc && ! $exportnums->{$exportnum} ) {
- $error = $export_svc->delete;
- if ( $error ) {
- $dbh->rollback if $oldAutoCommit;
- return $error;
+ if ( $export_svc ) {
+ my $old_role = $export_svc->role || 1; # 1 = null in the db
+ if ( ! $exportnums->{$exportnum}
+ or $old_role ne $exportnums->{$exportnum} ) {
+
+ $error = $export_svc->delete;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+ undef $export_svc; # on a role change, force it to be reinserted
+