source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/SynchAccess.pm @ 1950

Last change on this file since 1950 was 1405, checked in by nanardon, 9 years ago

Fix password change when user does not exists, trap more errors

  • Property svn:keywords set to Id Rev
File size: 2.1 KB
Line 
1package LATMOS::Accounts::SynchAccess;
2
3use strict;
4use warnings;
5use base qw(LATMOS::Accounts::SynchAccess::base);
6use LATMOS::Accounts::SynchAccess::Objects;
7use LATMOS::Accounts::Log;
8
9our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0];
10
11=head1 NAME
12
13LATMOS::Accounts::SynchAccess
14
15=head1 FUNCTIONS
16
17=cut 
18
19=head2 get_object ($otype, $uid)
20
21Compatibility function: return a set of objects for which action must be done.
22
23=cut
24
25sub get_object {
26    my ($self, $otype, $uid) = @_;
27    my @subobj;
28    foreach ($self->bases) {
29        if ($_->is_supported_object($otype)) {
30            my $u = $_->get_object($otype, $uid) or do {
31                $_->log(LA_ERR,
32                    "Cannot get object $otype/$uid",
33                );
34                return;
35            };
36            push(@subobj, $u);
37        }
38    }
39
40    return LATMOS::Accounts::SynchAccess::Objects->new(
41        [ @subobj ]
42    );
43}
44
45=head2 get_object_ifexists ($otype, $uid)
46
47Compatibility function: return a set of objects for which action must be done.
48
49Instead get_object, if the named object does not exists in a database no error is returned
50
51=cut
52
53sub get_object_ifexists {
54    my ($self, $otype, $uid) = @_;
55    my @subobj;
56    foreach ($self->bases) {
57        $_->log(LA_DEBUG,
58            "trying to get object $otype/$uid",
59        );
60        if ($_->is_supported_object($otype)) {
61            my $u = $_->get_object($otype, $uid) or do {
62                $_->log(LA_WARN,
63                    "Cannot get object $otype/$uid",
64                );
65                next
66            };
67            push(@subobj, $u);
68        }
69    }
70
71    if (!@subobj) {
72        la_log(LA_ERR, "No object $otype/$uid found in any bases");
73        return;
74    }
75
76    return LATMOS::Accounts::SynchAccess::Objects->new(
77        [ @subobj ]
78    );
79}
80
811;
82
83__END__
84
85=head1 AUTHOR
86
87Olivier Thauvin, E<lt>olivier.thauvin@aerov.jussieu.frE<gt>
88
89=head1 COPYRIGHT AND LICENSE
90
91Copyright (C) 2008, 2009, 2010, 2011, 2012 CNRS SA/CETP/LATMOS
92
93This library is free software; you can redistribute it and/or modify
94it under the same terms as Perl itself, either Perl version 5.10.0 or,
95at your option, any later version of Perl 5 you may have available.
96
97=cut
Note: See TracBrowser for help on using the repository browser.