@@ -, +, @@ --- 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 ++ 5 files changed, 156 insertions(+) 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 --- a/Koha/Import/Record/Item.pm +++ a/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 . + +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; --- a/Koha/Import/Record/Items.pm +++ a/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 . + +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; --- a/Koha/Schema/Result/ImportItem.pm +++ a/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; --- a/t/db_dependent/Koha/Import/Record/Items.t +++ a/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 . + +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; --- a/t/lib/TestBuilder.pm +++ a/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 + }, }; } --