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

(-)a/C4/Members.pm (+55 lines)
Lines 2465-2470 sub GetBorrowersWithEmail { Link Here
2465
    return @result;
2465
    return @result;
2466
}
2466
}
2467
2467
2468
=head2 AddMember_Opac
2469
2470
=cut
2471
2468
sub AddMember_Opac {
2472
sub AddMember_Opac {
2469
    my ( %borrower ) = @_;
2473
    my ( %borrower ) = @_;
2470
2474
Lines 2511-2516 sub AddEnrolmentFeeIfNeeded { Link Here
2511
    }
2515
    }
2512
}
2516
}
2513
2517
2518
=head2 HasOverdues
2519
2520
=cut
2521
2514
sub HasOverdues {
2522
sub HasOverdues {
2515
    my ( $borrowernumber ) = @_;
2523
    my ( $borrowernumber ) = @_;
2516
2524
Lines 2522-2527 sub HasOverdues { Link Here
2522
    return $count;
2530
    return $count;
2523
}
2531
}
2524
2532
2533
=head2 DeleteExpiredOpacRegistrations
2534
2535
    Delete accounts that haven't been upgraded from the 'temporary' category
2536
    Returns the number of removed patrons
2537
2538
=cut
2539
2540
sub DeleteExpiredOpacRegistrations {
2541
2542
    my $delay = C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay');
2543
    my $category_code = C4::Context->preference('PatronSelfRegistrationDefaultCategory');
2544
2545
    return 0 if not $category_code or not defined $delay or $delay eq q||;
2546
2547
    my $query = qq|
2548
SELECT borrowernumber
2549
FROM borrowers
2550
WHERE categorycode = ? AND DATEDIFF( NOW(), dateenrolled ) > ? |;
2551
2552
    my $dbh = C4::Context->dbh;
2553
    my $sth = $dbh->prepare($query);
2554
    $sth->execute( $category_code, $delay );
2555
    my $cnt=0;
2556
    while ( my ($borrowernumber) = $sth->fetchrow_array() ) {
2557
        DelMember($borrowernumber);
2558
        $cnt++;
2559
    }
2560
    return $cnt;
2561
}
2562
2563
=head2 DeleteUnverifiedOpacRegistrations
2564
2565
    Delete all unverified self registrations in borrower_modifications,
2566
    older than the specified number of days.
2567
2568
=cut
2569
2570
sub DeleteUnverifiedOpacRegistrations {
2571
    my ( $days ) = @_;
2572
    my $dbh = C4::Context->dbh;
2573
    my $sql=qq|
2574
DELETE FROM borrower_modifications
2575
WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|;
2576
    my $cnt=$dbh->do($sql, undef, ($days) );
2577
    return $cnt eq '0E0'? 0: $cnt;
2578
}
2579
2525
END { }    # module clean-up code here (global destructor)
2580
END { }    # module clean-up code here (global destructor)
2526
2581
2527
1;
2582
1;
(-)a/misc/cronjobs/cleanup_database.pl (-5 / +41 lines)
Lines 69-82 Usage: $0 [-h|--help] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueu Link Here
69
   --restrictions DAYS   purge patrons restrictions expired since more than DAYS days.
69
   --restrictions DAYS   purge patrons restrictions expired since more than DAYS days.
70
                         Defaults to 30 days if no days specified.
70
                         Defaults to 30 days if no days specified.
71
    --all-restrictions   purge all expired patrons restrictions.
71
    --all-restrictions   purge all expired patrons restrictions.
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
}
75
77
76
my (
78
my (
77
    $help,   $sessions,          $sess_days, $verbose, $zebraqueue_days,
79
    $help,
78
    $mail,   $purge_merged,      $pImport,   $pLogs,   $pSearchhistory,
80
    $sessions,
79
    $pZ3950, $pListShareInvites, $pDebarments, $allDebarments,
81
    $sess_days,
82
    $verbose,
83
    $zebraqueue_days,
84
    $mail,
85
    $purge_merged,
86
    $pImport,
87
    $pLogs,
88
    $pSearchhistory,
89
    $pZ3950,
90
    $pListShareInvites,
91
    $pDebarments,
92
    $allDebarments,
93
    $pExpSelfReg,
94
    $pUnvSelfReg,
80
);
95
);
81
96
82
GetOptions(
97
GetOptions(
Lines 94-99 GetOptions( Link Here
94
    'list-invites:i'  => \$pListShareInvites,
109
    'list-invites:i'  => \$pListShareInvites,
95
    'restrictions:i'  => \$pDebarments,
110
    'restrictions:i'  => \$pDebarments,
96
    'all-restrictions' => \$allDebarments,
111
    'all-restrictions' => \$allDebarments,
112
    'del-exp-selfreg' => \$pExpSelfReg,
113
    'del-unv-selfreg' => \$pUnvSelfReg,
97
) || usage(1);
114
) || usage(1);
98
115
99
# Use default values
116
# Use default values
Lines 120-127 unless ( $sessions Link Here
120
    || $pZ3950
137
    || $pZ3950
121
    || $pListShareInvites
138
    || $pListShareInvites
122
    || $pDebarments
139
    || $pDebarments
123
    || $allDebarments )
140
    || $allDebarments
124
{
141
    || $pExpSelfReg
142
    || $pUnvSelfReg
143
) {
125
    print "You did not specify any cleanup work for the script to do.\n\n";
144
    print "You did not specify any cleanup work for the script to do.\n\n";
126
    usage(1);
145
    usage(1);
127
}
146
}
Lines 253-258 if($allDebarments) { Link Here
253
    print "$count restrictions were deleted.\nDone with all restrictions purge.\n" if $verbose;
272
    print "$count restrictions were deleted.\nDone with all restrictions purge.\n" if $verbose;
254
}
273
}
255
274
275
if( $pExpSelfReg ) {
276
    DeleteExpiredSelfRegs();
277
}
278
if( $pUnvSelfReg ) {
279
    DeleteUnverifiedSelfRegs( $pUnvSelfReg );
280
}
281
256
exit(0);
282
exit(0);
257
283
258
sub RemoveOldSessions {
284
sub RemoveOldSessions {
Lines 340-342 sub PurgeDebarments { Link Here
340
    }
366
    }
341
    return $count;
367
    return $count;
342
}
368
}
369
370
sub DeleteExpiredSelfRegs {
371
    my $cnt= C4::Members::DeleteExpiredOpacRegistrations();
372
    print "Removed $cnt expired self-registered borrowers\n" if $verbose;
373
}
374
375
sub DeleteUnverifiedSelfRegs {
376
    my $cnt= C4::Members::DeleteUnverifiedOpacRegistrations( $_[0] );
377
    print "Removed $cnt unverified self-registrations\n" if $verbose;
378
}
(-)a/misc/cronjobs/delete_expired_opac_registrations.pl (-30 / +6 lines)
Lines 43-48 GetOptions( Link Here
43
);
43
);
44
my $usage = << 'ENDUSAGE';
44
my $usage = << 'ENDUSAGE';
45
45
46
IMPORTANT: You should no longer call this script. Please use
47
cleanup_database.pl with parameter --del-exp-selfreg.
48
46
This script removes confirmed OPAC based patron registrations
49
This script removes confirmed OPAC based patron registrations
47
that have not been changed from the patron category specified
50
that have not been changed from the patron category specified
48
in the system preference PatronSelfRegistrationDefaultCategory
51
in the system preference PatronSelfRegistrationDefaultCategory
Lines 64-96 if ( $help || !$confirm ) { Link Here
64
    exit;
67
    exit;
65
}
68
}
66
69
67
cronlogaction();
70
my $c= "$FindBin::Bin/cleanup_database.pl --del-exp-selfreg";
68
71
$c.= " -v" if $verbose;
69
# Delete accounts that haven't been upgraded from the 'temporary' category code
72
system($c);
70
my $delay =
71
  C4::Context->preference('PatronSelfRegistrationExpireTemporaryAccountsDelay');
