return @result;
}
+=head2 AddMember_Opac
+
+=cut
+
sub AddMember_Opac {
my ( %borrower ) = @_;
}
}
+=head2 HasOverdues
+
+=cut
+
sub HasOverdues {
my ( $borrowernumber ) = @_;
return $count;
}
+=head2 DeleteExpiredOpacRegistrations
+
+ Delete accounts that haven't been upgraded from the 'temporary' category
+ Returns the number of removed patrons
+
+=cut
+
+sub DeleteExpiredOpacRegistrations {
+
+ my $delay = C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay');
+ my $category_code = C4::Context->preference('PatronSelfRegistrationDefaultCategory');
+
+ return 0 if not $category_code or not defined $delay or $delay eq q||;
+
+ my $query = qq|
+SELECT borrowernumber
+FROM borrowers
+WHERE categorycode = ? AND DATEDIFF( NOW(), dateenrolled ) > ? |;
+
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare($query);
+ $sth->execute( $category_code, $delay );
+ my $cnt=0;
+ while ( my ($borrowernumber) = $sth->fetchrow_array() ) {
+ DelMember($borrowernumber);
+ $cnt++;
+ }
+ return $cnt;
+}
+
+=head2 DeleteUnverifiedOpacRegistrations
+
+ Delete all unverified self registrations in borrower_modifications,
+ older than the specified number of days.
+
+=cut
+
+sub DeleteUnverifiedOpacRegistrations {
+ my ( $days ) = @_;
+ my $dbh = C4::Context->dbh;
+ my $sql=qq|
+DELETE FROM borrower_modifications
+WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|;
+ my $cnt=$dbh->do($sql, undef, ($days) );
+ return $cnt eq '0E0'? 0: $cnt;
+}
+
END { } # module clean-up code here (global destructor)
1;
--restrictions DAYS purge patrons restrictions expired since more than DAYS days.
Defaults to 30 days if no days specified.
--all-restrictions purge all expired patrons restrictions.
+ --del-exp-selfreg Delete expired self registration accounts
+ --del-unv-selfreg DAYS Delete unverified self registrations older than DAYS
USAGE
exit $_[0];
}
my (
- $help, $sessions, $sess_days, $verbose, $zebraqueue_days,
- $mail, $purge_merged, $pImport, $pLogs, $pSearchhistory,
- $pZ3950, $pListShareInvites, $pDebarments, $allDebarments,
+ $help,
+ $sessions,
+ $sess_days,
+ $verbose,
+ $zebraqueue_days,
+ $mail,
+ $purge_merged,
+ $pImport,
+ $pLogs,
+ $pSearchhistory,
+ $pZ3950,
+ $pListShareInvites,
+ $pDebarments,
+ $allDebarments,
+ $pExpSelfReg,
+ $pUnvSelfReg,
);
GetOptions(
'list-invites:i' => \$pListShareInvites,
'restrictions:i' => \$pDebarments,
'all-restrictions' => \$allDebarments,
+ 'del-exp-selfreg' => \$pExpSelfReg,
+ 'del-unv-selfreg' => \$pUnvSelfReg,
) || usage(1);
# Use default values
|| $pZ3950
|| $pListShareInvites
|| $pDebarments
- || $allDebarments )
-{
+ || $allDebarments
+ || $pExpSelfReg
+ || $pUnvSelfReg
+) {
print "You did not specify any cleanup work for the script to do.\n\n";
usage(1);
}
print "$count restrictions were deleted.\nDone with all restrictions purge.\n" if $verbose;
}
+if( $pExpSelfReg ) {
+ DeleteExpiredSelfRegs();
+}
+if( $pUnvSelfReg ) {
+ DeleteUnverifiedSelfRegs( $pUnvSelfReg );
+}
+
exit(0);
sub RemoveOldSessions {
}
return $count;
}
+
+sub DeleteExpiredSelfRegs {
+ my $cnt= C4::Members::DeleteExpiredOpacRegistrations();
+ print "Removed $cnt expired self-registered borrowers\n" if $verbose;
+}
+
+sub DeleteUnverifiedSelfRegs {
+ my $cnt= C4::Members::DeleteUnverifiedOpacRegistrations( $_[0] );
+ print "Removed $cnt unverified self-registrations\n" if $verbose;
+}
);
my $usage = << 'ENDUSAGE';
+IMPORTANT: You should no longer call this script. Please use
+cleanup_database.pl with parameter --del-exp-selfreg.
+
This script removes confirmed OPAC based patron registrations
that have not been changed from the patron category specified
in the system preference PatronSelfRegistrationDefaultCategory
exit;
}
-cronlogaction();
-
-# Delete accounts that haven't been upgraded from the 'temporary' category code
-my $delay =
- C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay');
-my $category_code =
- C4::Context->preference('PatronSelfRegistrationDefaultCategory');
-
-die "PatronSelfRegistrationExpireTemporaryAccountsDelay and PatronSelfRegistrationDefaultCategory should be filled to use this script!"
- if not $category_code or not defined $delay or $delay eq q||;
-
-my $query = "
- SELECT borrowernumber
- FROM borrowers
- WHERE
- categorycode = ?
- AND
- DATEDIFF( NOW(), dateenrolled ) > ?
-";
-
-my $dbh = C4::Context->dbh;
-my $sth = $dbh->prepare($query);
-$sth->execute( $category_code, $delay );
-
-my $cnt=0;
-while ( my ($borrowernumber) = $sth->fetchrow_array() ) {
- DelMember($borrowernumber);
- $cnt++;
-}
-print "Removed $cnt expired self-registered borrowers in category $category_code\n" if $verbose;
+my $c= "$FindBin::Bin/cleanup_database.pl --del-exp-selfreg";
+$c.= " -v" if $verbose;
+system($c);
);
my $usage = << 'ENDUSAGE';
+IMPORTANT: You should no longer call this script. Please use
+cleanup_database.pl with parameter --del-unv-selfreg.
+
This script removes unconfirmed OPAC based patron registrations
that have not been confirmed within the required time period.
exit;
}
-cronlogaction();
-
-my $dbh = C4::Context->dbh;
-
-$dbh->do( "
- DELETE FROM borrower_modifications
- WHERE
- borrowernumber = 0
- AND
- TIME_TO_SEC( TIMEDIFF( NOW(), timestamp )) / 3600 > ?
-", undef, $hours );
+my $d= $hours>=24? int($hours/24): 1;
+my $c= "$FindBin::Bin/cleanup_database.pl -del-unv-selfreg $d";
+system($c);
use Modern::Perl;
-use Test::More tests => 61;
+use Test::More tests => 62;
use Test::MockModule;
use Data::Dumper;
use C4::Context;
$dbh->rollback();
};
+subtest 'purgeSelfRegistration' => sub {
+ plan tests => 2;
+
+ #purge unverified
+ my $d=360;
+ C4::Members::DeleteUnverifiedOpacRegistrations($d);
+ foreach(1..3) {
+ $dbh->do("INSERT INTO borrower_modifications (timestamp, borrowernumber, verification_token) VALUES ('2014-01-01 01:02:03',0,?)", undef, (scalar localtime)."_$_");
+ }
+ is( C4::Members::DeleteUnverifiedOpacRegistrations($d), 3, 'Test for DeleteUnverifiedOpacRegistrations' );
+
+ #purge members in temporary category
+ my $c= 'XYZ';
+ $dbh->do("INSERT IGNORE INTO categories (categorycode) VALUES ('$c')");
+ C4::Context->set_preference('PatronSelfRegistrationDefaultCategory', $c );
+ C4::Context->set_preference('PatronSelfRegistrationExpireTemporaryAccountsDelay', 360);
+ C4::Members::DeleteExpiredOpacRegistrations();
+ $dbh->do("INSERT INTO borrowers (surname, address, city, branchcode, categorycode, dateenrolled) VALUES ('Testaabbcc', 'Street 1', 'CITY', 'CPL', '$c', '2014-01-01 01:02:03')");
+ is( C4::Members::DeleteExpiredOpacRegistrations(), 1, 'Test for DeleteExpiredOpacRegistrations');
+ $dbh->rollback();
+};
+
sub _find_member {
my ($resultset) = @_;
my $found = $resultset && grep( { $_->{cardnumber} && $_->{cardnumber} eq $CARDNUMBER } @$resultset );