Bug 22284: DBRev 19.12.00.003
[koha-ffzg.git] / installer / data / mysql / updatedatabase.pl
index 79d73f9..d61b4e8 100755 (executable)
@@ -17542,6 +17542,17 @@ if( CheckVersion( $DBversion ) ) {
     }
 
     if ( column_exists( 'issuingrules', 'maxissueqty' ) ) {
+        # Cleaning invalid rules before, to avoid FK contraints to fail
+        $dbh->do(q|
+            DELETE FROM issuingrules WHERE categorycode != '*' AND categorycode NOT IN (SELECT categorycode FROM categories);
+        |);
+        $dbh->do(q|
+            DELETE FROM issuingrules WHERE branchcode != '*' AND branchcode NOT IN (SELECT branchcode FROM branches);
+        |);
+        $dbh->do(q|
+            DELETE FROM issuingrules WHERE itemtype != '*' AND itemtype NOT IN (SELECT itemtype FROM itemtypes);
+        |);
+
         $dbh->do("
             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
             SELECT IF(categorycode='*', NULL, categorycode),
@@ -17621,6 +17632,17 @@ if( CheckVersion( $DBversion ) ) {
 $DBversion = '18.12.00.024';
 if ( CheckVersion($DBversion) ) {
 
+    # Fixup any pre-existing bad suggestedby, manageddate, accepteddate dates
+    $dbh->do(
+        "UPDATE suggestions SET suggesteddate = '1970-01-01' WHERE suggesteddate = '0000-00-00';"    
+    );
+    $dbh->do(
+        "UPDATE suggestions SET manageddate = '1970-01-01' WHERE manageddate = '0000-00-00';"    
+    );
+    $dbh->do(
+        "UPDATE suggestions SET accepteddate = '1970-01-01' WHERE accepteddate = '0000-00-00';"    
+    );
+
     # Add constraint for suggestedby
     unless ( foreign_key_exists( 'suggestions', 'suggestions_ibfk_suggestedby' ) )
     {
@@ -18722,7 +18744,7 @@ if ( CheckVersion($DBversion) ) {
     $dbh->do(q{UPDATE subscriptionhistory SET librariannote = NULL WHERE librariannote = ''});
 
     SetVersion ($DBversion);
-    print "Upgrade to $DBversion done (Bug 10215 - Increase the size of opacnote and librariannote for table subscriptionhistory)\n";
+    print "Upgrade to $DBversion done (Bug 10215: Increase the size of opacnote and librariannote for table subscriptionhistory)\n";
 }
 
 $DBversion = '19.06.00.003';
@@ -18730,7 +18752,7 @@ if( CheckVersion( $DBversion ) ) {
     $dbh->do(q{UPDATE systempreferences SET value = REPLACE( value, ' ', '|' ) WHERE variable = 'UniqueItemFields'; });
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 22867 - UniqueItemFields preference value should be pipe-delimited)\n";
+    print "Upgrade to $DBversion done (Bug 22867: UniqueItemFields preference value should be pipe-delimited)\n";
 }
 
 $DBversion = '19.06.00.004';
@@ -18738,7 +18760,7 @@ if( CheckVersion( $DBversion ) ) {
     $dbh->do( 'UPDATE language_descriptions SET description = "Griechisch (Modern 1453-)"
       WHERE subtag = "el" and type = "language" and lang ="de"' );
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 22770 - Fix typo in language description for el in German)\n";
+    print "Upgrade to $DBversion done (Bug 22770: Fix typo in language description for el in German)\n";
 }
 
 $DBversion = '19.06.00.005';
@@ -18751,7 +18773,7 @@ if( CheckVersion( $DBversion ) ) {
     }
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 9834 - Add the reserves.item_level_hold column)\n";
+    print "Upgrade to $DBversion done (Bug  9834: Add the reserves.item_level_hold column)\n";
 }
 
 $DBversion = '19.06.00.006';
@@ -18771,21 +18793,21 @@ if( CheckVersion( $DBversion ) ) {
     Koha::Plugins->new({ enable_plugins => 1 })->InstallPlugins;
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 21073 - Improve plugin performance)\n";
+    print "Upgrade to $DBversion done (Bug 21073: Improve plugin performance)\n";
 }
 
 $DBversion = '19.06.00.007';
 if( CheckVersion( $DBversion ) ) {
     $dbh->do( "DELETE FROM systempreferences WHERE variable = 'RotationPreventTransfers'" );
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 22653 - Remove unimplemented RotationPreventTransfers system preference)\n";
+    print "Upgrade to $DBversion done (Bug 22653: Remove unimplemented RotationPreventTransfers system preference)\n";
 }
 
 $DBversion = '19.06.00.008';
 if( CheckVersion( $DBversion ) ) {
     $dbh->do( "UPDATE userflags SET flagdesc = 'Allow staff members to modify permissions and passwords for other staff members' WHERE flag = 'staffaccess'" );
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 23109 - Improve description of staffaccess permission)\n";
+    print "Upgrade to $DBversion done (Bug 23109: Improve description of staffaccess permission)\n";
 }
 
 $DBversion = '19.06.00.009';
