Changeset 83
- Timestamp:
- 05/10/09 19:03:39 (15 years ago)
- Location:
- LATMOS-Accounts
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts/bin/la-sync
r78 r83 27 27 'nocreate' => \my $nocreate, 28 28 'test' => \my $test, 29 'o|object=s' => \my $otype, 29 30 ) or pod2usage(); 30 31 … … 56 57 ) or die "cannot create sync object\n"; 57 58 $sync->load_dest and return; 58 $sync->process() or warn "Sync has failed\n"; 59 if ($otype) { 60 foreach (@ARGV) { 61 warn "Try to sync $otype: $_\n"; 62 $sync->sync_object($otype, $_); 63 } 64 } else { 65 $sync->process() or warn "Sync has failed\n"; 66 } -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
r74 r83 276 276 } 277 277 278 =head2 sync_object 279 280 Synchronise an object into this base 281 282 =cut 283 284 sub sync_object { 285 my ($self, $srcobj, %options) = @_; 286 $self->is_supported_object($srcobj->type) or return; 287 my @fields = $options{attrs} 288 ? @{ $options{attrs} } 289 : $self->list_canonicals_fields($srcobj->type, 'w'); 290 my %data; 291 foreach (@fields) { 292 $srcobj->get_field_name($_) or next; 293 $data{$_} = $srcobj->get_c_field($_); 294 } 295 if (my $dstobj = $self->get_object($srcobj->type, $srcobj->id)) { 296 return $dstobj->set_c_fields(%data); 297 } elsif(!$options{nocreate}) { 298 return $self->create_c_object($srcobj->type, $srcobj->id, %data); 299 } else { 300 return 0; 301 } 302 } 303 278 304 1; 279 305 -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Unix/User.pm
r81 r83 49 49 50 50 sub id { 51 $_[0]->{ login}51 $_[0]->{account} 52 52 } 53 53 -
LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm
r77 r83 140 140 foreach my $uid (@lobjfrom) { 141 141 my $sobj = $self->from->get_object($otype, $uid); 142 if ($exists{$uid}) { 143 my %fields = map { $_ => $sobj->get_c_field($_, 'r') } @common_fields; 144 my $dobj = $destbase->get_object($otype, $uid); 145 $dobj->set_c_fields(%fields) unless($self->{options}{test}); 146 warn " $otype $uid: synched\n"; 147 } elsif (!$self->{options}{nocreate} && !$options{nocreate}) { 148 my %fields = map { $_ => $sobj->get_c_field($_, 'r') } @common_fields; 149 $destbase->create_c_object($otype, $uid, %fields) unless($self->{options}{test}); 150 warn " $otype $uid: created\n"; 151 } 142 $destbase->sync_object( 143 $sobj, 144 nocreate => ($self->{options}{nocreate} || $options{nocreate}), 145 ) unless($self->{options}{test}); 146 warn " $otype $uid: synched\n"; 152 147 } 153 148 } … … 172 167 } 173 168 169 sub sync_object { 170 my ($self, $otype, $uid) = @_; 171 my $sobj = $self->from->get_object($otype, $uid) or return; 172 foreach ($self->to) { 173 $_->sync_object($sobj) 174 } 175 foreach ($self->to) { 176 $_->commit; 177 } 178 1; 179 } 180 174 181 sub process { 175 182 my ($self) = @_;
Note: See TracChangeset
for help on using the changeset viewer.