%# BEGIN LICENSE BLOCK %# %# Copyright (c) 1996-2003 Jesse Vincent %# %# (Except where explictly superceded by other copyright notices) %# %# 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. %# %# %# Unless otherwise specified, all modifications, corrections or %# extensions to this work which alter its source code become the %# property of Best Practical Solutions, LLC when submitted for %# inclusion in the work. %# %# %# END LICENSE BLOCK <& /Elements/Header, Title => $title, Refresh => $session{'tickets_refresh_interval'} &> <& '/RTIR/Search/Elements/RefineTabs', Title => $title, Ticket => $Ticket, Queue => $Queue, BaseQuery => $BaseQuery, QueryString => $QueryString, current_tab => $current_tab, current_subtab => 'RTIR/Search/Refine.html', &> % $m->callback(CallbackName => 'BeforeActionList', Actions => \@results, ARGSRef => \%ARGS, Ticket => $Ticket); <& /Elements/ListActions, actions => \@results &>
% if ( $siblings_query ) { <& /RTIR/Elements/MergeWith, %defaults, %ARGS, Title => loc('Other children of the parent incident(s) of #[_1]', $id), Ticket => $Ticket, Query => $siblings_query, Rows => 0, Page => 1, &> % } <& /RTIR/Elements/MergeWith, %defaults, %ARGS, Queue => $Ticket->QueueObj->Name, Ticket => $Ticket &> % if ( $Type eq 'Report' ) { <& /RTIR/Elements/MergeWith, %defaults, %ARGS, Queue => "Investigations", Ticket => $Ticket &> % } elsif ( $Type eq 'Investigation' ) { <& /RTIR/Elements/MergeWith, %defaults, %ARGS, Queue => "Incident Reports", Ticket => $Ticket &> % } <& /Elements/Submit, Caption=> loc('Merge into selected Ticket'), Label => loc("Merge") &>
<%INIT> my $Ticket = LoadTicket($id); $id = $ARGS{'id'} = $Ticket->id; $m->callback(CallbackName => 'Initial', %ARGS, Ticket => $Ticket); my $MergeTicket; $MergeTicket = LoadTicket( $SelectedTicket ) if $SelectedTicket; my (@results); my $checks_failure = 0; if ( $MergeTicket ) { my @queues = sort map $_->Name, $Ticket->QueueObj, $MergeTicket->QueueObj; unless ( $queues[0] eq $queues[1] or ($queues[0] eq "Incident Reports" and $queues[1] eq "Investigations") ) { push @results, loc("Merge failed: Ticket #[_1] is not the right type", $MergeTicket->Id ); $checks_failure = 1; } } if ( $MergeTicket && RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject' ) { if ( lc $MergeTicket->FirstCustomFieldValue('_RTIR_Constituency') ne lc $Ticket->FirstCustomFieldValue('_RTIR_Constituency') ) { push @results, loc("Merge failed: Tickets have different constituencies" ); $checks_failure = 1; } } if ( $MergeTicket && !$checks_failure ) { my @queues = sort map $_->Name, $Ticket->QueueObj, $MergeTicket->QueueObj; if ( $queues[0] ne $queues[1] && $queues[1] eq "Incident Reports" ) { # We always want to merge into the Investigation ($Ticket, $MergeTicket) = ($MergeTicket, $Ticket); } $m->callback(CallbackName => 'MergeTicketSelected', MergeFrom => $Ticket, MergeTo => $MergeTicket); $ARGS{ $Ticket->id .'-MergeInto' } = $MergeTicket->id; for my $t ( $Ticket, $MergeTicket ) { next if $t->Owner == $t->CurrentUser->Id; my ($status, $msg) = $t->SetOwner($t->CurrentUser->Id, 'Force'); push @results, $msg if $msg; } push @results, ProcessTicketLinks( TicketObj => $Ticket, ARGSRef => \%ARGS); $Ticket = LoadTicket($id); my $key = Digest::MD5::md5_hex( rand(1024) ); push @{ $session{"Actions"}{ $key } ||= [] }, @results; $session{'i'}++; RT::Interface::Web::Redirect( RT->Config->Get('WebURL') ."RTIR/Display.html?id=". $Ticket->id ."&results=$key" ); } my $Type = RT::IR::TicketType( Ticket => $Ticket ); my $Queue = $Ticket->QueueObj->Name; my $title = loc("Merge [_1] #[_2]: [_3]", $Type, $id, $Ticket->Subject); $Query ||= $m->comp('/RTIR/Elements/NewQuery', Queue => $Queue); unless ( $BaseQuery ) { my @parts; push @parts, "id != $id"; push @parts, $m->comp('/RTIR/Elements/BaseQuery', Queue => $Queue); push @parts, "CF.{_RTIR_Constituency} = '". $Ticket->FirstCustomFieldValue('_RTIR_Constituency') ."'" if RT->Config->Get('_RTIR_Constituency_Propagation') eq 'reject'; $BaseQuery = join ' AND ', map "( $_ )", grep $_, @parts; } my %defaults = ( Format => $Format, Rows => $Rows, Page => $Page, OrderBy => $OrderBy, Order => $Order, ); my $siblings_query = ''; if ( $Type ne 'Incident' ) { my $parents = RT::Tickets->new( $session{'CurrentUser'} ); $parents->FromSQL( "Queue = 'Incidents' AND HasMember = $id" ); if ( $parents->Count ) { my $parents_query = ''; 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 $QueryString = $m->comp('/Elements/QueryString', Query => $Query, %defaults); my $current_tab = "RTIR/Merge.html?id=$id"; <%ARGS> $id => undef $BaseQuery => undef $Query => undef $Format => RT->Config->Get('RTIRSearchResultFormats')->{'Merge'} $Rows => 50 $Page => 1 $OrderBy => 'id' $Order => 'ASC' $SelectedTicket => undef