[Rt-devel] PATCH 3.6 - Make search config fields mutable
Todd Chapman
todd at chaka.net
Mon Jul 31 22:53:16 EDT 2006
Same patch but with a small, unrelated POD fix.
-------------- next part --------------
==== Patch <tickets> level 1
Source: 6fc35107-3207-0410-b21e-9a2d7f624572:/local/bp/rt/features/3.6_mutable_search_fields:8060
Target: e417ac7c-1bcc-0310-8ffa-8f5827389a85:/rt/branches/3.6-RELEASE:5658
(svn://svn.bestpractical.com)
Log:
r8058 at slah001: root | 2006-07-31 21:56:10 -0400
Make it easier to extend searching.
r8059 at slah001: root | 2006-07-31 22:07:33 -0400
Make search configuration fields mutable.
r8060 at slah001: root | 2006-07-31 22:40:00 -0400
Small POD fix.
=== lib/t/regression/12-search.t
==================================================================
--- lib/t/regression/12-search.t (revision 5658)
+++ lib/t/regression/12-search.t (patch tickets level 1)
@@ -6,7 +6,7 @@
use strict;
use warnings;
-use Test::More tests => 44;
+use Test::More tests => 87;
use_ok('RT');
RT::LoadConfig();
RT::Init();
@@ -264,3 +264,83 @@
$tix->FromSQL("CF.SearchTest = 'foo1' OR CF.SearchTest = 'foo3' OR CF.SearchTest2 = 'bar1' OR CF.SearchTest2 = 'bar2'");
is($tix->Count, 3, "is cf1 or is cf1 or is cf2 or is cf2");
+# test class methods
+{
+# _mutable_hash
+my $hashref = { This => 1, That => 2 };
+is( RT::Tickets->_mutable_hash( $hashref ), $hashref, "returns hashref");
+is( RT::Tickets->_mutable_hash( $hashref, 'Unknown' ), undef, "unknown field returns undef");
+is( RT::Tickets->_mutable_hash( $hashref, 1 ), undef, "returns undef");
+is( RT::Tickets->_mutable_hash( $hashref, [] ), undef, "returns undef");
+is( RT::Tickets->_mutable_hash( $hashref, 'This' ), 1, "returns value");
+my $old_value = RT::Tickets->_mutable_hash( $hashref, 'This', 3 );
+is( $old_value, 1, "got old value");
+is( RT::Tickets->_mutable_hash( $hashref, 'This' ), 3, "got new value");
+$old_value = RT::Tickets->_mutable_hash( $hashref, 'This', undef );
+is( $old_value, 3, "got old value");
+is( RT::Tickets->_mutable_hash( $hashref, 'This' ), undef, "got new value");
+}
+
+{
+# FIELDS()
+is(ref(RT::Tickets->FIELDS()), 'HASH', "FIELDS() returns hashref");
+is(RT::Tickets->FIELDS('random_junk_xzy'), undef, "Unknown field name returns undef");
+is(ref(RT::Tickets->FIELDS('id')), 'ARRAY', "Known field name returns hashref");
+is(RT::Tickets->FIELDS('id')->[0], 'INT', "Known field name returns hashref");
+my $old_value = RT::Tickets->FIELDS('Owner');
+is($old_value->[0], 'WATCHERFIELD', "Known field name returns hashref");
+is($old_value->[1], 'Owner', "Known field name returns hashref");
+my $new_value = [ 'ENUM' => 'User' ];
+my $value = RT::Tickets->FIELDS('Owner', $new_value);
+is($value->[0], 'WATCHERFIELD', "Old value is returned");
+is($value->[1], 'Owner', "Old value is returned");
+$value = RT::Tickets->FIELDS('Owner');
+is($value->[0], 'ENUM', "New value is set");
+is($value->[1], 'User', "New value is set");
+$value = RT::Tickets->FIELDS('Owner', undef);
+is($value->[0], 'ENUM', "Old value is returned");
+is($value->[1], 'User', "Old value is returned");
+$value = RT::Tickets->FIELDS('Owner');
+is($value, undef, "Value is deleted");
+$value = RT::Tickets->FIELDS('Owner', $old_value);
+is($value->[0], undef, "Old value is returned");
+$value = RT::Tickets->FIELDS('Owner');
+is($value->[0], 'WATCHERFIELD', "Old value is restored");
+is($value->[1], 'Owner', "Old value is restored");
+RT::Tickets->FIELDS('Owner', { 'This should' => 'not work' });
+$value = RT::Tickets->FIELDS('Owner');
+is($value->[0], 'WATCHERFIELD', "Old value is restored");
+is($value->[1], 'Owner', "Old value is restored");
+}
+
+{
+# dispatch
+is(ref(RT::Tickets->dispatch()), 'HASH', "dispatch() returns hashref");
+is(RT::Tickets->dispatch('random_junk_xzy'), undef, "Unknown field type returns undef");
+is(ref(RT::Tickets->dispatch('INT')), 'CODE', "Known field type returns coderef");
+my $old_value = RT::Tickets->dispatch('INT');
+is($old_value, \&RT::Tickets::_IntLimit, "Known field type returns coderef");
+my $new_value = \&RT::Tickets::_StringLimit;
+my $value = RT::Tickets->dispatch('INT', $new_value);
+is($value, \&RT::Tickets::_IntLimit, "Old value is returned");
+$value = RT::Tickets->dispatch('INT');
+is($value, \&RT::Tickets::_StringLimit, "New value is set");
+$value = RT::Tickets->dispatch('INT', undef);
+is($value, \&RT::Tickets::_StringLimit, "Old value is returned");
+$value = RT::Tickets->dispatch('INT');
+is($value, undef, "Value is deleted");
+$value = RT::Tickets->dispatch('INT', $old_value);
+is($value, undef, "Old value is returned");
+$value = RT::Tickets->dispatch('INT');
+is($value, \&RT::Tickets::_IntLimit, "Old value is restored");
+RT::Tickets->dispatch('INT', { 'This should' => 'not work' });
+$value = RT::Tickets->dispatch('INT');
+is($value, \&RT::Tickets::_IntLimit, "Old value is restored");
+}
+
+is(ref(RT::Tickets->DefaultEA()), 'HASH', "DefaultEA() returns hashref");
+is( RT::Tickets->DefaultEA('INT'), 'AND', "DefaultEA() returns string");
+is(ref(RT::Tickets->DefaultEA('DATE')), 'HASH', "DefaultEA() returns hashref");
+
+is(ref(RT::Tickets->can_bundle()), 'HASH', "can_bundle() returns hashref");
+is( RT::Tickets->can_bundle('WATCHERFIELD'), 'yes', "can_bundle() returns string");
=== lib/RT/Tickets_Overlay.pm
==================================================================
--- lib/RT/Tickets_Overlay.pm (revision 5658)
+++ lib/RT/Tickets_Overlay.pm (patch tickets level 1)
@@ -202,10 +202,121 @@
# Helper functions for passing the above lexically scoped tables above
# into Tickets_Overlay_SQL.
-sub FIELDS { return \%FIELD_METADATA }
-sub dispatch { return \%dispatch }
-sub can_bundle { return \%can_bundle }
+=head2 FIELDS
+
+With no arguments returns a hash reference which is a mapping of
+searchable Field name, to Type, and other metadata.
+The keys are field names and the values are references to arrays:
+
+RT::Tickets->FIELDS()
+
+With one argument returns the array reference for that field name,
+or undef if it is not found:
+
+RT::Tickets->FIELDS('MyField')
+
+With two arguments sets the field name given in the first argument
+the value in the second argument. The second argument must either
+be an array reference, or undef, in which case the field is deleted
+from the map table:
+
+RT::Tickets->FIELDS('MyField', [ 'INT', ] )
+RT::Tickets->FIELDS('MyField', undef )
+
+For backward compatability FIELDS can be called as a function with
+no arguments, but must be called as a method if passing arguments.
+
+=cut
+
+sub FIELDS {
+
+ my $self = shift;
+
+ if ( @_ == 2 and $_[1] ) {
+ unless ( ref($_[1]) eq 'ARRAY' ) {
+ $RT::Logger->error("Second argument to FIELDS must be an array reference or undef!");
+ pop;
+ }
+ }
+
+ return __PACKAGE__->_mutable_hash(\%FIELD_METADATA, @_);
+}
+
+=head2 dispatch
+
+With no arguments returns a hash reference which is a mapping of
+searchable Field type, to limit function.
+The keys are field types and the values are code references:
+
+RT::Tickets->dispatch()
+
+With one argument returns the code reference for that field type,
+or undef if it is not found:
+
+RT::Tickets->dispatch(INT)
+
+With two arguments sets the field type given in the first argument
+the value in the second argument. The second argument must either
+be an code reference, or undef, in which case the field is deleted
+from the map table:
+
+RT::Tickets->dispatch(INT => \&_IntLimit)
+RT::Tickets->dispatch(INT => undef )
+
+=cut
+
+sub dispatch {
+
+ my $self = shift;
+
+ if ( @_ == 2 and $_[1] ) {
+ unless ( ref($_[1]) eq 'CODE' ) {
+ $RT::Logger->error("Second argument to dispatch must be a code reference or undef!");
+ pop;
+ }
+ }
+
+ return __PACKAGE__->_mutable_hash(\%dispatch, @_);
+}
+
+sub can_bundle {
+
+ my $self = shift;
+ return __PACKAGE__->_mutable_hash(\%can_bundle, @_);
+
+}
+
+=head2 DefaultEA
+
+With no arguments returns a hash reference which is a mapping of
+searchable Field type, to its default Entry aggregator.
+The keys are field types and the values strings or hash references:
+
+RT::Tickets->DefaultEA()
+
+With one argument returns the string or hash reference for that
+field type, or undef if it is not found:
+
+RT::Tickets->DefaultEA(INT)
+
+With two arguments sets the field type given in the first argument
+the value in the second argument. The second argument must either
+be a string, hash reference, or undef, in which case the field is
+deleted from the map table:
+
+RT::Tickets->DefaultEA(LINK => 'OR')
+RT::Tickets->DefaultEA(LINK => undef )
+
+=cut
+
+sub DefaultEA {
+
+ my $self = shift;
+ return __PACKAGE__->_mutable_hash(\%DefaultEA, @_);
+
+}
+
# Bring in the clowns.
require RT::Tickets_Overlay_SQL;
@@ -2889,6 +3000,33 @@
$self->RedoSearch();
}
+sub _mutable_hash {
+
+ my $self = shift;
+ my $hashref = shift;
+
+ unless ( ref($hashref) eq 'HASH' ) {
+ $RT::Logger->error("The first argument to _mutable must be a hash reference!");
+ return undef;
+ }
+
+ if ( @_ == 1 ) {
+ return $hashref->{ $_[0] };
+ }
+ elsif ( @_ == 2 ) {
+ my $old_value = $hashref->{ $_[0] };
+ if ( $_[1] ) {
+ $hashref->{ $_[0] } = $_[1];
+ }
+ else {
+ delete $hashref->{ $_[0] };
+ }
+ return $old_value;
+ }
+
+ return $hashref;
+}
+
=head1 FLAGS
RT::Tickets supports several flags which alter search behavior:
@@ -2914,6 +3052,8 @@
=end testing
+=cut
+
1;
==== BEGIN SVK PATCH BLOCK ====
Version: svk 1.07 (linux)
eJzdWs1u28oV9q4Aga7vopu5jhLZF5LNH5H6CSxYiJUmiGMHtpKgSAJiRI4k1hTpcig7ahggt/Wy
6266vK9wu+i6fYO+RN+iPTP8pyhLSuLgooIgU+SZ73znzMx3ZsZ67A0eHkpBtysGFUkMzl8963Re
YN+Y3JcaQUULiGn5rldRA5tcEbuiBLY7rjQCB08JPKXuzDPYhY+9MfHZhWVcEL/blQCuFcL1OUQM
y1GH2HcdWmlzeN33CKlIQfOwFRwq7K1XpHZACTzhsLpHrixquQ44bomaCBZgLkFz95I4uue6PjxR
taZyKLO2YmDYLiU6A4c7hyozlysQELc3LY8YwGjOorGGHCpqzl2rUfPUDiwYMY6jlOCoDGff514i
JG6rldhq3PZskDVe6lZO6DdKoKQQy9/3yNgjlGeIEVyFqiSoapzDkWWTitxawNuX5Dol2DMmez5n
sQq7EWLzp/jy0p7rPnnvm8T2MfenyIE2NDTZHGpDkciEmGobviiiaWqkaYgt1ag0NIjs/NXJ1ta/
fvjPd7/+yd368futP23981c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VaKMroqoRyVqEnMuN79wDRXfMf+VZ4qGrFpTppzEMXT
u6VYCZNFVedZWWzH0JhtUWEjTqSAEA7P2wl8XAg94f6wRL1jrHA8StDbQvkmNdwJGmZLG45kVSNk
KMG71RDbQ7FBlLapYrXBf30iN7QAeS1RbR1SG09EUeqAOxekJECyKGp1sVlXJCRLHVXrSCKqiw1R
FNBzfEGY7BBMLdiuweCAfSiBuR4qL0zqPYHDtm+HlTtis6MoOdgQAmqeM7LGMw/ztTuf9RRFIzAE
18RV4A2xIyacz6ewwEcvTo8A7P2eUGlGvxii3a4cVGQ5/MnQgP/up9N56YD8eRTb97UA9uVQGCcV
JfDIFXyZzSyz0mgG+7YLm4b94eW+5++PCIZOInRf2dOSaRzGoofso98QVRQt0EaGokqMpwwfYkMS
60NZIvU2ls3mSJMbalPu7srBMudyI2A+hx52jEnos37WP+73zvv8EEFtMS+kITWx0TTq0tAw6qIC
XlqjEYYPtSU3lVYbt9RKq70Wm86GwXZYqP8DocqMSw==
==== END SVK PATCH BLOCK ====
More information about the Rt-devel
mailing list