source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Task/Refreshexpired.pm @ 1457

Last change on this file since 1457 was 1199, checked in by nanardon, 12 years ago

don't load unused module

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1package LATMOS::Accounts::Task::Refreshexpired;
2
3use strict;
4use warnings;
5use base qw(LATMOS::Accounts::Task);
6use LATMOS::Accounts;
7use LATMOS::Accounts::Log;
8use LATMOS::Accounts::Utils;
9
10=head1 NAME
11
12LATMOS::Accounts::Task::Refreshexpired - Task to disable expired users
13
14=head1 DESCRIPTION
15
16Some base doesn't handle accounts expiration. One way to do it is to synchronize
17user with value denying login (wrong UNIX shell, password entry set to false,
18...).
19
20For performance issue, objects are not written at each synchronisation, only
21when they changes.
22
23This module find expired user and refresh modification time to ensure
24propagation to other database.
25
26=cut
27
28sub init {
29    my ($self) = @_;
30    my $LA = LATMOS::Accounts->new($self->{config});
31    my $labase = $self->{base} ? $LA->base($self->{base}) : $LA->base;
32    $labase && $labase->load or die "Cannot load base";
33
34    $self->{_la} = $LA;
35    $self->{_base} = $labase;
36
37    1;
38}
39
40sub run {
41    my ($self) = @_;
42
43    my $find = $self->{_base}->db->prepare(
44        q{
45        SELECT * FROM "user"
46        WHERE expire < now() and "date" < expire;
47        }
48    );
49    $find->execute();
50    my $upd = $self->{_base}->db->prepare(
51        q{
52        UPDATE "user" SET date = now() where "name" = ?
53        }
54    );
55    while ( my $res = $find->fetchrow_hashref ) {
56        la_log(LA_NOTICE, "Refresh user %s to take expiry into account",
57            $res->{name},
58        );
59        $upd->execute($res->{name});
60    }
61
62    $self->{_base}->commit;
63
64    1;
65}
66
671;
68
69__END__
70
71=head1 SEE ALSO
72
73L<LATMOS::Accounts>, L<LATMOS::Accounts::Task>
74
75=head1 AUTHOR
76
77Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
78
79=head1 COPYRIGHT AND LICENSE
80
81Copyright (C) 2012 CNRS SA/CETP/LATMOS
82
83This library is free software; you can redistribute it and/or modify
84it under the same terms as Perl itself, either Perl version 5.10.0 or,
85at your option, any later version of Perl 5 you may have available.
86
87=cut
88
Note: See TracBrowser for help on using the repository browser.