Compare commits

...

18 Commits

Author SHA1 Message Date
Marcel de Rooy 1e350b5bb6 Bug 29437: (QA follow-up) Update TODO in Breeding.t 2 years ago
Marcel de Rooy 3f0d86b2cb Bug 29437: (QA follow-up) Remove Business::ISBN from addbooks 2 years ago
Nick Clemens 10de703d61 Bug 29437: Search reservoir for term as title, author, or variations of ISBN 2 years ago
Nick Clemens 80f393cc3e Bug 29437: Unit tests 2 years ago
Katrin Fischer e6cdda9b01 Bug 29456: Add Hold_Reminder description to patron categories overview page 2 years ago
Jonathan Druart d50aad2a91 Bug 29456: (bug 18532 follow-up) handle Auto_Renewals messages in category 2 years ago
Jonathan Druart 8ee29390f1 Bug 5229: DBRev 21.06.00.049 2 years ago
Tomás Cohen Arazi c483fecc63 Bug 5229: Remove from searching.pref 2 years ago
Jonathan Druart 6f6c364ee0 Bug 5229: Remove system preference 'OPACItemsResultsDisplay' 2 years ago
Petro Vashchuk 288ef82461 Bug 29463: Escape utf8 characters before appending search query to url 2 years ago
Marcel de Rooy 5ddb520b96 Bug 29387: (QA follow-up) Fix modules in test 2 years ago
Jonathan Druart e34fa5b511 Bug 29387: Stringify exceptions for other background job modules 2 years ago
Jonathan Druart 27793b8979 Bug 29387: Stringify exception when logging error during a batch mod biblio 2 years ago
Jonathan Druart 62316cd585 Bug 29341: DBIC schema changes 2 years ago
Jonathan Druart 8a280a7d54 Bug 29341: DBRev 21.06.00.048 2 years ago
Jonathan Druart ee3ffed6f5 Bug 29341: Remove foreign keys on pseudonymized_transactions 2 years ago
Jonathan Druart 90090a3601 Bug 29496: (bug 27526 follow-up) Fix item form validation 2 years ago
Marion Durand 294741b1df Bug 29496: CheckMandatorySubfields don't work properly with select field in serials-edit.tt 2 years ago
  1. 30
      C4/Breeding.pm
  2. 1
      C4/UsageStats.pm
  3. 2
      Koha.pm
  4. 2
      Koha/BackgroundJob/BatchCancelHold.pm
  5. 2
      Koha/BackgroundJob/BatchDeleteAuthority.pm
  6. 2
      Koha/BackgroundJob/BatchDeleteBiblio.pm
  7. 2
      Koha/BackgroundJob/BatchUpdateAuthority.pm
  8. 2
      Koha/BackgroundJob/BatchUpdateBiblio.pm
  9. 34
      Koha/Schema/Result/Branch.pm
  10. 19
      Koha/Schema/Result/Category.pm
  11. 75
      Koha/Schema/Result/PseudonymizedTransaction.pm
  12. 10
      cataloguing/addbooks.pl
  13. 3
      circ/circulation.pl
  14. 17
      installer/data/mysql/db_revs/210600048.pl
  15. 11
      installer/data/mysql/db_revs/210600049.pl
  16. 5
      installer/data/mysql/kohastructure.sql
  17. 1
      installer/data/mysql/mandatory/sysprefs.sql
  18. 2
      koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt
  19. 2
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt
  20. 7
      koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref
  21. 2
      koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt
  22. 2
      koha-tmpl/intranet-tmpl/prog/en/modules/services/itemrecorddisplay.tt
  23. 1
      opac/opac-search.pl
  24. 39
      t/db_dependent/Breeding.t
  25. 74
      t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t

30
C4/Breeding.pm

