[Rt-commit] r3679 - in rt/branches/CHALDEA-EXPERIMENTAL: . lib/RT
lib/t/regression
jesse at bestpractical.com
jesse at bestpractical.com
Thu Aug 18 16:32:08 EDT 2005
Author: jesse
Date: Thu Aug 18 16:32:07 2005
New Revision: 3679
Added:
rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/22search_tix_by_txn.t
Modified:
rt/branches/CHALDEA-EXPERIMENTAL/ (props changed)
rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm
Log:
r13201 at hualien: jesse | 2005-08-18 14:27:20 -0400
r7399 at hualien: jesse | 2005-08-05 19:16:58 -0400
* Cleaned up searching by ticket or txn date.
Modified: rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm
==============================================================================
--- rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm (original)
+++ rt/branches/CHALDEA-EXPERIMENTAL/lib/RT/Tickets_Overlay.pm Thu Aug 18 16:32:07 2005
@@ -450,18 +450,11 @@
die "Incorrect Meta Data for $field"
unless ( defined $meta->[1] );
- require Time::ParseDate;
use POSIX 'strftime';
-
- # XXX TODO FIXME: Replace me with RT::Date( Type => 'unknown' ...)
- my $time = Time::ParseDate::parsedate(
- $value,
- UK => $RT::DateDayBeforeMonth,
- PREFER_PAST => $RT::AmbiguousDayInPast,
- PREFER_FUTURE => !($RT::AmbiguousDayInPast),
- FUZZY => 1,
- GMT => 1,
- );
+
+ my $date = RT::Date->new($sb->CurrentUser);
+ $date->Set(Format => 'unknown', Value => $value);
+ my $time = $date->Unix;
if ( $op eq "=" ) {
@@ -548,28 +541,67 @@
# See the comments for TransLimit, they apply here too
$sb->{_sql_transalias} = $sb->NewAlias('Transactions')
- unless defined $sb->{_sql_transalias};
+ unless defined $sb->{_sql_transalias};
$sb->{_sql_trattachalias} = $sb->NewAlias('Attachments')
- unless defined $sb->{_sql_trattachalias};
+ unless defined $sb->{_sql_trattachalias};
+
+ my $date = RT::Date->new( $sb->CurrentUser );
+ $date->Set( Format => 'unknown', Value => $value );
+ my $time = $date->Unix;
- # Join Transactions To Attachments
$sb->_OpenParen;
+ if ( $op eq "=" ) {
- #Search for the right field
- $sb->_SQLLimit(
- ALIAS => $sb->{_sql_trattachalias},
- FIELD => 'Created',
- OPERATOR => $op,
- VALUE => $value,
- CASESENSITIVE => 0,
- @rest
- );
+ # if we're specifying =, that means we want everything on a
+ # particular single day. in the database, we need to check for >
+ # and < the edges of that day.
+
+ my $daystart = strftime( "%Y-%m-%d %H:%M",
+ gmtime( $time - ( $time % 86400 ) ) );
+ my $dayend = strftime( "%Y-%m-%d %H:%M",
+ gmtime( $time + ( 86399 - $time % 86400 ) ) );
+
+ $sb->_SQLLimit(
+ ALIAS => $sb->{_sql_transalias},
+ FIELD => 'Created',
+ OPERATOR => ">=",
+ VALUE => $daystart,
+ CASESENSITIVE => 0,
+ @rest
+ );
+ $sb->_SQLLimit(
+ ALIAS => $sb->{_sql_transalias},
+ FIELD => 'Created',
+ OPERATOR => "<=",
+ VALUE => $dayend,
+ CASESENSITIVE => 0,
+ @rest,
+ ENTRYAGGREGATOR => 'AND',
+ );
+
+ }
+
+ # not searching for a single day
+ else {
+
+ #Search for the right field
+ $sb->_SQLLimit(
+ ALIAS => $sb->{_sql_transalias},
+ FIELD => 'Created',
+ OPERATOR => $op,
+ VALUE => $value,
+ CASESENSITIVE => 0,
+ @rest
+ );
+ }
+
+ # Join Transactions To Attachments
$sb->_SQLJoin(
ALIAS1 => $sb->{_sql_trattachalias},
FIELD1 => 'TransactionId',
- ALIAS2 => $sb->{_transalias},
- FIELD2 => 'id'
+ ALIAS2 => $sb->{_sql_transalias},
+ FIELD2 => 'id',
);
# Join Transactions to Tickets
@@ -586,10 +618,6 @@
VALUE => 'RT::Ticket'
);
- my $d = new RT::Date( $sb->CurrentUser );
- $d->Set( Format => 'ISO', Value => $value );
- $value = $d->ISO;
-
$sb->_CloseParen;
}
Added: rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/22search_tix_by_txn.t
==============================================================================
--- (empty file)
+++ rt/branches/CHALDEA-EXPERIMENTAL/lib/t/regression/22search_tix_by_txn.t Thu Aug 18 16:32:07 2005
@@ -0,0 +1,32 @@
+#use Test::More tests => 26;
+use Test::More qw/no_plan/;
+
+use RT;
+RT::LoadConfig();
+RT::Init();
+
+my $SUBJECT = "Search test - ".$$;
+
+use_ok('RT::Tickets');
+my $tix = RT::Tickets->new($RT::SystemUser);
+can_ok($tix, 'FromSQL');
+$tix->FromSQL('Updated = "2005-08-05" AND Subject = "$SUBJECT"');
+
+ok(! $tix->Count, "Searching for tickets updated on a random date finds nothing" . $tix->Count);
+
+my $ticket = RT::Ticket->new($RT::SystemUser);
+$ticket->Create(Queue => 'General', Subject => $SUBJECT);
+ok ($ticket->id, "We created a ticket");
+my ($id, $txnid, $txnobj) = $ticket->Comment( Content => 'A comment that happend on 2004-01-01');
+
+isa_ok($txnobj, 'RT::Transaction');
+
+ok($txnobj->CreatedObj->ISO);
+my ( $sid,$smsg) = $txnobj->__Set(Field => 'Created', Value => '2005-08-05 20:00:56');
+ok($sid,$smsg);
+is($txnobj->Created,'2005-08-05 20:00:56');
+is($txnobj->CreatedObj->ISO,'2005-08-05 20:00:56');
+
+$tix->FromSQL(qq{Updated = "2005-08-05" AND Subject = "$SUBJECT"});
+is( $tix->Count, 1);
+1;
More information about the Rt-commit
mailing list