@@ -18796,7 +18818,7 @@ if( CheckVersion( $DBversion ) ) {
     });
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 17178 - add shortcut to keyboard_shortcuts)\n";
+    print "Upgrade to $DBversion done (Bug 17178: add shortcut to keyboard_shortcuts)\n";
 }
 
 $DBversion = '19.06.00.010';
@@ -18887,7 +18909,7 @@ if( CheckVersion( $DBversion ) ) {
     }
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 18928 - Move holdallowed, hold_fulfillment_policy, returnbranch to circulation_rules)\n";
+    print "Upgrade to $DBversion done (Bug 18928: Move holdallowed, hold_fulfillment_policy, returnbranch to circulation_rules)\n";
 }
 
 $DBversion = '19.06.00.011';
@@ -18905,7 +18927,7 @@ if( CheckVersion( $DBversion ) ) {
     }
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 18930 - Move lost item refund rules to circulation_rules table)\n";
+    print "Upgrade to $DBversion done (Bug 18930: Move lost item refund rules to circulation_rules table)\n";
 }
 
 $DBversion = '19.06.00.012';
@@ -18985,7 +19007,7 @@ if ( CheckVersion($DBversion) ) {
     });
 
     SetVersion($DBversion);
-    print "Upgrade to $DBversion done (Bug 22563 - Fix accounttypes for 'L', 'LR' and 'CR')\n";
+    print "Upgrade to $DBversion done (Bug 22563: Fix accounttypes for 'L', 'LR' and 'CR')\n";
 }
 
 $DBversion = '19.06.00.013';
@@ -18994,7 +19016,7 @@ if ( CheckVersion( $DBversion ) ) {
         $dbh->do("ALTER TABLE borrower_modifications ADD changed_fields MEDIUMTEXT AFTER verification_token;");
     }
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 23151 - Add borrower_modifications.changed_fields column)\n";
+    print "Upgrade to $DBversion done (Bug 23151: Add borrower_modifications.changed_fields column)\n";
 }
 
 $DBversion = '19.06.00.014';
@@ -19044,7 +19066,7 @@ if ( CheckVersion($DBversion) ) {
     });
 
     SetVersion($DBversion);
-    print "Upgrade to $DBversion done (Bug 11573 - Fix accounttypes for 'Rent')\n";
+    print "Upgrade to $DBversion done (Bug 11573: Fix accounttypes for 'Rent')\n";
 }
 
 $DBversion = '19.06.00.015';
@@ -19052,7 +19074,7 @@ if( CheckVersion( $DBversion ) ) {
     $dbh->do( "UPDATE `search_field` SET `name` = 'date-time-last-modified', `label` = 'date-time-last-modified' WHERE `name` = 'date/time-last-modified'" );
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 22524 - Fix date/time-last-modified search with Elasticsearch)\n";
+    print "Upgrade to $DBversion done (Bug 22524: Fix date/time-last-modified search with Elasticsearch)\n";
 }
 
 $DBversion = '19.06.00.016';
@@ -19075,7 +19097,7 @@ if( CheckVersion( $DBversion ) ) {
     ;|);
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 23396 - Fix missing keyboard_shortcuts table)\n";
+    print "Upgrade to $DBversion done (Bug 23396: Fix missing keyboard_shortcuts table)\n";
 }
 
 $DBversion = '19.06.00.017';
@@ -19150,7 +19172,7 @@ if ( CheckVersion($DBversion) ) {
     }
 
     SetVersion($DBversion);
-    print "Upgrade to $DBversion done (Bug 22610 - Fix accounttypes for SIP2 payments)\n";
+    print "Upgrade to $DBversion done (Bug 22610: Fix accounttypes for SIP2 payments)\n";
 }
 
 $DBversion = '19.06.00.018';
