Changeset 76


Ignore:
Timestamp:
05/09/09 19:45:21 (15 years ago)
Author:
nanardon
Message:
  • perform delete once, and at beginning
File:
1 edited

Legend:

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

    r74 r76  
    101101 
    102102sub _traverse { 
    103     my ($self, $attr_cb, %options) = @_; 
     103    my ($self, $callback) = @_; 
    104104     
    105105    # listing existing obj one time: 
     
    116116        warn "Sync objects $otype\n"; 
    117117        foreach my $destbase (@obj_dest_base) { 
     118            $callback->($otype, $destbase); 
     119        } 
     120    } 
     121} 
     122 
     123sub _traverse_update { 
     124    my ($self, %options) = @_; 
     125    $self->_traverse( 
     126        sub { 
     127            my ($otype, $destbase) = @_; 
    118128            my @lobjfrom = $self->from->list_objects_from_rev( 
    119129                $otype, 
     
    121131            ); 
    122132            warn "objects $otype " . $self->from->label . " => " . $destbase->label . "\n"; 
    123             my @common_fields = $attr_cb->($self->from, $destbase, $otype) or next; 
     133            my @common_fields = $options{attr_cb}->($self->from, $destbase, $otype) or return; 
    124134            warn "Synching fields: " . join(', ', sort @common_fields) . "\n"; 
    125135            my %exists = map { $_ => 1 } $destbase->list_objects($otype); 
     
    137147                } 
    138148            } 
     149        } 
     150    ); 
     151} 
     152 
     153sub _traverse_delete { 
     154    my ($self, %options) = @_; 
     155    $self->_traverse( 
     156        sub { 
     157            my ($otype, $destbase) = @_; 
     158            my %exists = map { $_ => 1 } $destbase->list_objects($otype); 
    139159            my %srcexists = map { $_ => 1 } $self->from->list_objects($otype); 
    140160            foreach (keys %exists) { 
     
    145165            } 
    146166        } 
    147     } 
     167    ); 
    148168} 
    149169 
     
    160180 
    161181    my %delayed; 
    162     $self->_traverse( 
    163         sub { 
     182    $self->_traverse_delete; 
     183    $self->_traverse_update( 
     184        attr_cb => sub { 
    164185            my ($from, $to, $otype) = @_; 
    165186            my %fields = (); 
     
    179200        }, 
    180201    ); 
    181     $self->_traverse( 
    182         sub { 
     202    $self->_traverse_update( 
     203        attr_cb => sub { 
    183204            my ($from, $to, $otype) = @_; 
    184205            my %fields = (); 
Note: See TracChangeset for help on using the changeset viewer.