Bug 9295: Introduce operator equal/ notequal to OAI set mapping instead of hardcoded...
[koha.git] / installer / data / mysql / updatedatabase.pl
index 44bf889..d5769a7 100755 (executable)
@@ -5486,13 +5486,15 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
           constrainttype, branchcode, notificationdate,
           reminderdate, cancellationdate, reservenotes,
           priority, found, timestamp, itemnumber,
-          waitingdate, expirationdate, lowestPriority
+          waitingdate, expirationdate, lowestPriority,
+          suspend, suspend_until
         ) SELECT
           borrowernumber, reservedate, biblionumber,
           constrainttype, branchcode, notificationdate,
           reminderdate, cancellationdate, reservenotes,
           priority, found, timestamp, itemnumber,
-          waitingdate, expirationdate, lowestPriority
+          waitingdate, expirationdate, lowestPriority,
+          suspend, suspend_until
         FROM old_reserves ORDER BY reservedate
     ");
     $dbh->do('SET @ai = ( SELECT MAX( reserve_id ) FROM tmp_reserves )');
@@ -5505,18 +5507,20 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
           constrainttype, branchcode, notificationdate,
           reminderdate, cancellationdate, reservenotes,
           priority, found, timestamp, itemnumber,
-          waitingdate, expirationdate, lowestPriority
+          waitingdate, expirationdate, lowestPriority,
+          suspend, suspend_until
         ) SELECT
           borrowernumber, reservedate, biblionumber,
           constrainttype, branchcode, notificationdate,
           reminderdate, cancellationdate, reservenotes,
           priority, found, timestamp, itemnumber,
-          waitingdate, expirationdate, lowestPriority
+          waitingdate, expirationdate, lowestPriority,
+          suspend, suspend_until
         FROM reserves ORDER BY reservedate
     ");
     $dbh->do('TRUNCATE reserves');
     $dbh->do('ALTER TABLE reserves ADD reserve_id INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST');
-    $dbh->do('INSERT INTO reserves SELECT * FROM tmp_reserves WHERE reserve_id > @ai');
+    $dbh->do('INSERT INTO reserves SELECT * FROM tmp_reserves WHERE reserve_id > COALESCE(@ai, 0)');
     $dbh->do('DROP TABLE tmp_reserves');
     $dbh->do('COMMIT');
 
@@ -5557,7 +5561,7 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
 
 $DBversion = '3.09.00.027';
 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
-    $dbh->do("ALTER TABLE issuingrules ADD overduefinescap decimal DEFAULT NULL");
+    $dbh->do("ALTER TABLE issuingrules ADD overduefinescap decimal(28,6) DEFAULT NULL");
     my $maxfine = C4::Context->preference('MaxFine');
     if ($maxfine && $maxfine < 900) { # an arbitrary value that tells us it's not "some huge value"
       $dbh->do("UPDATE issuingrules SET overduefinescap=?",undef,$maxfine);
@@ -5797,7 +5801,6 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     SetVersion($DBversion);
 }
 
-
 $DBversion = "3.09.00.047";
 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     # to preserve default behaviour as best as possible, set this new preference differently depending on whether IndependantBranches is set or not
