]> git.uio.no Git - usit-rt.git/blob - etc/upgrade/3.8.4/content
Upgrade to 4.2.8
[usit-rt.git] / etc / upgrade / 3.8.4 / content
1 use strict;
2 use warnings;
3
4
5 our @Final = (
6     sub {
7         RT->Logger->debug("Going to correct arguments of NotifyGroup actions if you have any");
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 );
55             RT->Logger->warning( "Couldn't change argument value of the action: $msg" )
56                 unless $status;
57         }
58     },
59 );
60
61