From e273e11b084af645d5f9e4f4851cc2ad850c7675 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 17 Jul 2013 14:38:55 +0200 Subject: [PATCH] Bug 10602: Set default value for authority fields via the framework This patch allows to define default values in the authorities framework. Some code already existed but the feature did not work. Test plan: 1/ Choose a framework, field and subfields. 2/ Define a default value. 3/ Create a new authority and check that the subfield is automatically filled with the default value. Signed-off-by: Bernardo Gonzalez Kriegel Work as described. koha-qa reports some tabs, fixed in followup Test 1) Apply patch, run updatedatabase.pl 2) Edit auth framework, put default value someware, save 3) Add new auth, default value present Signed-off-by: Katrin Fischer Passes all tests and QA script. Verified database update is done correctly. Controlfields 0xx - Edited an existing field (001) - Set a default value for subfield @ - Edited subfield again, checking default was saved correctly - Verified the default shows up correctly when creating a new authority using this authority type Fields - Edited an existing field (100) - Set a default value for subfield e - Edited subfield again, checking default was saved correctly - Verified the default shows up correctly when creating a new authority using this authority type Signed-off-by: Galen Charlton --- C4/AuthoritiesMarc.pm | 6 ++++-- admin/auth_subfields_structure.pl | 9 +++++++-- installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 9 +++++++++ .../en/modules/admin/auth_subfields_structure.tt | 13 ++++++++++++- 5 files changed, 33 insertions(+), 5 deletions(-) diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index f1b4935843..7443f36c15 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -520,7 +520,7 @@ sub GetTagsLabels { $res->{$tag}->{repeatable} = $repeatable; } $sth= $dbh->prepare( -"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl +"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl,defaultvalue FROM auth_subfield_structure WHERE authtypecode=? ORDER BY tagfield,tagsubfield" @@ -535,12 +535,13 @@ ORDER BY tagfield,tagsubfield" my $hidden; my $isurl; my $link; + my $defaultvalue; while ( ( $tag, $subfield, $liblibrarian, , $libopac, $tab, $mandatory, $repeatable, $authorised_value, $authtypecode, $value_builder, $kohafield, $seealso, $hidden, - $isurl, $link ) + $isurl, $defaultvalue, $link ) = $sth->fetchrow ) { @@ -556,6 +557,7 @@ ORDER BY tagfield,tagsubfield" $res->{$tag}->{$subfield}->{hidden} = $hidden; $res->{$tag}->{$subfield}->{isurl} = $isurl; $res->{$tag}->{$subfield}->{link} = $link; + $res->{$tag}->{$subfield}->{defaultvalue} = $defaultvalue; } return $res; } diff --git a/admin/auth_subfields_structure.pl b/admin/auth_subfields_structure.pl index 537f0ea227..b4f9512fc1 100755 --- a/admin/auth_subfields_structure.pl +++ b/admin/auth_subfields_structure.pl @@ -139,6 +139,7 @@ if ($op eq 'add_form') { while ($data =$sth->fetchrow_hashref) { my %row_data; # get a fresh hash for the row data + $row_data{defaultvalue} = $data->{defaultvalue}; $row_data{tab} = CGI::scrolling_list(-name=>'tab', -id=>"tab$i", -values => @@ -386,9 +387,9 @@ if ($op eq 'add_form') { $template->param(tagfield => "$input->param('tagfield')"); # my $sth=$dbh->prepare("replace auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl) # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); - my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl) + my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl,defaultvalue) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); - my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=? + my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?, defaultvalue=? where authtypecode=? and tagfield=? and tagsubfield=?"); my @tagsubfield = $input->param('tagsubfield'); my @liblibrarian = $input->param('liblibrarian'); @@ -404,6 +405,7 @@ if ($op eq 'add_form') { my $authtypecode = $input->param('authtypecode'); my @frameworkcodes = $input->param('frameworkcode'); my @value_builder =$input->param('value_builder'); + my @defaultvalue = $input->param('defaultvalue'); for (my $i=0; $i<= $#tagsubfield ; $i++) { my $tagfield =$input->param('tagfield'); my $tagsubfield =$tagsubfield[$i]; @@ -418,6 +420,7 @@ if ($op eq 'add_form') { my $authorised_value =$authorised_values[$i]; my $frameworkcode =$frameworkcodes[$i]; my $value_builder=$value_builder[$i]; + my $defaultvalue = $defaultvalue[$i]; #my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens; my $hidden = $ohidden[$i]; #collate from 3 hiddens; my $isurl = $input->param("isurl$i")?1:0; @@ -440,6 +443,7 @@ if ($op eq 'add_form') { $value_builder, $hidden, $isurl, + $defaultvalue, ( $authtypecode, $tagfield, @@ -463,6 +467,7 @@ if ($op eq 'add_form') { $value_builder, $hidden, $isurl, + $defaultvalue, ); } } diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 82da0182f8..c1a8b8d964 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -56,6 +56,7 @@ CREATE TABLE `auth_subfield_structure` ( `linkid` tinyint(1) NOT NULL default 0, `kohafield` varchar(45) NULL default '', `frameworkcode` varchar(10) NOT NULL default '', + `defaultvalue` TEXT DEFAULT '', PRIMARY KEY (`authtypecode`,`tagfield`,`tagsubfield`), KEY `tab` (`authtypecode`,`tab`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e5e60f4cdc..20f0f953fd 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7176,6 +7176,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.13.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q| + ALTER TABLE auth_subfield_structure ADD COLUMN defaultvalue TEXT DEFAULT NULL AFTER frameworkcode + |); + print "Upgrade to $DBversion done (Bug 10602: Add the column auth_subfield_structure.defaultvalue)\n"; + SetVersion($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt index 688bd713e5..3d221929d7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/auth_subfields_structure.tt @@ -99,7 +99,18 @@ function displayMoreConstraint(numlayer){ -
  • [% loo.isurl %] (if checked, it means that the subfield is a URL and can be clicked)
  • +
  • +
    + Advanced constraints: +
      +
    1. [% loo.isurl %] (if checked, it means that the subfield is a URL and can be clicked)
    2. +
    3. + + +
    4. +
    +
    +
  • Help input
      -- 2.20.1