CHANGE TO PREVIOUS .046 DATABASE UPDATE
[srvgit] / installer / data / mysql / updatedatabase.pl
index a994352..47a1ce3 100755 (executable)
@@ -88,7 +88,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 
 $DBversion = "3.00.00.003";
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    if (C4::Context->preference("opaclanguage") eq "fr") {
+    if (C4::Context->preference("opaclanguages") eq "fr") {
         $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ReservesNeedReturns','0','Si ce paramètre est mis à 1, une réservation posée sur un exemplaire présent sur le site devra être passée en retour pour être disponible. Sinon, elle sera automatiquement disponible, Koha considère que le bibliothécaire place la réservation en ayant le document en mains','','YesNo')");
     } else {
         $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ReservesNeedReturns','0','If set, a reserve done on an item available in this branch need a check-in, otherwise, a reserve on a specific item, that is on the branch & available is considered as available','','YesNo')");
@@ -821,6 +821,126 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 }
 
 
+$DBversion = "3.00.00.041";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    # Strictly speaking it is not necessary to explicitly change
+    # NULL values to 0, because the ALTER TABLE statement will do that.
+    # However, setting them first avoids a warning.
+    $dbh->do("UPDATE items SET notforloan = 0 WHERE notforloan IS NULL");
+    $dbh->do("UPDATE items SET damaged = 0 WHERE damaged IS NULL");
+    $dbh->do("UPDATE items SET itemlost = 0 WHERE itemlost IS NULL");
+    $dbh->do("UPDATE items SET wthdrawn = 0 WHERE wthdrawn IS NULL");
+    $dbh->do("ALTER TABLE items
+                MODIFY notforloan tinyint(1) NOT NULL default 0,
+                MODIFY damaged    tinyint(1) NOT NULL default 0,
+                MODIFY itemlost   tinyint(1) NOT NULL default 0,
+                MODIFY wthdrawn   tinyint(1) NOT NULL default 0");
+       print "Upgrade to $DBversion done (disallow NULL in several item status columns)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.042";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
+       print "Upgrade to $DBversion done (disallow NULL in aqbooksellers.name; part of fix for bug 1251)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.043";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `currency` ADD `symbol` varchar(5) default NULL, ADD `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP");
+       print "Upgrade to $DBversion done (currency table: add symbol and timestamp columns)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.044";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE deletedborrowers
+  ADD `altcontactfirstname` varchar(255) default NULL,
+  ADD `altcontactsurname` varchar(255) default NULL,
+  ADD `altcontactaddress1` varchar(255) default NULL,
+  ADD `altcontactaddress2` varchar(255) default NULL,
+  ADD `altcontactaddress3` varchar(255) default NULL,
+  ADD `altcontactzipcode` varchar(50) default NULL,
+  ADD `altcontactphone` varchar(50) default NULL
+");
+        print "Upgrade to $DBversion done (syncing deletedborrowers table with borrowers table)\n";
+    SetVersion ($DBversion);
+}
+
+#-- http://www.w3.org/International/articles/language-tags/
+
+#-- RFC4646
+$DBversion = "3.00.00.045";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("
+CREATE TABLE language_subtag_registry (
+        subtag varchar(25),
+        type varchar(25), -- language-script-region-variant-extension-privateuse
+        description varchar(25), -- only one of the possible descriptions for ease of reference, see language_descriptions for the complete list
+        added date,
+        KEY `subtag` (`subtag`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+#-- TODO: add suppress_scripts
+#-- this maps three letter codes defined in iso639.2 back to their
+#-- two letter equivilents in rfc4646 (LOC maintains iso639+)
+ $dbh->do("CREATE TABLE language_rfc4646_to_iso639 (
+        rfc4646_subtag varchar(25),
+        iso639_2_code varchar(25),
+        KEY `rfc4646_subtag` (`rfc4646_subtag`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+ $dbh->do("CREATE TABLE language_descriptions (
+        subtag varchar(25),
+        type varchar(25),
+        lang varchar(25),
+        description varchar(255),
+        KEY `lang` (`lang`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+#-- bi-directional support, keyed by script subcode
+ $dbh->do("CREATE TABLE language_script_bidi (
+        rfc4646_subtag varchar(25), -- script subtag, Arab, Hebr, etc.
+        bidi varchar(3), -- rtl ltr
+        KEY `rfc4646_subtag` (`rfc4646_subtag`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+#-- BIDI Stuff, Arabic and Hebrew
+ $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
+VALUES( 'Arab', 'rtl')");
+ $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
+VALUES( 'Hebr', 'rtl')");
+
+#-- TODO: need to map language subtags to script subtags for detection
+#-- of bidi when script is not specified (like ar, he)
+ $dbh->do("CREATE TABLE language_script_mapping (
+        language_subtag varchar(25),
+        script_subtag varchar(25),
+        KEY `language_subtag` (`language_subtag`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+#-- Default mappings between script and language subcodes
+ $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
+VALUES( 'ar', 'Arab')");
+ $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
+VALUES( 'he', 'Hebr')");
+
+        print "Upgrade to $DBversion done (adding language subtag registry and basic BiDi support NOTE: You should import the subtag registry SQL)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.046";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `subscription` CHANGE `numberlength` `numberlength` int(11) default NULL , 
+                CHANGE `weeklength` `weeklength` int(11) default NULL");
+    $dbh->do("ALTER TABLE `serial` ADD UNIQUE KEY `serialitemidx` (`serialitem`)");
+    $dbh->do("CREATE TABLE `serialitems` (`serialid` int(11) NOT NULL, `itemnumber` int(11) NOT NULL, UNIQUE KEY (`serialid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+    $dbh->do("INSERT INTO `serialitems` SELECT `serialid`,`itemnumber` from serial where NOT ISNULL(itemnumber) && itemnumber <> '' && itemnumber NOT LIKE '%,%'");
+       print "Upgrade to $DBversion done (Update serial table, add index on itemnumber. )\n";
+    SetVersion ($DBversion);
+}
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table
@@ -884,4 +1004,3 @@ sub SetVersion {
 }
 exit;
 
-# Revision 1.172  2007/07/19 10:21:22  hdl