]>
Commit | Line | Data |
---|---|---|
af59614d MKG |
1 | use strict; |
2 | use warnings; | |
01e3b242 | 3 | |
af59614d MKG |
4 | |
5 | our @Final = ( | |
01e3b242 | 6 | sub { |
af59614d | 7 | RT->Logger->debug("Going to correct arguments of NotifyGroup actions if you have any"); |
01e3b242 MKG |
8 | |
9 | my $actions = RT::ScripActions->new( RT->SystemUser ); | |
10 | $actions->Limit( | |
11 | FIELD => 'ExecModule', | |
12 | VALUE => 'NotifyGroup', | |
13 | ); | |
14 | $actions->Limit( | |
15 | FIELD => 'ExecModule', | |
16 | VALUE => 'NotifyGroupAsComment', | |
17 | ); | |
18 | ||
19 | my $converter = sub { | |
20 | my $arg = shift; | |
21 | my @res; | |
22 | foreach my $r ( @{ $arg } ) { | |
23 | my $obj; | |
24 | next unless $r->{'Type'}; | |
25 | if( lc $r->{'Type'} eq 'user' ) { | |
26 | $obj = RT::User->new( RT->SystemUser ); | |
27 | } elsif ( lc $r->{'Type'} eq 'group' ) { | |
28 | $obj = RT::Group->new( RT->SystemUser ); | |
29 | } else { | |
30 | next; | |
31 | } | |
32 | $obj->Load( $r->{'Instance'} ); | |
33 | my $id = $obj->id; | |
34 | next unless( $id ); | |
35 | ||
36 | push @res, $id; | |
37 | } | |
38 | ||
39 | return join ',', @res; | |
40 | }; | |
41 | ||
42 | require Storable; | |
43 | while ( my $action = $actions->Next ) { | |
44 | my $argument = $action->Argument; | |
45 | my $new = ''; | |
46 | local $@; | |
47 | if ( my $struct = eval { Storable::thaw( $argument ) } ) { | |
48 | $new = $converter->( $struct ); | |
49 | } else { | |
50 | $new = join ", ", grep length, split /[^0-9]+/, $argument; | |
51 | } | |
52 | next if $new eq $argument; | |
53 | ||
54 | my ($status, $msg) = $action->__Set( Field => 'Argument', Value => $new ); | |
af59614d | 55 | RT->Logger->warning( "Couldn't change argument value of the action: $msg" ) |
01e3b242 MKG |
56 | unless $status; |
57 | } | |
58 | }, | |
59 | ); | |
60 | ||
61 |