+$DBversion = '3.09.00.027';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("ALTER TABLE issuingrules ADD overduefinescap decimal 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);
+ $dbh->do("UPDATE systempreferences SET value = NULL WHERE variable = 'MaxFine'");
+ }
+ $dbh->do("UPDATE systempreferences SET explanation = 'Maximum fine a patron can have for all late returns at one moment. Single item caps are specified in the circulation rules matrix.' WHERE variable = 'MaxFine'");
+ print "Upgrade to $DBversion done (Bug 7420 add overduefinescap to circulation matrix)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.09.00.028";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ unless ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) {
+ my %referencetypes = ( '00' => 'PERSO_CODE',
+ '10' => 'ORGO_CODE',
+ '11' => 'MEETI_NAME',
+ '30' => 'UNIF_TITLE',
+ '48' => 'CHRON_TERM',
+ '50' => 'TOPIC_TERM',
+ '51' => 'GEOGR_NAME',
+ '55' => 'GENRE/FORM'
+ );
+ my $query = q{SELECT DISTINCT authtypecode, tagfield
+ FROM auth_subfield_structure
+ WHERE (tagfield BETWEEN '400' AND '455' OR
+ tagfield BETWEEN '500' and '555') AND tagsubfield='a' AND
+ frameworkcode = '' AND ROW(authtypecode, tagfield) NOT IN
+ (SELECT authtypecode, tagfield FROM auth_subfield_structure
+ WHERE tagsubfield ='9' )};
+ $sth = $dbh->prepare($query);
+ $sth->execute;
+ my $sth2 = $dbh->prepare(q{INSERT INTO auth_subfield_structure
+ (authtypecode, tagfield, tagsubfield, liblibrarian, libopac,
+ repeatable, mandatory, tab, authorised_value, value_builder,
+ seealso, isurl, hidden, linkid, kohafield, frameworkcode)
+ VALUES (?, ?, '9', '9 (RLIN)', '9 (RLIN)', 0, 0, ?, NULL, NULL,
+ NULL, 0, 1, '', '', '')});
+ my $sth3 = $dbh->prepare(q{UPDATE auth_subfield_structure SET
+ frameworkcode = ? WHERE authtypecode = ? AND
+ tagfield = ? AND tagsubfield = 'a'});
+ while (my $row = $sth->fetchrow_arrayref()) {
+ my ($authtypecode, $field) = @$row;
+ $sth2->execute($authtypecode, $field, substr($field, 0, 1));
+ my $authtypemarker = substr $field, 1, 2;
+ if ($authtypemarker && $referencetypes{$authtypemarker}) {
+ $sth3->execute($referencetypes{$authtypemarker}, $authtypecode, $field);
+ }
+ }
+ }
+
+ print "Upgrade to $DBversion done (Add thesaurus links for MARC21/NORMARC)\n";
+ SetVersion($DBversion);
+}
+
+$DBversion = "3.09.00.029"; # FIXME
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+ $dbh->do("UPDATE systempreferences SET options=concat(options,'|EAN13') WHERE variable='itemBarcodeInputFilter' AND options NOT LIKE '%EAN13%'");
+ print "Upgrade to $DBversion done (Add itemBarcodeInputFilter choice EAN13)\n";
+
+ $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);
+}
+
+$DBversion ="3.09.00.030";
+if(C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+ my $query = "SELECT value FROM systempreferences WHERE variable='opacstylesheet'";
+ my $remote= $dbh->selectrow_arrayref($query);
+ $dbh->do("DELETE from systempreferences WHERE variable='opacstylesheet'");
+ if($remote && $remote->[0]) {
+ $query="UPDATE systempreferences SET value=? WHERE variable='opaclayoutstylesheet'";
+ $dbh->do($query,undef,$remote->[0]);
+ print "NOTE: The URL of your remote opac css file has been moved to preference opaclayoutstylesheet.\n";
+ }
+ print "Upgrade to $DBversion done (BZ 8263: Make OPAC stylesheet preferences more consistent)\n";
+ SetVersion($DBversion);
+}
+
+$DBversion = "3.09.00.XXX";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("DELETE FROM systempreferences WHERE variable='AmazonReviews'");
+ $dbh->do("DELETE FROM systempreferences WHERE variable='AmazonSimilarItems'");
+ $dbh->do("DELETE FROM systempreferences WHERE variable='AWSAccessKeyID'");
+ $dbh->do("DELETE FROM systempreferences WHERE variable='AWSPrivateKey'");
+ $dbh->do("DELETE FROM systempreferences WHERE variable='OPACAmazonReviews'");
+ $dbh->do("DELETE FROM systempreferences WHERE variable='OPACAmazonSimilarItems'");
+ $dbh->do("DELETE FROM systempreferences WHERE variable='AmazonEnabled'");
+ $dbh->do("DELETE FROM systempreferences WHERE variable='OPACAmazonEnabled'");
+ print "Upgrade to $DBversion done ('Remove preferences controlling broken Amazon features (Bug 8679')\n";
+ SetVersion ($DBversion);
+}
+