Bug 11611: DBRev 3.15.00.017
[koha_fer] / installer / data / mysql / updatedatabase.pl
index bf7d654..22bba73 100755 (executable)
@@ -7146,7 +7146,6 @@ if ( CheckVersion($DBversion) ) {
     SetVersion($DBversion);
 }
 
-
 $DBversion = "3.13.00.022";
 if ( CheckVersion($DBversion) ) {
     $dbh->do("DELETE from auth_tag_structure WHERE tagfield IN ('68a','68b')");
@@ -7262,7 +7261,7 @@ if ( CheckVersion($DBversion) ) {
     $dbh->{RaiseError} = 0;
 }
 
-$DBversion = "3.13.00.XXX";
+$DBversion = "3.13.00.031";
 if ( CheckVersion($DBversion) ) {
 
     $dbh->do(q{
@@ -7297,10 +7296,684 @@ if ( CheckVersion($DBversion) ) {
           ADD CONSTRAINT patron_list_patrons_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE;
     });
 
+    $dbh->do(q{
+        INSERT INTO permissions (module_bit, code, description) VALUES
+        (13, 'manage_patron_lists', 'Add, edit and delete patron lists and their contents')
+    });
+
     print "Upgrade to $DBversion done (Bug 10565 - Add a 'Patron List' feature for storing and manipulating collections of patrons)\n";
     SetVersion($DBversion);
 }
 
+$DBversion = "3.13.00.032";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("ALTER TABLE aqorders ADD COLUMN orderstatus varchar(16) DEFAULT 'new' AFTER parent_ordernumber");
+    $dbh->do("UPDATE aqorders SET orderstatus='ordered' WHERE basketno IN (SELECT basketno FROM aqbasket WHERE closedate IS NOT NULL)");
+    $dbh->do(q{
+        UPDATE aqorders SET orderstatus='partial'
+        WHERE quantity > quantityreceived
+        AND quantityreceived > 0
+        AND ordernumber IN (
+            SELECT parent_ordernumber
+            FROM (
+                SELECT DISTINCT(parent_ordernumber)
+                FROM aqorders
+                WHERE ordernumber != parent_ordernumber
+            ) AS aq 
+        )
+        AND basketno IN (SELECT basketno FROM aqbasket WHERE closedate IS NOT NULL)
+    });
+    $dbh->do("UPDATE aqorders SET orderstatus='complete' WHERE quantity=quantityreceived");
+    $dbh->do("UPDATE aqorders SET orderstatus='cancelled' WHERE datecancellationprinted IS NOT NULL");
+    print "Upgrade to $DBversion done (Bug 5336: Add the new column aqorders.orderstatus)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.033";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(qq|
+        DROP TABLE IF EXISTS subscription_frequencies
+    |);
+    $dbh->do(qq|
+        CREATE TABLE subscription_frequencies (
+            id INTEGER NOT NULL AUTO_INCREMENT,
+            description TEXT NOT NULL,
+            displayorder INT DEFAULT NULL,
+            unit ENUM('day','week','month','year') DEFAULT NULL,
+            unitsperissue INTEGER NOT NULL DEFAULT '1',
+            issuesperunit INTEGER NOT NULL DEFAULT '1',
+            PRIMARY KEY (id)
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8
+    |);
+
+    $dbh->do(qq|
+        DROP TABLE IF EXISTS subscription_numberpatterns
+    |);
+    $dbh->do(qq|
+        CREATE TABLE subscription_numberpatterns (
+            id INTEGER NOT NULL AUTO_INCREMENT,
+            label VARCHAR(255) NOT NULL,
+            displayorder INTEGER DEFAULT NULL,
+            description TEXT NOT NULL,
+            numberingmethod VARCHAR(255) NOT NULL,
+            label1 VARCHAR(255) DEFAULT NULL,
+            add1 INTEGER DEFAULT NULL,
+            every1 INTEGER DEFAULT NULL,
+            whenmorethan1 INTEGER DEFAULT NULL,
+            setto1 INTEGER DEFAULT NULL,
+            numbering1 VARCHAR(255) DEFAULT NULL,
+            label2 VARCHAR(255) DEFAULT NULL,
+            add2 INTEGER DEFAULT NULL,
+            every2 INTEGER DEFAULT NULL,
+            whenmorethan2 INTEGER DEFAULT NULL,
+            setto2 INTEGER DEFAULT NULL,
+            numbering2 VARCHAR(255) DEFAULT NULL,
+            label3 VARCHAR(255) DEFAULT NULL,
+            add3 INTEGER DEFAULT NULL,
+            every3 INTEGER DEFAULT NULL,
+            whenmorethan3 INTEGER DEFAULT NULL,
+            setto3 INTEGER DEFAULT NULL,
+            numbering3 VARCHAR(255) DEFAULT NULL,
+            PRIMARY KEY (id)
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8
+    |);
+
+    $dbh->do(qq|
+        INSERT INTO subscription_frequencies (description, unit, unitsperissue, issuesperunit, displayorder)
+        VALUES
+            ('2/day', 'day', 1, 2, 1),
+            ('1/day', 'day', 1, 1, 2),
+            ('3/week', 'week', 1, 3, 3),
+            ('1/week', 'week', 1, 1, 4),
+            ('1/2 weeks', 'week', 2, 1, 5),
+            ('1/3 weeks', 'week', 3, 1, 6),
+            ('1/month', 'month', 1, 1, 7),
+            ('1/2 months', 'month', 2, 1, 8),
+            ('1/3 months', 'month', 3, 1, 9),
+            ('2/year', 'month', 6, 1, 10),
+            ('1/year', 'year', 1, 1, 11),
+            ('1/2 year', 'year', 2, 1, 12),
+            ('Irregular', NULL, 1, 1, 13)
+    |);
+
+    # Used to link existing subscription to newly created frequencies
+    my $frequencies_mapping = {     # keys are old frequency numbers, values are the new ones
+        1 => 2,     # daily (n/week)
+        2 => 4,     # 1/week
+        3 => 5,     # 1/2 weeks
+        4 => 6,     # 1/3 weeks
+        5 => 7,     # 1/month
+        6 => 8,     # 1/2 months (6/year)
+        7 => 9,     # 1/3 months (1/quarter)
+        8 => 9,    # 1/quarter (seasonal)
+        9 => 10,    # 2/year
+        10 => 11,   # 1/year
+        11 => 12,   # 1/2 years
+        12 => 1,    # 2/day
+        16 => 13,   # Without periodicity
+        32 => 13,   # Irregular
+        48 => 13    # Unknown
+    };
+
+    $dbh->do(qq|
+        INSERT INTO subscription_numberpatterns
+            (label, displayorder, description, numberingmethod,
+            label1, add1, every1, whenmorethan1, setto1, numbering1,
+            label2, add2, every2, whenmorethan2, setto2, numbering2,
+            label3, add3, every3, whenmorethan3, setto3, numbering3)
+        VALUES
+            ('Number', 1, 'Simple Numbering method', 'No.{X}',
+            'Number', 1, 1, 99999, 1, NULL,
+            NULL, NULL, NULL, NULL, NULL, NULL,
+            NULL, NULL, NULL, NULL, NULL, NULL),
+
+            ('Volume, Number, Issue', 2, 'Volume Number Issue 1', 'Vol.{X}, Number {Y}, Issue {Z}',
+            'Volume', 1, 48, 99999, 1, NULL,
+            'Number', 1, 4, 12, 1, NULL,
+            'Issue', 1, 1, 4, 1, NULL),
+
+            ('Volume, Number', 3, 'Volume Number 1', 'Vol {X}, No {Y}',
+            'Volume', 1, 12, 99999, 1, NULL,
+            'Number', 1, 1, 12, 1, NULL,
+            NULL, NULL, NULL, NULL, NULL, NULL),
+
+            ('Seasonal', 4, 'Season Year', '{X} {Y}',
+            'Season', 1, 1, 3, 0, 'season',
+            'Year', 1, 4, 99999, 1, NULL,
+            NULL, NULL, NULL, NULL, NULL, NULL)
+    |);
+
+    $dbh->do(qq|
+        ALTER TABLE subscription
+        MODIFY COLUMN numberpattern INTEGER DEFAULT NULL,
+        MODIFY COLUMN periodicity INTEGER DEFAULT NULL
+    |);
+
+    # Update existing subscriptions
+
+    my $query = qq|
+        SELECT subscriptionid, periodicity, numberingmethod,
+            add1, every1, whenmorethan1, setto1,
+            add2, every2, whenmorethan2, setto2,
+            add3, every3, whenmorethan3, setto3
+        FROM subscription
+        ORDER BY subscriptionid
+    |;
+    my $sth = $dbh->prepare($query);
+    $sth->execute;
+    my $insert_numberpatterns_sth = $dbh->prepare(qq|
+        INSERT INTO subscription_numberpatterns
+             (label, displayorder, description, numberingmethod,
+            label1, add1, every1, whenmorethan1, setto1, numbering1,
+            label2, add2, every2, whenmorethan2, setto2, numbering2,
+            label3, add3, every3, whenmorethan3, setto3, numbering3)
+        VALUES
+            (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
+    |);
+    my $check_numberpatterns_sth = $dbh->prepare(qq|
+        SELECT * FROM subscription_numberpatterns
+        WHERE add1 = ? AND add2 = ? AND add3 = ?
+          AND every1 = ? AND every2 = ? AND every3 = ?
+          AND whenmorethan1 = ? AND whenmorethan2 = ? AND whenmorethan3 = ?
+          AND setto1 = ? AND setto2 = ? AND setto3 = ?
+          AND numberingmethod = ?
+        LIMIT 1
+    |);
+    my $update_subscription_sth = $dbh->prepare(qq|
+        UPDATE subscription
+        SET numberpattern = ?,
+            periodicity = ?
+        WHERE subscriptionid = ?
+    |);
+
+    my $i = 1;
+    while(my $sub = $sth->fetchrow_hashref) {
+        $check_numberpatterns_sth->execute(
+            $sub->{add1}, $sub->{add2}, $sub->{add3},
+            $sub->{every1}, $sub->{every2}, $sub->{every3},
+            $sub->{whenmorethan1}, $sub->{whenmorethan2}, $sub->{whenmorethan3},
+            $sub->{setto1}, $sub->{setto2}, $sub->{setto3},
+            $sub->{numberingmethod}
+        );
+        my $p = $check_numberpatterns_sth->fetchrow_hashref;
+        if (defined $p) {
+            # Pattern already exists, link to it
+            $update_subscription_sth->execute($p->{id},
+                $frequencies_mapping->{$sub->{periodicity}},
+                $sub->{subscriptionid});
+        } else {
+            # Create a new numbering pattern for this subscription
+            my $ok = $insert_numberpatterns_sth->execute(
+                "Backup pattern $i", 4+$i, "Automatically created pattern by updatedatabase", $sub->{numberingmethod},
+                "X", $sub->{add1}, $sub->{every1}, $sub->{whenmorethan1}, $sub->{setto1}, undef,
+                "Y", $sub->{add2}, $sub->{every2}, $sub->{whenmorethan2}, $sub->{setto2}, undef,
+                "Z", $sub->{add3}, $sub->{every3}, $sub->{whenmorethan3}, $sub->{setto3}, undef
+            );
+            if($ok) {
+                my $id = $dbh->last_insert_id(undef, undef, 'subscription_numberpatterns', undef);
+                # Link to subscription_numberpatterns and subscription_frequencies
+                $update_subscription_sth->execute($id,
+                    $frequencies_mapping->{$sub->{periodicity}},
+                    $sub->{subscriptionid});
+            }
+            $i++;
+        }
+    }
+
+    # Remove now useless columns
+    $dbh->do(qq|
+        ALTER TABLE subscription
+        DROP COLUMN numberingmethod,
+        DROP COLUMN add1,
+        DROP COLUMN every1,
+        DROP COLUMN whenmorethan1,
+        DROP COLUMN setto1,
+        DROP COLUMN add2,
+        DROP COLUMN every2,
+        DROP COLUMN whenmorethan2,
+        DROP COLUMN setto2,
+        DROP COLUMN add3,
+        DROP COLUMN every3,
+        DROP COLUMN whenmorethan3,
+        DROP COLUMN setto3,
+        DROP COLUMN dow,
+        DROP COLUMN issuesatonce,
+        DROP COLUMN hemisphere,
+        ADD COLUMN countissuesperunit INTEGER NOT NULL DEFAULT 1 AFTER periodicity,
+        ADD COLUMN skip_serialseq BOOLEAN NOT NULL DEFAULT 0 AFTER irregularity,
+        ADD COLUMN locale VARCHAR(80) DEFAULT NULL AFTER numberpattern,
+        ADD CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE,
+        ADD CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE
+    |);
+
+    # Set firstacquidate if not already set (firstacquidate is now mandatory)
+    my $get_first_planneddate_sth = $dbh->prepare(qq|
+        SELECT planneddate
+        FROM serial
+        WHERE subscriptionid = ?
+        ORDER BY serialid
+        LIMIT 1
+    |);
+    my $update_firstacquidate_sth = $dbh->prepare(qq|
+        UPDATE subscription
+        SET firstacquidate = ?
+        WHERE subscriptionid = ?
+    |);
+    my $get_subscriptions_sth = $dbh->prepare(qq|
+        SELECT subscriptionid, startdate
+        FROM subscription
+        WHERE firstacquidate IS NULL
+          OR firstacquidate = '0000-00-00'
+    |);
+    $get_subscriptions_sth->execute;
+    while ( my ($subscriptionid, $startdate) = $get_subscriptions_sth->fetchrow ) {
+        # Try to get the planned date of the first serial
+        $get_first_planneddate_sth->execute($subscriptionid);
+        my ($first_planneddate) = $get_first_planneddate_sth->fetchrow;
+        if ($first_planneddate and $first_planneddate =~ /^\d{4}-\d{2}-\d{2}$/) {
+            $update_firstacquidate_sth->execute($first_planneddate, $subscriptionid);
+        } else {
+            # Defaults to subscription start date
+            $update_firstacquidate_sth->execute($startdate, $subscriptionid);
+        }
+    }
+
+    print "Upgrade to $DBversion done (Bug 7688: add subscription_frequencies and subscription_numberpatterns tables)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.034";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("
+        ALTER TABLE `import_batches`
+        CHANGE `item_action` `item_action`
+          ENUM( 'always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore', 'replace' )
+          NOT NULL DEFAULT 'always_add'
+    ");
+    print "Upgrade to $DBversion done (Bug 7131 - way to overlay items in in marc import)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion ="3.13.00.035";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+CREATE TABLE borrower_debarments (
+  borrower_debarment_id int(11) NOT NULL AUTO_INCREMENT,
+  borrowernumber int(11) NOT NULL,
+  expiration date DEFAULT NULL,
+  `type` enum('SUSPENSION','OVERDUES','MANUAL') NOT NULL DEFAULT 'MANUAL',
+  `comment` text,
+  manager_id int(11) DEFAULT NULL,
+  created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+  updated timestamp NULL DEFAULT NULL,
+  PRIMARY KEY (borrower_debarment_id),
+  KEY borrowernumber (borrowernumber) ,
+  CONSTRAINT `borrower_debarments_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
+    ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+    });
+
+    $dbh->do(q{
+INSERT INTO borrower_debarments ( borrowernumber, expiration, comment ) SELECT borrowernumber, debarred, debarredcomment FROM borrowers WHERE debarred IS NOT NULL
+    });
+
+    $dbh->do(q{
+INSERT IGNORE INTO systempreferences (variable,value,explanation,type) VALUES
+('AutoRemoveOverduesRestrictions','0','Defines whether an OVERDUES debarment should be lifted automatically if all overdue items are returned by the patron.','YesNo')
+    });
+
+    print "Upgrade to $DBversion done (Bug 2720 - Overdues which debar automatically should undebar automatically when returned)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.036";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(qq{
+        INSERT INTO systempreferences (variable, value, explanation, options, type)
+        VALUES ('StaffDetailItemSelection', '1', 'Enable item selection in record detail page', NULL, 'YesNo')
+    });
+    print "Upgrade to $DBversion done (Add system preference StaffDetailItemSelection)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.037";
+if ( CheckVersion($DBversion) ) {
+    #add phone if it is not there already (explains the ignore option)
+    $dbh->do("
+INSERT IGNORE INTO message_transport_types (message_transport_type) values ('phone');
+    ");
+    print "Upgrade to $DBversion done (Bug 10572: Add phone to message_transport_types table for new installs)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.038";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES(15, 'superserials', 'Manage subscriptions from any branch (only applies when IndependentBranches is used)')");
+    print "Upgrade to $DBversion done (Bug 8435: Add superserials permission)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.039";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("
+        ALTER TABLE aqbasket ADD branch varchar(10) default NULL
+    ");
+    $dbh->do("
+        ALTER TABLE aqbasket
+        ADD CONSTRAINT aqbasket_ibfk_4 FOREIGN KEY (branch)
+            REFERENCES branches (branchcode)
+            ON UPDATE CASCADE ON DELETE SET NULL
+    ");
+    $dbh->do("
+        DROP TABLE IF EXISTS aqbasketusers
+    ");
+    $dbh->do("
+        CREATE TABLE aqbasketusers (
+            basketno int(11) NOT NULL,
+            borrowernumber int(11) NOT NULL,
+            PRIMARY KEY (basketno,borrowernumber),
+            CONSTRAINT aqbasketusers_ibfk_1 FOREIGN KEY (basketno) REFERENCES aqbasket (basketno) ON DELETE CASCADE ON UPDATE CASCADE,
+            CONSTRAINT aqbasketusers_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+    ");
+    $dbh->do("
+        INSERT INTO permissions (module_bit, code, description)
+        VALUES (11, 'order_manage_all', 'Manage all orders and baskets, regardless of restrictions on them')
+    ");
+
+    print "Upgrade to $DBversion done (Add branch and users list to baskets. "
+        . "New permission order_manage_all)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.040";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("CREATE TABLE IF NOT EXISTS marc_modification_templates (
+              template_id int(11) NOT NULL auto_increment,
+              name text NOT NULL,
+              PRIMARY KEY  (template_id)
+              ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;"
+    );
+
+    $dbh->do("
+      CREATE TABLE IF NOT EXISTS marc_modification_template_actions (
+      mmta_id int(11) NOT NULL auto_increment,
+      template_id int(11) NOT NULL,
+      ordering int(3) NOT NULL,
+      action enum('delete_field','update_field','move_field','copy_field') NOT NULL,
+      field_number smallint(6) NOT NULL default '0',
+      from_field varchar(3) NOT NULL,
+      from_subfield varchar(1) NULL,
+      field_value varchar(100) default NULL,
+      to_field varchar(3) default NULL,
+      to_subfield varchar(1) default NULL,
+      to_regex_search text,
+      to_regex_replace text,
+      to_regex_modifiers varchar(8) default '',
+      conditional enum('if','unless') default NULL,
+      conditional_field varchar(3) default NULL,
+      conditional_subfield varchar(1) default NULL,
+      conditional_comparison enum('exists','not_exists','equals','not_equals') default NULL,
+      conditional_value text,
+      conditional_regex tinyint(1) NOT NULL default '0',
+      description text,
+      PRIMARY KEY  (mmta_id),
+      CONSTRAINT `mmta_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `marc_modification_templates` (`template_id`) ON DELETE CASCADE ON UPDATE CASCADE
+      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+    ");
+
+    $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ('13', 'marc_modification_templates', 'Manage marc modification templates')");
+
+    print "Upgrade to $DBversion done ( Bug 8015: Added tables for MARC Modification Framework )\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.041";
+if(CheckVersion($DBversion)) {
+    $dbh->do(q{
+        INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AcqItemSetSubfieldsWhenReceived','','Set subfields for item when items are created when receiving (e.g. o=5|a="foo bar")','','Free');
+    });
+    print "Upgrade to $DBversion done (Added AcqItemSetSubfieldsWhenReceived syspref)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.042";
+if(CheckVersion($DBversion)) {
+    print "Upgrade to $DBversion done (Koha 3.14 beta)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.043";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES('SearchEngine','Zebra','Solr|Zebra','Search Engine','Choice')");
+    print "Upgrade to $DBversion done (Bug 11196: Add system preference SearchEngine if missing )\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.14.00.000";
+if ( CheckVersion($DBversion) ) {
+    print "Upgrade to $DBversion done (3.14.0 release)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.15.00.000';
+if ( CheckVersion($DBversion) ) {
+    print "Upgrade to $DBversion done (the road goes ever on)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.001";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("UPDATE systempreferences SET value='clear' where variable = 'CircAutoPrintQuickSlip' and value = '0'");
+    $dbh->do("UPDATE systempreferences SET value='qslip' where variable = 'CircAutoPrintQuickSlip' and value = '1'");
+    $dbh->do("UPDATE systempreferences SET explanation = 'Choose what should happen when an empty barcode field is submitted in circulation: Display a print quick slip window, Display a print slip window or Clear the screen.', type = 'Choice' where variable = 'CircAutoPrintQuickSlip'");
+    print "Upgrade to $DBversion done (Bug 11040: Add option to print full slip when checking out a null barcode)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.002";
+if(CheckVersion($DBversion)) {
+    $dbh->do("ALTER TABLE deleteditems MODIFY materials text;");
+    print "Upgrade to $DBversion done (Bug 11275: alter deleteditems.materials from varchar(10) to text)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.003";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        UPDATE accountlines
+        SET description = ''
+        WHERE description IN (
+            ' New Card',
+            ' Fine',
+            ' Sundry',
+            'Writeoff',
+            ' Account Management fee',
+            'Payment,thanks', 'Payment,thanks - ',
+            ' Lost Item'
+        )
+    });
+    print "Upgrade to $DBversion done (Bug 2546: Update fine descriptions)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.004";
+if ( CheckVersion($DBversion) ) {
+    if ( C4::Context->preference("marcflavour") eq 'MARC21' ) {
+        $dbh->do(qq{
+            INSERT IGNORE INTO marc_subfield_structure (tagfield, tagsubfield, liblibrarian, libopac, repeatable, mandatory,
+            kohafield, tab, authorised_value, authtypecode, value_builder, isurl, hidden, frameworkcode, seealso, link,
+            defaultvalue) VALUES
+            ('015', 'q', 'Qualifying information', 'Qualifying information', 1, 0, '', 0, '', '', '', 0, 0, '', '', '', NULL),
+            ('020', 'q', 'Qualifying information', 'Qualifying information', 1, 0, '', 0, '', '', '', 0, 0, '', '', '', NULL),
+            ('024', 'q', 'Qualifying information', 'Qualifying information', 1, 0, '', 0, '', '', '', 0, 0, '', '', '', NULL),
+            ('027', 'q', 'Qualifying information', 'Qualifying information', 1, 0, '', 0, '', '', '', 0, 0, '', '', '', NULL),
+            ('800', '7', 'Control subfield', 'Control subfield', 0, 0, '', 8, '', '', '', NULL, -6, '', '', '', NULL),
+            ('810', '7', 'Control subfield', 'Control subfield', 0, 0, '', 8, '', '', '', NULL, -6, '', '', '', NULL),
+            ('811', '7', 'Control subfield', 'Control subfield', 0, 0, '', 8, '', '', '', NULL, -6, '', '', '', NULL),
+            ('830', '7', 'Control subfield', 'Control subfield', 0, 0, '', 8, '', '', '', NULL, -6, '', '', '', NULL);
+        });
+        $dbh->do(qq{
+            INSERT IGNORE INTO auth_subfield_structure (authtypecode, tagfield, tagsubfield, liblibrarian, libopac, repeatable,
+            mandatory, tab, authorised_value, value_builder, seealso, isurl, hidden, linkid, kohafield, frameworkcode) VALUES
+            ('', '020', 'q', 'Qualifying information', 'Qualifying information', 1, 0, 0, NULL, NULL, NULL, 0, 0, '', '', ''),
+            ('', '024', 'q', 'Qualifying information', 'Qualifying information', 1, 0, 0, NULL, NULL, NULL, 0, 0, '', '', '');
+        });
+    }
+    print "Upgrade to $DBversion done (Bug 10970 - Update MARC21 frameworks to Update Nr. 17 - DB update)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.005";
+if ( CheckVersion($DBversion) ) {
+   $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('AcquisitionDetails', '1', '', 'Hide/Show acquisition details on the biblio detail page.', 'YesNo');");
+   print "Upgrade to $DBversion done (Bug 8230: Add AcquisitionDetails system preference)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.006";
+if(CheckVersion($DBversion)) {
+    $dbh->do(q{
+        ALTER TABLE `borrowers`
+        ADD KEY `surname_idx` (`surname`(255)),
+        ADD KEY `firstname_idx` (`firstname`(255)),
+        ADD KEY `othernames_idx` (`othernames`(255))
+    });
+    print "Upgrade to $DBversion done (Bug 11249 - Add DB indexes on borrower names)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.007";
+if ( CheckVersion($DBversion) ) {
+   $dbh->do("ALTER TABLE items ADD itemlost_on DATETIME NULL AFTER itemlost");
+   $dbh->do("ALTER TABLE items ADD withdrawn_on DATETIME NULL AFTER withdrawn");
+   $dbh->do("ALTER TABLE deleteditems ADD itemlost_on DATETIME NULL AFTER itemlost");
+   $dbh->do("ALTER TABLE deleteditems ADD withdrawn_on DATETIME NULL AFTER withdrawn");
+   print "Upgrade to $DBversion done (Bug 9673 - Track when items are marked as lost or withdrawn)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.008";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        ALTER TABLE collections_tracking CHANGE ctId collections_tracking_id integer(11) NOT NULL auto_increment;
+    });
+    print "Upgrade to $DBversion done (Bug 11384) - change name of collections_tracker.ctId column)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.009";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        ALTER TABLE suggestions MODIFY suggesteddate DATE NOT NULL
+    });
+    print "Upgrade to $DBversion done (Bug 11391) - drop default value on suggestions.suggesteddate column)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.010";
+if(CheckVersion($DBversion)) {
+    $dbh->do("ALTER TABLE deleteditems DROP COLUMN marc");
+    print "Upgrade to $DBversion done (Bug 6331: remove obsolete column in deleteditems.marc)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.011";
+if(CheckVersion($DBversion)) {
+    $dbh->do("UPDATE marc_subfield_structure SET maxlength=9999 WHERE maxlength IS NULL OR maxlength=0;");
+    print "Upgrade to $DBversion done (Bug 8018: set 9999 as default max length for subfields)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.15.00.012";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'force_checkout', 'Force checkout if a limitation exists')
+    });
+    $dbh->do(q{
+        INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'manage_restrictions', 'Manage restrictions for accounts')
+    });
+    $dbh->do(q{
+        INSERT INTO user_permissions (borrowernumber, module_bit, code)
+            SELECT user_permissions.borrowernumber, 1, 'force_checkout'
+            FROM user_permissions
+            LEFT JOIN borrowers USING(borrowernumber)
+            WHERE borrowers.flags & (1 << 1)
+    });
+    $dbh->do(q{
+        INSERT INTO user_permissions (borrowernumber, module_bit, code)
+            SELECT user_permissions.borrowernumber, 1, 'manage_restrictions'
+            FROM user_permissions
+            LEFT JOIN borrowers USING(borrowernumber)
+            WHERE borrowers.flags & (1 << 1)
+    });
+
+    print "Upgrade to $DBversion done (Bug 10863 - Add permissions force_checkout and manage_restrictions)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.013";
+if(CheckVersion($DBversion)) {
+    $dbh->do(q{
+        UPDATE systempreferences
+        SET explanation = 'Upon receiving items, update their subfields if they were created when placing an order (e.g. o=5|a="foo bar")'
+        WHERE variable = "AcqItemSetSubfieldsWhenReceived"
+    });
+
+    $dbh->do(q{
+        UPDATE systempreferences
+        SET value = ''
+        WHERE variable = "AcqItemSetSubfieldsWhenReceived"
+            AND value = "0"
+    });
+    print "Upgrade to $DBversion done (Bug 11237: Update explanation and default value for AcqItemSetSubfieldsWhenReceived syspref)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.014";
+if (CheckVersion($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('SelfCheckReceiptPrompt', '1', 'NULL', 'If ON, print receipt dialog pops up when self checkout is finished.', 'YesNo');");
+    print "Upgrade to $DBversion done (Bug 11415: add system preference for automatic self checkout receipt printing)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.015";
+if (CheckVersion($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences ( variable, value, options, explanation, type ) VALUES
+        ('OpacSuggestionManagedBy',1,'','Show the name of the staff member who managed a suggestion in OPAC','YesNo');");
+    print "Upgrade to $DBversion done (Bug 10907: Add OpacSuggestionManagedBy system preference)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.016";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE biblioitems CHANGE url url TEXT NULL DEFAULT NULL");
+    $dbh->do("ALTER TABLE deletedbiblioitems CHANGE url url TEXT NULL DEFAULT NULL");
+    print "Upgrade to $DBversion done (Bug 11268 - Biblioitems URL field is too small for some URLs)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.15.00.017";
+if(CheckVersion($DBversion)) {
+    $dbh->do(q{
+        UPDATE systempreferences
+        SET explanation = 'Define the contents of UNIMARC authority control field 100 position 08-35'
+        WHERE variable = "UNIMARCAuthorityField100"
+    });
+    $dbh->do(q{
+        UPDATE systempreferences
+        SET explanation = 'Define the contents of MARC21 authority control field 008 position 06-39'
+        WHERE variable = "MARCAuthorityControlField008"
+    });
+    $dbh->do(q{
+        UPDATE systempreferences
+        SET explanation = 'Define MARC Organization Code for MARC21 records - http://www.loc.gov/marc/organizations/orgshome.html'
+        WHERE variable = "MARCOrgCode"
+    });
+    print "Upgrade to $DBversion done (Bug 11611 - fix possible confusion between UNIMARC and MARC21 in some sysprefs)\n";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)