Bugzilla – Attachment 124605 Details for
Bug 24857
Add ability to group items for records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24857: (QA follow-up) Fix unit tests and code for changes in Koha::Item::delete
Bug-24857-QA-follow-up-Fix-unit-tests-and-code-for.patch (text/plain), 4.54 KB, created by
Martin Renvoize (ashimema)
on 2021-09-07 14:11:32 UTC
(
hide
)
Description:
Bug 24857: (QA follow-up) Fix unit tests and code for changes in Koha::Item::delete
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-09-07 14:11:32 UTC
Size:
4.54 KB
patch
obsolete
>From 8a825dd5dcf5c0ceb9b32ff34fe37a59974397c2 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Thu, 5 Nov 2020 14:48:41 -0500 >Subject: [PATCH] Bug 24857: (QA follow-up) Fix unit tests and code for changes > in Koha::Item::delete > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Biblio/Volume.pm | 2 +- > Koha/Item.pm | 21 ++++++++------------- > t/db_dependent/Koha/Volumes.t | 13 +++++++++---- > 3 files changed, 18 insertions(+), 18 deletions(-) > >diff --git a/Koha/Biblio/Volume.pm b/Koha/Biblio/Volume.pm >index 70633085fa..a5eda853dc 100644 >--- a/Koha/Biblio/Volume.pm >+++ b/Koha/Biblio/Volume.pm >@@ -68,7 +68,7 @@ sub items { > my $items_rs = $self->_result->volume_items; > my @item_numbers = $items_rs->get_column('itemnumber')->all; > >- return unless @item_numbers; >+ return Koha::Items->new->empty unless @item_numbers; > > return Koha::Items->search( > { >diff --git a/Koha/Item.pm b/Koha/Item.pm >index 1595f77069..cd51bf85e7 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -224,24 +224,18 @@ sub delete { > # FIXME check the item has no current issues > # i.e. raise the appropriate exception > >+ # Get the volume so we can delete it later if it has no items left >+ my $volume = C4::Context->preference('EnableVolumes') ? $self->volume : undef; >+ > my $result = $self->SUPER::delete; > >+ # Delete the volume if it has no items left >+ $volume->delete if ( $volume && $volume->items->count == 0 ); >+ > my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); > $indexer->index_records( $self->biblionumber, "specialUpdate", "biblioserver" ) > unless $params->{skip_record_index}; > >- if ( C4::Context->preference('EnableVolumes') ) { >- my $volume_item = >- Koha::Biblio::Volume::Items->find( { itemnumber => $self->itemnumber } ); >- my $volume_id = $volume_item ? $volume_item->volume_id : undef; >- >- # If this item is the last item on a volume, delete the volume as well >- if ($volume_id) { >- my $volume = Koha::Biblio::Volumes->find($volume_id); >- $volume->delete unless $volume->items->count > 1; >- } >- } >- > $self->_after_item_action_hooks({ action => 'delete' }); > > logaction( "CATALOGUING", "DELETE", $self->itemnumber, "item" ) >@@ -424,7 +418,8 @@ sub volume { > my $volume_rs = $volume_item->volume; > return unless $volume_rs; > >- return Koha::Biblio::Volume->_new_from_dbic( $volume_rs ); >+ my $volume = Koha::Biblio::Volume->_new_from_dbic( $volume_rs ); >+ return $volume; > } > > =head3 holds >diff --git a/t/db_dependent/Koha/Volumes.t b/t/db_dependent/Koha/Volumes.t >index 2930b83530..1d4b17f9d2 100644 >--- a/t/db_dependent/Koha/Volumes.t >+++ b/t/db_dependent/Koha/Volumes.t >@@ -73,11 +73,11 @@ subtest 'Test Koha::Biblio::Volume::add_item & Koha::Biblio::Volume::items' => s > > my $volume = Koha::Biblio::Volume->new( { biblionumber => $biblio->id } )->store(); > >- my @items = $volume->items; >- is( scalar(@items), 0, 'Volume has no items'); >+ my $items = $volume->items; >+ is( $items->count, 0, 'Volume has no items'); > > $volume->add_item({ item_id => $item_1->id }); >- @items = $volume->items->as_list; >+ my @items = $volume->items->as_list; > is( scalar(@items), 1, 'Volume has one item'); > is( $items[0]->id, $item_1->id, 'Item 1 is correct' ); > >@@ -117,7 +117,7 @@ subtest 'Test Koha::Item::volume' => sub { > > subtest 'Koha::Item::delete should delete volume if no other items are using the volume' => sub { > >- plan tests => 8; >+ plan tests => 11; > > $schema->storage->txn_begin; > >@@ -137,11 +137,16 @@ subtest 'Koha::Item::delete should delete volume if no other items are using the > my $volume = Koha::Biblio::Volumes->find( $volume_1->id ); > is( $volume->id, $volume_1->id, 'Found the correct volume'); > >+ is( $item_1->volume->id, $volume_1->id, 'Item 1 has correct volume'); >+ is( $item_2->volume->id, $volume_1->id, 'Item 2 has correct volume'); >+ > $item_1->delete(); > is( $biblio->items->count, 1, 'Bib has 2 item'); > $volume = Koha::Biblio::Volumes->find( $volume_1->id ); > is( $volume->id, $volume_1->id, 'Volume still exists after deleting and item, but other items remain'); > >+ is( $item_2->volume->id, $volume_1->id, 'Item 2 still has correct volume'); >+ > $item_2->delete(); > is( $biblio->items->count, 0, 'Bib has 0 items'); > $volume = Koha::Biblio::Volumes->find( $volume_1->id ); >-- >2.20.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 24857
:
100652
|
100653
|
100654
|
100655
|
100656
|
100657
|
100658
|
100659
|
100660
|
100661
|
100662
|
101637
|
101638
|
101639
|
101640
|
101641
|
101642
|
101643
|
101644
|
101645
|
101646
|
101647
|
101648
|
101650
|
101651
|
101652
|
101653
|
101654
|
101655
|
101656
|
101657
|
101658
|
101659
|
101660
|
101661
|
101670
|
101671
|
101672
|
101673
|
101674
|
101675
|
101676
|
101677
|
101678
|
101679
|
101680
|
101681
|
101730
|
101731
|
101732
|
101733
|
101734
|
101735
|
101736
|
101737
|
101738
|
101739
|
101740
|
101741
|
101752
|
101753
|
101754
|
101755
|
101756
|
101757
|
101758
|
101759
|
101760
|
101761
|
101762
|
101763
|
104952
|
104953
|
104954
|
104955
|
104956
|
104957
|
104958
|
104959
|
104960
|
104961
|
104962
|
104963
|
104964
|
104966
|
106728
|
106729
|
106730
|
106731
|
106732
|
106733
|
106734
|
106735
|
106736
|
106737
|
106738
|
106739
|
106740
|
106741
|
108443
|
108444
|
108445
|
108446
|
108447
|
108448
|
108449
|
108450
|
108451
|
108452
|
108453
|
108454
|
108455
|
108456
|
108666
|
108667
|
108668
|
108669
|
108670
|
108671
|
108672
|
108673
|
108674
|
108675
|
108676
|
108677
|
108678
|
108679
|
108680
|
108681
|
108682
|
108683
|
108684
|
108685
|
108686
|
109074
|
109075
|
109076
|
109077
|
109078
|
109079
|
109080
|
109081
|
109082
|
109083
|
109084
|
109085
|
109086
|
109087
|
109088
|
109089
|
109090
|
109091
|
109092
|
109093
|
109094
|
109795
|
109796
|
109797
|
109798
|
109799
|
109800
|
109801
|
109802
|
109803
|
109804
|
109805
|
109806
|
109807
|
109808
|
109809
|
109810
|
109811
|
109812
|
109813
|
109814
|
109815
|
109894
|
109901
|
109902
|
109903
|
109904
|
109905
|
109906
|
109907
|
109908
|
109909
|
109910
|
109911
|
109912
|
109913
|
109914
|
109915
|
109916
|
109917
|
109918
|
109919
|
109920
|
109921
|
109922
|
109923
|
113136
|
113137
|
113138
|
113139
|
113140
|
113141
|
113142
|
113143
|
113144
|
113145
|
113146
|
113147
|
113148
|
113149
|
113150
|
113151
|
113152
|
113153
|
113154
|
113155
|
113156
|
113157
|
113158
|
113159
|
113160
|
113168
|
113169
|
113170
|
113171
|
113172
|
113173
|
113174
|
113175
|
113176
|
113177
|
113178
|
113179
|
113180
|
113181
|
113182
|
113183
|
113184
|
113185
|
113186
|
113187
|
113188
|
113189
|
113190
|
113191
|
120495
|
120496
|
120497
|
120498
|
120499
|
120500
|
120501
|
120502
|
120503
|
120504
|
120505
|
120506
|
120507
|
120508
|
120509
|
120510
|
120511
|
120512
|
120513
|
120514
|
120515
|
120516
|
120517
|
120518
|
122808
|
122809
|
122810
|
122811
|
122812
|
122813
|
122814
|
122815
|
122816
|
122817
|
122818
|
122819
|
122820
|
122821
|
122822
|
122823
|
122824
|
122825
|
122826
|
122827
|
122828
|
122829
|
122830
|
122831
|
123882
|
123883
|
123884
|
123885
|
123886
|
123887
|
123888
|
123889
|
123890
|
123891
|
123892
|
123893
|
123894
|
123895
|
123896
|
123897
|
123898
|
123899
|
123900
|
123901
|
123902
|
123903
|
123904
|
123905
|
123906
|
123907
|
123908
|
123909
|
123910
|
123912
|
124021
|
124022
|
124023
|
124024
|
124025
|
124026
|
124027
|
124028
|
124029
|
124030
|
124031
|
124032
|
124033
|
124034
|
124035
|
124036
|
124037
|
124038
|
124039
|
124040
|
124041
|
124042
|
124043
|
124044
|
124045
|
124046
|
124047
|
124048
|
124049
|
124050
|
124051
|
124052
|
124053
|
124331
|
124332
|
124333
|
124334
|
124335
|
124336
|
124337
|
124338
|
124339
|
124340
|
124341
|
124342
|
124343
|
124344
|
124345
|
124346
|
124347
|
124348
|
124349
|
124351
|
124352
|
124353
|
124354
|
124355
|
124356
|
124357
|
124358
|
124359
|
124360
|
124361
|
124362
|
124363
|
124421
|
124463
|
124583
|
124584
|
124585
|
124586
|
124587
|
124588
|
124589
|
124590
|
124591
|
124592
|
124593
|
124594
|
124595
|
124596
|
124597
|
124598
|
124599
|
124600
|
124601
|
124602
|
124603
|
124604
|
124605
|
124606
|
124607
|
124608
|
124609
|
124610
|
124611
|
124612
|
124613
|
124614
|
124615
|
131449
|
131450
|
131451
|
131452
|
131453
|
131454
|
131455
|
131456
|
134288
|
134289
|
134290
|
134291
|
134292
|
134293
|
134294
|
134295
|
134296
|
135590
|
135591
|
135592
|
135593
|
135594
|
135595
|
135596
|
135597
|
135598
|
135599
|
135600
|
135601
|
135602
|
135603
|
135604
|
135605
|
135606
|
135607
|
135608
|
135609
|
135610
|
135614
|
135615
|
135616
|
135617
|
135618
|
135619
|
135620
|
135621
|
135622
|
135623
|
135624
|
135625
|
135626
|
135627
|
135628
|
135629
|
137259
|
137260
|
137261
|
137262
|
137263
|
137264
|
137265
|
137266
|
137267
|
137268
|
137311
|
137314
|
137315
|
137316
|
137317
|
137318
|
137319
|
137320
|
137321
|
137322
|
137323
|
137441
|
137442
|
137443
|
137608
|
138933