summaryrefslogtreecommitdiff
path: root/rt/etc/upgrade/3.8.4/content
blob: ac490d3e1b73297870d87bd9d26fe03e19dc3850 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use strict;
use warnings;


our @Final = (
    sub {
        RT->Logger->debug("Going to correct arguments of NotifyGroup actions if you have any");

        my $actions = RT::ScripActions->new( RT->SystemUser );
        $actions->Limit(
            FIELD => 'ExecModule',
            VALUE => 'NotifyGroup',
        );
        $actions->Limit(
            FIELD => 'ExecModule',
            VALUE => 'NotifyGroupAsComment',
        );

        my $converter = sub {
            my $arg = shift;
            my @res;
            foreach my $r ( @{ $arg } ) {
                my $obj;
                next unless $r->{'Type'};
                if( lc $r->{'Type'} eq 'user' ) {
                    $obj = RT::User->new( RT->SystemUser );
                } elsif ( lc $r->{'Type'} eq 'group' ) {
                    $obj = RT::Group->new( RT->SystemUser );
                } else {
                    next;
                }
                $obj->Load( $r->{'Instance'} );
                my $id = $obj->id;
                next unless( $id );

                push @res, $id;
            }

            return join ',', @res;
        };

        require Storable;
        while ( my $action = $actions->Next ) {
            my $argument = $action->Argument;
            my $new = '';
            local $@;
            if ( my $struct = eval { Storable::thaw( $argument ) } ) {
                $new = $converter->( $struct );
            } else {
                $new = join ", ", grep length, split /[^0-9]+/, $argument;
            }
            next if $new eq $argument;

            my ($status, $msg) = $action->__Set( Field => 'Argument', Value => $new );
            RT->Logger->warning( "Couldn't change argument value of the action: $msg" )
                unless $status;
        }
    },
);