From a3f96218a63e2dc84bc252f3420773f7500f1611 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Sun, 1 Jan 2017 11:50:44 +0100 Subject: [PATCH] Bug 9988: Add Koha objects for table need_merge_authorities Content-Type: text/plain; charset=utf-8 Test plan: Run t/db_dependent/Koha/Authorities.t Signed-off-by: Marcel de Rooy --- Koha/Authority.pm | 22 ++++++++---- Koha/AuthorityMergeRequest.pm | 60 ++++++++++++++++++++++++++++++++ Koha/AuthorityMergeRequests.pm | 72 +++++++++++++++++++++++++++++++++++++++ t/db_dependent/Koha/Authorities.t | 20 +++++++++-- 4 files changed, 166 insertions(+), 8 deletions(-) create mode 100644 Koha/AuthorityMergeRequest.pm create mode 100644 Koha/AuthorityMergeRequests.pm diff --git a/Koha/Authority.pm b/Koha/Authority.pm index b533fd7..e9fc8d8 100644 --- a/Koha/Authority.pm +++ b/Koha/Authority.pm @@ -19,13 +19,8 @@ package Koha::Authority; use Modern::Perl; -use Carp; - -use Koha::Database; -use C4::Context; -use MARC::Record; - use base qw(Koha::Object); +use Koha::AuthorityMergeRequest; =head1 NAME @@ -33,6 +28,21 @@ Koha::Authority - Koha Authority Object class =head1 API +=head2 Instance Methods + +=cut + +=head3 add_merge_request + +=cut + +sub add_merge_request { + my ( $self ) = @_; + if( $self->in_storage ) { + Koha::AuthorityMergeRequest->new({ authid => $self->authid })->store; + } +} + =head2 Class Methods =cut diff --git a/Koha/AuthorityMergeRequest.pm b/Koha/AuthorityMergeRequest.pm new file mode 100644 index 0000000..52a86cd --- /dev/null +++ b/Koha/AuthorityMergeRequest.pm @@ -0,0 +1,60 @@ +package Koha::AuthorityMergeRequest; + +# Copyright Rijksmuseum 2017 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use parent qw(Koha::Object); + +=head1 NAME + +Koha::AuthorityMergeRequest - Koha::Object class for single need_merge_authorities record + +=head1 SYNOPSIS + +use Koha::AuthorityMergeRequest; + +=head1 DESCRIPTION + +Description + +=head1 METHODS + +=head2 INSTANCE METHODS + +=head2 CLASS METHODS + +=head3 _type + +Returns name of corresponding DBIC resultset + +=cut + +sub _type { + return 'NeedMergeAuthority'; +} + +=head1 AUTHOR + +Marcel de Rooy (Rijksmuseum) + +Koha Development Team + +=cut + +1; diff --git a/Koha/AuthorityMergeRequests.pm b/Koha/AuthorityMergeRequests.pm new file mode 100644 index 0000000..9d7b971 --- /dev/null +++ b/Koha/AuthorityMergeRequests.pm @@ -0,0 +1,72 @@ +package Koha::AuthorityMergeRequests; + +# Copyright Rijksmuseum 2017 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Koha::AuthorityMergeRequest; + +use parent qw(Koha::Objects); + +=head1 NAME + +Koha::AuthorityMergeRequests - Koha::Objects class for need_merge_authorities + +=head1 SYNOPSIS + +use Koha::AuthorityMergeRequests; + +=head1 DESCRIPTION + +Description + +=head1 METHODS + +=head2 INSTANCE METHODS + +=head2 CLASS METHODS + +=head3 _type + +Returns name of corresponding DBIC resultset + +=cut + +sub _type { + return 'NeedMergeAuthority'; +} + +=head3 object_class + +Returns name of corresponding Koha object class + +=cut + +sub object_class { + return 'Koha::AuthorityMergeRequest'; +} + +=head1 AUTHOR + +Marcel de Rooy (Rijksmuseum) + +Koha Development Team + +=cut + +1; diff --git a/t/db_dependent/Koha/Authorities.t b/t/db_dependent/Koha/Authorities.t index 7210713..20ceaab 100644 --- a/t/db_dependent/Koha/Authorities.t +++ b/t/db_dependent/Koha/Authorities.t @@ -19,10 +19,11 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; use Koha::Authority; use Koha::Authorities; +use Koha::AuthorityMergeRequests; use Koha::Authority::Type; use Koha::Authority::Types; use Koha::Database; @@ -51,5 +52,20 @@ is( Koha::Authorities->search->count, $nb_of_authorities + 2, 'The 2 au $new_authority_1->delete; is( Koha::Authorities->search->count, $nb_of_authorities + 1, 'Delete should have deleted the library' ); +subtest 'Add merge request' => sub { + plan tests => 2; + + my $count = Koha::AuthorityMergeRequests->count; + $new_authority_2->add_merge_request; + is( Koha::AuthorityMergeRequests->count, + $count+1, + 'Merge request added' ); + my $new_authority_3 = Koha::Authority->new; + $new_authority_3->add_merge_request; + is( Koha::AuthorityMergeRequests->count, + $count+1, + 'No additional merge request added (not in storage)' ); + +}; + $schema->storage->txn_rollback; -1; -- 2.1.4