Bugzilla – Attachment 135259 Details for
Bug 30830
Add Koha Objects for Koha Import Items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30830: Add Koha Objects for Koha Import Items
Bug-30830-Add-Koha-Objects-for-Koha-Import-Items.patch (text/plain), 9.00 KB, created by
Nick Clemens (kidclamp)
on 2022-05-23 11:28:20 UTC
(
hide
)
Description:
Bug 30830: Add Koha Objects for Koha Import Items
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2022-05-23 11:28:20 UTC
Size:
9.00 KB
patch
obsolete
>From ac8816d94d6e878887355b048f2b43556e86b95f Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 23 May 2022 11:25:02 +0000 >Subject: [PATCH] Bug 30830: Add Koha Objects for Koha Import Items > >To test: >prove -v t/db_dependent/Koha/Import/Record/Items.t >--- > C4/ImportBatch.pm | 16 ++++--- > Koha/Import/Record/Item.pm | 44 ++++++++++++++++++ > Koha/Import/Record/Items.pm | 56 +++++++++++++++++++++++ > Koha/Schema/Result/ImportItem.pm | 6 +++ > t/db_dependent/Koha/Import/Record/Items.t | 46 +++++++++++++++++++ > t/lib/TestBuilder.pm | 4 ++ > 6 files changed, 166 insertions(+), 6 deletions(-) > create mode 100644 Koha/Import/Record/Item.pm > create mode 100644 Koha/Import/Record/Items.pm > create mode 100755 t/db_dependent/Koha/Import/Record/Items.t > >diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm >index e0dd051491..956c957ebf 100644 >--- a/C4/ImportBatch.pm >+++ b/C4/ImportBatch.pm >@@ -770,13 +770,14 @@ sub BatchCommitItems { > my $duplicate_barcode = exists( $item->{'barcode'} ) && Koha::Items->find({ barcode => $item->{'barcode'} }); > my $duplicate_itemnumber = exists( $item->{'itemnumber'} ); > >- my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ? WHERE import_items_id = ?"); >+ my $updsth = $dbh->prepare("UPDATE import_items SET status = ?, itemnumber = ?, import_error = ? WHERE import_items_id = ?"); > if ( $action eq "replace" && $duplicate_itemnumber ) { > # Duplicate itemnumbers have precedence, that way we can update barcodes by overlaying > ModItemFromMarc( $item_marc, $biblionumber, $item->{itemnumber} ); > $updsth->bind_param( 1, 'imported' ); > $updsth->bind_param( 2, $item->{itemnumber} ); >- $updsth->bind_param( 3, $row->{'import_items_id'} ); >+ $updsth->bind_param( 3, undef ); >+ $updsth->bind_param( 4, $row->{'import_items_id'} ); > $updsth->execute(); > $updsth->finish(); > $num_items_replaced++; >@@ -785,14 +786,16 @@ sub BatchCommitItems { > ModItemFromMarc( $item_marc, $biblionumber, $itemnumber ); > $updsth->bind_param( 1, 'imported' ); > $updsth->bind_param( 2, $item->{itemnumber} ); >- $updsth->bind_param( 3, $row->{'import_items_id'} ); >+ $updsth->bind_param( 3, undef ); >+ $updsth->bind_param( 4, $row->{'import_items_id'} ); > $updsth->execute(); > $updsth->finish(); > $num_items_replaced++; > } elsif ($duplicate_barcode) { > $updsth->bind_param( 1, 'error' ); >- $updsth->bind_param( 2, 'duplicate item barcode' ); >- $updsth->bind_param( 3, $row->{'import_items_id'} ); >+ $updsth->bind_param( 2, undef ); >+ $updsth->bind_param( 3, 'duplicate item barcode' ); >+ $updsth->bind_param( 4, $row->{'import_items_id'} ); > $updsth->execute(); > $num_items_errored++; > } else { >@@ -804,7 +807,8 @@ sub BatchCommitItems { > if( $itemnumber ) { > $updsth->bind_param( 1, 'imported' ); > $updsth->bind_param( 2, $itemnumber ); >- $updsth->bind_param( 3, $row->{'import_items_id'} ); >+ $updsth->bind_param( 3, undef ); >+ $updsth->bind_param( 4, $row->{'import_items_id'} ); > $updsth->execute(); > $updsth->finish(); > $num_items_added++; >diff --git a/Koha/Import/Record/Item.pm b/Koha/Import/Record/Item.pm >new file mode 100644 >index 0000000000..37c5e165f4 >--- /dev/null >+++ b/Koha/Import/Record/Item.pm >@@ -0,0 +1,44 @@ >+package Koha::Import::Record::Item; >+ >+# 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 Carp; >+ >+use Koha::Database; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::Import::Record::Item - Koha Import Record Item Object class >+ >+=head1 API >+ >+=head2 Internal methods >+ >+=head3 _type >+ >+Returns name of corresponding DBIC resultset >+ >+=cut >+ >+sub _type { >+ return 'ImportItem'; >+} >+ >+1; >diff --git a/Koha/Import/Record/Items.pm b/Koha/Import/Record/Items.pm >new file mode 100644 >index 0000000000..1f0047477e >--- /dev/null >+++ b/Koha/Import/Record/Items.pm >@@ -0,0 +1,56 @@ >+package Koha::Import::Record::Items; >+ >+# 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 Carp; >+ >+use Koha::Database; >+ >+use Koha::Import::Record::Item; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::Import::Record::Items - Koha Import Record Items Object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'ImportItem'; >+} >+ >+=head3 object_class >+ >+Koha::Object class >+ >+=cut >+ >+sub object_class { >+ return 'Koha::Import::Record::Item'; >+} >+ >+1; >diff --git a/Koha/Schema/Result/ImportItem.pm b/Koha/Schema/Result/ImportItem.pm >index 6d13719ee1..58c098c0f5 100644 >--- a/Koha/Schema/Result/ImportItem.pm >+++ b/Koha/Schema/Result/ImportItem.pm >@@ -120,6 +120,12 @@ __PACKAGE__->belongs_to( > # Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:53 > # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GaUyqPnOhETQO8YuuKvfNQ > >+sub koha_object_class { >+ 'Koha::Import::Record::Item'; >+} >+sub koha_objects_class { >+ 'Koha::Import::Record::Items'; >+} > > # You can replace this text with custom content, and it will be preserved on regeneration > 1; >diff --git a/t/db_dependent/Koha/Import/Record/Items.t b/t/db_dependent/Koha/Import/Record/Items.t >new file mode 100755 >index 0000000000..de5b6dd916 >--- /dev/null >+++ b/t/db_dependent/Koha/Import/Record/Items.t >@@ -0,0 +1,46 @@ >+#!/usr/bin/perl >+ >+# Copyright 2020 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 => 3; >+ >+use Koha::Import::Record::Items; >+use Koha::Database; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+$schema->storage->txn_begin; >+ >+my $builder = t::lib::TestBuilder->new; >+my $nb_of_record_items = Koha::Import::Record::Items->search->count; >+ >+my $record_item_1 = $builder->build({ source => 'ImportItem' }); >+my $record_item_2 = $builder->build({ source => 'ImportItem' }); >+ >+is( Koha::Import::Record::Items->search->count, $nb_of_record_items + 2, 'The 2 record items should have been added' ); >+ >+my $retrieved_record_item_1 = Koha::Import::Record::Items->search({ import_items_id => $record_item_1->{import_items_id}})->next; >+is_deeply( $retrieved_record_item_1->unblessed, $record_item_1, 'Find a record item by import items id should return the correct record item' ); >+ >+$retrieved_record_item_1->delete; >+is( Koha::Import::Record::Items->search->count, $nb_of_record_items + 1, 'Delete should have deleted the record item' ); >+ >+$schema->storage->txn_rollback; >diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm >index bf25c89693..86a793f1b9 100644 >--- a/t/lib/TestBuilder.pm >+++ b/t/lib/TestBuilder.pm >@@ -605,6 +605,10 @@ sub _gen_default_values { > issue_id => undef, # It should be a FK but we removed it > # We don't want to generate a random value > }, >+ ImportItem => { >+ status => 'staged', >+ import_error => undef >+ }, > }; > } > >-- >2.30.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 30830
:
135259
|
135261
|
135282
|
135296