[Rt-commit] rt branch, 4.0/fix-initialdata-basedon-cf, created. rt-4.0.5-114-gd632101

Emannuel Lacour elacour at bestpractical.com
Mon Apr 2 11:58:03 EDT 2012


The branch, 4.0/fix-initialdata-basedon-cf has been created
        at  d632101a84e874c77486f4d79dd27bc9bc5f6e31 (commit)

- Log -----------------------------------------------------------------
commit d632101a84e874c77486f4d79dd27bc9bc5f6e31
Author: Emmanuel Lacour <elacour at easter-eggs.com>
Date:   Mon Apr 2 17:56:34 2012 +0200

    Fix insertion of BasedOn CF with initialdata
    
        BasedOn is no longer an attribute in RT4, it's a dedicated field
        that can be used at CustomField creation time.

diff --git a/lib/RT/Handle.pm b/lib/RT/Handle.pm
index 4955bb7..e467402 100644
--- a/lib/RT/Handle.pm
+++ b/lib/RT/Handle.pm
@@ -860,26 +860,22 @@ sub InsertData {
                 @queues = @{ delete $item->{'Queue'} };
             }
 
-            my ( $return, $msg ) = $new_entry->Create(%$item);
-            unless( $return ) {
-                $RT::Logger->error( $msg );
-                next;
-            }
-
             if ( $item->{'BasedOn'} ) {
                 my $basedon = RT::CustomField->new($RT::SystemUser);
                 my ($ok, $msg ) = $basedon->LoadByCols( Name => $item->{'BasedOn'},
-                                                        LookupType => $new_entry->LookupType );
+                                                        LookupType => $item->{'LookupType'} );
                 if ($ok) {
-                    ($ok, $msg) = $new_entry->SetBasedOn( $basedon );
-                    if ($ok) {
-                        $RT::Logger->debug("Added BasedOn $item->{BasedOn}: $msg");
-                    } else {
-                        $RT::Logger->error("Failed to add basedOn $item->{BasedOn}: $msg");
-                    }
+                    $item->{'BasedOn'} = $basedon->Id;
                 } else {
-                    $RT::Logger->error("Unable to load $item->{BasedOn} as a $item->{LookupType} CF.  Skipping BasedOn");
+                    $RT::Logger->error("Unable to load $item->{BasedOn} as a $item->{LookupType} CF.  Skipping BasedOn: $msg");
+                    delete $item->{'BasedOn'};
                 }
+            } 
+
+            my ( $return, $msg ) = $new_entry->Create(%$item);
+            unless( $return ) {
+                $RT::Logger->error( $msg );
+                next;
             }
 
             foreach my $value ( @{$values} ) {

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


More information about the Rt-commit mailing list