[Rt-commit] rt branch, 4.0/attributes-in-initialdata, created. rt-4.0.19-72-g7960a28

Alex Vandiver alexmv at bestpractical.com
Wed Apr 9 17:51:37 EDT 2014


The branch, 4.0/attributes-in-initialdata has been created
        at  7960a280e99310cd31c72ed63c1491db244827d1 (commit)

- Log -----------------------------------------------------------------
commit 7960a280e99310cd31c72ed63c1491db244827d1
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Wed Apr 9 17:51:30 2014 -0400

    Allow attributes to be set after object creation

diff --git a/docs/initialdata.pod b/docs/initialdata.pod
index 11069df..1c7e25c 100644
--- a/docs/initialdata.pod
+++ b/docs/initialdata.pod
@@ -70,8 +70,10 @@ descriptions of the values to place in them, is below.
 
 Each hashref in C<@Users> is treated as a new user to create and passed
 straight into C<< RT::User->Create >>.  All of the normal user fields are
-available, as well as C<Privileged> and C<Disabled> (both booleans) which will
-do the appropriate internal group/flag handling.
+available, as well as C<Privileged> and C<Disabled> (both booleans) which
+will do the appropriate internal group/flag handling.  Also accepts an
+C<Attributes> key, which is equivalent to pushing its arrayref of values
+onto C<@Attributes>, below, with C<Object> set to the new user.
 
 For a full list of fields, read the documentation for L<RT::User/Create>.
 
@@ -94,6 +96,10 @@ array ref.  Each value should be a user-defined group name or hashref to
 pass into L<RT::Group/LoadByCols>.  Each group found will have the new
 group added as a member.
 
+It also accepts an C<Attributes> key, which is equivalent to pushing its
+arrayref of values onto C<@Attributes>, below, with C<Object> set to the
+new group.
+
 =head2 C<@Queues>
 
     push @Queues, {
@@ -103,7 +109,10 @@ group added as a member.
     };
 
 Creates a new L<RT::Queue> for each hashref.  Refer to the documentation of
-L<RT::Queue/Create> for the fields you can use.
+L<RT::Queue/Create> for the fields you can use.  It also accepts an
+C<Attributes> key, which is equivalent to pushing its arrayref of values
+onto C<@Attributes>, below, with C<Object> set to the new queue.
+
 
 =head2 C<@CustomFields>
 
@@ -238,6 +247,10 @@ The regular expression text (not C<qr//>!) used to validate values.
 
 =back
 
+It also accepts an C<Attributes> key, which is equivalent to pushing its
+arrayref of values onto C<@Attributes>, below, with C<Object> set to the
+new custom field.
+
 Refer to the documentation and implementation of L<RT::CustomField/Create> and
 L<RT::CustomFieldValue/Create> for the full list of available fields and
 allowed values.
diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index e6ecdda..89ce387 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -789,6 +789,7 @@ sub InsertData {
     if ( @Groups ) {
         $RT::Logger->debug("Creating groups...");
         foreach my $item (@Groups) {
+            my $attributes = delete $item->{ Attributes };
             my $new_entry = RT::Group->new( RT->SystemUser );
             $item->{Domain} ||= 'UserDefined';
             my $member_of = delete $item->{'MemberOf'};
@@ -799,6 +800,8 @@ sub InsertData {
                 next;
             } else {
                 $RT::Logger->debug($return .".");
+                $_->{Object} = $new_entry for @{$attributes || []};
+                push @Attributes, @{$attributes || []};
             }
             if ( $member_of ) {
                 $member_of = [ $member_of ] unless ref $member_of eq 'ARRAY';
@@ -846,12 +849,15 @@ sub InsertData {
             if ( $item->{'Name'} eq 'root' && $root_password ) {
                 $item->{'Password'} = $root_password;
             }
+            my $attributes = delete $item->{ Attributes };
             my $new_entry = RT::User->new( RT->SystemUser );
             my ( $return, $msg ) = $new_entry->Create(%$item);
             unless ( $return ) {
                 $RT::Logger->error( $msg );
             } else {
                 $RT::Logger->debug( $return ."." );
+                $_->{Object} = $new_entry for @{$attributes || []};
+                push @Attributes, @{$attributes || []};
             }
         }
         $RT::Logger->debug("done.");
@@ -886,12 +892,15 @@ sub InsertData {
     if ( @Queues ) {
         $RT::Logger->debug("Creating queues...");
         for my $item (@Queues) {
+            my $attributes = delete $item->{ Attributes };
             my $new_entry = RT::Queue->new(RT->SystemUser);
             my ( $return, $msg ) = $new_entry->Create(%$item);
             unless ( $return ) {
                 $RT::Logger->error( $msg );
             } else {
                 $RT::Logger->debug( $return ."." );
+                $_->{Object} = $new_entry for @{$attributes || []};
+                push @Attributes, @{$attributes || []};
             }
         }
         $RT::Logger->debug("done.");
@@ -899,6 +908,7 @@ sub InsertData {
     if ( @CustomFields ) {
         $RT::Logger->debug("Creating custom fields...");
         for my $item ( @CustomFields ) {
+            my $attributes = delete $item->{ Attributes };
             my $new_entry = RT::CustomField->new( RT->SystemUser );
             my $values    = delete $item->{'Values'};
 
@@ -960,6 +970,9 @@ sub InsertData {
                 );
                 $RT::Logger->error( $msg ) unless $return and $OCF->Id;
             }
+
+            $_->{Object} = $new_entry for @{$attributes || []};
+            push @Attributes, @{$attributes || []};
         }
 
         $RT::Logger->debug("done.");

-----------------------------------------------------------------------


More information about the rt-commit mailing list