Changeset 2501


Ignore:
Timestamp:
11/30/21 23:36:30 (3 years ago)
Author:
nanardon
Message:

add --attr option to la-sync

File:
1 edited

Legend:

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

    r2500 r2501  
    1717 
    1818    la-sync [options] 
    19     la-sync --from source --to dest -o type [-a|obj1 obj2] 
     19    la-sync --from source --to dest -o type [--all|obj1 obj2] 
    2020 
    2121=cut 
     
    3333    'b|batch'      => \my $batch, 
    3434    'unexp'        => \my $unexp, 
    35     'a|all'        => \my $all 
     35    'all'          => \my $all, 
     36    'a|attr=s'     => \my @attrs,  
    3637) or pod2usage(); 
    3738 
     
    8283Sync unexported objects in source base 
    8384 
     85=item -a|--attr 
     86 
     87Can be given multiple time, works only when oject type is given 
     88 
     89Sync only this attributes. 
     90 
     91If the destination attributes must be differents it can be given using a semi colon: 
     92 
     93 
     94To copy sn attribute sn from source to dest objects 
     95 
     96    --attr sn 
     97 
     98To copy sn attribute to uid on dest: 
     99 
     100   --aatr sn:uid 
     101 
    84102=back 
    85103 
     
    115133    } 
    116134 
    117     foreach (@list) { 
    118         warn "Try to sync $otype: $_\n"; 
    119         $sync->sync_object($otype, $_, onepass => 1) or do { 
    120             warn "Error while synching $_ ($otype)\n"; 
    121             exit 1; 
     135    if ( @attrs ) { 
     136 
     137        foreach my $id ( @list ) { 
     138            my $srcOjb = $sync->from->get_object($otype, $id) or next; 
     139            foreach my $dest ( $sync->to ) { 
     140                my $destObj = $dest->get_object($otype, $id) or next; 
     141                my %destvalue; 
     142                foreach ( sort @attrs ) { 
     143                    m/([^:]+)(?::(.*))?/; 
     144                    $destvalue{ $1 } = $srcOjb->get_c_field( $2 || $1 ); 
     145                } 
     146                $destObj->set_c_fields( %destvalue ); 
     147                $dest->commit; 
     148            } 
     149        } 
     150    } else { 
     151        foreach (@list) { 
     152            warn "Try to sync $otype: $_\n"; 
     153            $sync->sync_object($otype, $_, onepass => 1) or do { 
     154            warn "Error while synching $_ ($otype)\n"; 
     155            exit 1; 
     156            } 
    122157        } 
    123158    } 
Note: See TracChangeset for help on using the changeset viewer.