From 1510b0909360af4dcb702f93cea1aa4f575b8bce Mon Sep 17 00:00:00 2001
From: Joachim Ganseman <joachim.ganseman@student.ua.ac.be>
Date: Mon, 6 Jun 2016 14:00:37 +0000
Subject: [PATCH] With this second patch, bug 9701 is entirely fixed. The
 default values are also loaded in the cataloguing form. The database update
 is now done according to the database update workflow. Previous changes to
 files that ought not to have changed, done in the previous partial patch,
 have been undone in this patch..

Test: Define default values in some MARC framework. Go to cataloguing
and create a new record using this framework. Verify that the defined
defaults are visible when set. Verify the default is empty (as before)
    if no default was set. Verify that if the default is changed, the
    record is saved with the manually changed value. Verify that upon
    changing such a new record, the manually set indicator value is used
    and not the default one from the framework.
---
 cataloguing/addbiblio.pl                                     |  4 ++--
 .../mysql/atomicupdate/bug_9701-add_default_indicators.sql   |  3 +++
 installer/data/mysql/updatedatabase.pl                       | 12 ------------
 3 files changed, 5 insertions(+), 14 deletions(-)
 create mode 100644 installer/data/mysql/atomicupdate/bug_9701-add_default_indicators.sql

diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl
index f0263ef..6c65b93 100755
--- a/cataloguing/addbiblio.pl
+++ b/cataloguing/addbiblio.pl
@@ -662,8 +662,8 @@ sub build_tabs {
                         tag_lib          => $tagslib->{$tag}->{lib},
                         repeatable       => $tagslib->{$tag}->{repeatable},
                         mandatory       => $tagslib->{$tag}->{mandatory},
-                        indicator1       => $indicator1,
-                        indicator2       => $indicator2,
+                        indicator1       => ( $indicator1 || $tagslib->{$tag}->{ind1_defaultvalue} ), #if not set, try to load the default value
+                        indicator2       => ( $indicator2 || $tagslib->{$tag}->{ind2_defaultvalue} ), #use short-circuit operator for efficiency
                         subfield_loop    => \@subfields_data,
                         tagfirstsubfield => $subfields_data[0],
                         fixedfield       => $tag < 10?1:0,
diff --git a/installer/data/mysql/atomicupdate/bug_9701-add_default_indicators.sql b/installer/data/mysql/atomicupdate/bug_9701-add_default_indicators.sql
new file mode 100644
index 0000000..289883c
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_9701-add_default_indicators.sql
@@ -0,0 +1,3 @@
+ALTER TABLE marc_tag_structure 
+ADD COLUMN ind2_defaultvalue VARCHAR(1) NOT NULL DEFAULT '' AFTER authorized_value,
+ADD COLUMN ind1_defaultvalue VARCHAR(1) NOT NULL DEFAULT '' AFTER authorized_value;
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index f96692c..657ba4e 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -12614,18 +12614,6 @@ if ( CheckVersion($DBversion) ) {
                 SetVersion($DBversion);
 }
 
-$DBversion = "16.06.00.002";
-if (CheckVersion($DBversion) ) {
-	$dbh->do(q{
-		ALTER TABLE marc_tag_structure ADD COLUMN ind2_defaultvalue VARCHAR(1) NOT NULL DEFAULT '' AFTER authorized_value;
-    });
-	$dbh->do(q{
-		ALTER TABLE marc_tag_structure ADD COLUMN ind1_defaultvalue VARCHAR(1) NOT NULL DEFAULT '' AFTER authorized_value;
-    });
-	    print "Upgrade to $DBversion done (Bug 9701 - Configure default indicator)"
-		SetVersion($DBversion)
-}
-
 
 # DEVELOPER PROCESS, search for anything to execute in the db_update directory
 # SEE bug 13068
-- 
2.1.4