@@ -19268,7 +19290,7 @@ if ( CheckVersion($DBversion) ) {
 
     SetVersion($DBversion);
     print
-"Upgrade to $DBversion done (Bug 23228 - Add option to automatically display payment receipt for printing after making a payment)\n";
+"Upgrade to $DBversion done (Bug 23228: Add option to automatically display payment receipt for printing after making a payment)\n";
 }
 
 $DBversion = '19.06.00.020';
@@ -19279,7 +19301,7 @@ if( CheckVersion( $DBversion ) ) {
     |);
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 23416 - Add PreserveSerialNotes syspref)\n";
+    print "Upgrade to $DBversion done (Bug 23416: Add PreserveSerialNotes syspref)\n";
 }
 
 $DBversion = '19.06.00.021';
@@ -19290,7 +19312,7 @@ if( CheckVersion( $DBversion ) ) {
     |);
     # Always end with this (adjust the bug info)
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 23309 - Can't add new subfields to bibliographic frameworks in strict mode)\n";
+    print "Upgrade to $DBversion done (Bug 23309: Can't add new subfields to bibliographic frameworks in strict mode)\n";
 }
 
 $DBversion = '19.06.00.022';
@@ -19358,7 +19380,7 @@ if ( CheckVersion($DBversion) ) {
     }
 
     SetVersion($DBversion);
-    print "Upgrade to $DBversion done (Bug 14570 - Make it possible to add multiple guarantors to a record)\n";
+    print "Upgrade to $DBversion done (Bug 14570: Make it possible to add multiple guarantors to a record)\n";
 }
 
 $DBversion = '19.06.00.023';
@@ -19369,7 +19391,7 @@ if( CheckVersion( $DBversion ) ) {
     });
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 22258 - Add ElasticsearchMARCFormat preference)\n";
+    print "Upgrade to $DBversion done (Bug 22258: Add ElasticsearchMARCFormat preference)\n";
 }
 
 $DBversion = '19.06.00.024';
@@ -19377,14 +19399,14 @@ if( CheckVersion( $DBversion ) ) {
     $dbh->do(q{ALTER TABLE accountlines CHANGE COLUMN accounttype accounttype varchar(80) default NULL});
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 23539 - accountlines.accounttype should match authorised_values.authorised_value in size)\n";
+    print "Upgrade to $DBversion done (Bug 23539: accountlines.accounttype should match authorised_values.authorised_value in size)\n";
 }
 
 $DBversion = '19.06.00.025';
 if( CheckVersion( $DBversion ) ) {
     $dbh->do( q/INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES (?, ?, ?, ?, ?)/, undef, 'BarcodeSeparators','\s\r\n','','Splitting characters for barcodes','Free' );
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 22996 - Add pref BarcodeSeparators)\n";
+    print "Upgrade to $DBversion done (Bug 22996: Add pref BarcodeSeparators)\n";
 }
 
 $DBversion = '19.06.00.026';
@@ -19416,7 +19438,7 @@ if( CheckVersion( $DBversion ) ) {
     });
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 20691 - Add ability for guarantors to view guarantee's fines in OPAC)\n";
+    print "Upgrade to $DBversion done (Bug 20691: Add ability for guarantors to view guarantee's fines in OPAC)\n";
 }
 
 $DBversion = '19.06.00.027';
@@ -19434,7 +19456,7 @@ if( CheckVersion( $DBversion ) ) {
     }
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 15497 - Add itemtypes_branches table)\n";
+    print "Upgrade to $DBversion done (Bug 15497: Add itemtypes_branches table)\n";
 }
 
 $DBversion = '19.06.00.028';
@@ -19450,7 +19472,7 @@ if ( CheckVersion($DBversion) ) {
     });
 
     SetVersion($DBversion);
-    print "Upgrade to $DBversion done (Bug 11573 - Fix accounttypes for 'A')\n";
+    print "Upgrade to $DBversion done (Bug 11573: Fix accounttypes for 'A')\n";
 }
 
 $DBversion = '19.06.00.029';
@@ -19499,7 +19521,7 @@ if ( CheckVersion($DBversion) ) {
     });
 
     SetVersion($DBversion);
