Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / rt / etc / upgrade / 4.1.1 / content
1 use strict;
2 use warnings;
3
4 our @Initial = (
5     sub {
6         require RT::ObjectScrips;
7         foreach my $stage ('TransactionCreate', 'TransactionBatch') {
8             my $applications = RT::ObjectScrips->new( RT->SystemUser );
9             $applications->Limit( FIELD => 'Stage', VALUE => $stage );
10             my $alias = $applications->Join(
11                 FIELD1 => 'Scrip',
12                 TABLE2 => 'Scrips', FIELD2 => 'id'
13             );
14             $applications->OrderByCols(
15                 { ALIAS => $alias, FIELD => 'Description', ORDER => 'ASC' },
16             );
17             my %h; my $top_so = $h{0} = 0;
18             while ( my $record = $applications->Next ) {
19                 my $oid = $record->ObjectId || 0;
20
21                 my $so;
22                 unless ( $oid ) {
23                     %h = (); $h{0} = $so = ++$top_so;
24                 }
25                 else {
26                     $so = $h{ $oid } = ($h{$oid}||$h{0}) + 1;
27                 }
28                 next if $record->SortOrder == $so;
29
30                 my ($status, $msg) = $record->SetSortOrder($so);
31                 RT->Logger->error("Couldn't set sort order: $msg")
32                     unless $status;
33             }
34         }
35     },
36 );