Lines 23-33
use CGI qw ( -utf8 );
Link Here
|
23 |
use C4::Output; |
23 |
use C4::Output; |
24 |
use C4::Auth; |
24 |
use C4::Auth; |
25 |
use C4::AuthoritiesMarc; |
25 |
use C4::AuthoritiesMarc; |
26 |
use Koha::MetadataRecord::Authority; |
|
|
27 |
use C4::Koha; |
26 |
use C4::Koha; |
28 |
use C4::Biblio; |
27 |
use C4::Biblio; |
29 |
|
28 |
|
|
|
29 |
use Koha::Authority::Types; |
30 |
use Koha::Exceptions; |
30 |
use Koha::Exceptions; |
|
|
31 |
use Koha::MetadataRecord::Authority; |
31 |
|
32 |
|
32 |
my $input = new CGI; |
33 |
my $input = new CGI; |
33 |
my @authid = $input->multi_param('authid'); |
34 |
my @authid = $input->multi_param('authid'); |
Lines 52-63
if ($merge) {
Link Here
|
52 |
|
53 |
|
53 |
# Creating a new record from the html code |
54 |
# Creating a new record from the html code |
54 |
my $record = TransformHtmlToMarc($input, 0); |
55 |
my $record = TransformHtmlToMarc($input, 0); |
55 |
my $recordid1 = $input->param('recordid1'); |
56 |
my $recordid1 = $input->param('recordid1') // q{}; |
56 |
my $recordid2 = $input->param('recordid2'); |
57 |
my $recordid2 = $input->param('recordid2') // q{}; |
57 |
my $typecode = $input->param('frameworkcode'); |
58 |
my $typecode = $input->param('frameworkcode'); |
58 |
|
59 |
|
|
|
60 |
# Some error checking |
61 |
if( $recordid1 eq $recordid2 ) { |
62 |
push @errors, { code => 'DESTRUCTIVE_MERGE' }; |
63 |
} elsif( !$typecode || !Koha::Authority::Types->find($typecode) ) { |
64 |
push @errors, { code => 'WRONG_FRAMEWORK' }; |
65 |
} elsif( scalar $record->fields == 0 ) { |
66 |
push @errors, { code => 'EMPTY_MARC' }; |
67 |
} |
68 |
if( @errors ) { |
69 |
$template->param( errors => \@errors ); |
70 |
output_html_with_http_headers $input, $cookie, $template->output; |
71 |
exit; |
72 |
} |
73 |
|
59 |
# Rewriting the leader |
74 |
# Rewriting the leader |
60 |
$record->leader( GetAuthority($recordid1)->leader() ); |
75 |
if( my $authrec = GetAuthority($recordid1) ) { |
|
|
76 |
$record->leader( $authrec->leader() ); |
77 |
} |
61 |
|
78 |
|
62 |
# Modifying the reference record |
79 |
# Modifying the reference record |
63 |
# This triggers a merge for the biblios attached to $recordid1 |
80 |
# This triggers a merge for the biblios attached to $recordid1 |
Lines 87-94
else {
Link Here
|
87 |
|
104 |
|
88 |
if ( scalar(@authid) != 2 ) { |
105 |
if ( scalar(@authid) != 2 ) { |
89 |
push @errors, { code => "WRONG_COUNT", value => scalar(@authid) }; |
106 |
push @errors, { code => "WRONG_COUNT", value => scalar(@authid) }; |
90 |
} |
107 |
} elsif( $authid[0] eq $authid[1] ) { |
91 |
else { |
108 |
push @errors, { code => 'DESTRUCTIVE_MERGE' }; |
|
|
109 |
} else { |
92 |
my $recordObj1 = Koha::MetadataRecord::Authority->get_from_authid($authid[0]); |
110 |
my $recordObj1 = Koha::MetadataRecord::Authority->get_from_authid($authid[0]); |
93 |
Koha::Exceptions::ObjectNotFound->throw( "No authority record found for authid $authid[0]\n" ) if !$recordObj1; |
111 |
Koha::Exceptions::ObjectNotFound->throw( "No authority record found for authid $authid[0]\n" ) if !$recordObj1; |
94 |
|
112 |
|
Lines 104-111
else {
Link Here
|
104 |
|
122 |
|
105 |
my $framework; |
123 |
my $framework; |
106 |
if ( $recordObj1->authtypecode ne $recordObj2->authtypecode && $mergereference ne 'breeding' ) { |
124 |
if ( $recordObj1->authtypecode ne $recordObj2->authtypecode && $mergereference ne 'breeding' ) { |
107 |
$framework = $input->param('frameworkcode') |
125 |
$framework = $input->param('frameworkcode'); |
108 |
or push @errors, { code => 'FRAMEWORK_NOT_SELECTED' }; |
|
|
109 |
} |
126 |
} |
110 |
else { |
127 |
else { |
111 |
$framework = $recordObj1->authtypecode; |
128 |
$framework = $recordObj1->authtypecode; |
Lines 167-183
else {
Link Here
|
167 |
title2 => $recordObj2->authorized_heading, |
184 |
title2 => $recordObj2->authorized_heading, |
168 |
); |
185 |
); |
169 |
if ( $recordObj1->authtypecode ne $recordObj2->authtypecode ) { |
186 |
if ( $recordObj1->authtypecode ne $recordObj2->authtypecode ) { |
170 |
my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } ); |
187 |
my $authority_types = Koha::Authority::Types->search( { authtypecode => { '!=' => '' } }, { order_by => ['authtypecode'] } ); |
171 |
my @frameworkselect; |
|
|
172 |
while ( my $authority_type = $authority_types->next ) { |
173 |
my %row = ( |
174 |
value => $authority_type->authtypecode, |
175 |
frameworktext => $authority_type->authtypetext, |
176 |
); |
177 |
push @frameworkselect, \%row; |
178 |
} |
179 |
$template->param( |
188 |
$template->param( |
180 |
frameworkselect => \@frameworkselect, |
189 |
frameworkselect => $authority_types->unblessed, |
181 |
frameworkcode1 => $recordObj1->authtypecode, |
190 |
frameworkcode1 => $recordObj1->authtypecode, |
182 |
frameworkcode2 => $recordObj2->authtypecode, |
191 |
frameworkcode2 => $recordObj2->authtypecode, |
183 |
); |
192 |
); |
Lines 186-207
else {
Link Here
|
186 |
} |
195 |
} |
187 |
} |
196 |
} |
188 |
|
197 |
|
189 |
my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']}); |
|
|
190 |
$template->param( authority_types => $authority_types ); |
191 |
|
192 |
if (@errors) { |
198 |
if (@errors) { |
193 |
|
|
|
194 |
# Errors |
195 |
$template->param( errors => \@errors ); |
199 |
$template->param( errors => \@errors ); |
196 |
} |
200 |
} |
197 |
|
|
|
198 |
output_html_with_http_headers $input, $cookie, $template->output; |
201 |
output_html_with_http_headers $input, $cookie, $template->output; |
199 |
exit; |
|
|
200 |
|
201 |
=head1 FUNCTIONS |
202 |
|
203 |
=cut |
204 |
|
205 |
# ------------------------ |
206 |
# Functions |
207 |
# ------------------------ |