Changeset 74
- Timestamp:
- 05/08/09 17:07:20 (15 years ago)
- Location:
- LATMOS-Accounts/lib/LATMOS
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts/lib/LATMOS/Accounts.pm
r73 r74 91 91 if ($name) { 92 92 foreach my $param ($self->Parameters("sync:$name")) { 93 warn "$param $options{$param}";94 93 if (!defined($options{$param})) { 95 94 my @args = $self->val("sync:$name", $param); 96 warn join(', ', $param, @args);97 95 $options{$param} = ($args[1] || $param eq 'to') 98 96 ? [ @args ] -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm
r64 r74 186 186 } 187 187 188 =head2 delete_object($otype, $id) 189 190 Destroy from data base object type $otype having id $id. 191 192 =cut 193 194 sub delete_object { 195 my ($self, $otype, $id) = @_; 196 my $pclass = $self->_load_obj_class($otype); 197 $pclass->_delete($self, $id) or return; 198 } 199 188 200 =head2 load 189 201 -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ad.pm
r71 r74 89 89 sub object_base_dn { 90 90 my ($self, $otype) = @_; 91 warn $otype;92 91 return join(',', 93 92 ($self->param($otype . '_container') || 'cn=Users'), -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ad/objects.pm
r71 r74 46 46 callback => sub { 47 47 my ($mesg, $entry) = @_; 48 $mesg->code and die $mesg->error;48 #$mesg->code and die $mesg->error; 49 49 $entry or return; 50 50 ref $entry eq 'Net::LDAP::Entry' or return; … … 85 85 return if(@others); # we cannot have multiple entries... 86 86 return if (!$entry); 87 bless({ entry => $entry }, $class); 87 bless({ entry => $entry, _base => $base }, $class); 88 } 89 90 sub _delete { 91 my ($class, $base, $uid) = @_; 92 my $obj = $class->new($base, $uid) or return; 93 94 my $mesg = $base->ldap->delete($obj->{entry}->dn); 95 96 if ($mesg->code) { 97 warn $mesg->error; 98 return; 99 } else { return 1 } 88 100 } 89 101 -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Group.pm
r60 r74 40 40 41 41 sub key_field { 'groupname' } 42 43 sub has_extended_attributes { 1 } 42 44 43 45 sub _initial_fields { -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm
r68 r74 40 40 41 41 sub key_field { 'login' } 42 43 sub has_extended_attributes { 1 } 42 44 43 45 sub _inline_fields { -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm
r59 r74 74 74 } 75 75 76 sub has_extended_attributes { 0 } 77 76 78 sub _initial_fields { 77 79 my ($self, $for) = @_; … … 87 89 my ($class, $base, $for) = @_; 88 90 $for ||= 'rw'; 89 my $sth = $base->db->prepare_cached(90 sprintf(91 q{select canonical from %s order by canonical},92 $base->db->quote_identifier($class->object_table . '_attributes_list'),93 )94 );95 $sth->execute;96 91 my @attr; 97 while (my $res = $sth->fetchrow_hashref) { 98 push(@attr, $res->{canonical}); 92 if ($class->has_extended_attributes) { 93 my $sth = $base->db->prepare_cached( 94 sprintf( 95 q{select canonical from %s order by canonical}, 96 $base->db->quote_identifier($class->object_table . '_attributes_list'), 97 ) 98 ); 99 $sth->execute; 100 while (my $res = $sth->fetchrow_hashref) { 101 push(@attr, $res->{canonical}); 102 } 99 103 } 100 104 @attr, keys %{ $class->_inline_fields($for) || {} } … … 103 107 sub _get_field_name_db { 104 108 my ($class, $c_field, $base) = @_; 109 $class->has_extended_attributes or return; 105 110 $class->object_table or return; 106 111 my $sth = $base->db->prepare_cached( … … 160 165 } 161 166 167 sub _delete { 168 my ($class, $base, $id) = @_; 169 170 my $sthd = $base->db->prepare_cached( 171 sprintf( 172 q{delete from %s where %s = ?}, 173 $base->db->quote_identifier($class->object_table), 174 $base->db->quote_identifier($class->key_field), 175 ) 176 ); 177 $sthd->execute($id); 178 } 179 162 180 sub db { 163 181 return $_[0]->base->db; … … 176 194 177 195 sub get_field { 178 my ($self, $field, $for) = @_; 179 $for ||= 'rw'; 180 my $inl = $self->_inline_fields($for) || {}; 196 my ($self, $field) = @_; 197 my $inl = $self->_inline_fields('r') || {}; 181 198 my %inline = map { $inl->{$_} => 1 } keys %{ $inl || {}}; 182 199 if ($inline{$field}) { … … 193 210 $sth->finish; 194 211 return $res->{$field}; 195 } els e {212 } elsif ($self->has_extended_attributes) { # else, then we mandatory have extend attr 196 213 my $sth = $self->db->prepare_cached( 197 214 sprintf( … … 235 252 } 236 253 237 my $sthd = $self->db->prepare_cached( 238 sprintf( 239 q{delete from %s where id = ? and attr = ?}, 240 $self->db->quote_identifier($self->object_table. '_attributes'), 241 ), 242 ); 243 my $sthx = $self->db->prepare_cached( 244 sprintf( 245 q{insert into %s (id, attr, value) values (?,?,?)}, 246 $self->db->quote_identifier($self->object_table. '_attributes'), 247 ) 248 ); 249 250 foreach (keys %ext) { 251 $sthd->execute($self->{id}, $_) or return; 252 $ext{$_} or next; 253 $sthx->execute($self->{id}, $_, $ext{$_}) or return; 254 if ($self->has_extended_attributes) { 255 my $sthd = $self->db->prepare_cached( 256 sprintf( 257 q{delete from %s where id = ? and attr = ?}, 258 $self->db->quote_identifier($self->object_table. '_attributes'), 259 ), 260 ); 261 my $sthx = $self->db->prepare_cached( 262 sprintf( 263 q{insert into %s (id, attr, value) values (?,?,?)}, 264 $self->db->quote_identifier($self->object_table. '_attributes'), 265 ) 266 ); 267 268 foreach (keys %ext) { 269 $sthd->execute($self->{id}, $_) or return; 270 $ext{$_} or next; 271 $sthx->execute($self->{id}, $_, $ext{$_}) or return; 272 } 254 273 } 255 274 } -
LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Unix.pm
r72 r74 307 307 } 308 308 309 sub delete_object { 310 my ($self, $otype, $id, %data) = @_; 311 312 # objects are store into sub ref: 313 my $internal_obj = { 314 user => 'users', 315 group => 'groups', 316 }->{$otype}; 317 delete $self->{$internal_obj}{$id}; 318 1 319 } 320 309 321 1; 310 322 -
LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm
r73 r74 137 137 } 138 138 } 139 my %srcexists = map { $_ => 1 } $self->from->list_objects($otype); 140 foreach (keys %exists) { 141 if (!$srcexists{$_}) { 142 warn "delete $otype $_\n"; 143 $destbase->delete_object($otype, $_); 144 } 145 } 139 146 } 140 147 } … … 178 185 my %delayed = map { $_ => 1 } $to->delayed_fields($otype); 179 186 foreach ($from->list_canonicals_fields($otype, 'r')) { 180 $delayed{$_} andnext;187 $delayed{$_} or next; 181 188 $fields{$_} ||= 0; # avoid 182 189 $fields{$_}++; 183 190 } 184 191 foreach ($to->list_canonicals_fields($otype, 'w')) { 185 $delayed{$_} andnext;192 $delayed{$_} or next; 186 193 $fields{$_} ||= 0; # avoid 187 194 $fields{$_}++;
Note: See TracChangeset
for help on using the changeset viewer.