Putting 4.2.0 on top of 4.0.17
[usit-rt.git] / etc / upgrade / 3.9.7 / content
CommitLineData
af59614d
MKG
1use strict;
2use warnings;
3
01e3b242
MKG
4my $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
af59614d 9 my $res = RT->DatabaseHandle->SimpleQuery( $query, $column, $type );
01e3b242 10 unless ( $res ) {
af59614d 11 RT->Logger->error("Failed to move $column on $type from Attributes into $table table");
01e3b242
MKG
12 return;
13 }
14
15 $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
af59614d 16 $res = RT->DatabaseHandle->SimpleQuery( $query, $column, $type );
01e3b242 17 unless ( $res ) {
af59614d 18 RT->Logger->error("Failed to delete $column on $type from Attributes");
01e3b242
MKG
19 return;
20 }
21 return 1;
22};
23
af59614d 24our @Initial = (
01e3b242
MKG
25 sub {
26 return $move_attributes->( 'Users', 'RT::User', 'AuthToken');
27 },
28 sub {
29 return $move_attributes->( 'CustomFields', 'RT::CustomField', 'RenderType');
30 },
31 sub {
af59614d 32 my $cfs = RT::CustomFields->new( RT->SystemUser );
01e3b242
MKG
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 }
af59614d
MKG
45 my $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?';
46 my $res = RT->DatabaseHandle->SimpleQuery( $query, 'BasedOn', 'RT::CustomField' );
01e3b242 47 unless ( $res ) {
af59614d 48 RT->Logger->error("Failed to delete BasedOn CustomFields from Attributes");
01e3b242
MKG
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 = ?";
af59614d 58 my $res = RT->DatabaseHandle->SimpleQuery( $query, 'RT::CustomFieldValues' );
01e3b242 59 unless ( $res ) {
af59614d 60 RT->Logger->error("Failed to replace default with NULLs");
01e3b242
MKG
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 ) {
af59614d 74 RT->Logger->warning("Couldn't load queue #$qid. Skipping...");
01e3b242
MKG
75 next;
76 }
77
78 my ($status, $msg) = $queue->SetSubjectTag($tag);
79 unless ( $status ) {
af59614d 80 RT->Logger->error("Couldn't set subject tag for queue #$qid: $msg");
01e3b242
MKG
81 next;
82 }
83 }
84 },
85);