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

Last change on this file since 2439 was 2439, checked in by nanardon, 4 years ago

Flag in log when change are made by SyncManager?

  • Property svn:executable set to *
File size: 2.0 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 order { 0 }
29
30sub needupd { 1; }
31
32# Every 10 minutes
33sub runDelay { 10 * 60 }
34
35sub init {
36    my ($self) = @_;
37    my $LA = $self->LA;
38    my $labase = $self->{base} ? $LA->base($self->{base}) : $LA->base;
39    $labase && $labase->load or die "Cannot load base";
40
41    $self->{_la} = $LA;
42    $self->{_base} = $labase;
43
44    1;
45}
46
47sub run {
48    my ($self) = @_;
49
50    my $find = $self->{_base}->db->prepare(
51        q{
52        SELECT * FROM "user"
53        WHERE expire < now() and "date" < expire;
54        }
55    );
56    $find->execute();
57    my $upd = $self->{_base}->db->prepare(
58        q{
59        UPDATE "user" SET date = now() where "name" = ?
60        }
61    );
62    while ( my $res = $find->fetchrow_hashref ) {
63        la_log(LA_NOTICE, "Refresh user %s to take expiry into account",
64            $res->{name},
65        );
66        $upd->execute($res->{name});
67    }
68
69    $self->{_base}->commit;
70
71    1;
72}
73
741;
75
76__END__
77
78=head1 SEE ALSO
79
80L<LATMOS::Accounts>, L<LATMOS::Accounts::Task>
81
82=head1 AUTHOR
83
84Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
85
86=head1 COPYRIGHT AND LICENSE
87
88Copyright (C) 2012 CNRS SA/CETP/LATMOS
89
90This library is free software; you can redistribute it and/or modify
91it under the same terms as Perl itself, either Perl version 5.10.0 or,
92at your option, any later version of Perl 5 you may have available.
93
94=cut
95
Note: See TracBrowser for help on using the repository browser.