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

(-)a/C4/Suggestions.pm (-3 / +4 lines)
Lines 185-199 sub DelSuggestion { Link Here
185
    $borrowernumber //= '';
185
    $borrowernumber //= '';
186
186
187
    if ( defined $type && $type eq 'intranet' || $suggestedby eq $borrowernumber ) {
187
    if ( defined $type && $type eq 'intranet' || $suggestedby eq $borrowernumber ) {
188
        my $suggestion = Koha::Suggestions->find($suggestionid);
189
        if ( C4::Context->preference("SuggestionsLog") ) {
190
            logaction( 'SUGGESTION', 'DELETE', $suggestionid, $suggestion, undef, $suggestion );
191
        }
188
        my $queryDelete = q{
192
        my $queryDelete = q{
189
            DELETE FROM suggestions
193
            DELETE FROM suggestions
190
            WHERE suggestionid=?
194
            WHERE suggestionid=?
191
        };
195
        };
192
        $sth = $dbh->prepare($queryDelete);
196
        $sth = $dbh->prepare($queryDelete);
193
        my $suggestiondeleted = $sth->execute($suggestionid);
197
        my $suggestiondeleted = $sth->execute($suggestionid);
194
        if ( C4::Context->preference("SuggestionsLog") ) {
195
            logaction( 'SUGGESTION', 'DELETE', $suggestionid, '' );
196
        }
197
        return $suggestiondeleted;
198
        return $suggestiondeleted;
198
    }
199
    }
199
}
200
}
(-)a/Koha/Suggestion.pm (-2 / +9 lines)
Lines 71-82 sub store { Link Here
71
    my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions");
71
    my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions");
72
72
73
    my $new_suggestion = !$self->in_storage;
73
    my $new_suggestion = !$self->in_storage;
74
    my $original       = $new_suggestion ? undef : $self->get_from_storage->unblessed;
74
75
75
    my $result = $self->SUPER::store();
76
    my $result = $self->SUPER::store();
76
77
77
    if ( C4::Context->preference("SuggestionsLog") ) {
78
    if ( C4::Context->preference("SuggestionsLog") ) {
78
        my $action = $new_suggestion ? 'CREATE' : 'MODIFY';
79
        if ($new_suggestion) {
79
        logaction( 'SUGGESTION', $action, $result->suggestionid, $self );
80
            logaction(
81
                'SUGGESTION', 'CREATE', $result->suggestionid, undef, undef,
82
                $result->get_from_storage->unblessed
83
            );
84
        } else {
85
            logaction( 'SUGGESTION', 'MODIFY', $result->suggestionid, $result, undef, $original );
86
        }
80
    }
87
    }
81
88
82
    if ( $emailpurchasesuggestions && $self->STATUS eq 'ASKED' ) {
89
    if ( $emailpurchasesuggestions && $self->STATUS eq 'ASKED' ) {
(-)a/t/db_dependent/Koha/Suggestions.t (-2 / +49 lines)
Lines 20-29 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 12;
23
use Test::More tests => 13;
24
use Test::Exception;
24
use Test::Exception;
25
use Test::Warn;
25
use Test::Warn;
26
26
27
use C4::Suggestions qw( DelSuggestion );
28
use Koha::ActionLogs;
27
use Koha::Suggestions;
29
use Koha::Suggestions;
28
use Koha::Notice::Messages;
30
use Koha::Notice::Messages;
29
use Koha::Database;
31
use Koha::Database;
Lines 513-515 subtest 'filter_by_suggested_days_range() tests' => sub { Link Here
513
515
514
    $schema->storage->txn_rollback;
516
    $schema->storage->txn_rollback;
515
};
517
};
516
- 
518
519
subtest 'Suggestion action logs populate the diff column' => sub {
520
521
    plan tests => 9;
522
523
    $schema->storage->txn_begin;
524
525
    t::lib::Mocks::mock_preference( 'SuggestionsLog', 1 );
526
527
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
528
529
    # CREATE
530
    my $suggestion = Koha::Suggestion->new(
531
        {
532
            suggestedby => $patron->borrowernumber,
533
            title       => 'Test title',
534
        }
535
    )->store;
536
    my $suggestionid = $suggestion->suggestionid;
537
538
    my $create_log =
539
        Koha::ActionLogs->search( { module => 'SUGGESTION', action => 'CREATE', object => $suggestionid } )->single;
540
    ok( defined $create_log,       'CREATE log entry exists' );
541
    ok( defined $create_log->diff, 'diff column is populated for CREATE' );
542
    like( $create_log->diff, qr/title/, 'CREATE diff contains suggestion fields' );
543
544
    # MODIFY
545
    $suggestion->title('Updated title')->store;
546
547
    my $modify_log =
548
        Koha::ActionLogs->search( { module => 'SUGGESTION', action => 'MODIFY', object => $suggestionid } )->single;
549
    ok( defined $modify_log,       'MODIFY log entry exists' );
550
    ok( defined $modify_log->diff, 'diff column is populated for MODIFY' );
551
    like( $modify_log->diff, qr/title/, 'MODIFY diff contains changed field' );
552
553
    # DELETE via DelSuggestion
554
    C4::Suggestions::DelSuggestion( undef, $suggestionid, 'intranet' );
555
556
    my $delete_log =
557
        Koha::ActionLogs->search( { module => 'SUGGESTION', action => 'DELETE', object => $suggestionid } )->single;
558
    ok( defined $delete_log,       'DELETE log entry exists' );
559
    ok( defined $delete_log->diff, 'diff column is populated for DELETE' );
560
    like( $delete_log->diff, qr/title/, 'DELETE diff contains suggestion fields' );
561
562
    $schema->storage->txn_rollback;
563
};

Return to bug 42030