Changeset 44 for LATMOS-Accounts


Ignore:
Timestamp:
04/25/09 09:23:55 (15 years ago)
Author:
nanardon
Message:
  • LA_NO_COMMIT envirronement variable disable commit/rollback
Location:
LATMOS-Accounts/lib/LATMOS/Accounts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm

    r43 r44  
    112112sub commit { 
    113113    my ($self) = @_; 
     114    if ($ENV{LA_NO_COMMIT}) { return 1 } 
    114115    $self->db->commit; 
    115116} 
     
    117118sub rollback { 
    118119    my ($self) = @_; 
     120    if ($ENV{LA_NO_COMMIT}) { return 1 } 
    119121    $self->db->rollback; 
    120122} 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm

    r41 r44  
    8484} 
    8585 
     86# sync obj $from to $to 
     87# obj must be L::A::Base::Object based 
     88 
     89sub _sync_object { 
     90    my ($self, $from, $to) = @_; 
     91    my @common_fields = $self->_common_fields($from, $to); 
     92 
     93} 
     94 
     95sub _common_fields { 
     96    my ($self, $from, $to, $otype) = @_; 
     97    my %fields = (); 
     98    foreach my $base ($from, $to) { 
     99        foreach ($base->list_canonicals_fields($otype)) { 
     100            $fields{$_} ||= 0; # avoid  
     101            $fields{$_}++; 
     102        } 
     103    } 
     104    # field having value are in both 
     105    grep { $fields{$_} == 2 } keys %fields; 
     106} 
     107 
    86108sub process { 
    87109    my ($self, %options) = @_; 
     
    108130            warn "objects $otype => " . $destbase->type . "\n"; 
    109131            my %exists = map { $_ => 1 } $destbase->list_objects($otype); 
    110             foreach (@lobjfrom) { 
    111                 if (!$exists{$_}) { 
    112                     warn "  $otype $_: created\n"; 
     132            foreach my $uid (@lobjfrom) { 
     133                if (!$exists{$uid}) { 
     134                    # TODO cache this: 
     135                    my @common_fields = $self->_common_fields($self->from, $destbase, $otype); 
     136 
     137                    my $sobj = $self->from->get_object($otype, $uid); 
     138                    my %fields = map { $_ => $sobj->get_c_field($_) } @common_fields; 
     139                    $destbase->create_c_object($otype, $uid, %fields); 
     140                    warn "  $otype $uid: created\n"; 
    113141                } 
    114142            } 
Note: See TracChangeset for help on using the changeset viewer.