@ -22,7 +22,7 @@ use strict;
use warnings;
use C4::Biblio;
use C4::Koha qw( GetNormalizedISBN );
use C4::Koha qw( GetVariationsOfISBN );
use C4::Charset qw( MarcToUTF8Record SetUTF8Flag );
use MARC::File::USMARC;
use MARC::Field;
@ -56,9 +56,8 @@ cataloguing reservoir features.
=head2 BreedingSearch
($count, @results) = &BreedingSearch($title,$isbn);
C<$title> contains the title,
C<$isbn> contains isbn or issn,
($count, @results) = &BreedingSearch($term);
C<$term> contains the term to search, it will be searched as title,author, or isbn
C<$count> is the number of items in C<@results>. C<@results> is an
array of references-to-hash; the keys are the items from the C<import_records> and
@ -67,34 +66,25 @@ C<import_biblios> tables of the Koha database.
=cut
sub BreedingSearch {
my ($search,$isbn) = @_;
my ($term) = @_;
my $dbh = C4::Context->dbh;
my $count = 0;
my ($query,@bind);
my $sth;
my @results;
my $authortitle = $term;
$authortitle =~ s/(\s+)/\%/g; #Replace spaces with wildcard
$authortitle = "%" . $authortitle . "%"; #Add wildcard to start and end of string
# normalise ISBN like at import
$isbn = C4::Koha::GetNormalizedISBN($isbn);
my @isbns = C4::Koha::GetVariationsOfISBN($term);
$query = "SELECT import_record_id, file_name, isbn, title, author
FROM import_biblios
JOIN import_records USING (import_record_id)
JOIN import_batches USING (import_batch_id)
WHERE ";
@bind=();
if (defined($search) && length($search)>0) {
$search =~ s/(\s+)/\%/g;
$query .= "title like ? OR author like ?";
push(@bind,"%$search%", "%$search%");
}
if ($#bind!=-1 && defined($isbn) && length($isbn)>0) {
$query .= " and ";
}
if (defined($isbn) && length($isbn)>0) {
$query .= "isbn like ?";
push(@bind,"$isbn%");
}
WHERE title LIKE ? OR author LIKE ? OR isbn IN (" . join(',',('?') x @isbns) . ")";
@bind=( $authortitle, $authortitle, @isbns );
$sth = $dbh->prepare($query);
$sth->execute(@bind);
while (my $data = $sth->fetchrow_hashref) {

1
C4/UsageStats.pm

@ -346,7 +346,6 @@ sub _shared_preferences {
defaultSortField
displayFacetCount
OPACdefaultSortField
OPACItemsResultsDisplay
expandedSearchOption
IntranetNumbersPreferPhrase
OPACNumbersPreferPhrase

2
Koha.pm

@ -29,7 +29,7 @@ use vars qw{ $VERSION };
# - #4 : the developer version. The 4th number is the database subversion.
# used by developers when the database changes. updatedatabase take care of the changes itself
# and is automatically called by Auth.pm when needed.
$VERSION = "21.06.00.047";
$VERSION = "21.06.00.049";
sub version {
return $VERSION;

2
Koha/BackgroundJob/BatchCancelHold.pm

@ -94,7 +94,7 @@ sub process {
biblio_id => defined $biblio ? $biblio->biblionumber : '',
hold_id => $hold_id,
error => defined $hold
? ( $@ ? $@ : 0 )
? ( $@ ? "$@" : 0 )
: 'hold_not_found',
};
}

2
Koha/BackgroundJob/BatchDeleteAuthority.pm

@ -57,7 +57,7 @@ sub process {
type => 'error',
code => 'authority_not_deleted',
authid => $authid,
error => ($@ ? $@ : 0),
error => "$@",
};
$schema->storage->txn_rollback;
next;

2
Koha/BackgroundJob/BatchDeleteBiblio.pm

@ -101,7 +101,7 @@ sub process {
code => 'reserve_not_cancelled',
biblionumber => $biblionumber,
reserve_id => $hold->reserve_id,
error => $@,
error => "$@",
};
$schema->storage->txn_rollback;
$job->progress( ++$job_progress )->store;

2
Koha/BackgroundJob/BatchUpdateAuthority.pm

@ -90,7 +90,7 @@ sub process {
type => 'error',
code => 'authority_not_modified',
authid => $authid,
error => ($@ ? $@ : 0),
error => ($@ ? "$@" : 0),
};
} else {
push @messages, {

2
Koha/BackgroundJob/BatchUpdateBiblio.pm

@ -100,7 +100,7 @@ sub process {
type => 'error',
code => 'biblio_not_modified',
biblionumber => $biblionumber,
error => ($@ ? $@ : $error),
error => ($@ ? "$@" : $error),
};
} else {
push @messages, {

34
Koha/Schema/Result/Branch.pm

@ -761,36 +761,6 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 pseudonymized_transactions_branchcodes
Type: has_many
Related object: L<Koha::Schema::Result::PseudonymizedTransaction>
=cut
__PACKAGE__->has_many(
"pseudonymized_transactions_branchcodes",
"Koha::Schema::Result::PseudonymizedTransaction",
{ "foreign.branchcode" => "self.branchcode" },
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 pseudonymized_transactions_transaction_branchcodes
Type: has_many
Related object: L<Koha::Schema::Result::PseudonymizedTransaction>
=cut
__PACKAGE__->has_many(
"pseudonymized_transactions_transaction_branchcodes",
"Koha::Schema::Result::PseudonymizedTransaction",
{ "foreign.transaction_branchcode" => "self.branchcode" },
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 repeatable_holidays
Type: has_many
@ -897,8 +867,8 @@ __PACKAGE__->has_many(
);
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-10-27 13:48:49
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SVuazNjL6+ziK2Uwcc7OwA
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-11-19 14:20:11
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:v83MNP0UpFzlnax8rSQWSA
__PACKAGE__->add_columns(
'+pickup_location' => { is_boolean => 1 },

19
Koha/Schema/Result/Category.pm

@ -328,24 +328,9 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 pseudonymized_transactions
Type: has_many
Related object: L<Koha::Schema::Result::PseudonymizedTransaction>
=cut
__PACKAGE__->has_many(
"pseudonymized_transactions",
"Koha::Schema::Result::PseudonymizedTransaction",
{ "foreign.categorycode" => "self.categorycode" },
{ cascade_copy => 0, cascade_delete => 0 },
);
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:O4duiIu9dHKr31ToxFGubA
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-11-19 14:20:11
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xrnHXXv5sd3S2sMEKzHLmA
__PACKAGE__->add_columns(
'+exclude_from_local_holds_priority' => { is_boolean => 1 },

75
Koha/Schema/Result/PseudonymizedTransaction.pm

@ -71,7 +71,6 @@ __PACKAGE__->table("pseudonymized_transactions");
data_type: 'varchar'
default_value: (empty string)
is_foreign_key: 1
is_nullable: 0
size: 10
@ -79,7 +78,6 @@ __PACKAGE__->table("pseudonymized_transactions");
data_type: 'varchar'
default_value: (empty string)
is_foreign_key: 1
is_nullable: 0
size: 10
@ -116,7 +114,6 @@ __PACKAGE__->table("pseudonymized_transactions");
=head2 transaction_branchcode
data_type: 'varchar'
is_foreign_key: 1
is_nullable: 1
size: 10
@ -187,21 +184,9 @@ __PACKAGE__->add_columns(
"country",
{ data_type => "mediumtext", is_nullable => 1 },
"branchcode",
{
data_type => "varchar",
default_value => "",
is_foreign_key => 1,
is_nullable => 0,
size => 10,
},
{ data_type => "varchar", default_value => "", is_nullable => 0, size => 10 },
"categorycode",
{
data_type => "varchar",
default_value => "",
is_foreign_key => 1,
is_nullable => 0,
size => 10,
},
{ data_type => "varchar", default_value => "", is_nullable => 0, size => 10 },
"dateenrolled",
{ data_type => "date", datetime_undef_if_invalid => 1, is_nullable => 1 },
"sex",
@ -217,7 +202,7 @@ __PACKAGE__->add_columns(
is_nullable => 1,
},
"transaction_branchcode",
{ data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 },
{ data_type => "varchar", is_nullable => 1, size => 10 },
"transaction_type",
{ data_type => "varchar", is_nullable => 1, size => 16 },
"itemnumber",
@ -250,36 +235,6 @@ __PACKAGE__->set_primary_key("id");
=head1 RELATIONS
=head2 branchcode
Type: belongs_to
Related object: L<Koha::Schema::Result::Branch>
=cut
__PACKAGE__->belongs_to(
"branchcode",
"Koha::Schema::Result::Branch",
{ branchcode => "branchcode" },
{ is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" },
);
=head2 categorycode
Type: belongs_to
Related object: L<Koha::Schema::Result::Category>
=cut
__PACKAGE__->belongs_to(
"categorycode",
"Koha::Schema::Result::Category",
{ categorycode => "categorycode" },
{ is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" },
);
=head2 pseudonymized_borrower_attributes
Type: has_many
@ -295,29 +250,9 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);
=head2 transaction_branchcode
Type: belongs_to
Related object: L<Koha::Schema::Result::Branch>
=cut
__PACKAGE__->belongs_to(
"transaction_branchcode",
"Koha::Schema::Result::Branch",
{ branchcode => "transaction_branchcode" },
{
is_deferrable => 1,
join_type => "LEFT",
on_delete => "RESTRICT",
on_update => "RESTRICT",
},
);
# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-03-17 16:28:03
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jgUZi4W5vJo33KdKI7+jyQ
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-11-19 14:20:11
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GVTIlyIi8Vquhf662tDmsQ
__PACKAGE__->add_columns(
'+has_cardnumber' => { is_boolean => 1 },

10
cataloguing/addbooks.pl

@ -38,7 +38,6 @@ use Koha::BiblioFrameworks;
use Koha::SearchEngine::Search;
use Koha::SearchEngine::QueryBuilder;
use Koha::Z3950Servers;
use Business::ISBN;
my $input = CGI->new;
@ -106,14 +105,7 @@ if ($query) {
my $countbr = 0;
my @resultsbr;
if ($query) {
my ( $title, $isbn );
my $isbn_valid = Business::ISBN->new($query);
if ( $isbn_valid && $isbn_valid->is_valid() ) {
$isbn = $query;
} else {
$title = $query;
}
( $countbr, @resultsbr ) = BreedingSearch( $title, $isbn );
( $countbr, @resultsbr ) = BreedingSearch( $query );
}
my $breeding_loop = [];
for my $resultsbr (@resultsbr) {

3
circ/circulation.pl

@ -26,6 +26,7 @@
use Modern::Perl;
use CGI qw ( -utf8 );
use URI::Escape qw( uri_escape_utf8 );
use DateTime;
use DateTime::Duration;
use Scalar::Util qw( looks_like_number );
@ -227,7 +228,7 @@ if ($findborrower) {
if ( $patron ) {
$borrowernumber = $patron->borrowernumber;
} else {
print $query->redirect( "/cgi-bin/koha/members/member.pl?quicksearch=1&circsearch=1&searchmember=" . $findborrower );
print $query->redirect( "/cgi-bin/koha/members/member.pl?quicksearch=1&circsearch=1&searchmember=" . uri_escape_utf8($findborrower) );
exit;
}
}

17
installer/data/mysql/db_revs/210600048.pl

@ -0,0 +1,17 @@
use Modern::Perl;
return {
bug_number => "29341",
description => "Remove foreign keys on pseudonymized_transactions",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
for my $fk ( qw( pseudonymized_transactions_borrowers_ibfk_2 pseudonymized_transactions_borrowers_ibfk_3 pseudonymized_transactions_ibfk_1 ) ) {
if ( foreign_key_exists( 'pseudonymized_transactions', $fk ) ) {
$dbh->do(qq{
ALTER TABLE pseudonymized_transactions DROP FOREIGN KEY $fk
});
}
}
},
}

11
installer/data/mysql/db_revs/210600049.pl

@ -0,0 +1,11 @@
use Modern::Perl;
return {
bug_number => "5229",
description => "Remove system preference 'OPACItemsResultsDisplay'",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
$dbh->do(q{DELETE FROM systempreferences WHERE variable='OPACItemsResultsDisplay'});
},
}

5
installer/data/mysql/kohastructure.sql

@ -4230,10 +4230,7 @@ CREATE TABLE `pseudonymized_transactions` (
PRIMARY KEY (`id`),
KEY `pseudonymized_transactions_ibfk_1` (`categorycode`),
KEY `pseudonymized_transactions_borrowers_ibfk_2` (`branchcode`),
KEY `pseudonymized_transactions_borrowers_ibfk_3` (`transaction_branchcode`),
CONSTRAINT `pseudonymized_transactions_borrowers_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`),
CONSTRAINT `pseudonymized_transactions_borrowers_ibfk_3` FOREIGN KEY (`transaction_branchcode`) REFERENCES `branches` (`branchcode`),
CONSTRAINT `pseudonymized_transactions_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
KEY `pseudonymized_transactions_borrowers_ibfk_3` (`transaction_branchcode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

1
installer/data/mysql/mandatory/sysprefs.sql

File diff suppressed because one or more lines are too long

2
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt

@ -295,7 +295,7 @@ Batch list
[% END %]
[% IF ( iteminformatio.marc_value.type == 'select' ) %]
<select name="field_value">
<select name="field_value" class="input_marceditor">
[% FOREACH value IN iteminformatio.marc_value.values %]
[% IF ( value == iteminformatio.marc_value.default ) %]
<option value="[% value | html %]" selected="selected">[% iteminformatio.marc_value.labels.$value | html %]</option>

2
koha-tmpl/intranet-tmpl/prog/en/modules/admin/categories.tt

@ -596,6 +596,8 @@
[% ELSIF ( prefs.Item_Checkout ) %]Item checkout
[% ELSIF ( prefs.Ill_ready ) %]Interlibrary loan ready
[% ELSIF ( prefs.Ill_unavailable ) %]Interlibrary loan unavailable
[% ELSIF ( prefs.Auto_Renewals ) %]Auto renewal
[% ELSIF ( prefs.Hold_Reminder ) %]Hold reminder
[% ELSE %]Unknown
[% END %]:
<strong>[% transport.transport | html %]</strong><br />

7
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref

@ -253,13 +253,6 @@ Searching:
home: "home library"
holding: "holding library"
both: "both home and holding library"
-
- pref: OPACItemsResultsDisplay
type: boolean
choices:
1: Show
0: "Don't show"
- "an item's library, location and call number in OPAC search results."
-
- Truncate facets length to
- pref: FacetLabelTruncationLength

2
koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt

@ -246,7 +246,7 @@ $(document).ready(function() {
<label>[% iteminformatio.subfield | html %] - [% iteminformatio.marc_lib | $raw %]</label>
[% END %]
[% IF ( iteminformatio.marc_value.type == 'select' ) %]
<select name="field_value" class="select2">
<select name="field_value" class="select2 input_marceditor">
[% FOREACH value IN iteminformatio.marc_value.values %]
[% IF ( value == iteminformatio.marc_value.default ) %]
<option value="[% value | html %]" selected="selected">[% iteminformatio.marc_value.labels.$value | html %]</option>

2
koha-tmpl/intranet-tmpl/prog/en/modules/services/itemrecorddisplay.tt

@ -13,7 +13,7 @@
<label>[% iteminfo.subfield | html %] - [% iteminfo.marc_lib | $raw %]</label>
[% END %]
[% IF ( iteminfo.marc_value.type == 'select' ) %]
<select name="field_value">
<select name="field_value" class="input_marceditor">
[% FOREACH value IN iteminfo.marc_value.values %]
[% IF ( value == iteminfo.marc_value.default ) %]
<option value="[% value | html %]" selected="selected">[% iteminfo.marc_value.labels.$value | html %]</option>

1
opac/opac-search.pl

@ -763,7 +763,6 @@ for (my $i=0;$i<@servers;$i++) {
$template->param(
SEARCH_RESULTS => \@newresults,
OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay")),
suppress_result_number => $hide,
);
if (C4::Context->preference("OPACLocalCoverImages")){

39
t/db_dependent/Breeding.t

@ -22,14 +22,15 @@
# These subroutines are actually internal, but these tests may pave the way for
# a more comprehensive test of Z3950Search itself.
#
# TODO We need additional tests for Z3950SearchAuth, BreedingSearch
# TODO We need additional tests for Z3950SearchAuth
use Modern::Perl;
use File::Temp qw/tempfile/;
use Test::More tests => 5;
use Test::More tests => 6;
use Test::Warn;
use t::lib::Mocks qw( mock_preference );
use t::lib::TestBuilder;
use C4::Context;
use C4::Breeding;
@ -37,6 +38,7 @@ use Koha::Database;
use Koha::XSLT::Base;
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
$schema->storage->txn_begin;
#Group 1: testing _build_query and _translate_query (part of Z3950Search)
@ -84,6 +86,39 @@ subtest ImportBreedingAuth => sub {
isnt( $breedingid, $breedingid_2, "For a new record, we get a new id");
};
subtest BreedingSearch => sub {
plan tests => 5;
my $import_biblio_1 = $builder->build({ source => 'ImportBiblio', value => {
title => 'Unique title the first adventure',
author => 'Firstnamey Surnamey',
isbn => '1407239961'
}
});
my $import_biblio_2 = $builder->build({ source => 'ImportBiblio', value => {
title => 'Unique title the adventure continues',
author => 'Firstnamey Surnamey',
isbn => '9798200834976'
}
});
my ($count, @results) = C4::Breeding::BreedingSearch("Firstnamey Surnamey");
is( $count, 2, "Author search returns two results");
($count, @results) = C4::Breeding::BreedingSearch("first adventure");
is( $count, 1, "Title search returns one result");
($count, @results) = C4::Breeding::BreedingSearch("adventure continues");
is( $count, 1, "Title search returns one result");
($count, @results) = C4::Breeding::BreedingSearch("9781407239965");
is( $count, 1, "ISBN search matches normalized DB value");
($count, @results) = C4::Breeding::BreedingSearch("9798200834976");
is( $count, 1, "ISBN search for 13 digit ISBN matches 13 digit ISBN in database");
# FIXME - Import doesn't currently store these, but this proves the search works
};
$schema->storage->txn_rollback;
#-------------------------------------------------------------------------------

74
t/db_dependent/Koha/BackgroundJobs/BatchUpdateBiblio.t

@ -0,0 +1,74 @@
#!/usr/bin/perl
# Copyright 2021 Koha Development team
#
# This file is part of Koha
#
# Koha is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Koha is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 1;
use Test::MockModule;
use JSON qw( encode_json decode_json );
use Koha::Database;
use Koha::BackgroundJobs;
use Koha::BackgroundJob::BatchUpdateBiblio;
use Koha::Exceptions::Exception;
use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
subtest "Exceptions must be stringified" => sub {
plan tests => 1;
$schema->storage->txn_begin;
my $C4_biblio_module = Test::MockModule->new('C4::Biblio');
$C4_biblio_module->mock( 'ModBiblio',
sub { Koha::Exceptions::Exception->throw("It didn't work"); } );
my $biblio = $builder->build_sample_biblio;
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $job = Koha::BackgroundJob::BatchUpdateBiblio->new(
{
status => 'new',
size => 1,
borrowernumber => $patron->borrowernumber,
type => 'batch_biblio_record_modification',
data => encode_json {
record_ids => [ $biblio->biblionumber ],
}
}
)->store;
$job = Koha::BackgroundJobs->find( $job->id );
$job->process(
{ job_id => $job->id, record_ids => [ $biblio->biblionumber ] } );
my $data = decode_json $job->get_from_storage->data;
is_deeply(
$data->{messages}->[0],
{
biblionumber => $biblio->biblionumber,
code => 'biblio_not_modified',
error => "It didn't work",
type => "error"
}
);
$schema->storage->txn_rollback;
};
Loading…
Cancel
Save