Bug 7067 - OPAC Borrower Self Registration
[koha.git] / misc / cronjobs / delete_expired_opac_registrations.pl
1 #!/usr/bin/perl
2
3 # Copyright 2009-2010 Kyle Hall
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21 use Getopt::Long;
22
23 BEGIN {
24
25     # find Koha's Perl modules
26     # test carefully before changing this
27     use FindBin;
28     eval { require "$FindBin::Bin/../kohalib.pl" };
29 }
30
31 use C4::Context;
32 use C4::Members qw/ DelMember /;
33
34 my $help;
35 my $confirm;
36
37 GetOptions(
38     'h|help'    => \$help,
39     'c|confirm' => \$confirm,
40 );
41 my $usage = << 'ENDUSAGE';
42
43 This script remove confirmed OPAC based patron registrations
44 that have not been changed from the patron category specified
45 in the system preference PatronSelfRegistrationDefaultCategory
46 within the required time period.
47
48 This script has the following parameters :
49     -h --help:    This message
50
51     -c --confirm: Without this flag set, this script will do nothing.
52 ENDUSAGE
53
54 if ( $help || !$confirm ) {
55     print $usage;
56     exit;
57 }
58
59 ## Delete accounts that haven't been upgraded from the 'temporary' category code'
60 my $delay =
61   C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay');
62 my $category_code =
63   C4::Context->preference('PatronSelfRegistrationDefaultCategory');
64
65 my $query = "
66     SELECT borrowernumber
67     FROM borrowers
68     WHERE
69         categorycode = ?
70       AND
71         DATEDIFF( DATE( NOW() ), DATE(dateenrolled) ) = ? )
72 ";
73
74 my $dbh = C4::Context->dbh;
75 my $sth = $dbh->prepare($query);
76 $sth->execute( $category_code, $delay );
77
78 while ( my ($borrowernumber) = $sth->fetchrow_array() ) {
79     DelMember($borrowernumber);
80 }