+ print "Upgrade to $DBversion done (Bug 17140: Add pref to allow rounding fines at payment)\n";
+}
+
+$DBversion = '19.06.00.041';
+if( CheckVersion( $DBversion ) ) {
+ my ($socialnetworks) = $dbh->selectrow_array( q|
+ SELECT value FROM systempreferences WHERE variable='socialnetworks';
+ |);
+ if( $socialnetworks ){
+ # If the socialnetworks preference is enabled, enable all social networks
+ $dbh->do("UPDATE systempreferences SET value = 'email,facebook,linkedin,twitter', explanation = 'email|facebook|linkedin|twitter', type = 'multiple' WHERE variable = 'SocialNetworks'");
+ } else {
+ $dbh->do("UPDATE systempreferences SET value = '', explanation = 'email|facebook|linkedin|twitter', type = 'multiple' WHERE variable = 'SocialNetworks'");
+ }
+ SetVersion ($DBversion);
+ print "Upgrade to $DBversion done (Bug 22880: Allow granular control of socialnetworks preference)\n";
+}
+
+$DBversion = '19.06.00.042';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences
+ ( variable, value, options, explanation, type )
+ VALUES
+ ('CustomCoverImages','0',NULL,'If enabled, the custom cover images will be displayed in the staff client. CustomCoverImagesURL must be defined.','YesNo'),
+ ('OPACCustomCoverImages','0',NULL,'If enabled, the custom cover images will be displayed at the OPAC. CustomCoverImagesURL must be defined.','YesNo'),
+ ('CustomCoverImagesURL','',NULL,'Define an URL serving book cover images, using the following patterns: {issn}, {isbn}, {normalized_isbn}, {field$subfield} (use it with CustomCoverImages and/or OPACCustomCoverImages)','free')
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 22445: Add new pref *CustomCoverImages*)\n";
+}
+
+$DBversion = '19.06.00.043';
+if ( CheckVersion($DBversion) ) {
+
+ # Adding account_debit_types
+ $dbh->do(
+ qq{
+ CREATE TABLE IF NOT EXISTS account_debit_types (
+ code varchar(80) NOT NULL,
+ description varchar(200) NULL,
+ can_be_added_manually tinyint(4) NOT NULL DEFAULT 1,
+ default_amount decimal(28, 6) NULL,
+ is_system tinyint(1) NOT NULL DEFAULT 0,
+ archived tinyint(1) NOT NULL DEFAULT 0,
+ PRIMARY KEY (code)
+ ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
+ }
+ );
+
+ # Adding account_debit_types_branches
+ $dbh->do(
+ qq{
+ CREATE TABLE IF NOT EXISTS account_debit_types_branches (
+ debit_type_code VARCHAR(80),
+ branchcode VARCHAR(10),
+ FOREIGN KEY (debit_type_code) REFERENCES account_debit_types(code) ON DELETE CASCADE,
+ FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
+ }
+ );
+
+ # Populating account_debit_types
+ $dbh->do(
+ qq{
+ INSERT IGNORE INTO account_debit_types (
+ code,
+ description,
+ can_be_added_manually,
+ default_amount,
+ is_system
+ )
+ VALUES
+ ('ACCOUNT', 'Account creation fee', 0, NULL, 1),
+ ('ACCOUNT_RENEW', 'Account renewal fee', 0, NULL, 1),
+ ('RESERVE_EXPIRED', 'Hold waiting too long', 0, NULL, 1),
+ ('LOST', 'Lost item', 1, NULL, 1),
+ ('MANUAL', 'Manual fee', 1, NULL, 0),
+ ('NEW_CARD', 'New card fee', 1, NULL, 1),
+ ('OVERDUE', 'Overdue fine', 0, NULL, 1),
+ ('PROCESSING', 'Lost item processing fee', 0, NULL, 1),
+ ('RENT', 'Rental fee', 0, NULL, 1),
+ ('RENT_DAILY', 'Daily rental fee', 0, NULL, 1),
+ ('RENT_RENEW', 'Renewal of rental item', 0, NULL, 1),
+ ('RENT_DAILY_RENEW', 'Rewewal of daily rental item', 0, NULL, 1),
+ ('RESERVE', 'Hold fee', 0, NULL, 1)
+ }
+ );
+
+ # Update accountype 'Res' to 'RESERVE'
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET accounttype = 'RESERVE' WHERE accounttype = 'Res'
+ }
+ );
+
+ # Update accountype 'PF' to 'PROCESSING'
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET accounttype = 'PROCESSING' WHERE accounttype = 'PF'
+ }
+ );
+
+ # Update accountype 'HE' to 'RESERVE_EXPIRED'
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET accounttype = 'RESERVE_EXPIRED' WHERE accounttype = 'HE'
+ }
+ );
+
+ # Update accountype 'N' to 'NEW_CARD'
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET accounttype = 'NEW_CARD' WHERE accounttype = 'N'
+ }
+ );
+
+ # Update accountype 'M' to 'MANUAL'
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET accounttype = 'MANUAL' WHERE accounttype = 'M'
+ }
+ );
+
+ # Catch 'F' cases introduced since bug 22521
+ $dbh->do(qq{
+ UPDATE
+ accountlines
+ SET
+ accounttype = 'OVERDUE',
+ status = 'RETURNED'
+ WHERE
+ accounttype = 'F';
+ });
+
+ # Moving MANUAL_INV to account_debit_types
+ $dbh->do(
+ qq{
+ INSERT IGNORE INTO account_debit_types (
+ code,
+ default_amount,
+ description,
+ can_be_added_manually,
+ is_system
+ )
+ SELECT
+ authorised_value,
+ lib,
+ authorised_value,
+ 1,
+ 0
+ FROM
+ authorised_values
+ WHERE
+ category = 'MANUAL_INV'
+ }
+ );
+
+ # Update uncaught partial accounttypes left behind after bugs 23539 and 22521
+ my $sth = $dbh->prepare( "SELECT code, SUBSTR(code, 1,5) AS subcode FROM account_debit_types" );
+ $sth->execute();
+ while ( my $row = $sth->fetchrow_hashref ) {
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET accounttype = ? WHERE accounttype = ?
+ },
+ {},
+ (
+ $row->{code},
+ $row->{subcode}
+ )
+ );
+ }
+
+ # Add any unexpected accounttype codes to debit_types as appropriate
+ $dbh->do(
+ qq{
+ INSERT IGNORE INTO account_debit_types (
+ code,
+ description,
+ can_be_added_manually,
+ default_amount,
+ is_system
+ )
+ SELECT
+ DISTINCT(accounttype),
+ "Unexpected type found during upgrade",
+ 1,
+ NULL,
+ 0
+ FROM
+ accountlines
+ WHERE
+ amount >= 0
+ }
+ );
+
+ # Adding debit_type_code to accountlines
+ unless ( column_exists('accountlines', 'debit_type_code') ) {
+ $dbh->do(
+ qq{
+ ALTER TABLE accountlines
+ ADD
+ debit_type_code varchar(80) DEFAULT NULL
+ AFTER
+ accounttype
+ }
+ );
+ }
+
+ # Linking debit_type_code in accountlines to code in account_debit_types
+ unless ( foreign_key_exists( 'accountlines', 'accountlines_ibfk_debit_type' ) ) {
+ $dbh->do(
+ qq{
+ ALTER TABLE accountlines ADD CONSTRAINT `accountlines_ibfk_debit_type` FOREIGN KEY (`debit_type_code`) REFERENCES `account_debit_types` (`code`) ON DELETE RESTRICT ON UPDATE CASCADE
+ }
+ );
+ }
+
+ # Populating debit_type_code
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET debit_type_code = accounttype, accounttype = NULL WHERE accounttype IN (SELECT code from account_debit_types)
+ }
+ );
+
+ # Remove MANUAL_INV
+ $dbh->do(
+ qq{
+ DELETE FROM authorised_values WHERE category = 'MANUAL_INV'
+ }
+ );
+ $dbh->do(
+ qq{
+ DELETE FROM authorised_value_categories WHERE category_name = 'MANUAL_INV'
+ }
+ );
+
+ # Add new permission
+ $dbh->do(
+ q{
+ INSERT IGNORE INTO permissions (module_bit, code, description)
+ VALUES
+ (
+ 3,
+ 'manage_accounts',
+ 'Manage Account Debit and Credit Types'
+ )
+ }
+ );
+
+ SetVersion($DBversion);
+ print "Upgrade to $DBversion done (Bug 23049: Add account debit_types)\n";
+}
+
+$DBversion = '19.06.00.044';
+if ( CheckVersion($DBversion) ) {
+
+ # Adding account_credit_types
+ $dbh->do(
+ qq{
+ CREATE TABLE IF NOT EXISTS account_credit_types (
+ code varchar(80) NOT NULL,
+ description varchar(200) NULL,
+ can_be_added_manually tinyint(4) NOT NULL DEFAULT 1,
+ is_system tinyint(1) NOT NULL DEFAULT 0,
+ PRIMARY KEY (code)
+ ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci
+ }
+ );
+
+ # Adding account_credit_types_branches
+ $dbh->do(
+ qq{
+ CREATE TABLE IF NOT EXISTS account_credit_types_branches (
+ credit_type_code VARCHAR(80),
+ branchcode VARCHAR(10),
+ FOREIGN KEY (credit_type_code) REFERENCES account_credit_types(code) ON DELETE CASCADE,
+ FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON DELETE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
+ }
+ );
+
+ # Populating account_credit_types
+ $dbh->do(
+ qq{
+ INSERT IGNORE INTO account_credit_types (
+ code,
+ description,
+ can_be_added_manually,
+ is_system
+ )
+ VALUES
+ ('PAYMENT', 'Payment', 0, 1),
+ ('WRITEOFF', 'Writeoff', 0, 1),
+ ('FORGIVEN', 'Forgiven', 1, 1),
+ ('CREDIT', 'Credit', 1, 1),
+ ('LOST_RETURN', 'Lost item fee refund', 0, 1)
+ }
+ );
+
+ # Adding credit_type_code to accountlines
+ unless ( column_exists('accountlines', 'credit_type_code') ) {
+ $dbh->do(
+ qq{
+ ALTER TABLE accountlines
+ ADD
+ credit_type_code varchar(80) DEFAULT NULL
+ AFTER
+ accounttype
+ }
+ );
+ }
+
+ # Linking credit_type_code in accountlines to code in account_credit_types
+ unless ( foreign_key_exists( 'accountlines', 'accountlines_ibfk_credit_type' ) ) {
+ $dbh->do(
+ qq{
+ ALTER TABLE accountlines
+ ADD CONSTRAINT
+ `accountlines_ibfk_credit_type`
+ FOREIGN KEY (`credit_type_code`) REFERENCES `account_credit_types` (`code`)
+ ON DELETE RESTRICT
+ ON UPDATE CASCADE
+ }
+ );
+ }
+
+ # Update accountype 'C' to 'CREDIT'
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET accounttype = 'CREDIT' WHERE accounttype = 'C' OR accounttype = 'CR'
+ }
+ );
+
+ # Update accountype 'FOR' to 'FORGIVEN'
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET accounttype = 'FORGIVEN' WHERE accounttype = 'FOR' OR accounttype = 'FORW'
+ }
+ );
+
+ # Update accountype 'Pay' to 'PAYMENT'
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET accounttype = 'PAYMENT' WHERE accounttype = 'Pay' OR accounttype = 'PAY'
+ }
+ );
+
+ # Update accountype 'W' to 'WRITEOFF'
+ $dbh->do(
+ qq{
+ UPDATE accountlines SET accounttype = 'WRITEOFF' WHERE accounttype = 'W' OR accounttype = 'WO'
+ }
+ );
+
+ # Add any unexpected accounttype codes to credit_types as appropriate
+ $dbh->do(
+ qq{
+ INSERT IGNORE INTO account_credit_types (
+ code,
+ description,
+ can_be_added_manually,
+ is_system
+ )
+ SELECT
+ DISTINCT(accounttype),
+ "Unexpected type found during upgrade",
+ 1,
+ 0
+ FROM
+ accountlines
+ WHERE
+ amount < 0
+ }
+ );
+
+ # Populating credit_type_code
+ $dbh->do(
+ qq{
+ UPDATE
+ accountlines
+ SET
+ credit_type_code = accounttype, accounttype = NULL
+ WHERE accounttype IN (SELECT code from account_credit_types)
+ }
+ );
+
+ # Drop accounttype field
+ $dbh->do(
+ qq{
+ ALTER TABLE accountlines
+ DROP COLUMN `accounttype`
+ }
+ );
+
+ SetVersion($DBversion);
+ print "Upgrade to $DBversion done (Bug 23805: Add account credit_types)\n";
+}
+
+$DBversion = '19.06.00.045';
+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";
+}
+
+$DBversion = '19.06.00.046';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(qq{
+ UPDATE systempreferences
+ SET
+ options = "Calendar|Days|Datedue|Dayweek",
+ explanation = "Choose the method for calculating due date: select Calendar, Datedue or Dayweek to use the holidays module, and Days to ignore the holidays module"
+ WHERE
+ variable = "useDaysMode"
+ });
+
+ # Always end with this (adjust the bug info)
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 15260: Option for extended loan with useDaysMode)\n";
+}
+
+$DBversion = '19.06.00.047';
+if ( CheckVersion($DBversion) ) {
+ if ( !TableExists('return_claims') ) {
+ $dbh->do(
+ q{
+ CREATE TABLE return_claims (
+ id int(11) auto_increment, -- Unique ID of the return claim
+ itemnumber int(11) NOT NULL, -- ID of the item
+ issue_id int(11) NULL DEFAULT NULL, -- ID of the checkout that triggered the claim
+ borrowernumber int(11) NOT NULL, -- ID of the patron
+ notes MEDIUMTEXT DEFAULT NULL, -- Notes about the claim
+ created_on TIMESTAMP NULL, -- Time and date the claim was created
+ created_by int(11) NULL DEFAULT NULL, -- ID of the staff member that registered the claim
+ updated_on TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP, -- Time and date of the latest change on the claim (notes)
+ updated_by int(11) NULL DEFAULT NULL, -- ID of the staff member that updated the claim
+ resolution varchar(80) NULL DEFAULT NULL, -- Resolution code (RETURN_CLAIM_RESOLUTION AVs)
+ resolved_on TIMESTAMP NULL DEFAULT NULL, -- Time and date the claim was resolved
+ resolved_by int(11) NULL DEFAULT NULL, -- ID of the staff member that resolved the claim
+ PRIMARY KEY (`id`),
+ KEY `itemnumber` (`itemnumber`),
+ CONSTRAINT UNIQUE `issue_id` ( issue_id ),
+ CONSTRAINT `issue_id` FOREIGN KEY (`issue_id`) REFERENCES `issues` (`issue_id`) ON DELETE SET NULL ON UPDATE CASCADE,
+ CONSTRAINT `rc_items_ibfk` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `rc_borrowers_ibfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `rc_created_by_ibfk` FOREIGN KEY (`created_by`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
+ CONSTRAINT `rc_updated_by_ibfk` FOREIGN KEY (`updated_by`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
+ CONSTRAINT `rc_resolved_by_ibfk` FOREIGN KEY (`resolved_by`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+ }
+ );
+ }
+
+ $dbh->do(
+ q{
+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+ ('ClaimReturnedChargeFee', 'ask', 'ask|charge|no_charge', 'Controls whether or not a lost item fee is charged for return claims', 'Choice'),
+ ('ClaimReturnedLostValue', '', '', 'Sets the LOST AV value that represents "Claims returned" as a lost value', 'Free'),
+ ('ClaimReturnedWarningThreshold', '', '', 'Sets the number of return claims past which the librarian will be warned the patron has many return claims', 'Integer');
+ }
+ );
+
+ $dbh->do(
+ q{
+ INSERT IGNORE INTO authorised_value_categories ( category_name ) VALUES
+ ('RETURN_CLAIM_RESOLUTION');
+ }
+ );
+
+ $dbh->do(
+ q{
+ INSERT IGNORE INTO `authorised_values` ( category, authorised_value, lib )
+ VALUES
+ ('RETURN_CLAIM_RESOLUTION', 'RET_BY_PATRON', 'Returned by patron'),
+ ('RETURN_CLAIM_RESOLUTION', 'FOUND_IN_LIB', 'Found in library');
+ }
+ );
+
+ SetVersion($DBversion);
+ print
+"Upgrade to $DBversion done (Bug 14697: Extend and enhance 'Claims returned' lost status)\n";
+}
+
+$DBversion = '19.06.00.048';
+if( CheckVersion( $DBversion ) ) {
+ # you can use $dbh here like:
+ $dbh->do( qq{
+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` )
+ VALUES ('OPACShowMusicalInscripts','0','','Display musical inscripts on the OPAC record details page when available.','YesNo'),
+ ('OPACPlayMusicalInscripts','0','','If displayed musical inscripts, play midi conversion on the OPAC record details page.','YesNo')
+ } );
+
+ SetVersion( $DBversion );
+ 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";