[Rt-commit] rt branch, 4.2/txn-reference-object-methods, created. rt-4.1.6-244-gbd1c449
Thomas Sibley
trs at bestpractical.com
Wed Feb 13 15:35:57 EST 2013
The branch, 4.2/txn-reference-object-methods has been created
at bd1c449e7f7be83ab85fc784b18935766d1c14da (commit)
- Log -----------------------------------------------------------------
commit bd1c449e7f7be83ab85fc784b18935766d1c14da
Author: Thomas Sibley <trs at bestpractical.com>
Date: Wed Feb 13 12:29:55 2013 -0800
New/OldReferenceObject methods on RT::Transaction
Returns the referenced object itself, rather than calling ->Content on
it like NewValue and OldValue do.
diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index f90e9c9..23dcb93 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -1174,11 +1174,7 @@ sub TicketObj {
sub OldValue {
my $self = shift;
- if ( my $type = $self->__Value('ReferenceType')
- and my $id = $self->__Value('OldReference') )
- {
- my $Object = $type->new($self->CurrentUser);
- $Object->Load( $id );
+ if ( my $Object = $self->OldReferenceObject ) {
return $Object->Content;
}
else {
@@ -1188,11 +1184,7 @@ sub OldValue {
sub NewValue {
my $self = shift;
- if ( my $type = $self->__Value('ReferenceType')
- and my $id = $self->__Value('NewReference') )
- {
- my $Object = $type->new($self->CurrentUser);
- $Object->Load( $id );
+ if ( my $Object = $self->NewReferenceObject ) {
return $Object->Content;
}
else {
@@ -1207,6 +1199,37 @@ sub Object {
return $Object;
}
+=head2 NewReferenceObject
+
+=head2 OldReferenceObject
+
+Returns an object of the class specified by the column C<ReferenceType> and
+loaded with the id specified by the column C<NewReference> or C<OldReference>.
+C<ReferenceType> is assumed to be an L<RT::Record> subclass.
+
+The object may be unloaded (check C<< $object->id >>) if the reference is
+corrupt (such as if the referenced record was improperly deleted).
+
+Returns undef if either C<ReferenceType> or C<NewReference>/C<OldReference> is
+false.
+
+=cut
+
+sub NewReferenceObject { $_[0]->_ReferenceObject("New") }
+sub OldReferenceObject { $_[0]->_ReferenceObject("Old") }
+
+sub _ReferenceObject {
+ my $self = shift;
+ my $which = shift;
+ my $type = $self->__Value("ReferenceType");
+ my $id = $self->__Value("${which}Reference");
+ return unless $type and $id;
+
+ my $object = $type->new($self->CurrentUser);
+ $object->Load( $id );
+ return $object;
+}
+
sub FriendlyObjectType {
my $self = shift;
return $self->loc( $self->Object->RecordType );
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list