use MARC::File::XML ( BinaryEncoding => 'utf8' );
use File::Path qw[remove_tree]; # perl core module
-use File::Spec;
use File::Slurp;
# FIXME - The user might be installing a new database, so can't rely
WHERE COALESCE(permanent,0)=0 AND dir='koha_upload'
});
-my $tmp= File::Spec->tmpdir.'/koha_upload';
+my $tmp = C4::Context->temporary_directory . '/koha_upload';
remove_tree( $tmp ) if -d $tmp;
print "Upgrade to $DBversion done (Bug 14893 - Separate temporary storage per instance in Upload.pm)\n";
WHERE ordernumber = ?
|);
- require Koha::Number::Price;
+ require Number::Format;
+ my $format = Number::Format->new;
+ my $precision = 2;
for my $order ( @$orders ) {
$sth_get_bookseller->execute( $order->{ordernumber} );
my ( $bookseller ) = $sth_get_bookseller->fetchrow_hashref;
- $order->{rrp} = Koha::Number::Price->new( $order->{rrp} )->round;
- $order->{ecost} = Koha::Number::Price->new( $order->{ecost} )->round;
+ $order->{rrp} = $format->round( $order->{rrp}, $precision );
+ $order->{ecost} = $format->round( $order->{ecost}, $precision );
$order->{tax_rate} ||= 0 ; # tax_rate can be NULL in DB
# Ordering
if ( $bookseller->{listincgst} ) {
$order->{rrp_tax_included} = $order->{rrp};
- $order->{rrp_tax_excluded} = Koha::Number::Price->new(
- $order->{rrp_tax_included} / ( 1 + $order->{tax_rate} ) )->round;
+ $order->{rrp_tax_excluded} = $format->round(
+ $order->{rrp_tax_included} / ( 1 + $order->{tax_rate} ), $precision );
$order->{ecost_tax_included} = $order->{ecost};
- $order->{ecost_tax_excluded} = Koha::Number::Price->new(
- $order->{ecost} / ( 1 + $order->{tax_rate} ) )->round;
+ $order->{ecost_tax_excluded} = $format->round(
+ $order->{ecost} / ( 1 + $order->{tax_rate} ), $precision );
}
else {
$order->{rrp_tax_excluded} = $order->{rrp};
- $order->{rrp_tax_included} = Koha::Number::Price->new(
- $order->{rrp} * ( 1 + $order->{tax_rate} ) )->round;
+ $order->{rrp_tax_included} = $format->round(
+ $order->{rrp} * ( 1 + $order->{tax_rate} ), $precision );
$order->{ecost_tax_excluded} = $order->{ecost};
- $order->{ecost_tax_included} = Koha::Number::Price->new(
- $order->{ecost} * ( 1 + $order->{tax_rate} ) )->round;
+ $order->{ecost_tax_included} = $format->round(
+ $order->{ecost} * ( 1 + $order->{tax_rate} ), $precision );
}
#receiving
if ( $bookseller->{listincgst} ) {
- $order->{unitprice_tax_included} = Koha::Number::Price->new( $order->{unitprice} )->round;
- $order->{unitprice_tax_excluded} = Koha::Number::Price->new(
- $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate} ) )->round;
+ $order->{unitprice_tax_included} = $format->round( $order->{unitprice}, $precision );
+ $order->{unitprice_tax_excluded} = $format->round(
+ $order->{unitprice_tax_included} / ( 1 + $order->{tax_rate} ), $precision );
}
else {
- $order->{unitprice_tax_excluded} = Koha::Number::Price->new( $order->{unitprice} )->round;
- $order->{unitprice_tax_included} = Koha::Number::Price->new(
- $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate} ) )->round;
+ $order->{unitprice_tax_excluded} = $format->round( $order->{unitprice}, $precision );
+ $order->{unitprice_tax_included} = $format->round(
+ $order->{unitprice_tax_excluded} * ( 1 + $order->{tax_rate} ), $precision );
}
# If the order is received, the tax is calculated from the unit price
if ( $order->{orderstatus} eq 'complete' ) {
- $order->{tax_value} = Koha::Number::Price->new(
+ $order->{tax_value} = $format->round(
( $order->{unitprice_tax_included} - $order->{unitprice_tax_excluded} )
- * $order->{quantity} )->round;
+ * $order->{quantity}, $precision );
} else {
# otherwise the ecost is used
- $order->{tax_value} = Koha::Number::Price->new(
+ $order->{tax_value} = $format->round(
( $order->{ecost_tax_included} - $order->{ecost_tax_excluded} ) *
- $order->{quantity} )->round;
+ $order->{quantity}, $precision );
}
$sth_update_order->execute(
WHERE ordernumber = ?
|);
- require Koha::Number::Price;
for my $order (@$orders) {
my $tax_value_on_ordering =
$order->{quantity} *
borrowernumber int(11) NOT NULL,
date_enrolled timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
date_canceled timestamp NULL DEFAULT NULL,
- date_created timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+ date_created timestamp NULL DEFAULT NULL,
date_updated timestamp NULL DEFAULT NULL,
branchcode varchar(10) NULL DEFAULT NULL,
PRIMARY KEY (id),
$dbh->do(q|
INSERT IGNORE INTO letter (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`)
- VALUES ('circulation', 'PATRON_NOTE', '', 'Patron note on item', '0', 'Patron issue note', '<<borrowers.firstname>> <<borrowers.surname>> has added a note to the item <<biblio.item>> - <<biblio.author>> (<<biblio.biblionumber>>).','email');
+ VALUES ('circulation', 'CHECKOUT_NOTE', '', 'Checkout note on item set by patron', '0', 'Checkout note', '<<borrowers.firstname>> <<borrowers.surname>> has added a note to the item <<biblio.title>> - <<biblio.author>> (<<biblio.biblionumber>>).','email');
|);
$dbh->do(q|
$requested_expiration = dt_from_string($hold->expirationdate);
}
- my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode );
- my $expirationdate = dt_from_string();
- $expirationdate->add(days => $max_pickup_delay);
-
+ my $expirationdate = dt_from_string($hold->waitingdate);
if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) {
- $expirationdate = $calendar->days_forward( dt_from_string(), $max_pickup_delay );
+ my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode );
+ $expirationdate = $calendar->days_forward( $expirationdate, $max_pickup_delay );
+ } else {
+ $expirationdate->add( days => $max_pickup_delay );
}
my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;
print "Upgrade to $DBversion done (Bug 13912 - System preference for default place of publication (country code) for field 008, range 15-17)\n";
}
-# DEVELOPER PROCESS, search for anything to execute in the db_update directory
+$DBversion = '17.06.00.011';
+if ( CheckVersion($DBversion) ) {
+ # Drop index that might exist because of bug 5337
+ if( index_exists('biblioitems', 'ean')) {
+ $dbh->do(q{ ALTER TABLE biblioitems DROP INDEX ean });
+ }
+ if( index_exists('deletedbiblioitems', 'ean')) {
+ $dbh->do(q{ ALTER TABLE deletedbiblioitems DROP INDEX ean });
+ }
+
+ # Change data type of column
+ $dbh->do(q{ ALTER TABLE biblioitems MODIFY COLUMN ean MEDIUMTEXT default NULL });
+ $dbh->do(q{ ALTER TABLE deletedbiblioitems MODIFY COLUMN ean MEDIUMTEXT default NULL });
+
+ # Add indexes
+ $dbh->do(q{ ALTER TABLE biblioitems ADD INDEX ean ( ean(255) )});
+ $dbh->do(q{ ALTER TABLE deletedbiblioitems ADD INDEX ean ( ean(255 ) )});
+
+ SetVersion($DBversion);
+ print "Upgrade to $DBversion done (Bug 13766 - Make ean mediumtext and add ean indexes)\n";
+}
+
+$DBversion = '17.06.00.012';
+if( CheckVersion( $DBversion ) ) {
+ my $where = q|host='clio-db.cc.columbia.edu' AND port=7090|;
+ my $sql = "SELECT COUNT(*) FROM z3950servers WHERE $where";
+ my ( $cnt ) = $dbh->selectrow_array( $sql );
+ if( $cnt ) {
+ $dbh->do( "DELETE FROM z3950servers WHERE $where" );
+ print "Removed $cnt Z39.50 target(s) for Columbia University\n";
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19043 - Z39.50 target for Columbia University is no longer publicly available.)\n";
+}
+
+$DBversion = '17.06.00.013';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do( "UPDATE systempreferences SET value = CONCAT('http://', value) WHERE variable = 'staffClientBaseURL' AND value <> '' AND value NOT LIKE 'http%'" );
+
+ my ( $staffClientBaseURL_used_in_notices ) = $dbh->selectrow_array(q|
+ SELECT COUNT(*) FROM letter where content like "%staffClientBaseURL%"
+ |);
+ if ( $staffClientBaseURL_used_in_notices ) {
+ warn "\tYou may need to update one or more notice templates if they contain 'staffClientBaseURL'\n";
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 16401 - fix potentialy bad set staffClientBaseURL preference)\n";
+}
+
+$DBversion = '17.06.00.014';
+if( CheckVersion( $DBversion ) ) {
+ unless( column_exists('aqbasket','create_items') ){
+ $dbh->do(q{
+ ALTER TABLE aqbasket
+ ADD COLUMN create_items ENUM('ordering', 'receiving', 'cataloguing') default NULL AFTER is_standing
+ });
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 15685 - Allow creation of items (AcqCreateItem) to be customizable per-basket)\n";
+}
+
+$DBversion = '17.06.00.015';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES
+ ('SelfCheckoutByLogin','0',NULL,'Have patrons login into the web-based self checkout system with their username/password or their cardnumber','YesNo')
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19186 - Insert system preference SelfCheckoutByLogin if missing)\n";
+}
+
+$DBversion = '17.06.00.016';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`)
+ VALUES ('RequireStrongPassword','0','','Require a strong login password for staff and patrons','YesNo');
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 18298 - Allow enforcing password complexity (system preference RequireStrongPassword))\n";
+}
+
+$DBversion = '17.06.00.017';
+if( CheckVersion( $DBversion ) ) {
+ unless (TableExists('account_offsets')) {
+ $dbh->do(q{
+ DROP TABLE IF EXISTS `accountoffsets`;
+ });
+
+ $dbh->do(q{
+ CREATE TABLE IF NOT EXISTS `account_offset_types` (
+ `type` varchar(16) NOT NULL, -- The type of offset this is
+ PRIMARY KEY (`type`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+ });
+
+ $dbh->do(q{
+ CREATE TABLE IF NOT EXISTS `account_offsets` (
+ `id` int(11) NOT NULL auto_increment, -- unique identifier for each offset
+ `credit_id` int(11) NULL DEFAULT NULL, -- The id of the accountline the increased the patron's balance
+ `debit_id` int(11) NULL DEFAULT NULL, -- The id of the accountline that decreased the patron's balance
+ `type` varchar(16) NOT NULL, -- The type of offset this is
+ `amount` decimal(26,6) NOT NULL, -- The amount of the change
+ `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP,
+ PRIMARY KEY (`id`),
+ CONSTRAINT `account_offsets_ibfk_p` FOREIGN KEY (`credit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `account_offsets_ibfk_f` FOREIGN KEY (`debit_id`) REFERENCES `accountlines` (`accountlines_id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `account_offsets_ibfk_t` FOREIGN KEY (`type`) REFERENCES `account_offset_types` (`type`) ON DELETE CASCADE ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+ });
+
+ $dbh->do(q{
+ INSERT IGNORE INTO account_offset_types ( type ) VALUES
+ ('Writeoff'),
+ ('Payment'),
+ ('Lost Item'),
+ ('Processing Fee'),
+ ('Manual Debit'),
+ ('Reverse Payment'),
+ ('Forgiven'),
+ ('Dropbox'),
+ ('Rental Fee'),
+ ('Fine Update'),
+ ('Fine');
+ });
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 14826 - Resurrect account offsets table (Add new tables account_offsets and account_offset_types))\n";
+}
+
+$DBversion = '17.06.00.018';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (variable,value,explanation,type) VALUES ('useDefaultReplacementCost',0,'default replacement cost defined in item type','YesNo');
+ });
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (variable,value,explanation,type) VALUES ('ProcessingFeeNote','','Set the text to be recorded in the column note, table accountlines when the processing fee (defined in item type) is applied','textarea');
+ });
+ $dbh->do(q{
+ ALTER TABLE `itemtypes` MODIFY COLUMN `rentalcharge` DECIMAL(28,6) NULL DEFAULT NULL;
+ });
+ unless ( column_exists( 'itemtypes', 'defaultreplacecost' ) ) {
+ $dbh->do(q{
+ ALTER TABLE `itemtypes` ADD `defaultreplacecost` DECIMAL(28,6) NULL DEFAULT NULL AFTER `rentalcharge`;
+ });
+ }
+ unless ( column_exists( 'itemtypes', 'processfee' ) ) {
+ $dbh->do(q{
+ ALTER TABLE `itemtypes` ADD `processfee` DECIMAL(28,6) NULL DEFAULT NULL AFTER `defaultreplacecost`;
+ });
+
+ }
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 12768 - Insert system preferences useDefaultReplacementCost and ProcessingFeeNote + Add new columns defaultreplacecost and processfee to the itemtypes table)\n";
+}
+
+$DBversion = '17.06.00.019';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO account_offset_types ( type ) VALUES ( 'Processing Fee' );
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 12768 - Add 'Processing Fee' to the account_offset_types table if missing)\n";
+}
+
+$DBversion = '17.06.00.020';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ UPDATE systempreferences
+ SET
+ variable='OpacLocationOnDetail',
+ options='holding|home|both|column',
+ explanation='In the OPAC detail, display the shelving location on its own column or under a library columns.'
+ WHERE
+ variable='OpacLocationBranchToDisplayShelving'
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19028: Add 'shelving location' to holdings table in detail page (Rename syspref OpacLocationBranchToDisplayShelving with OpacLocationOnDetail))\n";
+}
+
+$DBversion = '17.06.00.021';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type` ) VALUES ('SCOMainUserBlock','','70|10','Add a block of HTML that will display on the self checkout screen','Textarea')
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 17381 - Add system preference SCOMainUserBlock)\n";
+}
+
+$DBversion = '17.06.00.022';
+if( CheckVersion( $DBversion ) ) {
+ my $hide_barcode = C4::Context->preference('OPACShowBarcode') ? 0 : 1;
+ $dbh->do(q{
+ DELETE FROM systempreferences
+ WHERE
+ variable='OPACShowBarcode'
+ });
+
+ # Configure column visibility if it isn't
+ $dbh->do(q{
+ INSERT IGNORE INTO columns_settings
+ (module,page,tablename,columnname,cannot_be_toggled,is_hidden)
+ VALUES
+ ('opac','biblio-detail','holdingst','item_barcode',0,?)
+ }, undef, $hide_barcode);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19038: Remove OPACShowBarcode syspref)\n";
+}
+
+$DBversion = '17.06.00.023';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+ ('MarkLostItemsAsReturned','1','','Mark items as returned when flagged as lost','YesNo');
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 12363 - Add system preference MarkLostItemsAsReturned)\n";
+}
+
+$DBversion = '17.06.00.024';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (`variable`,`value`,`options`,`explanation`,`type`) VALUES
+ ('OPACUserSummary', 1, NULL, "Show the summary of a logged in user's checkouts, overdues, holds and fines on the mainpage", 'YesNo');
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 2093 - Add system preference OPACUserSummary)\n";
+}
+
+$DBversion = '17.06.00.025';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ ALTER TABLE borrowers MODIFY cardnumber varchar(32);
+ });
+ $dbh->do(q{
+ ALTER TABLE borrower_modifications MODIFY cardnumber varchar(32);
+ });
+ $dbh->do(q{
+ ALTER TABLE deletedborrowers MODIFY cardnumber varchar(32);
+ });
+ $dbh->do(q{
+ ALTER TABLE pending_offline_operations MODIFY cardnumber varchar(32);
+ });
+ $dbh->do(q{
+ ALTER TABLE tmp_holdsqueue MODIFY cardnumber varchar(32);
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 13178 - Increase cardnumber fields to VARCHAR(32))\n";
+}
+
+$DBversion = '17.06.00.026';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+ ('BlockReturnOfLostItems','0','0','If enabled, items that are marked as lost cannot be returned.','YesNo');
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 10748 - Add system preference BlockReturnOfLostItems)\n";
+}
+
+$DBversion = '17.06.00.027';
+if( CheckVersion( $DBversion ) ) {
+ if ( !column_exists( 'statistics', 'location' ) ) {
+ $dbh->do('ALTER TABLE statistics ADD COLUMN location VARCHAR(80) default NULL AFTER itemtype');
+ }
+
+ SetVersion($DBversion);
+ print "Upgrade to $DBversion done (Bug 18882 - Add location code to statistics table for checkouts and renewals)\n";
+}
+
+$DBversion = '17.06.00.028';
+if( CheckVersion( $DBversion ) ) {
+ if ( !TableExists( 'illrequests' ) ) {
+ $dbh->do(q{
+ CREATE TABLE illrequests (
+ illrequest_id serial PRIMARY KEY, -- ILL request number
+ borrowernumber integer DEFAULT NULL, -- Patron associated with request
+ biblio_id integer DEFAULT NULL, -- Potential bib linked to request
+ branchcode varchar(50) NOT NULL, -- The branch associated with the request
+ status varchar(50) DEFAULT NULL, -- Current Koha status of request
+ placed date DEFAULT NULL, -- Date the request was placed
+ replied date DEFAULT NULL, -- Last API response
+ updated timestamp DEFAULT CURRENT_TIMESTAMP -- Last modification to request
+ ON UPDATE CURRENT_TIMESTAMP,
+ completed date DEFAULT NULL, -- Date the request was completed
+ medium varchar(30) DEFAULT NULL, -- The Koha request type
+ accessurl varchar(500) DEFAULT NULL, -- Potential URL for accessing item
+ cost varchar(20) DEFAULT NULL, -- Cost of request
+ notesopac text DEFAULT NULL, -- Patron notes attached to request
+ notesstaff text DEFAULT NULL, -- Staff notes attached to request
+ orderid varchar(50) DEFAULT NULL, -- Backend id attached to request
+ backend varchar(20) DEFAULT NULL, -- The backend used to create request
+ CONSTRAINT `illrequests_bnfk`
+ FOREIGN KEY (`borrowernumber`)
+ REFERENCES `borrowers` (`borrowernumber`)
+ ON UPDATE CASCADE ON DELETE CASCADE,
+ CONSTRAINT `illrequests_bcfk_2`
+ FOREIGN KEY (`branchcode`)
+ REFERENCES `branches` (`branchcode`)
+ ON UPDATE CASCADE ON DELETE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+ });
+ }
+
+ if ( !TableExists( 'illrequestattributes' ) ) {
+ $dbh->do(q{
+ CREATE TABLE illrequestattributes (
+ illrequest_id bigint(20) unsigned NOT NULL, -- ILL request number
+ type varchar(200) NOT NULL, -- API ILL property name
+ value text NOT NULL, -- API ILL property value
+ PRIMARY KEY (`illrequest_id`,`type`),
+ CONSTRAINT `illrequestattributes_ifk`
+ FOREIGN KEY (illrequest_id)
+ REFERENCES `illrequests` (`illrequest_id`)
+ ON UPDATE CASCADE ON DELETE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+ });
+ }
+
+ # System preferences
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES
+ ('ILLModule','0','If ON, enables the interlibrary loans module.','','YesNo');
+ });
+
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES
+ ('ILLModuleCopyrightClearance','','70|10','Enter text to enable the copyright clearance stage of request creation. Text will be displayed','Textarea');
+ });
+ # userflags
+ $dbh->do(q{
+ INSERT IGNORE INTO userflags (bit,flag,flagdesc,defaulton) VALUES
+ (22,'ill','The Interlibrary Loans Module',0);
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 7317 - Add an Interlibrary Loan Module to Circulation and OPAC)\n";
+}
+
+$DBversion = '17.11.00.000';
+if( CheckVersion( $DBversion ) ) {
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Koha 17.11)\n";
+}
+
+$DBversion = '17.12.00.000';
+if( CheckVersion( $DBversion ) ) {
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Tē tōia, tē haumatia)\n";
+}
+
+$DBversion = '17.12.00.001';
+if( CheckVersion( $DBversion ) ) {
+ foreach my $table (qw(biblio_metadata deletedbiblio_metadata)) {
+ if (!column_exists($table, 'timestamp')) {
+ $dbh->do(qq{
+ ALTER TABLE `$table`
+ ADD COLUMN `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER `metadata`,
+ ADD KEY `timestamp` (`timestamp`)
+ });
+ $dbh->do(qq{
+ UPDATE $table metadata
+ LEFT JOIN biblioitems ON (biblioitems.biblionumber = metadata.biblionumber)
+ LEFT JOIN biblio ON (biblio.biblionumber = metadata.biblionumber)
+ SET metadata.timestamp = GREATEST(biblioitems.timestamp, biblio.timestamp);
+ });
+ }
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19724 - Add [deleted]biblio_metadata.timestamp)\n";
+}
+
+$DBversion = '17.12.00.002';
+if( CheckVersion( $DBversion ) ) {
+
+ my $msss = $dbh->selectall_arrayref(q|
+ SELECT kohafield, tagfield, tagsubfield, frameworkcode
+ FROM marc_subfield_structure
+ WHERE frameworkcode != ''
+ |, { Slice => {} });
+
+
+ my $sth = $dbh->prepare(q|
+ SELECT kohafield
+ FROM marc_subfield_structure
+ WHERE frameworkcode = ''
+ AND tagfield = ?
+ AND tagsubfield = ?
+ |);
+
+ my @exceptions;
+ for my $mss ( @$msss ) {
+ $sth->execute($mss->{tagfield}, $mss->{tagsubfield} );
+ my ( $default_kohafield ) = $sth->fetchrow_array();
+ if( $mss->{kohafield} ) {
+ push @exceptions, { frameworkcode => $mss->{frameworkcode}, tagfield => $mss->{tagfield}, tagsubfield => $mss->{tagsubfield}, kohafield => $mss->{kohafield} } if not $default_kohafield or $default_kohafield ne $mss->{kohafield};
+ } else {
+ push @exceptions, { frameworkcode => $mss->{frameworkcode}, tagfield => $mss->{tagfield}, tagsubfield => $mss->{tagsubfield}, kohafield => q{} } if $default_kohafield;
+ }
+ }
+
+ if (@exceptions) {
+ print "WARNING: The Default framework is now considered as authoritative for Koha to MARC mappings. We have found that your additional frameworks contained "
+ . scalar(@exceptions)
+ . " mapping(s) that deviate from the standard mappings. Please look at the following list and consider if you need to add them again in Default (possibly as a second mapping).\n";
+ for my $exception (@exceptions) {
+ print "Field "
+ . $exception->{tagfield} . '$'
+ . $exception->{tagsubfield}
+ . " in framework "
+ . $exception->{frameworkcode} . ': ';
+ if ( $exception->{kohafield} ) {
+ print "Mapping to "
+ . $exception->{kohafield}
+ . " has been adjusted.\n";
+ }
+ else {
+ print "Mapping has been reset.\n";
+ }
+ }
+
+ # Sync kohafield
+
+ # Clear the destination frameworks first
+ $dbh->do(q|
+ UPDATE marc_subfield_structure
+ SET kohafield = NULL
+ WHERE frameworkcode > ''
+ AND Kohafield > ''
+ |);
+
+ # Now copy from Default
+ my $msss = $dbh->selectall_arrayref(q|
+ SELECT kohafield, tagfield, tagsubfield
+ FROM marc_subfield_structure
+ WHERE frameworkcode = ''
+ AND kohafield > ''
+ |, { Slice => {} });
+ my $sth = $dbh->prepare(q|
+ UPDATE marc_subfield_structure
+ SET kohafield = ?
+ WHERE frameworkcode > ''
+ AND tagfield = ?
+ AND tagsubfield = ?
+ |);
+ for my $mss (@$msss) {
+ $sth->execute( $mss->{kohafield}, $mss->{tagfield},
+ $mss->{tagsubfield} );
+ }
+
+ # Clear the cache
+ my @frameworkcodes = $dbh->selectall_arrayref(q|
+ SELECT frameworkcode FROM biblio_framework WHERE frameworkcode > ''
+ |);
+ for my $frameworkcode (@frameworkcodes) {
+ Koha::Caches->get_instance->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
+ }
+ Koha::Caches->get_instance->clear_from_cache("default_value_for_mod_marc-");
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19096 - Make Default authoritative for Koha to MARC mappings)\n";
+}
+
+$DBversion = '17.12.00.003';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q|DROP TABLE IF EXISTS notifys|);
+
+ if( column_exists( 'accountlines', 'notify_id' ) ) {
+ $dbh->do(q|ALTER TABLE accountlines DROP COLUMN notify_id|);
+ $dbh->do(q|ALTER TABLE accountlines DROP COLUMN notify_level|);
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 10021 - Drop notifys-related table and columns)\n";
+}
+
+$DBversion = '17.12.00.004';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` )
+ VALUES
+ ('RESTdefaultPageSize','20','','Set the default number of results returned by the REST API endpoints','Integer')
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19278 - Add a configurable default page size for REST endpoints)\n";
+}
+
+$DBversion = '17.12.00.005';
+if( CheckVersion( $DBversion ) ) {
+ # For installations having the note already
+ $dbh->do(q{
+ UPDATE letter
+ SET code = 'CHECKOUT_NOTE',
+ name = 'Checkout note on item set by patron',
+ title = 'Checkout note',
+ content = REPLACE(content, "<<biblio.item>>", "<<biblio.title>>")
+ WHERE code = 'PATRON_NOTE'
+ });
+ # For installations coming from 17.11
+ $dbh->do(q{
+ INSERT IGNORE INTO `letter` (`module`, `code`, `branchcode`, `name`, `is_html`, `title`, `content`, `message_transport_type`)
+ VALUES ('circulation', 'CHECKOUT_NOTE', '', 'Checkout note on item set by patron', '0', 'Checkout note', '<<borrowers.firstname>> <<borrowers.surname>> has added a note to the item <<biblio.title>> - <<biblio.author>> (<<biblio.biblionumber>>).','email')
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 18915 - Correct CHECKOUT_NOTE notice template)\n";
+}
+
+$DBversion = '17.12.00.006';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ UPDATE systempreferences SET value=replace(value, "http://www.scholar", "https://scholar") WHERE variable='OPACSearchForTitleIn';
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 17682 - Update URL for Google Scholar in OPACSearchForTitleIn)\n";
+}
+
+$DBversion = '17.12.00.007';
+if( CheckVersion( $DBversion ) ) {
+
+ unless ( TableExists( 'library_groups' ) ) {
+ $dbh->do(q{
+ CREATE TABLE library_groups (
+ id INT(11) NOT NULL auto_increment, -- unique id for each group
+ parent_id INT(11) NULL DEFAULT NULL, -- if this is a child group, the id of the parent group
+ branchcode VARCHAR(10) NULL DEFAULT NULL, -- The branchcode of a branch belonging to the parent group
+ title VARCHAR(100) NULL DEFAULT NULL, -- Short description of the goup
+ description TEXT NULL DEFAULT NULL, -- Longer explanation of the group, if necessary
+ created_on TIMESTAMP NULL, -- Date and time of creation
+ updated_on TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, -- Date and time of last
+ PRIMARY KEY id ( id ),
+ FOREIGN KEY (parent_id) REFERENCES library_groups(id) ON UPDATE CASCADE ON DELETE CASCADE,
+ FOREIGN KEY (branchcode) REFERENCES branches(branchcode) ON UPDATE CASCADE ON DELETE CASCADE,
+ UNIQUE KEY title ( title )
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+ });
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 15707 - Add new table library_groups)\n";
+}
+
+$DBversion = '17.12.00.008';
+if ( CheckVersion($DBversion) ) {
+
+ if ( TableExists( 'branchcategories' ) and TableExists('branchrelations' )) {
+ $dbh->do(q{
+ INSERT INTO library_groups ( title, description, created_on ) VALUES ( '__SEARCH_GROUPS__', 'Library search groups', NOW() )
+ });
+ my $search_groups_root_id = $dbh->last_insert_id(undef, undef, 'library_groups', undef);
+
+ my $sth = $dbh->prepare("SELECT * FROM branchcategories");
+
+ my $sth2 = $dbh->prepare("INSERT INTO library_groups ( parent_id, title, description, created_on ) VALUES ( ?, ?, ?, NOW() )");
+
+ my $sth3 = $dbh->prepare("SELECT * FROM branchrelations WHERE categorycode = ?");
+
+ my $sth4 = $dbh->prepare("INSERT INTO library_groups ( parent_id, branchcode, created_on ) VALUES ( ?, ?, NOW() )");
+
+ $sth->execute();
+ while ( my $lc = $sth->fetchrow_hashref ) {
+ my $description = $lc->{categorycode};
+ $description .= " - " . $lc->{codedescription} if $lc->{codedescription};
+
+ $sth2->execute($search_groups_root_id, $lc->{categoryname}, $description);
+
+ my $subgroup_id = $dbh->last_insert_id(undef, undef, 'library_groups', undef);
+
+ $sth3->execute( $lc->{categorycode} );
+
+ while ( my $l = $sth3->fetchrow_hashref ) {
+ $sth4->execute( $subgroup_id, $l->{branchcode} );
+ }
+ }
+
+ $dbh->do("DROP TABLE branchrelations");
+ $dbh->do("DROP TABLE branchcategories");
+ }
+
+ print "Upgrade to $DBversion done (Bug 16735 - Migrate library search groups into the new hierarchical groups)\n";
+ SetVersion($DBversion);
+}
+
+$DBversion = '17.12.00.009';
+if ( CheckVersion($DBversion) ) {
+ $dbh->do(q|
+ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES
+ (4, 'edit_borrowers', 'Add, modify and view patron information'),
+ (4, 'view_borrower_infos_from_any_libraries', 'View patron infos from any libraries');
+ |);
+
+ # We are lucky here, there is nothing else to do: flags 4-borrowers did not contain sub permissions
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 18403 - Add the view_borrower_infos_from_any_libraries permission )\n";
+}
+
+$DBversion = '17.12.00.010';
+if( CheckVersion( $DBversion ) ) {
+
+ if( !column_exists( 'library_groups', 'ft_hide_patron_info' ) ) {
+ $dbh->do( "ALTER TABLE library_groups ADD COLUMN ft_hide_patron_info tinyint(1) NOT NULL DEFAULT 0 AFTER description" );
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20133 - Add library_groups.ft_hide_patron_info)\n";
+}
+
+$DBversion = '17.12.00.011';
+if( CheckVersion( $DBversion ) ) {
+
+ if( !column_exists( 'library_groups', 'ft_search_groups_opac' ) ) {
+ $dbh->do( "ALTER TABLE library_groups ADD COLUMN ft_search_groups_opac tinyint(1) NOT NULL DEFAULT 0 AFTER ft_hide_patron_info" );
+ $dbh->do( "ALTER TABLE library_groups ADD COLUMN ft_search_groups_staff tinyint(1) NOT NULL DEFAULT 0 AFTER ft_search_groups_opac" );
+ $dbh->do( "UPDATE library_groups SET ft_search_groups_staff = 1 AND ft_search_groups_opac = 1 WHERE title = '__SEARCH_GROUPS__'" );
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20157 - Use group 'features' to decide which groups to use for group searching functionality)\n";
+}
+
+$DBversion = '17.12.00.012';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do( q|
+ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+ VALUES ('AutoSwitchPatron', '0', '', 'Auto switch to patron', 'YesNo');
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 15752 - Add system preference AutoSwitchPatron)\n";
+}
+
+$DBversion = '17.12.00.013';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do(q|
+ ALTER TABLE club_enrollments MODIFY date_created timestamp NULL DEFAULT NULL;
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20175 - Set DEFAULT NULL value for club_enrollments.date_created)\n";
+}
+
+$DBversion = '17.12.00.014';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do( "UPDATE marc_subfield_structure SET kohafield=NULL where kohafield='additionalauthors.author'" );
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19790 - Remove additionalauthors.author from installer files)\n";
+}
+
+$DBversion = '17.12.00.015';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q|
+ ALTER TABLE borrowers
+ MODIFY surname MEDIUMTEXT,
+ MODIFY address MEDIUMTEXT,
+ MODIFY city MEDIUMTEXT
+ |);
+ $dbh->do(q|
+ ALTER TABLE deletedborrowers
+ MODIFY surname MEDIUMTEXT,
+ MODIFY address MEDIUMTEXT,
+ MODIFY city MEDIUMTEXT
+ |);
+
+ $dbh->do(q|
+ ALTER TABLE export_format
+ MODIFY csv_separator VARCHAR(2) NOT NULL DEFAULT ',',
+ MODIFY field_separator VARCHAR(2),
+ MODIFY subfield_separator VARCHAR(2)
+ |);
+ $dbh->do(q|
+ ALTER TABLE export_format MODIFY encoding VARCHAR(255) NOT NULL DEFAULT 'utf8'
+ |);
+
+ $dbh->do(q|
+ ALTER TABLE reserves MODIFY lowestPriority tinyint(1) NOT NULL DEFAULT 0
+ |);
+ $dbh->do(q|
+ ALTER TABLE old_reserves MODIFY lowestPriority tinyint(1) NOT NULL DEFAULT 0
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20144 - Adapt DB structure to work with new SQL modes)\n";
+}
+
+$DBversion = '17.12.00.016';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q|SET foreign_key_checks = 0|);
+ my $sth = $dbh->table_info( '','','','TABLE' );
+
+ while ( my ( $cat, $schema, $name, $type, $remarks ) = $sth->fetchrow_array ) {
+ my $table_sth = $dbh->prepare(qq|SHOW CREATE TABLE $name|);
+ $table_sth->execute;
+ my @table = $table_sth->fetchrow_array;
+ unless ( $table[1] =~ /COLLATE=utf8mb4_unicode_ci/ ) {
+ # Some users might have done the upgrade to utf8mb4 on their own
+ # to support supplemental chars (japanese, chinese, etc)
+ if ( $name eq 'additional_fields' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP KEY `fields_uniq`,
+ ADD UNIQUE KEY `fields_uniq` (`tablename` (191), `name` (191))
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'authorised_values' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP KEY `lib`,
+ ADD KEY `lib` (`lib` (191))
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'borrower_modifications' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP PRIMARY KEY,
+ DROP KEY `verification_token`,
+ ADD PRIMARY KEY (`verification_token` (191),`borrowernumber`),
+ ADD KEY `verification_token` (`verification_token` (191))
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'columns_settings' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP PRIMARY KEY,
+ ADD PRIMARY KEY (`module` (191), `page` (191), `tablename` (191), `columnname` (191))
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'illrequestattributes' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP PRIMARY KEY,
+ ADD PRIMARY KEY (`illrequest_id`, `type` (191))
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'items_search_fields' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP PRIMARY KEY,
+ ADD PRIMARY KEY (`name` (191))
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'marc_subfield_structure' ) {
+ # In this case we convert each column explicitly
+ # to preserve 'tagsubield' collation (utf8mb4_bin)
+ $dbh->do(qq|
+ ALTER TABLE $name
+ MODIFY COLUMN tagfield
+ VARCHAR(3) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
+ MODIFY COLUMN tagsubfield
+ VARCHAR(1) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
+ MODIFY COLUMN liblibrarian
+ VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
+ MODIFY COLUMN libopac
+ VARCHAR(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
+ MODIFY COLUMN kohafield
+ VARCHAR(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+ MODIFY COLUMN authorised_value
+ VARCHAR(32) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+ MODIFY COLUMN authtypecode
+ VARCHAR(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+ MODIFY COLUMN value_builder
+ VARCHAR(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+ MODIFY COLUMN frameworkcode
+ VARCHAR(4) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
+ MODIFY COLUMN seealso
+ VARCHAR(1100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+ MODIFY COLUMN link
+ VARCHAR(80) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
+ MODIFY COLUMN defaultvalue
+ MEDIUMTEXT COLLATE utf8mb4_unicode_ci default NULL
+ |);
+ $dbh->do(qq|ALTER TABLE $name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'plugin_data' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP PRIMARY KEY,
+ ADD PRIMARY KEY (`plugin_class` (191), `plugin_key` (191))
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'search_field' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP KEY `name`,
+ ADD UNIQUE KEY `name` (`name` (191))
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'search_marc_map' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP KEY `index_name`,
+ ADD UNIQUE KEY `index_name` (`index_name`, `marc_field` (191), `marc_type`)
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'sms_providers' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP KEY `name`,
+ ADD UNIQUE KEY `name` (`name` (191))
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'tags' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ DROP PRIMARY KEY,
+ ADD PRIMARY KEY (`entry` (191))
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'tags_approval' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ MODIFY COLUMN `term` VARCHAR(191) NOT NULL
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ elsif ( $name eq 'tags_index' ) {
+ $dbh->do(qq|
+ ALTER TABLE $name
+ MODIFY COLUMN `term` VARCHAR(191) NOT NULL
+ |);
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ else {
+ $dbh->do(qq|ALTER TABLE $name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci|);
+ }
+ }
+ }
+ $dbh->do(q|SET foreign_key_checks = 1|);
+
+ print "Upgrade to $DBversion done (Bug 18336 - Convert DB tables to utf8mb4 🎁)\n";
+ SetVersion($DBversion);
+}
+
+
+$DBversion = '17.12.00.017';
+if( CheckVersion( $DBversion ) ) {
+
+ if( !column_exists( 'items', 'damaged_on' ) ) {
+ $dbh->do( "ALTER TABLE items ADD COLUMN damaged_on DATETIME NULL AFTER damaged");
+ }
+ if( !column_exists( 'deleteditems', 'damaged_on' ) ) {
+ $dbh->do( "ALTER TABLE deleteditems ADD COLUMN damaged_on DATETIME NULL AFTER damaged");
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 17672 - Add damaged_on to items and deleteditems tables)\n";
+}
+
+$DBversion = '17.12.00.018';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do( q|
+ INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('BrowseResultSelection','0',NULL,'Enable/Disable browsing search results fromt the bibliographic record detail page in staff client','YesNo')
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19290 - Add system preference BrowseResultSelection)\n";
+}
+
+$DBversion = '17.12.00.019';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do(q|UPDATE auth_subfield_structure SET hidden=1 WHERE hidden<>0|);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20074 - Auth_subfield_structure changes hidden attribute)\n";
+}
+
+$DBversion = '17.12.00.020';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do(q|
+ INSERT IGNORE INTO language_descriptions(subtag, type, lang, description)
+ VALUES ('vi', 'language', 'de', 'Vietnamesisch')
+ |);
+
+ $dbh->do(q|
+ UPDATE language_descriptions SET description = 'Tiếng Việt'
+ WHERE subtag = 'vi' and type = 'language' and lang = 'vi'
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20082 - Update descriptions of Vietnamese language)\n";
+}
+
+$DBversion = '17.12.00.021';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do(q|
+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+ ('PurgeSuggestionsOlderThan', '', NULL, 'Default value for cronjob purge_suggestions.pl', 'Integer');
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 13287 - Add system preference PurgeSuggestionsOlderThan)\n";
+}
+
+$DBversion = '17.12.00.022';
+if( CheckVersion( $DBversion ) ) {
+
+ if( !column_exists( 'currency', 'p_sep_by_space' ) ) {
+ $dbh->do(q|
+ ALTER TABLE currency ADD COLUMN p_sep_by_space tinyint(1) default 0 after archived
+ |);
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 4078 - Add column currency.p_sep_by_space)\n";
+}
+
+$DBversion = '17.12.00.023';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{
+ DELETE FROM systempreferences
+ WHERE variable='checkdigit'
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20264 - Remove system preference 'checkdigit')\n";
+}
+
+$DBversion = '17.12.00.024';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+ VALUES ('SelfCheckInMainUserBlock', '', '70|10', 'Add a block of HTML that will display on the self check-in screen.', 'Textarea');
+ });
+
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+ VALUES ('SelfCheckInModule', 0, NULL, 'Enable the standalone self-checkin module.', 'YesNo');
+ });
+
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+ VALUES ('SelfCheckInModuleUserID', NULL, NULL, 'Patron ID (borrowernumber) to be allowed on the self-checkin module.', 'Integer');
+ });
+
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+ VALUES ('SelfCheckInTimeout', 120, NULL, 'Define the number of seconds before the self check-in module times out.', 'Integer');
+ });
+
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+ VALUES ('SelfCheckInUserCSS', '', NULL, 'Add CSS to be included in the self check-in module in an embedded <style> tag.', 'free');
+ });
+
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+ VALUES ('SelfCheckInUserJS', '', NULL, 'Define custom javascript for inclusion in the self check-in module.', 'free');
+ });
+
+ # Add new userflag for self check
+ $dbh->do(q{
+ INSERT IGNORE INTO userflags (bit,flag,flagdesc,defaulton) VALUES
+ (23,'self_check','Self check modules',0);
+ });
+
+ # Add self check-in module subpermission
+ $dbh->do(q{
+ INSERT IGNORE INTO permissions (module_bit,code,description)
+ VALUES (23, 'self_checkin_module', 'Log into the self check-in module');
+ });
+
+ # Add self check-in module subpermission
+ $dbh->do(q{
+ INSERT IGNORE INTO permissions (module_bit,code,description)
+ VALUES (23, 'self_checkout_module', 'Perform self checkout at the OPAC. It should be used for the patron matching the AutoSelfCheckID');
+ });
+
+ # Update patrons with self_checkout permission
+ # IMPORTANT: Needs to happen before removing the old subpermission
+ $dbh->do(q{
+ UPDATE user_permissions
+ SET module_bit = 23,
+ code = 'self_checkout_module'
+ WHERE module_bit = 1 AND code = 'self_checkout';
+ });
+
+ # Remove old self_checkout permission
+ $dbh->do(q{
+ DELETE IGNORE FROM permissions
+ WHERE code='self_checkout';
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 15492 - Add a standalone self-checkin module)\n";
+}
+
+$DBversion = '17.12.00.025';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q|
+ INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
+ VALUES ('StaffLoginInstructions','','HTML to go into the login box for the staff client',NULL,'Free')
+ |);
+ $dbh->do(q|
+ UPDATE systempreferences
+ SET variable = 'OpacLoginInstructions'
+ WHERE variable = 'NoLoginInstructions'
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20291 - Add StaffLoginInstructions system preference and rename NoLoginInstructions with OpacLoginInstructions)\n";
+}
+
+$DBversion = '17.12.00.026';
+if( CheckVersion( $DBversion ) ) {
+ if( !column_exists( 'issuingrules', 'suspension_chargeperiod' ) ) {
+ $dbh->do(q|
+ ALTER TABLE issuingrules ADD COLUMN suspension_chargeperiod int(11) DEFAULT '1' AFTER maxsuspensiondays;
+ |);
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19804 - Add issuingrules.suspension_chargeperiod)\n";
+}
+
+$DBversion = '17.12.00.027';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q|
+ INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`)
+ VALUES ('UseACQFrameworkForBiblioRecords','0','','Use the ACQ framework for the catalog details','YesNo')
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19289 - Add system preference UseACQFrameworkForBiblioRecords)\n";
+}
+
+$DBversion = '17.12.00.028';
+if( CheckVersion( $DBversion ) ) {
+ if( !column_exists( 'marc_tag_structure', 'ind1_defaultvalue' ) ) {
+ $dbh->do(q|
+ ALTER TABLE marc_tag_structure
+ ADD COLUMN ind2_defaultvalue VARCHAR(1) NOT NULL DEFAULT '' AFTER authorised_value,
+ ADD COLUMN ind1_defaultvalue VARCHAR(1) NOT NULL DEFAULT '' AFTER authorised_value;
+ |);
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 9701 - Add default indicators (marc_tag_structure.indX_defaultvalue))\n";
+}
+
+$DBversion = '17.12.00.029';
+if( CheckVersion( $DBversion ) ) {
+ my $pref =
+q|# PERSO_NAME 100 600 696 700 796 800 896
+marc21, 100, ind1:auth1
+marc21, 600, ind1:auth1, ind2:thesaurus
+marc21, 696, ind1:auth1
+marc21, 700, ind1:auth1
+marc21, 796, ind1:auth1
+marc21, 800, ind1:auth1
+marc21, 896, ind1:auth1
+# CORPO_NAME 110 610 697 710 797 810 897
+marc21, 110, ind1:auth1
+marc21, 610, ind1:auth1, ind2:thesaurus
+marc21, 697, ind1:auth1
+marc21, 710, ind1:auth1
+marc21, 797, ind1:auth1
+marc21, 810, ind1:auth1
+marc21, 897, ind1:auth1
+# MEETI_NAME 111 611 698 711 798 811 898
+marc21, 111, ind1:auth1
+marc21, 611, ind1:auth1, ind2:thesaurus
+marc21, 698, ind1:auth1
+marc21, 711, ind1:auth1
+marc21, 798, ind1:auth1
+marc21, 811, ind1:auth1
+marc21, 898, ind1:auth1
+# UNIF_TITLE 130 440 630 699 730 799 830 899 / 240
+marc21, 130, ind1:auth2
+marc21, 240, , ind2:auth2
+marc21, 440, , ind2:auth2
+marc21, 630, ind1:auth2, ind2:thesaurus
+marc21, 699, ind1:auth2
+marc21, 730, ind1:auth2
+marc21, 799, ind1:auth2
+marc21, 830, , ind2:auth2
+marc21, 899, ind1:auth2
+# CHRON_TERM 648
+marc21, 648, , ind2:thesaurus
+# TOPIC_TERM 650 654 656 657 658 690
+marc21, 650, , ind2:thesaurus
+# GEOGR_NAME 651 662 691 / 751
+marc21, 651, , ind2:thesaurus
+# GENRE/FORM 655
+marc21, 655, , ind2:thesaurus
+
+# UNIMARC: Always copy the indicators from the authority
+unimarc, *, ind1:auth1, ind2:auth2|;
+
+ $dbh->do( q|
+ INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
+ VALUES ( 'AuthorityControlledIndicators', ?, 'Authority controlled indicators per biblio field', NULL, 'Free' );
+ |, undef, $pref );
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 14769 - Authorities merge: Set correct indicators in biblio field (new system preference AuthorityControlledIndicators))\n";
+}
+
+$DBversion = '17.12.00.030';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q|
+ INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
+ VALUES ('NovelistSelectStaffProfile',NULL,'Novelist staff client user Profile',NULL,'free')
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19882 - Add system preference NovelistSelectStaffProfile)\n";
+}
+
+$DBversion = '17.12.00.031';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q|
+ INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`)
+ VALUES ('MarcFieldDocURL', NULL, NULL, 'URL used for MARC field documentation. Following substitutions are available: {MARC} = marc flavour, eg. \"MARC21\" or \"UNIMARC\". {FIELD} = field number, eg. \"000\" or \"048\". {LANG} = user language, eg. \"en\" or \"fi-FI\"', 'free')
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 11674 - Add system preference MarcFieldDocURL)\n";
+}
+
+$DBversion = '17.12.00.032';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q|
+ UPDATE letter SET code = "SERIAL_ALERT" WHERE code = "RLIST";
+ |);
+ $dbh->do(q|
+ UPDATE letter SET name = "New serial issue" WHERE name = "Routing List";
+ |);
+ $dbh->do(q|
+ UPDATE subscription SET letter = "SERIAL_ALERT" WHERE letter = "RLIST";
+ |);
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19794 - Rename RLIST notice to SERIAL_ALERT)\n";
+}
+
+$DBversion = '17.12.00.033';
+if( CheckVersion( $DBversion ) ) {
+ if ( !column_exists( 'accountlines', 'payment_type' ) ) {
+ $dbh->do(q{
+ ALTER TABLE accountlines ADD payment_type varchar(80) default NULL AFTER accounttype
+ });
+ }
+
+ $dbh->do(q{
+ INSERT IGNORE INTO authorised_value_categories( category_name ) VALUES ('PAYMENT_TYPE')
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 18786 - Add ability to create custom payment types)\n";
+}
+
+$DBversion = '17.12.00.034';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do( q{
+ INSERT IGNORE INTO account_offset_types ( type ) VALUES ('Void Payment')
+ } );
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 18790 - Add ability to void payment)\n";
+}
+
+$DBversion = '17.12.00.035';
+if( CheckVersion( $DBversion ) ) {
+ my ( $original_value ) = $dbh->selectrow_array(q|
+ SELECT value FROM systempreferences WHERE variable="MarkLostItemsAsReturned"
+ |);
+ if ( $original_value and $original_value eq '1' ) {
+ $dbh->do(q{
+ UPDATE systempreferences
+ SET type="multiple",
+ options="batchmod|moredetail|cronjob|additem",
+ value="batchmod,moredetail,cronjob,additem"
+ WHERE variable="MarkLostItemsAsReturned"
+ });
+ } else {
+ $dbh->do(q{
+ UPDATE systempreferences
+ SET type="multiple",
+ options="batchmod|moredetail|cronjob|additem",
+ value=""
+ WHERE variable="MarkLostItemsAsReturned"
+ });
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19974 - Make MarkLostItemsAsReturned multiple)\n";
+}
+
+$DBversion = '17.12.00.036';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do( q{
+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('CanMarkHoldsToPullAsLost','do_not_allow','do_not_allow|allow|allow_and_notify','Add a button to the "Holds to pull" screen to mark an item as lost and notify the patron.','Choice');
+ } );
+ $dbh->do( q{
+ INSERT IGNORE INTO letter(module, code, branchcode, name, is_html, title, content, message_transport_type, lang) VALUES ('reserves', 'CANCEL_HOLD_ON_LOST', '', 'Hold has been cancelled', 0, "Hold has been cancelled", "Dear [% borrower.firstname %] [% borrower.surname %],\n\nWe regret to inform you, that the following item can not be provided due to it being missing. Your hold was cancelled.\n\nTitle: [% biblio.title %]\nAuthor: [% biblio.author %]\nCopy: [% item.copynumber %]\nLocation: [% branch.branchname %]", 'email', 'default');
+ } );
+ $dbh->do( q{
+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES ('UpdateItemWhenLostFromHoldList','',NULL,'This is a list of values to update an item when it is marked as lost from the holds to pull screen','Free');
+ } );
+ $dbh->do( q{
+ UPDATE systempreferences SET options="batchmod|moredetail|cronjob|additem|pendingreserves", value="batchmod|moredetail|cronjob|additem|pendingreserves" WHERE variable="MarkLostItemsAsReturned";
+ } );
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 19287 - Add ability to mark an item 'Lost' from 'Holds to pull' list (CanMarkHoldsToPullAsLost, UpdateItemWhenLostFromHoldList and CANCEL_HOLD_ON_LOST))\n";
+}
+
+$DBversion = '17.12.00.037';
+if( CheckVersion( $DBversion ) ) {
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (This change has been reverted, nothing done!)\n";
+}
+
+$DBversion = '17.12.00.038';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do( q{
+ UPDATE language_rfc4646_to_iso639 SET iso639_2_code = 'slo' WHERE iso639_2_code = 'slk' AND rfc4646_subtag = 'sk';
+ } );
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20245 - Use Bibliographic code value for Slovak language)\n";
+}
+
+$DBversion = '17.12.00.039';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do( q{
+ UPDATE language_rfc4646_to_iso639 SET iso639_2_code = 'baq' WHERE iso639_2_code = 'eus' AND rfc4646_subtag = 'eu';
+ } );
+ $dbh->do( q{
+ UPDATE language_rfc4646_to_iso639 SET iso639_2_code = 'mao' WHERE iso639_2_code = 'mri' AND rfc4646_subtag = 'mi';
+ } );
+ $dbh->do( q{
+ UPDATE language_rfc4646_to_iso639 SET iso639_2_code = 'alb' WHERE iso639_2_code = 'sqi' AND rfc4646_subtag = 'sq';
+ } );
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20482 - Use Bibliographic code value for Basque, Maori and Albanian languages)\n";
+}
+
+$DBversion = '17.12.00.040';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do( q{
+ INSERT IGNORE INTO systempreferences ( value, variable, options, explanation, type )
+ VALUES ( '0', 'ProtectSuperlibrarianPrivileges', NULL, 'If enabled, non-superlibrarians cannot set superlibrarian privileges', 'YesNo' )
+ } );
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20100 - Add new system preference ProtectSuperlibrarianPrivileges)\n";
+}
+
+$DBversion = '17.12.00.041';
+if( CheckVersion( $DBversion ) ) {
+
+ $dbh->do( q{
+ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES (13, 'access_files', 'Access to the files stored on the server');
+ } );
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 11317 - Add a new permission to access files stored on the server)\n";
+}
+
+$DBversion = '17.12.00.042';
+if( CheckVersion( $DBversion ) ) {
+
+ if (!TableExists('oauth_access_tokens')) {
+ $dbh->do(q{
+ CREATE TABLE oauth_access_tokens (
+ `access_token` VARCHAR(191) NOT NULL,
+ `client_id` VARCHAR(191) NOT NULL,
+ `expires` INT NOT NULL,
+ PRIMARY KEY (`access_token`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
+ });
+ }
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20402 - Implement OAuth2 authentication for REST API)\n";
+}
+
+$DBversion = '17.12.00.043';
+if(CheckVersion($DBversion)) {
+
+ if (!TableExists('api_keys')) {
+ $dbh->do(q{
+ CREATE TABLE `api_keys` (
+ `client_id` VARCHAR(191) NOT NULL,
+ `secret` VARCHAR(191) NOT NULL,
+ `description` VARCHAR(255) NOT NULL,
+ `patron_id` INT(11) NOT NULL,
+ `active` TINYINT(1) DEFAULT 1 NOT NULL,
+ PRIMARY KEY `client_id` (`client_id`),
+ UNIQUE KEY `secret` (`secret`),
+ KEY `patron_id` (`patron_id`),
+ CONSTRAINT `api_keys_fk_patron_id`
+ FOREIGN KEY (`patron_id`)
+ REFERENCES `borrowers` (`borrowernumber`)
+ ON DELETE CASCADE ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+ });
+ }
+
+ print "Upgrade to $DBversion done (Bug 20568 - Add API key management interface for patrons)\n";
+ SetVersion($DBversion);
+}
+
+$DBversion = '17.12.00.044';
+if(CheckVersion($DBversion)) {
+
+ $dbh->do(q{
+ INSERT IGNORE INTO systempreferences (`variable`,`value`,`options`,`explanation`,`type`)
+ VALUES
+ ('RESTOAuth2ClientCredentials','0',NULL,'If enabled, the OAuth2 client credentials flow is enabled for the REST API.','YesNo');
+ });
+
+ print "Upgrade to $DBversion done (Bug 20624 - Disable OAuth2 client credentials grant by default)\n";
+ SetVersion($DBversion);
+}
+
+$DBversion = '18.05.00.000';
+if( CheckVersion( $DBversion ) ) {
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Koha 18.05)\n";
+}
+
+$DBversion = '18.06.00.000';
+if( CheckVersion( $DBversion ) ) {
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Koha 18.06 - It's Adventure time!)\n";
+}
+
+$DBversion = '18.06.00.001';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{UPDATE permissions SET description = 'Manage budgets' WHERE code = 'period_manage';});
+ $dbh->do(q{UPDATE permissions SET description = 'Manage funds' WHERE code = 'budget_manage';});
+ $dbh->do(q{UPDATE permissions SET description = 'Modify funds (can''t create lines, but can modify existing ones)' WHERE code = 'budget_modify';});
+ $dbh->do(q{UPDATE permissions SET description = 'Manage baskets and order lines' WHERE code = 'order_manage';});
+ $dbh->do(q{UPDATE permissions SET description = 'Manage all baskets and order lines, regardless of restrictions on them' WHERE code = 'order_manage_all';});
+ $dbh->do(q{UPDATE permissions SET description = 'Manage basket groups' WHERE code = 'group_manage';});
+ $dbh->do(q{UPDATE permissions SET description = 'Receive orders and manage shipments' WHERE code = 'order_receive';});
+ $dbh->do(q{UPDATE permissions SET description = 'Add and delete funds (but can''t modify funds)' WHERE code = 'budget_add_del';});
+ $dbh->do(q{UPDATE permissions SET description = 'Manage all funds' WHERE code = 'budget_manage_all';});
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 3849- Improve descriptions of granular acquisition permissions)\n";
+}
+
+$DBversion = '18.06.00.002';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do(q{DELETE FROM userflags WHERE bit = 12 AND flag = 'management';});
+ $dbh->do(q{UPDATE borrowers SET flags = flags - ( flags & (1<<12) ) WHERE flags & (1 << 12);});
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 2426 - Remove deprecated management permission)\n";
+}
+
+$DBversion = '18.06.00.003';
+if( CheckVersion( $DBversion ) ) {
+ $dbh->do( "ALTER TABLE search_field CHANGE COLUMN type type ENUM('', 'string', 'date', 'number', 'boolean', 'sum', 'isbn', 'stdno') NOT NULL COMMENT 'what type of data this holds, relevant when storing it in the search engine'" );
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20073 - Add new types for Elasticsearch fields)\n";
+}
+
+$DBversion = '18.06.00.004';
+if( CheckVersion( $DBversion ) ) {
+
+ # Add 'Manual Credit' offset type
+ $dbh->do(q{
+ INSERT IGNORE INTO `account_offset_types` (`type`) VALUES ('Manual Credit');
+ });
+
+ # Fix wrong account offsets / Manual credits
+ $dbh->do(q{
+ UPDATE account_offsets
+ SET credit_id=debit_id,
+ debit_id=NULL,
+ type='Manual Credit'
+ WHERE amount < 0 AND
+ type='Manual Debit' AND
+ debit_id IN
+ (SELECT accountlines_id AS debit_id
+ FROM accountlines
+ WHERE accounttype='C');
+ });
+
+ # Fix wrong account offsets / Manually forgiven amounts
+ $dbh->do(q{
+ UPDATE account_offsets
+ SET credit_id=debit_id,
+ debit_id=NULL,
+ type='Writeoff'
+ WHERE amount < 0 AND
+ type='Manual Debit' AND
+ debit_id IN
+ (SELECT accountlines_id AS debit_id
+ FROM accountlines
+ WHERE accounttype='FOR');
+ });
+
+ SetVersion( $DBversion );
+ print "Upgrade to $DBversion done (Bug 20980 - Manual credit offsets are stored as debits)\n";
+}
+
# SEE bug 13068
# if there is anything in the atomicupdate, read and execute it.