Bugzilla – Attachment 42310 Details for
Bug 10855
Custom fields for subscriptions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 10855: Remove additional field values when subscription is removed
Bug-10855-Remove-additional-field-values-when-subs.patch (text/plain), 3.46 KB, created by
Julian Maurice
on 2015-09-03 12:16:35 UTC
(
hide
)
Description:
Bug 10855: Remove additional field values when subscription is removed
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2015-09-03 12:16:35 UTC
Size:
3.46 KB
patch
obsolete
>From 93723dfc71afd042264dead1ff3ad6b870734d16 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Thu, 3 Sep 2015 14:05:07 +0200 >Subject: [PATCH] Bug 10855: Remove additional field values when subscription > is removed > >--- > C4/Serials.pm | 5 +++++ > Koha/AdditionalField.pm | 31 +++++++++++++++++++++++++++++++ > t/db_dependent/AdditionalField.t | 14 +++++++++++++- > 3 files changed, 49 insertions(+), 1 deletion(-) > >diff --git a/C4/Serials.pm b/C4/Serials.pm >index 9441dfe..435e17f 100644 >--- a/C4/Serials.pm >+++ b/C4/Serials.pm >@@ -1844,6 +1844,11 @@ sub DelSubscription { > $dbh->do("DELETE FROM subscriptionhistory WHERE subscriptionid=$subscriptionid"); > $dbh->do("DELETE FROM serial WHERE subscriptionid=$subscriptionid"); > >+ my $afs = Koha::AdditionalField->all({tablename => 'subscription'}); >+ foreach my $af (@$afs) { >+ $af->delete_values({record_id => $subscriptionid}); >+ } >+ > logaction( "SERIAL", "DELETE", $subscriptionid, "" ) if C4::Context->preference("SubscriptionLog"); > } > >diff --git a/Koha/AdditionalField.pm b/Koha/AdditionalField.pm >index aa00bb6..563a7f3 100644 >--- a/Koha/AdditionalField.pm >+++ b/Koha/AdditionalField.pm >@@ -134,6 +134,29 @@ sub fetch_values { > } > } > >+sub delete_values { >+ my ($self, $args) = @_; >+ >+ my $record_id = $args->{record_id}; >+ >+ my $dbh = C4::Context->dbh; >+ >+ my @where_strs = ('field_id = ?'); >+ my @where_args = ($self->{id}); >+ >+ if ($record_id) { >+ push @where_strs, 'record_id = ?'; >+ push @where_args, $record_id; >+ } >+ >+ my $query = q{ >+ DELETE FROM additional_field_values >+ WHERE >+ } . join (' AND ', @where_strs); >+ >+ $dbh->do($query, undef, @where_args); >+} >+ > sub all { > my ( $class, $args ) = @_; > die "BAD CALL: Don't use fetch_all_values as an instance method" >@@ -331,6 +354,14 @@ The record_id argument is optional. > } > } > >+=head2 delete_values >+ >+Delete values from the database for a given record_id. >+The record_id argument is optional. >+ >+ my $af = Koha::AdditionalField({ id => $id })->fetch; >+ $af->delete_values({record_id => $record_id}); >+ > =head2 all > > Retrieve all additional fields in the database given some parameters. >diff --git a/t/db_dependent/AdditionalField.t b/t/db_dependent/AdditionalField.t >index ed28580..91d6cd3 100644 >--- a/t/db_dependent/AdditionalField.t >+++ b/t/db_dependent/AdditionalField.t >@@ -1,7 +1,7 @@ > #!/usr/bin/perl > > use Modern::Perl; >-use Test::More tests => 37; >+use Test::More tests => 40; > > use C4::Bookseller qw( AddBookseller ); > use C4::Context; >@@ -288,5 +288,17 @@ is ( $exists, 1, "get_matching_record_ids: field common: common% matches subscri > $exists = grep /not_existent_id/, @$matching_record_ids; > is ( $exists, 0, "get_matching_record_ids: field common: common% does not inexistent id" ); > >+# delete_values >+$af1 = Koha::AdditionalField->new({ id => $af1->id })->fetch; >+ >+$af1->fetch_values; >+is_deeply ( $af1->values, {$subscriptionid1 => qq|value_for_af1_$subscriptionid1|, $subscriptionid2 => qq|value_for_af1_$subscriptionid2| }, "fetch_values: without argument, returns 2 records" ); >+$af1->delete_values({record_id => $subscriptionid1}); >+$af1->fetch_values; >+is_deeply ( $af1->values, {$subscriptionid2 => qq|value_for_af1_$subscriptionid2|}, "fetch_values: values for af2 and subscription2" ); >+$af1->delete_values; >+$af1->fetch_values; >+is_deeply ( $af1->values, {}, "fetch_values: no values" ); >+ > > $dbh->rollback; >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10855
:
20937
|
20938
|
20939
|
20940
|
20941
|
20942
|
20943
|
20944
|
21184
|
21185
|
21186
|
21187
|
21188
|
21189
|
21190
|
21191
|
21663
|
22049
|
22050
|
22051
|
22052
|
22053
|
22054
|
22055
|
22056
|
22057
|
22359
|
22360
|
22600
|
22601
|
22602
|
22603
|
22604
|
22605
|
22606
|
22607
|
22608
|
22616
|
22698
|
22699
|
22700
|
22701
|
22702
|
22703
|
22722
|
22768
|
22769
|
22869
|
23052
|
23053
|
23142
|
23143
|
23301
|
23302
|
23594
|
23595
|
23596
|
23597
|
23598
|
23599
|
23600
|
23601
|
23602
|
23774
|
23775
|
23961
|
23962
|
23963
|
23964
|
24452
|
24453
|
24454
|
24455
|
24456
|
24457
|
24569
|
24570
|
26091
|
26092
|
26093
|
26094
|
26095
|
26096
|
26097
|
26254
|
26255
|
26256
|
26257
|
26258
|
26259
|
26260
|
26276
|
26651
|
26655
|
28929
|
28930
|
28931
|
28932
|
28933
|
28934
|
28935
|
28936
|
28937
|
28938
|
28939
|
28940
|
28941
|
29095
|
29161
|
35211
|
35212
|
35213
|
35214
|
35215
|
35216
|
35217
|
35218
|
35219
|
35220
|
35221
|
35309
|
35310
|
35369
|
35556
|
36359
|
36362
|
36363
|
36364
|
36365
|
36366
|
36367
|
36368
|
36369
|
36370
|
36371
|
36372
|
36373
|
36374
|
38549
|
38550
|
38551
|
38552
|
38553
|
38554
|
38555
|
38556
|
38557
|
38558
|
38559
|
38560
|
38561
|
42296
|
42297
|
42298
|
42299
|
42300
|
42301
|
42302
|
42303
|
42304
|
42305
|
42306
|
42307
|
42308
|
42309
|
42310
|
42332
|
42333
|
43076