summaryrefslogtreecommitdiff
path: root/rt/etc/upgrade/3.8.3/content
blob: 3147c87e274700fbfedae9397667041fd7664cfe (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use strict;
use warnings;

our @ScripConditions = (
    {  Name                 => 'On Reject',                                # loc
       Description          => 'Whenever a ticket is rejected',            # loc
       ApplicableTransTypes => 'Status',
       ExecModule           => 'StatusChange',
       Argument             => 'rejected'

    },
);

our @Final = (
    sub {
        RT->Logger->debug("Going to correct descriptions of notify actions in the DB");

        my $actions = RT::ScripActions->new( RT->SystemUser );
        $actions->Limit(
            FIELD => 'ExecModule',
            VALUE => 'Notify',
        );
        $actions->Limit(
            FIELD => 'Argument',
            VALUE => 'All',
        );
        while ( my $action = $actions->Next ) {
            my ($status, $msg) = $action->__Set( Field => 'Name', Value => 'Notify Owner, Requestors, Ccs and AdminCcs' );
            RT->Logger->warning( "Couldn't change action name: $msg" )
                unless $status;

            ($status, $msg) = $action->__Set( Field => 'Description', Value => 'Send mail to owner and all watchers' );
            RT->Logger->warning( "Couldn't change action description: $msg" )
                unless $status;
        }

        $actions = RT::ScripActions->new( RT->SystemUser );
        $actions->Limit(
            FIELD => 'ExecModule',
            VALUE => 'NotifyAsComment',
        );
        $actions->Limit(
            FIELD => 'Argument',
            VALUE => 'All',
        );
        while ( my $action = $actions->Next ) {
            my ($status, $msg) = $action->__Set( Field => 'Name', Value => 'Notify Owner, Requestors, Ccs and AdminCcs as Comment' );
            RT->Logger->warning( "Couldn't change action name: $msg" )
                unless $status;

            ($status, $msg) = $action->__Set( Field => 'Description', Value => 'Send mail to owner and all watchers as a "comment"' );
            RT->Logger->warning( "Couldn't change action description: $msg" )
                unless $status;
        }

        RT->Logger->debug("Corrected descriptions of notify actions in the DB.");
        return 1;
    },
);

our (@ScripActions, @Scrips);
{
RT->Logger->debug("Going to add in Extract Subject Tag actions if they were missed during a previous upgrade");

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

if ( $extract_action && $extract_action->Id ) {
    RT->Logger->debug("You appear to already have an Extract Subject Tag action, skipping");
    return 1;
} else {
    RT->Logger->debug("Didn't find an existing Extract Subject Tag action, adding it");
    push @ScripActions, (
            { Name        => 'Extract Subject Tag',                               # loc
              Description => 'Extract tags from a Transaction\'s subject and add them to the Ticket\'s subject.', # loc
              ExecModule  => 'ExtractSubjectTag' 
            },
    );

    RT->Logger->debug("Adding Extract Subject Tag Scrip");
    push @Final, sub {
        my $action = RT::ScripAction->new( RT->SystemUser );
        $action->Load( 'Extract Subject Tag' );
        my $condition = RT::ScripCondition->new( RT->SystemUser );
        $condition->Load( 'On Transaction' );
        my $template = RT::Template->new( RT->SystemUser );
        $template->LoadByName( Name => 'Blank', Queue => 0 );
        my $scrip = RT::Scrip->new( RT->SystemUser );
        $scrip->RT::Record::Create(
           Description    => "On transaction, add any tags in the transaction's subject to the ticket's subject",
           ScripCondition => $condition->id,
           ScripAction    => $action->id,
           Template       => $template->id,
           Stage          => 'TransactionCreate',
           Queue          => 0,
        );
    };
}
}