[Rt-commit] rt branch, 4.4/txn-string-fields-in-ticket-sql, created. rt-4.4.4-293-g7aff6174ea
? sunnavy
sunnavy at bestpractical.com
Tue Mar 23 16:15:39 EDT 2021
The branch, 4.4/txn-string-fields-in-ticket-sql has been created
at 7aff6174ea32ec8db634f3e925c8e4a63bdb8d09 (commit)
- Log -----------------------------------------------------------------
commit addb23cbe79254fad5efde6d0603a4b2a976fa4d
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Mar 24 03:38:26 2021 +0800
Support Transaction Type/Field/OldValue/NewValue limits in TicketSQL
This is initially to search tickets that got reassigned to current user
on previous day, the SQL is like:
Updated = 'yesterday' AND TransactionType = 'Set' AND
TransactionField = 'Owner' AND TransactionNewValue = '__CurrentUser__'
With this, people can search more transaction things in ticket search,
which could be very useful.
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index e094c63ef6..4879f27008 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -167,6 +167,10 @@ our %FIELD_METADATA = (
WatcherGroup => [ 'MEMBERSHIPFIELD', ], #loc_left_pair
HasAttribute => [ 'HASATTRIBUTE', 1 ],
HasNoAttribute => [ 'HASATTRIBUTE', 0 ],
+ TransactionType => [ 'TRANSSTRING', 'Type' ], #loc_left_pair
+ TransactionField => [ 'TRANSSTRING', 'Field' ], #loc_left_pair
+ TransactionOldValue => [ 'TRANSSTRING', 'OldValue' ], #loc_left_pair
+ TransactionNewValue => [ 'TRANSSTRING', 'NewValue' ], #loc_left_pair
);
# Lower Case version of FIELDS, for case insensitivity
@@ -197,6 +201,7 @@ our %dispatch = (
CUSTOMFIELD => \&_CustomFieldLimit,
HASATTRIBUTE => \&_HasAttributeLimit,
LIFECYCLE => \&_LifecycleLimit,
+ TRANSSTRING => \&_TransStringLimit,
);
# Default EntryAggregator per type
@@ -841,6 +846,43 @@ sub _TransCreatorLimit {
$sb->Limit( ALIAS => $txn_alias, FIELD => 'Creator', OPERATOR => $op, VALUE => $value, @rest );
}
+=head2 _TransStringLimit
+
+Handle transaction string fields. e.g. (Type, Field, OldValue, NewValue)
+
+=cut
+
+sub _TransStringLimit {
+ my ( $sb, $field, $op, $value, @rest ) = @_;
+
+ my $meta = $RT::Tickets::FIELD_METADATA{$field};
+ die "Incorrect Meta Data for $field" unless defined $meta->[1];
+
+ if ( RT->Config->Get('DatabaseType') eq 'Oracle'
+ && ( !defined $value || !length $value )
+ && lc($op) ne 'is'
+ && lc($op) ne 'is not' )
+ {
+ if ( $op eq '!=' || $op =~ /^NOT\s/i ) {
+ $op = 'IS NOT';
+ }
+ else {
+ $op = 'IS';
+ }
+ $value = 'NULL';
+ }
+
+ my $txn_alias = $sb->JoinTransactions;
+ $sb->Limit(
+ ALIAS => $txn_alias,
+ FIELD => $meta->[1],
+ OPERATOR => $op,
+ VALUE => $value,
+ CASESENSITIVE => 0,
+ @rest,
+ );
+}
+
=head2 _TransLimit
Limit based on the ContentType or the Filename of a transaction.
commit d3c2a57ff87b47fc132d60c3d812ae028994e3ae
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Mar 24 03:44:52 2021 +0800
Test Transaction Type/Field/OldValue/NewValue in TicketSQL
diff --git a/t/ticket/search_by_txn.t b/t/ticket/search_by_txn.t
index 6f970aadc0..e8c2a0b53c 100644
--- a/t/ticket/search_by_txn.t
+++ b/t/ticket/search_by_txn.t
@@ -5,7 +5,7 @@ use strict;
BEGIN{ $ENV{'TZ'} = 'GMT'};
-use RT::Test tests => 10;
+use RT::Test tests => undef;
my $SUBJECT = "Search test - ".$$;
@@ -32,3 +32,14 @@ is($txnobj->CreatedObj->ISO,'2005-08-05 20:00:56');
$tix->FromSQL(qq{Updated = "2005-08-05" AND Subject = "$SUBJECT"});
is( $tix->Count, 1);
+$tix->FromSQL(qq{TransactionType = 'Comment' AND Subject = "$SUBJECT"});
+is( $tix->Count, 1);
+
+ok( $ticket->SetStatus('open') );
+
+$tix->FromSQL(
+ qq{TransactionType = 'Status' AND TransactionField = 'Status' AND TransactionOldValue = 'new' AND TransactionNewValue = 'open' AND Subject = "$SUBJECT"}
+);
+is( $tix->Count, 1, 'Found ticket with Transaction Type/Field/OldValue/NewValue' );
+
+done_testing;
commit b668be519990475db34aa0eb84112586018fb9c6
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Mar 24 03:50:03 2021 +0800
Add TransactionCreated/TransactionCreator in TicketSQL for consistency
Both fields are already supported in TicketSQL, with different
names("Updated" and "UpdatedBy"). As we have TransactionType,
TransactionField, etc. it's natural to have TransactionCreated and
TransactionCreator.
diff --git a/lib/RT/Tickets.pm b/lib/RT/Tickets.pm
index 4879f27008..c1e80a57d6 100644
--- a/lib/RT/Tickets.pm
+++ b/lib/RT/Tickets.pm
@@ -159,7 +159,9 @@ our %FIELD_METADATA = (
QueueCF => [ 'CUSTOMFIELD' => 'Queue' ], #loc_left_pair
Lifecycle => [ 'LIFECYCLE' ], #loc_left_pair
Updated => [ 'TRANSDATE', ], #loc_left_pair
+ TransactionCreated => [ 'TRANSDATE', ], #loc_left_pair
UpdatedBy => [ 'TRANSCREATOR', ], #loc_left_pair
+ TransactionCreator => [ 'TRANSCREATOR', ], #loc_left_pair
OwnerGroup => [ 'MEMBERSHIPFIELD' => 'Owner', ], #loc_left_pair
RequestorGroup => [ 'MEMBERSHIPFIELD' => 'Requestor', ], #loc_left_pair
CCGroup => [ 'MEMBERSHIPFIELD' => 'Cc', ], #loc_left_pair
commit 7aff6174ea32ec8db634f3e925c8e4a63bdb8d09
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Mar 24 03:54:13 2021 +0800
Test Transaction Created/Creator in TicketSQL
diff --git a/t/ticket/search_by_txn.t b/t/ticket/search_by_txn.t
index e8c2a0b53c..6209bf4989 100644
--- a/t/ticket/search_by_txn.t
+++ b/t/ticket/search_by_txn.t
@@ -32,6 +32,11 @@ is($txnobj->CreatedObj->ISO,'2005-08-05 20:00:56');
$tix->FromSQL(qq{Updated = "2005-08-05" AND Subject = "$SUBJECT"});
is( $tix->Count, 1);
+$tix->FromSQL( qq{TransactionCreated = "2005-08-05" AND TransactionCreator = }
+ . RT->SystemUser->Id
+ . qq{ AND Subject = "$SUBJECT"} );
+is( $tix->Count, 1, 'Found ticket with Transaction Created/Creator' );
+
$tix->FromSQL(qq{TransactionType = 'Comment' AND Subject = "$SUBJECT"});
is( $tix->Count, 1);
-----------------------------------------------------------------------
More information about the rt-commit
mailing list