package Koha::Prosentient::Frameworks; # This file is part of Koha. # # Copyright Prosentient Systems 2014 # # 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 base qw(Class::Accessor); __PACKAGE__->mk_accessors(qw( X )); =head1 NAME Koha::Prosentient::Frameworks =head1 SYNOPSIS use Koha::Prosentient::Frameworks; my $KohaFrameworks = Koha::Prosentient::Frameworks->new(); =head1 DESCRIPTION This class adds third-party (ie Prosentient) MARC bibliographic framework management functionality =cut sub new { my ($class, $args) = @_; $args = {} unless defined $args; return bless ($args, $class); } =head2 UpdateFrameworkStructureFromCanon Search the database for framework fields and subfields using a DBIC resultset, and an arrayref of hashrefs containing a canonical version of the field or subfield bibliographic framework. Resets frameworkcode value in the hashref, as well as other values via a callback function Inserts/updates framework fields/subfields using DBIC and callback functions. =cut sub UpdateFrameworkStructureFromCanon { my ( $self, $args ) = @_; my $canonical_structure = $args->{canonical_structure}; my $dbic_resultset = $args->{dbic_resultset}; my $frameworkcodes = $args->{frameworkcodes}; my $canon_callback = $args->{canon_callback}; my $db_insert_callback = $args->{db_insert_callback} // sub { my ( $d_unit ) = @_; $d_unit->insert; }; my $db_update_callback = $args->{db_update_callback}; if ( $canonical_structure && $dbic_resultset ){ foreach my $frameworkcode (@{$frameworkcodes}){ #Iterate through canonical structure foreach my $canon_unit (@{$canonical_structure}){ $canon_unit->{frameworkcode} = $frameworkcode; #Reset some attributes for the canon_unit using a callback if ($canon_callback){ $canon_callback->({ c_unit => $canon_unit, }); } #Database interaction my $database_unit = $dbic_resultset->find_or_new($canon_unit,{ key => "primary" }); if( !$database_unit->in_storage ) { #The callback will perform the actual insertion if ($db_insert_callback){ $db_insert_callback->({ d_unit => $database_unit, }); } } elsif ($database_unit->in_storage) { #The callback will perform the actual update if ($db_update_callback){ $db_update_callback->({ d_unit => $database_unit, c_unit => $canon_unit, }); } } } } } } 1;