Bug 15752: DBRev 17.12.00.012
[koha.git] / installer / data / mysql / updatedatabase.pl
index 8da386d..b36d0d5 100755 (executable)
@@ -13868,16 +13868,12 @@ if( CheckVersion( $DBversion ) ) {
         $dbh->do(q|ALTER TABLE opac_news CHANGE COLUMN new content text NOT NULL|);
     }
 
-    my ( $used_in_templates ) = $dbh->selectrow_array(q|
-        SELECT COUNT(*) FROM letter WHERE content LIKE "%<<opac_news.new>>%";
+    $dbh->do(q|
+        UPDATE letter SET content = REPLACE(content, "<<opac_news.new>>", "<<opac_news.content>>") WHERE content LIKE "%<<opac_news.new>>%"
     |);
-    if ( $used_in_templates ) {
-        print "WARNING - It seems that you are using the opac_news.new column in your notice templates\n";
-        print "Since it has now been renamed with opac_news.content, you should update them.\n";
-    }
 
     SetVersion( $DBversion );
-    print "Upgrade to $DBversion done (Bug 17960 - Rename opac_news with opac_news.content)\n";
+    print "Upgrade to $DBversion done (Bug 17960 - Rename opac_news with opac_news.content (template notices have been updated!))\n";
 }
 
 $DBversion = "16.12.00.008";
@@ -13991,6 +13987,1355 @@ if( CheckVersion( $DBversion ) ) {
     print "Upgrade to $DBversion done (Bug 18066 - Hea version 2)\n";
 }
 
