+ print "Upgrade to $DBversion done (Updating patronimages syspref to reflect current kohastructure.sql. ) \n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.068";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("CREATE TABLE `permissions` (
+ `module_bit` int(11) NOT NULL DEFAULT 0,
+ `code` varchar(30) DEFAULT NULL,
+ `description` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`module_bit`, `code`),
+ CONSTRAINT `permissions_ibfk_1` FOREIGN KEY (`module_bit`) REFERENCES `userflags` (`bit`)
+ ON DELETE CASCADE ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+ $dbh->do("CREATE TABLE `user_permissions` (
+ `borrowernumber` int(11) NOT NULL DEFAULT 0,
+ `module_bit` int(11) NOT NULL DEFAULT 0,
+ `code` varchar(30) DEFAULT NULL,
+ CONSTRAINT `user_permissions_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
+ ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `user_permissions_ibfk_2` FOREIGN KEY (`module_bit`, `code`)
+ REFERENCES `permissions` (`module_bit`, `code`)
+ ON DELETE CASCADE ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+ $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES
+ (13, 'edit_news', 'Write news for the OPAC and staff interfaces'),
+ (13, 'label_creator', 'Create printable labels and barcodes from catalog and patron data'),
+ (13, 'edit_calendar', 'Define days when the library is closed'),
+ (13, 'moderate_comments', 'Moderate patron comments'),
+ (13, 'edit_notices', 'Define notices'),
+ (13, 'edit_notice_status_triggers', 'Set notice/status triggers for overdue items'),
+ (13, 'view_system_logs', 'Browse the system logs'),
+ (13, 'inventory', 'Perform inventory (stocktaking) of your catalogue'),
+ (13, 'stage_marc_import', 'Stage MARC records into the reservoir'),
+ (13, 'manage_staged_marc', 'Managed staged MARC records, including completing and reversing imports'),
+ (13, 'export_catalog', 'Export bibliographic and holdings data'),
+ (13, 'import_patrons', 'Import patron data'),
+ (13, 'delete_anonymize_patrons', 'Delete old borrowers and anonymize circulation history (deletes borrower reading history)'),
+ (13, 'batch_upload_patron_images', 'Upload patron images in batch or one at a time'),
+ (13, 'schedule_tasks', 'Schedule tasks to run')");
+
+ $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('GranularPermissions','0','Use detailed staff user permissions',NULL,'YesNo')");
+
+ print "Upgrade to $DBversion done (adding permissions and user_permissions tables and GranularPermissions syspref) \n";
+ SetVersion ($DBversion);
+}
+$DBversion = "3.00.00.069";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("ALTER TABLE labels_conf CHANGE COLUMN class classification int(1) DEFAULT NULL;");
+ print "Upgrade to $DBversion done ( Correcting columname in labels_conf )\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.070";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='yuipath'");
+ $sth->execute;
+ my ($value) = $sth->fetchrow;
+ $value =~ s/2.3.1/2.5.1/;
+ $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='yuipath';");
+ print "Update yuipath syspref to 2.5.1 if necessary\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.071";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do(" ALTER TABLE `subscription` ADD `serialsadditems` TINYINT( 1 ) NOT NULL DEFAULT '0';");
+ # fill the new field with the previous systempreference value, then drop the syspref
+ my $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='serialsadditems'");
+ $sth->execute;
+ my ($serialsadditems) = $sth->fetchrow();
+ $dbh->do("UPDATE subscription SET serialsadditems=$serialsadditems");
+ $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
+ print "Upgrade to $DBversion done ( moving serialsadditems from syspref to subscription )\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.072";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("ALTER TABLE labels_conf ADD COLUMN formatstring VARCHAR(64) DEFAULT NULL AFTER printingtype");
+ print "Upgrade to $DBversion done ( Adding format string to labels generator. )\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.073";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("DROP TABLE IF EXISTS `tags_all`;");
+ $dbh->do(q#
+ CREATE TABLE `tags_all` (
+ `tag_id` int(11) NOT NULL auto_increment,
+ `borrowernumber` int(11) NOT NULL,
+ `biblionumber` int(11) NOT NULL,
+ `term` varchar(255) NOT NULL,
+ `language` int(4) default NULL,
+ `date_created` datetime NOT NULL,
+ PRIMARY KEY (`tag_id`),
+ KEY `tags_borrowers_fk_1` (`borrowernumber`),
+ KEY `tags_biblionumber_fk_1` (`biblionumber`),
+ CONSTRAINT `tags_borrowers_fk_1` FOREIGN KEY (`borrowernumber`)
+ REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `tags_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
+ REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+ #);
+ $dbh->do("DROP TABLE IF EXISTS `tags_approval`;");
+ $dbh->do(q#
+ CREATE TABLE `tags_approval` (
+ `term` varchar(255) NOT NULL,
+ `approved` int(1) NOT NULL default '0',
+ `date_approved` datetime default NULL,
+ `approved_by` int(11) default NULL,
+ `weight_total` int(9) NOT NULL default '1',
+ PRIMARY KEY (`term`),
+ KEY `tags_approval_borrowers_fk_1` (`approved_by`),
+ CONSTRAINT `tags_approval_borrowers_fk_1` FOREIGN KEY (`approved_by`)
+ REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+ #);
+ $dbh->do("DROP TABLE IF EXISTS `tags_index`;");
+ $dbh->do(q#
+ CREATE TABLE `tags_index` (
+ `term` varchar(255) NOT NULL,
+ `biblionumber` int(11) NOT NULL,
+ `weight` int(9) NOT NULL default '1',
+ PRIMARY KEY (`term`,`biblionumber`),
+ KEY `tags_index_biblionumber_fk_1` (`biblionumber`),
+ CONSTRAINT `tags_index_term_fk_1` FOREIGN KEY (`term`)
+ REFERENCES `tags_approval` (`term`) ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `tags_index_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
+ REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+ #);
+ $dbh->do(q#
+ INSERT INTO `systempreferences` VALUES
+ ('BakerTaylorBookstoreURL','','','URL template for \"My Libary Bookstore\" links, to which the \"key\" value is appended, and \"https://\" is prepended. It should include your hostname and \"Parent Number\". Make this variable empty to turn MLB links off. Example: ocls.mylibrarybookstore.com/MLB/actions/searchHandler.do?nextPage=bookDetails&parentNum=10923&key=',''),
+ ('BakerTaylorEnabled','0','','Enable or disable all Baker & Taylor features.','YesNo'),
+ ('BakerTaylorPassword','','','Baker & Taylor Password for Content Cafe (external content)','Textarea'),
+ ('BakerTaylorUsername','','','Baker & Taylor Username for Content Cafe (external content)','Textarea'),
+ ('TagsEnabled','1','','Enables or disables all tagging features. This is the main switch for tags.','YesNo'),
+ ('TagsExternalDictionary',NULL,'','Path on server to local ispell executable, used to set $Lingua::Ispell::path This dictionary is used as a \"whitelist\" of pre-allowed tags.',''),
+ ('TagsInputOnDetail','1','','Allow users to input tags from the detail page.', 'YesNo'),
+ ('TagsInputOnList', '0','','Allow users to input tags from the search results list.', 'YesNo'),
+ ('TagsModeration', NULL,'','Require tags from patrons to be approved before becoming visible.','YesNo'),
+ ('TagsShowOnDetail','10','','Number of tags to display on detail page. 0 is off.', 'Integer'),
+ ('TagsShowOnList', '6','','Number of tags to display on search results list. 0 is off.','Integer')
+ #);
+ print "Upgrade to $DBversion done (Baker/Taylor,Tags: sysprefs and tables (tags_all, tags_index, tags_approval)) \n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.074";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do( q(update itemtypes set imageurl = concat( 'npl/', imageurl )
+ where imageurl not like 'http%'
+ and imageurl is not NULL
+ and imageurl != '') );
+ print "Upgrade to $DBversion done (updating imagetype.imageurls to reflect new icon locations.)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.075";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do( q(alter table authorised_values add imageurl varchar(200) default NULL) );
+ print "Upgrade to $DBversion done (adding imageurl field to authorised_values table)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.076";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("ALTER TABLE import_batches
+ ADD COLUMN nomatch_action enum('create_new', 'ignore') NOT NULL default 'create_new' AFTER overlay_action");
+ $dbh->do("ALTER TABLE import_batches
+ ADD COLUMN item_action enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore')
+ NOT NULL default 'always_add' AFTER nomatch_action");
+ $dbh->do("ALTER TABLE import_batches
+ MODIFY overlay_action enum('replace', 'create_new', 'use_template', 'ignore')
+ NOT NULL default 'create_new'");
+ $dbh->do("ALTER TABLE import_records
+ MODIFY status enum('error', 'staged', 'imported', 'reverted', 'items_reverted',
+ 'ignored') NOT NULL default 'staged'");
+ $dbh->do("ALTER TABLE import_items
+ MODIFY status enum('error', 'staged', 'imported', 'reverted', 'ignored') NOT NULL default 'staged'");
+
+ print "Upgrade to $DBversion done (changes to import_batches and import_records)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.077";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ # drop these tables only if they exist and none of them are empty
+ # these tables are not defined in the packaged 2.2.9, but since it is believed
+ # that at least one library may be using them in a post-2.2.9 but pre-3.0 Koha,
+ # some care is taken.
+ my ($print_error) = $dbh->{PrintError};
+ $dbh->{PrintError} = 0;
+ my ($raise_error) = $dbh->{RaiseError};
+ $dbh->{RaiseError} = 1;
+
+ my $count = 0;
+ my $do_drop = 1;
+ eval { $count = $dbh->do("SELECT 1 FROM categorytable"); };
+ if ($count > 0) {
+ $do_drop = 0;
+ }
+ eval { $count = $dbh->do("SELECT 1 FROM mediatypetable"); };
+ if ($count > 0) {
+ $do_drop = 0;
+ }
+ eval { $count = $dbh->do("SELECT 1 FROM subcategorytable"); };
+ if ($count > 0) {
+ $do_drop = 0;
+ }
+
+ if ($do_drop) {
+ $dbh->do("DROP TABLE IF EXISTS `categorytable`");
+ $dbh->do("DROP TABLE IF EXISTS `mediatypetable`");
+ $dbh->do("DROP TABLE IF EXISTS `subcategorytable`");
+ }
+
+ $dbh->{PrintError} = $print_error;
+ $dbh->{RaiseError} = $raise_error;
+ print "Upgrade to $DBversion done (drop categorytable, subcategorytable, and mediatypetable)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.078";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ my ($print_error) = $dbh->{PrintError};
+ $dbh->{PrintError} = 0;
+
+ unless ($dbh->do("SELECT 1 FROM browser")) {
+ $dbh->{PrintError} = $print_error;
+ $dbh->do("CREATE TABLE `browser` (
+ `level` int(11) NOT NULL,
+ `classification` varchar(20) NOT NULL,
+ `description` varchar(255) NOT NULL,
+ `number` bigint(20) NOT NULL,
+ `endnode` tinyint(4) NOT NULL
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+ }
+ $dbh->{PrintError} = $print_error;
+ print "Upgrade to $DBversion done (add browser table if not already present)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.079";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ my ($print_error) = $dbh->{PrintError};
+ $dbh->{PrintError} = 0;
+
+ $dbh->do("INSERT INTO `systempreferences` (variable, value,options,type, explanation)VALUES
+ ('AddPatronLists','categorycode','categorycode|category_type','Choice','Allow user to choose what list to pick up from when adding patrons')");
+ print "Upgrade to $DBversion done (add browser table if not already present)\n";
+ SetVersion ($DBversion);
+}
+
+
+
+$DBversion = "3.00.00.080";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("ALTER TABLE subscription CHANGE monthlength monthlength int(11) default '0'");
+ $dbh->do("ALTER TABLE deleteditems MODIFY marc LONGBLOB AFTER copynumber");
+ $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
+ print "Upgrade to $DBversion done (catch up on DB schema changes since alpha and beta)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.081";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("CREATE TABLE `borrower_attribute_types` (
+ `code` varchar(10) NOT NULL,
+ `description` varchar(255) NOT NULL,
+ `repeatable` tinyint(1) NOT NULL default 0,
+ `unique_id` tinyint(1) NOT NULL default 0,
+ `opac_display` tinyint(1) NOT NULL default 0,
+ `password_allowed` tinyint(1) NOT NULL default 0,
+ `staff_searchable` tinyint(1) NOT NULL default 0,
+ `authorised_value_category` varchar(10) default NULL,
+ PRIMARY KEY (`code`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+ $dbh->do("CREATE TABLE `borrower_attributes` (
+ `borrowernumber` int(11) NOT NULL,
+ `code` varchar(10) NOT NULL,
+ `attribute` varchar(30) default NULL,
+ `password` varchar(30) default NULL,
+ KEY `borrowernumber` (`borrowernumber`),
+ KEY `code_attribute` (`code`, `attribute`),
+ CONSTRAINT `borrower_attributes_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
+ ON DELETE CASCADE ON UPDATE CASCADE,
+ CONSTRAINT `borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`)
+ ON DELETE CASCADE ON UPDATE CASCADE
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+ $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ExtendedPatronAttributes','0','Use extended patron IDs and attributes',NULL,'YesNo')");
+ print "Upgrade to $DBversion done (added borrower_attributes and borrower_attribute_types)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.082";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do( q(alter table accountlines add column lastincrement decimal(28,6) default NULL) );
+ print "Upgrade to $DBversion done (adding lastincrement column to accountlines table)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.083";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do( qq(UPDATE systempreferences SET value='local' where variable='yuipath' and value like "%/intranet-tmpl/prog/%"));
+ print "Upgrade to $DBversion done (Changing yuipath behaviour in managing a local value)\n";
+ SetVersion ($DBversion);
+}
+$DBversion = "3.00.00.084";
+ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RenewSerialAddsSuggestion','0','if ON, adds a new suggestion at serial subscription renewal',NULL,'YesNo')");
+ $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GoogleJackets','0','if ON, displays jacket covers from Google Books API',NULL,'YesNo')");
+ print "Upgrade to $DBversion done (add new sysprefs)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.085";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ if (C4::Context->preference("marcflavour") eq 'MARC21') {
+ $dbh->do("UPDATE marc_subfield_structure SET tab = 0 WHERE tab = 9 AND tagfield = '037'");
+ $dbh->do("UPDATE marc_subfield_structure SET tab = 1 WHERE tab = 6 AND tagfield in ('100', '110', '111', '130')");
+ $dbh->do("UPDATE marc_subfield_structure SET tab = 2 WHERE tab = 6 AND tagfield in ('240', '243')");
+ $dbh->do("UPDATE marc_subfield_structure SET tab = 4 WHERE tab = 6 AND tagfield in ('400', '410', '411', '440')");
+ $dbh->do("UPDATE marc_subfield_structure SET tab = 5 WHERE tab = 9 AND tagfield = '584'");
+ $dbh->do("UPDATE marc_subfield_structure SET tab = 7 WHERE tab = -6 AND tagfield = '760'");
+ }
+ print "Upgrade to $DBversion done (move editing tab of various MARC21 subfields)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.086";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do(
+ "CREATE TABLE `tmp_holdsqueue` (
+ `biblionumber` int(11) default NULL,
+ `itemnumber` int(11) default NULL,
+ `barcode` varchar(20) default NULL,
+ `surname` mediumtext NOT NULL,
+ `firstname` text,
+ `phone` text,
+ `borrowernumber` int(11) NOT NULL,
+ `cardnumber` varchar(16) default NULL,
+ `reservedate` date default NULL,
+ `title` mediumtext,
+ `itemcallnumber` varchar(30) default NULL,
+ `holdingbranch` varchar(10) default NULL,
+ `pickbranch` varchar(10) default NULL,
+ `notes` text
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
+
+ $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RandomizeHoldsQueueWeight','0','if ON, the holds queue in circulation will be randomized, either based on all location codes, or by the location codes specified in StaticHoldsQueueWeight',NULL,'YesNo')");
+ $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('StaticHoldsQueueWeight','0','Specify a list of library location codes separated by commas -- the list of codes will be traversed and weighted with first values given higher weight for holds fulfillment -- alternatively, if RandomizeHoldsQueueWeight is set, the list will be randomly selective',NULL,'TextArea')");
+
+ print "Upgrade to $DBversion done (Table structure for table `tmp_holdsqueue`)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.087";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("INSERT INTO `systempreferences` VALUES ('AutoEmailOpacUser','0','','Sends notification emails containing new account details to patrons - when account is created.','YesNo')" );
+ $dbh->do("INSERT INTO `systempreferences` VALUES ('AutoEmailPrimaryAddress','OFF','email|emailpro|B_email|cardnumber|OFF','Defines the default email address where Account Details emails are sent.','Choice')");
+ print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.088";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('OPACShelfBrowser','1','','Enable/disable Shelf Browser on item details page','YesNo')");
+ $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('OPACItemHolds','1','Allow OPAC users to place hold on specific items. If OFF, users can only request next available copy.','','YesNo')");
+ $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('XSLTDetailsDisplay','0','','Enable XSL stylesheet control over details page display on OPAC WARNING: MARC21 Only','YesNo')");
+ $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('XSLTResultsDisplay','0','','Enable XSL stylesheet control over results page display on OPAC WARNING: MARC21 Only','YesNo')");
+ print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
+ SetVersion ($DBversion);
+}
+
+$DBversion = "3.00.00.089";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AdvancedSearchTypes','itemtypes','itemtypes|ccode','Select which set of fields comprise the Type limit in the advanced search','Choice')");
+ print "Upgrade to $DBversion done (added new AdvancedSearchTypes syspref)\n";