@@ -6347,43 +6350,43 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
 $DBversion = "3.11.00.016";
 if ( CheckVersion($DBversion) ) {
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="<b>Required for staff login.</b> Staff access, allows viewing of catalogue in staff client." where flag="catalogue";
+        UPDATE userflags SET flagdesc="<b>Required for staff login.</b> Staff access, allows viewing of catalogue in staff client." where flagdesc="Modify login / permissions for staff users";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Edit Authorities" where flag="editauthorities";
+        UPDATE userflags SET flagdesc="Edit Authorities" where flagdesc="Allow to edit authorities";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Allow access to the reports module" where flag="reports";
+        UPDATE userflags SET flagdesc="Allow access to the reports module" where flagdesc="Allow to access to the reports module";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Set library management parameters (deprecated)" where flag="management";
+        UPDATE userflags SET flagdesc="Set library management parameters (deprecated)" where flagdesc="Set library management parameters";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Manage serial subscriptions" where flag="serials";
+        UPDATE userflags SET flagdesc="Manage serial subscriptions" where flagdesc="Allow to manage serials subscriptions";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Manage patrons fines and fees" where flag="updatecharges";
+        UPDATE userflags SET flagdesc="Manage patrons fines and fees" where flagdesc="Update borrower charges";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Check out and check in items" where flag="circulate";
+        UPDATE userflags SET flagdesc="Check out and check in items" where flagdesc="Circulate books";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Manage Koha system settings (Administration panel)" where flag="parameters";
+        UPDATE userflags SET flagdesc="Manage Koha system settings (Administration panel)" where flagdesc="Set Koha system parameters";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Add or modify patrons" where flag="borrowers";
+        UPDATE userflags SET flagdesc="Add or modify patrons" where flagdesc="Add or modify borrowers";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Use all tools (expand for granular tools permissions)" where flag="tools";
+        UPDATE userflags SET flagdesc="Use all tools (expand for granular tools permissions)" where flagdesc="Use tools (export, import, barcodes)";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Allow staff members to modify permissions for other staff members" where flag="staffaccess";
+        UPDATE userflags SET flagdesc="Allow staff members to modify permissions for other staff members" where flagdesc="Set user permissions";
         });
    $dbh->do(q{
-        UPDATE userflags SET flagdesc="Perform batch modification of patrons" where flag="edit_patrons";
+        UPDATE permissions SET description="Perform batch modification of patrons" where description="Perform batch modifivation of patrons";
         });
 
-   print "Upgrade to $DBversion done (Bug 9382 - refresh permission descriptions to make more sense)\n";
+   print "Upgrade to $DBversion done (Bug 9382 (updated with bug 9745) - refresh permission descriptions to make more sense)\n";
    SetVersion ($DBversion);
 }
 
@@ -6405,14 +6408,14 @@ if ( CheckVersion($DBversion) ) {
 }
 
 $DBversion = "3.11.00.019";
-if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+if ( CheckVersion($DBversion) ) {
     $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('UNIMARCAuthorityField100', 'afrey50      ba0', NULL, NULL, 'Textarea')");
     print "Upgrade to $DBversion done (Bug 9145 - Add syspref UNIMARCAuthorityField100)\n";
     SetVersion ($DBversion);
 }
 
 $DBversion = "3.11.00.020";
