Bugzilla – Attachment 159828 Details for
Bug 33036
Add route to merge bibliographic records
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33036: Use Koha::Objects
Bug-33036-Use-KohaObjects.patch (text/plain), 7.00 KB, created by
Jonathan Druart
on 2023-12-14 10:29:09 UTC
(
hide
)
Description:
Bug 33036: Use Koha::Objects
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-12-14 10:29:09 UTC
Size:
7.00 KB
patch
obsolete
>From 10dbaaa4c995f68b5d568a47f7967dcca410b3e9 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 14 Dec 2023 10:55:42 +0100 >Subject: [PATCH] Bug 33036: Use Koha::Objects > >Better to use Koha::Objects everywhere and have the same pattern for the >different related objects. >--- > Koha/Biblio.pm | 69 ++++++++++++++++++++++++++----- > t/db_dependent/Koha/Biblio.t | 78 +++++++++++++++++++++++++++++++++++- > 2 files changed, 137 insertions(+), 10 deletions(-) > >diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm >index 42a835b0981..0b4cd67898c 100644 >--- a/Koha/Biblio.pm >+++ b/Koha/Biblio.pm >@@ -995,6 +995,34 @@ sub subscriptions { > return Koha::Subscriptions->_new_from_dbic($rs); > } > >+=head3 serials >+ >+my $serials = $self->serials >+ >+Returns the related Koha::Serials object for this Biblio object >+ >+=cut >+ >+sub serials { >+ my ($self) = @_; >+ my $rs = $self->_result->serials; >+ return Koha::Serials->_new_from_dbic($rs); >+} >+ >+=head3 subscription_histories >+ >+my $subscription_histories = $self->subscription_histories >+ >+Returns the related Koha::Subscription::Histories object for this Biblio object >+ >+=cut >+ >+sub subscription_histories { >+ my ($self) = @_; >+ my $rs = $self->_result->subscriptionhistories; >+ return Koha::Subscription::Histories->_new_from_dbic($rs); >+} >+ > =head3 has_items_waiting_or_intransit > > my $itemsWaitingOrInTransit = $biblio->has_items_waiting_or_intransit >@@ -1953,27 +1981,50 @@ sub merge_with { > foreach my $bn_merge (@biblio_ids_to_merge) { > my $from_biblio = Koha::Biblios->find($bn_merge); > $from_biblio->items->move_to_biblio($self); >+ >+ # Move article requests > $from_biblio->article_requests->update( > { biblionumber => $ref_biblionumber }, > { no_triggers => 1 } > ); > >- for my $resultset_name (qw(Subscription Subscriptionhistory Serial Suggestion)) { >- $schema->resultset($resultset_name)->search( { biblionumber => $bn_merge } ) >- ->update( { biblionumber => $ref_biblionumber } ); >- } >+ # Move subscriptions >+ $from_biblio->subscriptions->update( >+ { biblionumber => $ref_biblionumber }, >+ { no_triggers => 1 } >+ ); > >- # TODO should this be ported to more modern DB usage (i.e. DBIx::Class)? >- my @allorders = GetOrdersByBiblionumber($bn_merge); >- foreach my $myorder (@allorders) { >- $myorder->{'biblionumber'} = $ref_biblionumber; >- ModOrder($myorder); >+ # Move subscription histories >+ $from_biblio->subscription_histories->update( >+ { biblionumber => $ref_biblionumber }, >+ { no_triggers => 1 } >+ ); >+ >+ # Move serials >+ $from_biblio->serials->update( >+ { biblionumber => $ref_biblionumber }, >+ { no_triggers => 1 } >+ ); >+ >+ # Move suggestions >+ $from_biblio->suggestions->update( >+ { biblionumber => $ref_biblionumber }, >+ { no_triggers => 1 } >+ ); >+ >+ my $orders = $from_biblio->orders->unblessed; >+ for my $order (@$orders) { >+ $order->{'biblionumber'} = $ref_biblionumber; >+ >+ # TODO Do we really need to call ModOrder here? >+ ModOrder($order); > > # TODO : add error control (in ModOrder?) > } > > # Move holds > MergeHolds( $schema->storage->dbh, $ref_biblionumber, $bn_merge ); >+ > my $error = DelBiblio($bn_merge); #DelBiblio return undef unless an error occurs > if ($error) { > die $error; >diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t >index 1ce1e25ae36..b68fa35afef 100755 >--- a/t/db_dependent/Koha/Biblio.t >+++ b/t/db_dependent/Koha/Biblio.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 31; >+use Test::More tests => 33; > use Test::Exception; > use Test::Warn; > >@@ -912,6 +912,41 @@ subtest 'tickets() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'serials() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $biblio = $builder->build_sample_biblio; >+ >+ my $serials = $biblio->serials; >+ is( >+ ref($serials), 'Koha::Serials', >+ 'Koha::Biblio->serials should return a Koha::Serials object' >+ ); >+ is( $serials->count, 0, 'Koha::Biblio->serials should return the correct number of serials' ); >+ >+ # Add two serials >+ foreach ( 1 .. 2 ) { >+ $builder->build_object( >+ { >+ class => 'Koha::Serials', >+ value => { biblionumber => $biblio->biblionumber } >+ } >+ ); >+ } >+ >+ $serials = $biblio->serials; >+ is( >+ ref($serials), 'Koha::Serials', >+ 'Koha::Biblio->serials should return a Koha::Serials object' >+ ); >+ is( $serials->count, 2, 'Koha::Biblio->serials should return the correct number of serials' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'subscriptions() tests' => sub { > > plan tests => 4; >@@ -945,6 +980,47 @@ subtest 'subscriptions() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'subscription_histories() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ my $biblio = $builder->build_sample_biblio; >+ >+ my $sub_histories = $biblio->subscription_histories; >+ is( >+ ref($sub_histories), 'Koha::Subscription::Histories', >+ 'Koha::Biblio->subscription_histories should return a Koha::Subscription::Histories object' >+ ); >+ is( >+ $sub_histories->count, 0, >+ 'Koha::Biblio->subscription_histories should return the correct number of subscription histories' >+ ); >+ >+ # Add two subscription histories >+ foreach ( 1 .. 2 ) { >+ $builder->build_object( >+ { >+ class => 'Koha::Subscription::Histories', >+ value => { biblionumber => $biblio->biblionumber } >+ } >+ ); >+ } >+ >+ $sub_histories = $biblio->subscription_histories; >+ is( >+ ref($sub_histories), 'Koha::Subscription::Histories', >+ 'Koha::Biblio->subscription_histories should return a Koha::Subscription::Histories object' >+ ); >+ is( >+ $sub_histories->count, 2, >+ 'Koha::Biblio->subscription_histories should return the correct number of subscription histories' >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'get_marc_notes() MARC21 tests' => sub { > plan tests => 14; > >-- >2.34.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 33036
:
152436
|
152437
|
152438
|
152439
|
152440
|
152447
|
152472
|
152659
|
152678
|
157481
|
157482
|
157731
|
159011
|
159012
|
159103
|
159120
|
159191
|
159239
|
159826
|
159827
|
159828
|
159829
|
160302
|
160468
|
160469
|
160470
|
160471
|
160472