Changeset 74


Ignore:
Timestamp:
05/08/09 17:07:20 (15 years ago)
Author:
nanardon
Message:
  • support object deletion
  • fix synchro of delayed fields
Location:
LATMOS-Accounts/lib/LATMOS
Files:
9 edited

Legend:

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

    r73 r74  
    9191    if ($name) { 
    9292        foreach my $param ($self->Parameters("sync:$name")) { 
    93             warn "$param $options{$param}"; 
    9493            if (!defined($options{$param})) { 
    9594                my @args = $self->val("sync:$name", $param); 
    96                 warn join(', ', $param, @args); 
    9795                $options{$param} = ($args[1] || $param eq 'to') 
    9896                    ? [ @args ] 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm

    r64 r74  
    186186} 
    187187 
     188=head2 delete_object($otype, $id) 
     189 
     190Destroy from data base object type $otype having id $id. 
     191 
     192=cut 
     193 
     194sub delete_object { 
     195    my ($self, $otype, $id) = @_; 
     196    my $pclass = $self->_load_obj_class($otype); 
     197    $pclass->_delete($self, $id) or return; 
     198} 
     199 
    188200=head2 load 
    189201 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ad.pm

    r71 r74  
    8989sub object_base_dn { 
    9090    my ($self, $otype) = @_; 
    91     warn $otype; 
    9291    return join(',', 
    9392        ($self->param($otype . '_container') || 'cn=Users'), 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Ad/objects.pm

    r71 r74  
    4646        callback => sub { 
    4747            my ($mesg, $entry) = @_; 
    48             $mesg->code and die $mesg->error; 
     48            #$mesg->code and die $mesg->error; 
    4949            $entry or return; 
    5050            ref $entry eq 'Net::LDAP::Entry' or return; 
     
    8585    return if(@others); # we cannot have multiple entries... 
    8686    return if (!$entry); 
    87     bless({ entry => $entry }, $class); 
     87    bless({ entry => $entry, _base => $base }, $class); 
     88} 
     89 
     90sub _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 } 
    88100} 
    89101 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/Group.pm

    r60 r74  
    4040 
    4141sub key_field { 'groupname' } 
     42 
     43sub has_extended_attributes { 1 } 
    4244 
    4345sub _initial_fields { 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm

    r68 r74  
    4040 
    4141sub key_field { 'login' } 
     42 
     43sub has_extended_attributes { 1 } 
    4244 
    4345sub _inline_fields { 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r59 r74  
    7474} 
    7575 
     76sub has_extended_attributes { 0 } 
     77 
    7678sub _initial_fields { 
    7779    my ($self, $for) = @_; 
     
    8789    my ($class, $base, $for) = @_; 
    8890    $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; 
    9691    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        } 
    99103    } 
    100104    @attr, keys %{ $class->_inline_fields($for) || {} } 
     
    103107sub _get_field_name_db { 
    104108    my ($class, $c_field, $base) = @_; 
     109    $class->has_extended_attributes or return; 
    105110    $class->object_table or return; 
    106111    my $sth = $base->db->prepare_cached( 
     
    160165} 
    161166 
     167sub _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 
    162180sub db { 
    163181    return $_[0]->base->db; 
     
    176194 
    177195sub 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') || {}; 
    181198    my %inline = map { $inl->{$_} => 1 }  keys %{ $inl || {}}; 
    182199    if ($inline{$field}) { 
     
    193210    $sth->finish; 
    194211    return $res->{$field}; 
    195     } else { 
     212    } elsif ($self->has_extended_attributes) { # else, then we mandatory have extend attr 
    196213        my $sth = $self->db->prepare_cached( 
    197214            sprintf( 
     
    235252    } 
    236253     
    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        } 
    254273    } 
    255274} 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Unix.pm

    r72 r74  
    307307} 
    308308 
     309sub 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 
    3093211; 
    310322 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm

    r73 r74  
    137137                } 
    138138            } 
     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            } 
    139146        } 
    140147    } 
     
    178185            my %delayed = map { $_ => 1 } $to->delayed_fields($otype); 
    179186            foreach ($from->list_canonicals_fields($otype, 'r')) { 
    180                 $delayed{$_} and next; 
     187                $delayed{$_} or next; 
    181188                $fields{$_} ||= 0; # avoid  
    182189                $fields{$_}++; 
    183190            } 
    184191            foreach ($to->list_canonicals_fields($otype, 'w')) { 
    185                 $delayed{$_} and next; 
     192                $delayed{$_} or next; 
    186193                $fields{$_} ||= 0; # avoid  
    187194                $fields{$_}++; 
Note: See TracChangeset for help on using the changeset viewer.