[56] | 1 | package LATMOS::Accounts::SynchAccess; |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use base qw(LATMOS::Accounts::SynchAccess::base); |
---|
| 6 | use LATMOS::Accounts::SynchAccess::Objects; |
---|
[619] | 7 | use LATMOS::Accounts::Log; |
---|
[56] | 8 | |
---|
| 9 | our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; |
---|
| 10 | |
---|
[1023] | 11 | =head1 NAME |
---|
| 12 | |
---|
| 13 | LATMOS::Accounts::SynchAccess |
---|
| 14 | |
---|
| 15 | =head1 FUNCTIONS |
---|
| 16 | |
---|
| 17 | =cut |
---|
| 18 | |
---|
| 19 | =head2 get_object ($otype, $uid) |
---|
| 20 | |
---|
[1405] | 21 | Compatibility function: return a set of objects for which action must be done. |
---|
[1023] | 22 | |
---|
| 23 | =cut |
---|
| 24 | |
---|
[56] | 25 | sub get_object { |
---|
| 26 | my ($self, $otype, $uid) = @_; |
---|
[619] | 27 | my @subobj; |
---|
| 28 | foreach ($self->bases) { |
---|
| 29 | if ($_->is_supported_object($otype)) { |
---|
| 30 | my $u = $_->get_object($otype, $uid) or do { |
---|
[1405] | 31 | $_->log(LA_ERR, |
---|
| 32 | "Cannot get object $otype/$uid", |
---|
[619] | 33 | ); |
---|
| 34 | return; |
---|
[1405] | 35 | }; |
---|
[619] | 36 | push(@subobj, $u); |
---|
| 37 | } |
---|
[56] | 38 | } |
---|
[1405] | 39 | |
---|
[56] | 40 | return LATMOS::Accounts::SynchAccess::Objects->new( |
---|
| 41 | [ @subobj ] |
---|
| 42 | ); |
---|
| 43 | } |
---|
| 44 | |
---|
[1405] | 45 | =head2 get_object_ifexists ($otype, $uid) |
---|
| 46 | |
---|
| 47 | Compatibility function: return a set of objects for which action must be done. |
---|
| 48 | |
---|
| 49 | Instead get_object, if the named object does not exists in a database no error is returned |
---|
| 50 | |
---|
| 51 | =cut |
---|
| 52 | |
---|
| 53 | sub 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 | |
---|
[56] | 81 | 1; |
---|
| 82 | |
---|
| 83 | __END__ |
---|
[1023] | 84 | |
---|
| 85 | =head1 AUTHOR |
---|
| 86 | |
---|
| 87 | Olivier Thauvin, E<lt>olivier.thauvin@aerov.jussieu.frE<gt> |
---|
| 88 | |
---|
| 89 | =head1 COPYRIGHT AND LICENSE |
---|
| 90 | |
---|
| 91 | Copyright (C) 2008, 2009, 2010, 2011, 2012 CNRS SA/CETP/LATMOS |
---|
| 92 | |
---|
| 93 | This library is free software; you can redistribute it and/or modify |
---|
| 94 | it under the same terms as Perl itself, either Perl version 5.10.0 or, |
---|
| 95 | at your option, any later version of Perl 5 you may have available. |
---|
| 96 | |
---|
| 97 | =cut |
---|