[Rt-commit] [rtir] 11/12: Continue wrapping Ticket->Create, but cleanly now
Kevin Falcone
falcone at bestpractical.com
Mon Apr 14 13:16:45 EDT 2014
This is an automated email from the git hooks/post-receive script.
falcone pushed a commit to branch 3.2/unwrap-hook-lexwrap
in repository rtir.
commit 0cba869016be9f9aa898fbaac84ec74d47757058
Author: Kevin Falcone <falcone at bestpractical.com>
Date: Thu Mar 27 17:10:36 2014 -0400
Continue wrapping Ticket->Create, but cleanly now
This code tries to ensure that we have a default Constituency either
from mail headers or the config default so that every ticket ends up
with *some* value for that CF.
---
lib/RT/IR.pm | 35 +++++++++++++++++++++++------------
1 file changed, 23 insertions(+), 12 deletions(-)
diff --git a/lib/RT/IR.pm b/lib/RT/IR.pm
index 7407aba..50cea6e 100644
--- a/lib/RT/IR.pm
+++ b/lib/RT/IR.pm
@@ -840,15 +840,22 @@ if ( RT::IR->HasConstituency ) {
if ( RT::IR->HasConstituency ) {
# Set Constituency on Create
+ no warnings 'redefine';
+
require RT::Ticket;
- wrap 'RT::Ticket::Create', pre => sub {
- my $ticket = $_[0];
- my %args = (@_[1..(@_-2)]);
+ my $orig_Create = RT::Ticket->can('Create');
+ *RT::Ticket::Create = sub {
+ my $self = shift;
+ my %args = @_;
# get out if there is constituency value in arguments
my $cf = GetCustomField( 'Constituency' );
- return unless $cf && $cf->id;
- return if $args{ 'CustomField-'. $cf->id };
+ unless ($cf && $cf->id) {
+ return $orig_Create->($self,%args);
+ }
+ if ($args{ 'CustomField-'. $cf->id }) {
+ return $orig_Create->($self,%args);
+ }
# get out of here if it's not RTIR queue
my $QueueObj = RT::Queue->new( RT->SystemUser );
@@ -859,11 +866,13 @@ if ( RT::IR->HasConstituency ) {
$QueueObj->Load( $args{'Queue'} );
}
else {
- return;
+ return $orig_Create->($self,%args);
+ }
+ unless ( $QueueObj->id &&
+ $QueueObj->Name =~ /^(Incidents|Incident Reports|Investigations|Blocks)$/i ) {
+ return $orig_Create->($self,%args);
}
- return unless $QueueObj->id;
- return unless $QueueObj->Name =~
- /^(Incidents|Incident Reports|Investigations|Blocks)$/i;
+
# fetch value
my $value;
@@ -878,13 +887,15 @@ if ( RT::IR->HasConstituency ) {
RT->Logger->debug("Found Constituency '$tmp' in email") if $tmp;
}
$value ||= RT->Config->Get('RTIR_CustomFieldsDefaults')->{'Constituency'};
- return unless $value;
+ unless ($value) {
+ return $orig_Create->($self,%args);
+ }
- my @res = $ticket->Create(
+ my @res = $self->Create(
%args,
'CustomField-'. $cf->id => $value,
);
- $_[-1] = \@res;
+ return @res;
};
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the rt-commit
mailing list