Bugzilla – Attachment 165646 Details for
Bug 35287
Add additional fields support to ERM licenses
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35287: perltidy for green QA script
Bug-35287-perltidy-for-green-QA-script.patch (text/plain), 16.84 KB, created by
Pedro Amorim
on 2024-04-26 10:32:19 UTC
(
hide
)
Description:
Bug 35287: perltidy for green QA script
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2024-04-26 10:32:19 UTC
Size:
16.84 KB
patch
obsolete
>From 8f6c96019a902eb89bfb00369291393a17acc0ed Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Thu, 9 Nov 2023 14:39:51 +0000 >Subject: [PATCH] Bug 35287: perltidy for green QA script > >Signed-off-by: Edith Speller <edith.speller@ukhsa.gov.uk> >Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> >--- > Koha/Object/Mixin/AdditionalFields.pm | 40 +++++----- > Koha/REST/V1/ERM/Licenses.pm | 76 +++++++------------ > .../Koha/Object/Mixin/AdditionalFields.t | 49 +++++------- > 3 files changed, 68 insertions(+), 97 deletions(-) > >diff --git a/Koha/Object/Mixin/AdditionalFields.pm b/Koha/Object/Mixin/AdditionalFields.pm >index ec60285795f..45a299c369f 100644 >--- a/Koha/Object/Mixin/AdditionalFields.pm >+++ b/Koha/Object/Mixin/AdditionalFields.pm >@@ -43,51 +43,53 @@ Koha::Object::Mixin::AdditionalFields > =cut > > sub set_additional_fields { >- my ($self, $additional_fields) = @_; >+ my ( $self, $additional_fields ) = @_; > > $self->additional_field_values->delete; > > my $biblionumber; > my $record; > my $record_updated; >- if ($self->_result->has_column('biblionumber')) { >+ if ( $self->_result->has_column('biblionumber') ) { > $biblionumber = $self->biblionumber; > } > > foreach my $additional_field (@$additional_fields) { >- my $field = Koha::AdditionalFields->find($additional_field->{id}); >+ my $field = Koha::AdditionalFields->find( $additional_field->{id} ); > my $value = $additional_field->{value}; > >- if ($biblionumber and $field->marcfield) { >+ if ( $biblionumber and $field->marcfield ) { > require Koha::Biblios; > $record //= Koha::Biblios->find($biblionumber)->metadata->record; > >- my ($tag, $subfield) = split /\$/, $field->marcfield; >+ my ( $tag, $subfield ) = split /\$/, $field->marcfield; > my $marc_field = $record->field($tag); >- if ($field->marcfield_mode eq 'get') { >+ if ( $field->marcfield_mode eq 'get' ) { > $value = $marc_field ? $marc_field->subfield($subfield) : ''; >- } elsif ($field->marcfield_mode eq 'set') { >+ } elsif ( $field->marcfield_mode eq 'set' ) { > if ($marc_field) { >- $marc_field->update($subfield => $value); >+ $marc_field->update( $subfield => $value ); > } else { >- $marc_field = MARC::Field->new($tag, '', '', $subfield => $value); >+ $marc_field = MARC::Field->new( $tag, '', '', $subfield => $value ); > $record->append_fields($marc_field); > } > $record_updated = 1; > } > } > >- if (defined $value) { >- my $field_value = Koha::AdditionalFieldValue->new({ >- field_id => $additional_field->{id}, >- record_id => $self->id, >- value => $value, >- })->store; >+ if ( defined $value ) { >+ my $field_value = Koha::AdditionalFieldValue->new( >+ { >+ field_id => $additional_field->{id}, >+ record_id => $self->id, >+ value => $value, >+ } >+ )->store; > } > } > > if ($record_updated) { >- C4::Biblio::ModBiblio($record, $biblionumber); >+ C4::Biblio::ModBiblio( $record, $biblionumber ); > } > } > >@@ -193,7 +195,7 @@ sub additional_field_values { > my ($self) = @_; > > my $afv_rs = $self->_result->additional_field_values; >- return Koha::AdditionalFieldValues->_new_from_dbic( $afv_rs ); >+ return Koha::AdditionalFieldValues->_new_from_dbic($afv_rs); > } > > =head3 extended_attributes >@@ -203,7 +205,7 @@ REST API embed of additional_field_values > =cut > > sub extended_attributes { >- my ($self, $extended_attributes) = @_; >+ my ( $self, $extended_attributes ) = @_; > > if ($extended_attributes) { > $self->set_additional_fields($extended_attributes); >@@ -268,7 +270,7 @@ sub strings_map { > ); > } > >- my @sorted = sort { $a->{field_id} <=> $b->{field_id} } @{ $strings->{additional_field_values} }; >+ my @sorted = sort { $a->{field_id} <=> $b->{field_id} } @{ $strings->{additional_field_values} }; > my @non_empty = grep { $_->{value_str} ne "" } @sorted; > $strings->{additional_field_values} = \@non_empty; > >diff --git a/Koha/REST/V1/ERM/Licenses.pm b/Koha/REST/V1/ERM/Licenses.pm >index 80c1cafe8af..bbc87aaaa93 100644 >--- a/Koha/REST/V1/ERM/Licenses.pm >+++ b/Koha/REST/V1/ERM/Licenses.pm >@@ -22,7 +22,7 @@ use Mojo::Base 'Mojolicious::Controller'; > use Koha::ERM::Licenses; > > use Scalar::Util qw( blessed ); >-use Try::Tiny qw( catch try ); >+use Try::Tiny qw( catch try ); > > =head1 API > >@@ -38,8 +38,7 @@ sub list { > return try { > my $licenses = $c->objects->search( Koha::ERM::Licenses->new ); > return $c->render( status => 200, openapi => $licenses ); >- } >- catch { >+ } catch { > $c->unhandled_exception($_); > }; > >@@ -68,8 +67,7 @@ sub get { > status => 200, > openapi => $license > ); >- } >- catch { >+ } catch { > $c->unhandled_exception($_); > }; > } >@@ -89,26 +87,26 @@ sub add { > > my $body = $c->req->json; > >- my $user_roles = delete $body->{user_roles} // []; >- my $documents = delete $body->{documents} // []; >+ my $user_roles = delete $body->{user_roles} // []; >+ my $documents = delete $body->{documents} // []; > my $extended_attributes = delete $body->{extended_attributes} // []; > > my $license = Koha::ERM::License->new_from_api($body)->store; > $license->user_roles($user_roles); > $license->documents($documents); > >- my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes}; >+ my @extended_attributes = >+ map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; > $license->extended_attributes( \@extended_attributes ); > >- $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id); >+ $c->res->headers->location( $c->req->url->to_string . '/' . $license->license_id ); > return $c->render( > status => 201, > openapi => $c->objects->to_api($license), > ); > } > ); >- } >- catch { >+ } catch { > > my $to_api_mapping = Koha::ERM::License->new->to_api_mapping; > >@@ -118,28 +116,17 @@ sub add { > status => 409, > openapi => { error => $_->error, conflict => $_->duplicate_id } > ); >- } >- elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) { >+ } elsif ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) { > return $c->render( > status => 400, >- openapi => { >- error => "Given " >- . $to_api_mapping->{ $_->broken_fk } >- . " does not exist" >- } >+ openapi => { error => "Given " . $to_api_mapping->{ $_->broken_fk } . " does not exist" } > ); >- } >- elsif ( $_->isa('Koha::Exceptions::BadParameter') ) { >+ } elsif ( $_->isa('Koha::Exceptions::BadParameter') ) { > return $c->render( > status => 400, >- openapi => { >- error => "Given " >- . $to_api_mapping->{ $_->parameter } >- . " does not exist" >- } >+ openapi => { error => "Given " . $to_api_mapping->{ $_->parameter } . " does not exist" } > ); >- } >- elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) { >+ } elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) { > return $c->render( > status => 413, > openapi => { error => $_->error } >@@ -175,50 +162,40 @@ sub update { > > my $body = $c->req->json; > >- my $user_roles = delete $body->{user_roles} // []; >- my $documents = delete $body->{documents} // []; >+ my $user_roles = delete $body->{user_roles} // []; >+ my $documents = delete $body->{documents} // []; > my $extended_attributes = delete $body->{extended_attributes} // []; > > $license->set_from_api($body)->store; > $license->user_roles($user_roles); > $license->documents($documents); > >- my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes}; >+ my @extended_attributes = >+ map { { 'id' => $_->{field_id}, 'value' => $_->{value} } } @{$extended_attributes}; > $license->extended_attributes( \@extended_attributes ); > >- $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id); >+ $c->res->headers->location( $c->req->url->to_string . '/' . $license->license_id ); > return $c->render( > status => 200, > openapi => $c->objects->to_api($license), > ); > } > ); >- } >- catch { >+ } catch { > my $to_api_mapping = Koha::ERM::License->new->to_api_mapping; > > if ( blessed $_ ) { > if ( $_->isa('Koha::Exceptions::Object::FKConstraint') ) { > return $c->render( > status => 400, >- openapi => { >- error => "Given " >- . $to_api_mapping->{ $_->broken_fk } >- . " does not exist" >- } >+ openapi => { error => "Given " . $to_api_mapping->{ $_->broken_fk } . " does not exist" } > ); >- } >- elsif ( $_->isa('Koha::Exceptions::BadParameter') ) { >+ } elsif ( $_->isa('Koha::Exceptions::BadParameter') ) { > return $c->render( > status => 400, >- openapi => { >- error => "Given " >- . $to_api_mapping->{ $_->parameter } >- . " does not exist" >- } >+ openapi => { error => "Given " . $to_api_mapping->{ $_->parameter } . " does not exist" } > ); >- } >- elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) { >+ } elsif ( $_->isa('Koha::Exceptions::PayloadTooLarge') ) { > return $c->render( > status => 413, > openapi => { error => $_->error } >@@ -228,7 +205,7 @@ sub update { > > $c->unhandled_exception($_); > }; >-}; >+} > > =head3 delete > >@@ -251,8 +228,7 @@ sub delete { > status => 204, > openapi => q{} > ); >- } >- catch { >+ } catch { > $c->unhandled_exception($_); > }; > } >diff --git a/t/db_dependent/Koha/Object/Mixin/AdditionalFields.t b/t/db_dependent/Koha/Object/Mixin/AdditionalFields.t >index 3f4a1d08a87..ed15a982ec1 100755 >--- a/t/db_dependent/Koha/Object/Mixin/AdditionalFields.t >+++ b/t/db_dependent/Koha/Object/Mixin/AdditionalFields.t >@@ -12,7 +12,7 @@ use Koha::ERM::License; > use C4::Context; > > my $builder = t::lib::TestBuilder->new; >-my $schema = Koha::Database->schema; >+my $schema = Koha::Database->schema; > > subtest 'set_additional_fields with marcfield_mode = "get"' => sub { > plan tests => 1; >@@ -22,9 +22,9 @@ subtest 'set_additional_fields with marcfield_mode = "get"' => sub { > my $biblio = $builder->build_sample_biblio(); > my $record = $biblio->record; > $record->append_fields( >- MARC::Field->new('998', '', '', 'Z' => 'some value'), >+ MARC::Field->new( '998', '', '', 'Z' => 'some value' ), > ); >- $biblio->metadata->metadata($record->as_xml_record(C4::Context->preference('marcflavour'))); >+ $biblio->metadata->metadata( $record->as_xml_record( C4::Context->preference('marcflavour') ) ); > $biblio->metadata->store()->discard_changes(); > my $subscription = Koha::Subscription->new( > { >@@ -35,9 +35,9 @@ subtest 'set_additional_fields with marcfield_mode = "get"' => sub { > > my $field = Koha::AdditionalField->new( > { >- tablename => 'subscription', >- name => random_string('c' x 100), >- marcfield => '998$Z', >+ tablename => 'subscription', >+ name => random_string( 'c' x 100 ), >+ marcfield => '998$Z', > marcfield_mode => 'get', > } > ); >@@ -50,7 +50,7 @@ subtest 'set_additional_fields with marcfield_mode = "get"' => sub { > > my $values = $subscription->additional_field_values()->as_list(); > >- is($values->[0]->value, 'some value', 'value was copied from the biblio record to the field'); >+ is( $values->[0]->value, 'some value', 'value was copied from the biblio record to the field' ); > > $schema->txn_rollback; > }; >@@ -60,7 +60,7 @@ subtest 'set_additional_fields with marcfield_mode = "set"' => sub { > > $schema->txn_begin; > >- my $biblio = $builder->build_sample_biblio(); >+ my $biblio = $builder->build_sample_biblio(); > my $subscription = Koha::Subscription->new( > { > biblionumber => $biblio->biblionumber, >@@ -70,9 +70,9 @@ subtest 'set_additional_fields with marcfield_mode = "set"' => sub { > > my $field = Koha::AdditionalField->new( > { >- tablename => 'subscription', >- name => random_string('c' x 100), >- marcfield => '999$Z', >+ tablename => 'subscription', >+ name => random_string( 'c' x 100 ), >+ marcfield => '999$Z', > marcfield_mode => 'set', > } > ); >@@ -80,14 +80,14 @@ subtest 'set_additional_fields with marcfield_mode = "set"' => sub { > $subscription->set_additional_fields( > [ > { >- id => $field->id, >+ id => $field->id, > value => 'some value', > }, > ] > ); > > my $record = $biblio->record; >- is($record->subfield('999', 'Z'), 'some value', 'value was copied from the field to the biblio record'); >+ is( $record->subfield( '999', 'Z' ), 'some value', 'value was copied from the field to the biblio record' ); > > $schema->txn_rollback; > }; >@@ -107,16 +107,16 @@ subtest 'get_additional_field_values_for_template' => sub { > > my $field = Koha::AdditionalField->new( > { >- tablename => 'subscription', >- name => random_string( 'c' x 100 ) >+ tablename => 'subscription', >+ name => random_string( 'c' x 100 ) > } > ); > $field->store()->discard_changes(); > > my $field2 = Koha::AdditionalField->new( > { >- tablename => 'subscription', >- name => random_string( 'c' x 100 ) >+ tablename => 'subscription', >+ name => random_string( 'c' x 100 ) > } > ); > $field2->store()->discard_changes(); >@@ -201,17 +201,13 @@ subtest 'add_additional_fields' => sub { > > $subscription->add_additional_fields( > { >- $field2->id => [ >- 'second field' >- ], >+ $field2->id => ['second field'], > }, > 'subscription' > ); > > my $template_additional_field_values = $subscription->get_additional_field_values_for_template; > >- >- > is_deeply( > $template_additional_field_values, > { $field->id => [ $value . ' 1', $value . ' 2' ], $field2->id => ['second field'] }, >@@ -274,13 +270,12 @@ subtest 'strings_map() tests' => sub { > 'erm_licenses' > ); > >- >- my $av_category = Koha::AuthorisedValueCategory->new( { category_name => "AV_CAT_NAME" } ); >+ my $av_category = Koha::AuthorisedValueCategory->new( { category_name => "AV_CAT_NAME" } ); > $av_category->store()->discard_changes(); > > my $av_value = Koha::AuthorisedValue->new( > { >- category => $av_category->category_name, >+ category => $av_category->category_name, > authorised_value => 'BOB', > lib => "Robert" > } >@@ -295,11 +290,9 @@ subtest 'strings_map() tests' => sub { > ); > $av_field->store()->discard_changes(); > >- >- > $license->add_additional_fields( > { >- $av_field->id => [$av_value->authorised_value], >+ $av_field->id => [ $av_value->authorised_value ], > }, > 'erm_licenses' > ); >-- >2.39.2
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 35287
:
158725
|
158726
|
158727
|
158728
|
158729
|
158730
|
158731
|
158732
|
158733
|
158734
|
159634
|
159635
|
159636
|
159637
|
159638
|
159639
|
159640
|
159641
|
159642
|
159643
|
165451
|
165637
|
165638
|
165639
|
165640
|
165641
|
165642
|
165643
|
165644
|
165645
|
165646
|
165647
|
167681
|
169728
|
169729
|
169730
|
169731
|
169732
|
169733
|
169734
|
169735
|
169736
|
169737
|
170448
|
170753
|
172850
|
172851
|
172852
|
172853
|
172854
|
172855
|
172856
|
172857
|
172858
|
172860
|
172861
|
173022
|
173102
|
173103
|
173104
|
173105
|
173106
|
173107
|
173108
|
173109
|
173110
|
173111
|
173112
|
173113
|
173290