72
my $category_code =
73
  C4::Context->preference('PatronSelfRegistrationDefaultCategory');
74
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||;
77
78
my $query = "
79
    SELECT borrowernumber
80
    FROM borrowers
81
    WHERE
82
        categorycode = ?
83
      AND
84
        DATEDIFF( NOW(), dateenrolled ) > ?
85
";
86
87
my $dbh = C4::Context->dbh;
88
my $sth = $dbh->prepare($query);
89
$sth->execute( $category_code, $delay );
90
91
my $cnt=0;
92
while ( my ($borrowernumber) = $sth->fetchrow_array() ) {
93
    DelMember($borrowernumber);
94
    $cnt++;
95
}
96
print "Removed $cnt expired self-registered borrowers in category $category_code\n" if $verbose;
(-)a/misc/cronjobs/delete_unverified_opac_registrations.pl (-11 / +6 lines)
Lines 43-48 GetOptions( Link Here
43
);
43
);
44
my $usage = << 'ENDUSAGE';
44
my $usage = << 'ENDUSAGE';
45
45
46
IMPORTANT: You should no longer call this script. Please use
47
cleanup_database.pl with parameter --del-unv-selfreg.
48
46
This script removes unconfirmed OPAC based patron registrations
49
This script removes unconfirmed OPAC based patron registrations
47
that have not been confirmed within the required time period.
50
that have not been confirmed within the required time period.
48
51
Lines 60-73 if ( $help || !$confirm ) { Link Here
60
    exit;
63
    exit;
61
}
64
}
62
65
63
cronlogaction();
66
my $d= $hours>=24? int($hours/24): 1;
64
67
my $c= "$FindBin::Bin/cleanup_database.pl -del-unv-selfreg $d";
65
my $dbh = C4::Context->dbh;
68
system($c);
66
67
$dbh->do( "
68
         DELETE FROM borrower_modifications
69
         WHERE
70
             borrowernumber = 0
71
           AND
72
             TIME_TO_SEC( TIMEDIFF( NOW(), timestamp )) / 3600 > ?
73
", 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 => 61;
20
use Test::More tests => 62;
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 314-319 subtest 'GetMemberAccountBalance' => sub { Link Here
314
    $dbh->rollback();
314
    $dbh->rollback();
315
};
315
};
316
316
317
subtest 'purgeSelfRegistration' => sub {
318
    plan tests => 2;
319
320
    #purge unverified
321
    my $d=360;
322
    C4::Members::DeleteUnverifiedOpacRegistrations($d);
323
    foreach(1..3) {
324
        $dbh->do("INSERT INTO borrower_modifications (timestamp, borrowernumber, verification_token) VALUES ('2014-01-01 01:02:03',0,?)", undef, (scalar localtime)."_$_");
325
    }
326
    is( C4::Members::DeleteUnverifiedOpacRegistrations($d), 3, 'Test for DeleteUnverifiedOpacRegistrations' );
327
328
    #purge members in temporary category
329
    my $c= 'XYZ';
330
    $dbh->do("INSERT IGNORE INTO categories (categorycode) VALUES ('$c')");
331
    C4::Context->set_preference('PatronSelfRegistrationDefaultCategory', $c );
332
    C4::Context->set_preference('PatronSelfRegistrationExpireTemporaryAccountsDelay', 360);
333
    C4::Members::DeleteExpiredOpacRegistrations();
334
    $dbh->do("INSERT INTO borrowers (surname, address, city, branchcode, categorycode, dateenrolled) VALUES ('Testaabbcc', 'Street 1', 'CITY', 'CPL', '$c', '2014-01-01 01:02:03')");
335
    is( C4::Members::DeleteExpiredOpacRegistrations(), 1, 'Test for DeleteExpiredOpacRegistrations');
336
    $dbh->rollback();
337
};
338
317
sub _find_member {
339
sub _find_member {
318
    my ($resultset) = @_;
340
    my ($resultset) = @_;
319
    my $found = $resultset && grep( { $_->{cardnumber} && $_->{cardnumber} eq $CARDNUMBER } @$resultset );
341
    my $found = $resultset && grep( { $_->{cardnumber} && $_->{cardnumber} eq $CARDNUMBER } @$resultset );
320
- 

Return to bug 13049