Bug 8585 : Add System Preference to specify Holds to Pull List Start Date
[koha.git] / installer / data / mysql / updatedatabase.pl
index 6eb9c74..63b8803 100755 (executable)
@@ -5617,7 +5617,6 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
 
     $dbh->do("UPDATE systempreferences SET options = concat(options,'|EAN13'), explanation = concat(explanation,'; EAN13 - incremental') WHERE variable = 'autoBarcode' AND options NOT LIKE '%EAN13%'");
     print "Upgrade to $DBversion done ( Added EAN13 barcode autogeneration sequence )\n";
-
     SetVersion($DBversion);
 }
 
@@ -5669,6 +5668,337 @@ if(C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     $dbh->do("UPDATE auth_subfield_structure SET frameworkcode = 'PERSO_NAME' WHERE frameworkcode = 'PERSO_CODE'");
     $dbh->do("UPDATE auth_subfield_structure SET frameworkcode = 'CORPO_NAME' WHERE frameworkcode = 'ORGO_CODE'");
     print "Upgrade to $DBversion done (Bug 8207: correct typo in authority types)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.09.00.035";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("
+    INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('PrefillItem','0','When a new item is added, should it be prefilled with last created item values?','','YesNo');
+    ");
+    $dbh->do(
+    "INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SubfieldsToUseWhenPrefill','','Define a list of subfields to use when prefilling items (separated by space)','','Free');
+    ");
+    print "Upgrade to $DBversion done (Adding PrefillItem and SubfieldsToUseWhenPrefill sysprefs)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.09.00.036";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    # biblioitems changes
+    $dbh->do("ALTER TABLE biblioitems ADD COLUMN agerestriction VARCHAR(255) DEFAULT NULL AFTER cn_sort");
+    $dbh->do("ALTER TABLE deletedbiblioitems ADD COLUMN agerestriction VARCHAR(255) DEFAULT NULL AFTER cn_sort");
+    # preferences changes
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AgeRestrictionMarker','','Markers for age restriction indication, e.g. FSK|PEGI|Age|. See: http://wiki.koha-community.org/wiki/Age_restriction',NULL,'free')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AgeRestrictionOverride',0,'Allow staff to check out an item with age restriction.',NULL,'YesNo')");
+
+    print "Upgrade to $DBversion done (Add colum agerestriction to biblioitems and deletedbiblioitems, add system preferences AgeRestrictionMarker and AgeRestrictionOverride)\n";
+   SetVersion ($DBversion);
+}
+
+$DBversion = "3.09.00.037";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('UseTransportCostMatrix',0,'Use Transport Cost Matrix when filling holds','','YesNo')");
+
+ $dbh->do("CREATE TABLE `transport_cost` (
+              `frombranch` varchar(10) NOT NULL,
+              `tobranch` varchar(10) NOT NULL,
+              `cost` decimal(6,2) NOT NULL,
+              `disable_transfer` tinyint(1) NOT NULL DEFAULT 0,
+              CHECK ( `frombranch` <> `tobranch` ), -- a dud check, mysql does not support that
+              PRIMARY KEY (`frombranch`, `tobranch`),
+              CONSTRAINT `transport_cost_ibfk_1` FOREIGN KEY (`frombranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE,
+              CONSTRAINT `transport_cost_ibfk_2` FOREIGN KEY (`tobranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
+          ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+    print "Upgrade to $DBversion done (creating `transport_cost` table; adding UseTransportCostMatrix systempref, in circulation)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion ="3.09.00.038";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE borrower_attributes CHANGE  attribute  attribute VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL");
+    print "Upgrade to $DBversion done (Increase the maximum size of a borrower attribute value)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion ="3.09.00.039";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,type) VALUES('DidYouMeanFromAuthorities','0','Suggest searches based on authority file.','YesNo');");
+    print "Upgrade to $DBversion done (Add system preference DidYouMeanFromAuthorities)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.09.00.040";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('IncludeSeeFromInSearches','0','','Include see-from references in searches.','YesNo');");
+    print "Upgrade to $DBversion done (Add IncludeSeeFromInSearches system preference)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.09.00.041";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do(qq{
+        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('ExportRemoveFields','','List of fields for non export in circulation.pl (separated by a space)','','');
+    });
+    print "Upgrade to $DBversion done (Add system preference ExportRemoveFields)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.09.00.042";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do(qq{
+        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('ExportWithCsvProfile','','Set a profile name for CSV export','','');
+    });
+    print "Upgrade to $DBversion done (Adds New System preference ExportWithCsvProfile)\n";
+    SetVersion($DBversion)
+}
+
+$DBversion = "3.09.00.043";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("
+        ALTER TABLE aqorders
+        ADD parent_ordernumber int(11) DEFAULT NULL
+    ");
+    $dbh->do("
+        UPDATE aqorders
+        SET parent_ordernumber = ordernumber;
+    ");
+    print "Upgrade to $DBversion done (Adding parent_ordernumber in aqorders)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = '3.09.00.044';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE statistics ADD COLUMN ccode VARCHAR ( 10 ) NULL AFTER associatedborrower");
+    $dbh->do("UPDATE statistics SET statistics.ccode = ( SELECT items.ccode FROM items WHERE statistics.itemnumber = items.itemnumber )");
+    $dbh->do("UPDATE statistics SET statistics.ccode = (
+              SELECT deleteditems.ccode FROM deleteditems
+                  WHERE statistics.itemnumber = deleteditems.itemnumber
+              ) WHERE statistics.ccode IS NULL");
+    print "Upgrade done ( Added Collection Code to Statistics table. )\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.09.00.045";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE borrower_attribute_types MODIFY category_code VARCHAR( 10 ) NULL DEFAULT NULL");
+    print "Upgrade to $DBversion done. (Bug 8002: Update patron attribute types table from varchar(1) to varchar(10) category_code)\nWarning to Koha System Administrators: If you use borrower attributes defined by borrower categories, you have to check your configuration. A bug may have removed your attribute links to borrower categories.\nPlease check, and fix it if necessary.";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.09.00.046";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE `accountlines` ADD `accountlines_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST;");
+    print "Upgrade to $DBversion done (adding accountlines_id field in accountlines table)\n";
+    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
+    my $prefvalue = 'anywhere';
+    if (C4::Context->preference("IndependantBranches")) { $prefvalue = 'homeorholdingbranch';}
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowReturnToBranch', '$prefvalue', 'Where an item may be returned', 'anywhere|homebranch|holdingbranch|homeorholdingbranch', 'Choice');");
+
+    print "Upgrade to $DBversion done: adding AllowReturnToBranch syspref (bug 6151)";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.09.00.048";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE authorised_values MODIFY lib varchar(200)");
+    $dbh->do("ALTER TABLE authorised_values MODIFY lib_opac varchar(200)");
+
+    print "Upgrade to $DBversion done (Raise the length of Authorised Values descriptions)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion ="3.09.00.049";
+if(C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OPACMobileUserCSS','','Include the following CSS for the mobile view on all pages in the OPAC:',NULL,'free');");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacMainUserBlockMobile','','Show the following HTML in its own column on the main page of the OPAC (mobile version):',NULL,'free');");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowLibrariesPulldownMobile','1','Show the libraries pulldown on the mobile version of the OPAC.',NULL,'YesNo');");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowFiltersPulldownMobile','1','Show the search filters pulldown on the mobile version of the OPAC.',NULL,'YesNo');");
+    print "Upgrade to $DBversion done (Add OPACMobileUserCSS, OpacMainUserBlockMobile, OpacShowLibrariesPulldownMobile and OpacShowFiltersPulldownMobile sysprefs)\n";
+    SetVersion($DBversion);
+}
+
+
+
+$DBversion = "3.09.00.050";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE authorised_values MODIFY category varchar(16) NOT NULL DEFAULT '';");
+    $dbh->do("INSERT INTO authorised_values (category, authorised_value, lib) VALUES
+              ('REPORT_GROUP', 'CIRC', 'Circulation'),
+              ('REPORT_GROUP', 'CAT', 'Catalog'),
+              ('REPORT_GROUP', 'PAT', 'Patrons'),
+              ('REPORT_GROUP', 'ACQ', 'Acquisitions'),
+              ('REPORT_GROUP', 'ACC', 'Accounts');");
+
+    $dbh->do("ALTER TABLE reports_dictionary ADD report_area varchar(6) DEFAULT NULL;");
+    $dbh->do("UPDATE reports_dictionary SET report_area = CASE area
+                  WHEN 1 THEN 'CIRC'
+                  WHEN 2 THEN 'CAT'
+                  WHEN 3 THEN 'PAT'
+                  WHEN 4 THEN 'ACQ'
+                  WHEN 5 THEN 'ACC'
+                  END;");
+    $dbh->do("ALTER TABLE reports_dictionary DROP area;");
+    $dbh->do("ALTER TABLE reports_dictionary ADD KEY dictionary_area_idx (report_area);");
+
+    $dbh->do("ALTER TABLE saved_sql ADD report_area varchar(6) DEFAULT NULL;");
+    $dbh->do("ALTER TABLE saved_sql ADD report_group varchar(80) DEFAULT NULL;");
+    $dbh->do("ALTER TABLE saved_sql ADD report_subgroup varchar(80) DEFAULT NULL;");
+    $dbh->do("ALTER TABLE saved_sql ADD KEY sql_area_group_idx (report_group, report_subgroup);");
+
+    print "Upgrade to $DBversion done saved_sql new fields report_group and report_area; authorised_values.category 16 char \n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.09.00.051";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("
+        CREATE TABLE aqinvoices (
+          invoiceid int(11) NOT NULL AUTO_INCREMENT,
+          invoicenumber mediumtext NOT NULL,
+          booksellerid int(11) NOT NULL,
+          shipmentdate date default NULL,
+          billingdate date default NULL,
+          closedate date default NULL,
+          shipmentcost decimal(28,6) default NULL,
+          shipmentcost_budgetid int(11) default NULL,
+          PRIMARY KEY (invoiceid),
+          CONSTRAINT aqinvoices_fk_aqbooksellerid FOREIGN KEY (booksellerid) REFERENCES aqbooksellers (id) ON DELETE CASCADE ON UPDATE CASCADE,
+          CONSTRAINT aqinvoices_fk_shipmentcost_budgetid FOREIGN KEY (shipmentcost_budgetid) REFERENCES aqbudgets (budget_id) ON DELETE SET NULL ON UPDATE CASCADE
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8
+    ");
+
+    # Fill this new table with existing invoices
+    my $sth = $dbh->prepare("
+        SELECT aqorders.booksellerinvoicenumber AS invoicenumber, aqbasket.booksellerid, aqorders.datereceived
+        FROM aqorders
+          LEFT JOIN aqbasket ON aqorders.basketno = aqbasket.basketno
+        WHERE aqorders.booksellerinvoicenumber IS NOT NULL
+          AND aqorders.booksellerinvoicenumber != ''
+        GROUP BY aqorders.booksellerinvoicenumber
+    ");
+    $sth->execute;
+    my $results = $sth->fetchall_arrayref({});
+    $sth = $dbh->prepare("
+        INSERT INTO aqinvoices (invoicenumber, booksellerid, shipmentdate) VALUES (?,?,?)
+    ");
+    foreach(@$results) {
+        $sth->execute($_->{invoicenumber}, $_->{booksellerid}, $_->{datereceived});
+    }
+
+    # Add the column in aqorders, fill it with correct value
+    # and then drop booksellerinvoicenumber column
+    $dbh->do("
+        ALTER TABLE aqorders
+        ADD COLUMN invoiceid int(11) default NULL AFTER booksellerinvoicenumber,
+        ADD CONSTRAINT aqorders_ibfk_3 FOREIGN KEY (invoiceid) REFERENCES aqinvoices (invoiceid) ON DELETE SET NULL ON UPDATE CASCADE
+    ");
+
+    $dbh->do("
+        UPDATE aqorders, aqinvoices
+        SET aqorders.invoiceid = aqinvoices.invoiceid
+        WHERE aqorders.booksellerinvoicenumber = aqinvoices.invoicenumber
+    ");
+
+    $dbh->do("
+        ALTER TABLE aqorders
+        DROP COLUMN booksellerinvoicenumber
+    ");
+
+    print "Upgrade to $DBversion done (Add aqinvoices table) \n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.09.00.052";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('decreaseLoanHighHolds', NULL, '', 'Decreases the loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue', 'YesNo');");
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('decreaseLoanHighHoldsValue', NULL, '', 'Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)', 'Integer');");
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('decreaseLoanHighHoldsDuration', NULL, '', 'Specifies a number of days that a loan is reduced to when used in conjunction with decreaseLoanHighHolds', 'Integer');");
+    print "Upgrade to $DBversion done (Add systempreferences to decrease loan length on high demand items decreaseLoanHighHolds, decreaseLoanHighHoldsValue and decreaseLoanHighHoldsDuration) \n";
+    SetVersion ($DBversion);
+}
+
+
+$DBversion = "3.09.00.053";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do(
+    q|CREATE TABLE `import_auths` (
+        import_record_id int(11) NOT NULL,
+        matched_authid int(11) default NULL,
+        control_number varchar(25) default NULL,
+        authorized_heading varchar(128) default NULL,
+        original_source varchar(25) default NULL,
+        CONSTRAINT import_auths_ibfk_1 FOREIGN KEY (import_record_id)
+        REFERENCES import_records (import_record_id) ON DELETE CASCADE ON UPDATE CASCADE,
+        KEY matched_authid (matched_authid)
+        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;|
+    );
+    $dbh->do("ALTER TABLE import_batches
+                CHANGE COLUMN num_biblios num_records int(11) NOT NULL default 0,
+                ADD COLUMN record_type enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio'");
+    $dbh->do("UPDATE import_batches SET record_type='auth' WHERE import_batch_id IN
+                (SELECT import_batch_id FROM import_records WHERE record_type='auth')");
+    
+    print "Upgrade to $DBversion done (Added support for staging authorities)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.09.00.054";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE aqorders CHANGE COLUMN gst gstrate DECIMAL(6,4)  DEFAULT NULL");
+    print "Upgrade to $DBversion done (Change column name in aqorders gst --> gstrate)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.09.00.055";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE aqorders ADD discount float(6,4) DEFAULT NULL AFTER gstrate");
+    print "Upgrade to $DBversion done (Add discount field in aqorders table)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion ="3.09.00.056";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('AuthDisplayHierarchy','0','Display authority hierarchies','','YesNo')");
+    print "Upgrade to $DBversion done (Add system preference AuthDisplayHierarchy)\n";
+    SetVersion($DBversion);
+}
+
+
+$DBversion = "3.09.00.057";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE aqbasket ADD deliveryplace VARCHAR(10) default NULL AFTER basketgroupid;");
+    $dbh->do("ALTER TABLE aqbasket ADD billingplace VARCHAR(10) default NULL AFTER deliveryplace;");
+    print "Upgrade to $DBversion done (Bug 5356: Added billingplace, deliveryplace to the aqbasket table)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion ="3.09.00.058";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,type) VALUES('OPACdidyoumean',NULL,'Did you mean? configuration for the OPAC. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free');");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,type) VALUES('INTRAdidyoumean',NULL,'Did you mean? configuration for the Intranet. Do not change, as this is controlled by /cgi-bin/koha/admin/didyoumean.pl.','Free');");
+    print "Upgrade to $DBversion done (Add Did You Mean? configuration)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion ="3.09.00.059";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable, value, options, explanation, type) VALUES ('BlockReturnOfWithdrawnItems', '1', '0', 'If enabled, items that are marked as withdrawn cannot be returned.', 'YesNo');");
+    print "Upgrade to $DBversion done (Add system preference BlockReturnOfWithdrawnItems)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "XXX";
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('HoldsToPullStartDate','2','Set the default start date for the Holds to pull list to this many days ago',NULL,'Integer')");
+    print "Upgrade to $DBversion done (Added HoldsToPullStartDate syspref)\n";
     SetVersion($DBversion);
 }
 
@@ -5694,8 +6024,6 @@ sub TableExists {
 Drop all foreign keys of the table $table
 
 =cut
-
-
 sub DropAllForeignKeys {
     my ($table) = @_;
     # get the table description
@@ -5756,4 +6084,3 @@ sub SetVersion {
     C4::Context::clear_syspref_cache(); # invalidate cached preferences
 }
 exit;
-