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

(-)a/C4/Serials.pm (+5 lines)
Lines 1844-1849 sub DelSubscription { Link Here
1844
    $dbh->do("DELETE FROM subscriptionhistory WHERE subscriptionid=$subscriptionid");
1844
    $dbh->do("DELETE FROM subscriptionhistory WHERE subscriptionid=$subscriptionid");
1845
    $dbh->do("DELETE FROM serial WHERE subscriptionid=$subscriptionid");
1845
    $dbh->do("DELETE FROM serial WHERE subscriptionid=$subscriptionid");
1846
1846
1847
    my $afs = Koha::AdditionalField->all({tablename => 'subscription'});
1848
    foreach my $af (@$afs) {
1849
        $af->delete_values({record_id => $subscriptionid});
1850
    }
1851
1847
    logaction( "SERIAL", "DELETE", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog");
1852
    logaction( "SERIAL", "DELETE", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog");
1848
}
1853
}
1849
1854
(-)a/Koha/AdditionalField.pm (+31 lines)
Lines 134-139 sub fetch_values { Link Here
134
    }
134
    }
135
}
135
}
136
136
137
sub delete_values {
138
    my ($self, $args) = @_;
139
140
    my $record_id = $args->{record_id};
141
142
    my $dbh = C4::Context->dbh;
143
144
    my @where_strs = ('field_id = ?');
145
    my @where_args = ($self->{id});
146
147
    if ($record_id) {
148
        push @where_strs, 'record_id = ?';
149
        push @where_args, $record_id;
150
    }
151
152
    my $query = q{
153
        DELETE FROM additional_field_values
154
        WHERE
155
    } . join (' AND ', @where_strs);
156
157
    $dbh->do($query, undef, @where_args);
158
}
159
137
sub all {
160
sub all {
138
    my ( $class, $args ) = @_;
161
    my ( $class, $args ) = @_;
139
    die "BAD CALL: Don't use fetch_all_values as an instance method"
162
    die "BAD CALL: Don't use fetch_all_values as an instance method"
Lines 331-336 The record_id argument is optional. Link Here
331
        }
354
        }
332
    }
355
    }
333
356
357
=head2 delete_values
358
359
Delete values from the database for a given record_id.
360
The record_id argument is optional.
361
362
    my $af = Koha::AdditionalField({ id => $id })->fetch;
363
    $af->delete_values({record_id => $record_id});
364
334
=head2 all
365
=head2 all
335
366
336
Retrieve all additional fields in the database given some parameters.
367
Retrieve all additional fields in the database given some parameters.
(-)a/t/db_dependent/AdditionalField.t (-2 / +13 lines)
Lines 1-7 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 37;
4
use Test::More tests => 40;
5
5
6
use C4::Bookseller qw( AddBookseller );
6
use C4::Bookseller qw( AddBookseller );
7
use C4::Context;
7
use C4::Context;
Lines 288-292 is ( $exists, 1, "get_matching_record_ids: field common: common% matches subscri Link Here
288
$exists = grep /not_existent_id/, @$matching_record_ids;
288
$exists = grep /not_existent_id/, @$matching_record_ids;
289
is ( $exists, 0, "get_matching_record_ids: field common: common% does not inexistent id" );
289
is ( $exists, 0, "get_matching_record_ids: field common: common% does not inexistent id" );
290
290
291
# delete_values
292
$af1 = Koha::AdditionalField->new({ id => $af1->id })->fetch;
293
294
$af1->fetch_values;
295
is_deeply ( $af1->values, {$subscriptionid1 => qq|value_for_af1_$subscriptionid1|, $subscriptionid2 => qq|value_for_af1_$subscriptionid2| }, "fetch_values: without argument, returns 2 records" );
296
$af1->delete_values({record_id => $subscriptionid1});
297
$af1->fetch_values;
298
is_deeply ( $af1->values, {$subscriptionid2 => qq|value_for_af1_$subscriptionid2|}, "fetch_values: values for af2 and subscription2" );
299
$af1->delete_values;
300
$af1->fetch_values;
301
is_deeply ( $af1->values, {}, "fetch_values: no values" );
302
291
303
292
$dbh->rollback;
304
$dbh->rollback;
293
- 

Return to bug 10855