-    print "Upgrade to $DBversion done (Bug 23321 - Add cash_registers table, permissions and preferences)\n";
+    print "Upgrade to $DBversion done (Bug 23321: Add cash_registers table, permissions and preferences)\n";
 }
 
 $DBversion = '19.06.00.030';
@@ -19542,7 +19564,7 @@ if( CheckVersion( $DBversion ) ) {
 
     # Always end with this (adjust the bug info)
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 19618 - add club_holds tables)\n";
+    print "Upgrade to $DBversion done (Bug 19618: add club_holds tables)\n";
 }
 
 $DBversion = '19.06.00.031';
@@ -19553,7 +19575,7 @@ if( CheckVersion( $DBversion ) ) {
     |);
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 23566 - Add OPACDetailQRCode system preference)\n";
+    print "Upgrade to $DBversion done (Bug 23566: Add OPACDetailQRCode system preference)\n";
 }
 
 $DBversion = '19.06.00.032';
@@ -19576,7 +19598,7 @@ if ( CheckVersion($DBversion) ) {
 
     SetVersion($DBversion);
     print
-"Upgrade to $DBversion done (Bug 20589 - Add field boosting and use elastic query fields parameter instead of depricated _all)\n";
+"Upgrade to $DBversion done (Bug 20589: Add field boosting and use elastic query fields parameter instead of depricated _all)\n";
 }
 
 $DBversion = '19.06.00.033';
@@ -19640,14 +19662,14 @@ if( CheckVersion( $DBversion ) ) {
     });
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 21701 - PayPal return URL option)\n";
+    print "Upgrade to $DBversion done (Bug 21701: PayPal return URL option)\n";
 }
 
 $DBversion = '19.06.00.038';
 if( CheckVersion( $DBversion ) ) {
     $dbh->do( "UPDATE systempreferences SET variable='PatronAutoComplete' WHERE variable='CircAutocompl' LIMIT 1" );
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 23697 - Rename CircAutocompl system preference to PatronAutoComplete)\n";
+    print "Upgrade to $DBversion done (Bug 23697: Rename CircAutocompl system preference to PatronAutoComplete)\n";
 }
 
 $DBversion = '19.06.00.039';
@@ -19661,7 +19683,7 @@ if( CheckVersion( $DBversion ) ) {
         ;
     |);
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 17179 - Add additional keyboard_shortcuts)\n";
+    print "Upgrade to $DBversion done (Bug 17179: Add additional keyboard_shortcuts)\n";
 }
 
 $DBversion = '19.06.00.040';
@@ -19674,7 +19696,7 @@ if( CheckVersion( $DBversion ) ) {
     |);
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 17140 - Add pref to allow rounding fines at payment)\n";
+    print "Upgrade to $DBversion done (Bug 17140: Add pref to allow rounding fines at payment)\n";
 }
 
 $DBversion = '19.06.00.041';
@@ -19704,7 +19726,7 @@ if( CheckVersion( $DBversion ) ) {
     });
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 22445 - Add new pref *CustomCoverImages*)\n";
+    print "Upgrade to $DBversion done (Bug 22445: Add new pref *CustomCoverImages*)\n";
 }
 
 $DBversion = '19.06.00.043';
