View | Details | Raw Unified | Return to bug 13049
Collapse All | Expand All

(-)a/C4/Members.pm (+55 lines)
Lines 2523-2528 sub GetBorrowersWithEmail { Link Here
2523
    return @result;
2523
    return @result;
2524
}
2524
}
2525
2525
2526
=head2 AddMember_Opac
2527
2528
=cut
2529
2526
sub AddMember_Opac {
2530
sub AddMember_Opac {
2527
    my ( %borrower ) = @_;
2531
    my ( %borrower ) = @_;
2528
2532
Lines 2569-2574 sub AddEnrolmentFeeIfNeeded { Link Here
2569
    }
2573
    }
2570
}
2574
}
2571
2575
2576
=head2 HasOverdues
2577
2578
=cut
2579
2572
sub HasOverdues {
2580
sub HasOverdues {
2573
    my ( $borrowernumber ) = @_;
2581
    my ( $borrowernumber ) = @_;
2574
2582
Lines 2580-2585 sub HasOverdues { Link Here
2580
    return $count;
2588
    return $count;
2581
}
2589
}
2582
2590
2591
=head2 DeleteExpiredOpacRegistrations
2592
2593
    Delete accounts that haven't been upgraded from the 'temporary' category
2594
    Returns the number of removed patrons
2595
2596
=cut
2597
2598
sub DeleteExpiredOpacRegistrations {
2599
2600
    my $delay = C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay');
2601
    my $category_code = C4::Context->preference('PatronSelfRegistrationDefaultCategory');
2602
2603
    return 0 if not $category_code or not defined $delay or $delay eq q||;
2604
2605
    my $query = qq|
2606
SELECT borrowernumber
2607
FROM borrowers
2608
WHERE categorycode = ? AND DATEDIFF( NOW(), dateenrolled ) > ? |;
2609
2610
    my $dbh = C4::Context->dbh;
2611
    my $sth = $dbh->prepare($query);
2612
    $sth->execute( $category_code, $delay );
2613
    my $cnt=0;
2614
    while ( my ($borrowernumber) = $sth->fetchrow_array() ) {
2615
        DelMember($borrowernumber);
2616
        $cnt++;
2617
    }
2618
    return $cnt;
2619
}
2620
2621
=head2 DeleteUnverifiedOpacRegistrations
2622
2623
    Delete all unverified self registrations in borrower_modifications,
2624
    older than the specified number of days.
2625
2626
=cut
2627
2628
sub DeleteUnverifiedOpacRegistrations {
2629
    my ( $days ) = @_;
2630
    my $dbh = C4::Context->dbh;
2631
    my $sql=qq|
2632
DELETE FROM borrower_modifications
2633
WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|;
2634
    my $cnt=$dbh->do($sql, undef, ($days) );
2635
    return $cnt eq '0E0'? 0: $cnt;
2636
}
2637
2583
END { }    # module clean-up code here (global destructor)
2638
END { }    # module clean-up code here (global destructor)
2584
2639
2585
1;
2640
1;
(-)a/misc/cronjobs/cleanup_database.pl (-3 / +25 lines)
Lines 69-74 Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu Link Here
69
                         days.  Defaults to 14 days if no days specified.
69
                         days.  Defaults to 14 days if no days specified.
70
   --restrictions DAYS   purge patrons restrictions expired since more than DAYS days.
70
   --restrictions DAYS   purge patrons restrictions expired since more than DAYS days.
71
                         Defaults to 30 days if no days specified.
71
                         Defaults to 30 days if no days specified.
72
   --del-exp-selfreg  Delete expired self registration accounts
73
   --del-unv-selfreg DAYS  Delete unverified self registrations older than DAYS
72
USAGE
74
USAGE
73
    exit $_[0];
75
    exit $_[0];
74
}
76
}
Lines 76-82 USAGE Link Here
76
my (
78
my (
77
    $help,   $sessions,          $sess_days, $verbose, $zebraqueue_days,
79
    $help,   $sessions,          $sess_days, $verbose, $zebraqueue_days,
78
    $mail,   $purge_merged,      $pImport,   $pLogs,   $pSearchhistory,
80
    $mail,   $purge_merged,      $pImport,   $pLogs,   $pSearchhistory,
79
    $pZ3950, $pListShareInvites, $pDebarments,
81
    $pZ3950, $pListShareInvites, $pDebarments, $pExpSelfReg, $pUnvSelfReg,
80
);
82
);
81
83
82
GetOptions(
84
GetOptions(
Lines 93-98 GetOptions( Link Here
93
    'searchhistory:i' => \$pSearchhistory,
95
    'searchhistory:i' => \$pSearchhistory,
94
    'list-invites:i'  => \$pListShareInvites,
96
    'list-invites:i'  => \$pListShareInvites,
95
    'restrictions:i'  => \$pDebarments,
97
    'restrictions:i'  => \$pDebarments,
98
    'del-exp-selfreg' => \$pExpSelfReg,
99
    'del-unv-selfreg' => \$pUnvSelfReg,
96
) || usage(1);
100
) || usage(1);
97
101
98
# Use default values
102
# Use default values
Lines 118-125 unless ( $sessions Link Here
118
    || $pSearchhistory
122
    || $pSearchhistory
119
    || $pZ3950
123
    || $pZ3950
120
    || $pListShareInvites
124
    || $pListShareInvites
121
    || $pDebarments )
125
    || $pDebarments
122
{
126
    || $pExpSelfReg
127
    || $pUnvSelfReg ) {
123
    print "You did not specify any cleanup work for the script to do.\n\n";
128
    print "You did not specify any cleanup work for the script to do.\n\n";
124
    usage(1);
129
    usage(1);
125
}
130
}
Lines 238-243 if ($pDebarments) { Link Here
238
    print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose;
243
    print "$count restrictions were deleted.\nDone with restrictions purge.\n" if $verbose;
239
}
244
}
240
245
246
if( $pExpSelfReg ) {
247
    DeleteExpiredSelfRegs();
248
}
249
if( $pUnvSelfReg ) {
250
    DeleteUnverifiedSelfRegs( $pUnvSelfReg );
251
}
252
241
exit(0);
253
exit(0);
242
254
243
sub RemoveOldSessions {
255
sub RemoveOldSessions {
Lines 324-326 sub PurgeDebarments { Link Here
324
    }
336
    }
325
    return $count;
337
    return $count;
326
}
338
}
339
340
sub DeleteExpiredSelfRegs {
341
    my $cnt= C4::Members::DeleteExpiredOpacRegistrations();
342
    print "Removed $cnt expired self-registered borrowers\n" if $verbose;
343
}
344
345
sub DeleteUnverifiedSelfRegs {
346
    my $cnt= C4::Members::DeleteUnverifiedOpacRegistrations( $_[0] );
347
    print "Removed $cnt unverified self-registrations\n" if $verbose;
348
}
(-)a/misc/cronjobs/delete_expired_opac_registrations.pl (-28 / +6 lines)
Lines 42-47 GetOptions( Link Here
42
);
42
);
43
my $usage = << 'ENDUSAGE';
43
my $usage = << 'ENDUSAGE';
44
44
45
IMPORTANT: You should no longer call this script. Please use
46
cleanup_database.pl with parameter --del-exp-selfreg.
47
45
This script removes confirmed OPAC based patron registrations
48
This script removes confirmed OPAC based patron registrations
46
that have not been changed from the patron category specified
49
that have not been changed from the patron category specified
47
in the system preference PatronSelfRegistrationDefaultCategory
50
in the system preference PatronSelfRegistrationDefaultCategory
Lines 63-93 if ( $help || !$confirm ) { Link Here
63
    exit;
66
    exit;
64
}
67
}
65
68
66
# Delete accounts that haven't been upgraded from the 'temporary' category code
69
my $c= "$FindBin::Bin/cleanup_database.pl --del-exp-selfreg";
67
my $delay =
70
$c.= " -v" if $verbose;
68
  C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay');
