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

(-)a/C4/Suggestions.pm (-39 lines)
Lines 32-38 use C4::Log qw(logaction); Link Here
32
use base qw(Exporter);
32
use base qw(Exporter);
33
33
34
our @EXPORT = qw(
34
our @EXPORT = qw(
35
    DelSuggestion
36
    ModStatus
35
    ModStatus
37
    ModSuggestion
36
    ModSuggestion
38
    MarcRecordFromNewSuggestion
37
    MarcRecordFromNewSuggestion
Lines 134-177 sub ModSuggestion { Link Here
134
    return 1;    # No useful if the exception is raised earlier
133
    return 1;    # No useful if the exception is raised earlier
135
}
134
}
136
135
137
=head2 DelSuggestion
138
139
&DelSuggestion($borrowernumber,$ordernumber)
140
141
Delete a suggestion. A borrower can delete a suggestion only if they are its owner.
142
143
=cut
144
145
sub DelSuggestion {
146
    my ( $borrowernumber, $suggestionid, $type ) = @_;
147
    my $dbh = C4::Context->dbh;
148
149
    # check that the suggestion comes from the suggestor
150
    my $query = q{
151
        SELECT suggestedby
152
        FROM   suggestions
153
        WHERE  suggestionid=?
154
    };
155
    my $sth = $dbh->prepare($query);
156
    $sth->execute($suggestionid);
157
    my ($suggestedby) = $sth->fetchrow;
158
    $suggestedby    //= '';
159
    $borrowernumber //= '';
160
161
    if ( defined $type && $type eq 'intranet' || $suggestedby eq $borrowernumber ) {
162
        my $queryDelete = q{
163
            DELETE FROM suggestions
164
            WHERE suggestionid=?
165
        };
166
        $sth = $dbh->prepare($queryDelete);
167
        my $suggestiondeleted = $sth->execute($suggestionid);
168
        if ( C4::Context->preference("SuggestionsLog") ) {
169
            logaction( 'SUGGESTION', 'DELETE', $suggestionid, '' );
170
        }
171
        return $suggestiondeleted;
172
    }
173
}
174
175
=head2 MarcRecordFromNewSuggestion
136
=head2 MarcRecordFromNewSuggestion
176
137
177
    $record = MarcRecordFromNewSuggestion ( $suggestion )
138
    $record = MarcRecordFromNewSuggestion ( $suggestion )
(-)a/Koha/Suggestion.pm (+14 lines)
Lines 123-128 sub store { Link Here
123
    return $result;
123
    return $result;
124
}
124
}
125
125
126
=head3 delete
127
128
Overloads the default  behavior so that it becomes logged
129
130
=cut
131
132
sub delete {
133
    my ($self) = @_;
134
    if ( C4::Context->preference("SuggestionsLog") ) {
135
        logaction( 'SUGGESTION', 'DELETE', $self->suggestionid, '' );
136
    }
137
    $self->SUPER::delete();
138
}
139
126
=head3 library
140
=head3 library
127
141
128
my $library = $suggestion->library;
142
my $library = $suggestion->library;
(-)a/opac/opac-suggestions.pl (-2 / +6 lines)
Lines 24-30 use C4::Members; Link Here
24
use C4::Koha        qw( GetAuthorisedValues );
24
use C4::Koha        qw( GetAuthorisedValues );
25
use C4::Output      qw( output_html_with_http_headers );
25
use C4::Output      qw( output_html_with_http_headers );
26
use C4::Suggestions qw(
26
use C4::Suggestions qw(
27
    DelSuggestion
28
    MarcRecordFromNewSuggestion
27
    MarcRecordFromNewSuggestion
29
);
28
);
30
use C4::Koha qw( GetAuthorisedValues );
29
use C4::Koha qw( GetAuthorisedValues );
Lines 251-257 my $suggestions = [ Link Here
251
if ( $op eq "cud-delete" ) {
250
if ( $op eq "cud-delete" ) {
252
    my @delete_field = $input->multi_param("delete_field");
251
    my @delete_field = $input->multi_param("delete_field");
253
    foreach my $delete_field (@delete_field) {
252
    foreach my $delete_field (@delete_field) {
254
        &DelSuggestion( $borrowernumber, $delete_field );
253
        Koha::Suggestions->search(
254
            {
255
                suggestedby  => $borrowernumber,
256
                suggestionid => $delete_field
257
            }
258
        )->single->delete;
255
    }
259
    }
256
    $op = 'else';
260
    $op = 'else';
257
    print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else");
261
    print $input->redirect("/cgi-bin/koha/opac-suggestions.pl?op=else");
(-)a/suggestion/suggestion.pl (-1 / +1 lines)
Lines 347-353 if ( $op =~ /cud-save/ ) { Link Here
347
} elsif ( $op eq "cud-delete" ) {
347
} elsif ( $op eq "cud-delete" ) {
348
    if ( $librarian->has_permission( { 'suggestions' => 'suggestions_delete' } ) ) {
348
    if ( $librarian->has_permission( { 'suggestions' => 'suggestions_delete' } ) ) {
349
        foreach my $delete_field (@editsuggestions) {
349
        foreach my $delete_field (@editsuggestions) {
350
            &DelSuggestion( $borrowernumber, $delete_field, 'intranet' );
350
            Koha::Suggestions->find( { suggestionid => $delete_field } )->delete();
351
        }
351
        }
352
        redirect_with_params($input);
352
        redirect_with_params($input);
353
    } else {
353
    } else {
(-)a/t/db_dependent/Suggestions.t (-14 / +2 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use DateTime::Duration;
20
use DateTime::Duration;
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::More tests => 50;
22
use Test::More tests => 44;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 38-44 use Koha::Suggestions; Link Here
38
BEGIN {
38
BEGIN {
39
    use_ok(
39
    use_ok(
40
        'C4::Suggestions',
40
        'C4::Suggestions',
41
        qw( ModSuggestion DelSuggestion MarcRecordFromNewSuggestion )
41
        qw( ModSuggestion MarcRecordFromNewSuggestion )
42
    );
42
    );
43
}
43
}
44
44
Lines 320-337 my $del_suggestion = { Link Here
320
my $del_suggestion_object = Koha::Suggestion->new($del_suggestion)->store();
320
my $del_suggestion_object = Koha::Suggestion->new($del_suggestion)->store();
321
my $del_suggestionid      = $del_suggestion_object->id;
321
my $del_suggestionid      = $del_suggestion_object->id;
322
322
323
is( DelSuggestion(),                '0E0', 'DelSuggestion without arguments returns 0E0' );
324
is( DelSuggestion($borrowernumber), '',    'DelSuggestion without the suggestion id returns an empty string' );
325
is(
326
    DelSuggestion( undef, $my_suggestionid ), '',
327
    'DelSuggestion with an invalid borrower number returns an empty string'
328
);
329
$suggestion = DelSuggestion( $borrowernumber, $my_suggestionid );
330
is( $suggestion, 1, 'DelSuggestion deletes one suggestion' );
331
332
my $suggestions = Koha::Suggestions->search( { STATUS => 'CHECKED' } )->as_list;
323
my $suggestions = Koha::Suggestions->search( { STATUS => 'CHECKED' } )->as_list;
333
is( @$suggestions,                           2,                        'DelSuggestion deletes one suggestion' );
334
is( $suggestions->[1]->unblessed()->{title}, $del_suggestion->{title}, 'DelSuggestion deletes the correct suggestion' );
335
324
336
# Test budgetid fk
325
# Test budgetid fk
337
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
326
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
338
- 

Return to bug 39730