+$DBversion = "16.12.00.016";
+if ( CheckVersion($DBversion) ) {
+    unless ( column_exists( 'borrower_attribute_types', 'opac_editable' ) )
+    {
+        $dbh->do(q{
+            ALTER TABLE borrower_attribute_types
+                ADD COLUMN `opac_editable` tinyint(1) NOT NULL default 0 AFTER `opac_display`
+        });
+    }
+
+    print "Upgrade to $DBversion done (Bug 13757: Make patron attributes editable in the opac if set to 'editable in OPAC)'\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "16.12.00.017";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+        VALUES ('CumulativeRestrictionPeriods',  0,  NULL,  'Cumulate the restriction periods instead of keeping the highest',  'YesNo')
+    });
+
+    print "Upgrade to $DBversion done (Bug 14146 - Additional days are not added to restriction period when checking-in several overdues for same patron)'\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "16.12.00.018";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( variable, value, options, explanation, type )
+            SELECT 'ExportCircHistory', COUNT(*), NULL, "Display the export circulation options",  'YesNo'
+            FROM systempreferences
+            WHERE ( variable = 'ExportRemoveFields' AND value != "" AND value IS NOT NULL )
+                OR ( variable = 'ExportWithCsvProfile' AND value != "" AND value IS NOT NULL );
+    });
+
+    $dbh->do(q{
+        DELETE FROM systempreferences WHERE variable="ExportWithCsvProfile";
+    });
+
+    print "Upgrade to $DBversion done (Bug 15498 - Replace ExportWithCsvProfile with ExportCircHistory)'\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "16.12.00.019";
+if( CheckVersion( $DBversion ) ) {
+    if ( column_exists( 'issues', 'return' ) ) {
+        $dbh->do(q|ALTER TABLE issues DROP column `return`|);
+    }
+
+    if ( column_exists( 'old_issues', 'return' ) ) {
+        $dbh->do(q|ALTER TABLE old_issues DROP column `return`|);
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 18173 - Remove issues.return DB field)\n";
+}
+
+$DBversion = "16.12.00.020";
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        UPDATE systempreferences SET options="any_time_is_placed|not_always|any_time_is_collected" WHERE variable="HoldFeeMode";
+    });
+
+    $dbh->do(q{
+        UPDATE systempreferences SET value="any_time_is_placed" WHERE variable="HoldFeeMode" AND value="always";
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 17560 - Hold fee placement at point of checkout)\n";
+}
+
+$DBversion = "16.12.00.021";
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+        ('RenewalLog','0','','If ON, log information about renewals','YesNo');
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 17708 - Renewal log seems empty)\n";
+}
+
+$DBversion = "16.12.00.022";
+if( CheckVersion( $DBversion ) ) {
+    print "NOTE: The sender for claim notifications has been corrected. The email address of the staff member is no longer used. We will use the branch email address or KohaAdminEmailAddress, as is done for other notices.\n";
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 17866 - Change sender for serial claim notifications)\n";
+}
+
+$DBversion = '16.12.00.023';
+if( CheckVersion( $DBversion ) ) {
+    my $oldval = C4::Context->preference('dontmerge');
+    my $newval = $oldval ? 0 : 50;
+
+    # Remove dontmerge, add AuthorityMergeLimit
+    $dbh->do(q{
+        DELETE FROM systempreferences WHERE variable = 'dontmerge';
+    });
+    $dbh->do(qq{
+        INSERT IGNORE INTO systempreferences ( variable, value, options, explanation, type ) VALUES ('AuthorityMergeLimit','$newval',NULL,'Maximum number of biblio records updated immediately when an authority record has been modified.','integer');
+    });
+
+    $dbh->do(q{
+        ALTER TABLE need_merge_authorities
+            ADD COLUMN authid_new BIGINT AFTER authid,
+            ADD COLUMN reportxml text AFTER authid_new,
+            ADD COLUMN timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
+    });
+
+    $dbh->do(q{
+        UPDATE need_merge_authorities SET authid_new=authid WHERE done <> 1
+    });
+
+    SetVersion( $DBversion );
+    if( $newval == 0 ) {
+        print "NOTE: Since dontmerge was enabled, we have initialized AuthorityMergeLimit to 0 records. Please consider raising this value. This will allow for performing smaller merges directly and only postponing larger merges.\n";
+    }
+    print "IMPORTANT NOTE: If you are not using a Debian package install, please verify that you no longer use misc/migration_tools/merge_authority.pl in your cron files AND add misc/cronjobs/merge_authorities.pl to cron now. This job is no longer optional! You need it to perform larger authority merges.\n";
+    print "Upgrade to $DBversion done (Bug 9988 - Add AuthorityMergeLimit)\n";
+}
+
+$DBversion = '16.12.00.024';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        UPDATE systempreferences SET variable="NoticeBcc" WHERE variable="OverdueNoticeBcc";
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 14537 - The system preference 'OverdueNoticeBcc' is mis-named.)\n";
+}
+
+$DBversion = '16.12.00.025';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q|
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` )
+        VALUES ('UploadPurgeTemporaryFilesDays','',NULL,'If not empty, number of days used when automatically deleting temporary uploads','integer');
+    |);
+
+    my ( $cnt ) = $dbh->selectrow_array( "SELECT COUNT(*) FROM uploaded_files WHERE permanent IS NULL or permanent=0" );
+    if( $cnt ) {
+        print "NOTE: You have $cnt temporary uploads. You could benefit from setting pref UploadPurgeTemporaryFilesDays now to automatically delete them.\n";
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 17669 - Introduce preference for deleting temporary uploads)\n";
+}
+
+$DBversion = '16.12.00.026';
+if( CheckVersion( $DBversion ) ) {
+
+    # In order to be overcomplete, we check if the situation is what we expect
+    if( !index_exists( 'serialitems', 'PRIMARY' ) ) {
+        if( index_exists( 'serialitems', 'serialitemsidx' ) ) {
+            $dbh->do(q|
+                ALTER TABLE serialitems ADD PRIMARY KEY (itemnumber), DROP INDEX serialitemsidx;
+            |);
+        } else {
+            $dbh->do(q|ALTER TABLE serialitems ADD PRIMARY KEY (itemnumber)|);
+        }
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 18427 - Add a primary key to serialitems)\n";
+}
+
+$DBversion = '16.12.00.027';
+if( CheckVersion( $DBversion ) ) {
+
+    $dbh->do(q{
+        CREATE TABLE IF NOT EXISTS club_templates (
+          id int(11) NOT NULL AUTO_INCREMENT,
+          `name` tinytext NOT NULL,
+          description text,
+          is_enrollable_from_opac tinyint(1) NOT NULL DEFAULT '0',
+          is_email_required tinyint(1) NOT NULL DEFAULT '0',
+          branchcode varchar(10) NULL DEFAULT NULL,
+          date_created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+          date_updated timestamp NULL DEFAULT NULL,
+          is_deletable tinyint(1) NOT NULL DEFAULT '1',
+          PRIMARY KEY (id),
+          KEY ct_branchcode (branchcode),
+          CONSTRAINT `club_templates_ibfk_1` FOREIGN KEY (branchcode) REFERENCES `branches` (branchcode) ON DELETE CASCADE ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+    });
+
+    $dbh->do(q{
+        CREATE TABLE IF NOT EXISTS clubs (
+          id int(11) NOT NULL AUTO_INCREMENT,
+          club_template_id int(11) NOT NULL,
+          `name` tinytext NOT NULL,
+          description text,
+          date_start date DEFAULT NULL,
+          date_end date DEFAULT NULL,
+          branchcode varchar(10) NULL DEFAULT NULL,
+          date_created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+          date_updated timestamp NULL DEFAULT NULL,
+          PRIMARY KEY (id),
+          KEY club_template_id (club_template_id),
+          KEY branchcode (branchcode),
+          CONSTRAINT clubs_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE,
+          CONSTRAINT clubs_ibfk_2 FOREIGN KEY (branchcode) REFERENCES branches (branchcode)
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+    });
+
+    $dbh->do(q{
+        CREATE TABLE IF NOT EXISTS club_enrollments (
+          id int(11) NOT NULL AUTO_INCREMENT,
+          club_id int(11) NOT NULL,
+          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_updated timestamp NULL DEFAULT NULL,
+          branchcode varchar(10) NULL DEFAULT NULL,
+          PRIMARY KEY (id),
+          KEY club_id (club_id),
+          KEY borrowernumber (borrowernumber),
+          KEY branchcode (branchcode),
+          CONSTRAINT club_enrollments_ibfk_1 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE,
+          CONSTRAINT club_enrollments_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE,
+          CONSTRAINT club_enrollments_ibfk_3 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE SET NULL ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+    });
+
+    $dbh->do(q{
+        CREATE TABLE IF NOT EXISTS club_template_enrollment_fields (
+          id int(11) NOT NULL AUTO_INCREMENT,
+          club_template_id int(11) NOT NULL,
+          `name` tinytext NOT NULL,
+          description text,
+          authorised_value_category varchar(16) DEFAULT NULL,
+          PRIMARY KEY (id),
+          KEY club_template_id (club_template_id),
+          CONSTRAINT club_template_enrollment_fields_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+    });
+
+    $dbh->do(q{
+        CREATE TABLE IF NOT EXISTS club_enrollment_fields (
+          id int(11) NOT NULL AUTO_INCREMENT,
+          club_enrollment_id int(11) NOT NULL,
+          club_template_enrollment_field_id int(11) NOT NULL,
+          `value` text NOT NULL,
+          PRIMARY KEY (id),
+          KEY club_enrollment_id (club_enrollment_id),
+          KEY club_template_enrollment_field_id (club_template_enrollment_field_id),
+          CONSTRAINT club_enrollment_fields_ibfk_1 FOREIGN KEY (club_enrollment_id) REFERENCES club_enrollments (id) ON DELETE CASCADE ON UPDATE CASCADE,
+          CONSTRAINT club_enrollment_fields_ibfk_2 FOREIGN KEY (club_template_enrollment_field_id) REFERENCES club_template_enrollment_fields (id) ON DELETE CASCADE ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+    });
+
+    $dbh->do(q{
+        CREATE TABLE IF NOT EXISTS club_template_fields (
+          id int(11) NOT NULL AUTO_INCREMENT,
+          club_template_id int(11) NOT NULL,
+          `name` tinytext NOT NULL,
+          description text,
+          authorised_value_category varchar(16) DEFAULT NULL,
+          PRIMARY KEY (id),
+          KEY club_template_id (club_template_id),
+          CONSTRAINT club_template_fields_ibfk_1 FOREIGN KEY (club_template_id) REFERENCES club_templates (id) ON DELETE CASCADE ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+    });
+
+    $dbh->do(q{
+        CREATE TABLE IF NOT EXISTS club_fields (
+          id int(11) NOT NULL AUTO_INCREMENT,
+          club_template_field_id int(11) NOT NULL,
+          club_id int(11) NOT NULL,
+          `value` text,
+          PRIMARY KEY (id),
+          KEY club_template_field_id (club_template_field_id),
+          KEY club_id (club_id),
+          CONSTRAINT club_fields_ibfk_3 FOREIGN KEY (club_template_field_id) REFERENCES club_template_fields (id) ON DELETE CASCADE ON UPDATE CASCADE,
+          CONSTRAINT club_fields_ibfk_4 FOREIGN KEY (club_id) REFERENCES clubs (id) ON DELETE CASCADE ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+    });
+
+    $dbh->do(q{
+        INSERT IGNORE INTO userflags (bit, flag, flagdesc, defaulton) VALUES (21, 'clubs', 'Patron clubs', '0');
+    });
+
+    $dbh->do(q{
+        INSERT IGNORE INTO permissions (module_bit, code, description) VALUES
+           (21, 'edit_templates', 'Create and update club templates'),
+           (21, 'edit_clubs', 'Create and update clubs'),
+           (21, 'enroll', 'Enroll patrons in clubs')
+        ;
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 12461 - Add patron clubs feature)\n";
+}
+
+$DBversion = '16.12.00.028';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        UPDATE systempreferences  SET options = 'us|de|fr' WHERE variable = 'AddressFormat';
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 18110 - Adds FR to the syspref AddressFormat)\n";
+}
+
+$DBversion = '16.12.00.029';
+if( CheckVersion( $DBversion ) ) {
+    unless( column_exists( 'issues', 'note' ) ) {
+        $dbh->do(q|ALTER TABLE issues ADD note mediumtext default NULL AFTER onsite_checkout|);
+    }
+    unless( column_exists( 'issues', 'notedate' ) ) {
+        $dbh->do(q|ALTER TABLE issues ADD notedate datetime default NULL AFTER note|);
+    }
+    unless( column_exists( 'old_issues', 'note' ) ) {
+        $dbh->do(q|ALTER TABLE old_issues ADD note mediumtext default NULL AFTER onsite_checkout|);
+    }
+    unless( column_exists( 'old_issues', 'notedate' ) ) {
+        $dbh->do(q|ALTER TABLE old_issues ADD notedate datetime default NULL AFTER note|);
+    }
+
+    $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');
+    |);
+
+    $dbh->do(q|
+        INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`,`type`)
+        VALUES ('AllowCheckoutNotes', '0', NULL, 'Allow patrons to submit notes about checked out items.','YesNo');
+    |);
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 14224: Add column issues.note and issues.notedate)\n";
+}
+
+$DBversion = '16.12.00.030';
+if( CheckVersion( $DBversion ) ) {
+    unless( column_exists( 'issuingrules', 'no_auto_renewal_after_hard_limit' ) ) {
+        $dbh->do(q{
+            ALTER TABLE issuingrules ADD COLUMN no_auto_renewal_after_hard_limit DATE DEFAULT NULL AFTER no_auto_renewal_after;
+        });
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 16344 - Add a circ rule to limit the auto renewals given a specific date)\n";
+}
+
+$DBversion = '16.12.00.031';
+if( CheckVersion( $DBversion ) ) {
+    if ( !index_exists( 'biblioitems', 'timestamp' ) ) {
+        $dbh->do("ALTER TABLE biblioitems ADD KEY `timestamp` (`timestamp`);");
+    }
+    if ( !index_exists( 'deletedbiblioitems', 'timestamp' ) ) {
+        $dbh->do("ALTER TABLE deletedbiblioitems ADD KEY `timestamp` (`timestamp`);");
+    }
+    if ( !index_exists( 'items', 'timestamp' ) ) {
+        $dbh->do("ALTER TABLE items ADD KEY `timestamp` (`timestamp`);");
+    }
+    if ( !index_exists( 'deleteditems', 'timestamp' ) ) {
+        $dbh->do("ALTER TABLE deleteditems ADD KEY `timestamp` (`timestamp`);");
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 15108: OAI-PMH provider improvements)\n";
+}
+
+$DBversion = '16.12.00.032';
+if( CheckVersion( $DBversion ) ) {
+    require Koha::Calendar;
+    require Koha::Holds;
+
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) 
+        VALUES ('ExcludeHolidaysFromMaxPickUpDelay', '0', 'If ON, reserves max pickup delay takes into account the closed days.', NULL, 'Integer');
+    });
+
+    my $waiting_holds = Koha::Holds->search({ found => 'W', priority => 0 });
+    my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
+    while ( my $hold = $waiting_holds->next ) {
+
+        my $requested_expiration;
+        if ($hold->expirationdate) {
+            $requested_expiration = dt_from_string($hold->expirationdate);
+        }
+
+        my $expirationdate = dt_from_string($hold->waitingdate);
+        if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) {
+            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;
+        $hold->expirationdate($cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd)->store;
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 12063 - Update reserves.expirationdate)\n";
+}
+
+$DBversion = '16.12.00.033';
+if( CheckVersion( $DBversion ) ) {
+
+    if( !column_exists( 'letter', 'lang' ) ) {
+        $dbh->do( "ALTER TABLE letter ADD COLUMN lang VARCHAR(25) NOT NULL DEFAULT 'default' AFTER message_transport_type" );
+    }
+
+    if( !column_exists( 'borrowers', 'lang' ) ) {
+        $dbh->do( "ALTER TABLE borrowers ADD COLUMN lang VARCHAR(25) NOT NULL DEFAULT 'default' AFTER lastseen" );
+        $dbh->do( "ALTER TABLE deletedborrowers ADD COLUMN lang VARCHAR(25) NOT NULL DEFAULT 'default' AFTER lastseen" );
+    }
+
+    # Add test on existene of this key
+    $dbh->do( "ALTER TABLE message_transports DROP FOREIGN KEY message_transports_ibfk_3 ");
+    $dbh->do( "ALTER TABLE letter DROP PRIMARY KEY ");
+    $dbh->do( "ALTER TABLE letter ADD PRIMARY KEY (`module`, `code`, `branchcode`, `message_transport_type`, `lang`) ");
+
+    $dbh->do( "INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
+        VALUES ('TranslateNotices',  '0',  NULL,  'Allow notices to be translated',  'YesNo') ");
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 17762 - Add columns letter.lang and borrowers.lang to allow translation of notices)\n";
+}
+
+$DBversion = '16.12.00.034';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` )
+        VALUES ('OPACFineNoRenewalsBlockAutoRenew','0','','Block/Allow auto renewals if the patron owe more than OPACFineNoRenewals','YesNo')
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 15582 - Ability to block auto renewals if the OPACFineNoRenewals amount is reached)\n";
+}
+
+$DBversion = '16.12.00.035';
+if( CheckVersion( $DBversion ) ) {
+    if( !column_exists( 'issues', 'auto_renew_error' ) ) {
+        $dbh->do(q{
+           ALTER TABLE issues ADD COLUMN auto_renew_error VARCHAR(32) DEFAULT NULL AFTER auto_renew;
+        });
+    }
+
+    if( !column_exists( 'old_issues', 'auto_renew_error' ) ) {
+        $dbh->do(q{
+            ALTER TABLE old_issues ADD COLUMN auto_renew_error VARCHAR(32) DEFAULT NULL AFTER auto_renew;
+        });
+    }
+
+    $dbh->do(q{
+        INSERT INTO letter (module, code, name, title, content, message_transport_type) VALUES ('circulation', 'AUTO_RENEWALS', 'notification on auto renewing', 'Auto renewals',
+"Dear [% borrower.firstname %] [% borrower.surname %],
+[% IF checkout.auto_renew_error %]
+The following item [% biblio.title %] has not been correctly renewed
+[% IF checkout.auto_renew_error == 'too_many' %]
+You have reach the maximum of checkouts possible.
+[% ELSIF checkout.auto_renew_error == 'on_reserve' %]
+This item is on hold for another patron.
+[% ELSIF checkout.auto_renew_error == 'restriction' %]
+You are currently restricted.
+[% ELSIF checkout.auto_renew_error == 'overdue' %]
+You have overdues.
+[% ELSIF checkout.auto_renew_error == 'auto_too_late' %]
+It\'s too late to renew this checkout.
+[% ELSIF checkout.auto_renew_error == 'auto_too_much_oweing' %]
+You have too much unpaid fines.
+[% END %]
+[% ELSE %]
+The following item [% biblio.title %] has correctly been renewed and is now due [% checkout.date_due %]
+[% END %]", 'email');
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 15705 - Notify the user on auto renewing)\n";
+}
+
+$DBversion = '16.12.00.036';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`)
+        VALUES ('NumSavedReports', '20', NULL, 'By default, show this number of saved reports.', 'Integer');
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 17465 - Add a System Preference to control number of Saved Reports displayed)\n";
+}
+
+$DBversion = '16.12.00.037';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( q|
+        INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`)
+        VALUES ('FailedLoginAttempts','','','Number of login attempts before lockout the patron account','Integer');
+    |);
+
+    unless( column_exists( 'borrowers', 'login_attempts' ) ) {
+        $dbh->do(q|
+            ALTER TABLE borrowers ADD COLUMN login_attempts INT(4) DEFAULT 0 AFTER lastseen
+        |);
+        $dbh->do(q|
+            ALTER TABLE deletedborrowers ADD COLUMN login_attempts INT(4) DEFAULT 0 AFTER lastseen
+        |);
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 18314 - Add FailedLoginAttempts and borrowers.login_attempts)\n";
+}
+
+$DBversion = '16.12.00.038';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+        ('ExportRemoveFields','',NULL,'List of fields for non export in circulation.pl (separated by a space)','Free');
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 18663 - Missing db update for ExportRemoveFields)\n";
+}
+
+$DBversion = '16.12.00.039';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+        ('TalkingTechItivaPhoneNotification','0',NULL,'If ON, enables Talking Tech I-tiva phone notifications','YesNo');
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 18600 - Missing db update for TalkingTechItivaPhoneNotification)\n";
+}
+
+$DBversion = '17.05.00.000';
+if( CheckVersion( $DBversion ) ) {
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Koha 17.05)\n";
+}
+
+$DBversion = '17.06.00.000';
+if( CheckVersion( $DBversion ) ) {
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (He pai ake te iti i te kore)\n";
+}
+
+$DBversion = '17.06.00.001';
+if( CheckVersion( $DBversion ) ) {
+
+    unless ( column_exists( 'export_format', 'used_for' ) ) {
+        $dbh->do(q|ALTER TABLE export_format ADD used_for varchar(255) DEFAULT 'export_records' AFTER type|);
+
+        $dbh->do(q|UPDATE export_format SET used_for = 'late_issues' WHERE type = 'sql'|);
+        $dbh->do(q|UPDATE export_format SET used_for = 'export_records' WHERE type = 'marc'|);
+    }
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 8612 - Add new column export_format.used_for)\n";
+}
+
+$DBversion = '17.06.00.002';
+if ( CheckVersion($DBversion) ) {
+
+    unless ( column_exists('virtualshelves', 'allow_change_from_owner' ) ) {
+        $dbh->do(q|
+            ALTER TABLE virtualshelves
+            ADD COLUMN allow_change_from_owner tinyint(1) default 1,
+            ADD COLUMN allow_change_from_others tinyint(1) default 0
+        |);
+
+        # Conversion:
+        # Since we had no readonly lists, change_from_owner is set to true.
+        # When adding or delete_other was granted, change_from_others is true.
+        # Note: In my opinion the best choice; there is no exact match.
+        $dbh->do(q|
+            UPDATE virtualshelves
+            SET allow_change_from_owner = 1,
+                allow_change_from_others = CASE WHEN allow_add=1 OR allow_delete_other=1 THEN 1 ELSE 0 END
+        |);
+
+        # Remove the old columns
+        $dbh->do(q|
+            ALTER TABLE virtualshelves
+            DROP COLUMN allow_add,
+            DROP COLUMN allow_delete_own,
+            DROP COLUMN allow_delete_other
+        |);
+    }
+
+    SetVersion($DBversion);
+    print "Upgrade to $DBversion done (Bug 18228 - Alter table virtualshelves to simplify permissions)\n";
+}
+
+$DBversion = '17.06.00.003';
+if ( CheckVersion($DBversion) ) {
+
+    # Fetch all auth types
+    my $authtypes = $dbh->selectcol_arrayref(q|SELECT authtypecode FROM auth_types|);
+
+    if ( grep { $_ eq 'Default' } @$authtypes ) {
+
+        # If this exists as an authtypecode, we don't do anything
+    }
+    else {
+        # Replace the incorrect Default by empty string
+        $dbh->do(q|
+            UPDATE auth_header SET authtypecode='' WHERE authtypecode='Default'
+        |);
+    }
+
+    SetVersion($DBversion);
+    print "Upgrade to $DBversion done (Bug 18801 - Update incorrect Default auth type codes)\n";
+}
+
+$DBversion = '17.06.00.004';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
+        ('GoogleOpenIDConnectAutoRegister',   '0',NULL,' Google OpenID Connect logins to auto-register patrons.','YesNo'),
+        ('GoogleOpenIDConnectDefaultCategory','','','This category code will be used to create Google OpenID Connect patrons.','Textarea'),
+        ('GoogleOpenIDConnectDefaultBranch',  '','','This branch code will be used to create Google OpenID Connect patrons.','Textarea');
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 16892: Add automatic patron registration via OAuth2 login)\n";
+}
+
+$DBversion = '17.06.00.005';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES  ('StaffLangSelectorMode','footer','top|both|footer','Select the location to display the language selector in staff client','Choice')
+        });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 18718 - Language selector in staff header menu similar to OPAC )\n";
+}
+
+$DBversion = '17.06.00.006';
+if( CheckVersion( $DBversion ) ) {
+    print q{WARNING: Bug 18811 fixed an inconsistency in the visibility settings for authority frameworks. It is recommended that you run script misc/maintenance/auth_show_hidden_data.pl to check if you have data in hidden fields and adjust your frameworks accordingly to prevent data loss when editing such records.};
+    print "\n";
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 18811 - Visibility settings inconsistent between framework and authority editor)\n";
+}
+
+$DBversion = '17.06.00.007';
+if( CheckVersion( $DBversion ) ) {
+    if( !column_exists( 'branches', 'marcorgcode' ) ) {
+        $dbh->do( "ALTER TABLE branches ADD COLUMN marcorgcode VARCHAR(16) default NULL AFTER geolocation" );
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 10132 - MARCOrgCode on branch level (branches.marcorgcode))\n";
+}
+
+$DBversion = '17.06.00.008';
+if( CheckVersion( $DBversion ) ) {
+    unless ( column_exists( 'borrowers', 'date_renewed' ) ) {
+        $dbh->do(q{
+            ALTER TABLE borrowers ADD COLUMN date_renewed DATE NULL DEFAULT NULL AFTER dateexpiry;
+        });
+    }
+
+    unless ( column_exists( 'deletedborrowers', 'date_renewed' ) ) {
+        $dbh->do(q{
+            ALTER TABLE deletedborrowers ADD COLUMN date_renewed DATE NULL DEFAULT NULL AFTER dateexpiry;
+        });
+    }
+
+    unless ( column_exists( 'borrower_modifications', 'date_renewed' ) ) {
+        $dbh->do(q{
+            ALTER TABLE borrower_modifications ADD COLUMN date_renewed DATE NULL DEFAULT NULL AFTER dateexpiry;
+        });
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 6758 - Capture membership renewal date for reporting purposes (borrowers.date_renewed))\n";
+}
+
+$DBversion = '17.06.00.009';
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do(q{
+        ALTER TABLE borrowers MODIFY COLUMN login_attempts int(4) AFTER lang;
+    });
+    $dbh->do(q{
+        ALTER TABLE deletedborrowers MODIFY COLUMN login_attempts int(4) AFTER lang;
+    });
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 19344 -  Reorder lang and login_attempts in the [deleted]borrowers tables)\n";
+}
+
+$DBversion = '17.06.00.010';
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` )
+        VALUES (
+            'DefaultCountryField008','','',
+            'Fill in the default country code for field 008 Range 15-17 of MARC21 - Place of publication, production, or execution. See <a href=\"http://www.loc.gov/marc/countries/countries_code.html\">MARC Code List for Countries</a>','Free')
+    });
+    SetVersion($DBversion);
+    print "Upgrade to $DBversion done (Bug 13912 - System preference for default place of publication (country code) for field 008, range 15-17)\n";
+}
+
+$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";
+}
+
 # DEVELOPER PROCESS, search for anything to execute in the db_update directory
 # SEE bug 13068
 # if there is anything in the atomicupdate, read and execute it.