@@ -19876,7 +19898,7 @@ if ( CheckVersion($DBversion) ) {
     unless ( column_exists('accountlines', 'debit_type_code') ) {
         $dbh->do(
             qq{
-                ALTER IGNORE TABLE accountlines
+                ALTER TABLE accountlines
                 ADD
                   debit_type_code varchar(80) DEFAULT NULL
                 AFTER
@@ -19927,7 +19949,7 @@ if ( CheckVersion($DBversion) ) {
     );
 
     SetVersion($DBversion);
-    print "Upgrade to $DBversion done (Bug 23049 - Add account debit_types)\n";
+    print "Upgrade to $DBversion done (Bug 23049: Add account debit_types)\n";
 }
 
 $DBversion = '19.06.00.044';
@@ -19980,7 +20002,7 @@ if ( CheckVersion($DBversion) ) {
     unless ( column_exists('accountlines', 'credit_type_code') ) {
         $dbh->do(
             qq{
-                ALTER IGNORE TABLE accountlines
+                ALTER TABLE accountlines
                 ADD
                   credit_type_code varchar(80) DEFAULT NULL
                 AFTER
@@ -20072,7 +20094,7 @@ if ( CheckVersion($DBversion) ) {
     );
 
     SetVersion($DBversion);
-    print "Upgrade to $DBversion done (Bug 23805 - Add account credit_types)\n";
+    print "Upgrade to $DBversion done (Bug 23805: Add account credit_types)\n";
 }
 
 $DBversion = '19.06.00.045';
@@ -20080,7 +20102,7 @@ if( CheckVersion( $DBversion ) ) {
     $dbh->do( "UPDATE systempreferences SET value = '2' WHERE value = '0' AND variable = 'UsageStats'" );
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 23866 - Set HEA syspref to prompt for review)\n";
+    print "Upgrade to $DBversion done (Bug 23866: Set HEA syspref to prompt for review)\n";
 }
 
 $DBversion = '19.06.00.046';
@@ -20096,7 +20118,7 @@ if( CheckVersion( $DBversion ) ) {
 
     # Always end with this (adjust the bug info)
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 15260 - Option for extended loan with useDaysMode)\n";
+    print "Upgrade to $DBversion done (Bug 15260: Option for extended loan with useDaysMode)\n";
 }
 
 $DBversion = '19.06.00.047';
@@ -20158,7 +20180,7 @@ if ( CheckVersion($DBversion) ) {
 
     SetVersion($DBversion);
     print
-"Upgrade to $DBversion done (Bug 14697 - Extend and enhance 'Claims returned' lost status)\n";
+"Upgrade to $DBversion done (Bug 14697: Extend and enhance 'Claims returned' lost status)\n";
 }
 
 $DBversion = '19.06.00.048';
@@ -20171,7 +20193,81 @@ if( CheckVersion( $DBversion ) ) {
     } );
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 22581 - add new OPACShowMusicalInscripts and OPACPlayMusicalInscripts system preferences)\n";
+    print "Upgrade to $DBversion done (Bug 22581: add new OPACShowMusicalInscripts and OPACPlayMusicalInscripts system preferences)\n";
+}
+
+$DBversion = '19.06.00.049';
+if( CheckVersion( $DBversion ) ) {
+
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+        SELECT
+            'SuspensionsCalendar',
+            IF( value='noFinesWhenClosed', 'noSuspensionsWhenClosed', 'ignoreCalendar'),
+            'ignoreCalendar|noSuspensionsWhenClosed',
+            'Specify whether to use the Calendar in calculating suspensions',
+            'Choice'
+        FROM systempreferences
+        WHERE variable='finesCalendar';
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 13958: Add a SuspensionsCalendar syspref)\n";
+}
+
+$DBversion = '19.06.00.050';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( q{
+            INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+            VALUES ('OPACFineNoRenewalsIncludeCredits','1',NULL,'If enabled the value specified in OPACFineNoRenewals should include any unapplied account credits in the calculation','YesNo')
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 23293: Add 'OPACFineNoRenewalsIncludeCredits' system preference)\n";
+}
+
+$DBversion = '19.11.00.000';
+if( CheckVersion( $DBversion ) ) {
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (19.11.00 release)\n";
+}
+
+$DBversion = '19.12.00.000';
+if( CheckVersion( $DBversion ) ) {
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Dobbie is a free elf...)\n";
+}
+
+$DBversion = '19.12.00.001';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( "UPDATE marc_subfield_structure SET kohafield = NULL WHERE kohafield = 'bibliosubject.subject';" );
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 17831 - Remove non-existing bibliosubject.subject from frameworks)\n";
+}
+
+$DBversion = '19.12.00.002';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        UPDATE systempreferences SET
+        variable = 'AllowItemsOnHoldCheckoutSIP',
+        explanation = 'Do not generate RESERVE_WAITING and RESERVED warning when checking out items reserved to someone else via SIP. This allows self checkouts for those items.'
+        WHERE variable = 'AllowItemsOnHoldCheckout'
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 23233 - Rename AllowItemsOnHoldCheckout syspref)\n";
+}
+
+$DBversion = '19.12.00.003';
+if( CheckVersion( $DBversion ) ) {
+
+    if( !column_exists( 'library_groups', 'ft_local_hold_group' ) ) {
+        $dbh->do( "ALTER TABLE library_groups ADD COLUMN ft_local_hold_group tinyint(1) NOT NULL DEFAULT 0 AFTER ft_search_groups_staff" );
+    }
+
+    # Always end with this (adjust the bug info)
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 22284 - Add ft_local_hold_group column to library_groups)\n";
 }
 
 # SEE bug 13068