X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FTicketSystem.pm;h=c1c69fa3f0f562e0ac87ade2fffe0699e177a590;hb=b5d22578f60ba105934c92c031799671bf6c0f29;hp=7b18575275a2e5751f25d5b022598514f85ac76b;hpb=3d0a1bb06b895c5be6e3f0517d355442a6b1e125;p=freeside.git diff --git a/FS/FS/TicketSystem.pm b/FS/FS/TicketSystem.pm index 7b1857527..c1c69fa3f 100644 --- a/FS/FS/TicketSystem.pm +++ b/FS/FS/TicketSystem.pm @@ -209,7 +209,7 @@ sub _upgrade_data { while (my $item = $search->Next) { my ($c, $a, $t) = map {lc $item->$_->Name} ('ScripConditionObj', 'ScripActionObj', 'TemplateObj'); - if ( exists $scrip{$c}{$a}{$t} and $item->Creator == 1 ) { + if ( exists $scrip{$c}{$a} and $item->Creator == 1 ) { warn "Deleting duplicate scrip $c $a [$t]\n"; my ($val, $msg) = $item->Delete; warn "error deleting scrip: $msg\n" if !$val; @@ -220,7 +220,7 @@ sub _upgrade_data { warn "error deleting scrip: $msg\n" if !$val; } else { - $scrip{$c}{$a}{$t} = $item->id; + $scrip{$c}{$a} = $item->id; } } my $Scrip = RT::Scrip->new($CurrentUser); @@ -228,30 +228,42 @@ sub _upgrade_data { my $desc = $s->{'Description'}; my ($c, $a, $t) = map lc, @{ $s }{'ScripCondition', 'ScripAction', 'Template'}; - # skip existing scrips - next if ( exists($scrip{$c}{$a}{$t}) ); - if ( !exists($condition{$c}) ) { - warn "ScripCondition '$c' not found.\n"; - next; - } - if ( !exists($action{$a}) ) { - warn "ScripAction '$a' not found.\n"; - next; - } - if ( !exists($template{$t}) ) { - warn "Template '$t' not found.\n"; - next; + + if ( exists($scrip{$c}{$a}) ) { + $Scrip->Load( $scrip{$c}{$a} ); + } else { # need to create it + + if ( !exists($condition{$c}) ) { + warn "ScripCondition '$c' not found.\n"; + next; + } + if ( !exists($action{$a}) ) { + warn "ScripAction '$a' not found.\n"; + next; + } + if ( !exists($template{$t}) ) { + warn "Template '$t' not found.\n"; + next; + } + my %new_param = ( + ScripCondition => $condition{$c}->[0], + ScripAction => $action{$a}->[0], + Template => $template{$t}->[0], + Queue => 0, + Description => $desc, + ); + warn "Creating scrip: $c $a [$t]\n"; + my ($val, $msg) = $Scrip->Create(%new_param); + die $msg if !$val; + + } #if $scrip{...} + # set the Immutable attribute on them if needed + if ( !$Scrip->FirstAttribute('Immutable') ) { + my ($val, $msg) = + $Scrip->SetAttribute(Name => 'Immutable', Content => '1'); + die $msg if !$val; } - my %new_param = ( - ScripCondition => $condition{$c}->[0], - ScripAction => $action{$a}->[0], - Template => $template{$t}->[0], - Queue => 0, - Description => $desc, - ); - warn "Creating scrip: $c $a [$t]\n"; - my ($val, $msg) = $Scrip->Create(%new_param); - die $msg if !$val; + } #foreach (@Scrips) # one-time fix: accumulator fields (support time, etc.) that had values