Ignore:
Timestamp:
04/25/09 21:18:18 (15 years ago)
Author:
nanardon
Message:
  • support database revision, store current revision, allowing to synch only object changed since last sync
File:
1 edited

Legend:

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

    r45 r49  
    3030our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; 
    3131 
    32 =head2 new($from, $to) 
     32=head2 new($from, $to, %options) 
    3333 
    3434Create a new synchronisation where $from and $to are LATMOS::Accounts::Base 
     
    3838 
    3939sub new { 
    40     my ($class, $from, $to) = @_; 
     40    my ($class, $from, $to, %options) = @_; 
    4141 
    42     my $self = {}; 
     42    if ($options{state_file} && ! -w $options{state_file}) { 
     43        # don't exists, we have to create it 
     44        open(my $handle, '>', $options{state_file}) or return; 
     45        close($handle); 
     46    } 
    4347 
     48    my $self = Config::IniFiles->new( 
     49        $options{state_file} 
     50        ? (-file => $options{state_file}) 
     51        : (), 
     52    ); 
     53 
     54     
    4455    $self->{from} = $from; 
    4556 
     
    105116    $self->load_dest and return; 
    106117     
     118    # tracking current base revision: 
     119    my $current_rev = $self->from->current_rev; 
     120 
    107121    # listing existing obj one time: 
    108122    foreach my $otype ($self->from->list_supported_objects) { 
     
    115129        # loading object list one time for all 
    116130        # TODO optimize this, using rev of objects 
    117         my @lobjfrom = $self->from->list_objects($otype); 
    118131 
    119132        warn "Sync objects $otype\n"; 
    120133        foreach my $destbase (@obj_dest_base) { 
     134            my @lobjfrom = $self->from->list_objects_from_rev( 
     135                $otype, 
     136                $self->val($self->from->label, $destbase->label), 
     137            ); 
    121138            warn "objects $otype => " . $destbase->type . "\n"; 
    122139            my @common_fields = $self->_common_fields($self->from, $destbase, $otype); 
     
    141158 
    142159    foreach ($self->to) { 
    143         $_->commit; 
     160        $_->commit or next; 
     161        $self->newval($self->from->label, $_->label, $current_rev) if($current_rev); 
    144162    } 
    145163 
     164    $self->RewriteConfig if($self->GetFileName); 
     165     
    146166    1; 
    147167} 
Note: See TracChangeset for help on using the changeset viewer.