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

(-)a/C4/Suggestions.pm (-1 / +2 lines)
Lines 588-599 sub DelSuggestion { Link Here
588
    &DelSuggestionsOlderThan($days)
588
    &DelSuggestionsOlderThan($days)
589
589
590
    Delete all suggestions older than TODAY-$days , that have be accepted or rejected.
590
    Delete all suggestions older than TODAY-$days , that have be accepted or rejected.
591
    We do now allow a negative number. If you want to delete all suggestions, just use Koha::Suggestions->delete or so.
591
592
592
=cut
593
=cut
593
594
594
sub DelSuggestionsOlderThan {
595
sub DelSuggestionsOlderThan {
595
    my ($days) = @_;
596
    my ($days) = @_;
596
    return unless $days;
597
    return unless $days && $days > 0;
597
    my $dbh = C4::Context->dbh;
598
    my $dbh = C4::Context->dbh;
598
    my $sth = $dbh->prepare(
599
    my $sth = $dbh->prepare(
599
        q{
600
        q{
(-)a/t/db_dependent/Suggestions.t (-3 / +35 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use DateTime::Duration;
20
use DateTime::Duration;
21
use Test::More tests => 102;
21
use Test::More tests => 103;
22
use Test::Warn;
22
use Test::Warn;
23
23
24
use t::lib::Mocks;
24
use t::lib::Mocks;
Lines 29-37 use C4::Members; Link Here
29
use C4::Letters;
29
use C4::Letters;
30
use C4::Budgets qw( AddBudgetPeriod AddBudget );
30
use C4::Budgets qw( AddBudgetPeriod AddBudget );
31
use Koha::Database;
31
use Koha::Database;
32
use Koha::DateUtils qw( dt_from_string );
32
use Koha::DateUtils qw( dt_from_string output_pref );
33
use Koha::Library;
33
use Koha::Library;
34
use Koha::Libraries;
34
use Koha::Libraries;
35
use Koha::Suggestions;
35
36
36
BEGIN {
37
BEGIN {
37
    use_ok('C4::Suggestions');
38
    use_ok('C4::Suggestions');
Lines 382-385 subtest 'GetUnprocessedSuggestions' => sub { Link Here
382
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' );
383
    is( scalar(@$unprocessed_suggestions), 0, 'GetUnprocessedSuggestions should not return the suggestion, it has not been suggested 5 days ago' );
383
};
384
};
384
385
386
subtest 'DelSuggestionsOlderThan' => sub {
387
    plan tests => 6;
388
389
    Koha::Suggestions->delete;
390
391
    # Add four suggestions; note that STATUS needs uppercase (FIXME)
392
    my $d1 = output_pref({ dt => dt_from_string->add(days => -2), dateformat => 'sql' });
393
    my $d2 = output_pref({ dt => dt_from_string->add(days => -4), dateformat => 'sql' });
394
    my $sugg01 = $builder->build({ source => 'Suggestion', value => { date => $d1, STATUS => 'ASKED' }});
395
    my $sugg02 = $builder->build({ source => 'Suggestion', value => { date => $d1, STATUS => 'CHECKED' }});
396
    my $sugg03 = $builder->build({ source => 'Suggestion', value => { date => $d2, STATUS => 'ASKED' }});
397
    my $sugg04 = $builder->build({ source => 'Suggestion', value => { date => $d2, STATUS => 'ACCEPTED' }});
398
399
    # Test no parameter: should do nothing
400
    C4::Suggestions::DelSuggestionsOlderThan();
401
    is( Koha::Suggestions->count, 4, 'No suggestions deleted' );
402
    # Test zero: should do nothing too
403
    C4::Suggestions::DelSuggestionsOlderThan(0);
404
    is( Koha::Suggestions->count, 4, 'No suggestions deleted again' );
405
    # Test negative value
406
    C4::Suggestions::DelSuggestionsOlderThan(-1);
407
    is( Koha::Suggestions->count, 4, 'No suggestions deleted for -1' );
408
409
    # Test positive values
410
    C4::Suggestions::DelSuggestionsOlderThan(5);
411
    is( Koha::Suggestions->count, 4, 'No suggestions>5d deleted' );
412
    C4::Suggestions::DelSuggestionsOlderThan(3);
413
    is( Koha::Suggestions->count, 3, '1 suggestions>3d deleted' );
414
    C4::Suggestions::DelSuggestionsOlderThan(1);
415
    is( Koha::Suggestions->count, 2, '1 suggestions>1d deleted' );
416
};
417
385
$schema->storage->txn_rollback;
418
$schema->storage->txn_rollback;
386
- 

Return to bug 13287