Ignore:
Timestamp:
04/25/09 10:29:23 (15 years ago)
Author:
nanardon
Message:
  • fix array ref check
File:
1 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm

    r44 r45  
    4646    # allow ref and array ref of, eg 
    4747    # to = $foo and $to = [ $foo, $bar ] 
    48     foreach (ref $to ? @{ $to || []} : ($to)) { 
     48    foreach (ref($to) eq 'ARRAY' ? @{ $to || []} : ($to)) { 
    4949        push(@{$self->{to}}, $_); 
    5050    } 
     
    8282    $self->{to} = \@loaded; 
    8383    return $unloaded; 
    84 } 
    85  
    86 # sync obj $from to $to 
    87 # obj must be L::A::Base::Object based 
    88  
    89 sub _sync_object { 
    90     my ($self, $from, $to) = @_; 
    91     my @common_fields = $self->_common_fields($from, $to); 
    92  
    9384} 
    9485 
     
    129120        foreach my $destbase (@obj_dest_base) { 
    130121            warn "objects $otype => " . $destbase->type . "\n"; 
     122            my @common_fields = $self->_common_fields($self->from, $destbase, $otype); 
    131123            my %exists = map { $_ => 1 } $destbase->list_objects($otype); 
    132124            foreach my $uid (@lobjfrom) { 
    133125                if (!$exists{$uid}) { 
    134                     # TODO cache this: 
    135                     my @common_fields = $self->_common_fields($self->from, $destbase, $otype); 
    136  
    137126                    my $sobj = $self->from->get_object($otype, $uid); 
    138127                    my %fields = map { $_ => $sobj->get_c_field($_) } @common_fields; 
    139128                    $destbase->create_c_object($otype, $uid, %fields); 
    140129                    warn "  $otype $uid: created\n"; 
     130                } else { 
     131                    my $sobj = $self->from->get_object($otype, $uid); 
     132                    my %fields = map { $_ => $sobj->get_c_field($_) } @common_fields; 
     133                    my $dobj = $destbase->get_object($otype, $uid); 
     134                    $dobj->set_c_fields(%fields); 
     135                        
     136                    warn "  $otype $uid: synched\n"; 
    141137                } 
    142138            } 
    143139        } 
     140    } 
     141 
     142    foreach ($self->to) { 
     143        $_->commit; 
    144144    } 
    145145 
Note: See TracChangeset for help on using the changeset viewer.