Bug 25261: DBRev 20.06.00.043
[srvgit] / installer / data / mysql / updatedatabase.pl
index d2bd7cb..63a54c2 100755 (executable)
@@ -21260,12 +21260,17 @@ if( CheckVersion( $DBversion ) ) {
 
 $DBversion = '19.12.00.052';
 if( CheckVersion( $DBversion ) ) {
+    my $finesCalendar = C4::Context->preference('finesCalendar');
+    my $value = $finesCalendar eq 'noFinesWhenClosed' ? 1 : 0;
+
     if( !column_exists( 'itemtypes', 'rentalcharge_daily_calendar' ) ) {
         $dbh->do(q{
             ALTER TABLE itemtypes ADD COLUMN
             rentalcharge_daily_calendar tinyint(1) NOT NULL DEFAULT 1
             AFTER rentalcharge_daily;
         });
+
+        $dbh->do("UPDATE itemtypes SET rentalcharge_daily_calendar = $value");
     }
 
     if( !column_exists( 'itemtypes', 'rentalcharge_hourly_calendar' ) ) {
@@ -21274,11 +21279,9 @@ if( CheckVersion( $DBversion ) ) {
             rentalcharge_hourly_calendar tinyint(1) NOT NULL DEFAULT 1
             AFTER rentalcharge_hourly;
         });
-    }
 
-    my $finesCalendar = C4::Context->preference('finesCalendar');
-    my $value = $finesCalendar eq 'noFinesWhenClosed' ? 1 : 0;
-    $dbh->do("UPDATE itemtypes SET rentalcharge_hourly_calendar = $value, rentalcharge_daily_calendar = $value");
+        $dbh->do("UPDATE itemtypes SET rentalcharge_hourly_calendar = $value");
+    }
 
     NewVersion( $DBversion, 21443, "Add ability to exclude holidays when calculating rentals fees by time period");
 }
