Bugzilla – Attachment 175713 Details for
Bug 38262
Add additional fields to Vendors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38262: Update object classes
Bug-38262-Update-object-classes.patch (text/plain), 7.42 KB, created by
Matt Blenkinsop
on 2024-12-19 12:25:32 UTC
(
hide
)
Description:
Bug 38262: Update object classes
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2024-12-19 12:25:32 UTC
Size:
7.42 KB
patch
obsolete
>From 1f74af091cbd6fccfb695453afd3ae9b343ecc17 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >Date: Tue, 29 Oct 2024 17:12:09 +0000 >Subject: [PATCH] Bug 38262: Update object classes > >--- > Koha/Acquisition/Bookseller.pm | 2 +- > Koha/Acquisition/Booksellers.pm | 2 +- > Koha/AdditionalField.pm | 1 + > Koha/REST/V1/Acquisitions/Vendors.pm | 49 ++++++++++++++++---------- > Koha/REST/V1/ExtendedAttributeTypes.pm | 1 + > Koha/Schema/Result/Aqbookseller.pm | 32 +++++++++++++++++ > 6 files changed, 67 insertions(+), 20 deletions(-) > >diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm >index da9c98c86b5..3ae36c13f0e 100644 >--- a/Koha/Acquisition/Bookseller.pm >+++ b/Koha/Acquisition/Bookseller.pm >@@ -25,7 +25,7 @@ use Koha::Subscriptions; > > use C4::Contract qw( GetContracts ); > >-use base qw( Koha::Object ); >+use base qw( Koha::Object::Mixin::AdditionalFields Koha::Object ); > > =head1 NAME > >diff --git a/Koha/Acquisition/Booksellers.pm b/Koha/Acquisition/Booksellers.pm >index 1484396256d..466270751db 100644 >--- a/Koha/Acquisition/Booksellers.pm >+++ b/Koha/Acquisition/Booksellers.pm >@@ -19,7 +19,7 @@ use Modern::Perl; > > use Koha::Acquisition::Bookseller; > >-use base qw( Koha::Objects ); >+use base qw( Koha::Object::Mixin::AdditionalFields Koha::Objects ); > > =head1 NAME > >diff --git a/Koha/AdditionalField.pm b/Koha/AdditionalField.pm >index ec0263697f9..989bc63ca66 100644 >--- a/Koha/AdditionalField.pm >+++ b/Koha/AdditionalField.pm >@@ -63,6 +63,7 @@ sub to_api { > 'erm_agreements' => 'agreement', > 'erm_packages' => 'package', > 'aqorders' => 'order', >+ 'aqbooksellers:vendor' => 'vendor', > }; > > my $json = $self->SUPER::to_api($params); >diff --git a/Koha/REST/V1/Acquisitions/Vendors.pm b/Koha/REST/V1/Acquisitions/Vendors.pm >index 13f464157ed..f61e4d2309b 100644 >--- a/Koha/REST/V1/Acquisitions/Vendors.pm >+++ b/Koha/REST/V1/Acquisitions/Vendors.pm >@@ -87,13 +87,14 @@ Controller function that handles adding a new Koha::Acquisition::Bookseller obje > sub add { > my $c = shift->openapi->valid_input or return; > >- my $vendor = $c->req->json; >- my $contacts = delete $vendor->{contacts}; >- my $interfaces = delete $vendor->{interfaces}; >- my $aliases = delete $vendor->{aliases}; >- my $subscriptions = delete $vendor->{subscriptions}; >- my $baskets = delete $vendor->{baskets}; >- my $contracts = delete $vendor->{contracts}; >+ my $vendor = $c->req->json; >+ my $contacts = delete $vendor->{contacts}; >+ my $interfaces = delete $vendor->{interfaces}; >+ my $aliases = delete $vendor->{aliases}; >+ my $subscriptions = delete $vendor->{subscriptions}; >+ my $baskets = delete $vendor->{baskets}; >+ my $contracts = delete $vendor->{contracts}; >+ my $extended_attributes = delete $vendor->{extended_attributes}; > > my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json ); > >@@ -101,8 +102,13 @@ sub add { > $vendor_to_store->store; > > $vendor_to_store->contacts($contacts) if scalar($contacts) > 0; >- $vendor_to_store->aliases($aliases) if scalar($aliases) > 0; >- $vendor_to_store->interfaces($interfaces) if scalar($interfaces) > 0; >+ $vendor_to_store->aliases($aliases) if scalar(@$aliases) > 0; >+ $vendor_to_store->interfaces($interfaces) if scalar(@$interfaces) > 0; >+ >+ if(scalar(@$extended_attributes) > 0) { >+ my @extended_attributes = map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; >+ $vendor_to_store->extended_attributes( \@extended_attributes ); >+ } > > $c->res->headers->location( $c->req->url->to_string . '/' . $vendor_to_store->id ); > return $c->render( >@@ -131,20 +137,27 @@ sub update { > unless $vendor; > > return try { >- my $vendor_update = $c->req->json; >- my $contacts = delete $vendor_update->{contacts}; >- my $interfaces = delete $vendor_update->{interfaces}; >- my $aliases = delete $vendor_update->{aliases}; >- my $subscriptions = delete $vendor_update->{subscriptions}; >- my $baskets = delete $vendor_update->{baskets}; >- my $contracts = delete $vendor_update->{contracts}; >+ my $vendor_update = $c->req->json; >+ my $contacts = delete $vendor_update->{contacts}; >+ my $interfaces = delete $vendor_update->{interfaces}; >+ my $aliases = delete $vendor_update->{aliases}; >+ my $subscriptions = delete $vendor_update->{subscriptions}; >+ my $baskets = delete $vendor_update->{baskets}; >+ my $contracts = delete $vendor_update->{contracts}; >+ my $extended_attributes = delete $vendor_update->{extended_attributes}; > > $vendor->set_from_api($vendor_update); > $vendor->store(); > > $vendor->contacts($contacts) if scalar($contacts) > 0; >- $vendor->aliases($aliases) if scalar($aliases) > 0; >- $vendor->interfaces($interfaces) if scalar($interfaces) > 0; >+ $vendor->aliases($aliases) if scalar(@$aliases) > 0; >+ $vendor->interfaces($interfaces) if scalar(@$interfaces) > 0; >+ >+ if ( scalar(@$extended_attributes) > 0 ) { >+ my @extended_attributes = >+ map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; >+ $vendor->extended_attributes( \@extended_attributes ); >+ } > > return $c->render( > status => 200, >diff --git a/Koha/REST/V1/ExtendedAttributeTypes.pm b/Koha/REST/V1/ExtendedAttributeTypes.pm >index 844582c5a48..07e70d520d5 100644 >--- a/Koha/REST/V1/ExtendedAttributeTypes.pm >+++ b/Koha/REST/V1/ExtendedAttributeTypes.pm >@@ -54,6 +54,7 @@ sub list { > agreement => 'erm_agreements', > package => 'erm_packages', > order => 'aqorders', >+ vendor => 'aqbooksellers:vendor', > }; > > return try { >diff --git a/Koha/Schema/Result/Aqbookseller.pm b/Koha/Schema/Result/Aqbookseller.pm >index 1cfaa93ff07..2e10398d849 100644 >--- a/Koha/Schema/Result/Aqbookseller.pm >+++ b/Koha/Schema/Result/Aqbookseller.pm >@@ -566,6 +566,38 @@ __PACKAGE__->has_many( > { cascade_copy => 0, cascade_delete => 0 }, > ); > >+__PACKAGE__->has_many( >+ "additional_field_values", >+ "Koha::Schema::Result::AdditionalFieldValue", >+ sub { >+ my ($args) = @_; >+ >+ return { >+ "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.id" }, >+ >+ "$args->{foreign_alias}.field_id" => >+ { -in => \'(SELECT id FROM additional_fields WHERE tablename LIKE "aqbooksellers:%")' }, >+ }; >+ }, >+ { cascade_copy => 0, cascade_delete => 0 }, >+); >+ >+__PACKAGE__->has_many( >+ "extended_attributes", >+ "Koha::Schema::Result::AdditionalFieldValue", >+ sub { >+ my ($args) = @_; >+ >+ return { >+ "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.id" }, >+ >+ "$args->{foreign_alias}.field_id" => >+ { -in => \'(SELECT id FROM additional_fields WHERE tablename LIKE "aqbooksellers:%")' }, >+ }; >+ }, >+ { cascade_copy => 0, cascade_delete => 0 }, >+); >+ > sub koha_object_class { > 'Koha::Acquisition::Bookseller'; > } >-- >2.39.5 (Apple Git-154)
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 38262
:
175147
|
175148
|
175149
|
175712
| 175713 |
175714