use C4::Output;
use C4::Auth;
use C4::AuthoritiesMarc;
-use Koha::MetadataRecord::Authority;
use C4::Koha;
use C4::Biblio;
+use Koha::Authority::Types;
use Koha::Exceptions;
+use Koha::MetadataRecord::Authority;
my $input = new CGI;
my @authid = $input->multi_param('authid');
# Creating a new record from the html code
my $record = TransformHtmlToMarc($input, 0);
- my $recordid1 = $input->param('recordid1');
- my $recordid2 = $input->param('recordid2');
+ my $recordid1 = $input->param('recordid1') // q{};
+ my $recordid2 = $input->param('recordid2') // q{};
my $typecode = $input->param('frameworkcode');
+ # Some error checking
+ if( $recordid1 eq $recordid2 ) {
+ push @errors, { code => 'DESTRUCTIVE_MERGE' };
+ } elsif( !$typecode || !Koha::Authority::Types->find($typecode) ) {
+ push @errors, { code => 'WRONG_FRAMEWORK' };
+ } elsif( scalar $record->fields == 0 ) {
+ push @errors, { code => 'EMPTY_MARC' };
+ }
+ if( @errors ) {
+ $template->param( errors => \@errors );
+ output_html_with_http_headers $input, $cookie, $template->output;
+ exit;
+ }
+
# Rewriting the leader
- $record->leader( GetAuthority($recordid1)->leader() );
+ if( my $authrec = GetAuthority($recordid1) ) {
+ $record->leader( $authrec->leader() );
+ }
# Modifying the reference record
# This triggers a merge for the biblios attached to $recordid1
if ( scalar(@authid) != 2 ) {
push @errors, { code => "WRONG_COUNT", value => scalar(@authid) };
- }
- else {
+ } elsif( $authid[0] eq $authid[1] ) {
+ push @errors, { code => 'DESTRUCTIVE_MERGE' };
+ } else {
my $recordObj1 = Koha::MetadataRecord::Authority->get_from_authid($authid[0]);
Koha::Exceptions::ObjectNotFound->throw( "No authority record found for authid $authid[0]\n" ) if !$recordObj1;
my $framework;
if ( $recordObj1->authtypecode ne $recordObj2->authtypecode && $mergereference ne 'breeding' ) {
- $framework = $input->param('frameworkcode')
- or push @errors, { code => 'FRAMEWORK_NOT_SELECTED' };
+ $framework = $input->param('frameworkcode');
}
else {
$framework = $recordObj1->authtypecode;
title2 => $recordObj2->authorized_heading,
);
if ( $recordObj1->authtypecode ne $recordObj2->authtypecode ) {
- my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } );
- my @frameworkselect;
- while ( my $authority_type = $authority_types->next ) {
- my %row = (
- value => $authority_type->authtypecode,
- frameworktext => $authority_type->authtypetext,
- );
- push @frameworkselect, \%row;
- }
+ my $authority_types = Koha::Authority::Types->search( { authtypecode => { '!=' => '' } }, { order_by => ['authtypecode'] } );
$template->param(
- frameworkselect => \@frameworkselect,
+ frameworkselect => $authority_types->unblessed,
frameworkcode1 => $recordObj1->authtypecode,
frameworkcode2 => $recordObj2->authtypecode,
);
}
}
-my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']});
-$template->param( authority_types => $authority_types );
-
if (@errors) {
-
- # Errors
$template->param( errors => \@errors );
}
-
output_html_with_http_headers $input, $cookie, $template->output;
-exit;
-
-=head1 FUNCTIONS
-
-=cut
-
-# ------------------------
-# Functions
-# ------------------------
<h1>Merging records</h1>
-[% IF ( result ) %]
- [% IF ( errors ) %]
+
+[% IF ( errors ) %]
[% FOREACH error IN errors %]
<div class="dialog alert">
-
- [% IF error.code == 'CANNOT_MOVE' %]
- The following items could not be moved from the old record to the new one: [% error.value %]
- [% ELSIF error.code == 'FRAMEWORK_NOT_SELECTED' %]
- No framework has been selected. Please select a framework for merging.
- [% ELSE %]
- [% error %]
- [% END %]
-
- <br />Therefore, the record to be merged has not been deleted.</div>
+ [% IF error.code == 'WRONG_COUNT' %]
+ Number of records provided for merging: [% error.value %]. Currently only 2 records can be merged at a time.
+ [% ELSIF error.code == 'DESTRUCTIVE_MERGE' %]
+ You cannot merge a record with itself. Please select two different authorities.
+ [% ELSIF error.code == 'WRONG_FRAMEWORK' %]
+ The Default framework cannot be used, or the framework does not exist. Please select another framework for merging.
+ [% ELSIF error.code == 'EMPTY_MARC' %]
+ Sorry, but we did not find any MARC tags in the reference record.
+ [% ELSE %]
+ [% error %]
+ [% END %]
+ </div>
[% END %]
- [% ELSE %]
+[% ELSIF ( result ) %]
+
<script type="text/javascript">window.location.href="/cgi-bin/koha/authorities/detail.pl?authid=[% recordid1 %]"</script>
<p>The merging was successful. <a href="/cgi-bin/koha/authorities/detail.pl?authid=[% recordid1 %]">Click here to see the merged record.</a></p>
- [% END %]
-[% ELSE %]
+[% ELSIF ( choosereference ) %]
-[% IF ( choosereference ) %]
<p>Please choose which record will be the reference for the merge. The record chosen as reference will be kept, and the other will be deleted.</p>
<form id="mergeform" action="/cgi-bin/koha/authorities/merge.pl" method="post">
<fieldset class="rows">
<select name="frameworkcode" id="frameworkcode">
[% FOREACH frameworkcodeloo IN frameworkselect %]
[% IF frameworkcodeloo.authtypecode == frameworkcode1 %]
- <option value="[% frameworkcodeloo.value %]" selected="selected">
+ <option value="[% frameworkcodeloo.authtypecode %]" selected="selected">
[% ELSE %]
- <option value="[% frameworkcodeloo.value %]">
+ <option value="[% frameworkcodeloo.authtypecode %]">
[% END %]
- [% frameworkcodeloo.frameworktext %]
+ [% frameworkcodeloo.authtypetext %]
</option>
[% END %]
</select></li>
<fieldset class="action"><input type="submit" value="Next" /></fieldset>
</fieldset>
</form>
+
[% ELSE %]
-[% IF ( errors ) %]
- <div class="dialog alert">
- [% FOREACH error IN errors %]
- <p>
- [% IF error.code == 'WRONG_COUNT' %]
- Number of records provided for merging: [% error.value %]. Currently only 2 records can be merged at a time.
- [% ELSE %]
- [% error %]
- [% END %]
-
- </p>
- [% END %]
- </div>
-[% ELSE %]
+
<form id="mergeform" action="/cgi-bin/koha/authorities/merge.pl" method="post" onsubmit="return mergeformsubmit()">
<div class="yui-g">
<fieldset class="action"><input type="submit" name="merge" value="Merge" /></fieldset>
</div>
</form>
-[% END %]
-[% END %]
+
[% END %]
</div>