Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / etc / upgrade / 3.8.8 / content
1 @Initial = (
2     sub {
3         # make sure global CFs are not applied to local objects
4         my $ocfs = RT::ObjectCustomFields->new( RT->SystemUser );
5         $ocfs->Limit( FIELD => 'ObjectId', OPERATOR => '!=', VALUE => 0 );
6         my $alias = $ocfs->Join(
7             FIELD1 => 'CustomField',
8             TABLE2 => 'ObjectCustomFields',
9             FIELD2 => 'CustomField',
10         );
11         $ocfs->Limit( ALIAS => $alias, FIELD => 'ObjectId', VALUE => 0 );
12         while ( my $ocf = $ocfs->Next ) {
13             $ocf->Delete;
14         }
15     },
16     sub {
17         # sort SortOrder
18         my $sth = $RT::Handle->dbh->prepare(
19             "SELECT cfs.LookupType, ocfs.id"
20             ." FROM ObjectCustomFields ocfs, CustomFields cfs"
21             ." WHERE cfs.id = ocfs.CustomField"
22             ." ORDER BY cfs.LookupType, ocfs.SortOrder, cfs.Name"
23         );
24         $sth->execute;
25
26         my ($i, $prev_type) = (0, '');
27         while ( my ($lt, $id) = $sth->fetchrow_array ) {
28             $i = 0 if $prev_type ne $lt;
29             my $ocf = RT::ObjectCustomField->new( RT->SystemUser );
30             $ocf->Load( $id );
31             my ($status, $msg) = $ocf->SetSortOrder( $i++ );
32             $RT::Logger->warning("Couldn't set SortOrder: $msg")
33                 unless $status;
34             $prev_type = $lt;
35         }
36     },
37 );
38