-if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+if ( CheckVersion($DBversion) ) {
     $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('UNIMARCField100Language', 'fre','UNIMARC field 100 default language',NULL,'short')");
     print "Upgrade to $DBversion done (Bug 8347 - Koha forces UNIMARC 100 field code language to 'fre')\n";
     SetVersion($DBversion);
@@ -6441,7 +6444,6 @@ if ( CheckVersion($DBversion) ) {
     SetVersion($DBversion);
 }
 
-
 $DBversion = "3.11.00.024";
 if ( CheckVersion($DBversion) ) {
     $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacItemLocation','callnum','Show the shelving location of items in the opac','callnum|ccode|location','Choice');");
@@ -6490,7 +6492,7 @@ if ( CheckVersion($DBversion) ) {
         VALUES  ( '1', 'overdues_report', 'Execute overdue items report' )
     });
     # add new permission for users with all report permissions and circulation remaining permission
-    my $sth = $dbh->prepare(q{
+    $dbh->do(q{
         INSERT INTO user_permissions (borrowernumber, module_bit, code)
         SELECT user_permissions.borrowernumber, 1, 'overdues_report'
         FROM user_permissions
@@ -6524,9 +6526,9 @@ if ( CheckVersion($DBversion) ) {
 }
 
 $DBversion = "3.11.00.100";
-if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+if ( CheckVersion($DBversion) ) {
     print "Upgrade to $DBversion done (3.12-alpha release)\n";
-   SetVersion ($DBversion);
+    SetVersion ($DBversion);
 }
 
 $DBversion = "3.11.00.101";
@@ -6556,7 +6558,7 @@ if ( CheckVersion($DBversion) ) {
 }
 
 $DBversion = "3.11.00.104";
-if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+if ( CheckVersion($DBversion) ) {
     print "Upgrade to $DBversion done (3.12-alpha2 release)\n";
     SetVersion ($DBversion);
 }
@@ -6629,7 +6631,7 @@ if ( CheckVersion($DBversion) ) {
 
 
 $DBversion = "3.11.00.106";
-if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+if ( CheckVersion($DBversion) ) {
     $dbh->do("INSERT INTO userflags (bit, flag, flagdesc, defaulton) VALUES ('19', 'plugins', 'Koha plugins', '0')");
     $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES
               ('19', 'manage', 'Manage plugins ( install / uninstall )'),
@@ -6714,7 +6716,7 @@ if ( CheckVersion($DBversion) ) {
 }
 
 $DBversion = "3.11.00.113";
-if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+if ( CheckVersion($DBversion) ) {
     $dbh->do(q{
         ALTER TABLE branchcategories ADD show_in_pulldown BOOLEAN NOT NULL DEFAULT '0',
         ADD INDEX ( show_in_pulldown )
@@ -6723,6 +6725,457 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = "3.11.00.115";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('HighlightOwnItemsOnOPAC','0','','If on, and a patron is logged into the OPAC, items from his or her home library will be emphasized and shown first in search results and item details.','YesNo')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('HighlightOwnItemsOnOPACWhich','PatronBranch','PatronBranch|OpacURLBranch','Decides which branch''s items to emphasize. If PatronBranch, emphasize the logged in user''s library''s items. If OpacURLBranch, highlight the items of the Apache var BRANCHCODE defined in Koha''s Apache configuration file.','Choice')");
+    print "Upgrade to $DBversion done (Bug 7740: Add syspref HighlightOwnItemsOnOPAC)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.11.00.116";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{ALTER TABLE aqorders DROP COLUMN serialid;});
+    $dbh->do(q{ALTER TABLE aqorders DROP COLUMN subscription;});
+    $dbh->do(q{ALTER TABLE aqorders ADD COLUMN subscriptionid INT(11) DEFAULT NULL;});
+    $dbh->do(q{ALTER TABLE aqorders ADD CONSTRAINT aqorders_subscriptionid FOREIGN KEY (subscriptionid) REFERENCES subscription (subscriptionid) ON DELETE CASCADE ON UPDATE CASCADE;});
+    $dbh->do(q{ALTER TABLE subscription ADD COLUMN reneweddate DATE DEFAULT NULL;});
+    print "Upgrade to $DBversion done (Bug 5343: table aqorders: DROP serialid and subscription fields and ADD subscriptionid, table subscription: ADD reneweddate)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.11.00.200";
+if ( CheckVersion($DBversion) ) {
+    print "Upgrade to $DBversion done (3.12-beta1 release)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.11.00.201";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("UPDATE z3950servers SET encoding = 'ISO_8859-1' WHERE name = 'BIBSYS' AND host LIKE 'z3950.bibsys.no'");
+    $dbh->do("UPDATE z3950servers SET encoding = 'ISO_8859-1' WHERE name = 'NORBOK' AND host LIKE 'z3950.nb.no'");
+    $dbh->do("UPDATE z3950servers SET encoding = 'ISO_8859-1' WHERE name = 'SAMBOK' AND host LIKE 'z3950.nb.no'");
+    $dbh->do("UPDATE z3950servers SET encoding = 'ISO_8859-1' WHERE name = 'DEICHMAN' AND host like 'z3950.deich.folkebibl.no'");
+    print "Upgrade to $DBversion done (Bug 9498 - Update encoding for Norwegian sample Z39.50 servers)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.11.00.202";
+if ( CheckVersion($DBversion) ) {
+   $dbh->do("INSERT INTO language_subtag_registry( subtag, type, description, added) VALUES ( 'ca', 'language', 'Catalan','2013-01-12' )");
+   $dbh->do("INSERT INTO language_rfc4646_to_iso639(rfc4646_subtag,iso639_2_code) VALUES( 'ca','cat')");
+   $dbh->do("INSERT INTO language_descriptions(subtag, type, lang, description) VALUES( 'ca', 'language', 'es', 'Catalán')");
+   $dbh->do("INSERT INTO language_descriptions(subtag, type, lang, description) VALUES( 'ca', 'language', 'en', 'Catalan')");
+   $dbh->do("INSERT INTO language_descriptions(subtag, type, lang, description) VALUES( 'ca', 'language', 'fr', 'Catalan')");
+   $dbh->do("INSERT INTO language_descriptions(subtag, type, lang, description) VALUES( 'ca', 'language', 'ca', 'CatalĂ ')");
+   $dbh->do("INSERT INTO language_descriptions(subtag, type, lang, description) VALUES( 'ca', 'language', 'de', 'Katalanisch')");
+   print "Upgrade to $DBversion done (Bug 9381: Add Catalan laguage)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = "3.11.00.203";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{ALTER TABLE suggestions CHANGE COLUMN title title VARCHAR(255) DEFAULT NULL;});
+    print "Upgrade to $DBversion done (Bug 2046 - increasing title column length for suggestions)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.11.00.300";
+if ( CheckVersion($DBversion) ) {
+    print "Upgrade to $DBversion done (3.12-beta3 release)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.11.00.301";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    #issues
+    $dbh->do(q{
+        ALTER TABLE `issues`
+            ADD KEY `itemnumber_idx` (`itemnumber`),
+            ADD KEY `branchcode_idx` (`branchcode`),
+            ADD KEY `issuingbranch_idx` (`issuingbranch`)
+    });
+    $dbh->do(q{
+        ALTER TABLE `old_issues`
+            ADD KEY `branchcode_idx` (`branchcode`),
+            ADD KEY `issuingbranch_idx` (`issuingbranch`)
+    });
+    #items
+    $dbh->do(q{
+        ALTER TABLE `items` ADD KEY `itype_idx` (`itype`)
+    });
+    $dbh->do(q{
+        ALTER TABLE `deleteditems` ADD KEY `itype_idx` (`itype`)
+    });
+    # biblioitems
+    $dbh->do(q{
+        ALTER TABLE `biblioitems` ADD KEY `itemtype_idx` (`itemtype`)
+    });
+    $dbh->do(q{
+        ALTER TABLE `deletedbiblioitems` ADD KEY `itemtype_idx` (`itemtype`)
+    });
+    # statistics
+    $dbh->do(q{
+        ALTER TABLE `statistics`
+            ADD KEY `branch_idx` (`branch`),
+            ADD KEY `proccode_idx` (`proccode`),
+            ADD KEY `type_idx` (`type`),
+            ADD KEY `usercode_idx` (`usercode`),
+            ADD KEY `itemnumber_idx` (`itemnumber`),
+            ADD KEY `itemtype_idx` (`itemtype`),
+            ADD KEY `borrowernumber_idx` (`borrowernumber`),
+            ADD KEY `associatedborrower_idx` (`associatedborrower`),
+            ADD KEY `ccode_idx` (`ccode`)
+    });
+
+    print "Upgrade to $DBversion done (Bug 9681: Add some database indexes)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.12.00.000";
+if ( CheckVersion($DBversion) ) {
+    print "Upgrade to $DBversion done (3.12.0 release)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.13.00.000';
+if ( CheckVersion($DBversion) ) {
+    print "Upgrade to $DBversion done (start the journey to Koha Pi)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.13.00.001";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('UseCourseReserves', '0', NULL, 'Enable the course reserves feature.', 'YesNo')");
+    $dbh->do("INSERT INTO userflags (bit,flag,flagdesc,defaulton) VALUES ('18','coursereserves','Course Reserves','0')");
+    $dbh->do("
+CREATE TABLE `courses` (
+  `course_id` int(11) NOT NULL AUTO_INCREMENT,
+  `department` varchar(20) DEFAULT NULL,
+  `course_number` varchar(255) DEFAULT NULL,
+  `section` varchar(255) DEFAULT NULL,
+  `course_name` varchar(255) DEFAULT NULL,
+  `term` varchar(20) DEFAULT NULL,
+  `staff_note` mediumtext,
+  `public_note` mediumtext,
+  `students_count` varchar(20) DEFAULT NULL,
+  `enabled` enum('yes','no') NOT NULL DEFAULT 'yes',
+  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+   PRIMARY KEY (`course_id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+    ");
+
+    $dbh->do("
+CREATE TABLE `course_instructors` (
+  `course_id` int(11) NOT NULL,
+  `borrowernumber` int(11) NOT NULL,
+  PRIMARY KEY (`course_id`,`borrowernumber`),
+  KEY `borrowernumber` (`borrowernumber`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+    ");
+
+    $dbh->do("
+ALTER TABLE `course_instructors`
+  ADD CONSTRAINT `course_instructors_ibfk_2` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`),
+  ADD CONSTRAINT `course_instructors_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE;
+    ");
+
+    $dbh->do("
+CREATE TABLE `course_items` (
+  `ci_id` int(11) NOT NULL AUTO_INCREMENT,
+  `itemnumber` int(11) NOT NULL,
+  `itype` varchar(10) DEFAULT NULL,
+  `ccode` varchar(10) DEFAULT NULL,
+  `holdingbranch` varchar(10) DEFAULT NULL,
+  `location` varchar(80) DEFAULT NULL,
+  `enabled` enum('yes','no') NOT NULL DEFAULT 'no',
+  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+   PRIMARY KEY (`ci_id`),
+   UNIQUE KEY `itemnumber` (`itemnumber`),
+   KEY `holdingbranch` (`holdingbranch`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+    ");
+
+    $dbh->do("
+ALTER TABLE `course_items`
+  ADD CONSTRAINT `course_items_ibfk_2` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
+  ADD CONSTRAINT `course_items_ibfk_1` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE;
+");
+
+    $dbh->do("
+CREATE TABLE `course_reserves` (
+  `cr_id` int(11) NOT NULL AUTO_INCREMENT,
+  `course_id` int(11) NOT NULL,
+  `ci_id` int(11) NOT NULL,
+  `staff_note` mediumtext,
+  `public_note` mediumtext,
+  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+   PRIMARY KEY (`cr_id`),
+   UNIQUE KEY `pseudo_key` (`course_id`,`ci_id`),
+   KEY `course_id` (`course_id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+");
+
+    $dbh->do("
+ALTER TABLE `course_reserves`
+  ADD CONSTRAINT `course_reserves_ibfk_1` FOREIGN KEY (`course_id`) REFERENCES `courses` (`course_id`);
+    ");
+
+    $dbh->do("
+INSERT INTO permissions (module_bit, code, description) VALUES
+  (18, 'manage_courses', 'Add, edit and delete courses'),
+  (18, 'add_reserves', 'Add course reserves'),
+  (18, 'delete_reserves', 'Remove course reserves')
+;
+    ");
+
+
+    print "Upgrade to $DBversion done (Add Course Reserves ( system preference UseCourseReserves ))\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.002";
+if ( CheckVersion($DBversion) ) {
+   $dbh->do("UPDATE systempreferences SET variable = 'IndependentBranches' WHERE variable = 'IndependantBranches'");
+   print "Upgrade to $DBversion done (Bug 10080 - Change system pref IndependantBranches to IndependentBranches)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = '3.13.00.003';
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("ALTER TABLE serial DROP itemnumber");
+    print "Upgrade to $DBversion done (Bug 7718 - Remove itemnumber column from serials table)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.004";
+if(CheckVersion($DBversion)) {
+    $dbh->do(
+"INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowHoldNotes',0,'Show hold notes on OPAC','','YesNo')"
+    );
+    print "Upgrade to $DBversion done (Bug 9722: Allow users to add notes when placing a hold in OPAC)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.005";
+if(CheckVersion($DBversion)) {
+    my $intra= C4::Context->preference("intranetstylesheet");
+    #if this pref is not blank or starting with http, https or / [root], then
+    #add an additional / to the front
+    if($intra && $intra !~ /^(\/|https?)/) {
+        $dbh->do("UPDATE systempreferences SET value=? WHERE variable=?",
+            undef,('/'.$intra,"intranetstylesheet"));
+        print "WARNING: Your system preference intranetstylesheet has been prefixed with a slash to make it an absolute path.\n";
+    }
+    print "Upgrade to $DBversion done (Bug 10052: Make intranetstylesheet and intranetcolorstylesheet behave exactly like their opac counterparts)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.13.00.006";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(
+        q{
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CalculateFinesOnReturn','1','Switch to control if overdue fines are calculated on return or not', '', 'YesNo');
+}
+    );
+    print
+"Upgrade to $DBversion done (Bug 10120 - Fines on item return controlled by a systempreference)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.007";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("UPDATE systempreferences SET variable='OpacHoldNotes' WHERE variable='OpacShowHoldNotes'");
+    print "Upgrade to $DBversion done (Bug 10343: Rename OpacShowHoldNotes to OpacHoldNotes)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.008";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("
+CREATE TABLE IF NOT EXISTS borrower_files (
+  file_id int(11) NOT NULL AUTO_INCREMENT,
+  borrowernumber int(11) NOT NULL,
+  file_name varchar(255) NOT NULL,
+  file_type varchar(255) NOT NULL,
+  file_description varchar(255) DEFAULT NULL,
+  file_content longblob NOT NULL,
+  date_uploaded timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  PRIMARY KEY (file_id),
+  KEY borrowernumber (borrowernumber),
+  CONSTRAINT borrower_files_ibfk_1 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+    ");
+    print "Upgrade to $DBversion done (Bug 10443: make sure borrower_files table exists)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.009";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("ALTER TABLE aqorders DROP COLUMN biblioitemnumber");
+    print "Upgrade to $DBversion done (Bug 9987 - Drop column aqorders.biblioitemnumber)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.010";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(
+        q{
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AcqWarnOnDuplicateInvoice','0','Warn librarians when they try to create a duplicate invoice', '', 'YesNo');
+}
+    );
+    print
+"Upgrade to $DBversion done (Bug 10366 - Add system preference to enabling warning librarian when invoice is duplicated)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.011";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("UPDATE language_rfc4646_to_iso639 SET iso639_2_code='ita' WHERE rfc4646_subtag='it'");
+    print "Upgrade to $DBversion done (Bug 9519: Wrong language code for Italian in the advanced search language limitations)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.012";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("ALTER TABLE issuingrules MODIFY COLUMN overduefinescap decimal(28,6) DEFAULT NULL;");
+    print "Upgrade to $DBversion done (Bug 10490: Correct datatype for overduefinescap in issuingrules)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion ="3.13.00.013";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('AllowTooManyOverride', '1', 'If on, allow staff to override and check out items when the patron has reached the maximum number of allowed checkouts', '', 'YesNo');");
+    print "Upgrade to $DBversion done (Bug 9576: add AllowTooManyOverride syspref to enable or disable issue limit confirmation)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.014";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("ALTER TABLE courses MODIFY COLUMN department varchar(80) DEFAULT NULL;");
+    $dbh->do("ALTER TABLE courses MODIFY COLUMN term       varchar(80) DEFAULT NULL;");
+    print "Upgrade to $DBversion done (Bug 10604: correct width of courses.department and courses.term)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.015";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(
+"INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeFallbackSearch','','If set, enables the automatic use of a keyword catalog search if the phrase entered as a barcode on the checkout page does not turn up any results during an item barcode search',NULL,'YesNo')"
+    );
+    print "Upgrade to $DBversion done (Bug 7494: Add itemBarcodeFallbackSearch syspref)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.016";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        ALTER TABLE items CHANGE wthdrawn withdrawn TINYINT( 1 ) NOT NULL DEFAULT  '0'
+    });
+
+    $dbh->do(q{
+        ALTER TABLE deleteditems CHANGE wthdrawn withdrawn TINYINT( 1 ) NOT NULL DEFAULT  '0'
+    });
+
+    $dbh->do(q{
+        UPDATE saved_sql SET savedsql = REPLACE(savedsql, 'wthdrawn', 'withdrawn')
+    });
+
+    $dbh->do(q{
+        UPDATE marc_subfield_structure SET kohafield = 'items.withdrawn' WHERE kohafield = 'items.wthdrawn'
+    });
+
+    print "Upgrade to $DBversion done (Bug 10550 - Fix database typo wthdrawn)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.017";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(
+"INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OverDriveClientKey','','Client key for OverDrive integration','30','Free')"
+    );
+    $dbh->do(
+"INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OverDriveClientSecret','','Client key for OverDrive integration','30','YesNo')"
+    );
+    $dbh->do(
+"INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('OverDriveLibraryID','','Library ID for OverDrive integration','','Integer')"
+    );
+    print "Upgrade to $DBversion done (Bug 10320 - Show results from library's OverDrive collection in OPAC search)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.018";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(qq{DROP TABLE IF EXISTS aqorders_transfers;});
+    $dbh->do(qq{
+        CREATE TABLE aqorders_transfers (
+          ordernumber_from int(11) NULL,
+          ordernumber_to int(11) NULL,
+          timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+          UNIQUE KEY ordernumber_from (ordernumber_from),
+          UNIQUE KEY ordernumber_to (ordernumber_to),
+          CONSTRAINT aqorders_transfers_ordernumber_from FOREIGN KEY (ordernumber_from) REFERENCES aqorders (ordernumber) ON DELETE SET NULL ON UPDATE CASCADE,
+          CONSTRAINT aqorders_transfers_ordernumber_to FOREIGN KEY (ordernumber_to) REFERENCES aqorders (ordernumber) ON DELETE SET NULL ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+    });
+    print "Upgrade to $DBversion done (Bug 5349: Add aqorders_transfers table)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.019";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("ALTER TABLE itemtypes ADD COLUMN checkinmsg VARCHAR(255) AFTER summary;");
+    $dbh->do("ALTER TABLE itemtypes ADD COLUMN checkinmsgtype CHAR(16) DEFAULT 'message' NOT NULL AFTER checkinmsg;");
+    print "Upgrade to $DBversion done (Bug 10513 - Light up a warning/message when returning a chosen item type)\n";
+    SetVersion($DBversion);
+}
+
+
+$DBversion = "3.13.00.020";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('WhenLostForgiveFine','0',NULL,'If ON, Forgives the fines on an item when it is lost.','YesNo')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('WhenLostChargeReplacementFee','1',NULL,'If ON, Charge the replacement price when a patron loses an item.','YesNo')");
+    print "Upgrade to $DBversion done (Bug 7639: system preferences to forgive fines on lost items)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion ="3.13.00.021";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('ConfirmFutureHolds','0','Number of days for confirming future holds','','Integer');");
+    print "Upgrade to $DBversion done (Bug 9761: Add ConfirmFutureHolds pref)\n";
+    SetVersion($DBversion);
+}
+
+
+$DBversion = "3.13.00.022";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("DELETE from auth_tag_structure WHERE tagfield IN ('68a','68b')");
+    $dbh->do("DELETE from auth_subfield_structure WHERE tagfield IN ('68a','68b')");
+    print "Upgrade to $DBversion done (Bug 10687 - Delete erroneous tags 68a and 68b on default MARC21 auth framework)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.023";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("ALTER TABLE borrowers CHANGE password password VARCHAR(60);");
+    print "Upgrade to $DBversion done (Bug 9611 upgrading password storage system)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.024";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{ALTER TABLE z3950servers ADD COLUMN recordtype VARCHAR(45) NOT NULL DEFAULT 'biblio' AFTER description;});
+    print "Upgrade to $DBversion done (Bug 10096 - Add a Z39.50 interface for authority searching)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.13.00.XXX";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+   $dbh->do("ALTER TABLE oai_sets_mappings ADD COLUMN operator varchar(8) NOT NULL default 'equal' AFTER marcsubfield;");
+   print "Upgrade to $DBversion done (Bug 9295: OAI notequal: add operator column to OAI mappings table)\n";
+   SetVersion ($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)