Bug 14264: Fix export of late orders when translated
[koha.git] / misc / cronjobs / delete_expired_opac_registrations.pl
blob44cc9dabedf3c2bc47070a7efa66f9baf2898745
1 #!/usr/bin/perl
3 # Copyright 2009-2010 Kyle Hall
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
21 use Getopt::Long;
23 BEGIN {
25 # find Koha's Perl modules
26 # test carefully before changing this
27 use FindBin;
28 eval { my $lib = "$FindBin::Bin/../kohalib.pl"; require $lib };
31 use C4::Context;
32 use C4::Members qw/ DelMember /;
33 use C4::Log;
35 my $help;
36 my $confirm;
37 my $verbose;
39 GetOptions(
40 'h|help' => \$help,
41 'c|confirm' => \$confirm,
42 'v|verbose' => \$verbose,
44 my $usage = << 'ENDUSAGE';
46 This script removes confirmed OPAC based patron registrations
47 that have not been changed from the patron category specified
48 in the system preference PatronSelfRegistrationDefaultCategory
49 within the required time period.
51 NOTE: If you do not use self registration, do NOT run this script.
52 If you use self registration, but you do not use a temporary
53 category for new registrations, do NOT run this script too.
55 This script has the following parameters :
56 -c --confirm: Without this flag set, this script will do nothing.
57 -h --help: Print this message.
58 -v --verbose: Print number of removed patrons.
60 ENDUSAGE
62 if ( $help || !$confirm ) {
63 print $usage;
64 exit;
67 cronlogaction();
69 # Delete accounts that haven't been upgraded from the 'temporary' category code
70 my $delay =
71 C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay');
72 my $category_code =
73 C4::Context->preference('PatronSelfRegistrationDefaultCategory');
75 die "PatronSelfRegistrationExpireTemporaryAccountsDelay and PatronSelfRegistrationDefaultCategory should be filled to use this script!"
76 if not $category_code or not defined $delay or $delay eq q||;
78 my $query = "
79 SELECT borrowernumber
80 FROM borrowers
81 WHERE
82 categorycode = ?
83 AND
84 DATEDIFF( NOW(), dateenrolled ) > ?
87 my $dbh = C4::Context->dbh;
88 my $sth = $dbh->prepare($query);
89 $sth->execute( $category_code, $delay );
91 my $cnt=0;
92 while ( my ($borrowernumber) = $sth->fetchrow_array() ) {
93 DelMember($borrowernumber);
94 $cnt++;
96 print "Removed $cnt expired self-registered borrowers in category $category_code\n" if $verbose;