@@ -22576,18 +22579,303 @@ if( CheckVersion( $DBversion ) ) {
 $DBversion = '20.06.00.023';
 if( CheckVersion( $DBversion ) ) {
 
+    my $QuoteOfTheDay = C4::Context->preference('QuoteOfTheDay');
     $dbh->do( q|
         UPDATE systempreferences
-        SET value = '',
-            options = 'intranet,opac',
+        SET options = 'intranet,opac',
             explanation = 'Enable or disable display of Quote of the Day on the OPAC and staff interface home page',
             type = 'multiple'
         WHERE variable = 'QuoteOfTheDay'
     | );
 
+    C4::Context->set_preference('QuoteOfTheDay', $QuoteOfTheDay ? 'opac' : '');
+
     NewVersion( $DBversion, 16371, "Quote of the Day (QOTD) for the staff interface " );
 }
 
+$DBversion = '20.06.00.024';
+if( CheckVersion( $DBversion ) ) {
+
+    $dbh->do( "UPDATE marc_subfield_structure SET liblibrarian = 'Home library' WHERE liblibrarian = 'Permanent location'
+        AND tagfield = 952 and tagsubfield = 'a'" );
+    $dbh->do( "UPDATE marc_subfield_structure SET libopac = 'Home library' WHERE libopac = 'Permanent location'
+        AND tagfield = 952 and tagsubfield = 'a'" );
+    $dbh->do( "UPDATE marc_subfield_structure SET liblibrarian = 'Current library' WHERE liblibrarian = 'Current location'
+        AND tagfield = 952 and tagsubfield = 'b'" );
+    $dbh->do( "UPDATE marc_subfield_structure SET libopac = 'Current library' WHERE libopac = 'Current location'
+        AND tagfield = 952 and tagsubfield = 'b'" );
+
+    NewVersion( $DBversion, 25867, "Update subfield descriptions for 952\$a and 952\$b");
+}
+
+$DBversion = '20.06.00.025';
+if( CheckVersion( $DBversion ) ) {
+
+    $dbh->do( q{
+        INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES
+        ('PatronDuplicateMatchingAddFields','surname|firstname|dateofbirth', NULL,'A list of fields separated by "|" to deduplicate patrons when created','Free')
+    });
+
+    NewVersion( $DBversion, 6725, "Adds PatronDuplicateMatchingAddFields system preference");
+}
+
+$DBversion = '20.06.00.026';
+if (CheckVersion($DBversion)) {
+    unless (column_exists('accountlines', 'credit_number')) {
+        $dbh->do('ALTER TABLE accountlines ADD COLUMN credit_number VARCHAR(20) NULL DEFAULT NULL COMMENT "autogenerated number for credits" AFTER debit_type_code');
+    }
+
+    unless (column_exists('account_credit_types', 'credit_number_enabled')) {
+        $dbh->do(q{
+            ALTER TABLE account_credit_types
+            ADD COLUMN credit_number_enabled TINYINT(1) NOT NULL DEFAULT 0
+                COMMENT "Is autogeneration of credit number enabled for this credit type"
+                AFTER can_be_added_manually
+        });
+    }
+
+    $dbh->do('INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES(?, ?, ?, ?, ?)', undef, 'AutoCreditNumber', '', '', 'Automatically generate a number for account credits', 'Choice');
+
+    NewVersion( $DBversion, 19036, "Add accountlines.credit_number, account_credit_types.credit_number_enabled and syspref AutoCreditNumber" );
+}
+
+$DBversion = '20.06.00.027';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( "INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('BiblioItemtypeInfo', '0','Control whether biblio level itemtype image displays','0','YesNo')" );
+
+    NewVersion( $DBversion, 8732, 'Add new BiblioItemtypeInfo to system preferences' );
+}
+
+$DBversion = '20.06.00.028';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+        ('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free')
+    });
+
+    NewVersion( $DBversion, 25958, "Allow LongOverdue cron to exclude specified lost values");
+}
+
+$DBversion = '20.06.00.029';
+if ( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO authorised_value_categories( category_name, is_system ) VALUES ('HOLD_CANCELLATION', 0);
+    });
+
+    $dbh->do(q{
+INSERT IGNORE INTO `letter` VALUES ('reserves','HOLD_CANCELLATION','','Hold Cancellation',0,'Your hold was canceled.','[%- USE AuthorisedValues -%]\r\nDear [% borrower.firstname %] [% borrower.surname %],\r\n\r\nYour hold for [% biblio.title %] was canceled for the following reason: [% AuthorisedValues.GetByCode( \'HOLD_CANCELLATION\', hold.cancellation_reason ) %]','email','default');
+    });
+
+    if ( !column_exists( 'reserves', 'cancellation_reason' ) ) {
+        $dbh->do(q{
+            ALTER TABLE reserves ADD COLUMN `cancellation_reason` varchar(80) default NULL AFTER cancellationdate;
+        });
+    }
+
+    if ( !column_exists( 'old_reserves', 'cancellation_reason' ) ) {
+        $dbh->do(q{
+            ALTER TABLE old_reserves ADD COLUMN `cancellation_reason` varchar(80) default NULL AFTER cancellationdate;
+        });
+    }
+
+    NewVersion( $DBversion, 25534, "Add ability to send an email specifying a reason when canceling a hold");
+}
+
+$DBversion = '20.06.00.030';
+if ( CheckVersion( $DBversion ) ) {
+
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type`) VALUES
+        ('AutoApprovePatronProfileSettings', '0', '', 'Automatically approve patron profile changes from the OPAC.', 'YesNo');
+    });
+
+    NewVersion( $DBversion, 20057, "Add new system preference 'AutoApprovePatronProfileSettings'");
+}
+
+$DBversion = '20.06.00.031';
+if( CheckVersion( $DBversion ) ) {
+
+    if( !column_exists( 'reserves', 'non_priority' ) ) {
+        $dbh->do("ALTER TABLE reserves ADD COLUMN `non_priority` tinyint(1) NOT NULL DEFAULT 0 AFTER `item_level_hold`");
+    }
+
+    if( !column_exists( 'old_reserves', 'non_priority' ) ) {
+        $dbh->do("ALTER TABLE old_reserves ADD COLUMN `non_priority` tinyint(1) NOT NULL DEFAULT 0 AFTER `item_level_hold`");
+    }
+
+    NewVersion( $DBversion, 22789, "Add non_priority column on reserves and old_reserves tables");
+}
+
+$DBversion = '20.06.00.032';
+if( CheckVersion( $DBversion ) ) {
+    if( !column_exists( 'items', 'exclude_from_local_holds_priority' ) ) {
+        $dbh->do(q{
+            ALTER TABLE `items` ADD COLUMN `exclude_from_local_holds_priority` tinyint(1) default NULL AFTER `new_status`
+        });
+    }
+
+    if( !column_exists( 'deleteditems', 'exclude_from_local_holds_priority' ) ) {
+        $dbh->do(q{
+            ALTER TABLE `deleteditems` ADD COLUMN `exclude_from_local_holds_priority` tinyint(1) default NULL AFTER `new_status`
+        });
+    }
+
+    if( !column_exists( 'categories', 'exclude_from_local_holds_priority' ) ) {
+        $dbh->do(q{
+            ALTER TABLE `categories` ADD COLUMN `exclude_from_local_holds_priority` tinyint(1) default NULL AFTER `change_password`
+        });
+    }
+    NewVersion( $DBversion, 19889, "Add exclude_from_local_holds_priority column to items, deleteditems and categories tables");
+}
+
+$DBversion = '20.06.00.033';
+if( CheckVersion( $DBversion ) ) {
+    if( column_exists( 'opac_news', 'timestamp' ) ) {
+        $dbh->do(q|
+            ALTER TABLE opac_news
+            CHANGE COLUMN timestamp published_on date DEFAULT NULL
+        |);
+    }
+    if( !column_exists( 'opac_news', 'updated_on' ) ) {
+        $dbh->do(q|
+            ALTER TABLE opac_news
+            ADD COLUMN updated_on timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER published_on
+        |);
+    }
+
+    $dbh->do(q|
+        UPDATE letter
+        SET content = REPLACE(content,?,?)
+        WHERE content LIKE ?
+    |, undef, 'opac_news.timestamp', 'opac_news.published_on', '%opac_news.timestamp%' );
+
+    NewVersion( $DBversion, 21066, ["Rename column opac_news.timestamp with published_on", "Add new column opac_news.updated_on", "Replace timestamp references in letters table"] );
+}
+
+$DBversion = '20.06.00.034';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q|
+        INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type)
+        VALUES ('AddressForFailedOverdueNotices', '', NULL, 'Destination email for failed overdue notices. If left empty then it will fallback to the first defined address in the following list: Library ReplyTo, Library Email, ReplytoDefault and KohaAdminEmailAddress', 'free')
+    |);
+
+    NewVersion( $DBversion, 24197, "Add new system preference 'AddressForFailedOverdueNotices'" );
+}
+
+$DBversion = '20.06.00.035';
+if ( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+        ('EdifactInvoiceImport', 'automatic', 'automatic|manual', "If on, don't auto-import EDI invoices, just keep them in the database with the status 'new'", 'Choice')
+    });
+
+    NewVersion( $DBversion, 23682, "Add new system preference 'EdifactInvoiceImport'" );
+}
+
+$DBversion = '20.06.00.036';
+if( CheckVersion( $DBversion ) ) {
+    # Fix the markup in the OPACSearchForTitleIn system preference
+    $dbh->do("UPDATE systempreferences SET VALUE = replace( value, '</li>', ''), value = REPLACE( value, '<li>', '') WHERE VARIABLE = 'OPACSearchForTitleIn';");
+
+    NewVersion( $DBversion, 20168, "Update OPACSearchForTitleIn to work with Bootstrap 4");
+}
+
+$DBversion = '20.06.00.037';
+if( CheckVersion( $DBversion ) ) {
+    if( !column_exists( 'categories', 'min_password_length' ) ) {
+        $dbh->do("ALTER TABLE categories ADD COLUMN `min_password_length` smallint(6) NULL DEFAULT NULL AFTER `change_password` -- set minimum password length for patrons in this category");
+    }
+    if( !column_exists( 'categories', 'require_strong_password' ) ) {
+        $dbh->do("ALTER TABLE categories ADD COLUMN `require_strong_password` TINYINT(1) NULL DEFAULT NULL AFTER `min_password_length` -- set required password strength for patrons in this category");
+    }
+
+    NewVersion( $DBversion, 23816, "Add min_password_length and require_strong_password columns in categories table");
+}
+
+$DBversion = '20.06.00.038';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( "ALTER TABLE `search_field` MODIFY COLUMN `type` enum('','string','date','number','boolean','sum','isbn','stdno','year') NOT NULL" );
+    $dbh->do( "UPDATE `search_field` SET type = 'year' WHERE name = 'date-of-publication'" );
+
+    NewVersion( $DBversion, 24807, "Add 'year' type to improve sorting behaviour" );
+}
+
+$DBversion = '20.06.00.039';
+if( CheckVersion( $DBversion ) ) {
+
+    if( !column_exists( 'hold_fill_targets', 'reserve_id' ) ) {
+        $dbh->do( "ALTER TABLE hold_fill_targets ADD COLUMN reserve_id int(11) DEFAULT NULL AFTER item_level_request" );
+    }
+
+    NewVersion( $DBversion, 18958, "Add reserve_id to hold_fill_targets");
+}
+
+$DBversion = '20.06.00.040';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( "INSERT IGNORE INTO systempreferences (variable, value, options, explanation, type) VALUES ('OpacMetaDescription','','','This description will show in search engine results (160 characters).','Textarea');" );
+
+    NewVersion( $DBversion, 26454, "Add system preference to set meta description for the OPAC");
+}
+
+$DBversion = '20.06.00.041';
+if ( CheckVersion($DBversion) ) {
+
+    if ( column_exists( 'items', 'paidfor' ) ) {
+        my ($count) = $dbh->selectrow_array(
+            q|
+                SELECT COUNT(*)
+                FROM items
+                WHERE paidfor IS NOT NULL AND paidfor <> ""
+            |
+        );
+        if ($count) {
+            warn "Warning - Cannot remove column items.paidfor. At least one value exists";
+        }
+        else {
+            $dbh->do(q|ALTER TABLE items DROP COLUMN paidfor|);
+            $dbh->do(q|UPDATE marc_subfield_structure SET kohafield = '' WHERE kohafield = 'items.paidfor'|);
+        }
+    }
+
+    if ( column_exists( 'deleteditems', 'paidfor' ) ) {
+        my ($count) = $dbh->selectrow_array(
+            q|
+                SELECT COUNT(*)
+                FROM deleteditems
+                WHERE paidfor IS NOT NULL AND paidfor <> ""
+            |
+        );
+        if ($count) {
+            warn "Warning - Cannot remove column deleteditems.paidfor. At least one value exists";
+        }
+        else {
+            $dbh->do(q|ALTER TABLE deleteditems DROP COLUMN paidfor|);
+        }
+    }
+
+    NewVersion( $DBversion, 26268, "Remove items.paidfor field" );
+}
+
+$DBversion = '20.06.00.042';
+if( CheckVersion( $DBversion ) ) {
+    unless ( column_exists('letter', 'updated_on') ) {
+        $dbh->do(q|
+            ALTER TABLE letter ADD COLUMN updated_on timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER lang
+        |);
+    }
+
+    NewVersion( $DBversion, 25776, "Add letter.updated_on");
+}
+
+$DBversion = '20.06.00.043';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('CircConfirmItemParts', '0', NULL, 'Require staff to confirm that all parts of an item are present at checkin/checkout.', 'YesNo')
+    });
+
+    NewVersion( $DBversion, 25261, "Add CircConfirmItemParts syspref");
+}
+
 # SEE bug 13068
 # if there is anything in the atomicupdate, read and execute it.
 my $update_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/atomicupdate/';