Bug 34346: Show error message instead of 500 for duplicate tags
This change shows a user-friendly error message instead of a 500 error if adding a duplicate MARC tag to a MARC bibliographic framework. Test plan: 0. Add patch and koha-plack --reload kohadev 1. Go to http://localhost:8081/cgi-bin/koha/admin/marctagstructure.pl?searchfield=264&frameworkcode= 2. Click "New tag" 3. Enter "264" in "Tag:" field 4. Click "Save changes" 5. See error message on screen (instead of 500 error) Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Bug 34346: Tidy Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Slightly adjusted error message and added punctuation. Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
parent
0e61e56e57
commit
a24829939e
2 changed files with 44 additions and 20 deletions
|
@ -28,6 +28,7 @@ use C4::Context;
|
||||||
use Koha::Caches;
|
use Koha::Caches;
|
||||||
use Koha::AuthorisedValues;
|
use Koha::AuthorisedValues;
|
||||||
use Koha::BiblioFrameworks;
|
use Koha::BiblioFrameworks;
|
||||||
|
use Koha::Database;
|
||||||
|
|
||||||
# retrieve parameters
|
# retrieve parameters
|
||||||
my $input = CGI->new;
|
my $input = CGI->new;
|
||||||
|
@ -120,6 +121,7 @@ if ($op eq 'add_form') {
|
||||||
my $authorised_value = $input->param('authorised_value');
|
my $authorised_value = $input->param('authorised_value');
|
||||||
my $ind1_defaultvalue = $input->param('ind1_defaultvalue');
|
my $ind1_defaultvalue = $input->param('ind1_defaultvalue');
|
||||||
my $ind2_defaultvalue = $input->param('ind2_defaultvalue');
|
my $ind2_defaultvalue = $input->param('ind2_defaultvalue');
|
||||||
|
my $error;
|
||||||
if ($input->param('modif')) {
|
if ($input->param('modif')) {
|
||||||
$sth = $dbh->prepare(
|
$sth = $dbh->prepare(
|
||||||
"UPDATE marc_tag_structure SET liblibrarian=? ,libopac=? ,repeatable=? ,mandatory=? ,important=? ,authorised_value=?, ind1_defaultvalue=?, ind2_defaultvalue=? WHERE frameworkcode=? AND tagfield=?"
|
"UPDATE marc_tag_structure SET liblibrarian=? ,libopac=? ,repeatable=? ,mandatory=? ,important=? ,authorised_value=?, ind1_defaultvalue=?, ind2_defaultvalue=? WHERE frameworkcode=? AND tagfield=?"
|
||||||
|
@ -136,26 +138,40 @@ if ($op eq 'add_form') {
|
||||||
$tagfield
|
$tagfield
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$sth = $dbh->prepare(
|
my $schema = Koha::Database->new()->schema();
|
||||||
"INSERT INTO marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,important,authorised_value,ind1_defaultvalue,ind2_defaultvalue,frameworkcode) values (?,?,?,?,?,?,?,?,?,?)"
|
my $rs = $schema->resultset('MarcTagStructure');
|
||||||
);
|
my $field = $rs->find( { tagfield => $tagfield, frameworkcode => $frameworkcode } );
|
||||||
$sth->execute($tagfield,
|
if ( !$field ) {
|
||||||
$liblibrarian,
|
$sth = $dbh->prepare(
|
||||||
$libopac,
|
"INSERT INTO marc_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,important,authorised_value,ind1_defaultvalue,ind2_defaultvalue,frameworkcode) values (?,?,?,?,?,?,?,?,?,?)"
|
||||||
$repeatable,
|
);
|
||||||
$mandatory,
|
$sth->execute(
|
||||||
$important,
|
$tagfield,
|
||||||
$authorised_value,
|
$liblibrarian,
|
||||||
$ind1_defaultvalue,
|
$libopac,
|
||||||
$ind2_defaultvalue,
|
$repeatable,
|
||||||
$frameworkcode
|
$mandatory,
|
||||||
);
|
$important,
|
||||||
|
$authorised_value,
|
||||||
|
$ind1_defaultvalue,
|
||||||
|
$ind2_defaultvalue,
|
||||||
|
$frameworkcode
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$error = 'duplicate_tagfield';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
|
if ( !$error ) {
|
||||||
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
|
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
|
||||||
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
|
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
|
||||||
$cache->clear_from_cache("MarcCodedFields-$frameworkcode");
|
$cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
|
||||||
print $input->redirect("/cgi-bin/koha/admin/marctagstructure.pl?searchfield=$tagfield&frameworkcode=$frameworkcode");
|
$cache->clear_from_cache("MarcCodedFields-$frameworkcode");
|
||||||
|
}
|
||||||
|
my $redirect_url = "/cgi-bin/koha/admin/marctagstructure.pl?searchfield=$tagfield&frameworkcode=$frameworkcode";
|
||||||
|
if ($error) {
|
||||||
|
$redirect_url .= "&error=$error";
|
||||||
|
}
|
||||||
|
print $input->redirect($redirect_url);
|
||||||
exit;
|
exit;
|
||||||
# END $OP eq ADD_VALIDATE
|
# END $OP eq ADD_VALIDATE
|
||||||
################## DELETE_CONFIRM ##################################
|
################## DELETE_CONFIRM ##################################
|
||||||
|
@ -200,6 +216,12 @@ if ($op eq 'add_form') {
|
||||||
|
|
||||||
################## DEFAULT ##################################
|
################## DEFAULT ##################################
|
||||||
} else { # DEFAULT
|
} else { # DEFAULT
|
||||||
|
my $error_code = $input->param('error');
|
||||||
|
if ($error_code){
|
||||||
|
if ($error_code eq 'duplicate_tagfield'){
|
||||||
|
$template->param('blocking_error' => $error_code);
|
||||||
|
}
|
||||||
|
}
|
||||||
# here, $op can be unset or set to "cud-framework_create_confirm".
|
# here, $op can be unset or set to "cud-framework_create_confirm".
|
||||||
if ($searchfield ne '') {
|
if ($searchfield ne '') {
|
||||||
$template->param(searchfield => $searchfield);
|
$template->param(searchfield => $searchfield);
|
||||||
|
|
|
@ -22,9 +22,11 @@
|
||||||
[% CASE 'budget_is_locked' %]
|
[% CASE 'budget_is_locked' %]
|
||||||
<div class="dialog message">The budget is locked, fund creation is not possible.</div>
|
<div class="dialog message">The budget is locked, fund creation is not possible.</div>
|
||||||
[% CASE 'missing_es_modules' %]
|
[% CASE 'missing_es_modules' %]
|
||||||
<div class="dialog message">Necessary Elasticsearch packages are not installed on your server. Please contact your server admin if you wish to configure Elasticsearch</div>
|
<div class="dialog message">Necessary Elasticsearch packages are not installed on your server. Please contact your server admin if you wish to configure Elasticsearch.</div>
|
||||||
[% CASE 'insufficient_permission' %]
|
[% CASE 'insufficient_permission' %]
|
||||||
<div class="dialog message">You do not have sufficient permission to continue.</div>
|
<div class="dialog message">You do not have sufficient permission to continue.</div>
|
||||||
|
[% CASE 'duplicate_tagfield' %]
|
||||||
|
<div class="dialog message">MARC field not added to MARC bibliographic framework. MARC tag already exists in framework.</div>
|
||||||
[% CASE %]
|
[% CASE %]
|
||||||
<div class="dialog alert">[% blocking_error | html %]</div>
|
<div class="dialog alert">[% blocking_error | html %]</div>
|
||||||
[% END %]
|
[% END %]
|
||||||
|
|
Loading…
Reference in a new issue