Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / etc / upgrade / 4.2.2 / content
1 use strict;
2 use warnings;
3
4 our @Initial = (
5     sub {
6         use RT::CustomFields;
7         my $cfs = RT::CustomFields->new(RT->SystemUser);
8         $cfs->{'find_disabled_rows'} = 1;
9         $cfs->Limit( FIELD => 'LookupType', VALUE => 'RT::FM::Class-RT::FM::Article' );
10         while ( my $cf = $cfs->Next ) {
11             my ($ret, $msg) = $cf->__Set( Field => 'LookupType', Value => 'RT::Class-RT::Article' );
12             RT->Logger->warning("Update Custom Field LookupType for CF.".$cf->Id." $msg");
13         }
14         return 1;
15     },
16
17     sub {
18         use RT::ObjectCustomFieldValues;
19         my $ocfvs = RT::ObjectCustomFieldValues->new(RT->System);
20         $ocfvs->{'find_expired_rows'} = 1;
21         $ocfvs->Limit( FIELD => 'ObjectType', VALUE => 'RT::FM::Article' );
22         while ( my $ocfv = $ocfvs->Next ) {
23             my ($ret, $msg) = $ocfv->__Set( Field => 'ObjectType', Value => 'RT::Article' );
24             RT->Logger->warning("Updated CF ".$ocfv->__Value('CustomField')." Value for Article ".$ocfv->__Value('ObjectId'));
25         }
26         return 1;
27     },
28
29     sub {
30         require RT::Scrips;
31         my $scrips = RT::Scrips->new( RT->SystemUser );
32         $scrips->{'find_disabled_rows'} = 1;
33         $scrips->Limit( FIELD => 'Disabled', VALUE => 1 );;
34         while ( my $scrip = $scrips->Next ) {
35             my $id = $scrip->Template;
36             if ( $id =~ /\D/ ) {
37                 $RT::Logger->info('Template column for scrip #'. $scrip->id .' already contains characters');
38                 next;
39             }
40
41             my $name;
42
43             my $template = RT::Template->new( RT->SystemUser );
44             $template->Load( $id );
45             unless ( $template->id ) {
46                 $RT::Logger->error("Scrip #". $scrip->id ." has template set to #$id, but it's not in DB, setting it 'Blank'");
47                 $name = 'Blank';
48             } else {
49                 $name = $template->Name;
50             }
51
52             my ($status, $msg) = $scrip->_Set( Field => 'Template', Value => $name );
53             unless ( $status ) {
54                 $RT::Logger->error("Couldn't set template: $msg");
55             }
56         }
57     },
58 );
59