Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / etc / upgrade / 3.8.3 / content
1 use strict;
2 use warnings;
3
4 our @ScripConditions = (
5     {  Name                 => 'On Reject',                                # loc
6        Description          => 'Whenever a ticket is rejected',            # loc
7        ApplicableTransTypes => 'Status',
8        ExecModule           => 'StatusChange',
9        Argument             => 'rejected'
10
11     },
12 );
13
14 our @Final = (
15     sub {
16         RT->Logger->debug("Going to correct descriptions of notify actions in the DB");
17
18         my $actions = RT::ScripActions->new( RT->SystemUser );
19         $actions->Limit(
20             FIELD => 'ExecModule',
21             VALUE => 'Notify',
22         );
23         $actions->Limit(
24             FIELD => 'Argument',
25             VALUE => 'All',
26         );
27         while ( my $action = $actions->Next ) {
28             my ($status, $msg) = $action->__Set( Field => 'Name', Value => 'Notify Owner, Requestors, Ccs and AdminCcs' );
29             RT->Logger->warning( "Couldn't change action name: $msg" )
30                 unless $status;
31
32             ($status, $msg) = $action->__Set( Field => 'Description', Value => 'Send mail to owner and all watchers' );
33             RT->Logger->warning( "Couldn't change action description: $msg" )
34                 unless $status;
35         }
36
37         $actions = RT::ScripActions->new( RT->SystemUser );
38         $actions->Limit(
39             FIELD => 'ExecModule',
40             VALUE => 'NotifyAsComment',
41         );
42         $actions->Limit(
43             FIELD => 'Argument',
44             VALUE => 'All',
45         );
46         while ( my $action = $actions->Next ) {
47             my ($status, $msg) = $action->__Set( Field => 'Name', Value => 'Notify Owner, Requestors, Ccs and AdminCcs as Comment' );
48             RT->Logger->warning( "Couldn't change action name: $msg" )
49                 unless $status;
50
51             ($status, $msg) = $action->__Set( Field => 'Description', Value => 'Send mail to owner and all watchers as a "comment"' );
52             RT->Logger->warning( "Couldn't change action description: $msg" )
53                 unless $status;
54         }
55
56         RT->Logger->debug("Corrected descriptions of notify actions in the DB.");
57         return 1;
58     },
59 );
60
61 our (@ScripActions, @Scrips);
62 {
63 RT->Logger->debug("Going to add in Extract Subject Tag actions if they were missed during a previous upgrade");
64
65 my $actions = RT::ScripActions->new( RT->SystemUser );
66 $actions->Limit(
67     FIELD => 'ExecModule',
68     VALUE => 'ExtractSubjectTag',
69 );
70 my $extract_action = $actions->First;
71
72 if ( $extract_action && $extract_action->Id ) {
73     RT->Logger->debug("You appear to already have an Extract Subject Tag action, skipping");
74     return 1;
75 } else {
76     RT->Logger->debug("Didn't find an existing Extract Subject Tag action, adding it");
77     push @ScripActions, (
78             { Name        => 'Extract Subject Tag',                               # loc
79               Description => 'Extract tags from a Transaction\'s subject and add them to the Ticket\'s subject.', # loc
80               ExecModule  => 'ExtractSubjectTag' 
81             },
82     );
83
84     RT->Logger->debug("Adding Extract Subject Tag Scrip");
85     push @Final, sub {
86         my $action = RT::ScripAction->new( RT->SystemUser );
87         $action->Load( 'Extract Subject Tag' );
88         my $condition = RT::ScripCondition->new( RT->SystemUser );
89         $condition->Load( 'On Transaction' );
90         my $template = RT::Template->new( RT->SystemUser );
91         $template->LoadByName( Name => 'Blank', Queue => 0 );
92         my $scrip = RT::Scrip->new( RT->SystemUser );
93         $scrip->RT::Record::Create(
94            Description    => "On transaction, add any tags in the transaction's subject to the ticket's subject",
95            ScripCondition => $condition->id,
96            ScripAction    => $action->id,
97            Template       => $template->id,
98            Stage          => 'TransactionCreate',
99            Queue          => 0,
100         );
101     };
102 }
103 }
104