[Rt-commit] rtir branch, 2.9-trunk, updated. 2.6.1rc1-330-gbdbff28
Ruslan Zakirov
ruz at bestpractical.com
Thu Aug 25 15:04:37 EDT 2011
The branch, 2.9-trunk has been updated
via bdbff28afc102f3d16a5a8cfe7045348071b02d7 (commit)
via a57bc4e1e40eaf86c0374e061710e651b45c17af (commit)
via e98b6d37e2d8cc13d1dc5f98c1b7c19eacabcd7f (commit)
from 70d6d6c203e8d13e88d13e9dfcad61145165b09f (commit)
Summary of changes:
TODO.porting_over_RT4 | 2 +-
html/RTIR/Elements/AttachReports | 9 ++++---
html/RTIR/Incident/Display.html | 4 +--
html/RTIR/Incident/Edit.html | 7 +-----
html/RTIR/Merge/index.html | 23 ++++++++----------
lib/RT/Action/RTIR_ResolveChildren.pm | 32 ++++++++++---------------
lib/RT/IR.pm | 41 +++++++++++++++++----------------
7 files changed, 52 insertions(+), 66 deletions(-)
- Log -----------------------------------------------------------------
commit e98b6d37e2d8cc13d1dc5f98c1b7c19eacabcd7f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Aug 25 21:20:18 2011 +0400
don't use on_incident_resolve, use maps instead
diff --git a/TODO.porting_over_RT4 b/TODO.porting_over_RT4
index 5b3b29e..30e1ec0 100644
--- a/TODO.porting_over_RT4
+++ b/TODO.porting_over_RT4
@@ -50,7 +50,7 @@
=== DOCS
-* on_incident_resolve - document it
+* document why maps are required
=== CLEANUP && REFACTORING
diff --git a/lib/RT/Action/RTIR_ResolveChildren.pm b/lib/RT/Action/RTIR_ResolveChildren.pm
index 5c4e973..2758d2e 100644
--- a/lib/RT/Action/RTIR_ResolveChildren.pm
+++ b/lib/RT/Action/RTIR_ResolveChildren.pm
@@ -73,26 +73,18 @@ Resolve all children.
sub Commit {
my $self = shift;
- my $id = $self->TicketObj->Id;
+ my $incident = $self->TicketObj;
+ my $id = $incident->Id;
foreach my $qname ( 'Incident Reports', 'Investigations', 'Blocks' ) {
next if $qname eq 'Blocks' && RT->Config->Get('RTIR_DisableBlocksQueue');
- my $queue = RT::Queue->new( $self->CurrentUser );
- $queue->Load( $qname );
- unless ( $queue->id ) {
- $RT::Logger->error("Couldn't load '$qname' queue");
- next;
- }
-
- my $cycle = $queue->Lifecycle;
- my $query = "MemberOf = $id AND Queue = '$qname' AND "
- . join ' AND ', map "Status != '$_'", $cycle->Inactive;
-
- my $members = RT::Tickets->new( $self->CurrentUser );
- $members->FromSQL( $query );
+ my $members = RT::IR->IncidentChildren(
+ $incident, Queue => $qname,
+ Initial => 1, Active => 1,
+ );
while ( my $member = $members->Next ) {
- if ( RT::IR->IsLinkedToActiveIncidents( $member, $self->TicketObj ) ) {
+ if ( RT::IR->IsLinkedToActiveIncidents( $member, $incident ) ) {
$member->Comment(Content => <<END);
Linked Incident \#$id was resolved, but ticket still has unresolved linked Incidents.
@@ -100,10 +92,12 @@ Linked Incident \#$id was resolved, but ticket still has unresolved linked Incid
END
next;
}
- my ($res, $msg) = $member->SetStatus(
- $cycle->DefaultStatus('on_incident_resolve') || ($cycle->Inactive)[0]
- );
- $RT::Logger->info( "Couldn't resolve ticket: $msg" ) unless $res;
+ my $set_to = RT::IR->MapStatus( $incident->Status, $incident => $qname );
+ next unless $set_to;
+ next if $member->Status eq $set_to;
+
+ my ($res, $msg) = $member->SetStatus( $set_to );
+ RT->Logger->info( "Couldn't resolve ticket: $msg" ) unless $res;
}
}
return 1;
commit a57bc4e1e40eaf86c0374e061710e651b45c17af
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Aug 25 22:20:35 2011 +0400
in RT::IR->Query support more formats of arguments
for most arguments support mix of scalars, objects or
array with those things
diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index 3b1507c..350525e 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -205,15 +205,20 @@ Examples:
=cut
+my $flat = sub {
+ my ($arg, $method) = @_;
+ my @list = blessed $arg ? ($arg) : ref $arg ? @$arg : ($arg);
+ if ( $method ) {
+ $_ = $_->$method() foreach grep blessed($_), @list;
+ }
+ return @list;
+};
+
sub Statuses {
my $self = shift;
my %arg = ( Queue => undef, Initial => 1, Active => 1, Inactive => 0, @_ );
- my @queues = !$arg{'Queue'}
- ? (@QUEUES)
- : ref $arg{'Queue'} && !blessed $arg{'Queue'}
- ? @{ $arg{'Queue'} }
- : ( $arg{'Queue'} );
+ my @queues = $flat->( $arg{'Queue'} || \@QUEUES );
my (@initial, @active, @inactive);
foreach my $queue (@queues) {
@@ -256,36 +261,32 @@ sub Query {
And => undef,
@_
);
+
my @res;
if ( $args{'Queue'} ) {
- my @queues = ref $args{'Queue'} && !blessed $args{'Queue'}
- ? @{ $args{'Queue'} }
- : ( $args{'Queue'} )
- ;
push @res, map "($_)", join ' OR ', map "Queue = '$_'",
- map blessed $_? $_->Name : $_,
- @queues;
+ $flat->( $args{'Queue'}, 'Name' );
}
if ( !$args{'Status'} && ( $args{'Initial'} || $args{'Active'} || $args{'Inactive'} ) ) {
$args{'Status'} = [ $self->Statuses( %args ) ];
}
if ( my $s = $args{'Status'} ) {
- push @res, '('. join( ' OR ', map "Status = '$_'", ref $s? (@$s) : ($s) ) .')';
+ push @res, join ' OR ', map "Status = '$_'", $flat->( $s );
}
if ( my $t = $args{'Exclude'} ) {
- push @res, '('. join( ' AND ', map "id != '$_'", map int $_, ref $t? (@$t) : ($t) ) .')';
+ push @res, join ' AND ', map "id != '$_'", map int $_, $flat->( $t, 'id' );
}
if ( my $t = $args{'HasMember'} ) {
- push @res, 'HasMember = '. (ref $t? $t->id : int $t);
+ push @res, join ' OR ', map "HasMember = $_", map int $_, $flat->( $t, 'id' );
}
if ( my $t = $args{'HasNoMember'} ) {
- push @res, 'HasMember != '. (ref $t? $t->id : int $t);
- }
- if ( my $t = $args{'NotMemberOf'} ) {
- push @res, 'MemberOf != '. (ref $t? $t->id : int $t);
+ push @res, join ' AND ', map "HasMember != $_", map int $_, $flat->( $t, 'id' );
}
if ( my $t = $args{'MemberOf'} ) {
- push @res, 'MemberOf = '. (ref $t? $t->id : int $t);
+ push @res, join ' OR ', map "MemberOf = $_", map int $_, $flat->( $t, 'id' );
+ }
+ if ( my $t = $args{'NotMemberOf'} ) {
+ push @res, join ' AND ', map "MemberOf != $_", map int $_, $flat->( $t, 'id' );
}
if (
my $t = $args{'Constituency'}
@@ -301,7 +302,7 @@ sub Query {
if ( my $c = $args{'And'} ) {
push @res, ref $c? @$c : ($c);
}
- return join ' AND ', @res;
+ return join ' AND ', map { /\b(?:AND|OR)\b/? "( $_ )" : $_ } @res;
}
sub OurQuery {
commit bdbff28afc102f3d16a5a8cfe7045348071b02d7
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Thu Aug 25 22:43:44 2011 +0400
use RT::IR->Query and friends in more places
diff --git a/html/RTIR/Elements/AttachReports b/html/RTIR/Elements/AttachReports
index d467b0b..61571a0 100644
--- a/html/RTIR/Elements/AttachReports
+++ b/html/RTIR/Elements/AttachReports
@@ -24,10 +24,11 @@ if ( $type eq 'Incident' ) {
return unless @parents;
my $siblings = RT::Tickets->new( $Ticket->CurrentUser );
-my $query = "Queue = 'Incident Reports'"
- ." AND (". join( ' OR ', map "MemberOf = $_", @parents ) . ")";
-$query .= " AND id != ". $Ticket->id if $type eq 'Report';
-$siblings->FromSQL( $query );
+$siblings->FromSQL( RT::IR->Query(
+ Queue => 'Incident Reports',
+ MemberOf => \@parents,
+ Exclude => $Ticket,
+) );
$siblings->_DoSearch;
return unless $siblings->Count;
diff --git a/html/RTIR/Incident/Display.html b/html/RTIR/Incident/Display.html
index aecf135..9d7b658 100644
--- a/html/RTIR/Incident/Display.html
+++ b/html/RTIR/Incident/Display.html
@@ -145,9 +145,7 @@ my $DoLinks = sub {
# Blocks or Incedent Reports can have multiple incidents
my $Type = RT::IR::TicketType( Ticket => $child );
unless( $Type eq 'Block' || $Type eq 'Report' ) {
- my $query = "Queue = 'Incidents' AND HasMember = ". $child->Id ." AND id != ". $parent->id;
- my $incidents = RT::Tickets->new( $session{'CurrentUser'} );
- $incidents->FromSQL( $query );
+ my $incidents = RT::IR->Incidents( $child, Exclude => $parent );
while ( my $incident = $incidents->Next ) {
$deleted_links = 1;
$args{'DeleteLink-'. $child->id .'-MemberOf-'. $incident->id } = '';
diff --git a/html/RTIR/Incident/Edit.html b/html/RTIR/Incident/Edit.html
index faa152d..10d48aa 100644
--- a/html/RTIR/Incident/Edit.html
+++ b/html/RTIR/Incident/Edit.html
@@ -125,12 +125,7 @@ my $constituency_cf = RT::IR->CustomFields( Constituency => Ticket => $Ticket );
my $constituency_propagation = RT->Config->Get('_RTIR_Constituency_Propagation');
my $has_children = 0;
if ( $constituency_cf && $constituency_propagation eq 'reject' ) {
- my $query = "( Queue = 'Incident Reports' OR Queue = 'Investigations' OR Queue = 'Blocks' )"
- ." AND MemberOf = ". $Ticket->id;
- my $tickets = RT::Tickets->new( $RT::SystemUser );
- $tickets->FromSQL( $query );
- $tickets->RowsPerPage(1);
- $has_children = $tickets->First ? 1 : 0;
+ $has_children = RT::IR->IncidentChildren( $Ticket )->Count;
}
my @results;
diff --git a/html/RTIR/Merge/index.html b/html/RTIR/Merge/index.html
index 4a687f3..08b64a0 100644
--- a/html/RTIR/Merge/index.html
+++ b/html/RTIR/Merge/index.html
@@ -134,19 +134,16 @@ my %defaults = (
my $siblings_query = '';
if ( $Type ne 'Incident' ) {
- my $parents_query = '';
-
- my $parents = RT::IR->Incidents( $Ticket );
- while ( my $parent = $parents->Next ) {
- $parents_query .= ' OR ' if $parents_query;
- $parents_query .= "MemberOf = ". $parent->id;
- }
- if ( $parents_query ) {
- $siblings_query .= "( $parents_query )";
- my $queue_query = "Queue = '$Queue'";
- $queue_query .= " OR Queue = 'Investigations'" if $Type eq 'Report';
- $queue_query .= " OR Queue = 'Incident Reports'" if $Type eq 'Investigation';
- $siblings_query .= " AND ( $queue_query )";
+ my @parents = @{ RT::IR->Incidents( $Ticket )->ItemsArrayRef || [] };
+ if ( @parents ) {
+ my @queues = ($Queue);
+ push @queues, 'Investigations' if $Type eq 'Report';
+ push @queues, 'Incident Reports' if $Type eq 'Investigation';
+ $siblings_query = RT::IR->Query(
+ Queue => \@queues,
+ MemberOf => \@parents,
+ Exclude => $id
+ );
}
}
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list