Merge branch 'master' of https://github.com/jgoodman/Freeside
[freeside.git] / rt / etc / upgrade / 3.7.19 / content
1
2 { use strict;
3 add_description_to_all_scrips();
4
5 sub add_description_to_all_scrips {
6     require RT::Scrips;
7     my $scrips = RT::Scrips->new( RT->SystemUser );
8     $scrips->Limit( FIELD => 'Description', OPERATOR => 'IS', VALUE => 'NULL' );
9     $scrips->Limit( FIELD => 'Description', VALUE => '' );
10     while ( my $scrip = $scrips->Next ) {
11         my $desc = $scrip->Description;
12         next if defined $desc && length $desc;
13
14         $desc = gen_scrip_description( $scrip );
15
16         my ($status, $msg) = $scrip->SetDescription( $desc );
17         unless ( $status ) {
18             print STDERR "Couldn't set description of a scrip: $msg";
19         } else {
20             print "Added description to scrip #". $scrip->id ."\n";
21         }
22     }
23 }
24
25 sub gen_scrip_description {
26     my $scrip = shift;
27
28     my $condition;
29     eval{
30       $condition = $scrip->ConditionObj->Name
31         || $scrip->ConditionObj->Description
32         || ('On Condition #'. $scrip->Condition);
33     };
34
35     if ($@){
36       print STDERR $@;
37       print STDERR "Reference to missing scrip condition found. If you have ScripCondition = 0 in the Scrips table, update with a real condition number.\n";
38       $condition = 'On undefined Condition # 0';
39     }
40
41     my $action = $scrip->ActionObj->Name
42         || $scrip->ActionObj->Description
43         || ('Run Action #'. $scrip->Action);
44     return join ' ', $condition, $action;
45   }
46 }
47
48 1;