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

(-)a/C4/Members.pm (-18 lines)
Lines 46-52 BEGIN { Link Here
46
46
47
      IssueSlip
47
      IssueSlip
48
48
49
      DeleteUnverifiedOpacRegistrations
50
      DeleteExpiredOpacRegistrations
49
      DeleteExpiredOpacRegistrations
51
    );
50
    );
52
}
51
}
Lines 524-546 sub DeleteExpiredOpacRegistrations { Link Here
524
    return $cnt;
523
    return $cnt;
525
}
524
}
526
525
527
=head2 DeleteUnverifiedOpacRegistrations
528
529
    Delete all unverified self registrations in borrower_modifications,
530
    older than the specified number of days.
531
532
=cut
533
534
sub DeleteUnverifiedOpacRegistrations {
535
    my ( $days ) = @_;
536
    my $dbh = C4::Context->dbh;
537
    my $sql=qq|
538
DELETE FROM borrower_modifications
539
WHERE borrowernumber = 0 AND DATEDIFF( NOW(), timestamp ) > ?|;
540
    my $cnt=$dbh->do($sql, undef, ($days) );
541
    return $cnt eq '0E0'? 0: $cnt;
542
}
543
544
END { }    # module clean-up code here (global destructor)
526
END { }    # module clean-up code here (global destructor)
545
527
546
1;
528
1;
(-)a/misc/cronjobs/cleanup_database.pl (-9 / +10 lines)
Lines 522-532 if ($pExpSelfReg) { Link Here
522
        say "self-registered borrowers may be deleted";
522
        say "self-registered borrowers may be deleted";
523
    }
523
    }
524
}
524
}
525
525
if ($pUnvSelfReg) {
526
if ($pUnvSelfReg) {
526
    if ($confirm) {
527
    my $opac_registrations =
527
        DeleteUnverifiedSelfRegs($pUnvSelfReg);
528
        Koha::Patron::Modifications->search( { borrowernumber => 0 } )
528
    } elsif ($verbose) {
529
        ->filter_by_last_update( { days => $pUnvSelfReg } );
529
        say "unverified self-registrations may be deleted";
530
    my $count = $opac_registrations->count;
531
    $opac_registrations->delete if $confirm;
532
    if ($verbose) {
533
        say $confirm
534
            ? sprintf( "Done with removing %d unverified self-registrations",      $count )
535
            : sprintf( "%d unverified self-registrations would have been removed", $count );
530
    }
536
    }
531
}
537
}
532
538
Lines 907-917 sub DeleteExpiredSelfRegs { Link Here
907
    print "Removed $cnt expired self-registered borrowers\n" if $verbose;
913
    print "Removed $cnt expired self-registered borrowers\n" if $verbose;
908
}
914
}
909
915
910
sub DeleteUnverifiedSelfRegs {
911
    my $cnt = C4::Members::DeleteUnverifiedOpacRegistrations( $_[0] );
912
    print "Removed $cnt unverified self-registrations\n" if $verbose;
913
}
914
915
sub DeleteSpecialHolidays {
916
sub DeleteSpecialHolidays {
916
    my ($days) = @_;
917
    my ($days) = @_;
917
918
(-)a/t/db_dependent/Members.t (-14 / +2 lines)
Lines 33-39 use t::lib::Mocks; Link Here
33
use t::lib::TestBuilder;
33
use t::lib::TestBuilder;
34
34
35
BEGIN {
35
BEGIN {
36
        use_ok('C4::Members', qw( GetBorrowersToExpunge DeleteUnverifiedOpacRegistrations DeleteExpiredOpacRegistrations ));
36
        use_ok('C4::Members', qw( GetBorrowersToExpunge DeleteExpiredOpacRegistrations ));
37
}
37
}
38
38
39
my $schema = Koha::Database->schema;
39
my $schema = Koha::Database->schema;
Lines 389-406 $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; Link Here
389
ok( $borrower->{userid},  'A userid should have been generated correctly' );
389
ok( $borrower->{userid},  'A userid should have been generated correctly' );
390
390
391
subtest 'purgeSelfRegistration' => sub {
391
subtest 'purgeSelfRegistration' => sub {
392
    plan tests => 8;
392
    plan tests => 7;
393
394
    #purge unverified
395
    my $d=360;
396
    C4::Members::DeleteUnverifiedOpacRegistrations($d);
397
    foreach(1..3) {
398
        $dbh->do("INSERT INTO borrower_modifications (timestamp, borrowernumber, verification_token, changed_fields) VALUES ('2014-01-01 01:02:03',0,?,'firstname,surname')", undef, (scalar localtime)."_$_");
399
    }
400
    # Add a record with a borrowernumber which should not be deleted by DeleteUnverifiedOpacRegistrations
401
    # NOTE: We are using the borrowernumber from the last test outside this subtest
402
    $dbh->do( "INSERT INTO borrower_modifications (timestamp, borrowernumber, verification_token, changed_fields) VALUES ('2014-01-01 01:02:03', ?, '', 'firstname,surname' )", undef, $borrowernumber );
403
    is( C4::Members::DeleteUnverifiedOpacRegistrations($d), 3, 'Test for DeleteUnverifiedOpacRegistrations' );
404
393
405
    #purge members in temporary category
394
    #purge members in temporary category
406
    my $c= 'XYZ';
395
    my $c= 'XYZ';
407
- 

Return to bug 37844