Ignore:
Timestamp:
12/02/11 11:42:17 (13 years ago)
Author:
nanardon
Message:
  • reimport missing files from previous svn
File:
1 edited

Legend:

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

    r819 r861  
    124124    $self->load_dest and return; 
    125125    my %state = (); 
    126     $state{$self->from->label} = $self->from->wexported(0); 
     126    $state{$self->from->label} = $self->from->wexported( 
     127        $self->{options}{unexported} ? 1 : 0 
     128    ); 
    127129    foreach ($self->to) { 
    128130        $state{$_->label} = $_->wexported(1); 
     
    137139    la_log(LA_DEBUG, "Leaving synch mode"); 
    138140    $self->from->wexported($state{$self->from->label}); 
    139     foreach ($self->to) { 
    140         $_->commit; 
    141         $_->wexported($state{$_->label}); 
     141    foreach my $base (grep { $_ } $self->to) { 
     142        $base->commit; 
     143        $base->wexported($state{$base->label}); 
    142144    } 
    143145} 
     
    205207 
    206208    $self->lock or return; 
     209     
     210    if (!(my $res = $self->run_pre_synchro({}))) { 
     211        la_log(LA_ERR, "Pre synchro script failed, aborting"); 
     212        $self->unlock; 
     213        return; 
     214    } 
    207215 
    208216    my %state = $self->enter_synch_mode; 
     
    230238                            $self->from->label, $otype, $_, $destbase->label, $res, 
    231239                        ); 
     240                        if ($destbase->is_transactionnal) { 
     241                            $destbase->commit; 
     242                        } 
    232243                        $updated = 1; 
     244                    } else { 
     245                        if ($destbase->is_transactionnal) { 
     246                            $destbase->rollback; 
     247                        } 
    233248                    } 
    234249                } 
     
    241256        } 
    242257        foreach my $pass (1, 0) { 
    243             foreach my $otype ( 
    244                 sort { $a eq 'user' ? 1 : -1 } # user in last because gidNumber needed 
    245                 keys %objlist) { 
    246                 next if (!$pass && !$destbase->delayed_fields($otype)); 
     258            foreach my $otype ($destbase->ordered_objects) { 
     259                exists($objlist{$otype}) or next; 
    247260                foreach (@{$objlist{$otype} || []}) { 
    248261                    my $res = $destbase->sync_object_from($self->from, $otype, $_, 
     
    254267                                $destbase->label, $res, 
    255268                            ); 
     269                            if ($destbase->is_transactionnal) { 
     270                                $destbase->commit; 
     271                            } 
    256272                            $updated = 1; 
    257273                        } 
     
    262278                        ); 
    263279                        $desterror{$destbase->label} = 1; 
     280                        if ($destbase->is_transactionnal) { 
     281                            $destbase->rollback; 
     282                        } 
    264283                    } 
    265284 
     
    272291    my $res = $self->run_post_synchro( 
    273292        { 
    274             UPDATED => $updated, 
     293            UPDATED => $updated || undef, 
    275294        } 
    276295    ); 
     
    313332} 
    314333 
     334sub run_pre_synchro { 
     335    my ($self, $env) = @_; 
     336 
     337    $env ||= {}; 
     338    $env->{HOOK_TYPE} = 'PRE'; 
     339 
     340    foreach my $base ($self->to) { 
     341        if ($base->options('presynchro')) { 
     342            la_log LA_DEBUG, "Executing base pre synchro `%s' for %s", 
     343                $base->options('presynchro'), $base->label; 
     344            exec_command( 
     345                $base->options('presynchro'), 
     346                { 
     347                    BASE => $base->label, 
     348                    BASETYPE => $base->type, 
     349                    %{ $env }, 
     350                } 
     351            ); 
     352        } 
     353    } 
     354 
     355    $self->{options}{pre} or return 1; 
     356 
     357    la_log(LA_DEBUG, "Running post synchro `%s'", $self->{options}{pre}); 
     358 
     359    exec_command($self->{options}{post}, $env); 
     360} 
     361 
    315362sub run_post_synchro { 
    316363    my ($self, $env) = @_; 
     364     
     365    $env ||= {}; 
     366    $env->{HOOK_TYPE} = 'PRE'; 
     367 
     368    foreach my $base ($self->to) { 
     369        if ($base->options('postsynchro')) { 
     370            la_log LA_DEBUG, "Executing base post synchro `%s' for %s", 
     371                $base->options('postsynchro'), $base->label; 
     372            exec_command( 
     373                $base->options('postsynchro'), 
     374                { 
     375                    BASE => $base->label, 
     376                    BASETYPE => $base->type, 
     377                    %{ $env }, 
     378                } 
     379            ); 
     380        } 
     381    } 
    317382 
    318383    $self->{options}{post} or return 1; 
    319384 
    320     la_log(LA_INFO, "Running post synchro `%s'", $self->{options}{post}); 
    321  
     385    la_log(LA_DEBUG, "Running post synchro `%s'", $self->{options}{post}); 
     386     
    322387    exec_command($self->{options}{post}, $env); 
    323388} 
Note: See TracChangeset for help on using the changeset viewer.