default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / rt / etc / upgrade / 3.9.7 / content
1 use strict;
2 use warnings;
3
4 my $move_attributes = sub {
5     my ($table, $type, $column) = @_;
6     my $query = "UPDATE $table SET $column = (SELECT Content FROM Attributes WHERE"
7         ." Name = ? AND ObjectType = ? AND $table.id = Attributes.ObjectId)";
8
9     my $res = RT->DatabaseHandle->SimpleQuery( $query, $column, $type );
10     unless ( $res ) {
11         RT->Logger->error("Failed to move $column on $type from Attributes into $table table");
12         return;
13     }
14
15     $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
16     $res = RT->DatabaseHandle->SimpleQuery( $query, $column, $type );
17     unless ( $res ) {
18         RT->Logger->error("Failed to delete $column on $type from Attributes");
19         return;
20     }
21     return 1;
22 };
23
24 our @Initial = (
25     sub {
26         return $move_attributes->( 'Users', 'RT::User', 'AuthToken');
27     },
28     sub {
29         return $move_attributes->( 'CustomFields', 'RT::CustomField', 'RenderType');
30     },
31     sub {
32         my $cfs = RT::CustomFields->new( RT->SystemUser );
33         $cfs->UnLimit;
34         $cfs->FindAllRows;
35         while ( my $cf = $cfs->Next ) {
36             # Explicitly remove 'ORDER BY id asc' to emulate the
37             # previous functionality, where Pg might return the the
38             # rows in arbitrary order
39             $cf->Attributes->OrderByCols();
40
41             my $attr = $cf->FirstAttribute('BasedOn');
42             next unless $attr;
43             $cf->SetBasedOn($attr->Content);
44         }
45         my $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
46         my $res = RT->DatabaseHandle->SimpleQuery( $query, 'BasedOn', 'RT::CustomField' );
47         unless ( $res ) {
48             RT->Logger->error("Failed to delete BasedOn CustomFields from Attributes");
49             return;
50         }
51         return 1;
52     },
53     sub {
54         $move_attributes->( 'CustomFields', 'RT::CustomField', 'ValuesClass')
55             or return;
56
57         my $query = "UPDATE CustomFields SET ValuesClass = NULL WHERE ValuesClass = ?";
58         my $res = RT->DatabaseHandle->SimpleQuery( $query, 'RT::CustomFieldValues' );
59         unless ( $res ) {
60             RT->Logger->error("Failed to replace default with NULLs");
61             return;
62         }
63         return 1;
64     },
65     sub {
66         my $attr = RT->System->FirstAttribute('BrandedSubjectTag');
67         return 1 unless $attr;
68
69         my $map = $attr->Content || {};
70         while ( my ($qid, $tag) = each %$map ) {
71             my $queue = RT::Queue->new( RT->SystemUser );
72             $queue->Load( $qid );
73             unless ( $queue->id ) {
74                 RT->Logger->warning("Couldn't load queue #$qid. Skipping...");
75                 next;
76             }
77
78             my ($status, $msg) = $queue->SetSubjectTag($tag);
79             unless ( $status ) {
80                 RT->Logger->error("Couldn't set subject tag for queue #$qid: $msg");
81                 next;
82             }
83         }
84     },
85 );