71
system($c);
69
my $category_code =
70
  C4::Context->preference('PatronSelfRegistrationDefaultCategory');
71
72
die "PatronSelfRegistrationExpireTemporaryAccountsDelay and PatronSelfRegistrationDefaultCategory should be filled to use this script!"
73
    if not $category_code or not defined $delay or $delay eq q||;
74
75
my $query = "
76
    SELECT borrowernumber
77
    FROM borrowers
78
    WHERE
79
        categorycode = ?
80
      AND
81
        DATEDIFF( NOW(), dateenrolled ) > ?
82
";
83
84
my $dbh = C4::Context->dbh;
85
my $sth = $dbh->prepare($query);
86
$sth->execute( $category_code, $delay );
87
88
my $cnt=0;
89
while ( my ($borrowernumber) = $sth->fetchrow_array() ) {
90
    DelMember($borrowernumber);
91
    $cnt++;
92
}
93
print "Removed $cnt expired self-registered borrowers in category $category_code\n" if $verbose;
(-)a/misc/cronjobs/delete_unverified_opac_registrations.pl (-9 / +6 lines)
Lines 42-47 GetOptions( Link Here
42
);
42
);
43
my $usage = << 'ENDUSAGE';
43
my $usage = << 'ENDUSAGE';
44
44
45
IMPORTANT: You should no longer call this script. Please use
46
cleanup_database.pl with parameter --del-unv-selfreg.
47
45
This script removes unconfirmed OPAC based patron registrations
48
This script removes unconfirmed OPAC based patron registrations
46
that have not been confirmed within the required time period.
49
that have not been confirmed within the required time period.
47
50
Lines 59-70 if ( $help || !$confirm ) { Link Here
59
    exit;
62
    exit;
60
}
63
}
61
64
62
my $dbh = C4::Context->dbh;
65
my $d= $hours>=24? int($hours/24): 1;
63
66
my $c= "$FindBin::Bin/cleanup_database.pl -del-unv-selfreg $d";
64
$dbh->do( "
67
system($c);
65
         DELETE FROM borrower_modifications
66
         WHERE
67
             borrowernumber = 0
68
           AND
69
             TIME_TO_SEC( TIMEDIFF( NOW(), timestamp )) / 3600 > ?
70
", undef, $hours );
(-)a/t/db_dependent/Members.t (-2 / +23 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 72;
20
use Test::More tests => 73;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Data::Dumper;
22
use Data::Dumper;
23
use C4::Context;
23
use C4::Context;
Lines 372-377 subtest 'GetMemberAccountBalance' => sub { Link Here
372
    $dbh->rollback();
372
    $dbh->rollback();
373
};
373
};
374
374
375
subtest 'purgeSelfRegistration' => sub {
376
    plan tests => 2;
377
378
    #purge unverified
379
    my $d=360;
380
    C4::Members::DeleteUnverifiedOpacRegistrations($d);
381
    foreach(1..3) {
382
        $dbh->do("INSERT INTO borrower_modifications (timestamp, borrowernumber, verification_token) VALUES ('2014-01-01 01:02:03',0,?)", undef, (scalar localtime)."_$_");
383
    }
384
    is( C4::Members::DeleteUnverifiedOpacRegistrations($d), 3, 'Test for DeleteUnverifiedOpacRegistrations' );
385
386
    #purge members in temporary category
387
    my $c= 'XYZ';
388
    $dbh->do("INSERT IGNORE INTO categories (categorycode) VALUES ('$c')");
389
    C4::Context->set_preference('PatronSelfRegistrationDefaultCategory', $c );
390
    C4::Context->set_preference('PatronSelfRegistrationExpireTemporaryAccountsDelay', 360);
391
    C4::Members::DeleteExpiredOpacRegistrations();
392
    $dbh->do("INSERT INTO borrowers (surname, address, city, branchcode, categorycode, dateenrolled) VALUES ('Testaabbcc', 'Street 1', 'CITY', 'CPL', '$c', '2014-01-01 01:02:03')");
393
    is( C4::Members::DeleteExpiredOpacRegistrations(), 1, 'Test for DeleteExpiredOpacRegistrations');
394
    $dbh->rollback();
395
};
396
375
sub _find_member {
397
sub _find_member {
376
    my ($resultset) = @_;
398
    my ($resultset) = @_;
377
    my $found = $resultset && grep( { $_->{cardnumber} && $_->{cardnumber} eq $CARDNUMBER } @$resultset );
399
    my $found = $resultset && grep( { $_->{cardnumber} && $_->{cardnumber} eq $CARDNUMBER } @$resultset );
378
- 

Return to bug 13049