Changeset 2416


Ignore:
Timestamp:
06/25/20 09:25:24 (4 years ago)
Author:
nanardon
Message:

Make la-rename continue even if rename failed in one base (or object is not found)

Location:
trunk/LATMOS-Accounts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/bin/la-rename

    r891 r2416  
    5959$labase->wexported(1); 
    6060 
    61 my $obj = $labase->get_object($otype, $ARGV[0]) or do { 
    62     die "Object $otype $ARGV[0] not found\n"; 
    63 }; 
     61if ($labase->can('SetCB')) { 
     62    $labase->SetCB( sub { 
     63        my ( $base, $res ) = @_; 
     64        if ($res) { 
     65            print $base->label . ': Object renamed' . "\n"; 
     66            $base->commit; 
     67        } else { 
     68            warn $base->label . ': Cannot rename object' . "\n"; 
     69            $base->rollback; 
     70        } 
     71    } ); 
     72} 
    6473 
    6574if (!$labase->rename_object($otype, @ARGV)) { 
    66     die "Error while renaming $otype $ARGV[0] to $ARGV[1]\n"; 
     75    die "Some errors occurs, please check\n"; 
    6776} 
    6877 
    69 $labase->commit; 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/SynchAccess/base.pm

    r2283 r2416  
    8585} 
    8686 
     87=head2 CB ( @Args ) 
     88 
     89Run callback if set 
     90 
     91=cut 
     92 
     93sub CB { 
     94    my ( $self, @Args ) = @_; 
     95 
     96    if ($self->{cb}) { 
     97        return $self->{cb}->( @Args ); 
     98    } else { 
     99        return 1; 
     100    } 
     101} 
     102 
    87103sub _return_all { 
    88104    my ($self, $sub, @args) = @_; 
     
    90106    foreach my $ba ($self->bases) { 
    91107        my @res = $_->$sub(@args); 
    92         $self->{cb}->($ba, @res) if($self->{cb}); 
     108        $self->CB($ba, @res); 
    93109        push(@allres, @res); 
    94110    } 
     
    114130    foreach ($self->bases) { 
    115131        my $res = $_->$sub(@args); 
    116         $self->{cb}->($_, $res) if($self->{cb}); 
     132        $self->CB($_, $res); 
    117133        $res or do { 
    118134                    la_log(LA_ERR, "SyncA: Erreur call $sub() for %s", $_); 
     
    128144    foreach ($self->bases) { 
    129145        my $res = $_->$sub(@args) and $failure = 1; 
    130         $self->{cb}->($_, $res) if($self->{cb}); 
     146        $self->CB($_, $res); 
    131147    } 
    132148    $failure ? 0 : 1; 
     
    141157    foreach ($self->bases) { 
    142158        if ($_->is_supported_object($otype)) { 
     159            $_->get_object($otype, $uid) or do { 
     160                $_->log(LA_ERR, 
     161                    "Cannot get object $otype/$uid", 
     162                ); 
     163                next; 
     164            }; 
     165 
    143166            my $res = $_->rename_object($otype, $uid, $newuid); 
    144             $self->{cb}->($_, $res) if($self->{cb}); 
     167            $self->CB($_, $res); 
    145168            $res or do { 
    146                 la_log(LA_ERR, 
     169                la_log(LA_WARN, 
    147170                    "Cannot get object $otype/$uid in %s/%s", 
    148171                    $_->type, 
    149172                    $_->label 
    150173                ); 
    151                 return; 
     174                $_->rollback; 
    152175            }; 
    153176        } 
Note: See TracChangeset for help on using the changeset viewer.