diff options
author | Ivan Kohler <ivan@freeside.biz> | 2015-07-09 22:18:55 -0700 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2015-07-09 22:18:55 -0700 |
commit | 1c538bfabc2cd31f27067505f0c3d1a46cba6ef0 (patch) | |
tree | 96922ad4459eda1e649327fd391d60c58d454c53 /rt/etc/upgrade | |
parent | 4f5619288413a185e9933088d9dd8c5afbc55dfa (diff) |
RT 4.2.11, ticket#13852
Diffstat (limited to 'rt/etc/upgrade')
128 files changed, 2152 insertions, 314 deletions
diff --git a/rt/etc/upgrade/3.1.0/content b/rt/etc/upgrade/3.1.0/content deleted file mode 100644 index 3117daf..0000000 --- a/rt/etc/upgrade/3.1.0/content +++ /dev/null @@ -1,2 +0,0 @@ -# nothing to do -1; diff --git a/rt/etc/upgrade/3.1.0/schema.Oracle b/rt/etc/upgrade/3.1.0/schema.Oracle index a8aae18..8a3c142 100644 --- a/rt/etc/upgrade/3.1.0/schema.Oracle +++ b/rt/etc/upgrade/3.1.0/schema.Oracle @@ -1,16 +1,16 @@ CREATE SEQUENCE ATTRIBUTES_seq; CREATE TABLE Attributes ( - id NUMBER(11,0) PRIMARY KEY, - Name VARCHAR2(255) NOT NULL, - Description VARCHAR2(255), - Content CLOB, + id NUMBER(11,0) PRIMARY KEY, + Name VARCHAR2(255) NOT NULL, + Description VARCHAR2(255), + Content CLOB, ContentType VARCHAR(16), - ObjectType VARCHAR2(25) NOT NULL, - ObjectId NUMBER(11,0) DEFAULT 0 NOT NULL, - Creator NUMBER(11,0) DEFAULT 0 NOT NULL, - Created DATE, - LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL, - LastUpdated DATE + ObjectType VARCHAR2(25) NOT NULL, + ObjectId NUMBER(11,0) DEFAULT 0 NOT NULL, + Creator NUMBER(11,0) DEFAULT 0 NOT NULL, + Created DATE, + LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL, + LastUpdated DATE ); CREATE INDEX Attributes1 on Attributes(Name); diff --git a/rt/etc/upgrade/3.1.15/content b/rt/etc/upgrade/3.1.15/content index d23125a..9e4b253 100644 --- a/rt/etc/upgrade/3.1.15/content +++ b/rt/etc/upgrade/3.1.15/content @@ -1,4 +1,7 @@ -@Scrips = ( +use strict; +use warnings; + +our @Scrips = ( { ScripCondition => 'On Owner Change', ScripAction => 'Notify Owner', Template => 'Transaction' }, diff --git a/rt/etc/upgrade/3.1.17/content b/rt/etc/upgrade/3.1.17/content index 1d648d8..a6b5c54 100644 --- a/rt/etc/upgrade/3.1.17/content +++ b/rt/etc/upgrade/3.1.17/content @@ -1,4 +1,7 @@ -@ScripActions = ( +use strict; +use warnings; + +our @ScripActions = ( { Name => 'Notify Ccs as Comment', # loc Description => 'Sends mail to the Ccs as a comment', # loc ExecModule => 'NotifyAsComment', @@ -10,7 +13,7 @@ ); -@ScripConditions = ( +our @ScripConditions = ( { Name => 'On Priority Change', # loc Description => 'Whenever a ticket\'s priority changes', # loc diff --git a/rt/etc/upgrade/3.3.0/content b/rt/etc/upgrade/3.3.0/content deleted file mode 100644 index 0afc604..0000000 --- a/rt/etc/upgrade/3.3.0/content +++ /dev/null @@ -1 +0,0 @@ -1; diff --git a/rt/etc/upgrade/3.3.11/content b/rt/etc/upgrade/3.3.11/content deleted file mode 100644 index 0afc604..0000000 --- a/rt/etc/upgrade/3.3.11/content +++ /dev/null @@ -1 +0,0 @@ -1; diff --git a/rt/etc/upgrade/3.5.1/content b/rt/etc/upgrade/3.5.1/content index 02d6a0c..59f9dfd 100644 --- a/rt/etc/upgrade/3.5.1/content +++ b/rt/etc/upgrade/3.5.1/content @@ -1,4 +1,7 @@ -@Attributes = ( +use strict; +use warnings; + +our @Attributes = ( { Name => 'Search - My Tickets', Description => '[_1] highest priority tickets I own', Content => @@ -19,16 +22,16 @@ Description => 'HomepageSettings', Content => { 'body' => - [ { type => 'system', name => 'My Tickets' }, - { type => 'system', name => 'Unowned Tickets' }, - { type => 'component', name => 'QuickCreate'}, - ], + [ { type => 'system', name => 'My Tickets' }, + { type => 'system', name => 'Unowned Tickets' }, + { type => 'component', name => 'QuickCreate'}, + ], 'summary' => - [ - { type => 'component', name => 'MyReminders' }, + [ + { type => 'component', name => 'MyReminders' }, { type => 'component', name => 'Quicksearch' }, - { type => 'component', name => 'RefreshHomepage' }, - ] + { type => 'component', name => 'RefreshHomepage' }, + ] }, } ); diff --git a/rt/etc/upgrade/3.7.1/content b/rt/etc/upgrade/3.7.1/content index fdd5061..e39ef8a 100644 --- a/rt/etc/upgrade/3.7.1/content +++ b/rt/etc/upgrade/3.7.1/content @@ -1,4 +1,7 @@ -@ScripConditions = ( +use strict; +use warnings; + +our @ScripConditions = ( { Name => 'On Close', # loc Description => 'Whenever a ticket is closed', # loc ApplicableTransTypes => 'Status,Set', diff --git a/rt/etc/upgrade/3.7.10/content b/rt/etc/upgrade/3.7.10/content index d19f9e6..fd4628d 100644 --- a/rt/etc/upgrade/3.7.10/content +++ b/rt/etc/upgrade/3.7.10/content @@ -1,5 +1,8 @@ +use strict; +use warnings; -@Templates = ( + +our @Templates = ( { Queue => 0, Name => "Error: public key", # loc Description => diff --git a/rt/etc/upgrade/3.7.15/content b/rt/etc/upgrade/3.7.15/content index 9d97c35..a3a27fd 100644 --- a/rt/etc/upgrade/3.7.15/content +++ b/rt/etc/upgrade/3.7.15/content @@ -1,5 +1,8 @@ +use strict; +use warnings; -@Templates = ( + +our @Templates = ( { Queue => 0, Name => "Forward", # loc Description => "Heading of a forwarded message", # loc diff --git a/rt/etc/upgrade/3.7.19/content b/rt/etc/upgrade/3.7.19/content index ff43dd0..34af550 100644 --- a/rt/etc/upgrade/3.7.19/content +++ b/rt/etc/upgrade/3.7.19/content @@ -1,26 +1,28 @@ - -{ use strict; -add_description_to_all_scrips(); - -sub add_description_to_all_scrips { - require RT::Scrips; - my $scrips = RT::Scrips->new( RT->SystemUser ); - $scrips->Limit( FIELD => 'Description', OPERATOR => 'IS', VALUE => 'NULL' ); - $scrips->Limit( FIELD => 'Description', VALUE => '' ); - while ( my $scrip = $scrips->Next ) { - my $desc = $scrip->Description; - next if defined $desc && length $desc; - - $desc = gen_scrip_description( $scrip ); - - my ($status, $msg) = $scrip->SetDescription( $desc ); - unless ( $status ) { - print STDERR "Couldn't set description of a scrip: $msg"; - } else { - print "Added description to scrip #". $scrip->id ."\n"; +use strict; +use warnings; + +our @Final = ( + sub { + require RT::Scrips; + my $scrips = RT::Scrips->new( RT->SystemUser ); + $scrips->{'with_disabled_column'} = 0; + $scrips->Limit( FIELD => 'Description', OPERATOR => 'IS', VALUE => 'NULL' ); + $scrips->Limit( FIELD => 'Description', VALUE => '' ); + while ( my $scrip = $scrips->Next ) { + my $desc = $scrip->Description; + next if defined $desc && length $desc; + + $desc = gen_scrip_description( $scrip ); + + my ($status, $msg) = $scrip->SetDescription( $desc ); + unless ( $status ) { + print STDERR "Couldn't set description of a scrip: $msg"; + } else { + print "Added description to scrip #". $scrip->id ."\n"; + } } - } -} + }, +); sub gen_scrip_description { my $scrip = shift; @@ -29,7 +31,7 @@ sub gen_scrip_description { eval{ $condition = $scrip->ConditionObj->Name || $scrip->ConditionObj->Description - || ('On Condition #'. $scrip->Condition); + || ('On Condition #'. $scrip->Condition); }; if ($@){ @@ -42,7 +44,6 @@ sub gen_scrip_description { || $scrip->ActionObj->Description || ('Run Action #'. $scrip->Action); return join ' ', $condition, $action; - } } 1; diff --git a/rt/etc/upgrade/3.7.82/content b/rt/etc/upgrade/3.7.82/content index a1c555f..da406c4 100644 --- a/rt/etc/upgrade/3.7.82/content +++ b/rt/etc/upgrade/3.7.82/content @@ -1,4 +1,7 @@ -@Attributes = ( +use strict; +use warnings; + +our @Attributes = ( { Name => 'Search - Bookmarked Tickets', Description => 'Bookmarked Tickets', #loc Content => diff --git a/rt/etc/upgrade/3.7.85/content b/rt/etc/upgrade/3.7.85/content index 49ab286..e9ec15c 100644 --- a/rt/etc/upgrade/3.7.85/content +++ b/rt/etc/upgrade/3.7.85/content @@ -1,9 +1,12 @@ -@Templates = ( - - { Queue => '0', - Name => 'Email Digest', # loc - Description => 'Email template for periodic notification digests', # loc - Content => q[Subject: RT Email Digest +use strict; +use warnings; + +our @Templates = ( + + { Queue => '0', + Name => 'Email Digest', # loc + Description => 'Email template for periodic notification digests', # loc + Content => q[Subject: RT Email Digest { $Argument } ], diff --git a/rt/etc/upgrade/3.7.86/content b/rt/etc/upgrade/3.7.86/content index 94912d6..029939d 100644 --- a/rt/etc/upgrade/3.7.86/content +++ b/rt/etc/upgrade/3.7.86/content @@ -1,13 +1,16 @@ -@Final = ( +use strict; +use warnings; + +our @Final = ( sub { - $RT::Logger->debug("Adding search for bookmarked tickets to defaults"); + RT->Logger->debug("Adding search for bookmarked tickets to defaults"); my $sys = RT::System->new(RT->SystemUser); my $attrs = RT::Attributes->new( RT->SystemUser ); $attrs->LimitToObject( $sys ); my ($attr) = $attrs->Named( 'HomepageSettings' ); unless ($attr) { - $RT::Logger->error("You have no global home page settings"); + RT->Logger->error("You have no global home page settings"); return; } my $content = $attr->Content; @@ -15,9 +18,9 @@ { type => 'system', name => 'Bookmarked Tickets' }; my ($status, $msg) = $attr->SetContent( $content ); - $RT::Logger->error($msg) unless $status; + RT->Logger->error($msg) unless $status; - $RT::Logger->debug("done."); + RT->Logger->debug("done."); return 1; }, ); diff --git a/rt/etc/upgrade/3.7.87/content b/rt/etc/upgrade/3.7.87/content index 0c677c4..c67feb4 100644 --- a/rt/etc/upgrade/3.7.87/content +++ b/rt/etc/upgrade/3.7.87/content @@ -1,4 +1,7 @@ -@Templates = ( +use strict; +use warnings; + +our @Templates = ( { Queue => 0, Name => "Error: Missing dashboard", # loc diff --git a/rt/etc/upgrade/3.8-ical-extension.in b/rt/etc/upgrade/3.8-ical-extension.in index 89e5191..928888f 100644 --- a/rt/etc/upgrade/3.8-ical-extension.in +++ b/rt/etc/upgrade/3.8-ical-extension.in @@ -46,16 +46,16 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} +use 5.10.1; use strict; use warnings; use lib "@LOCAL_LIB_PATH@"; use lib "@RT_LIB_PATH@"; +use RT -init; -use RT; -RT::LoadConfig(); -RT::Init(); +$| = 1; use RT::Attributes; my $attrs = RT::Attributes->new( RT->SystemUser ); diff --git a/rt/etc/upgrade/3.8.0/content b/rt/etc/upgrade/3.8.0/content index 4fa5ac7..ae3a9fc 100644 --- a/rt/etc/upgrade/3.8.0/content +++ b/rt/etc/upgrade/3.8.0/content @@ -1,21 +1,24 @@ -@Final = ( +use strict; +use warnings; + +our @Final = ( # by incident we've changed 'My Bookmarks' to 'Bookmarked Tickets' when # 3.7.82 upgrade script still was creating 'My Bookmarks', try to fix it sub { - $RT::Logger->debug("Going to rename 'My Bookmarks' to 'Bookmarked Tickets'"); + RT->Logger->debug("Going to rename 'My Bookmarks' to 'Bookmarked Tickets'"); my $sys = RT::System->new(RT->SystemUser); my $attrs = RT::Attributes->new( RT->SystemUser ); $attrs->LimitToObject( $sys ); my ($attr) = $attrs->Named( 'Search - My Bookmarks' ); unless ($attr) { - $RT::Logger->debug("You have no global search 'My Bookmarks'. Skipped."); + RT->Logger->debug("You have no global search 'My Bookmarks'. Skipped."); return 1; } my ($status, $msg) = $attr->SetName( 'Search - Bookmarked Tickets' ); - $RT::Logger->error($msg) and return undef unless $status; + RT->Logger->error($msg) and return undef unless $status; - $RT::Logger->debug("Renamed."); + RT->Logger->debug("Renamed."); return 1; }, ); diff --git a/rt/etc/upgrade/3.8.1/content b/rt/etc/upgrade/3.8.1/content index 1667efa..08c6430 100644 --- a/rt/etc/upgrade/3.8.1/content +++ b/rt/etc/upgrade/3.8.1/content @@ -1,22 +1,25 @@ -@Final = ( +use strict; +use warnings; + +our @Final = ( sub { - $RT::Logger->debug("Going to adjust 'Bookmarked Tickets'"); + RT->Logger->debug("Going to adjust 'Bookmarked Tickets'"); my $sys = RT::System->new(RT->SystemUser); my $attrs = RT::Attributes->new( RT->SystemUser ); $attrs->LimitToObject( $sys ); my ($attr) = $attrs->Named( 'Search - Bookmarked Tickets' ); unless ($attr) { - $RT::Logger->debug("You have no global search 'Bookmarked Tickets'. Skipped."); + RT->Logger->debug("You have no global search 'Bookmarked Tickets'. Skipped."); return 1; } my $props = $attr->Content; $props->{'Query'} =~ s/__Bookmarks__/id = '__Bookmarked__'/g; my ($status, $msg) = $attr->SetContent( $props ); - $RT::Logger->error($msg) and return undef unless $status; + RT->Logger->error($msg) and return undef unless $status; - $RT::Logger->debug("Fixed."); + RT->Logger->debug("Fixed."); return 1; }, ); diff --git a/rt/etc/upgrade/3.8.2/content b/rt/etc/upgrade/3.8.2/content index 0eef401..dc68c92 100644 --- a/rt/etc/upgrade/3.8.2/content +++ b/rt/etc/upgrade/3.8.2/content @@ -1,6 +1,19 @@ -@Initial = ( +use strict; +use warnings; + +our @Initial = ( + sub { + # We do the delete in pure SQL because Attribute collections + # otherwise attempt to hash everything in memory. As this may + # be a large list, do it directly. + RT->DatabaseHandle->dbh->do(<<EOSQL); + DELETE FROM Attributes + WHERE Name = 'DeferredRecipients' + AND Content IS NULL; +EOSQL + }, sub { - $RT::Logger->warning( + RT->Logger->warning( "Going to add [OLD] prefix to all templates in approvals queue." ." If you have never used approvals, you can safely delete all the" ." templates with the [OLD] prefix. Leave the new Approval templates because" @@ -10,7 +23,7 @@ my $approvals_q = RT::Queue->new( RT->SystemUser ); $approvals_q->Load('___Approvals'); unless ( $approvals_q->id ) { - $RT::Logger->error("You have no approvals queue."); + RT->Logger->error("You have no approvals queue."); return 1; } @@ -19,19 +32,32 @@ while ( my $tmpl = $templates->Next ) { my ($status, $msg) = $tmpl->SetName( "[OLD] ". $tmpl->Name ); unless ( $status ) { - $RT::Logger->error("Couldn't rename template #". $tmpl->id .": $msg"); + RT->Logger->error("Couldn't rename template #". $tmpl->id .": $msg"); } } return 1; }, -); -@ACL = ( - { GroupDomain => 'SystemInternal', - GroupType => 'privileged', - Right => 'ShowApprovalsTab', }, + + sub { + my $group = RT::Group->new( RT->SystemUser ); + $group->DBIx::SearchBuilder::Record::LoadByCols( + Domain => 'SystemInternal', + Type => 'Privileged', + ); + unless ($group->id) { + RT->Logger->warn("Failed to load Privilged group"); + return; + } + my ( $return, $msg ) = $group->PrincipalObj->GrantRight( + Right => 'ShowApprovalsTab', + Object => RT->System, + ); + RT->Logger->warn("Failed to grant ShowApprovalsTab right: $msg") + unless $return; + }, ); -@Templates = ( +our @Templates = ( { Queue => '___Approvals', Name => "New Pending Approval", # loc Description => @@ -106,17 +132,17 @@ The ticket has been approved, you may now start to act on it. }, ); -@Final = ( +our @Final = ( sub { - $RT::Logger->debug("Going to adjust dashboards"); + RT->Logger->debug("Going to adjust dashboards"); my $sys = RT::System->new(RT->SystemUser); my $attrs = RT::Attributes->new( RT->SystemUser ); - $attrs->UnLimit; + $attrs->Limit( FIELD => "Name", VALUE => "Dashboard"); my @dashboards = $attrs->Named('Dashboard'); if (@dashboards == 0) { - $RT::Logger->debug("You have no dashboards. Skipped."); + RT->Logger->debug("You have no dashboards. Skipped."); return 1; } @@ -140,28 +166,28 @@ The ticket has been approved, you may now start to act on it. }; } my ($status, $msg) = $attr->SetContent( $props ); - $RT::Logger->error($msg) unless $status; + RT->Logger->error($msg) unless $status; } - $RT::Logger->debug("Fixed."); + RT->Logger->debug("Fixed."); return 1; }, sub { my $approvals_q = RT::Queue->new( RT->SystemUser ); $approvals_q->Load('___Approvals'); unless ( $approvals_q->id ) { - $RT::Logger->error("You have no approvals queue."); + RT->Logger->error("You have no approvals queue."); return 1; } require File::Temp; my ($tmp_fh, $tmp_fn) = File::Temp::tempfile( 'rt-approvals-scrips-XXXX', CLEANUP => 0 ); unless ( $tmp_fh ) { - $RT::Logger->error("Couldn't create temporary file."); + RT->Logger->error("Couldn't create temporary file."); return 0; } - $RT::Logger->warning( + RT->Logger->warning( "IMPORTANT: We're going to delete all scrips in Approvals queue" ." and save them in '$tmp_fn' file." ); @@ -169,17 +195,20 @@ The ticket has been approved, you may now start to act on it. require Data::Dumper; my $scrips = RT::Scrips->new( RT->SystemUser ); - $scrips->LimitToQueue( $approvals_q->id ); + $scrips->{'with_disabled_column'} = 0; + $scrips->Limit( FIELD => 'Queue', VALUE => $approvals_q->id ); while ( my $scrip = $scrips->Next ) { my %tmp = - map { $tmp->{ $_ } = $scrip->_Value( $_ ) } - $scrip->ReadableAttributes; + map { $_ => $scrip->_Value( $_ ) } + qw/id Description ScripCondition ScripAction + CustomIsApplicableCode CustomPrepareCode CustomCommitCode + Stage Queue Template Creator Created LastUpdatedBy LastUpdated/; print $tmp_fh Data::Dumper::Dumper( \%tmp ); - my ($status, $msg) = $scrip->Delete; + my ($status, $msg) = $scrip->DBIx::SearchBuilder::Record::Delete; unless ( $status ) { - $RT::Logger->error( "Couldn't delete scrip: $msg"); + RT->Logger->error( "Couldn't delete scrip: $msg"); } } }, diff --git a/rt/etc/upgrade/3.8.3/content b/rt/etc/upgrade/3.8.3/content index b8052ac..3147c87 100644 --- a/rt/etc/upgrade/3.8.3/content +++ b/rt/etc/upgrade/3.8.3/content @@ -1,4 +1,7 @@ -@ScripConditions = ( +use strict; +use warnings; + +our @ScripConditions = ( { Name => 'On Reject', # loc Description => 'Whenever a ticket is rejected', # loc ApplicableTransTypes => 'Status', @@ -8,9 +11,9 @@ }, ); -@Final = ( +our @Final = ( sub { - $RT::Logger->debug("Going to correct descriptions of notify actions in the DB"); + RT->Logger->debug("Going to correct descriptions of notify actions in the DB"); my $actions = RT::ScripActions->new( RT->SystemUser ); $actions->Limit( @@ -23,11 +26,11 @@ ); while ( my $action = $actions->Next ) { my ($status, $msg) = $action->__Set( Field => 'Name', Value => 'Notify Owner, Requestors, Ccs and AdminCcs' ); - $RT::Logger->warning( "Couldn't change action name: $msg" ) + RT->Logger->warning( "Couldn't change action name: $msg" ) unless $status; ($status, $msg) = $action->__Set( Field => 'Description', Value => 'Send mail to owner and all watchers' ); - $RT::Logger->warning( "Couldn't change action description: $msg" ) + RT->Logger->warning( "Couldn't change action description: $msg" ) unless $status; } @@ -42,24 +45,24 @@ ); while ( my $action = $actions->Next ) { my ($status, $msg) = $action->__Set( Field => 'Name', Value => 'Notify Owner, Requestors, Ccs and AdminCcs as Comment' ); - $RT::Logger->warning( "Couldn't change action name: $msg" ) + RT->Logger->warning( "Couldn't change action name: $msg" ) unless $status; ($status, $msg) = $action->__Set( Field => 'Description', Value => 'Send mail to owner and all watchers as a "comment"' ); - $RT::Logger->warning( "Couldn't change action description: $msg" ) + RT->Logger->warning( "Couldn't change action description: $msg" ) unless $status; } - $RT::Logger->debug("Corrected descriptions of notify actions in the DB."); + RT->Logger->debug("Corrected descriptions of notify actions in the DB."); return 1; }, ); - +our (@ScripActions, @Scrips); { -$RT::Logger->debug("Going to add in Extract Subject Tag actions if they were missed during a previous upgrade"); +RT->Logger->debug("Going to add in Extract Subject Tag actions if they were missed during a previous upgrade"); -$actions = RT::ScripActions->new( RT->SystemUser ); +my $actions = RT::ScripActions->new( RT->SystemUser ); $actions->Limit( FIELD => 'ExecModule', VALUE => 'ExtractSubjectTag', @@ -67,10 +70,10 @@ $actions->Limit( my $extract_action = $actions->First; if ( $extract_action && $extract_action->Id ) { - $RT::Logger->debug("You appear to already have an Extract Subject Tag action, skipping"); + RT->Logger->debug("You appear to already have an Extract Subject Tag action, skipping"); return 1; } else { - $RT::Logger->debug("Didn't find an existing Extract Subject Tag action, adding it"); + RT->Logger->debug("Didn't find an existing Extract Subject Tag action, adding it"); push @ScripActions, ( { Name => 'Extract Subject Tag', # loc Description => 'Extract tags from a Transaction\'s subject and add them to the Ticket\'s subject.', # loc @@ -78,14 +81,24 @@ if ( $extract_action && $extract_action->Id ) { }, ); - $RT::Logger->debug("Adding Extract Subject Tag Scrip"); - push @Scrips, ( - { Description => "On transaction, add any tags in the transaction's subject to the ticket's subject", - ScripCondition => 'On Transaction', - ScripAction => 'Extract Subject Tag', - Template => 'Blank' - }, - ); + RT->Logger->debug("Adding Extract Subject Tag Scrip"); + push @Final, sub { + my $action = RT::ScripAction->new( RT->SystemUser ); + $action->Load( 'Extract Subject Tag' ); + my $condition = RT::ScripCondition->new( RT->SystemUser ); + $condition->Load( 'On Transaction' ); + my $template = RT::Template->new( RT->SystemUser ); + $template->LoadByName( Name => 'Blank', Queue => 0 ); + my $scrip = RT::Scrip->new( RT->SystemUser ); + $scrip->RT::Record::Create( + Description => "On transaction, add any tags in the transaction's subject to the ticket's subject", + ScripCondition => $condition->id, + ScripAction => $action->id, + Template => $template->id, + Stage => 'TransactionCreate', + Queue => 0, + ); + }; } } diff --git a/rt/etc/upgrade/3.8.4/content b/rt/etc/upgrade/3.8.4/content index 14ecba4..ac490d3 100644 --- a/rt/etc/upgrade/3.8.4/content +++ b/rt/etc/upgrade/3.8.4/content @@ -1,8 +1,10 @@ +use strict; +use warnings; -@Final = ( + +our @Final = ( sub { - $RT::Logger->debug("Going to correct arguments of NotifyGroup actions if you have any"); - use strict; + RT->Logger->debug("Going to correct arguments of NotifyGroup actions if you have any"); my $actions = RT::ScripActions->new( RT->SystemUser ); $actions->Limit( @@ -50,7 +52,7 @@ next if $new eq $argument; my ($status, $msg) = $action->__Set( Field => 'Argument', Value => $new ); - $RT::Logger->warning( "Couldn't change argument value of the action: $msg" ) + RT->Logger->warning( "Couldn't change argument value of the action: $msg" ) unless $status; } }, diff --git a/rt/etc/upgrade/3.8.6/content b/rt/etc/upgrade/3.8.6/content index a9793c6..3651a66 100644 --- a/rt/etc/upgrade/3.8.6/content +++ b/rt/etc/upgrade/3.8.6/content @@ -1,4 +1,7 @@ -@Templates = ( +use strict; +use warnings; + +our @Templates = ( { Queue => 0, Name => "Forward Ticket", # loc Description => "Heading of a forwarded Ticket", # loc diff --git a/rt/etc/upgrade/3.8.8/content b/rt/etc/upgrade/3.8.8/content index cad77e9..50b3314 100644 --- a/rt/etc/upgrade/3.8.8/content +++ b/rt/etc/upgrade/3.8.8/content @@ -1,4 +1,7 @@ -@Initial = ( +use strict; +use warnings; + +our @Initial = ( sub { # make sure global CFs are not applied to local objects my $ocfs = RT::ObjectCustomFields->new( RT->SystemUser ); @@ -15,7 +18,7 @@ }, sub { # sort SortOrder - my $sth = $RT::Handle->dbh->prepare( + my $sth = RT->DatabaseHandle->dbh->prepare( "SELECT cfs.LookupType, ocfs.id" ." FROM ObjectCustomFields ocfs, CustomFields cfs" ." WHERE cfs.id = ocfs.CustomField" @@ -29,7 +32,7 @@ my $ocf = RT::ObjectCustomField->new( RT->SystemUser ); $ocf->Load( $id ); my ($status, $msg) = $ocf->SetSortOrder( $i++ ); - $RT::Logger->warning("Couldn't set SortOrder: $msg") + RT->Logger->warning("Couldn't set SortOrder: $msg") unless $status; $prev_type = $lt; } diff --git a/rt/etc/upgrade/3.8.9/content b/rt/etc/upgrade/3.8.9/content index d7d64f5..d0a2516 100644 --- a/rt/etc/upgrade/3.8.9/content +++ b/rt/etc/upgrade/3.8.9/content @@ -1,7 +1,9 @@ -@Initial = ( +use strict; +use warnings; + +our @Initial = ( sub { - use strict; - $RT::Logger->debug('Make sure local links are local'); + RT->Logger->debug('Make sure local links are local'); use RT::URI::fsck_com_rt; my $prefix = RT::URI::fsck_com_rt->LocalURIPrefix . '/ticket/'; @@ -53,7 +55,7 @@ # there is only one OwnerObj->Name normally, so no need /g if ( $content =~ -s!(?<=Your ticket has been (?:approved|rejected) by { eval { )\$Approval->OwnerObj->Name!\$Approver->Name! +s!(?<=Your ticket has been (?:approved|rejected) by \{ eval \{ )\$Approval->OwnerObj->Name!\$Approver->Name! ) { $template->SetType('Perl'); diff --git a/rt/etc/upgrade/3.9.1/content b/rt/etc/upgrade/3.9.1/content index acdc0ad..3e35f47 100644 --- a/rt/etc/upgrade/3.9.1/content +++ b/rt/etc/upgrade/3.9.1/content @@ -1,7 +1,9 @@ -@Initial = ( +use strict; +use warnings; + +our @Initial = ( sub { - use strict; - $RT::Logger->debug('Make sure templates all have known types'); + RT->Logger->debug('Make sure templates all have known types'); # We update all NULL rows, below. We want to find non-NULL # rows, which weren't created by the current codebase running @@ -26,12 +28,11 @@ ); while (my $template = $templates->Next) { my ($status, $msg) = $template->SetType('Perl'); - $RT::Logger->warning( "Couldn't change Type of Template #" . $template->Id . ": $msg" ) unless $status; + RT->Logger->warning( "Couldn't change Type of Template #" . $template->Id . ": $msg" ) unless $status; } }, sub { - use strict; - $RT::Logger->debug('Adding ExecuteCode right to principals that currently have ModifyTemplate or ModifyScrips'); + RT->Logger->debug('Adding ExecuteCode right to principals that currently have ModifyTemplate or ModifyScrips'); my $acl = RT::ACL->new(RT->SystemUser); $acl->Limit( @@ -60,7 +61,7 @@ ); if (!$ok) { - $RT::Logger->warn("Unable to grant ExecuteCode on principal " . $principal->id . ": $msg"); + RT->Logger->warn("Unable to grant ExecuteCode on principal " . $principal->id . ": $msg"); } } }, diff --git a/rt/etc/upgrade/3.9.2/content b/rt/etc/upgrade/3.9.2/content index d0dbbfd..1851a9e 100644 --- a/rt/etc/upgrade/3.9.2/content +++ b/rt/etc/upgrade/3.9.2/content @@ -1,7 +1,9 @@ -@Initial = ( +use strict; +use warnings; + +our @Initial = ( sub { - use strict; - $RT::Logger->debug('Removing all delegated rights'); + RT->Logger->debug('Removing all delegated rights'); my $acl = RT::ACL->new(RT->SystemUser); $acl->Limit( CLAUSE => 'search', @@ -20,7 +22,7 @@ my ( $ok, $msg ) = $ace->Delete(); if ( !$ok ) { - $RT::Logger->warn( + RT->Logger->warn( "Unable to delete ACE " . $ace->id . ": " . $msg ); } } @@ -28,14 +30,15 @@ my $groups = RT::Groups->new(RT->SystemUser); $groups->Limit( FIELD => 'Domain', OPERATOR => '=', - VALUE => 'Personal' + VALUE => 'Personal', + CASESENSITIVE => 0, ); while ( my $group = $groups->Next ) { my $members = $group->MembersObj(); while ( my $member = $members->Next ) { my ( $ok, $msg ) = $group->DeleteMember( $member->MemberId ); if ( !$ok ) { - $RT::Logger->warn( "Unable to remove group member " + RT->Logger->warn( "Unable to remove group member " . $member->id . ": " . $msg ); } diff --git a/rt/etc/upgrade/3.9.3/schema.Oracle b/rt/etc/upgrade/3.9.3/schema.Oracle index 4ee50c4..6ca1bdf 100644 --- a/rt/etc/upgrade/3.9.3/schema.Oracle +++ b/rt/etc/upgrade/3.9.3/schema.Oracle @@ -1,2 +1 @@ -ALTER TABLE ACL DROP COLUMN DelegatedBy; -ALTER TABLE ACL DROP COLUMN DelegatedFrom; +ALTER TABLE ACL DROP( DelegatedBy, DelegatedFrom ); diff --git a/rt/etc/upgrade/3.9.3/schema.Pg b/rt/etc/upgrade/3.9.3/schema.Pg index 4ee50c4..9b34ac7 100644 --- a/rt/etc/upgrade/3.9.3/schema.Pg +++ b/rt/etc/upgrade/3.9.3/schema.Pg @@ -1,2 +1,3 @@ -ALTER TABLE ACL DROP COLUMN DelegatedBy; -ALTER TABLE ACL DROP COLUMN DelegatedFrom; +ALTER TABLE ACL + DROP COLUMN DelegatedBy, + DROP COLUMN DelegatedFrom; diff --git a/rt/etc/upgrade/3.9.3/schema.mysql b/rt/etc/upgrade/3.9.3/schema.mysql index 4ee50c4..9b34ac7 100644 --- a/rt/etc/upgrade/3.9.3/schema.mysql +++ b/rt/etc/upgrade/3.9.3/schema.mysql @@ -1,2 +1,3 @@ -ALTER TABLE ACL DROP COLUMN DelegatedBy; -ALTER TABLE ACL DROP COLUMN DelegatedFrom; +ALTER TABLE ACL + DROP COLUMN DelegatedBy, + DROP COLUMN DelegatedFrom; diff --git a/rt/etc/upgrade/3.9.5/backcompat b/rt/etc/upgrade/3.9.5/backcompat index 611ab51..ca0b289 100644 --- a/rt/etc/upgrade/3.9.5/backcompat +++ b/rt/etc/upgrade/3.9.5/backcompat @@ -1 +1,15 @@ -RT::ACE LastUpdated LastUpdatedBy Creator Created +my ($upgrade) = @_; + +my %removed; +my @fields = qw/LastUpdated LastUpdatedBy Creator Created/; + +RT::ACE->_BuildTableAttributes; +$RT::Logger->debug("Temporarily removing @fields from RT::ACE"); +$removed{$_} = delete $RT::Record::_TABLE_ATTR->{"RT::ACE"}{$_} + for @fields; + +$upgrade->(); + +# Put back the fields we chopped off +$RT::Record::_TABLE_ATTR->{"RT::ACE"}{$_} = $removed{$_} + for @fields; diff --git a/rt/etc/upgrade/3.9.5/schema.Oracle b/rt/etc/upgrade/3.9.5/schema.Oracle index 065776d..bcf5b1f 100644 --- a/rt/etc/upgrade/3.9.5/schema.Oracle +++ b/rt/etc/upgrade/3.9.5/schema.Oracle @@ -6,15 +6,21 @@ AND CustomFieldValues.id = Attributes.ObjectId); DELETE FROM Attributes WHERE Name = 'Category' AND ObjectType = 'RT::CustomFieldValue'; -ALTER TABLE Groups ADD Creator NUMBER(11,0) DEFAULT 0 NOT NULL; -ALTER TABLE Groups ADD Created DATE; -ALTER TABLE Groups ADD LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL; -ALTER TABLE Groups ADD LastUpdated DATE; -ALTER TABLE GroupMembers ADD Creator NUMBER(11,0) DEFAULT 0 NOT NULL; -ALTER TABLE GroupMembers ADD Created DATE; -ALTER TABLE GroupMembers ADD LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL; -ALTER TABLE GroupMembers ADD LastUpdated DATE; -ALTER TABLE ACL ADD Creator NUMBER(11,0) DEFAULT 0 NOT NULL; -ALTER TABLE ACL ADD Created DATE; -ALTER TABLE ACL ADD LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL; -ALTER TABLE ACL ADD LastUpdated DATE; +ALTER TABLE Groups ADD( + Creator NUMBER(11,0) DEFAULT 0 NOT NULL, + Created DATE, + LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL, + LastUpdated DATE +); +ALTER TABLE GroupMembers ADD( + Creator NUMBER(11,0) DEFAULT 0 NOT NULL, + Created DATE, + LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL, + LastUpdated DATE +); +ALTER TABLE ACL ADD( + Creator NUMBER(11,0) DEFAULT 0 NOT NULL, + Created DATE, + LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL, + LastUpdated DATE +); diff --git a/rt/etc/upgrade/3.9.5/schema.Pg b/rt/etc/upgrade/3.9.5/schema.Pg index cea2c44..cd91901 100644 --- a/rt/etc/upgrade/3.9.5/schema.Pg +++ b/rt/etc/upgrade/3.9.5/schema.Pg @@ -6,15 +6,18 @@ AND CustomFieldValues.id = Attributes.ObjectId); DELETE FROM Attributes WHERE Name = 'Category' AND ObjectType = 'RT::CustomFieldValue'; -ALTER TABLE Groups ADD COLUMN Creator integer NOT NULL DEFAULT 0; -ALTER TABLE Groups ADD COLUMN Created TIMESTAMP NULL; -ALTER TABLE Groups ADD COLUMN LastUpdatedBy integer NOT NULL DEFAULT 0; -ALTER TABLE Groups ADD COLUMN LastUpdated TIMESTAMP NULL; -ALTER TABLE GroupMembers ADD COLUMN Creator integer NOT NULL DEFAULT 0; -ALTER TABLE GroupMembers ADD COLUMN Created TIMESTAMP NULL; -ALTER TABLE GroupMembers ADD COLUMN LastUpdatedBy integer NOT NULL DEFAULT 0; -ALTER TABLE GroupMembers ADD COLUMN LastUpdated TIMESTAMP NULL; -ALTER TABLE ACL ADD COLUMN Creator integer NOT NULL DEFAULT 0; -ALTER TABLE ACL ADD COLUMN Created TIMESTAMP NULL; -ALTER TABLE ACL ADD COLUMN LastUpdatedBy integer NOT NULL DEFAULT 0; -ALTER TABLE ACL ADD COLUMN LastUpdated TIMESTAMP NULL; +ALTER TABLE Groups + ADD COLUMN Creator integer NOT NULL DEFAULT 0, + ADD COLUMN Created TIMESTAMP NULL, + ADD COLUMN LastUpdatedBy integer NOT NULL DEFAULT 0, + ADD COLUMN LastUpdated TIMESTAMP NULL; +ALTER TABLE GroupMembers + ADD COLUMN Creator integer NOT NULL DEFAULT 0, + ADD COLUMN Created TIMESTAMP NULL, + ADD COLUMN LastUpdatedBy integer NOT NULL DEFAULT 0, + ADD COLUMN LastUpdated TIMESTAMP NULL; +ALTER TABLE ACL + ADD COLUMN Creator integer NOT NULL DEFAULT 0, + ADD COLUMN Created TIMESTAMP NULL, + ADD COLUMN LastUpdatedBy integer NOT NULL DEFAULT 0, + ADD COLUMN LastUpdated TIMESTAMP NULL; diff --git a/rt/etc/upgrade/3.9.5/schema.mysql b/rt/etc/upgrade/3.9.5/schema.mysql index fe5018c..83f2f40 100644 --- a/rt/etc/upgrade/3.9.5/schema.mysql +++ b/rt/etc/upgrade/3.9.5/schema.mysql @@ -6,15 +6,18 @@ AND CustomFieldValues.id = Attributes.ObjectId); DELETE FROM Attributes WHERE Name = 'Category' AND ObjectType = 'RT::CustomFieldValue'; -ALTER TABLE Groups ADD COLUMN Creator integer NOT NULL DEFAULT 0, +ALTER TABLE Groups + ADD COLUMN Creator integer NOT NULL DEFAULT 0, ADD COLUMN Created DATETIME NULL, ADD COLUMN LastUpdatedBy integer NOT NULL DEFAULT 0, ADD COLUMN LastUpdated DATETIME NULL; -ALTER TABLE GroupMembers ADD COLUMN Creator integer NOT NULL DEFAULT 0, +ALTER TABLE GroupMembers + ADD COLUMN Creator integer NOT NULL DEFAULT 0, ADD COLUMN Created DATETIME NULL, ADD COLUMN LastUpdatedBy integer NOT NULL DEFAULT 0, ADD COLUMN LastUpdated DATETIME NULL; -ALTER TABLE ACL ADD COLUMN Creator integer NOT NULL DEFAULT 0, +ALTER TABLE ACL + ADD COLUMN Creator integer NOT NULL DEFAULT 0, ADD COLUMN Created DATETIME NULL, ADD COLUMN LastUpdatedBy integer NOT NULL DEFAULT 0, ADD COLUMN LastUpdated DATETIME NULL; diff --git a/rt/etc/upgrade/3.9.7/content b/rt/etc/upgrade/3.9.7/content index 504ddf1..9b48b4b 100644 --- a/rt/etc/upgrade/3.9.7/content +++ b/rt/etc/upgrade/3.9.7/content @@ -1,24 +1,27 @@ +use strict; +use warnings; + my $move_attributes = sub { my ($table, $type, $column) = @_; my $query = "UPDATE $table SET $column = (SELECT Content FROM Attributes WHERE" ." Name = ? AND ObjectType = ? AND $table.id = Attributes.ObjectId)"; - my $res = $RT::Handle->SimpleQuery( $query, $column, $type ); + my $res = RT->DatabaseHandle->SimpleQuery( $query, $column, $type ); unless ( $res ) { - $RT::Logger->error("Failed to move $column on $type from Attributes into $table table"); + RT->Logger->error("Failed to move $column on $type from Attributes into $table table"); return; } $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?'; - $res = $RT::Handle->SimpleQuery( $query, $column, $type ); + $res = RT->DatabaseHandle->SimpleQuery( $query, $column, $type ); unless ( $res ) { - $RT::Logger->error("Failed to delete $column on $type from Attributes"); + RT->Logger->error("Failed to delete $column on $type from Attributes"); return; } return 1; }; -@Initial = ( +our @Initial = ( sub { return $move_attributes->( 'Users', 'RT::User', 'AuthToken'); }, @@ -26,7 +29,7 @@ my $move_attributes = sub { return $move_attributes->( 'CustomFields', 'RT::CustomField', 'RenderType'); }, sub { - my $cfs = RT::CustomFields->new($RT::SystemUser); + my $cfs = RT::CustomFields->new( RT->SystemUser ); $cfs->UnLimit; $cfs->FindAllRows; while ( my $cf = $cfs->Next ) { @@ -39,10 +42,10 @@ my $move_attributes = sub { next unless $attr; $cf->SetBasedOn($attr->Content); } - $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?'; - $res = $RT::Handle->SimpleQuery( $query, 'BasedOn', 'RT::CustomField' ); + my $query = 'DELETE FROM Attributes WHERE Name = ? AND ObjectType = ?'; + my $res = RT->DatabaseHandle->SimpleQuery( $query, 'BasedOn', 'RT::CustomField' ); unless ( $res ) { - $RT::Logger->error("Failed to delete BasedOn CustomFields from Attributes"); + RT->Logger->error("Failed to delete BasedOn CustomFields from Attributes"); return; } return 1; @@ -52,9 +55,9 @@ my $move_attributes = sub { or return; my $query = "UPDATE CustomFields SET ValuesClass = NULL WHERE ValuesClass = ?"; - my $res = $RT::Handle->SimpleQuery( $query, 'RT::CustomFieldValues' ); + my $res = RT->DatabaseHandle->SimpleQuery( $query, 'RT::CustomFieldValues' ); unless ( $res ) { - $RT::Logger->error("Failed to replace default with NULLs"); + RT->Logger->error("Failed to replace default with NULLs"); return; } return 1; @@ -68,13 +71,13 @@ my $move_attributes = sub { my $queue = RT::Queue->new( RT->SystemUser ); $queue->Load( $qid ); unless ( $queue->id ) { - $RT::Logger->warning("Couldn't load queue #$qid. Skipping..."); + RT->Logger->warning("Couldn't load queue #$qid. Skipping..."); next; } my ($status, $msg) = $queue->SetSubjectTag($tag); unless ( $status ) { - $RT::Logger->error("Couldn't set subject tag for queue #$qid: $msg"); + RT->Logger->error("Couldn't set subject tag for queue #$qid: $msg"); next; } } diff --git a/rt/etc/upgrade/3.9.7/schema.Oracle b/rt/etc/upgrade/3.9.7/schema.Oracle index 3c75c91..70b4a12 100644 --- a/rt/etc/upgrade/3.9.7/schema.Oracle +++ b/rt/etc/upgrade/3.9.7/schema.Oracle @@ -1,6 +1,12 @@ ALTER TABLE Users ADD AuthToken VARCHAR2(16) NULL; -ALTER TABLE CustomFields ADD BasedOn NUMBER(11,0) NULL; -ALTER TABLE CustomFields ADD RenderType VARCHAR2(64) NULL; -ALTER TABLE CustomFields ADD ValuesClass VARCHAR2(64) NULL; -ALTER TABLE Queues ADD SubjectTag VARCHAR2(120) NULL; -ALTER TABLE Queues ADD Lifecycle VARCHAR2(32) NULL; + +ALTER TABLE CustomFields ADD( + BasedOn NUMBER(11,0) NULL, + RenderType VARCHAR2(64) NULL, + ValuesClass VARCHAR2(64) NULL +); + +ALTER TABLE Queues ADD( + SubjectTag VARCHAR2(120) NULL, + Lifecycle VARCHAR2(32) NULL +); diff --git a/rt/etc/upgrade/3.9.7/schema.Pg b/rt/etc/upgrade/3.9.7/schema.Pg index 1704fa6..d6fe7cc 100644 --- a/rt/etc/upgrade/3.9.7/schema.Pg +++ b/rt/etc/upgrade/3.9.7/schema.Pg @@ -1,6 +1,10 @@ ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) NULL; -ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL; -ALTER TABLE CustomFields ADD COLUMN RenderType VARCHAR(64) NULL; -ALTER TABLE CustomFields ADD COLUMN ValuesClass VARCHAR(64) NULL; -ALTER TABLE Queues ADD COLUMN SubjectTag VARCHAR(120) NULL; -ALTER TABLE Queues ADD COLUMN Lifecycle VARCHAR(32) NULL; + +ALTER TABLE CustomFields + ADD COLUMN BasedOn INTEGER NULL, + ADD COLUMN RenderType VARCHAR(64) NULL, + ADD COLUMN ValuesClass VARCHAR(64) NULL; + +ALTER TABLE Queues + ADD COLUMN SubjectTag VARCHAR(120) NULL, + ADD COLUMN Lifecycle VARCHAR(32) NULL; diff --git a/rt/etc/upgrade/3.9.7/schema.mysql b/rt/etc/upgrade/3.9.7/schema.mysql index 4cbed6c..0e61d64 100644 --- a/rt/etc/upgrade/3.9.7/schema.mysql +++ b/rt/etc/upgrade/3.9.7/schema.mysql @@ -1,6 +1,10 @@ ALTER TABLE Users ADD COLUMN AuthToken VARCHAR(16) CHARACTER SET ascii NULL; -ALTER TABLE CustomFields ADD COLUMN BasedOn INTEGER NULL, + +ALTER TABLE CustomFields + ADD COLUMN BasedOn INTEGER NULL, ADD COLUMN RenderType VARCHAR(64) NULL, ADD COLUMN ValuesClass VARCHAR(64) CHARACTER SET ascii NULL; -ALTER TABLE Queues ADD COLUMN SubjectTag VARCHAR(120) NULL, + +ALTER TABLE Queues + ADD COLUMN SubjectTag VARCHAR(120) NULL, ADD COLUMN Lifecycle VARCHAR(32) NULL; diff --git a/rt/etc/upgrade/3.9.8/content b/rt/etc/upgrade/3.9.8/content index 24242fd..e9a1a32 100644 --- a/rt/etc/upgrade/3.9.8/content +++ b/rt/etc/upgrade/3.9.8/content @@ -1,4 +1,7 @@ -@Initial = sub { +use strict; +use warnings; + +our @Initial = sub { my $found_fm_tables = {}; foreach my $name ( $RT::Handle->_TableNames ) { next unless $name =~ /^fm_/i; @@ -8,15 +11,15 @@ return unless %$found_fm_tables; unless ( $found_fm_tables->{fm_topics} && $found_fm_tables->{fm_objecttopics} ) { - $RT::Logger->error("You appear to be upgrading from RTFM 2.0 - We don't support upgrading this old of an RTFM yet"); + RT->Logger->error("You appear to be upgrading from RTFM 2.0 - We don't support upgrading this old of an RTFM yet"); } - $RT::Logger->error("We found RTFM tables in your database. Checking for content."); + RT->Logger->error("We found RTFM tables in your database. Checking for content."); my $dbh = $RT::Handle->dbh; my $result = $dbh->selectall_arrayref("SELECT count(*) AS articlecount FROM FM_Articles", { Slice => {} } ); if ($result->[0]{articlecount} > 0) { - $RT::Logger->error("You appear to have RTFM Articles. You can upgrade using the etc/upgrade/upgrade-articles script. Read more about it in docs/UPGRADING-4.0"); + RT->Logger->error("You appear to have RTFM Articles. You can upgrade using the /opt/rt4/etc/upgrade/upgrade-articles script. Read more about it in docs/UPGRADING-4.0"); } }; diff --git a/rt/etc/upgrade/3.9.8/schema.Pg b/rt/etc/upgrade/3.9.8/schema.Pg index d12e27a..1f56d3b 100644 --- a/rt/etc/upgrade/3.9.8/schema.Pg +++ b/rt/etc/upgrade/3.9.8/schema.Pg @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS Classes; CREATE TABLE Classes ( id SERIAL, Name varchar(255) NOT NULL DEFAULT '', @@ -12,6 +13,7 @@ HotList smallint NOT NULL DEFAULT 0, PRIMARY KEY (id) ); +DROP TABLE IF EXISTS Articles; CREATE TABLE Articles ( id SERIAL, Name varchar(255) NOT NULL DEFAULT '', @@ -28,6 +30,7 @@ PRIMARY KEY (id) ); +DROP TABLE IF EXISTS Topics; CREATE TABLE Topics ( id SERIAL, Parent integer NOT NULL DEFAULT 0, @@ -39,6 +42,7 @@ PRIMARY KEY (id) ); +DROP TABLE IF EXISTS ObjectTopics; CREATE TABLE ObjectTopics ( id SERIAL, Topic integer NOT NULL, @@ -48,6 +52,7 @@ PRIMARY KEY (id) ); +DROP TABLE IF EXISTS ObjectClasses; CREATE TABLE ObjectClasses ( id SERIAL, Class integer NOT NULL, diff --git a/rt/etc/upgrade/3.9.8/schema.SQLite b/rt/etc/upgrade/3.9.8/schema.SQLite index 29ed7e8..b5af936 100644 --- a/rt/etc/upgrade/3.9.8/schema.SQLite +++ b/rt/etc/upgrade/3.9.8/schema.SQLite @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS Classes; CREATE TABLE Classes ( id INTEGER PRIMARY KEY, Name varchar(255) NOT NULL DEFAULT '', @@ -11,6 +12,7 @@ LastUpdated TIMESTAMP NULL, HotList smallint NOT NULL DEFAULT 0 ); +DROP TABLE IF EXISTS Articles; CREATE TABLE Articles ( id INTEGER PRIMARY KEY, Name varchar(255) NOT NULL DEFAULT '', @@ -25,7 +27,7 @@ LastUpdatedBy integer NOT NULL DEFAULT 0, LastUpdated TIMESTAMP NULL ); - +DROP TABLE IF EXISTS Topics; CREATE TABLE Topics ( id INTEGER PRIMARY KEY, Parent integer NOT NULL DEFAULT 0, @@ -36,6 +38,7 @@ ObjectId integer NOT NULL ); +DROP TABLE IF EXISTS ObjectTopics; CREATE TABLE ObjectTopics ( id INTEGER PRIMARY KEY, Topic integer NOT NULL, @@ -43,6 +46,7 @@ ObjectType varchar(64) NOT NULL DEFAULT '', ObjectId integer NOT NULL ); +DROP TABLE IF EXISTS ObjectClasses; CREATE TABLE ObjectClasses ( id INTEGER PRIMARY KEY, Class integer NOT NULL, diff --git a/rt/etc/upgrade/3.9.8/schema.mysql b/rt/etc/upgrade/3.9.8/schema.mysql index e7ed84d..4eaa3a1 100644 --- a/rt/etc/upgrade/3.9.8/schema.mysql +++ b/rt/etc/upgrade/3.9.8/schema.mysql @@ -1,3 +1,4 @@ +DROP TABLE IF EXISTS Classes; CREATE TABLE Classes ( id int(11) NOT NULL auto_increment, Name varchar(255) NOT NULL default '', @@ -12,6 +13,7 @@ CREATE TABLE Classes ( PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +DROP TABLE IF EXISTS Articles; CREATE TABLE Articles ( id int(11) NOT NULL auto_increment, Name varchar(255) NOT NULL default '', @@ -27,6 +29,7 @@ CREATE TABLE Articles ( PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +DROP TABLE IF EXISTS Topics; CREATE TABLE Topics ( id int(11) NOT NULL auto_increment, Parent int(11) NOT NULL default '0', @@ -37,6 +40,7 @@ CREATE TABLE Topics ( PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +DROP TABLE IF EXISTS ObjectTopics; CREATE TABLE ObjectTopics ( id int(11) NOT NULL auto_increment, Topic int(11) NOT NULL default '0', @@ -45,6 +49,7 @@ CREATE TABLE ObjectTopics ( PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +DROP TABLE IF EXISTS ObjectClasses; CREATE TABLE ObjectClasses ( id int(11) NOT NULL auto_increment, Class int(11) NOT NULL default '0', diff --git a/rt/etc/upgrade/4.0-customfield-checkbox-extension b/rt/etc/upgrade/4.0-customfield-checkbox-extension index 5f04cb1..dc8904e 100755 --- a/rt/etc/upgrade/4.0-customfield-checkbox-extension +++ b/rt/etc/upgrade/4.0-customfield-checkbox-extension @@ -46,15 +46,16 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} +use 5.10.1; use strict; use warnings; use lib "/opt/rt3/local/lib"; use lib "/opt/rt3/lib"; -use RT; -RT::LoadConfig(); -RT::Init(); +use RT -init + +$| = 1; use RT::CustomFields; my $cfs = RT::CustomFields->new( RT->SystemUser ); diff --git a/rt/etc/upgrade/4.0-customfield-checkbox-extension.in b/rt/etc/upgrade/4.0-customfield-checkbox-extension.in index 8cc0ec7..b3d466e 100644 --- a/rt/etc/upgrade/4.0-customfield-checkbox-extension.in +++ b/rt/etc/upgrade/4.0-customfield-checkbox-extension.in @@ -46,15 +46,16 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} +use 5.10.1; use strict; use warnings; use lib "@LOCAL_LIB_PATH@"; use lib "@RT_LIB_PATH@"; -use RT; -RT::LoadConfig(); -RT::Init(); +use RT -init; + +$| = 1; use RT::CustomFields; my $cfs = RT::CustomFields->new( RT->SystemUser ); diff --git a/rt/etc/upgrade/4.0.0rc7/content b/rt/etc/upgrade/4.0.0rc7/content index d0d210b..4fd63e7 100644 --- a/rt/etc/upgrade/4.0.0rc7/content +++ b/rt/etc/upgrade/4.0.0rc7/content @@ -1,19 +1,22 @@ -@Initial = ( +use strict; +use warnings; + +our @Initial = ( sub { - $RT::Logger->debug("Going to set lifecycle for approvals"); + RT->Logger->debug("Going to set lifecycle for approvals"); my $queue = RT::Queue->new( RT->SystemUser ); $queue->Load('___Approvals'); unless ( $queue->id ) { - $RT::Logger->warning("There is no ___Approvals queue in the DB"); + RT->Logger->warning("There is no ___Approvals queue in the DB"); return 1; } - return 1 if $queue->Lifecycle->Name eq 'approvals'; + return 1 if $queue->Lifecycle && $queue->Lifecycle eq 'approvals'; my ($status, $msg) = $queue->SetLifecycle('approvals'); unless ( $status ) { - $RT::Logger->error("Couldn't set lifecycle for '___Approvals' queue: $msg"); + RT->Logger->error("Couldn't set lifecycle for '___Approvals' queue: $msg"); return 0; } return 1; diff --git a/rt/etc/upgrade/4.0.1/content b/rt/etc/upgrade/4.0.1/content index 9b74ff1..cc3b5f1 100644 --- a/rt/etc/upgrade/4.0.1/content +++ b/rt/etc/upgrade/4.0.1/content @@ -1,40 +1,44 @@ -@Initial = ( +use strict; +use warnings; + +our @Initial = ( sub { - use strict; - $RT::Logger->debug('Removing all delegated rights'); + RT->Logger->debug('Removing all delegated rights'); my $acl = RT::ACL->new(RT->SystemUser); - my $groupjoin = $acl->NewAlias('Groups'); - $acl->Join( ALIAS1 => 'main', - FIELD1 => 'PrincipalId', - ALIAS2 => $groupjoin, - FIELD2 => 'id' - ); + my $groupjoin = $acl->Join( + ALIAS1 => 'main', + FIELD1 => 'PrincipalId', + TABLE2 => 'Groups', + FIELD2 => 'id', + ); $acl->Limit( ALIAS => $groupjoin, FIELD => 'Domain', OPERATOR => '=', VALUE => 'Personal', + CASESENSITIVE => 0, ); while ( my $ace = $acl->Next ) { my ( $ok, $msg ) = $ace->Delete(); if ( !$ok ) { - $RT::Logger->warn( "Unable to delete ACE " . $ace->id . ": " . $msg ); + RT->Logger->warn( "Unable to delete ACE " . $ace->id . ": " . $msg ); } } my $groups = RT::Groups->new(RT->SystemUser); $groups->Limit( FIELD => 'Domain', OPERATOR => '=', - VALUE => 'Personal' + VALUE => 'Personal', + CASESENSITIVE => 0, ); while ( my $group = $groups->Next ) { my $members = $group->MembersObj(); while ( my $member = $members->Next ) { my ( $ok, $msg ) = $group->DeleteMember( $member->MemberId ); if ( !$ok ) { - $RT::Logger->warn( "Unable to remove group member " + RT->Logger->warn( "Unable to remove group member " . $member->id . ": " . $msg ); } @@ -44,8 +48,7 @@ } }, sub { - use strict; - $RT::Logger->debug('Removing all Delegate and PersonalGroup rights'); + RT->Logger->debug('Removing all Delegate and PersonalGroup rights'); my $acl = RT::ACL->new(RT->SystemUser); for my $right (qw/AdminOwnPersonalGroups AdminAllPersonalGroups DelegateRights/) { @@ -54,16 +57,15 @@ while ( my $ace = $acl->Next ) { my ( $ok, $msg ) = $ace->Delete(); - $RT::Logger->debug("Removing ACE ".$ace->id." for right ".$ace->__Value('RightName')); + RT->Logger->debug("Removing ACE ".$ace->id." for right ".$ace->__Value('RightName')); if ( !$ok ) { - $RT::Logger->warn( "Unable to delete ACE " . $ace->id . ": " . $msg ); + RT->Logger->warn( "Unable to delete ACE " . $ace->id . ": " . $msg ); } } }, sub { - use strict; - $RT::Logger->debug('Removing unimplemented RejectTicket and ModifyTicketStatus rights'); + RT->Logger->debug('Removing unimplemented RejectTicket and ModifyTicketStatus rights'); my $acl = RT::ACL->new(RT->SystemUser); for my $right (qw/RejectTicket ModifyTicketStatus/) { @@ -72,10 +74,10 @@ while ( my $ace = $acl->Next ) { my ( $ok, $msg ) = $ace->Delete(); - $RT::Logger->debug("Removing ACE ".$ace->id." for right ".$ace->__Value('RightName')); + RT->Logger->debug("Removing ACE ".$ace->id." for right ".$ace->__Value('RightName')); if ( !$ok ) { - $RT::Logger->warn( "Unable to delete ACE " . $ace->id . ": " . $msg ); + RT->Logger->warn( "Unable to delete ACE " . $ace->id . ": " . $msg ); } } }, diff --git a/rt/etc/upgrade/4.0.18/content b/rt/etc/upgrade/4.0.18/content new file mode 100644 index 0000000..64eea9a --- /dev/null +++ b/rt/etc/upgrade/4.0.18/content @@ -0,0 +1,14 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + my $attr = RT->System->FirstAttribute('BrandedSubjectTag'); + return 1 unless $attr; + my ( $status, $msg ) = $attr->Delete; + unless ( $status ) { + RT->Logger->error("Couldn't delete System BrandedSubjectTag: $msg"); + } + return 1; + }, +); diff --git a/rt/etc/upgrade/4.0.19/content b/rt/etc/upgrade/4.0.19/content new file mode 100644 index 0000000..31e4d9f --- /dev/null +++ b/rt/etc/upgrade/4.0.19/content @@ -0,0 +1,29 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + use RT::CustomFields; + my $cfs = RT::CustomFields->new(RT->SystemUser); + $cfs->{'find_disabled_rows'} = 1; + $cfs->Limit( FIELD => 'LookupType', VALUE => 'RT::FM::Class-RT::FM::Article' ); + while ( my $cf = $cfs->Next ) { + my ($ret, $msg) = $cf->__Set( Field => 'LookupType', Value => 'RT::Class-RT::Article' ); + RT->Logger->warning("Update Custom Field LookupType for CF.".$cf->Id." $msg"); + } + return 1; + }, + + sub { + use RT::ObjectCustomFieldValues; + my $ocfvs = RT::ObjectCustomFieldValues->new(RT->System); + $ocfvs->{'find_expired_rows'} = 1; + $ocfvs->Limit( FIELD => 'ObjectType', VALUE => 'RT::FM::Article' ); + while ( my $ocfv = $ocfvs->Next ) { + my ($ret, $msg) = $ocfv->__Set( Field => 'ObjectType', Value => 'RT::Article' ); + RT->Logger->warning("Updated CF ".$ocfv->__Value('CustomField')." Value for Article ".$ocfv->__Value('ObjectId')); + } + return 1; + }, +); + diff --git a/rt/etc/upgrade/4.0.19/schema.mysql b/rt/etc/upgrade/4.0.19/schema.mysql new file mode 100644 index 0000000..de28cc9 --- /dev/null +++ b/rt/etc/upgrade/4.0.19/schema.mysql @@ -0,0 +1,5 @@ +ALTER TABLE Users MODIFY EmailAddress varchar(120) CHARACTER SET utf8; +ALTER TABLE Queues + MODIFY Lifecycle varchar(32) CHARACTER SET utf8, + MODIFY CorrespondAddress varchar(120) CHARACTER SET utf8, + MODIFY CommentAddress varchar(120) CHARACTER SET utf8; diff --git a/rt/etc/upgrade/4.0.3/content b/rt/etc/upgrade/4.0.3/content index 3e06c89..74870aa 100644 --- a/rt/etc/upgrade/4.0.3/content +++ b/rt/etc/upgrade/4.0.3/content @@ -1,4 +1,7 @@ -@ScripConditions = ( +use strict; +use warnings; + +our @ScripConditions = ( { Name => 'On Forward', # loc diff --git a/rt/etc/upgrade/4.0.4/content b/rt/etc/upgrade/4.0.4/content index fdfcb3e..4770289 100644 --- a/rt/etc/upgrade/4.0.4/content +++ b/rt/etc/upgrade/4.0.4/content @@ -1,4 +1,7 @@ -@Initial = ( +use strict; +use warnings; + +our @Initial = ( sub { use strict; my $templates = RT::Templates->new(RT->SystemUser); @@ -9,7 +12,7 @@ ); while (my $template = $templates->Next) { my ($status, $msg) = $template->SetType('Perl'); - $RT::Logger->warning( "Couldn't change Type of Template #" . $template->Id . ": $msg" ) unless $status; + RT->Logger->warning( "Couldn't change Type of Template #" . $template->Id . ": $msg" ) unless $status; } }, ); diff --git a/rt/etc/upgrade/4.0.6/content b/rt/etc/upgrade/4.0.6/content index dc1a009..ef01f4e 100644 --- a/rt/etc/upgrade/4.0.6/content +++ b/rt/etc/upgrade/4.0.6/content @@ -1,6 +1,9 @@ -@Initial = ( +use strict; +use warnings; + +our @Initial = ( sub { - my $txns = RT::Transactions->new( $RT::SystemUser ); + my $txns = RT::Transactions->new( RT->SystemUser ); $txns->Limit( FIELD => "ObjectType", VALUE => "RT::User", diff --git a/rt/etc/upgrade/4.0.9/content b/rt/etc/upgrade/4.0.9/content index f2abf62..6f526ce 100644 --- a/rt/etc/upgrade/4.0.9/content +++ b/rt/etc/upgrade/4.0.9/content @@ -1,6 +1,9 @@ -@Initial = ( +use strict; +use warnings; + +our @Initial = ( sub { - $RT::Logger->debug( + RT->Logger->debug( 'Going to update empty Queue Lifecycle column to "default"'); my $queues = RT::Queues->new( RT->SystemUser ); @@ -32,7 +35,8 @@ my $groups = RT::Groups->new(RT->SystemUser); $groups->Limit( FIELD => 'Domain', OPERATOR => '=', - VALUE => 'Personal' + VALUE => 'Personal', + CASESENSITIVE => 0, ); $groups->LimitToDeleted; while ( my $group = $groups->Next ) { @@ -40,7 +44,7 @@ while ( my $member = $members->Next ) { my ( $ok, $msg ) = $group->DeleteMember( $member->MemberId ); if ( !$ok ) { - $RT::Logger->warn( "Unable to remove group member " + RT->Logger->warn( "Unable to remove group member " . $member->id . ": " . $msg ); } diff --git a/rt/etc/upgrade/4.1.0/content b/rt/etc/upgrade/4.1.0/content new file mode 100644 index 0000000..2a02c68 --- /dev/null +++ b/rt/etc/upgrade/4.1.0/content @@ -0,0 +1,43 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + my $users = RT::Users->new(RT->SystemUser); + my $attributes = $users->Join( + ALIAS1 => "main", + FIELD1 => "id", + TABLE2 => "Attributes", + FIELD2 => "ObjectId", + ); + $users->Limit( + ALIAS => $attributes, + FIELD => "ObjectType", + VALUE => "RT::User", + ); + $users->Limit( + ALIAS => $attributes, + FIELD => "Name", + VALUE => RT::User::_PrefName('HomepageSettings'), + ); + + while (my $user = $users->Next) { + my $settings = $user->Preferences('HomepageSettings') + or next; + next if exists $settings->{sidebar}; + + $settings->{sidebar} = delete $settings->{summary}; + $user->SetPreferences('HomepageSettings', $settings); + } + }, + sub { + my ($default_portlets) = RT->System->Attributes->Named('HomepageSettings'); + my $settings = $default_portlets->Content; + return if exists $settings->{sidebar}; + + $settings->{sidebar} = delete $settings->{summary}; + $default_portlets->SetContent($settings); + }, +); + + diff --git a/rt/etc/upgrade/4.1.1/acl.Pg b/rt/etc/upgrade/4.1.1/acl.Pg new file mode 100644 index 0000000..9e8fc0a --- /dev/null +++ b/rt/etc/upgrade/4.1.1/acl.Pg @@ -0,0 +1,31 @@ + +sub acl { + my $dbh = shift; + + my @acls; + + my @tables = qw ( + objectscrips_id_seq + ObjectScrips + ); + + my $db_user = RT->Config->Get('DatabaseUser'); + + my $sequence_right + = ( $dbh->{pg_server_version} >= 80200 ) + ? "USAGE, SELECT, UPDATE" + : "SELECT, UPDATE"; + + foreach my $table (@tables) { + # Tables are upper-case, sequences are lowercase in @tables + if ( $table =~ /^[a-z]/ ) { + push @acls, "GRANT $sequence_right ON $table TO \"$db_user\";" + } + else { + push @acls, "GRANT SELECT, INSERT, UPDATE, DELETE ON $table TO \"$db_user\";" + } + } + return (@acls); +} + +1; diff --git a/rt/etc/upgrade/4.1.1/content b/rt/etc/upgrade/4.1.1/content new file mode 100644 index 0000000..f3580bd --- /dev/null +++ b/rt/etc/upgrade/4.1.1/content @@ -0,0 +1,36 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + require RT::ObjectScrips; + foreach my $stage ('TransactionCreate', 'TransactionBatch') { + my $applications = RT::ObjectScrips->new( RT->SystemUser ); + $applications->Limit( FIELD => 'Stage', VALUE => $stage ); + my $alias = $applications->Join( + FIELD1 => 'Scrip', + TABLE2 => 'Scrips', FIELD2 => 'id' + ); + $applications->OrderByCols( + { ALIAS => $alias, FIELD => 'Description', ORDER => 'ASC' }, + ); + my %h; my $top_so = $h{0} = 0; + while ( my $record = $applications->Next ) { + my $oid = $record->ObjectId || 0; + + my $so; + unless ( $oid ) { + %h = (); $h{0} = $so = ++$top_so; + } + else { + $so = $h{ $oid } = ($h{$oid}||$h{0}) + 1; + } + next if $record->SortOrder == $so; + + my ($status, $msg) = $record->SetSortOrder($so); + RT->Logger->error("Couldn't set sort order: $msg") + unless $status; + } + } + }, +); diff --git a/rt/etc/upgrade/4.1.1/schema.Oracle b/rt/etc/upgrade/4.1.1/schema.Oracle new file mode 100644 index 0000000..33ea738 --- /dev/null +++ b/rt/etc/upgrade/4.1.1/schema.Oracle @@ -0,0 +1,29 @@ +CREATE SEQUENCE OBJECTSCRIPS_seq; +CREATE TABLE ObjectScrips ( + id NUMBER(11,0) + CONSTRAINT ObjectScrips_Key PRIMARY KEY, + Scrip NUMBER(11,0) NOT NULL, + Stage VARCHAR2(32) DEFAULT 'TransactionCreate' NOT NULL, + ObjectId NUMBER(11,0) NOT NULL, + SortOrder NUMBER(11,0) DEFAULT 0 NOT NULL, + Creator NUMBER(11,0) DEFAULT 0 NOT NULL, + Created DATE, + LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL, + LastUpdated DATE +); +ALTER TABLE Scrips ADD Disabled NUMBER(11,0) DEFAULT 0 NOT NULL; + +INSERT INTO ObjectScrips( + id, Scrip, Stage, ObjectId, + Creator, Created, LastUpdatedBy, LastUpdated +) +(SELECT OBJECTSCRIPS_seq.nextval, id, Stage, Queue, Creator, Created, LastUpdatedBy, LastUpdated +FROM Scrips) +; + +UPDATE Scrips SET Disabled = 1 WHERE Stage = 'Disabled'; +UPDATE ObjectScrips SET Stage = 'TransactionCreate' WHERE Stage = 'Disabled'; + +CREATE UNIQUE INDEX ObjectScrips1 ON ObjectScrips (ObjectId, Scrip); + +ALTER TABLE Scrips DROP( Stage, Queue ); diff --git a/rt/etc/upgrade/4.1.1/schema.Pg b/rt/etc/upgrade/4.1.1/schema.Pg new file mode 100644 index 0000000..91ba5a6 --- /dev/null +++ b/rt/etc/upgrade/4.1.1/schema.Pg @@ -0,0 +1,36 @@ +DROP TABLE IF EXISTS ObjectScrips; +DROP SEQUENCE IF EXISTS objectscrips_id_seq; + +CREATE SEQUENCE objectscrips_id_seq; +CREATE TABLE ObjectScrips ( + id INTEGER DEFAULT nextval('objectscrips_id_seq'), + Scrip integer NOT NULL, + Stage varchar(32) NOT NULL DEFAULT 'TransactionCreate' , + ObjectId integer NOT NULL, + SortOrder integer NOT NULL DEFAULT 0 , + + Creator integer NOT NULL DEFAULT 0 , + Created TIMESTAMP NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated TIMESTAMP NULL , + PRIMARY KEY (id) + +); +ALTER TABLE Scrips ADD COLUMN Disabled int2 NOT NULL DEFAULT 0; + +INSERT INTO ObjectScrips( + Scrip, Stage, ObjectId, + Creator, Created, LastUpdatedBy, LastUpdated +) +SELECT id, Stage, Queue, Creator, Created, LastUpdatedBy, LastUpdated +FROM Scrips +; + +UPDATE Scrips SET Disabled = 1 WHERE Stage = 'Disabled'; +UPDATE ObjectScrips SET Stage = 'TransactionCreate' WHERE Stage = 'Disabled'; + +CREATE UNIQUE INDEX ObjectScrips1 ON ObjectScrips (ObjectId, Scrip); + +ALTER TABLE Scrips + DROP COLUMN Stage, + DROP COLUMN Queue; diff --git a/rt/etc/upgrade/4.1.1/schema.SQLite b/rt/etc/upgrade/4.1.1/schema.SQLite new file mode 100644 index 0000000..2a6a2c4 --- /dev/null +++ b/rt/etc/upgrade/4.1.1/schema.SQLite @@ -0,0 +1,31 @@ +DROP TABLE IF EXISTS ObjectScrips; +CREATE TABLE ObjectScrips ( + id INTEGER NOT NULL , + Scrip int NOT NULL , + Stage varchar(32) NOT NULL DEFAULT 'TransactionCreate' , + ObjectId integer NOT NULL, + SortOrder integer NOT NULL DEFAULT 0 , + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +); +ALTER TABLE Scrips ADD COLUMN Disabled int2 NOT NULL DEFAULT 0; + +INSERT INTO ObjectScrips( + Scrip, Stage, ObjectId, + Creator, Created, LastUpdatedBy, LastUpdated +) +SELECT id, Stage, Queue, Creator, Created, LastUpdatedBy, LastUpdated +FROM Scrips +; + +UPDATE Scrips SET Disabled = 1 WHERE Stage = 'Disabled'; +UPDATE ObjectScrips SET Stage = 'TransactionCreate' WHERE Stage = 'Disabled'; + +CREATE UNIQUE INDEX ObjectScrips1 ON ObjectScrips (ObjectId, Scrip); + +# TODO: ALTER TABLE Scrips DROP COLUMN Stage; +# TODO: ALTER TABLE Scrips DROP COLUMN Queue; diff --git a/rt/etc/upgrade/4.1.1/schema.mysql b/rt/etc/upgrade/4.1.1/schema.mysql new file mode 100644 index 0000000..82f3f84 --- /dev/null +++ b/rt/etc/upgrade/4.1.1/schema.mysql @@ -0,0 +1,32 @@ +DROP TABLE IF EXISTS ObjectScrips; +CREATE TABLE ObjectScrips ( + id INTEGER NOT NULL AUTO_INCREMENT, + Scrip integer NOT NULL , + Stage varchar(32) CHARACTER SET ascii NOT NULL DEFAULT 'TransactionCreate', + ObjectId integer NOT NULL, + SortOrder integer NOT NULL DEFAULT 0 , + + Creator integer NOT NULL DEFAULT 0 , + Created DATETIME NULL , + LastUpdatedBy integer NOT NULL DEFAULT 0 , + LastUpdated DATETIME NULL , + PRIMARY KEY (id) +) ENGINE=InnoDB CHARACTER SET utf8; +ALTER TABLE Scrips ADD COLUMN Disabled int2 NOT NULL DEFAULT 0; + +INSERT INTO ObjectScrips( + Scrip, Stage, ObjectId, + Creator, Created, LastUpdatedBy, LastUpdated +) +SELECT id, Stage, Queue, Creator, Created, LastUpdatedBy, LastUpdated +FROM Scrips +; + +UPDATE Scrips SET Disabled = 1 WHERE Stage = 'Disabled'; +UPDATE ObjectScrips SET Stage = 'TransactionCreate' WHERE Stage = 'Disabled'; + +CREATE UNIQUE INDEX ObjectScrips1 ON ObjectScrips (ObjectId, Scrip); + +ALTER TABLE Scrips + DROP COLUMN Stage, + DROP COLUMN Queue; diff --git a/rt/etc/upgrade/4.1.10/schema.Oracle b/rt/etc/upgrade/4.1.10/schema.Oracle new file mode 100644 index 0000000..93f036f --- /dev/null +++ b/rt/etc/upgrade/4.1.10/schema.Oracle @@ -0,0 +1 @@ +-- No update is necessary, given that '' == NULL on Oracle diff --git a/rt/etc/upgrade/4.1.10/schema.Pg b/rt/etc/upgrade/4.1.10/schema.Pg new file mode 100644 index 0000000..af862b6 --- /dev/null +++ b/rt/etc/upgrade/4.1.10/schema.Pg @@ -0,0 +1 @@ +UPDATE ObjectCustomFieldValues SET Content = NULL WHERE LargeContent IS NOT NULL AND Content = ''; diff --git a/rt/etc/upgrade/4.1.10/schema.mysql b/rt/etc/upgrade/4.1.10/schema.mysql new file mode 100644 index 0000000..af862b6 --- /dev/null +++ b/rt/etc/upgrade/4.1.10/schema.mysql @@ -0,0 +1 @@ +UPDATE ObjectCustomFieldValues SET Content = NULL WHERE LargeContent IS NOT NULL AND Content = ''; diff --git a/rt/etc/upgrade/4.1.11/schema.Oracle b/rt/etc/upgrade/4.1.11/schema.Oracle new file mode 100644 index 0000000..6ae68bd --- /dev/null +++ b/rt/etc/upgrade/4.1.11/schema.Oracle @@ -0,0 +1 @@ +ALTER TABLE CustomFields DROP COLUMN Repeated; diff --git a/rt/etc/upgrade/4.1.11/schema.Pg b/rt/etc/upgrade/4.1.11/schema.Pg new file mode 100644 index 0000000..6ae68bd --- /dev/null +++ b/rt/etc/upgrade/4.1.11/schema.Pg @@ -0,0 +1 @@ +ALTER TABLE CustomFields DROP COLUMN Repeated; diff --git a/rt/etc/upgrade/4.1.11/schema.mysql b/rt/etc/upgrade/4.1.11/schema.mysql new file mode 100644 index 0000000..6ae68bd --- /dev/null +++ b/rt/etc/upgrade/4.1.11/schema.mysql @@ -0,0 +1 @@ +ALTER TABLE CustomFields DROP COLUMN Repeated; diff --git a/rt/etc/upgrade/4.1.12/content b/rt/etc/upgrade/4.1.12/content new file mode 100644 index 0000000..1f0473d --- /dev/null +++ b/rt/etc/upgrade/4.1.12/content @@ -0,0 +1,10 @@ +use strict; +use warnings; + +our @ACL = ( { + Right => 'ShowArticlesMenu', + GroupDomain => 'SystemInternal', + GroupType => 'Privileged', +} ); + +1; diff --git a/rt/etc/upgrade/4.1.13/backcompat b/rt/etc/upgrade/4.1.13/backcompat new file mode 100644 index 0000000..0dc53d2 --- /dev/null +++ b/rt/etc/upgrade/4.1.13/backcompat @@ -0,0 +1,34 @@ +my $upgrade = shift; + +my $groups = RT::Groups->new( RT->SystemUser ); +$groups->Limit( + FIELD => 'Name', OPERATOR => '!=', VALUE => 'main.Type', QUOTEVALUE => 0 +); +$groups->Limit( + FIELD => 'Name', OPERATOR => 'IS', VALUE => 'NULL', +); +$groups->Limit( + FIELD => 'Domain', + VALUE => 'SystemInternal', + CASESENSITIVE => 0, +); +$groups->RowsPerPage(1); +if ( $groups->Next ) { + my $dbh = $RT::Handle->dbh; + my $db_type = RT->Config->Get('DatabaseType'); + if ( $db_type eq 'Oracle' || $db_type eq 'Pg' ) { + $dbh->do( + "UPDATE Groups SET Name = Type + WHERE LOWER(Domain) IN ('aclequivalence', 'systeminternal') + OR LOWER(Domain) LIKE '%-role'" + ); + } else { + $dbh->do( + "UPDATE Groups SET Name = Type + WHERE Domain IN ('ACLEquivalence', 'SystemInternal') + OR Domain LIKE '%-Role'" + ); + } +} + +$upgrade->(); diff --git a/rt/etc/upgrade/4.1.13/schema.Oracle b/rt/etc/upgrade/4.1.13/schema.Oracle new file mode 100644 index 0000000..96869c6 --- /dev/null +++ b/rt/etc/upgrade/4.1.13/schema.Oracle @@ -0,0 +1,3 @@ +UPDATE Groups SET Name = Type +WHERE LOWER(Domain) IN ('aclequivalence', 'systeminternal') OR LOWER(Domain) LIKE '%-role'; + diff --git a/rt/etc/upgrade/4.1.13/schema.Pg b/rt/etc/upgrade/4.1.13/schema.Pg new file mode 100644 index 0000000..96869c6 --- /dev/null +++ b/rt/etc/upgrade/4.1.13/schema.Pg @@ -0,0 +1,3 @@ +UPDATE Groups SET Name = Type +WHERE LOWER(Domain) IN ('aclequivalence', 'systeminternal') OR LOWER(Domain) LIKE '%-role'; + diff --git a/rt/etc/upgrade/4.1.13/schema.SQLite b/rt/etc/upgrade/4.1.13/schema.SQLite new file mode 100644 index 0000000..9ea6a91 --- /dev/null +++ b/rt/etc/upgrade/4.1.13/schema.SQLite @@ -0,0 +1,3 @@ +UPDATE Groups SET Name = Type +WHERE Domain IN ('ACLEquivalence', 'SystemInternal') OR Domain LIKE '%-Role'; + diff --git a/rt/etc/upgrade/4.1.13/schema.mysql b/rt/etc/upgrade/4.1.13/schema.mysql new file mode 100644 index 0000000..a429007 --- /dev/null +++ b/rt/etc/upgrade/4.1.13/schema.mysql @@ -0,0 +1,2 @@ +UPDATE Groups SET Name = Type +WHERE Domain IN ('ACLEquivalence', 'SystemInternal') OR Domain LIKE '%-Role';
\ No newline at end of file diff --git a/rt/etc/upgrade/4.1.14/schema.Oracle b/rt/etc/upgrade/4.1.14/schema.Oracle new file mode 100644 index 0000000..f626093 --- /dev/null +++ b/rt/etc/upgrade/4.1.14/schema.Oracle @@ -0,0 +1 @@ +ALTER TABLE Scrips DROP( ConditionRules, ActionRules ); diff --git a/rt/etc/upgrade/4.1.14/schema.Pg b/rt/etc/upgrade/4.1.14/schema.Pg new file mode 100644 index 0000000..0b45d51 --- /dev/null +++ b/rt/etc/upgrade/4.1.14/schema.Pg @@ -0,0 +1,3 @@ +ALTER TABLE Scrips + DROP COLUMN ConditionRules, + DROP COLUMN ActionRules; diff --git a/rt/etc/upgrade/4.1.14/schema.mysql b/rt/etc/upgrade/4.1.14/schema.mysql new file mode 100644 index 0000000..0b45d51 --- /dev/null +++ b/rt/etc/upgrade/4.1.14/schema.mysql @@ -0,0 +1,3 @@ +ALTER TABLE Scrips + DROP COLUMN ConditionRules, + DROP COLUMN ActionRules; diff --git a/rt/etc/upgrade/4.1.15/content b/rt/etc/upgrade/4.1.15/content new file mode 100644 index 0000000..3e1f1d5 --- /dev/null +++ b/rt/etc/upgrade/4.1.15/content @@ -0,0 +1,22 @@ +use strict; +use warnings; + +our @ScripActions = ( + { Name => 'Notify Owner and AdminCcs', # loc + Description => 'Sends mail to the Owner and administrative Ccs', # loc + ExecModule => 'Notify', + Argument => 'Owner,AdminCc' }, +); + +our @Templates = ( + # Shadow the global templates of the same name to suppress duplicate + # notifications until rules is ripped out. + { Queue => "___Approvals", + Name => "Transaction in HTML", + Content => "", + }, + { Queue => "___Approvals", + Name => "Transaction", + Content => "", + }, +); diff --git a/rt/etc/upgrade/4.1.16/content b/rt/etc/upgrade/4.1.16/content new file mode 100644 index 0000000..44f2129 --- /dev/null +++ b/rt/etc/upgrade/4.1.16/content @@ -0,0 +1,16 @@ +use strict; +use warnings; + +our @Templates = ( + { Queue => '0', + Name => 'Reminder', # loc + Description => 'Default reminder template', # loc + Content => +'Subject:{$Ticket->Subject} is due {$Ticket->DueObj->AsString} + +This reminder is for ticket #{$Target = $Ticket->RefersTo->First->TargetObj;$Target->Id}. + +{RT->Config->Get(\'WebURL\')}Ticket/Display.html?id={$Target->Id} +' + }, +); diff --git a/rt/etc/upgrade/4.1.17/content b/rt/etc/upgrade/4.1.17/content new file mode 100644 index 0000000..2e6a78c --- /dev/null +++ b/rt/etc/upgrade/4.1.17/content @@ -0,0 +1,26 @@ +use strict; +use warnings; + +our @Initial = (sub { + my $searches = RT::Attributes->new(RT->SystemUser); + $searches->Limit( FIELD => 'Name', VALUE => 'SavedSearch' ); + $searches->OrderBy( FIELD => 'id' ); + + while (my $search = $searches->Next) { + my $content = $search->Content; + next unless ref $content eq 'HASH'; + next unless ($content->{SearchType} || '') eq 'Chart'; + + # Switch from PrimaryGroupBy to GroupBy name + # Switch from "CreatedMonthly" to "Created.Monthly" + $content->{GroupBy} ||= [delete $content->{PrimaryGroupBy}]; + for (@{$content->{GroupBy}}) { + next if !defined || /\./; + s/(?<=[a-z])(?=[A-Z])/./; + } + + my ($ok, $msg) = $search->SetContent($content); + RT->Logger->error("Unable to upgrade saved chart #@{[$search->id]}: $msg") + unless $ok; + } +}); diff --git a/rt/etc/upgrade/4.1.18/content b/rt/etc/upgrade/4.1.18/content new file mode 100644 index 0000000..818351b --- /dev/null +++ b/rt/etc/upgrade/4.1.18/content @@ -0,0 +1,16 @@ +use strict; +use warnings; + +# Ticket-level notifications +our @ScripActions = ({ + Name => 'On SetStarted Open Ticket', + Description => 'When Started is Updated Set Ticket Status to Open', + ExecModule => 'OpenOnStarted', +}); + +our @Scrips = ({ + Description => "On transaction and SetStarted Open Ticket", + ScripCondition => 'On Transaction', + ScripAction => 'On SetStarted Open Ticket', + Template => 'Blank' +}); diff --git a/rt/etc/upgrade/4.1.19/schema.Oracle b/rt/etc/upgrade/4.1.19/schema.Oracle new file mode 100644 index 0000000..2371a5d --- /dev/null +++ b/rt/etc/upgrade/4.1.19/schema.Oracle @@ -0,0 +1 @@ +ALTER TABLE Templates DROP( Language, TranslationOf ); diff --git a/rt/etc/upgrade/4.1.19/schema.Pg b/rt/etc/upgrade/4.1.19/schema.Pg new file mode 100644 index 0000000..cfaa9a7 --- /dev/null +++ b/rt/etc/upgrade/4.1.19/schema.Pg @@ -0,0 +1,3 @@ +ALTER TABLE Templates + DROP COLUMN Language, + DROP COLUMN TranslationOf; diff --git a/rt/etc/upgrade/4.1.19/schema.mysql b/rt/etc/upgrade/4.1.19/schema.mysql new file mode 100644 index 0000000..cfaa9a7 --- /dev/null +++ b/rt/etc/upgrade/4.1.19/schema.mysql @@ -0,0 +1,3 @@ +ALTER TABLE Templates + DROP COLUMN Language, + DROP COLUMN TranslationOf; diff --git a/rt/etc/upgrade/4.1.20/content b/rt/etc/upgrade/4.1.20/content new file mode 100644 index 0000000..edde022 --- /dev/null +++ b/rt/etc/upgrade/4.1.20/content @@ -0,0 +1,56 @@ +use strict; +use warnings; + +our @ScripActions = ( + { Name => 'Send Forward', + Description => 'Send forwarded message', + ExecModule => 'SendForward', }, +); + +our @Scrips = ( + { Description => 'On Forward Transaction Send forwarded message', + ScripCondition => 'On Forward Transaction', + ScripAction => 'Send Forward', + Template => 'Forward' }, + { Description => 'On Forward Ticket Send forwarded message', + ScripCondition => 'On Forward Ticket', + ScripAction => 'Send Forward', + Template => 'Forward Ticket' }, +); + +our @Initial = ( + sub { + my $forward_template = RT::Template->new(RT->SystemUser); + $forward_template->Load('Forward'); + $forward_template->SetDescription('Forwarded message'); + + if ( $forward_template->Content =~ + m/^\n*This is (a )?forward of transaction #\{\s*\$Transaction->id\s*\} of (a )?ticket #\{\s*\$Ticket->id\s*\}\n*$/ + ) { + $forward_template->SetContent(q{ + +{ $ForwardTransaction->Content =~ /\S/ ? $ForwardTransaction->Content : "This is a forward of transaction #".$Transaction->id." of ticket #". $Ticket->id } +}); + } + else { + RT->Logger->error('Current "Forward" template is not the default version, please check docs/UPGRADING-4.2'); + } + + my $forward_ticket_template = RT::Template->new(RT->SystemUser); + $forward_ticket_template->Load('Forward Ticket'); + $forward_ticket_template->SetDescription('Forwarded ticket message'); + if ( $forward_ticket_template->Content eq q{ + +This is a forward of ticket #{ $Ticket->id } +} ) { + $forward_ticket_template->SetContent(q{ + +{ $ForwardTransaction->Content =~ /\S/ ? $ForwardTransaction->Content : "This is a forward of ticket #". $Ticket->id } +}); + + } + else { + RT->Logger->error('Current "Forward Ticket" template is not the default version, please check docs/UPGRADING-4.2'); + } + }, +); diff --git a/rt/etc/upgrade/4.1.21/content b/rt/etc/upgrade/4.1.21/content new file mode 100644 index 0000000..dbf75c7 --- /dev/null +++ b/rt/etc/upgrade/4.1.21/content @@ -0,0 +1,64 @@ +use strict; +use warnings; + +sub dashboards_for_object { + my $object = shift; + my $user = shift; + my %dashboards; + my $privacy = RT::Dashboard->_build_privacy($object); + + while ( my $attr = $object->Attributes->Next ) { + if ( $attr->Name =~ /^Dashboard\b/ ) { + my $dashboard = RT::Dashboard->new($user); + my ( $ok, $msg ) = $dashboard->Load( $privacy, $attr->id ); + next unless $ok; + + if ( $object->isa('RT::System') ) { + push @{ $dashboards{system} }, $dashboard; + } + elsif ( $object->isa('RT::User') ) { + push @{ $dashboards{personal} }, $dashboard; + } + elsif ( $object->isa('RT::Group') ) { + push @{ $dashboards{group}{ $object->Name } }, $dashboard; + } + } + } + return \%dashboards; +} + +our @Final = ( + sub { + my $users = RT::Users->new( RT->SystemUser ); + $users->LimitToPrivileged(); + while ( my $user = $users->Next ) { + my @objs = RT::Dashboard->new($user)->ObjectsForLoading( IncludeSuperuserGroups => 0 ); + + my %dashboard_map; + + for my $object (@objs) { + my $dashboards = dashboards_for_object( $object, $user ); + push @{ $dashboard_map{$_} }, @{ $dashboards->{$_} || [] } for qw/personal system/; + + push @{ $dashboard_map{group}{$_} }, @{ $dashboards->{group}{$_} } + for keys %{ $dashboards->{group} || {} }; + } + + my @dashboards = ( + ( sort { $a->Id <=> $b->Id } @{ $dashboard_map{personal} || [] } ), + ( sort { $a->Id <=> $b->Id } @{ $dashboard_map{system} || [] } ), + + map { + sort { $a->Id <=> $b->Id } + @{ $dashboard_map{group}{$_} } + } + keys %{ $dashboard_map{group} || {} }, + ); + + splice @dashboards, 7 if @dashboards > 7; + @dashboards = map { $_->id } @dashboards; + my ( $ret, $msg ) = $user->SetPreferences( 'DashboardsInMenu', { dashboards => \@dashboards } ); + RT->Logger->error( $msg ) unless $ret; + } + }, +); diff --git a/rt/etc/upgrade/4.1.22/content b/rt/etc/upgrade/4.1.22/content new file mode 100644 index 0000000..c9f18ff --- /dev/null +++ b/rt/etc/upgrade/4.1.22/content @@ -0,0 +1,85 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + my $template = RT::Template->new( RT->SystemUser ); + $template->Load("Error: bad GnuPG data"); + unless ($template->id) { + RT->Logger->error( "Couldn't find 'Error: bad GnuPG data' template to rename" ); + return; + } + + my ($ok, $msg) = $template->SetName("Error: bad encrypted data"); + RT->Logger->error( "Couldn't rename 'Error: bad GnuPG data' template: $msg") + unless $ok; + + ($ok, $msg) = $template->SetDescription("Inform user that a message he sent has invalid encryption data"); + RT->Logger->error( "Couldn't update 'Error: bad encrypted data' template description: $msg") + unless $ok; + + my $content = $template->Content; + $content =~ s/GnuPG signature/signature/g; + ($ok, $msg) = $template->SetContent( $content ); + RT->Logger->error( "Couldn't update 'Error: bad encrypted data' template content: $msg") + unless $ok; + }, + sub { + my $type = RT::User->new( $RT::SystemUser )->CustomFieldLookupType; + my $cf = RT::CustomField->new( $RT::SystemUser ); + $cf->LoadByCols( Name => 'SMIME Key', LookupType => $type ); + $cf->LoadByCols( Name => 'PublicKey', LookupType => $type ) unless $cf->id; + unless ( $cf->id ) { + $RT::Logger->debug("You don't have an 'SMIME Key' or 'PublicKey' user CF -- nothing to do."); + return; + } + + my $users = RT::Users->new( RT->SystemUser ); + $users->LimitCustomField( + CUSTOMFIELD => $cf->id, + OPERATOR => "IS NOT", + VALUE => "NULL", + ); + while (my $u = $users->Next) { + $u->SetSMIMECertificate( + $u->FirstCustomFieldValue( $cf->id ), + ); + } + + my $ocfs = $cf->AddedTo; + while (my $ocf = $ocfs->Next) { + my ($ok, $msg) = $ocf->Delete; + RT->Logger->error( "Couldn't delete OCF ".$ocf->id." while deleting ".$cf->Name." CF: $msg") + unless $ok; + } + + my ($ok, $msg) = $cf->Delete; + RT->Logger->error( "Couldn't delete ".$cf->Name." CF: $msg") + unless $ok; + }, + sub { + $RT::Logger->info("Going to delete all SMIMEKeyNotAfter attributes"); + my $attrs = RT::Attributes->new( $RT::SystemUser ); + $attrs->Limit( FIELD => 'ObjectType', VALUE => 'RT::User' ); + $attrs->Limit( FIELD => 'Name', VALUE => 'SMIMEKeyNotAfter' ); + while ( my $attr = $attrs->Next ) { + my ($status, $msg) = $attr->Delete; + unless ( $status ) { + $RT::Logger->error("Couldn't delete attribute: $msg"); + } + } + return 1; + }, +); + +our @Templates = ( + { Queue => 0, + Name => "Error: unencrypted message", # loc + Description => + "Inform user that their unencrypted mail has been rejected", # loc + Content => q{Subject: RT requires that all incoming mail be encrypted + +You received this message because RT received mail from you that was not encrypted. As such, it has been rejected. +} + }, +); diff --git a/rt/etc/upgrade/4.1.22/schema.Oracle b/rt/etc/upgrade/4.1.22/schema.Oracle new file mode 100644 index 0000000..273779b --- /dev/null +++ b/rt/etc/upgrade/4.1.22/schema.Oracle @@ -0,0 +1 @@ +ALTER TABLE Users ADD SMIMECertificate CLOB; diff --git a/rt/etc/upgrade/4.1.22/schema.Pg b/rt/etc/upgrade/4.1.22/schema.Pg new file mode 100644 index 0000000..7da9d2c --- /dev/null +++ b/rt/etc/upgrade/4.1.22/schema.Pg @@ -0,0 +1 @@ +ALTER TABLE Users ADD COLUMN SMIMECertificate TEXT NULL; diff --git a/rt/etc/upgrade/4.1.22/schema.SQLite b/rt/etc/upgrade/4.1.22/schema.SQLite new file mode 100644 index 0000000..3b7d6ce --- /dev/null +++ b/rt/etc/upgrade/4.1.22/schema.SQLite @@ -0,0 +1 @@ +ALTER TABLE Users ADD COLUMN SMIMECertificate TEXT COLLATE NOCASE NULL; diff --git a/rt/etc/upgrade/4.1.22/schema.mysql b/rt/etc/upgrade/4.1.22/schema.mysql new file mode 100644 index 0000000..7da9d2c --- /dev/null +++ b/rt/etc/upgrade/4.1.22/schema.mysql @@ -0,0 +1 @@ +ALTER TABLE Users ADD COLUMN SMIMECertificate TEXT NULL; diff --git a/rt/etc/upgrade/4.1.23/indexes b/rt/etc/upgrade/4.1.23/indexes new file mode 100644 index 0000000..78db4aee --- /dev/null +++ b/rt/etc/upgrade/4.1.23/indexes @@ -0,0 +1,168 @@ +use strict; +use warnings; + +# groups table +{ + foreach my $name ( qw(Groups1 Groups2 Groups3) ) { + my ($status, $msg) = $RT::Handle->DropIndexIfExists( + Table => 'Groups', Name => $name, + ); + my $method = $status ? 'debug' : 'warning'; + RT->Logger->$method($msg); + } + + my ($name, $msg) = $RT::Handle->CreateIndex( + Table => 'Groups', + Columns => [qw(Domain Type Instance)], + CaseInsensitive => { domain => 1, type => 1 }, + ); + my $method = $name ? 'debug' : 'warning'; + RT->Logger->$method($msg); + + ($name, $msg) = $RT::Handle->CreateIndex( + Table => 'Groups', + Columns => [qw(Domain Name Instance)], + CaseInsensitive => { domain => 1, name => 1 }, + ); + $method = $name ? 'debug' : 'warning'; + RT->Logger->$method($msg); + + ($name, $msg) = $RT::Handle->CreateIndex( + Table => 'Groups', + Columns => [qw(Instance)], + ); + $method = $name ? 'debug' : 'warning'; + RT->Logger->$method($msg); +} + +my $dedup = sub { + my ($table, $column) = (@_); + + my $collection_class = "RT::$table"; + my $record_class = $collection_class; + $record_class =~ s/s$//; + + my $sql; + + my $cs = $RT::Handle->CaseSensitive; + if ($cs) { + $sql = "SELECT DISTINCT LOWER(t1.$column) FROM $table t1, $table t2" + ." WHERE LOWER(t1.$column) = LOWER(t2.$column)" + .' AND t1.id != t2.id'; + } else { + $sql = "SELECT DISTINCT t1.$column FROM $table t1, $table t2" + ." WHERE t1.$column = t2.$column" + .' AND t1.id != t2.id'; + } + + my $dbh = $RT::Handle->dbh; + my $sth = $dbh->prepare($sql); + $sth->execute; + + my $found = 0; + while ( my ($value) = $sth->fetchrow_array ) { + $found = 1; + + my $ids = $dbh->selectcol_arrayref( + "SELECT id FROM $table WHERE ". ($cs? "LOWER($column)" : $column) ." = LOWER(?)", + undef, + $value + ); + + # skip first + shift @$ids; + + foreach my $id ( @$ids ) { + RT->Logger->debug("Changing $column of $record_class #". $id ); + $dbh->do("UPDATE $table SET $column = ? WHERE id = ?", undef, $value . '-dup-'.$id, $id); + } + } + + if ( $found ) { + RT->Logger->warning( + "Records in $table table had non-unique values in $column column." + ." $column has been changed for such records, and now matches '%-dup-%'" + ); + } +}; + +# a few case insensitive and unique indexes +{ + my @list = ( + { Table => 'Queues', Column => 'Name' }, + { Table => 'Users', Column => 'Name' }, + ); + foreach my $e (@list) { + RT->Logger->debug("Checking index on ". $e->{'Column'} ." in ". $e->{'Table'} ); + my (@indexes) = $RT::Handle->IndexesThatBeginWith( + Table => $e->{'Table'}, Columns => [$e->{'Column'}] + ); + @indexes = grep {@{$_->{'Columns'}} == 1} @indexes; + if (grep {$_->{Unique} && ($RT::Handle->CaseSensitive? $_->{'CaseInsensitive'}{ lc $e->{'Column'} } : 1 ) } @indexes + ) { + RT->Logger->debug("Required index exists. Skipping."); + next; + } + + $dedup->( $e->{'Table'}, $e->{'Column'} ); + + for my $index ( @indexes ) { + my ($status, $msg) = $RT::Handle->DropIndex( + Table => $e->{'Table'}, Name => $index->{'Name'}, + ); + my $method = $status ? 'debug' : 'warning'; + RT->Logger->$method($msg); + } + + my ($status, $msg) = $RT::Handle->CreateIndex( + Table => $e->{'Table'}, Columns => [$e->{'Column'}], + Unique => 1, CaseInsensitive => { lc $e->{'Column'} => 1 }, + ); + my $method = $status ? 'debug' : 'warning'; + RT->Logger->$method($msg); + } +} + +# cached group members +{ + $RT::Handle->MakeSureIndexExists( + Table => 'CachedGroupMembers', + Columns => ['MemberId', 'ImmediateParentId'], + ); + $RT::Handle->MakeSureIndexExists( + Table => 'CachedGroupMembers', + Columns => ['MemberId', 'GroupId'], + Optional => ['Disabled'], + ); + $RT::Handle->DropIndexesThatArePrefix( + Table => 'CachedGroupMembers', + Columns => ['MemberId', 'GroupId', 'Disabled'], + ); + $RT::Handle->MakeSureIndexExists( + Table => 'CachedGroupMembers', + Columns => ['GroupId', 'MemberId'], + Optional => ['Disabled'], + ); + $RT::Handle->DropIndexesThatArePrefix( + Table => 'CachedGroupMembers', + Columns => ['GroupId', 'MemberId', 'Disabled'], + ); +} + +# drop indexes that start with 'id' column +foreach my $table ('Users', 'Tickets') { + my @list = $RT::Handle->IndexesThatBeginWith( + Table => $table, Columns => ['id'], + ); + @list = grep @{ $_->{'Columns'} } > 1, @list; + + foreach my $index (@list) { + my ($status, $msg) = $RT::Handle->DropIndex( + Table => $table, Name => $index->{'Name'}, + ); + my $method = $status ? 'debug' : 'warning'; + RT->Logger->$method($msg); + } +} + +1; diff --git a/rt/etc/upgrade/4.1.4/content b/rt/etc/upgrade/4.1.4/content new file mode 100644 index 0000000..b320695 --- /dev/null +++ b/rt/etc/upgrade/4.1.4/content @@ -0,0 +1,49 @@ +use strict; +use warnings; + +our (@Final); + +push @Final, sub { + my %global = %{ RT->System->AvailableRights }; + my $handle = RT->DatabaseHandle; + + for my $role (RT::System->Roles) { + my $group = RT::Group->new( RT->SystemUser ); + my ($ok, $msg) = $group->LoadRoleGroup( + Object => RT->System, + Name => $role, + ); + + unless ($group->id) { + RT->Logger->error("Can't load role group $role: $msg"); + next; + } + + my %rights = %{ RT->System->AvailableRights( $group->PrincipalObj ) }; + + # Global rights which aren't available on the role anymore + my @remove = grep { not $rights{$_} } + keys %global; + my $placeholders = join ",", map { "?" } 1 .. scalar @remove; + + my $query = <<" SQL"; + DELETE FROM ACL + WHERE PrincipalType = ? + AND PrincipalId = ? + AND ObjectType = 'RT::System' + AND RightName IN ($placeholders) + SQL + + my $res = $handle->SimpleQuery( + $query, + $role, # Type + $group->PrincipalId, # Id + @remove, # Right names + ); + + unless ($res) { + RT->Logger->error("Failed to delete invalid rights on system role $role!"); + next; + } + } +}; diff --git a/rt/etc/upgrade/4.1.4/schema.Oracle b/rt/etc/upgrade/4.1.4/schema.Oracle new file mode 100644 index 0000000..e530ede --- /dev/null +++ b/rt/etc/upgrade/4.1.4/schema.Oracle @@ -0,0 +1 @@ +UPDATE Groups SET Instance = 1 WHERE Domain = 'RT::System-Role' AND Instance = 0; diff --git a/rt/etc/upgrade/4.1.4/schema.Pg b/rt/etc/upgrade/4.1.4/schema.Pg new file mode 100644 index 0000000..e530ede --- /dev/null +++ b/rt/etc/upgrade/4.1.4/schema.Pg @@ -0,0 +1 @@ +UPDATE Groups SET Instance = 1 WHERE Domain = 'RT::System-Role' AND Instance = 0; diff --git a/rt/etc/upgrade/4.1.4/schema.SQLite b/rt/etc/upgrade/4.1.4/schema.SQLite new file mode 100644 index 0000000..e530ede --- /dev/null +++ b/rt/etc/upgrade/4.1.4/schema.SQLite @@ -0,0 +1 @@ +UPDATE Groups SET Instance = 1 WHERE Domain = 'RT::System-Role' AND Instance = 0; diff --git a/rt/etc/upgrade/4.1.4/schema.mysql b/rt/etc/upgrade/4.1.4/schema.mysql new file mode 100644 index 0000000..e530ede --- /dev/null +++ b/rt/etc/upgrade/4.1.4/schema.mysql @@ -0,0 +1 @@ +UPDATE Groups SET Instance = 1 WHERE Domain = 'RT::System-Role' AND Instance = 0; diff --git a/rt/etc/upgrade/4.1.5/content b/rt/etc/upgrade/4.1.5/content new file mode 100644 index 0000000..0ed1dda --- /dev/null +++ b/rt/etc/upgrade/4.1.5/content @@ -0,0 +1,34 @@ +use strict; +use warnings; + +our @Initial = ( + # upgrade Template from id to name + sub { + require RT::Scrips; + my $scrips = RT::Scrips->new( RT->SystemUser ); + $scrips->UnLimit; + while ( my $scrip = $scrips->Next ) { + my $id = $scrip->Template; + if ( $id =~ /\D/ ) { + $RT::Logger->info('Template column for scrip #'. $scrip->id .' already contains characters'); + next; + } + + my $name; + + my $template = RT::Template->new( RT->SystemUser ); + $template->Load( $id ); + unless ( $template->id ) { + $RT::Logger->error("Scrip #". $scrip->id ." has template set to #$id, but it's not in DB, setting it 'Blank'"); + $name = 'Blank'; + } else { + $name = $template->Name; + } + + my ($status, $msg) = $scrip->_Set( Field => 'Template', Value => $name ); + unless ( $status ) { + $RT::Logger->error("Couldn't set template: $msg"); + } + } + }, +); diff --git a/rt/etc/upgrade/4.1.5/schema.Oracle b/rt/etc/upgrade/4.1.5/schema.Oracle new file mode 100644 index 0000000..648784d --- /dev/null +++ b/rt/etc/upgrade/4.1.5/schema.Oracle @@ -0,0 +1,6 @@ +# Template column +ALTER TABLE Scrips RENAME COLUMN Template TO TemplateOld; +ALTER TABLE Scrips ADD Template VARCHAR2(200); +UPDATE Scrips SET Template = CAST(TemplateOld AS varchar2(200)); +ALTER TABLE Scrips MODIFY Template VARCHAR2(200) NOT NULL; +ALTER TABLE Scrips DROP COLUMN TemplateOld; diff --git a/rt/etc/upgrade/4.1.5/schema.Pg b/rt/etc/upgrade/4.1.5/schema.Pg new file mode 100644 index 0000000..3a12d4d --- /dev/null +++ b/rt/etc/upgrade/4.1.5/schema.Pg @@ -0,0 +1,2 @@ +# Template colum +ALTER TABLE Scrips ALTER COLUMN Template TYPE varchar(200); diff --git a/rt/etc/upgrade/4.1.5/schema.mysql b/rt/etc/upgrade/4.1.5/schema.mysql new file mode 100644 index 0000000..d35d730 --- /dev/null +++ b/rt/etc/upgrade/4.1.5/schema.mysql @@ -0,0 +1,2 @@ +# Template column +ALTER TABLE Scrips CHANGE Template Template varchar(200) NOT NULL; diff --git a/rt/etc/upgrade/4.1.6/content b/rt/etc/upgrade/4.1.6/content new file mode 100644 index 0000000..d27014c --- /dev/null +++ b/rt/etc/upgrade/4.1.6/content @@ -0,0 +1,43 @@ +use strict; +use warnings; + +our @Initial = (sub { + my $users = RT::Users->new(RT->SystemUser); + $users->FindAllRows; + + my $attributes = $users->Join( + ALIAS1 => "main", + FIELD1 => "id", + TABLE2 => RT::Attributes->Table, + FIELD2 => "ObjectId", + ); + $users->Limit( + ALIAS => $attributes, + FIELD => "ObjectType", + VALUE => "RT::User", + ); + $users->Limit( + ALIAS => $attributes, + FIELD => "Name", + VALUE => RT::User::_PrefName( RT->System ), + ); + + # Iterate all users (including disabled), with config preferences set. + # Avoids running a query for every user in the system by only selecting + # those known to have preferences. + while (my $user = $users->Next) { + RT->Logger->debug(sprintf "User #%d has config preferences", $user->id); + + my $config = $user->Preferences( RT->System ) + or next; + next unless exists $config->{DeferTransactionLoading}; + + $config->{ShowHistory} = delete $config->{DeferTransactionLoading} + ? "click" : "delay"; + + $user->SetPreferences( RT->System, $config ); + RT->Logger->debug(sprintf "Updated config Preferences for user %s (#%d)", $user->Name, $user->id); + } +}); + +1; diff --git a/rt/etc/upgrade/4.1.7/schema.Oracle b/rt/etc/upgrade/4.1.7/schema.Oracle new file mode 100644 index 0000000..b53dceb --- /dev/null +++ b/rt/etc/upgrade/4.1.7/schema.Oracle @@ -0,0 +1,5 @@ +UPDATE Transactions +SET TimeTaken + = COALESCE(TO_NUMBER(REGEXP_SUBSTR(NewValue, '^-?\d+$')), 0) + - COALESCE(TO_NUMBER(OldValue),0) +WHERE ObjectType = 'RT::Ticket' AND Type = 'Set' AND Field = 'TimeWorked';
\ No newline at end of file diff --git a/rt/etc/upgrade/4.1.7/schema.Pg b/rt/etc/upgrade/4.1.7/schema.Pg new file mode 100644 index 0000000..2949e32 --- /dev/null +++ b/rt/etc/upgrade/4.1.7/schema.Pg @@ -0,0 +1,5 @@ +UPDATE Transactions +SET TimeTaken + = (CASE WHEN NewValue~E'^-?\\d+$' THEN NewValue::integer ELSE 0 END) + - COALESCE(OldValue::integer, 0) +WHERE ObjectType = 'RT::Ticket' AND Type = 'Set' AND Field = 'TimeWorked';
\ No newline at end of file diff --git a/rt/etc/upgrade/4.1.7/schema.SQLite b/rt/etc/upgrade/4.1.7/schema.SQLite new file mode 100644 index 0000000..8d6680d --- /dev/null +++ b/rt/etc/upgrade/4.1.7/schema.SQLite @@ -0,0 +1,2 @@ +UPDATE Transactions SET TimeTaken = NewValue - OldValue +WHERE ObjectType = 'RT::Ticket' AND Type = 'Set' AND Field = 'TimeWorked';
\ No newline at end of file diff --git a/rt/etc/upgrade/4.1.7/schema.mysql b/rt/etc/upgrade/4.1.7/schema.mysql new file mode 100644 index 0000000..95013f3 --- /dev/null +++ b/rt/etc/upgrade/4.1.7/schema.mysql @@ -0,0 +1,5 @@ +UPDATE Transactions +SET TimeTaken + = COALESCE(NewValue,0) + - COALESCE(OldValue,0) +WHERE ObjectType = 'RT::Ticket' AND Type = 'Set' AND Field = 'TimeWorked';
\ No newline at end of file diff --git a/rt/etc/upgrade/4.1.8/schema.Oracle b/rt/etc/upgrade/4.1.8/schema.Oracle new file mode 100644 index 0000000..07cd148 --- /dev/null +++ b/rt/etc/upgrade/4.1.8/schema.Oracle @@ -0,0 +1,2 @@ +ALTER TABLE Tickets ADD IsMerged NUMBER(11,0) DEFAULT NULL NULL; +UPDATE Tickets SET IsMerged = 1 WHERE id != EffectiveId; diff --git a/rt/etc/upgrade/4.1.8/schema.Pg b/rt/etc/upgrade/4.1.8/schema.Pg new file mode 100644 index 0000000..a35287e --- /dev/null +++ b/rt/etc/upgrade/4.1.8/schema.Pg @@ -0,0 +1,2 @@ +ALTER TABLE Tickets ADD COLUMN IsMerged smallint NULL DEFAULT NULL; +UPDATE Tickets SET IsMerged = 1 WHERE id != EffectiveId; diff --git a/rt/etc/upgrade/4.1.8/schema.SQLite b/rt/etc/upgrade/4.1.8/schema.SQLite new file mode 100644 index 0000000..4e28e3b --- /dev/null +++ b/rt/etc/upgrade/4.1.8/schema.SQLite @@ -0,0 +1,3 @@ +ALTER TABLE Tickets ADD COLUMN IsMerged int2 NULL DEFAULT NULL; +UPDATE Tickets SET IsMerged = 1 WHERE id != EffectiveId; + diff --git a/rt/etc/upgrade/4.1.8/schema.mysql b/rt/etc/upgrade/4.1.8/schema.mysql new file mode 100644 index 0000000..8977c10 --- /dev/null +++ b/rt/etc/upgrade/4.1.8/schema.mysql @@ -0,0 +1,2 @@ +ALTER TABLE Tickets ADD COLUMN IsMerged int2 NULL DEFAULT NULL; +UPDATE Tickets SET IsMerged = 1 WHERE id != EffectiveId; diff --git a/rt/etc/upgrade/4.1.9/content b/rt/etc/upgrade/4.1.9/content new file mode 100644 index 0000000..3c68b69 --- /dev/null +++ b/rt/etc/upgrade/4.1.9/content @@ -0,0 +1,190 @@ +use strict; +use warnings; + +# New HTML templates + +our @Templates = ( + { Queue => '0', + Name => 'Autoreply in HTML', # loc + Description => 'HTML Autoresponse template', # loc + Content => q[Subject: AutoReply: {$Ticket->Subject} +Content-Type: text/html + +<p>Greetings,</p> + +<p>This message has been automatically generated in response to the +creation of a trouble ticket regarding <b>{$Ticket->Subject()}</b>, +a summary of which appears below.</p> + +<p>There is no need to reply to this message right now. Your ticket has been +assigned an ID of <b>{$Ticket->SubjectTag}</b>.</p> + +<p>Please include the string <b>{$Ticket->SubjectTag}</b> +in the subject line of all future correspondence about this issue. To do so, +you may reply to this message.</p> + +<p>Thank you,<br/> +{$Ticket->QueueObj->CorrespondAddress()}</p> + +<hr/> +{$Transaction->Content(Type => 'text/html')} +], + }, + { Queue => '0', + Name => 'Transaction in HTML', # loc + Description => 'HTML transaction template', # loc + Content => 'RT-Attach-Message: yes +Content-Type: text/html + +<b>{$Transaction->CreatedAsString}: Request <a href="{RT->Config->Get("WebURL")}Ticket/Display.html?id={$Ticket->id}">{$Ticket->id}</a> was acted upon by {$Transaction->CreatorObj->Name}.</b> +<br> +<table border="0"> +<tr><td align="right"><b>Transaction:</b></td><td>{$Transaction->Description}</td></tr> +<tr><td align="right"><b>Queue:</b></td><td>{$Ticket->QueueObj->Name}</td></tr> +<tr><td align="right"><b>Subject:</b></td><td>{$Transaction->Subject || $Ticket->Subject || "(No subject given)"} </td></tr> +<tr><td align="right"><b>Owner:</b></td><td>{$Ticket->OwnerObj->Name}</td></tr> +<tr><td align="right"><b>Requestors:</b></td><td>{$Ticket->RequestorAddresses}</td></tr> +<tr><td align="right"><b>Status:</b></td><td>{$Ticket->Status}</td></tr> +<tr><td align="right"><b>Ticket URL:</b></td><td><a href="{RT->Config->Get("WebURL")}Ticket/Display.html?id={$Ticket->id}">{RT->Config->Get("WebURL")}Ticket/Display.html?id={$Ticket->id}</a></td></tr> +</table> +<br/> +<br/> +{$Transaction->Content( Type => "text/html")} +' + }, + { Queue => '0', + Name => 'Admin Correspondence in HTML', # loc + Description => 'HTML admin correspondence template', # loc + Content => 'RT-Attach-Message: yes +Content-Type: text/html + +Ticket URL: <a href="{RT->Config->Get("WebURL")}Ticket/Display.html?id={$Ticket->id}">{RT->Config->Get("WebURL")}Ticket/Display.html?id={$Ticket->id}</a> +<br /> +<br /> +{$Transaction->Content(Type => "text/html");} +' + }, + { Queue => '0', + Name => 'Correspondence in HTML', # loc + Description => 'HTML correspondence template', # loc + Content => 'RT-Attach-Message: yes +Content-Type: text/html + +{$Transaction->Content( Type => "text/html")} +' + }, + { Queue => '0', + Name => 'Admin Comment in HTML', # loc + Description => 'HTML admin comment template', # loc + Content => +'Subject: [Comment] {my $s=($Transaction->Subject||$Ticket->Subject); $s =~ s/\\[Comment\\]\\s*//g; $s =~ s/^Re:\\s*//i; $s;} +RT-Attach-Message: yes +Content-Type: text/html + +<p>This is a comment about <a href="{RT->Config->Get("WebURL")}Ticket/Display.html?id={$Ticket->id}">ticket {$Ticket->id}</a>. It is not sent to the Requestor(s):</p> + +{$Transaction->Content(Type => "text/html")} +' + }, + { Queue => '0', + Name => 'Status Change in HTML', # loc + Description => 'HTML Ticket status changed', # loc + Content => 'Subject: Status Changed to: {$Transaction->NewValue} +Content-Type: text/html + +<a href="{RT->Config->Get("WebURL")}Ticket/Display.html?id={$Ticket->id}">{RT->Config->Get("WebURL")}Ticket/Display.html?id={$Ticket->id}</a> +<br/> +<br/> +{$Transaction->Content(Type => "text/html")} +' + }, + { Queue => '0', + Name => 'Resolved in HTML', # loc + Description => 'HTML Ticket Resolved', # loc + Content => 'Subject: Resolved: {$Ticket->Subject} +Content-Type: text/html + +<p>According to our records, your request has been resolved. If you have any further questions or concerns, please respond to this message.</p> +' + }, + { Queue => '___Approvals', + Name => "New Pending Approval in HTML", # loc + Description => "Notify Owners and AdminCcs of new items pending their approval", # loc + Content => 'Subject: New Pending Approval: {$Ticket->Subject} +Content-Type: text/html + +<p>Greetings,</p> + +<p>There is a new item pending your approval: <b>{$Ticket->Subject()}</b>, +a summary of which appears below.</p> + +<p>Please <a href="{RT->Config->Get(\'WebURL\')}Approvals/Display.html?id={$Ticket->id}">approve +or reject this ticket</a>, or visit the <a href="{RT->Config->Get(\'WebURL\')}Approvals/">approvals +overview</a> to batch-process all your pending approvals.</p> + +<hr /> +{$Transaction->Content()} +' + }, + { Queue => '___Approvals', + Name => "Approval Passed in HTML", # loc + Description => + "Notify Requestor of their ticket has been approved by some approver", # loc + Content => 'Subject: Ticket Approved: {$Ticket->Subject} +Content-Type: text/html + +<p>Greetings,</p> + +<p>Your ticket has been approved by <b>{ eval { $Approver->Name } }</b>. +Other approvals may be pending.</p> + +<p>Approver\'s notes:</p> +<blockquote>{ $Notes }</blockquote> +' + }, + { Queue => '___Approvals', + Name => "All Approvals Passed in HTML", # loc + Description => + "Notify Requestor of their ticket has been approved by all approvers", # loc + Content => 'Subject: Ticket Approved: {$Ticket->Subject} +Content-Type: text/html + +<p>Greetings,</p> + +<p>Your ticket has been approved by <b>{ eval { $Approver->Name } }</b>. +Its Owner may now start to act on it.</p> + +<p>Approver\'s notes:</p> +<blockquote>{ $Notes }</blockquote> +' + }, + { Queue => '___Approvals', + Name => "Approval Rejected in HTML", # loc + Description => + "Notify Owner of their rejected ticket", # loc + Content => 'Subject: Ticket Rejected: {$Ticket->Subject} +Content-Type: text/html + +<p>Greetings,</p> + +<p>Your ticket has been rejected by <b>{ eval { $Approver->Name } }</b>.</p> + +<p>Approver\'s notes:</p> +<blockquote>{ $Notes }</blockquote> +' + }, + { Queue => '___Approvals', + Name => "Approval Ready for Owner in HTML", # loc + Description => + "Notify Owner of their ticket has been approved and is ready to be acted on", # loc + Content => 'Subject: Ticket Approved: {$Ticket->Subject} +Content-Type: text/html + +<p>Greetings,</p> + +<p>The ticket has been approved, you may now start to act on it.</p> + +' + }, +); + diff --git a/rt/etc/upgrade/4.2.1/content b/rt/etc/upgrade/4.2.1/content new file mode 100644 index 0000000..64eea9a --- /dev/null +++ b/rt/etc/upgrade/4.2.1/content @@ -0,0 +1,14 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + my $attr = RT->System->FirstAttribute('BrandedSubjectTag'); + return 1 unless $attr; + my ( $status, $msg ) = $attr->Delete; + unless ( $status ) { + RT->Logger->error("Couldn't delete System BrandedSubjectTag: $msg"); + } + return 1; + }, +); diff --git a/rt/etc/upgrade/4.2.10/content b/rt/etc/upgrade/4.2.10/content new file mode 100644 index 0000000..d9aadcc --- /dev/null +++ b/rt/etc/upgrade/4.2.10/content @@ -0,0 +1,19 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + my $attrs = RT::Attributes->new(RT->SystemUser); + $attrs->Limit( FIELD => 'Name', VALUE => 'SavedSearch' ); + while ( my $attr = $attrs->Next ) { + my $content = $attr->Content; + if ( $content->{ChartStyle} && $content->{ChartStyle} =~ /^(?:pie|bar)$/ ) { + $content->{ChartStyle} .= '+table+sql'; + my ($ret, $msg) = $attr->SetContent($content); + unless ( $ret ) { + RT->Logger->error("Failed to update ChartStyle for SavedSearch #" . $attr->id . ": $msg"); + } + } + } + }, +); diff --git a/rt/etc/upgrade/4.2.11/content b/rt/etc/upgrade/4.2.11/content new file mode 100644 index 0000000..5e43db7 --- /dev/null +++ b/rt/etc/upgrade/4.2.11/content @@ -0,0 +1,60 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + # We do the delete in pure SQL because Attribute collections + # otherwise attempt to hash everything in memory. As this may + # be a large list, do it directly. + RT->DatabaseHandle->dbh->do(<<EOSQL); + DELETE FROM Attributes + WHERE Name = 'DeferredRecipients' + AND Content IS NULL +EOSQL + }, + sub { + # Remove globally-granted role rights which couldn't also apply + # to some other object. That is, globally granting that + # AdminCcs have SuperUser makes no sense. + + # Find rights which apply globally + no warnings 'once'; + my @rights = sort map {$_->{Name}} values %{$RT::ACE::RIGHTS{'RT::System'}}; + + # Those are not allowed to be granted on global role groups + my $invalid = RT::ACL->new( RT->SystemUser ); + $invalid->LimitToObject( 'RT::System' ); + $invalid->LimitToPrincipal( Id => RT::System->RoleGroup($_)->PrincipalId ) + for RT::System->Roles; + $invalid->Limit( FIELD => 'RightName', OPERATOR => 'IN', VALUE => \@rights ); + + return unless $invalid->Count; + + # Remove them, warning in the process + $RT::Logger->warning("There are invalid global role rights; removing:"); + while (my $right = $invalid->Next) { + $RT::Logger->warning(" ".$right->RightName." granted globally to ".$right->PrincipalObj->Object->Name); + my ($ok, $msg) = $right->Delete; + $RT::Logger->error("Failed to remove right ".$right->id.": $msg") unless $ok; + } + }, + sub { + my $txns = RT::Transactions->new(RT->SystemUser); + $txns->Limit( FIELD => 'Type', VALUE => 'Forward Transaction' ); + $txns->Limit( FIELD => 'Type', VALUE => 'Forward Ticket' ); + while ( my $txn = $txns->Next ) { + my $att = $txn->Attachments->First; + next unless $att; + + # we only need to process ascii-only strings + unless ( $att->Subject =~ /[^\x00-\x7F]/ ) { + $att->__Set( Field => 'Subject', Value => Encode::decode("UTF-8", RT::I18N::DecodeMIMEWordsToUTF8($att->Subject, 'Subject')) ); + } + for my $field ( qw/Subject From To Cc Bcc/ ) { + next if !$att->GetHeader($field) || $att->GetHeader($field) =~ /[^\x00-\x7F]/; + # Subject here is not a typo, because we don't really want to parse email addresses here + $att->SetHeader( $field, Encode::decode("UTF-8", RT::I18N::DecodeMIMEWordsToUTF8($att->GetHeader($field), 'Subject')) ); + } + } + }, +); diff --git a/rt/etc/upgrade/4.2.2/content b/rt/etc/upgrade/4.2.2/content new file mode 100644 index 0000000..762289a --- /dev/null +++ b/rt/etc/upgrade/4.2.2/content @@ -0,0 +1,59 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + use RT::CustomFields; + my $cfs = RT::CustomFields->new(RT->SystemUser); + $cfs->{'find_disabled_rows'} = 1; + $cfs->Limit( FIELD => 'LookupType', VALUE => 'RT::FM::Class-RT::FM::Article' ); + while ( my $cf = $cfs->Next ) { + my ($ret, $msg) = $cf->__Set( Field => 'LookupType', Value => 'RT::Class-RT::Article' ); + RT->Logger->warning("Update Custom Field LookupType for CF.".$cf->Id." $msg"); + } + return 1; + }, + + sub { + use RT::ObjectCustomFieldValues; + my $ocfvs = RT::ObjectCustomFieldValues->new(RT->System); + $ocfvs->{'find_expired_rows'} = 1; + $ocfvs->Limit( FIELD => 'ObjectType', VALUE => 'RT::FM::Article' ); + while ( my $ocfv = $ocfvs->Next ) { + my ($ret, $msg) = $ocfv->__Set( Field => 'ObjectType', Value => 'RT::Article' ); + RT->Logger->warning("Updated CF ".$ocfv->__Value('CustomField')." Value for Article ".$ocfv->__Value('ObjectId')); + } + return 1; + }, + + sub { + require RT::Scrips; + my $scrips = RT::Scrips->new( RT->SystemUser ); + $scrips->{'find_disabled_rows'} = 1; + $scrips->Limit( FIELD => 'Disabled', VALUE => 1 );; + while ( my $scrip = $scrips->Next ) { + my $id = $scrip->Template; + if ( $id =~ /\D/ ) { + $RT::Logger->info('Template column for scrip #'. $scrip->id .' already contains characters'); + next; + } + + my $name; + + my $template = RT::Template->new( RT->SystemUser ); + $template->Load( $id ); + unless ( $template->id ) { + $RT::Logger->error("Scrip #". $scrip->id ." has template set to #$id, but it's not in DB, setting it 'Blank'"); + $name = 'Blank'; + } else { + $name = $template->Name; + } + + my ($status, $msg) = $scrip->_Set( Field => 'Template', Value => $name ); + unless ( $status ) { + $RT::Logger->error("Couldn't set template: $msg"); + } + } + }, +); + diff --git a/rt/etc/upgrade/4.2.2/schema.mysql b/rt/etc/upgrade/4.2.2/schema.mysql new file mode 100644 index 0000000..de28cc9 --- /dev/null +++ b/rt/etc/upgrade/4.2.2/schema.mysql @@ -0,0 +1,5 @@ +ALTER TABLE Users MODIFY EmailAddress varchar(120) CHARACTER SET utf8; +ALTER TABLE Queues + MODIFY Lifecycle varchar(32) CHARACTER SET utf8, + MODIFY CorrespondAddress varchar(120) CHARACTER SET utf8, + MODIFY CommentAddress varchar(120) CHARACTER SET utf8; diff --git a/rt/etc/upgrade/4.2.4/content b/rt/etc/upgrade/4.2.4/content new file mode 100644 index 0000000..c56e369 --- /dev/null +++ b/rt/etc/upgrade/4.2.4/content @@ -0,0 +1,47 @@ +use strict; +use warnings; + +our @ScripActions = ( + { Name => 'Open Inactive Tickets', # loc + Description => 'Open inactive tickets', # loc + ExecModule => 'AutoOpenInactive' }, +); + +# Ignore the above if there is already an AutoOpenInactive in the +# database -- i.e. originally a 4.2 install, or someone added one +# themselves. +our @Initial; +push @Initial, sub { + my $exist = RT::ScripAction->new( RT->SystemUser ); + $exist->LoadByCols( ExecModule => 'AutoOpenInactive' ); + @ScripActions = () if $exist->Id; +}; + +push @Initial, sub { + my $queue = RT::Queue->new( RT->SystemUser ); + my ($ok, $msg) = $queue->Load('___Approvals'); + unless ($ok) { + RT->Logger->warning("Unable to load ___Approvals: $msg"); + return; + } + unless ($queue->Disabled == 2) { + RT->Logger->warning("Going to force ___Approvals queue to be Disabled = 2"); + ($ok, $msg) = $queue->SetDisabled( 2 ); + unless ($ok) { + RT->Logger->error("Unable to set ___Approvals.Disabled = 2: $msg"); + return; + } + } + + unless ($queue->Lifecycle eq "approvals") { + RT->Logger->warning("Going to force ___Approvals queue to the approvals lifecycle"); + ($ok, $msg) = $queue->SetLifecycle( "approvals" ); + unless ($ok) { + RT->Logger->error("Unable to set ___Approvals lifecycle: $msg"); + return; + } + } + + return 1; + +}; diff --git a/rt/etc/upgrade/4.2.6/content b/rt/etc/upgrade/4.2.6/content new file mode 100644 index 0000000..e17c5ea --- /dev/null +++ b/rt/etc/upgrade/4.2.6/content @@ -0,0 +1,9 @@ +use strict; +use warnings; + +our @ScripActions = ( + { Name => 'Notify Owner or AdminCcs', # loc + Description => 'Sends mail to the Owner if set, otherwise administrative Ccs', # loc + ExecModule => 'NotifyOwnerOrAdminCc', + }, +); diff --git a/rt/etc/upgrade/4.2.6/schema.mysql b/rt/etc/upgrade/4.2.6/schema.mysql new file mode 100644 index 0000000..71f8f64 --- /dev/null +++ b/rt/etc/upgrade/4.2.6/schema.mysql @@ -0,0 +1,4 @@ +ALTER TABLE Links + DEFAULT CHARACTER SET utf8, + MODIFY Base varchar(240) CHARACTER SET utf8 NULL, + MODIFY Target varchar(240) CHARACTER SET utf8 NULL; diff --git a/rt/etc/upgrade/4.2.7/content b/rt/etc/upgrade/4.2.7/content new file mode 100644 index 0000000..e828cc7 --- /dev/null +++ b/rt/etc/upgrade/4.2.7/content @@ -0,0 +1,15 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + # We do the delete in pure SQL because Attribute collections + # otherwise attempt to hash everything in memory. As this may + # be a large list, do it directly. + RT->DatabaseHandle->dbh->do(<<EOSQL); + DELETE FROM Attributes + WHERE (Name = 'LinkValueTo' OR Name = 'IncludeContentForValue') + AND (LENGTH(Content) = 0 OR Content IS NULL) +EOSQL + }, +); diff --git a/rt/etc/upgrade/4.2.8/content b/rt/etc/upgrade/4.2.8/content new file mode 100644 index 0000000..64b61de --- /dev/null +++ b/rt/etc/upgrade/4.2.8/content @@ -0,0 +1,16 @@ +use strict; +use warnings; + +our @Initial = ( + sub { + # This upgrade step is identical to the 4.2.7 upgrade, but only + # runs on Oracle because 4.2.7 was originally released with + # flawed SQL which did not run on Oracle. + return unless RT->Config->Get('DatabaseType') eq 'Oracle'; + RT->DatabaseHandle->dbh->do(<<EOSQL); + DELETE FROM Attributes + WHERE (Name = 'LinkValueTo' OR Name = 'IncludeContentForValue') + AND (LENGTH(Content) = 0 OR Content IS NULL) +EOSQL + }, +); diff --git a/rt/etc/upgrade/generate-rtaddressregexp.in b/rt/etc/upgrade/generate-rtaddressregexp.in index a6262df..3cdd5a6 100644 --- a/rt/etc/upgrade/generate-rtaddressregexp.in +++ b/rt/etc/upgrade/generate-rtaddressregexp.in @@ -46,18 +46,15 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} +use 5.10.1; use strict; use warnings; use lib "@LOCAL_LIB_PATH@"; use lib "@RT_LIB_PATH@"; -use RT; -RT::LoadConfig(); -RT->Config->Set('LogToScreen' => 'debug'); -RT::Init(); - -$| = 1; +use RT::Interface::CLI qw(Init); +Init(); if (my $re = RT->Config->Get('RTAddressRegexp')) { print "No need to use this script, you already have RTAddressRegexp set to $re\n"; @@ -86,7 +83,7 @@ for my $domain (sort keys %merged) { } } if (@addresses > 1) { - push @domains, "(?:".join("|", @addresses).")\Q\@".$domain."\E"; + push @domains, "(?:".join("|", @addresses).")\Q\@$domain\E"; } else { push @domains, "$addresses[0]\Q\@$domain\E"; } diff --git a/rt/etc/upgrade/sanity-check-stylesheets.pl b/rt/etc/upgrade/sanity-check-stylesheets.in index cdc5588..510abf7 100644 --- a/rt/etc/upgrade/sanity-check-stylesheets.pl +++ b/rt/etc/upgrade/sanity-check-stylesheets.in @@ -1,3 +1,4 @@ +#!@PERL@ # BEGIN BPS TAGGED BLOCK {{{ # # COPYRIGHT: @@ -45,34 +46,34 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} +use 5.10.1; use strict; use warnings; -use RT; -RT::LoadConfig(); -RT->Config->Set('LogToScreen' => 'debug'); -RT::Init(); +use lib "@LOCAL_LIB_PATH@"; +use lib "@RT_LIB_PATH@"; -$| = 1; +use RT::Interface::CLI qw(Init); +Init(); use RT::Users; my $users = RT::Users->new( $RT::SystemUser ); $users->UnLimit(); -my @comp_roots = RT::Interface::Web->ComponentRoots; -my %comp_root_check_cache; +my @static_roots = RT::Interface::Web->StaticRoots; +my %static_root_check_cache; sub stylesheet_exists { my $stylesheet = shift; - return $comp_root_check_cache{$stylesheet} - if exists $comp_root_check_cache{$stylesheet}; + return $static_root_check_cache{$stylesheet} + if exists $static_root_check_cache{$stylesheet}; - for my $comp_root (@comp_roots) { - return ++$comp_root_check_cache{$stylesheet} - if -d "$comp_root/NoAuth/css/$stylesheet"; + for my $static_root (@static_roots) { + return ++$static_root_check_cache{$stylesheet} + if -d "$static_root/css/$stylesheet"; } - return $comp_root_check_cache{$stylesheet} = 0; + return $static_root_check_cache{$stylesheet} = 0; } my $system_stylesheet = RT->Config->Get('WebDefaultStylesheet'); diff --git a/rt/etc/upgrade/shrink_cgm_table.pl b/rt/etc/upgrade/shrink-cgm-table.in index 85aa307..8654271 100644 --- a/rt/etc/upgrade/shrink_cgm_table.pl +++ b/rt/etc/upgrade/shrink-cgm-table.in @@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!@PERL@ # BEGIN BPS TAGGED BLOCK {{{ # # COPYRIGHT: @@ -46,14 +46,15 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} -use 5.8.3; +use 5.10.1; use strict; use warnings; -use RT; -RT::LoadConfig(); -RT->Config->Set('LogToScreen' => 'debug'); -RT::Init(); +use lib "@LOCAL_LIB_PATH@"; +use lib "@RT_LIB_PATH@"; + +use RT::Interface::CLI qw(Init); +Init(); use RT::CachedGroupMembers; my $cgms = RT::CachedGroupMembers->new( RT->SystemUser ); @@ -89,7 +90,6 @@ $cgms->Limit( ENTRYAGGREGATOR => 'AND', ); -$| = 1; my $total = $cgms->Count; my $i = 0; @@ -100,7 +100,7 @@ while ( my $rec = FetchNext( $cgms ) ) { $RT::Handle->BeginTransaction; my ($status) = $rec->Delete; unless ($status) { - print STDERR "Couldn't delete CGM #". $rec->id; + $RT::Logger->error( "Couldn't delete CGM #". $rec->id ); exit 1; } $RT::Handle->Commit; diff --git a/rt/etc/upgrade/shrink_transactions_table.pl b/rt/etc/upgrade/shrink-transactions-table.in index 0d0287f..8eea6ed 100644 --- a/rt/etc/upgrade/shrink_transactions_table.pl +++ b/rt/etc/upgrade/shrink-transactions-table.in @@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!@PERL@ # BEGIN BPS TAGGED BLOCK {{{ # # COPYRIGHT: @@ -46,14 +46,15 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} -use 5.8.3; +use 5.10.1; use strict; use warnings; -use RT; -RT::LoadConfig(); -RT->Config->Set('LogToScreen' => 'debug'); -RT::Init(); +use lib "@LOCAL_LIB_PATH@"; +use lib "@RT_LIB_PATH@"; + +use RT::Interface::CLI qw(Init); +Init(); use RT::Transactions; my $txns = RT::Transactions->new( RT->SystemUser ); @@ -76,20 +77,21 @@ $txns->Limit( FIELD => 'Domain', OPERATOR => '=', VALUE => 'ACLEquivalence', + CASESENSITIVE => 0, QUOTEVALUE => 1, ENTRYAGGREGATOR => 'AND', ); $txns->Limit( ALIAS => $alias, - FIELD => 'Type', + FIELD => 'Name', OPERATOR => '=', VALUE => 'UserEquiv', QUOTEVALUE => 1, + CASESENSITIVE => 0, ENTRYAGGREGATOR => 'AND', ); -$| = 1; my $total = $txns->Count; my $i = 0; @@ -100,7 +102,7 @@ while ( my $rec = FetchNext( $txns ) ) { $RT::Handle->BeginTransaction; my ($status) = $rec->Delete; unless ($status) { - print STDERR "Couldn't delete TXN #". $rec->id; + $RT::Logger->error( "Couldn't delete TXN #". $rec->id ); exit 1; } $RT::Handle->Commit; diff --git a/rt/etc/upgrade/split-out-cf-categories.in b/rt/etc/upgrade/split-out-cf-categories.in index d7dd117..6faf29c 100644 --- a/rt/etc/upgrade/split-out-cf-categories.in +++ b/rt/etc/upgrade/split-out-cf-categories.in @@ -46,18 +46,15 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} +use 5.10.1; use strict; use warnings; use lib "@LOCAL_LIB_PATH@"; use lib "@RT_LIB_PATH@"; -use RT; -RT::LoadConfig(); -RT->Config->Set('LogToScreen' => 'debug'); -RT::Init(); - -$| = 1; +use RT::Interface::CLI qw(Init); +Init(); $RT::Handle->BeginTransaction(); @@ -168,4 +165,4 @@ while (my $cf = $CFs->Next ) { } $RT::Handle->Commit; -print "No custom fields with categories found\n" unless $seen;
\ No newline at end of file +print "No custom fields with categories found\n" unless $seen; diff --git a/rt/etc/upgrade/switch-templates-to.in b/rt/etc/upgrade/switch-templates-to.in new file mode 100644 index 0000000..384d8f7 --- /dev/null +++ b/rt/etc/upgrade/switch-templates-to.in @@ -0,0 +1,145 @@ +#!@PERL@ +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC +# <sales@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} +use 5.10.1; +use strict; +use warnings; + +use lib "@LOCAL_LIB_PATH@"; +use lib "@RT_LIB_PATH@"; + +use RT::Interface::CLI qw(Init); +Init(); + +my $to = shift || ''; +my $from; + +if ($to =~ /html|text/i) { + $to = $to =~ /html/i ? 'html' : 'text'; + $from = $to eq 'html' ? 'text' : 'html'; +} else { + print "Usage: $0 [html|text]\n"; + warn "Please specify if you'd like to switch to HTML or text templates.\n"; + exit 1; +} + + +my @templates = ( + "Autoreply", + "Transaction", + "Admin Correspondence", + "Correspondence", + "Admin Comment", + "Status Change", + "Resolved", + "New Pending Approval", + "Approval Passed", + "All Approvals Passed", + "Approval Rejected", + "Approval Ready for Owner", +); + +$RT::Handle->BeginTransaction(); + +use RT::Scrips; +my $scrips = RT::Scrips->new( RT->SystemUser ); +$scrips->UnLimit; + +for (@templates) { + $scrips->Limit( + FIELD => 'Template', + VALUE => ($to eq 'html' ? $_ : "$_ in HTML"), + ENTRYAGGREGATOR => 'OR' + ); +} + +my $switched = 0; +while ( my $s = $scrips->Next ) { + my $new = $s->TemplateObj->Name; + + if ($to eq 'html') { + $new .= ' in HTML'; + } else { + $new =~ s/ in HTML$//; + } + + print $s->id, ": ", $s->Description, "\n"; + print " ", $s->TemplateObj->Name, " -> $new\n\n"; + + my ($ok, $msg) = $s->SetTemplate($new); + + if ($ok) { + $switched++; + } else { + warn " Couldn't switch templates: $msg\n"; + } +} + +$RT::Handle->Commit; + +if ($switched) { + print <<" EOT"; +Switched $switched scrips to $to templates. You should now manually port any +customizations from the old templates to the new templates. + EOT + exit 1 if $switched != $scrips->Count; +} +elsif ($scrips->Count) { + print <<" EOT"; +@{[$scrips->Count]} scrips using $from templates were found, but none were +successfully switched to $to. See the errors above. + EOT + exit 1; +} +else { + print <<" EOT"; +No scrips were found using the $from templates, so none were switched to +$to templates. + EOT +} + diff --git a/rt/etc/upgrade/time-worked-history.in b/rt/etc/upgrade/time-worked-history.in new file mode 100644 index 0000000..fe216fa --- /dev/null +++ b/rt/etc/upgrade/time-worked-history.in @@ -0,0 +1,111 @@ +#!@PERL@ +# BEGIN BPS TAGGED BLOCK {{{ +# +# COPYRIGHT: +# +# This software is Copyright (c) 1996-2015 Best Practical Solutions, LLC +# <sales@bestpractical.com> +# +# (Except where explicitly superseded by other copyright notices) +# +# +# LICENSE: +# +# This work is made available to you under the terms of Version 2 of +# the GNU General Public License. A copy of that license should have +# been provided with this software, but in any event can be snarfed +# from www.gnu.org. +# +# This work is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301 or visit their web page on the internet at +# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. +# +# +# CONTRIBUTION SUBMISSION POLICY: +# +# (The following paragraph is not intended to limit the rights granted +# to you to modify and distribute this software under the terms of +# the GNU General Public License and is only of importance to you if +# you choose to contribute your changes and enhancements to the +# community by submitting them to Best Practical Solutions, LLC.) +# +# By intentionally submitting any modifications, corrections or +# derivatives to this work, or any other work intended for use with +# Request Tracker, to Best Practical Solutions, LLC, you confirm that +# you are the copyright holder for those contributions and you grant +# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, +# royalty-free, perpetual, license to use, copy, create derivative +# works based on those contributions, and sublicense and distribute +# those contributions and any derivatives thereof. +# +# END BPS TAGGED BLOCK }}} +use 5.10.1; +use strict; +use warnings; + +use lib "@LOCAL_LIB_PATH@"; +use lib "@RT_LIB_PATH@"; + +use RT::Interface::CLI qw(Init); +Init(); + +my $dbh = RT->DatabaseHandle->dbh; +my $ids = $dbh->selectcol_arrayref( + "SELECT t1.id FROM Tickets t1, Tickets t2 WHERE t1.id = t2.EffectiveId" + ." AND t2.id != t2.EffectiveId AND t2.EffectiveId = t1.id" +); +foreach my $id ( @$ids ) { + my $t = RT::Ticket->new( RT->SystemUser ); + $t->Load( $id ); + unless ( $t->id ) { + $RT::Logger->error("Couldn't load ticket #$id"); + next; + } + + fix_time_worked_history($t); +} + +sub fix_time_worked_history { + my ($t) = (@_); + + my $history = 0; + my $candidate = undef; + my @delete = (); + my $delete_time = 0; + + my $txns = $t->Transactions; + while ( my $txn = $txns->Next ) { + if ( $txn->Type =~ /^(Create|Correspond|Comment)$/ ) { + $history += $txn->TimeTaken || 0; + } elsif ( $txn->Type eq 'Set' && $txn->Field eq 'TimeWorked' ) { + $history += $txn->NewValue - $txn->OldValue; + $candidate = $txn; + } elsif ( $candidate && ($txn->Field||'') eq 'MergedInto' ) { + if ($candidate->Creator eq $txn->Creator ) { + push @delete, $candidate; + $delete_time += $candidate->NewValue - $candidate->OldValue; + } + + $candidate = undef; + } + } + + if ( $history == $t->TimeWorked ) { + $RT::Logger->info("Ticket #". $t->id . " has TimeWorked matching history. Skipping"); + } elsif ( $history - $delete_time == $t->TimeWorked ) { + $RT::Logger->warn( "Ticket #". $t->id ." has TimeWorked mismatch. Deleting transactions" ); + foreach my $dtxn ( @delete ) { + my ($status, $msg) = $dtxn->Delete; + $RT::Logger->error("Couldn't delete transaction: $msg") unless $status; + } + } else { + $RT::Logger->error( "Ticket #". $t->id ." has TimeWorked mismatch, but we couldn't find correct transactions to delete. Skipping" ); + } +} diff --git a/rt/etc/upgrade/upgrade-articles b/rt/etc/upgrade/upgrade-articles index ec1b5f4..6ff4a2a 100755 --- a/rt/etc/upgrade/upgrade-articles +++ b/rt/etc/upgrade/upgrade-articles @@ -46,21 +46,18 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} +use 5.10.1; use strict; use warnings; use lib "/opt/rt3/local/lib"; use lib "/opt/rt3/lib"; -use RT; -RT::LoadConfig(); -RT->Config->Set('LogToScreen' => 'debug'); -RT::Init(); +use RT::Interface::CLI qw(Init); +Init(); -$| = 1; - -my $db_name = RT->Config->Get('DatabaseName'); -my $db_type = RT->Config->Get('DatabaseType'); + my $db_name = RT->Config->Get('DatabaseName'); + my $db_type = RT->Config->Get('DatabaseType'); my $dbh = $RT::Handle->dbh; diff --git a/rt/etc/upgrade/upgrade-articles.in b/rt/etc/upgrade/upgrade-articles.in index 21cba4b..742fd17 100644 --- a/rt/etc/upgrade/upgrade-articles.in +++ b/rt/etc/upgrade/upgrade-articles.in @@ -46,18 +46,15 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} +use 5.10.1; use strict; use warnings; use lib "@LOCAL_LIB_PATH@"; use lib "@RT_LIB_PATH@"; -use RT; -RT::LoadConfig(); -RT->Config->Set('LogToScreen' => 'debug'); -RT::Init(); - -$| = 1; +use RT::Interface::CLI qw(Init); +Init(); my $db_name = RT->Config->Get('DatabaseName'); my $db_type = RT->Config->Get('DatabaseType'); diff --git a/rt/etc/upgrade/vulnerable-passwords.in b/rt/etc/upgrade/vulnerable-passwords.in index b00625c..1ccf0a1 100755 --- a/rt/etc/upgrade/vulnerable-passwords.in +++ b/rt/etc/upgrade/vulnerable-passwords.in @@ -46,15 +46,14 @@ # those contributions and any derivatives thereof. # # END BPS TAGGED BLOCK }}} +use 5.10.1; use strict; use warnings; use lib "@LOCAL_LIB_PATH@"; use lib "@RT_LIB_PATH@"; -use RT; -RT::LoadConfig; -RT::Init; +use RT -init; $| = 1; |