[Rt-commit] rt branch, 4.4/queue-cf-charting, created. rt-4.4.1-322-gb8d3016
Dave Goehrig
dave at bestpractical.com
Wed Mar 15 16:50:27 EDT 2017
The branch, 4.4/queue-cf-charting has been created
at b8d3016b7a747dacba9ec88fb913f544303ce9f4 (commit)
- Log -----------------------------------------------------------------
commit b8d3016b7a747dacba9ec88fb913f544303ce9f4
Author: Dave Goehrig <dave at bestpractical.com>
Date: Wed Mar 15 16:40:47 2017 -0400
Fix QueueCF Charting
When you search using a 'QueueCF.{CF Name}' = 'something', the join will
vector through a hash populated when the packages load with the
LookupTypes for additional classes. RT::Tickets loads the joins for
RT::Queue and RT::Transaction when the module is loaded. Because
the join code creates a state hash for each class using it,
RT::Report::Tickets did not have this hash populated. As a result the
query would always fail. Adding these join constructors fixes the
search issue, and allows you to search against these lookup types and
chart it.
The test creates 3 queues, and 2 custom fields. It then performs two
searches, one that aggregates across two of the queues, and one that
only affects a single queue. Adding the thrid tivial search (no items
returned) is not useful, as it replicates the existing behavior.
diff --git a/lib/RT/Report/Tickets.pm b/lib/RT/Report/Tickets.pm
index fdd8890..bf69d52 100644
--- a/lib/RT/Report/Tickets.pm
+++ b/lib/RT/Report/Tickets.pm
@@ -56,6 +56,19 @@ use warnings;
use Scalar::Util qw(weaken);
+__PACKAGE__->RegisterCustomFieldJoin(@$_) for
+ [ "RT::Transaction" => sub { $_[0]->JoinTransactions } ],
+ [ "RT::Queue" => sub {
+ # XXX: Could avoid join and use main.Queue with some refactoring?
+ return $_[0]->{_sql_aliases}{queues} ||= $_[0]->Join(
+ ALIAS1 => 'main',
+ FIELD1 => 'Queue',
+ TABLE2 => 'Queues',
+ FIELD2 => 'id',
+ );
+ }
+ ];
+
our @GROUPINGS = (
Status => 'Enum', #loc_left_pair
diff --git a/t/charts/search-queue-cf.t b/t/charts/search-queue-cf.t
new file mode 100644
index 0000000..130e498
--- /dev/null
+++ b/t/charts/search-queue-cf.t
@@ -0,0 +1,90 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+use RT::Ticket;
+
+my $general = RT::Test->load_or_create_queue(Name => 'General');
+ok $general && $general->id, 'loaded or created queue';
+
+my $test_queue1 = RT::Test->load_or_create_queue(Name => 'Test Queue 1');
+ok $test_queue1 && $test_queue1->id, 'created Test Queue 1';
+
+my $test_queue2 = RT::Test->load_or_create_queue(Name => 'Test Queue 2');
+ok $test_queue2 && $test_queue2->id, 'created Test Queue 2';
+
+my @tickets = create_tickets(
+ # 3 tickets in General
+ { Queue => $general, Subject => 'new general', Status => 'new' },
+ { Queue => $general, Subject => 'open general 1', Status => 'open' },
+ { Queue => $general, Subject => 'open general 2', Status => 'open' },
+ # 2 tickets in Test Queue 1
+ { Queue => $test_queue1, Subject => 'new test queue 1', Status => 'new' },
+ { Queue => $test_queue1, Subject => 'open tests queue 1', Status => 'open' },
+ # 1 tickets in Test Queue 2
+ { Queue => $test_queue2, Subject => 'new test queue 2', Status => 'new' },
+);
+
+my $test_cf1 = RT::CustomField->new(RT->SystemUser);
+my ($cf1_id,$msg1) = $test_cf1->Create(ObjectId => 0, Name => 'Test Field 1', Type => 'Freeform', MaxValues => 1, LookupType => 'RT::Queue', Description => 'First queue test field');
+ok $cf1_id, "Created custom field 1 $msg1";
+
+my $test_cf2 = RT::CustomField->new(RT->SystemUser);
+my ($cf2_id,$msg2) = $test_cf2->Create(ObjectId => 0, Name => 'Test Field 2', Type => 'Freeform', MaxValues => 1, LookupType => 'RT::Queue', Description => 'Second queue test field');
+ok $cf2_id, "Created custom field 2 $msg2";
+
+my ($value1_id,$msg3) = $test_cf1->AddValueForObject(Object => $general, Content => 'Test A');
+ok $value1_id, "Create Custom Field Value 1";
+my ($value2_id,$msg4) = $test_cf1->AddValueForObject(Object => $test_queue1, Content => 'Test A');
+ok $value2_id, "Create Custom Field Value 2";
+my ($value3_id,$msg5) = $test_cf2->AddValueForObject(Object => $test_queue2, Content => 'Test B');
+ok $value3_id, "Create Custom Field Value 3";
+
+use_ok 'RT::Report::Tickets';
+
+diag "Test A search";
+{
+ my $report = RT::Report::Tickets->new(RT->SystemUser);
+ my %columns = $report->SetupGroupings(
+ Query => "'QueueCF.{Test Field 1}' = 'Test A'",
+ GroupBy => ['Status'],
+ Function => ['COUNT'],
+ );
+ $report->SortEntries;
+ my %table = $report->FormatTable(%columns);
+ is $table{tbody}[0]{cells}[0]{value},'new', "Test A new tickets";
+ is $table{tbody}[0]{cells}[1]{value},2, "Test A 2 new tickets";
+ is $table{tbody}[1]{cells}[0]{value},'open', "Test A open tickets";
+ is $table{tbody}[1]{cells}[1]{value},3, "Test A 3 open tickets";
+
+}
+
+diag "Test B search";
+{
+ my $report = RT::Report::Tickets->new(RT->SystemUser);
+ my %columns = $report->SetupGroupings(
+ Query => "'QueueCF.{Test Field 2}' = 'Test B'",
+ GroupBy => ['Status'],
+ Function => ['COUNT'],
+ );
+ $report->SortEntries;
+ my %table = $report->FormatTable(%columns);
+ is $table{tbody}[0]{cells}[0]{value},'new', "Test B new tickets";
+ is $table{tbody}[0]{cells}[1]{value},1, "Test B 1 new tickets";
+}
+
+done_testing;
+
+sub create_tickets {
+ my (@tix) = @_;
+ my @res = ();
+ for (@tix) {
+ my $t = RT::Ticket->new($RT::SystemUser);
+ my ($id, undef, $msg) = $t->Create(Queue => $_->{Queue}->id, Subject => $_->{Subject}, Status => $_->{Status});
+ ok($id, "ticket created" ) or diag("error: $msg");
+ is $t->Status, $_->{'Status'}, 'correct status';
+ push @res, $t;
+ }
+ return @res;
+}
+
-----------------------------------------------------------------------
More information about the rt-commit
mailing list