Bug 17428: [REST] Cities swagger specification
[koha.git] / admin / marc_subfields_structure.pl
index bfaa3dc..24c8005 100755 (executable)
@@ -24,6 +24,7 @@ use CGI qw ( -utf8 );
 use C4::Context;
 
 use Koha::Authority::Types;
+use Koha::AuthorisedValueCategories;
 
 use List::MoreUtils qw( uniq );
 
@@ -77,7 +78,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
         debug           => 1,
     }
 );
-my $cache = Koha::Cache->get_instance();
+my $cache = Koha::Caches->get_instance();
 
 my $op       = $input->param('op') || "";
 $tagfield =~ s/\,//g;
@@ -128,14 +129,8 @@ if ( $op eq 'add_form' ) {
     $sth2->finish;
     $sth2 = $dbh->prepare("select distinct category from authorised_values");
     $sth2->execute;
-    my @authorised_values;
-    push @authorised_values, "";
-    while ( ( my $category ) = $sth2->fetchrow_array ) {
-        push @authorised_values, $category;
-    }
-    push( @authorised_values, "branches" );
-    push( @authorised_values, "itemtypes" );
-    push( @authorised_values, "cn_source" );
+    my @av_cat = Koha::AuthorisedValueCategories->search;
+    my @authorised_values = map { $_->category_name } @av_cat;
 
     # build thesaurus categories list
     my @authtypes = uniq( "", map { $_->authtypecode } Koha::Authority::Types->search );
@@ -285,7 +280,8 @@ elsif ( $op eq 'add_validate' ) {
         my $maxlength = $maxlength[$i] ? $maxlength[$i] : 9999;
         
         if (defined($liblibrarian) && $liblibrarian ne "") {
-            unless ( C4::Context->config('demo') or C4::Context->config('demo') eq 1 ) {
+            my $is_demo = C4::Context->config('demo') || '';
+            if ( $is_demo ne '1' ) {
                 if (marc_subfield_structure_exists($tagfield, $tagsubfield, $frameworkcode)) {
                     $sth_update->execute(
                         $tagfield,
@@ -342,6 +338,7 @@ elsif ( $op eq 'add_validate' ) {
     $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
     $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
     $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
+    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
 
     print $input->redirect("/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode");
     exit;
@@ -375,7 +372,8 @@ elsif ( $op eq 'delete_confirm' ) {
 }
 elsif ( $op eq 'delete_confirmed' ) {
     my $dbh = C4::Context->dbh;
-    unless ( C4::Context->config('demo') or C4::Context->config('demo') eq 1 ) {
+    my $is_demo = C4::Context->config('demo') || '';
+    if ( $is_demo ne '1' ) {
         my $sth =
           $dbh->prepare(
 "delete from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
@@ -386,6 +384,7 @@ elsif ( $op eq 'delete_confirmed' ) {
     $cache->clear_from_cache("MarcStructure-0-$frameworkcode");
     $cache->clear_from_cache("MarcStructure-1-$frameworkcode");
     $cache->clear_from_cache("default_value_for_mod_marc-$frameworkcode");
+    $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
     print $input->redirect("/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode");
     exit;