Bug 10636: DBrev 3.13.00.030
[koha.git] / installer / data / mysql / updatedatabase.pl
index 1f7b491..5c020cb 100755 (executable)
@@ -7036,7 +7036,6 @@ if ( CheckVersion($DBversion) ) {
     SetVersion($DBversion);
 }
 
-
 $DBversion = "3.13.00.012";
 if ( CheckVersion($DBversion) ) {
     $dbh->do("ALTER TABLE issuingrules MODIFY COLUMN overduefinescap decimal(28,6) DEFAULT NULL;");
@@ -7044,6 +7043,226 @@ if ( CheckVersion($DBversion) ) {
     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.025";
+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);
+}
+
+$DBversion = "3.13.00.026";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q|
+        ALTER TABLE auth_subfield_structure ADD COLUMN defaultvalue TEXT DEFAULT NULL AFTER frameworkcode
+    |);
+    print "Upgrade to $DBversion done (Bug 10602: Add the column auth_subfield_structure.defaultvalue)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.027";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('AllowOfflineCirculation','0','','If on, enables HTML5 offline circulation functionality.','YesNo')");
+    print "Upgrade to $DBversion done (Bug 10240: Add syspref AllowOfflineCirculation)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.13.00.028";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        ALTER TABLE export_format ADD type VARCHAR(255) DEFAULT 'marc' AFTER encoding
+    });
+    $dbh->do(q{
+        ALTER TABLE export_format CHANGE marcfields content mediumtext NOT NULL
+    });
+    print "Upgrade to $DBversion done (Bug 10853: Add new field export_format.type and rename export_format.marcfields with export_format.content)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.029";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(q{
+        INSERT IGNORE INTO export_format( profile, description, content, csv_separator, type ) 
+        VALUES ( "issues to claim", "efault CSV export for serial issue claims",
+                "SUPPLIER=aqbooksellers.name|TITLE=subscription.title|ISSUE NUMBER=serial.serialseq|LATE SINCE=serial.planneddate", 
+                ",", "sql" )
+    });
+    print "Upgrade to $DBversion done (Bug 10854: Add the default CSV profile for claiming issues)\n";
+    SetVersion($DBversion);
+}
+
+$DBversion = "3.13.00.030";
+if ( CheckVersion($DBversion) ) {
+    $dbh->do(qq{
+        DELETE FROM patronimage WHERE NOT EXISTS (SELECT * FROM borrowers WHERE borrowers.cardnumber = patronimage.cardnumber)
+    });
+
+    $dbh->do(qq{
+        ALTER TABLE patronimage ADD borrowernumber INT( 11 ) NULL FIRST
+    });
+
+    $dbh->{AutoCommit} = 0;
+    $dbh->{RaiseError} = 1;
+
+    eval {
+        $dbh->do(qq{
+            UPDATE patronimage LEFT JOIN borrowers USING ( cardnumber ) SET patronimage.borrowernumber = borrowers.borrowernumber
+        });
+        $dbh->commit();
+    };
+
+    if ($@) {
+        print "Upgrade to $DBversion done (Bug 10636 - patronimage should have borrowernumber as PK, not cardnumber) failed! Transaction aborted because $@\n";
+        eval { $dbh->rollback };
+    }
+    else {
+        $dbh->do(qq{
+            ALTER TABLE patronimage DROP FOREIGN KEY patronimage_fk1
+        });
+        $dbh->do(qq{
+            ALTER TABLE patronimage DROP PRIMARY KEY, ADD PRIMARY KEY( borrowernumber )
+        });
+        $dbh->do(qq{
+            ALTER TABLE patronimage DROP cardnumber
+        });
+        $dbh->do(qq{
+            ALTER TABLE patronimage ADD FOREIGN KEY ( borrowernumber ) REFERENCES borrowers ( borrowernumber ) ON DELETE CASCADE ON UPDATE CASCADE
+        });
+
+        print "Upgrade to $DBversion done (Bug 10636 - patronimage should have borrowernumber as PK, not cardnumber)\n";
+        SetVersion($DBversion);
+    }
+
+    $dbh->{AutoCommit} = 1;
+    $dbh->{RaiseError} = 0;
+}
+
+
 =head1 FUNCTIONS
 
 =head2 TableExists($table)