Bug 24606: (QA follow-up) Set existing sharing setting when updating existing template
[koha-ffzg.git] / admin / biblio_framework.pl
index 79f3eba..d8988e0 100755 (executable)
 use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Context;
-use C4::Auth;
-use C4::Output;
+use C4::Auth qw( get_template_and_user );
+use C4::Output qw( output_html_with_http_headers );
 use Koha::Biblios;
 use Koha::BiblioFramework;
 use Koha::BiblioFrameworks;
-use Koha::Cache;
+use Koha::Caches;
 
-my $input         = new CGI;
+my $input         = CGI->new;
 my $frameworkcode = $input->param('frameworkcode') || q||;
 my $op            = $input->param('op') || q|list|;
-my $cache         = Koha::Cache->get_instance();
+my $cache         = Koha::Caches->get_instance();
 my @messages;
 
 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     {   template_name   => "admin/biblio_framework.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
-        flagsrequired   => { parameters => 'parameters_remaining_permissions' },
-        debug           => 1,
+        flagsrequired   => { parameters => 'manage_marc_frameworks' },
     }
 );
 
@@ -54,9 +52,10 @@ if ( $op eq 'add_form' ) {
 } elsif ( $op eq 'add_validate' ) {
     my $frameworkcode = $input->param('frameworkcode');
     my $frameworktext = $input->param('frameworktext');
+    my $is_a_modif    = $input->param('is_a_modif');
 
-    my $framework = Koha::BiblioFrameworks->find($frameworkcode);
-    if ($framework) {
+    if ($is_a_modif) {
+        my $framework = Koha::BiblioFrameworks->find($frameworkcode);
         $framework->frameworktext($frameworktext);
         eval { $framework->store; };
         if ($@) {
@@ -65,7 +64,7 @@ if ( $op eq 'add_form' ) {
             push @messages, { type => 'message', code => 'success_on_update' };
         }
     } else {
-        $framework = Koha::BiblioFramework->new(
+        my $framework = Koha::BiblioFramework->new(
             {   frameworkcode => $frameworkcode,
                 frameworktext => $frameworktext,
             }
@@ -79,6 +78,8 @@ if ( $op eq 'add_form' ) {
     }
     $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
     $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
+    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
+    $cache->clear_from_cache("MarcCodedFields-$frameworkcode");
     $op = 'list';
 } elsif ( $op eq 'delete_confirm' ) {
     my $framework = Koha::BiblioFrameworks->find($frameworkcode);
@@ -108,6 +109,8 @@ if ( $op eq 'add_form' ) {
     }
     $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
     $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
+    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
+    $cache->clear_from_cache("MarcCodedFields-$frameworkcode");
     $op = 'list';
 }