[Rt-commit] rt branch, 4.0/loadable-object-for-attribute-initialdata, created. rt-4.0.19-62-g0d671fc
Todd Wade
todd at bestpractical.com
Thu Apr 3 09:27:16 EDT 2014
The branch, 4.0/loadable-object-for-attribute-initialdata has been created
at 0d671fcde7ef09cb9f945536fc444685776e637e (commit)
- Log -----------------------------------------------------------------
commit 0d671fcde7ef09cb9f945536fc444685776e637e
Author: Todd Wade <todd at bestpractical.com>
Date: Thu Apr 3 09:19:16 2014 -0400
add a way to give an attribute an ObjectType besides RT::System
This code allows you to provide a code ref in the Object field in
an Attribute initialdata hash that returns an object that can be
used as the ObjectType for the Attribute:
@Attributes = ({
Name => 'SavedSearch',
Description => 'New Tickets in SomeQueue',
Object => sub {
my $GroupName = 'SomeQueue Group';
my $group = RT::Group->new( RT->SystemUser );
my( $ret, $msg ) = $group->LoadUserDefinedGroup( $GroupName );
die $msg unless $ret;
return $group;
},
Content => {
Format => <<' END_OF_FORMAT',
....
END_OF_FORMAT
Query => "Status = 'new' AND Queue = 'SomeQueue'",
OrderBy => 'id',
Order => 'DESC'
},
});
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index e6ecdda..1bac679 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -1105,7 +1105,12 @@ sub InsertData {
my $sys = RT::System->new(RT->SystemUser);
for my $item (@Attributes) {
- my $obj = delete $item->{Object}; # XXX: make this something loadable
+ my $obj = delete $item->{Object};
+
+ if ( ref $obj eq 'CODE' ) {
+ $obj = $obj->();
+ }
+
$obj ||= $sys;
my ( $return, $msg ) = $obj->AddAttribute (%$item);
unless ( $return ) {
-----------------------------------------------------------------------
More information about the rt-commit
mailing list