[Rt-commit] rtir branch, 3.4/countermeasures, updated. 3.3.0-96-g39c6332
Shawn Moore
shawn at bestpractical.com
Fri May 20 14:13:42 EDT 2016
The branch, 3.4/countermeasures has been updated
via 39c6332cff290d0b4b6f46deb5aff18e767cb863 (commit)
via 73e6e5d90dc121adc81dbb9bd0b2b23b89944508 (commit)
from 6fb2227dc527e51f461acab03d02ff4d3a809988 (commit)
Summary of changes:
etc/upgrade/3.3.0/content | 195 -------------------------------
etc/upgrade/{3.3.4 => 3.3.1}/content | 0
etc/upgrade/3.3.2/content | 217 ++++++++++++++++++++++++++++++-----
etc/upgrade/3.3.3/content | 51 ++++----
etc/upgrade/3.3.4/content | 55 ++++-----
5 files changed, 241 insertions(+), 277 deletions(-)
copy etc/upgrade/{3.3.4 => 3.3.1}/content (100%)
- Log -----------------------------------------------------------------
commit 73e6e5d90dc121adc81dbb9bd0b2b23b89944508
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Fri May 20 18:05:27 2016 +0000
Break up constituency and countermeasures upgrades
There's no reason these need to be intertwined
diff --git a/etc/upgrade/3.3.0/content b/etc/upgrade/3.3.0/content
index 9d8321d..c78291a 100644
--- a/etc/upgrade/3.3.0/content
+++ b/etc/upgrade/3.3.0/content
@@ -1,55 +1,8 @@
use strict;
use warnings;
-our @CustomFields = (
- {
- Name => 'RTIR Constituency',
- Type => 'SelectSingle',
- Disabled => 0,
- RenderType => 'Dropdown',
- LookupType => 'RT::Queue',
- Description => 'Associates RTIR queues with constituencies',
- Values => [],
- },
- {
-
- Name => 'RTIR default WHOIS server',
- Type => 'FreeformSingle',
- Disabled => 0,
- LookupType => 'RT::Queue',
- Description => 'If set, defines the default WHOIS server for an RTIR Queue',
- ApplyTo => [ 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ],
- },
-
-);
-
-our @ScripActions = (
- {
- Name => 'RTIR Change Child Constituencies',
- Description => 'Move all tickets related to an incident to a new constituency',
- ExecModule => 'RTIR_ChangeChildConstituencies',
- },
-);
-
-our @Scrips = (
- {
- Description => "Propagate Constituency Changes",
- Queue => 'Incidents',
- ScripCondition => 'On Queue Change',
- ScripAction => 'RTIR Change Child Constituencies',
- Template => 'Blank',
- },
-);
-
our @Final = (
sub {
- # remove old code
- {
- remove_scrip_action( $_ ) for ( 'RTIR_SetConstituency', 'RTIR_SetConstituencyGroup' );
- remove_scrip_condition( $_ )
- for ( 'RTIR_RequireConstituencyChange', 'RTIR_RequireConstituencyGroupChange' );
- }
-
# fix lifecycle from blocks to countermeasures
{
my $queues = RT::Queues->new(RT->SystemUser);
@@ -78,154 +31,6 @@ our @Final = (
$queue->SetName($new);
}
}
-
- # update values of rtir constituency
- my @constituencies;
- {
- my $cf = RT::CustomField->new( RT->SystemUser );
- $cf->LoadByName( Name => 'Constituency', LookupType => 'RT::Queue-RT::Ticket' );
- if ( $cf->id ) {
- my $values = $cf->Values;
- while ( my $value = $values->Next ) {
- push @constituencies, $value->Name;
- }
- }
- else {
- RT->Logger->error( "Failed to load Constituency cf" );
- }
- my $queue_cf = RT::CustomField->new( RT->SystemUser );
- $queue_cf->LoadByName( Name => 'RTIR Constituency', LookupType => 'RT::Queue' );
- if ( $queue_cf->id ) {
- for my $constituency ( @constituencies ) {
- my ( $ret, $msg ) = $queue_cf->AddValue( Name => $constituency );
- if ( !$ret ) {
- RT->Logger->error( "Failed to add $constituency to 'RTIR Constituency': $msg " );
- }
- }
- }
- else {
- RT->Logger->error( "Failed to load 'RTIR Constituency' cf" );
- }
- }
-
- # create new queues
- my $add_constituency_cmd = File::Spec->catfile( $RT::LocalPluginPath, 'RT-IR', 'bin', 'add_constituency' );
-
- for my $constituency ( @constituencies ) {
- system( $add_constituency_cmd, '--name', $constituency, '--force' );
- }
-
- # move tickets
- for my $queue ( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
- my $tickets = RT::Tickets->new( RT->SystemUser );
- $tickets->FromSQL( qq{Queue = '$queue' AND CF.{Constituency} IS NOT NULL} );
- while ( my $ticket = $tickets->Next ) {
- my $constituency = $ticket->FirstCustomFieldValue( 'Constituency' );
- my $new_queue = RT::Queue->new( RT->SystemUser );
- $new_queue->Load( "$queue - $constituency" );
- if ( $new_queue->id ) {
- my ( $ret, $msg ) = $ticket->_Set( Field => 'Queue', Value => $new_queue->id );
- if ( !$ret ) {
- RT->Logger->error(
- "Failed to move ticket #" . $ticket->id . qq{ to "$queue - $constituency": $msg} );
- }
- }
- else {
- RT->Logger->warning( "Failed to load queue '$queue - $constituency'" );
- }
- }
- }
-
- # update code
- {
- my $attrs = RT::Attributes->new( RT->SystemUser );
- $attrs->Limit( FIELD => 'Name', VALUE => 'RTIR_HomepageSettings' );
- while ( my $attr = $attrs->Next ) {
- my $content = $attr->Content;
- my $sidebar_has_refresh;
- my $sidebar_has_constituency;
- for my $pane ( qw/body sidebar/ ) {
- my @new;
- for my $value ( @{ $content->{ $pane } } ) {
- if ( $value->{ name } eq 'Quicksearch' && $value->{ type } eq 'component' ) {
- push @new, { %$value, name => '/RTIR/Elements/QueueSummary' };
- }
- elsif ($pane eq 'sidebar'
- && $value->{ name } eq 'RefreshHomepage'
- && $value->{ type } eq 'component' )
- {
- # we want to put refresh component to the end of the list
- $sidebar_has_refresh = 1;
- }
- elsif ($pane eq 'sidebar'
- && $value->{ name } eq '/RTIR/Elements/WorkWithConstituency'
- && $value->{ type } eq 'component' )
- {
- $sidebar_has_constituency = 1;
- push @new, $value;
- }
- else {
- push @new, $value;
- }
- }
- $content->{ $pane } = \@new;
- }
- unless ( $sidebar_has_constituency ) {
- unshift @{ $content->{ sidebar } },
- { type => 'component', name => '/RTIR/Elements/WorkWithConstituency' };
- }
-
- if ( $sidebar_has_refresh ) {
- push @{ $content->{ sidebar } }, { type => 'component', name => 'RefreshHomepage' };
- }
-
- my ( $ret, $msg ) = $attr->SetContent( $content );
- unless ( $ret ) {
- RT->Logger->error( "Failed to update content of attribute #" . $attr->id . ": $msg" );
- }
- }
- }
-
- # disable old Constituency cf
- {
- my $cf = RT::CustomField->new( RT->SystemUser );
- $cf->LoadByName( Name => 'Constituency', LookupType => 'RT::Queue-RT::Ticket' );
- if ( $cf->id && !$cf->Disabled ) {
- my ( $ret, $msg ) = $cf->SetDisabled( 1 );
- if ( !$ret ) {
- RT->Logger->error( "Couldn't disable old Constituency cf: $msg" );
- }
- }
- }
},
);
-sub remove_scrip_action {
- my $module = shift;
-
- my $actions = RT::ScripActions->new( RT->SystemUser );
- $actions->Limit( FIELD => 'ExecModule', VALUE => $module );
- while ( my $action = $actions->Next ) {
- my $scrips = RT::Scrips->new( $RT::SystemUser );
- $scrips->Limit( FIELD => 'ScripAction', VALUE => $action->id );
- while ( my $scrip = $scrips->Next ) {
- $scrip->Delete;
- }
- $action->DBIx::SearchBuilder::Record::Delete();
- }
-}
-
-sub remove_scrip_condition {
- my $module = shift;
-
- my $conditions = RT::ScripConditions->new( RT->SystemUser );
- $conditions->Limit( FIELD => 'ExecModule', VALUE => $module );
- while ( my $condition = $conditions->Next ) {
- my $scrips = RT::Scrips->new( $RT::SystemUser );
- $scrips->Limit( FIELD => 'ScripCondition', VALUE => $condition->id );
- while ( my $scrip = $scrips->Next ) {
- $scrip->Delete;
- }
- $condition->DBIx::SearchBuilder::Record::Delete();
- }
-}
diff --git a/etc/upgrade/3.3.0/content b/etc/upgrade/3.3.1/content
similarity index 89%
copy from etc/upgrade/3.3.0/content
copy to etc/upgrade/3.3.1/content
index 9d8321d..424956e 100644
--- a/etc/upgrade/3.3.0/content
+++ b/etc/upgrade/3.3.1/content
@@ -50,35 +50,6 @@ our @Final = (
for ( 'RTIR_RequireConstituencyChange', 'RTIR_RequireConstituencyGroupChange' );
}
- # fix lifecycle from blocks to countermeasures
- {
- my $queues = RT::Queues->new(RT->SystemUser);
- $queues->Limit(FIELD => 'Lifecycle', VALUE => 'blocks');
- while (my $queue = $queues->Next) {
- $queue->SetLifecycle(RT::IR->lifecycle_countermeasure);
- }
- }
-
- # fix queue name from Blocks to Countermeasures
- {
- my $queues = RT::Queues->new(RT->SystemUser);
- $queues->Limit(
- FIELD => 'Name',
- OPERATOR => 'STARTSWITH',
- VALUE => 'Blocks',
- );
-
- while (my $queue = $queues->Next) {
- next unless $queue->Name eq 'Blocks'
- || $queue->Name =~ /^Blocks - /;
-
- my $new = $queue->Name;
- $new =~ s/^Blocks/Countermeasures/;
-
- $queue->SetName($new);
- }
- }
-
# update values of rtir constituency
my @constituencies;
{
commit 39c6332cff290d0b4b6f46deb5aff18e767cb863
Author: Shawn M Moore <shawn at bestpractical.com>
Date: Fri May 20 18:11:31 2016 +0000
Fix mis-set constituency-queue lifecycles _before_ constituency upgrade
See 995398271072ceb09d72388979f01f43ab5bedc9 for more context
diff --git a/etc/upgrade/3.3.1/content b/etc/upgrade/3.3.1/content
index 424956e..d303765 100644
--- a/etc/upgrade/3.3.1/content
+++ b/etc/upgrade/3.3.1/content
@@ -1,202 +1,43 @@
use strict;
use warnings;
-our @CustomFields = (
- {
- Name => 'RTIR Constituency',
- Type => 'SelectSingle',
- Disabled => 0,
- RenderType => 'Dropdown',
- LookupType => 'RT::Queue',
- Description => 'Associates RTIR queues with constituencies',
- Values => [],
- },
- {
-
- Name => 'RTIR default WHOIS server',
- Type => 'FreeformSingle',
- Disabled => 0,
- LookupType => 'RT::Queue',
- Description => 'If set, defines the default WHOIS server for an RTIR Queue',
- ApplyTo => [ 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ],
- },
-
-);
-
-our @ScripActions = (
- {
- Name => 'RTIR Change Child Constituencies',
- Description => 'Move all tickets related to an incident to a new constituency',
- ExecModule => 'RTIR_ChangeChildConstituencies',
- },
-);
-
-our @Scrips = (
- {
- Description => "Propagate Constituency Changes",
- Queue => 'Incidents',
- ScripCondition => 'On Queue Change',
- ScripAction => 'RTIR Change Child Constituencies',
- Template => 'Blank',
- },
-);
-
-our @Final = (
+our @Initial = (
sub {
- # remove old code
- {
- remove_scrip_action( $_ ) for ( 'RTIR_SetConstituency', 'RTIR_SetConstituencyGroup' );
- remove_scrip_condition( $_ )
- for ( 'RTIR_RequireConstituencyChange', 'RTIR_RequireConstituencyGroupChange' );
- }
-
- # update values of rtir constituency
- my @constituencies;
- {
- my $cf = RT::CustomField->new( RT->SystemUser );
- $cf->LoadByName( Name => 'Constituency', LookupType => 'RT::Queue-RT::Ticket' );
- if ( $cf->id ) {
- my $values = $cf->Values;
- while ( my $value = $values->Next ) {
- push @constituencies, $value->Name;
- }
+ my $queues = RT::Queues->new(RT->SystemUser);
+ $queues->UnLimit;
+ while (my $queue = $queues->Next) {
+ my $name = $queue->Name;
+ my $lifecycle;
+
+ if ($name =~ /^Incident Reports - /) {
+ $lifecycle = RT::IR->lifecycle_report;
}
- else {
- RT->Logger->error( "Failed to load Constituency cf" );
+ elsif ($name =~ /^Incidents - /) {
+ $lifecycle = RT::IR->lifecycle_incident;
}
- my $queue_cf = RT::CustomField->new( RT->SystemUser );
- $queue_cf->LoadByName( Name => 'RTIR Constituency', LookupType => 'RT::Queue' );
- if ( $queue_cf->id ) {
- for my $constituency ( @constituencies ) {
- my ( $ret, $msg ) = $queue_cf->AddValue( Name => $constituency );
- if ( !$ret ) {
- RT->Logger->error( "Failed to add $constituency to 'RTIR Constituency': $msg " );
- }
- }
+ elsif ($name =~ /^Investigations - /) {
+ $lifecycle = RT::IR->lifecycle_investigation;
+ }
+ elsif ($name =~ /^Countermeasures - /) {
+ $lifecycle = RT::IR->lifecycle_countermeasure;
}
else {
- RT->Logger->error( "Failed to load 'RTIR Constituency' cf" );
+ next;
}
- }
- # create new queues
- my $add_constituency_cmd = File::Spec->catfile( $RT::LocalPluginPath, 'RT-IR', 'bin', 'add_constituency' );
+ my $old_lifecycle = $queue->Lifecycle;
- for my $constituency ( @constituencies ) {
- system( $add_constituency_cmd, '--name', $constituency, '--force' );
- }
+ next if $old_lifecycle eq $lifecycle;
- # move tickets
- for my $queue ( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
- my $tickets = RT::Tickets->new( RT->SystemUser );
- $tickets->FromSQL( qq{Queue = '$queue' AND CF.{Constituency} IS NOT NULL} );
- while ( my $ticket = $tickets->Next ) {
- my $constituency = $ticket->FirstCustomFieldValue( 'Constituency' );
- my $new_queue = RT::Queue->new( RT->SystemUser );
- $new_queue->Load( "$queue - $constituency" );
- if ( $new_queue->id ) {
- my ( $ret, $msg ) = $ticket->_Set( Field => 'Queue', Value => $new_queue->id );
- if ( !$ret ) {
- RT->Logger->error(
- "Failed to move ticket #" . $ticket->id . qq{ to "$queue - $constituency": $msg} );
- }
- }
- else {
- RT->Logger->warning( "Failed to load queue '$queue - $constituency'" );
- }
+ if ($old_lifecycle ne 'default') {
+ RT->Logger->warning( "Unwilling to change queue $name lifecycle from unexpected lifecycle of $old_lifecycle to $lifecycle. (expected lifecycle default)" );
+ next;
}
- }
- # update code
- {
- my $attrs = RT::Attributes->new( RT->SystemUser );
- $attrs->Limit( FIELD => 'Name', VALUE => 'RTIR_HomepageSettings' );
- while ( my $attr = $attrs->Next ) {
- my $content = $attr->Content;
- my $sidebar_has_refresh;
- my $sidebar_has_constituency;
- for my $pane ( qw/body sidebar/ ) {
- my @new;
- for my $value ( @{ $content->{ $pane } } ) {
- if ( $value->{ name } eq 'Quicksearch' && $value->{ type } eq 'component' ) {
- push @new, { %$value, name => '/RTIR/Elements/QueueSummary' };
- }
- elsif ($pane eq 'sidebar'
- && $value->{ name } eq 'RefreshHomepage'
- && $value->{ type } eq 'component' )
- {
- # we want to put refresh component to the end of the list
- $sidebar_has_refresh = 1;
- }
- elsif ($pane eq 'sidebar'
- && $value->{ name } eq '/RTIR/Elements/WorkWithConstituency'
- && $value->{ type } eq 'component' )
- {
- $sidebar_has_constituency = 1;
- push @new, $value;
- }
- else {
- push @new, $value;
- }
- }
- $content->{ $pane } = \@new;
- }
- unless ( $sidebar_has_constituency ) {
- unshift @{ $content->{ sidebar } },
- { type => 'component', name => '/RTIR/Elements/WorkWithConstituency' };
- }
+ RT->Logger->debug( "Changing queue $name lifecycle from $old_lifecycle to $lifecycle" );
- if ( $sidebar_has_refresh ) {
- push @{ $content->{ sidebar } }, { type => 'component', name => 'RefreshHomepage' };
- }
-
- my ( $ret, $msg ) = $attr->SetContent( $content );
- unless ( $ret ) {
- RT->Logger->error( "Failed to update content of attribute #" . $attr->id . ": $msg" );
- }
- }
- }
-
- # disable old Constituency cf
- {
- my $cf = RT::CustomField->new( RT->SystemUser );
- $cf->LoadByName( Name => 'Constituency', LookupType => 'RT::Queue-RT::Ticket' );
- if ( $cf->id && !$cf->Disabled ) {
- my ( $ret, $msg ) = $cf->SetDisabled( 1 );
- if ( !$ret ) {
- RT->Logger->error( "Couldn't disable old Constituency cf: $msg" );
- }
- }
+ my ($ok, $msg) = $queue->SetLifecycle($lifecycle);
+ RT->Logger->error( "Unable to change queue $name lifecycle from $old_lifecycle to $lifecycle: $msg" ) if !$ok;
}
},
);
-
-sub remove_scrip_action {
- my $module = shift;
-
- my $actions = RT::ScripActions->new( RT->SystemUser );
- $actions->Limit( FIELD => 'ExecModule', VALUE => $module );
- while ( my $action = $actions->Next ) {
- my $scrips = RT::Scrips->new( $RT::SystemUser );
- $scrips->Limit( FIELD => 'ScripAction', VALUE => $action->id );
- while ( my $scrip = $scrips->Next ) {
- $scrip->Delete;
- }
- $action->DBIx::SearchBuilder::Record::Delete();
- }
-}
-
-sub remove_scrip_condition {
- my $module = shift;
-
- my $conditions = RT::ScripConditions->new( RT->SystemUser );
- $conditions->Limit( FIELD => 'ExecModule', VALUE => $module );
- while ( my $condition = $conditions->Next ) {
- my $scrips = RT::Scrips->new( $RT::SystemUser );
- $scrips->Limit( FIELD => 'ScripCondition', VALUE => $condition->id );
- while ( my $scrip = $scrips->Next ) {
- $scrip->Delete;
- }
- $condition->DBIx::SearchBuilder::Record::Delete();
- }
-}
diff --git a/etc/upgrade/3.3.2/content b/etc/upgrade/3.3.2/content
index 894d2d3..424956e 100644
--- a/etc/upgrade/3.3.2/content
+++ b/etc/upgrade/3.3.2/content
@@ -1,41 +1,202 @@
use strict;
use warnings;
-our @Initial = (
+our @CustomFields = (
+ {
+ Name => 'RTIR Constituency',
+ Type => 'SelectSingle',
+ Disabled => 0,
+ RenderType => 'Dropdown',
+ LookupType => 'RT::Queue',
+ Description => 'Associates RTIR queues with constituencies',
+ Values => [],
+ },
+ {
+
+ Name => 'RTIR default WHOIS server',
+ Type => 'FreeformSingle',
+ Disabled => 0,
+ LookupType => 'RT::Queue',
+ Description => 'If set, defines the default WHOIS server for an RTIR Queue',
+ ApplyTo => [ 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ],
+ },
+
+);
+
+our @ScripActions = (
+ {
+ Name => 'RTIR Change Child Constituencies',
+ Description => 'Move all tickets related to an incident to a new constituency',
+ ExecModule => 'RTIR_ChangeChildConstituencies',
+ },
+);
+
+our @Scrips = (
+ {
+ Description => "Propagate Constituency Changes",
+ Queue => 'Incidents',
+ ScripCondition => 'On Queue Change',
+ ScripAction => 'RTIR Change Child Constituencies',
+ Template => 'Blank',
+ },
+);
+
+our @Final = (
sub {
- my $action = RT::ScripAction->new(RT->SystemUser);
- $action->Load('RTIR Set Incident Due');
- if ( $action->id ) {
- my $scrips = RT::Scrips->new(RT->SystemUser);
- $scrips->Limit( FIELD => 'ScripAction', VALUE => $action->id );
- return unless $scrips->Count;
- my $report_queues = RT::Queues->new(RT->SystemUser);
- $report_queues->Limit( FIELD => 'Lifecycle', VALUE => RT::IR->lifecycle_report );
- return unless $report_queues->Count;
- my @report_queues = @{$report_queues->ItemsArrayRef};
- my $incident_queues = RT::Queues->new(RT->SystemUser);
- $incident_queues->Limit( FIELD => 'Lifecycle', VALUE => RT::IR->lifecycle_incident );
- return unless $incident_queues->Count;
- my @incident_queues = @{$incident_queues->ItemsArrayRef};
- my %queue_map;
- for my $incident_queue( @incident_queues ) {
- $queue_map{$incident_queue->FirstCustomFieldValue('RTIR Constituency') || '' } = $incident_queue;
+ # remove old code
+ {
+ remove_scrip_action( $_ ) for ( 'RTIR_SetConstituency', 'RTIR_SetConstituencyGroup' );
+ remove_scrip_condition( $_ )
+ for ( 'RTIR_RequireConstituencyChange', 'RTIR_RequireConstituencyGroupChange' );
+ }
+
+ # update values of rtir constituency
+ my @constituencies;
+ {
+ my $cf = RT::CustomField->new( RT->SystemUser );
+ $cf->LoadByName( Name => 'Constituency', LookupType => 'RT::Queue-RT::Ticket' );
+ if ( $cf->id ) {
+ my $values = $cf->Values;
+ while ( my $value = $values->Next ) {
+ push @constituencies, $value->Name;
+ }
+ }
+ else {
+ RT->Logger->error( "Failed to load Constituency cf" );
+ }
+ my $queue_cf = RT::CustomField->new( RT->SystemUser );
+ $queue_cf->LoadByName( Name => 'RTIR Constituency', LookupType => 'RT::Queue' );
+ if ( $queue_cf->id ) {
+ for my $constituency ( @constituencies ) {
+ my ( $ret, $msg ) = $queue_cf->AddValue( Name => $constituency );
+ if ( !$ret ) {
+ RT->Logger->error( "Failed to add $constituency to 'RTIR Constituency': $msg " );
+ }
+ }
+ }
+ else {
+ RT->Logger->error( "Failed to load 'RTIR Constituency' cf" );
+ }
+ }
+
+ # create new queues
+ my $add_constituency_cmd = File::Spec->catfile( $RT::LocalPluginPath, 'RT-IR', 'bin', 'add_constituency' );
+
+ for my $constituency ( @constituencies ) {
+ system( $add_constituency_cmd, '--name', $constituency, '--force' );
+ }
+
+ # move tickets
+ for my $queue ( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
+ my $tickets = RT::Tickets->new( RT->SystemUser );
+ $tickets->FromSQL( qq{Queue = '$queue' AND CF.{Constituency} IS NOT NULL} );
+ while ( my $ticket = $tickets->Next ) {
+ my $constituency = $ticket->FirstCustomFieldValue( 'Constituency' );
+ my $new_queue = RT::Queue->new( RT->SystemUser );
+ $new_queue->Load( "$queue - $constituency" );
+ if ( $new_queue->id ) {
+ my ( $ret, $msg ) = $ticket->_Set( Field => 'Queue', Value => $new_queue->id );
+ if ( !$ret ) {
+ RT->Logger->error(
+ "Failed to move ticket #" . $ticket->id . qq{ to "$queue - $constituency": $msg} );
+ }
+ }
+ else {
+ RT->Logger->warning( "Failed to load queue '$queue - $constituency'" );
+ }
}
+ }
- while ( my $scrip = $scrips->Next ) {
- for my $report_queue ( @report_queues ) {
- if ( $scrip->IsAdded($report_queue->id) ) {
- my $incident_queue =
- $queue_map{$report_queue->FirstCustomFieldValue('RTIR Constituency') || ''};
- if ( $incident_queue && !$incident_queue->SLADisabled ) {
- my ($ret, $msg) = $incident_queue->SetSLADisabled(1);
- unless ( $ret ) {
- RT->Logger->error("Couldn't disable core SLA for queue #" . $incident_queue->id . ": $msg");
- }
+ # update code
+ {
+ my $attrs = RT::Attributes->new( RT->SystemUser );
+ $attrs->Limit( FIELD => 'Name', VALUE => 'RTIR_HomepageSettings' );
+ while ( my $attr = $attrs->Next ) {
+ my $content = $attr->Content;
+ my $sidebar_has_refresh;
+ my $sidebar_has_constituency;
+ for my $pane ( qw/body sidebar/ ) {
+ my @new;
+ for my $value ( @{ $content->{ $pane } } ) {
+ if ( $value->{ name } eq 'Quicksearch' && $value->{ type } eq 'component' ) {
+ push @new, { %$value, name => '/RTIR/Elements/QueueSummary' };
+ }
+ elsif ($pane eq 'sidebar'
+ && $value->{ name } eq 'RefreshHomepage'
+ && $value->{ type } eq 'component' )
+ {
+ # we want to put refresh component to the end of the list
+ $sidebar_has_refresh = 1;
+ }
+ elsif ($pane eq 'sidebar'
+ && $value->{ name } eq '/RTIR/Elements/WorkWithConstituency'
+ && $value->{ type } eq 'component' )
+ {
+ $sidebar_has_constituency = 1;
+ push @new, $value;
+ }
+ else {
+ push @new, $value;
}
}
+ $content->{ $pane } = \@new;
+ }
+ unless ( $sidebar_has_constituency ) {
+ unshift @{ $content->{ sidebar } },
+ { type => 'component', name => '/RTIR/Elements/WorkWithConstituency' };
+ }
+
+ if ( $sidebar_has_refresh ) {
+ push @{ $content->{ sidebar } }, { type => 'component', name => 'RefreshHomepage' };
+ }
+
+ my ( $ret, $msg ) = $attr->SetContent( $content );
+ unless ( $ret ) {
+ RT->Logger->error( "Failed to update content of attribute #" . $attr->id . ": $msg" );
+ }
+ }
+ }
+
+ # disable old Constituency cf
+ {
+ my $cf = RT::CustomField->new( RT->SystemUser );
+ $cf->LoadByName( Name => 'Constituency', LookupType => 'RT::Queue-RT::Ticket' );
+ if ( $cf->id && !$cf->Disabled ) {
+ my ( $ret, $msg ) = $cf->SetDisabled( 1 );
+ if ( !$ret ) {
+ RT->Logger->error( "Couldn't disable old Constituency cf: $msg" );
}
}
}
},
);
+
+sub remove_scrip_action {
+ my $module = shift;
+
+ my $actions = RT::ScripActions->new( RT->SystemUser );
+ $actions->Limit( FIELD => 'ExecModule', VALUE => $module );
+ while ( my $action = $actions->Next ) {
+ my $scrips = RT::Scrips->new( $RT::SystemUser );
+ $scrips->Limit( FIELD => 'ScripAction', VALUE => $action->id );
+ while ( my $scrip = $scrips->Next ) {
+ $scrip->Delete;
+ }
+ $action->DBIx::SearchBuilder::Record::Delete();
+ }
+}
+
+sub remove_scrip_condition {
+ my $module = shift;
+
+ my $conditions = RT::ScripConditions->new( RT->SystemUser );
+ $conditions->Limit( FIELD => 'ExecModule', VALUE => $module );
+ while ( my $condition = $conditions->Next ) {
+ my $scrips = RT::Scrips->new( $RT::SystemUser );
+ $scrips->Limit( FIELD => 'ScripCondition', VALUE => $condition->id );
+ while ( my $scrip = $scrips->Next ) {
+ $scrip->Delete;
+ }
+ $condition->DBIx::SearchBuilder::Record::Delete();
+ }
+}
diff --git a/etc/upgrade/3.3.3/content b/etc/upgrade/3.3.3/content
index 0e1513d..894d2d3 100644
--- a/etc/upgrade/3.3.3/content
+++ b/etc/upgrade/3.3.3/content
@@ -3,29 +3,36 @@ use warnings;
our @Initial = (
sub {
- my $cf = RT::CustomField->new(RT->SystemUser);
- $cf->Load( "RTIR Constituency", LookupType => 'RT::Queue' );
- my @constituencies = ('', map { $_->Name } @{$cf->Values->ItemsArrayRef || []} );
+ my $action = RT::ScripAction->new(RT->SystemUser);
+ $action->Load('RTIR Set Incident Due');
+ if ( $action->id ) {
+ my $scrips = RT::Scrips->new(RT->SystemUser);
+ $scrips->Limit( FIELD => 'ScripAction', VALUE => $action->id );
+ return unless $scrips->Count;
+ my $report_queues = RT::Queues->new(RT->SystemUser);
+ $report_queues->Limit( FIELD => 'Lifecycle', VALUE => RT::IR->lifecycle_report );
+ return unless $report_queues->Count;
+ my @report_queues = @{$report_queues->ItemsArrayRef};
+ my $incident_queues = RT::Queues->new(RT->SystemUser);
+ $incident_queues->Limit( FIELD => 'Lifecycle', VALUE => RT::IR->lifecycle_incident );
+ return unless $incident_queues->Count;
+ my @incident_queues = @{$incident_queues->ItemsArrayRef};
+ my %queue_map;
+ for my $incident_queue( @incident_queues ) {
+ $queue_map{$incident_queue->FirstCustomFieldValue('RTIR Constituency') || '' } = $incident_queue;
+ }
- my %groups;
- for my $constituency ( @constituencies ) {
- my $group = RT::Group->new(RT->SystemUser);
- $group->LoadUserDefinedGroup('DutyTeam' . ($constituency ? " $constituency" : '') );
- $groups{$constituency} = $group if $group->id;
- }
- my $queues = RT::Queues->new(RT->SystemUser);
- $queues->UnLimit;
- while ( my $queue = $queues->Next ) {
- my $constituency = $queue->FirstCustomFieldValue('RTIR Constituency');
- if ( $constituency || $queue->Name =~ /^(?:Incidents|Incident Reports|Investigations|Blocks)$/ ) {
- my $group = $groups{$constituency || ''};
- if ( $group && !$group->PrincipalObj->HasRight( Right => 'ForwardMessage', Object => $queue ) ) {
- my ( $ret, $msg ) = $group->PrincipalObj->GrantRight(
- Right => 'ForwardMessage',
- Object => $queue,
- );
- unless ($ret) {
- RT->Logger->error("Couldn't grant ForwardMessage to DutyTeam of queue #" . $queue->id . ": $msg");
+ while ( my $scrip = $scrips->Next ) {
+ for my $report_queue ( @report_queues ) {
+ if ( $scrip->IsAdded($report_queue->id) ) {
+ my $incident_queue =
+ $queue_map{$report_queue->FirstCustomFieldValue('RTIR Constituency') || ''};
+ if ( $incident_queue && !$incident_queue->SLADisabled ) {
+ my ($ret, $msg) = $incident_queue->SetSLADisabled(1);
+ unless ( $ret ) {
+ RT->Logger->error("Couldn't disable core SLA for queue #" . $incident_queue->id . ": $msg");
+ }
+ }
}
}
}
diff --git a/etc/upgrade/3.3.4/content b/etc/upgrade/3.3.4/content
index d303765..0e1513d 100644
--- a/etc/upgrade/3.3.4/content
+++ b/etc/upgrade/3.3.4/content
@@ -3,41 +3,32 @@ use warnings;
our @Initial = (
sub {
+ my $cf = RT::CustomField->new(RT->SystemUser);
+ $cf->Load( "RTIR Constituency", LookupType => 'RT::Queue' );
+ my @constituencies = ('', map { $_->Name } @{$cf->Values->ItemsArrayRef || []} );
+
+ my %groups;
+ for my $constituency ( @constituencies ) {
+ my $group = RT::Group->new(RT->SystemUser);
+ $group->LoadUserDefinedGroup('DutyTeam' . ($constituency ? " $constituency" : '') );
+ $groups{$constituency} = $group if $group->id;
+ }
my $queues = RT::Queues->new(RT->SystemUser);
$queues->UnLimit;
- while (my $queue = $queues->Next) {
- my $name = $queue->Name;
- my $lifecycle;
-
- if ($name =~ /^Incident Reports - /) {
- $lifecycle = RT::IR->lifecycle_report;
- }
- elsif ($name =~ /^Incidents - /) {
- $lifecycle = RT::IR->lifecycle_incident;
- }
- elsif ($name =~ /^Investigations - /) {
- $lifecycle = RT::IR->lifecycle_investigation;
- }
- elsif ($name =~ /^Countermeasures - /) {
- $lifecycle = RT::IR->lifecycle_countermeasure;
- }
- else {
- next;
+ while ( my $queue = $queues->Next ) {
+ my $constituency = $queue->FirstCustomFieldValue('RTIR Constituency');
+ if ( $constituency || $queue->Name =~ /^(?:Incidents|Incident Reports|Investigations|Blocks)$/ ) {
+ my $group = $groups{$constituency || ''};
+ if ( $group && !$group->PrincipalObj->HasRight( Right => 'ForwardMessage', Object => $queue ) ) {
+ my ( $ret, $msg ) = $group->PrincipalObj->GrantRight(
+ Right => 'ForwardMessage',
+ Object => $queue,
+ );
+ unless ($ret) {
+ RT->Logger->error("Couldn't grant ForwardMessage to DutyTeam of queue #" . $queue->id . ": $msg");
+ }
+ }
}
-
- my $old_lifecycle = $queue->Lifecycle;
-
- next if $old_lifecycle eq $lifecycle;
-
- if ($old_lifecycle ne 'default') {
- RT->Logger->warning( "Unwilling to change queue $name lifecycle from unexpected lifecycle of $old_lifecycle to $lifecycle. (expected lifecycle default)" );
- next;
- }
-
- RT->Logger->debug( "Changing queue $name lifecycle from $old_lifecycle to $lifecycle" );
-
- my ($ok, $msg) = $queue->SetLifecycle($lifecycle);
- RT->Logger->error( "Unable to change queue $name lifecycle from $old_lifecycle to $lifecycle: $msg" ) if !$ok;
}
},
);
-----------------------------------------------------------------------
More information about the rt-commit
mailing list