From 5ba8a8510a374de0b0574f30d7796c42168960c3 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 20 Jul 2023 10:24:41 -0300 Subject: [PATCH] Bug 33105: Tidy files Signed-off-by: Tomas Cohen Arazi --- Koha/Acquisition/Bookseller.pm | 2 +- Koha/Acquisition/Bookseller/Issue.pm | 13 ++++---- Koha/REST/V1/Acquisitions/Vendor/Issues.pm | 7 ++-- acqui/vendor_issues.pl | 6 ++-- .../data/mysql/atomicupdate/bug_33105.pl | 32 ++++++++++++------- t/db_dependent/Koha/Acquisition/Booksellers.t | 4 +-- .../api/v1/acquisitions_vendor_issues.t | 26 +++++++-------- 7 files changed, 48 insertions(+), 42 deletions(-) diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm index 2fc1c0a95d..50daff7fa2 100644 --- a/Koha/Acquisition/Bookseller.pm +++ b/Koha/Acquisition/Bookseller.pm @@ -147,7 +147,7 @@ sub interfaces { sub issues { my ($self) = @_; my $rs = $self->_result->aqbookseller_issues; - return Koha::Acquisition::Bookseller::Issues->_new_from_dbic( $rs ); + return Koha::Acquisition::Bookseller::Issues->_new_from_dbic($rs); } =head3 to_api_mapping diff --git a/Koha/Acquisition/Bookseller/Issue.pm b/Koha/Acquisition/Bookseller/Issue.pm index f4d1ecd069..5ff3e13308 100644 --- a/Koha/Acquisition/Bookseller/Issue.pm +++ b/Koha/Acquisition/Bookseller/Issue.pm @@ -43,16 +43,17 @@ sub strings_map { if ( defined $self->type ) { my $av = Koha::AuthorisedValues->search( { - category => ISSUE_TYPE_CATEGORY, + category => ISSUE_TYPE_CATEGORY, authorised_value => $self->type, } ); - my $type_str = $av->count - ? $params->{public} - ? $av->next->opac_description - : $av->next->lib - : $self->type; + my $type_str = + $av->count + ? $params->{public} + ? $av->next->opac_description + : $av->next->lib + : $self->type; $strings->{type} = { category => ISSUE_TYPE_CATEGORY, diff --git a/Koha/REST/V1/Acquisitions/Vendor/Issues.pm b/Koha/REST/V1/Acquisitions/Vendor/Issues.pm index 683d52ae79..ae979c75e0 100644 --- a/Koha/REST/V1/Acquisitions/Vendor/Issues.pm +++ b/Koha/REST/V1/Acquisitions/Vendor/Issues.pm @@ -47,7 +47,7 @@ sub list { return try { my $vendor_id = $c->validation->param('vendor_id'); - my $vendor = Koha::Acquisition::Booksellers->find($vendor_id); + my $vendor = Koha::Acquisition::Booksellers->find($vendor_id); unless ($vendor) { return $c->render( @@ -57,14 +57,13 @@ sub list { } my $issues_rs = $vendor->issues; - my $issues = $c->objects->search( $issues_rs ); + my $issues = $c->objects->search($issues_rs); return $c->render( status => 200, openapi => $issues, ); - } - catch { + } catch { $c->unhandled_exception($_); }; } diff --git a/acqui/vendor_issues.pl b/acqui/vendor_issues.pl index 48a8ef703e..4b154e8d99 100755 --- a/acqui/vendor_issues.pl +++ b/acqui/vendor_issues.pl @@ -42,13 +42,13 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( ); my $issue; -if ( $issue_id ) { - $issue = Koha::Acquisition::Bookseller::Issues->find($issue_id); +if ($issue_id) { + $issue = Koha::Acquisition::Bookseller::Issues->find($issue_id); $booksellerid = $issue->vendor_id; } my $vendor = Koha::Acquisition::Booksellers->find($booksellerid); -unless ( $vendor ) { +unless ($vendor) { print $input->redirect("/cgi-bin/koha/errors/404.pl"); exit; } diff --git a/installer/data/mysql/atomicupdate/bug_33105.pl b/installer/data/mysql/atomicupdate/bug_33105.pl index 462aa2cfa8..4682732561 100755 --- a/installer/data/mysql/atomicupdate/bug_33105.pl +++ b/installer/data/mysql/atomicupdate/bug_33105.pl @@ -1,13 +1,14 @@ use Modern::Perl; return { - bug_number => "33105", + bug_number => "33105", description => "Add vendor issues", - up => sub { + up => sub { my ($args) = @_; - my ($dbh, $out) = @$args{qw(dbh out)}; - unless (TableExists('aqbookseller_issues')) { - $dbh->do(q{ + my ( $dbh, $out ) = @$args{qw(dbh out)}; + unless ( TableExists('aqbookseller_issues') ) { + $dbh->do( + q{ CREATE TABLE `aqbookseller_issues` ( `issue_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key and unique identifier assigned by Koha', `vendor_id` int(11) NOT NULL COMMENT 'link to the vendor', @@ -18,27 +19,34 @@ return { PRIMARY KEY (`issue_id`), CONSTRAINT `aqbookseller_issues_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - }); + } + ); say $out "Added new table 'aqbookseller_issues'"; } - $dbh->do(q{ + $dbh->do( + q{ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES (11, 'issue_manage', 'Manage issues'); - }); + } + ); say $out "Added new permission 'acquisition.issue_manage'"; - $dbh->do(q{ + $dbh->do( + q{ INSERT IGNORE INTO authorised_value_categories (category_name, is_system) VALUES ('VENDOR_ISSUE_TYPE', 1) - }); - $dbh->do(q{ + } + ); + $dbh->do( + q{ INSERT IGNORE INTO authorised_values (category, authorised_value, lib) VALUES ('VENDOR_ISSUE_TYPE', 'MAINTENANCE', 'Maintenance'), ('VENDOR_ISSUE_TYPE', 'OUTAGE', 'Outage') - }); + } + ); say $out "Added new authorised value category 'VENDOR_ISSUE_TYPE'"; }, }; diff --git a/t/db_dependent/Koha/Acquisition/Booksellers.t b/t/db_dependent/Koha/Acquisition/Booksellers.t index 3f9b8a6c87..604a40e79f 100755 --- a/t/db_dependent/Koha/Acquisition/Booksellers.t +++ b/t/db_dependent/Koha/Acquisition/Booksellers.t @@ -246,8 +246,8 @@ subtest 'issues' => sub { $vendor = $vendor->get_from_storage; my $issues = $vendor->issues; - is( $issues->count, 1, '1 issue stored' ); - is( ref($issues), 'Koha::Acquisition::Bookseller::Issues', 'Type is correct' ); + is( $issues->count, 1, '1 issue stored' ); + is( ref($issues), 'Koha::Acquisition::Bookseller::Issues', 'Type is correct' ); is( $issues->next->strings_map->{type}->{str}, 'Maintenance' ); diff --git a/t/db_dependent/api/v1/acquisitions_vendor_issues.t b/t/db_dependent/api/v1/acquisitions_vendor_issues.t index 7c0d8e973e..5ed470daaf 100755 --- a/t/db_dependent/api/v1/acquisitions_vendor_issues.t +++ b/t/db_dependent/api/v1/acquisitions_vendor_issues.t @@ -38,13 +38,13 @@ subtest 'list() tests' => sub { $schema->storage->txn_begin; - my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } ); + my $vendor = $builder->build_object( { class => 'Koha::Acquisition::Booksellers' } ); my $vendor_id = $vendor->id; my $librarian = $builder->build_object( { class => 'Koha::Patrons', - value => { flags => 2 ** 11 } + value => { flags => 2**11 } } ); my $password = 'thePassword123'; @@ -52,9 +52,7 @@ subtest 'list() tests' => sub { my $userid = $librarian->userid; # No issues, so empty array should be returned - $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues") - ->status_is(200) - ->json_is( [] ); + $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues")->status_is(200)->json_is( [] ); my $issue = Koha::Acquisition::Bookseller::Issue->new( { @@ -63,20 +61,20 @@ subtest 'list() tests' => sub { notes => 'a vendor issue' } )->store; + # One issue created, should get returned - $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues") - ->status_is(200) - ->json_is( [$issue->to_api] ); + $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues")->status_is(200) + ->json_is( [ $issue->to_api ] ); + # Embed the AV description - $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues" - => { 'x-koha-embed' => '+strings' }) - ->status_is(200) - ->json_is( [$issue->to_api({ strings => 1 })] ); + $t->get_ok( + "//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues" => { 'x-koha-embed' => '+strings' } ) + ->status_is(200)->json_is( [ $issue->to_api( { strings => 1 } ) ] ); $vendor->delete; + # No vendor, should get 404 - $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues") - ->status_is(404); + $t->get_ok("//$userid:$password@/api/v1/acquisitions/vendors/$vendor_id/issues")->status_is(404); $schema->storage->txn_rollback; }; -- 2.39.5