4 # This script checks for required updates to the database.
6 # Parts copyright Catalyst IT 2011
8 # Part of the Koha Library Software www.koha-community.org
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 # - Would also be a good idea to offer to do a backup at this time...
26 # NOTE: If you do something more than once in here, make it table driven.
28 # NOTE: Please keep the version in kohaversion.pl up-to-date!
45 use MARC::File::XML ( BinaryEncoding => 'utf8' );
47 use File::Path qw[remove_tree]; # perl core module
50 # FIXME - The user might be installing a new database, so can't rely
51 # on /etc/koha.conf anyway.
58 %existingtables, # tables already in database
62 $type, $null, $key, $default, $extra,
63 $prefitem, # preference item in systempreferences table
66 my $schema = Koha::Database->new()->schema();
72 my $dbh = C4::Context->dbh;
73 $|=1; # flushes output
75 local $dbh->{RaiseError} = 0;
77 # Record the version we are coming from
79 my $original_version = C4::Context->preference("Version");
81 # Deal with virtualshelves
82 my $DBversion = "3.00.00.001";
83 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
84 # update virtualshelves table to
86 $dbh->do("ALTER TABLE `bookshelf` RENAME `virtualshelves`");
87 $dbh->do("ALTER TABLE `shelfcontents` RENAME `virtualshelfcontents`");
88 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD `biblionumber` INT( 11 ) NOT NULL default '0' AFTER shelfnumber");
89 $dbh->do("UPDATE `virtualshelfcontents` SET biblionumber=(SELECT biblionumber FROM items WHERE items.itemnumber=virtualshelfcontents.itemnumber)");
90 # drop all foreign keys : otherwise, we can't drop itemnumber field.
91 DropAllForeignKeys('virtualshelfcontents');
92 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD KEY biblionumber (biblionumber)");
93 # create the new foreign keys (on biblionumber)
94 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `virtualshelfcontents_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE");
95 # re-create the foreign key on virtualshelf
96 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `shelfcontents_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE");
97 $dbh->do("ALTER TABLE `virtualshelfcontents` DROP `itemnumber`");
98 print "Upgrade to $DBversion done (virtualshelves)\n";
99 SetVersion ($DBversion);
103 $DBversion = "3.00.00.002";
104 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
105 $dbh->do("DROP TABLE sessions");
106 $dbh->do("CREATE TABLE `sessions` (
107 `id` varchar(32) NOT NULL,
108 `a_session` text NOT NULL,
109 UNIQUE KEY `id` (`id`)
110 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
111 print "Upgrade to $DBversion done (sessions uses CGI::session, new table structure for sessions)\n";
112 SetVersion ($DBversion);
116 $DBversion = "3.00.00.003";
117 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
118 if (C4::Context->preference("opaclanguages") eq "fr") {
119 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ReservesNeedReturns','0','Si ce paramètre est mis à 1, une réservation posée sur un exemplaire présent sur le site devra être passée en retour pour être disponible. Sinon, elle sera automatiquement disponible, Koha considère que le bibliothécaire place la réservation en ayant le document en mains','','YesNo')");
121 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ReservesNeedReturns','0','If set, a reserve done on an item available in this branch need a check-in, otherwise, a reserve on a specific item, that is on the branch & available is considered as available','','YesNo')");
123 print "Upgrade to $DBversion done (adding ReservesNeedReturns systempref, in circulation)\n";
124 SetVersion ($DBversion);
128 $DBversion = "3.00.00.004";
129 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
130 $dbh->do("INSERT INTO `systempreferences` VALUES ('DebugLevel','2','set the level of error info sent to the browser. 0=none, 1=some, 2=most','0|1|2','Choice')");
131 print "Upgrade to $DBversion done (adding DebugLevel systempref, in 'Admin' tab)\n";
132 SetVersion ($DBversion);
135 $DBversion = "3.00.00.005";
136 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
137 $dbh->do("CREATE TABLE `tags` (
138 `entry` varchar(255) NOT NULL default '',
139 `weight` bigint(20) NOT NULL default 0,
140 PRIMARY KEY (`entry`)
141 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
143 $dbh->do("CREATE TABLE `nozebra` (
144 `server` varchar(20) NOT NULL,
145 `indexname` varchar(40) NOT NULL,
146 `value` varchar(250) NOT NULL,
147 `biblionumbers` longtext NOT NULL,
148 KEY `indexname` (`server`,`indexname`),
149 KEY `value` (`server`,`value`))
150 ENGINE=InnoDB DEFAULT CHARSET=utf8;
152 print "Upgrade to $DBversion done (adding tags and nozebra tables )\n";
153 SetVersion ($DBversion);
156 $DBversion = "3.00.00.006";
157 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
158 $dbh->do("UPDATE issues SET issuedate=timestamp WHERE issuedate='0000-00-00'");
159 print "Upgrade to $DBversion done (filled issues.issuedate with timestamp)\n";
160 SetVersion ($DBversion);
163 $DBversion = "3.00.00.007";
164 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
165 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SessionStorage','mysql','Use mysql or a temporary file for storing session data','mysql|tmp','Choice')");
166 print "Upgrade to $DBversion done (set SessionStorage variable)\n";
167 SetVersion ($DBversion);
170 $DBversion = "3.00.00.008";
171 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
172 $dbh->do("ALTER TABLE `biblio` ADD `datecreated` DATE NOT NULL AFTER `timestamp` ;");
173 $dbh->do("UPDATE biblio SET datecreated=timestamp");
174 print "Upgrade to $DBversion done (biblio creation date)\n";
175 SetVersion ($DBversion);
178 $DBversion = "3.00.00.009";
179 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
181 # Create backups of call number columns
182 # in case default migration needs to be customized
184 # UPGRADE NOTE: temp_upg_biblioitems_call_num should be dropped
185 # after call numbers have been transformed to the new structure
187 # Not bothering to do the same with deletedbiblioitems -- assume
188 # default is good enough.
189 $dbh->do("CREATE TABLE `temp_upg_biblioitems_call_num` AS
190 SELECT `biblioitemnumber`, `biblionumber`,
191 `classification`, `dewey`, `subclass`,
193 FROM `biblioitems`");
195 # biblioitems changes
196 $dbh->do("ALTER TABLE `biblioitems` CHANGE COLUMN `volumeddesc` `volumedesc` TEXT,
197 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
198 ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
199 ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
200 ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
201 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
202 ADD `totalissues` INT(10) AFTER `cn_sort`");
204 # default mapping of call number columns:
205 # cn_class = concatentation of classification + dewey,
206 # trimmed to fit -- assumes that most users do not
207 # populate both classification and dewey in a single record
209 # cn_source = left null
212 # After upgrade, cn_sort will have to be set based on whatever
213 # default call number scheme user sets as a preference. Misc
214 # script will be added at some point to do that.
216 $dbh->do("UPDATE `biblioitems`
217 SET cn_class = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
222 # Now drop the old call number columns
223 $dbh->do("ALTER TABLE `biblioitems` DROP COLUMN `classification`,
225 DROP COLUMN `subclass`,
226 DROP COLUMN `lcsort`,
227 DROP COLUMN `ccode`");
229 # deletedbiblio changes
230 $dbh->do("ALTER TABLE `deletedbiblio` ALTER COLUMN `frameworkcode` SET DEFAULT '',
232 ADD `datecreated` DATE NOT NULL AFTER `timestamp`");
233 $dbh->do("UPDATE deletedbiblio SET datecreated = timestamp");
235 # deletedbiblioitems changes
236 $dbh->do("ALTER TABLE `deletedbiblioitems`
237 MODIFY `publicationyear` TEXT,
238 CHANGE `volumeddesc` `volumedesc` TEXT,
239 MODIFY `collectiontitle` MEDIUMTEXT DEFAULT NULL AFTER `volumedesc`,
240 MODIFY `collectionissn` TEXT DEFAULT NULL AFTER `collectiontitle`,
241 MODIFY `collectionvolume` MEDIUMTEXT DEFAULT NULL AFTER `collectionissn`,
242 MODIFY `editionstatement` TEXT DEFAULT NULL AFTER `collectionvolume`,
243 MODIFY `editionresponsibility` TEXT DEFAULT NULL AFTER `editionstatement`,
244 MODIFY `place` VARCHAR(255) DEFAULT NULL AFTER `size`,
245 MODIFY `marc` LONGBLOB,
246 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `url`,
247 ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
248 ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
249 ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
250 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
251 ADD `totalissues` INT(10) AFTER `cn_sort`,
252 ADD `marcxml` LONGTEXT NOT NULL AFTER `totalissues`,
253 ADD KEY `isbn` (`isbn`),
254 ADD KEY `publishercode` (`publishercode`)
257 $dbh->do("UPDATE `deletedbiblioitems`
258 SET `cn_class` = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
259 `cn_item` = `subclass`,
262 $dbh->do("ALTER TABLE `deletedbiblioitems`
263 DROP COLUMN `classification`,
265 DROP COLUMN `subclass`,
266 DROP COLUMN `lcsort`,
270 # deleteditems changes
271 $dbh->do("ALTER TABLE `deleteditems`
272 MODIFY `barcode` VARCHAR(20) DEFAULT NULL,
273 MODIFY `price` DECIMAL(8,2) DEFAULT NULL,
274 MODIFY `replacementprice` DECIMAL(8,2) DEFAULT NULL,
276 MODIFY `itemcallnumber` VARCHAR(30) DEFAULT NULL AFTER `wthdrawn`,
277 MODIFY `holdingbranch` VARCHAR(10) DEFAULT NULL,
279 MODIFY `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP AFTER `paidfor`,
281 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
282 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
283 ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
284 ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
285 ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`,
286 MODIFY `marc` LONGBLOB AFTER `uri`,
288 DROP KEY `itembarcodeidx`,
289 DROP KEY `itembinoidx`,
290 DROP KEY `itembibnoidx`,
291 ADD UNIQUE KEY `delitembarcodeidx` (`barcode`),
292 ADD KEY `delitembinoidx` (`biblioitemnumber`),
293 ADD KEY `delitembibnoidx` (`biblionumber`),
294 ADD KEY `delhomebranch` (`homebranch`),
295 ADD KEY `delholdingbranch` (`holdingbranch`)");
296 $dbh->do("UPDATE deleteditems SET `ccode` = `itype`");
297 $dbh->do("ALTER TABLE deleteditems DROP `itype`");
298 $dbh->do("UPDATE `deleteditems` SET `cn_sort` = `itemcallnumber`");
301 $dbh->do("ALTER TABLE `items` ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
302 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
303 ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
304 ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
305 ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`
307 $dbh->do("ALTER TABLE `items`
308 DROP KEY `itembarcodeidx`,
309 ADD UNIQUE KEY `itembarcodeidx` (`barcode`)");
311 # map items.itype to items.ccode and
312 # set cn_sort to itemcallnumber -- as with biblioitems.cn_sort,
313 # will have to be subsequently updated per user's default
314 # classification scheme
315 $dbh->do("UPDATE `items` SET `cn_sort` = `itemcallnumber`,
318 $dbh->do("ALTER TABLE `items` DROP `cutterextra`,
321 print "Upgrade to $DBversion done (major changes to biblio, biblioitems, items, and deleted* versions of same\n";
322 SetVersion ($DBversion);
325 $DBversion = "3.00.00.010";
326 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
327 $dbh->do("CREATE INDEX `userid` ON borrowers (`userid`) ");
328 print "Upgrade to $DBversion done (userid index added)\n";
329 SetVersion ($DBversion);
332 $DBversion = "3.00.00.011";
333 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
334 $dbh->do("ALTER TABLE `branchcategories` CHANGE `categorycode` `categorycode` varchar(10) ");
335 $dbh->do("ALTER TABLE `branchcategories` CHANGE `categoryname` `categoryname` varchar(32) ");
336 $dbh->do("ALTER TABLE `branchcategories` ADD COLUMN `categorytype` varchar(16) ");
337 $dbh->do("UPDATE `branchcategories` SET `categorytype` = 'properties'");
338 $dbh->do("ALTER TABLE `branchrelations` CHANGE `categorycode` `categorycode` varchar(10) ");
339 print "Upgrade to $DBversion done (added branchcategory type)\n";
340 SetVersion ($DBversion);
343 $DBversion = "3.00.00.012";
344 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
345 $dbh->do("CREATE TABLE `class_sort_rules` (
346 `class_sort_rule` varchar(10) NOT NULL default '',
347 `description` mediumtext,
348 `sort_routine` varchar(30) NOT NULL default '',
349 PRIMARY KEY (`class_sort_rule`),
350 UNIQUE KEY `class_sort_rule_idx` (`class_sort_rule`)
351 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
352 $dbh->do("CREATE TABLE `class_sources` (
353 `cn_source` varchar(10) NOT NULL default '',
354 `description` mediumtext,
355 `used` tinyint(4) NOT NULL default 0,
356 `class_sort_rule` varchar(10) NOT NULL default '',
357 PRIMARY KEY (`cn_source`),
358 UNIQUE KEY `cn_source_idx` (`cn_source`),
359 KEY `used_idx` (`used`),
360 CONSTRAINT `class_source_ibfk_1` FOREIGN KEY (`class_sort_rule`)
361 REFERENCES `class_sort_rules` (`class_sort_rule`)
362 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
363 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type)
364 VALUES('DefaultClassificationSource','ddc',
365 'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.', NULL,'free')");
366 $dbh->do("INSERT INTO `class_sort_rules` (`class_sort_rule`, `description`, `sort_routine`) VALUES
367 ('dewey', 'Default filing rules for DDC', 'Dewey'),
368 ('lcc', 'Default filing rules for LCC', 'LCC'),
369 ('generic', 'Generic call number filing rules', 'Generic')");
370 $dbh->do("INSERT INTO `class_sources` (`cn_source`, `description`, `used`, `class_sort_rule`) VALUES
371 ('ddc', 'Dewey Decimal Classification', 1, 'dewey'),
372 ('lcc', 'Library of Congress Classification', 1, 'lcc'),
373 ('udc', 'Universal Decimal Classification', 0, 'generic'),
374 ('sudocs', 'SuDoc Classification (U.S. GPO)', 0, 'generic'),
375 ('z', 'Other/Generic Classification Scheme', 0, 'generic')");
376 print "Upgrade to $DBversion done (classification sources added)\n";
377 SetVersion ($DBversion);
380 $DBversion = "3.00.00.013";
381 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
382 $dbh->do("CREATE TABLE `import_batches` (
383 `import_batch_id` int(11) NOT NULL auto_increment,
384 `template_id` int(11) default NULL,
385 `branchcode` varchar(10) default NULL,
386 `num_biblios` int(11) NOT NULL default 0,
387 `num_items` int(11) NOT NULL default 0,
388 `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
389 `overlay_action` enum('replace', 'create_new', 'use_template') NOT NULL default 'create_new',
390 `import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging',
391 `batch_type` enum('batch', 'z3950') NOT NULL default 'batch',
392 `file_name` varchar(100),
393 `comments` mediumtext,
394 PRIMARY KEY (`import_batch_id`),
395 KEY `branchcode` (`branchcode`)
396 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
397 $dbh->do("CREATE TABLE `import_records` (
398 `import_record_id` int(11) NOT NULL auto_increment,
399 `import_batch_id` int(11) NOT NULL,
400 `branchcode` varchar(10) default NULL,
401 `record_sequence` int(11) NOT NULL default 0,
402 `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
403 `import_date` DATE default NULL,
404 `marc` longblob NOT NULL,
405 `marcxml` longtext NOT NULL,
406 `marcxml_old` longtext NOT NULL,
407 `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio',
408 `overlay_status` enum('no_match', 'auto_match', 'manual_match', 'match_applied') NOT NULL default 'no_match',
409 `status` enum('error', 'staged', 'imported', 'reverted', 'items_reverted') NOT NULL default 'staged',
410 `import_error` mediumtext,
411 `encoding` varchar(40) NOT NULL default '',
412 `z3950random` varchar(40) default NULL,
413 PRIMARY KEY (`import_record_id`),
414 CONSTRAINT `import_records_ifbk_1` FOREIGN KEY (`import_batch_id`)
415 REFERENCES `import_batches` (`import_batch_id`) ON DELETE CASCADE ON UPDATE CASCADE,
416 KEY `branchcode` (`branchcode`),
417 KEY `batch_sequence` (`import_batch_id`, `record_sequence`)
418 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
419 $dbh->do("CREATE TABLE `import_record_matches` (
420 `import_record_id` int(11) NOT NULL,
421 `candidate_match_id` int(11) NOT NULL,
422 `score` int(11) NOT NULL default 0,
423 CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`)
424 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
425 KEY `record_score` (`import_record_id`, `score`)
426 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
427 $dbh->do("CREATE TABLE `import_biblios` (
428 `import_record_id` int(11) NOT NULL,
429 `matched_biblionumber` int(11) default NULL,
430 `control_number` varchar(25) default NULL,
431 `original_source` varchar(25) default NULL,
432 `title` varchar(128) default NULL,
433 `author` varchar(80) default NULL,
434 `isbn` varchar(14) default NULL,
435 `issn` varchar(9) default NULL,
436 `has_items` tinyint(1) NOT NULL default 0,
437 CONSTRAINT `import_biblios_ibfk_1` FOREIGN KEY (`import_record_id`)
438 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
439 KEY `matched_biblionumber` (`matched_biblionumber`),
440 KEY `title` (`title`),
442 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
443 $dbh->do("CREATE TABLE `import_items` (
444 `import_items_id` int(11) NOT NULL auto_increment,
445 `import_record_id` int(11) NOT NULL,
446 `itemnumber` int(11) default NULL,
447 `branchcode` varchar(10) default NULL,
448 `status` enum('error', 'staged', 'imported', 'reverted') NOT NULL default 'staged',
449 `marcxml` longtext NOT NULL,
450 `import_error` mediumtext,
451 PRIMARY KEY (`import_items_id`),
452 CONSTRAINT `import_items_ibfk_1` FOREIGN KEY (`import_record_id`)
453 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
454 KEY `itemnumber` (`itemnumber`),
455 KEY `branchcode` (`branchcode`)
456 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
458 $dbh->do("INSERT INTO `import_batches`
459 (`overlay_action`, `import_status`, `batch_type`, `file_name`)
460 SELECT distinct 'create_new', 'staged', 'z3950', `file`
461 FROM `marc_breeding`");
463 $dbh->do("INSERT INTO `import_records`
464 (`import_batch_id`, `import_record_id`, `record_sequence`, `marc`, `record_type`, `status`,
465 `encoding`, `z3950random`, `marcxml`, `marcxml_old`)
466 SELECT `import_batch_id`, `id`, 1, `marc`, 'biblio', 'staged', `encoding`, `z3950random`, '', ''
468 JOIN `import_batches` ON (`file_name` = `file`)");
470 $dbh->do("INSERT INTO `import_biblios`
471 (`import_record_id`, `title`, `author`, `isbn`)
472 SELECT `import_record_id`, `title`, `author`, `isbn`
474 JOIN `import_records` ON (`import_record_id` = `id`)");
476 $dbh->do("UPDATE `import_batches`
477 SET `num_biblios` = (
479 FROM `import_records`
480 WHERE `import_batch_id` = `import_batches`.`import_batch_id`
483 $dbh->do("DROP TABLE `marc_breeding`");
485 print "Upgrade to $DBversion done (import_batches et al. added)\n";
486 SetVersion ($DBversion);
489 $DBversion = "3.00.00.014";
490 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
491 $dbh->do("ALTER TABLE subscription ADD lastbranch VARCHAR(4)");
492 print "Upgrade to $DBversion done (userid index added)\n";
493 SetVersion ($DBversion);
496 $DBversion = "3.00.00.015";
497 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
498 $dbh->do("CREATE TABLE `saved_sql` (
499 `id` int(11) NOT NULL auto_increment,
500 `borrowernumber` int(11) default NULL,
501 `date_created` datetime default NULL,
502 `last_modified` datetime default NULL,
504 `last_run` datetime default NULL,
505 `report_name` varchar(255) default NULL,
506 `type` varchar(255) default NULL,
509 KEY boridx (`borrowernumber`)
510 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
511 $dbh->do("CREATE TABLE `saved_reports` (
512 `id` int(11) NOT NULL auto_increment,
513 `report_id` int(11) default NULL,
515 `date_run` datetime default NULL,
517 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
518 print "Upgrade to $DBversion done (saved_sql and saved_reports added)\n";
519 SetVersion ($DBversion);
522 $DBversion = "3.00.00.016";
523 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
524 $dbh->do(" CREATE TABLE reports_dictionary (
525 id int(11) NOT NULL auto_increment,
526 name varchar(255) default NULL,
528 date_created datetime default NULL,
529 date_modified datetime default NULL,
531 area int(11) default NULL,
533 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
534 print "Upgrade to $DBversion done (reports_dictionary) added)\n";
535 SetVersion ($DBversion);
538 $DBversion = "3.00.00.017";
539 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
540 $dbh->do("ALTER TABLE action_logs DROP PRIMARY KEY");
541 $dbh->do("ALTER TABLE action_logs ADD KEY timestamp (timestamp,user)");
542 $dbh->do("ALTER TABLE action_logs ADD action_id INT(11) NOT NULL FIRST");
543 $dbh->do("UPDATE action_logs SET action_id = if (\@a, \@a:=\@a+1, \@a:=1)");
544 $dbh->do("ALTER TABLE action_logs MODIFY action_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY");
545 print "Upgrade to $DBversion done (added column to action_logs)\n";
546 SetVersion ($DBversion);
549 $DBversion = "3.00.00.018";
550 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
551 $dbh->do("ALTER TABLE `zebraqueue`
552 ADD `done` INT NOT NULL DEFAULT '0',
553 ADD `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ;
555 print "Upgrade to $DBversion done (adding timestamp and done columns to zebraque table to improve problem tracking) added)\n";
556 SetVersion ($DBversion);
559 $DBversion = "3.00.00.019";
560 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
561 $dbh->do("ALTER TABLE biblio MODIFY biblionumber INT(11) NOT NULL AUTO_INCREMENT");
562 $dbh->do("ALTER TABLE biblioitems MODIFY biblioitemnumber INT(11) NOT NULL AUTO_INCREMENT");
563 $dbh->do("ALTER TABLE items MODIFY itemnumber INT(11) NOT NULL AUTO_INCREMENT");
564 print "Upgrade to $DBversion done (made bib/item PKs auto_increment)\n";
565 SetVersion ($DBversion);
568 $DBversion = "3.00.00.020";
569 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
570 $dbh->do("ALTER TABLE deleteditems
571 DROP KEY `delitembarcodeidx`,
572 ADD KEY `delitembarcodeidx` (`barcode`)");
573 print "Upgrade to $DBversion done (dropped uniqueness of key on deleteditems.barcode)\n";
574 SetVersion ($DBversion);
577 $DBversion = "3.00.00.021";
578 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
579 $dbh->do("ALTER TABLE items CHANGE homebranch homebranch VARCHAR(10)");
580 $dbh->do("ALTER TABLE deleteditems CHANGE homebranch homebranch VARCHAR(10)");
581 $dbh->do("ALTER TABLE statistics CHANGE branch branch VARCHAR(10)");
582 $dbh->do("ALTER TABLE subscription CHANGE lastbranch lastbranch VARCHAR(10)");
583 print "Upgrade to $DBversion done (extended missed branchcode columns to 10 chars)\n";
584 SetVersion ($DBversion);
587 $DBversion = "3.00.00.022";
588 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
589 $dbh->do("ALTER TABLE items
590 ADD `damaged` tinyint(1) default NULL AFTER notforloan");
591 $dbh->do("ALTER TABLE deleteditems
592 ADD `damaged` tinyint(1) default NULL AFTER notforloan");
593 print "Upgrade to $DBversion done (adding damaged column to items table)\n";
594 SetVersion ($DBversion);
597 $DBversion = "3.00.00.023";
598 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
599 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
600 VALUES ('yuipath','http://yui.yahooapis.com/2.3.1/build','Insert the path to YUI libraries','','free')");
601 print "Upgrade to $DBversion done (adding new system preference for controlling YUI path)\n";
602 SetVersion ($DBversion);
604 $DBversion = "3.00.00.024";
605 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
606 $dbh->do("ALTER TABLE biblioitems CHANGE itemtype itemtype VARCHAR(10)");
607 print "Upgrade to $DBversion done (changing itemtype to (10))\n";
608 SetVersion ($DBversion);
611 $DBversion = "3.00.00.025";
612 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
613 $dbh->do("ALTER TABLE items ADD COLUMN itype VARCHAR(10)");
614 $dbh->do("ALTER TABLE deleteditems ADD COLUMN itype VARCHAR(10) AFTER uri");
615 if(C4::Context->preference('item-level_itypes')){
616 $dbh->do('update items,biblioitems set items.itype=biblioitems.itemtype where items.biblionumber=biblioitems.biblionumber and itype is null');
618 print "Upgrade to $DBversion done (reintroduce items.itype - fill from itemtype)\n ";
619 SetVersion ($DBversion);
622 $DBversion = "3.00.00.026";
623 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
624 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
625 VALUES ('HomeOrHoldingBranch','homebranch','homebranch|holdingbranch','With independent branches turned on this decides whether to check the items holdingbranch or homebranch at circulatilon','choice')");
626 print "Upgrade to $DBversion done (adding new system preference for choosing whether homebranch or holdingbranch is checked in circulation)\n";
627 SetVersion ($DBversion);
630 $DBversion = "3.00.00.027";
631 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
632 $dbh->do("CREATE TABLE `marc_matchers` (
633 `matcher_id` int(11) NOT NULL auto_increment,
634 `code` varchar(10) NOT NULL default '',
635 `description` varchar(255) NOT NULL default '',
636 `record_type` varchar(10) NOT NULL default 'biblio',
637 `threshold` int(11) NOT NULL default 0,
638 PRIMARY KEY (`matcher_id`),
640 KEY `record_type` (`record_type`)
641 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
642 $dbh->do("CREATE TABLE `matchpoints` (
643 `matcher_id` int(11) NOT NULL,
644 `matchpoint_id` int(11) NOT NULL auto_increment,
645 `search_index` varchar(30) NOT NULL default '',
646 `score` int(11) NOT NULL default 0,
647 PRIMARY KEY (`matchpoint_id`),
648 CONSTRAINT `matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
649 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE
650 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
651 $dbh->do("CREATE TABLE `matchpoint_components` (
652 `matchpoint_id` int(11) NOT NULL,
653 `matchpoint_component_id` int(11) NOT NULL auto_increment,
654 sequence int(11) NOT NULL default 0,
655 tag varchar(3) NOT NULL default '',
656 subfields varchar(40) NOT NULL default '',
657 offset int(4) NOT NULL default 0,
658 length int(4) NOT NULL default 0,
659 PRIMARY KEY (`matchpoint_component_id`),
660 KEY `by_sequence` (`matchpoint_id`, `sequence`),
661 CONSTRAINT `matchpoint_components_ifbk_1` FOREIGN KEY (`matchpoint_id`)
662 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
663 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
664 $dbh->do("CREATE TABLE `matchpoint_component_norms` (
665 `matchpoint_component_id` int(11) NOT NULL,
666 `sequence` int(11) NOT NULL default 0,
667 `norm_routine` varchar(50) NOT NULL default '',
668 KEY `matchpoint_component_norms` (`matchpoint_component_id`, `sequence`),
669 CONSTRAINT `matchpoint_component_norms_ifbk_1` FOREIGN KEY (`matchpoint_component_id`)
670 REFERENCES `matchpoint_components` (`matchpoint_component_id`) ON DELETE CASCADE ON UPDATE CASCADE
671 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
672 $dbh->do("CREATE TABLE `matcher_matchpoints` (
673 `matcher_id` int(11) NOT NULL,
674 `matchpoint_id` int(11) NOT NULL,
675 CONSTRAINT `matcher_matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
676 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
677 CONSTRAINT `matcher_matchpoints_ifbk_2` FOREIGN KEY (`matchpoint_id`)
678 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
679 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
680 $dbh->do("CREATE TABLE `matchchecks` (
681 `matcher_id` int(11) NOT NULL,
682 `matchcheck_id` int(11) NOT NULL auto_increment,
683 `source_matchpoint_id` int(11) NOT NULL,
684 `target_matchpoint_id` int(11) NOT NULL,
685 PRIMARY KEY (`matchcheck_id`),
686 CONSTRAINT `matcher_matchchecks_ifbk_1` FOREIGN KEY (`matcher_id`)
687 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
688 CONSTRAINT `matcher_matchchecks_ifbk_2` FOREIGN KEY (`source_matchpoint_id`)
689 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE,
690 CONSTRAINT `matcher_matchchecks_ifbk_3` FOREIGN KEY (`target_matchpoint_id`)
691 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
692 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
693 print "Upgrade to $DBversion done (added C4::Matcher serialization tables)\n ";
694 SetVersion ($DBversion);
697 $DBversion = "3.00.00.028";
698 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
699 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
700 VALUES ('canreservefromotherbranches','1','','With Independent branches on, can a user from one library reserve an item from another library','YesNo')");
701 print "Upgrade to $DBversion done (adding new system preference for changing reserve/holds behaviour with independent branches)\n";
702 SetVersion ($DBversion);
706 $DBversion = "3.00.00.029";
707 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
708 $dbh->do("ALTER TABLE `import_batches` ADD `matcher_id` int(11) NULL AFTER `import_batch_id`");
709 print "Upgrade to $DBversion done (adding matcher_id to import_batches)\n";
710 SetVersion ($DBversion);
713 $DBversion = "3.00.00.030";
714 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
716 CREATE TABLE services_throttle (
717 service_type varchar(10) NOT NULL default '',
718 service_count varchar(45) default NULL,
719 PRIMARY KEY (service_type)
720 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
722 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
723 VALUES ('FRBRizeEditions',0,'','If ON, Koha will query one or more ISBN web services for associated ISBNs and display an Editions tab on the details pages','YesNo')");
724 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
725 VALUES ('XISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use the OCLC xISBN web service in the Editions tab on the detail pages. See: http://www.worldcat.org/affiliate/webservices/xisbn/app.jsp','YesNo')");
726 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
727 VALUES ('OCLCAffiliateID','','','Use with FRBRizeEditions and XISBN. You can sign up for an AffiliateID here: http://www.worldcat.org/wcpa/do/AffiliateUserServices?method=initSelfRegister','free')");
728 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
729 VALUES ('XISBNDailyLimit',499,'','The xISBN Web service is free for non-commercial use when usage does not exceed 500 requests per day','free')");
730 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
731 VALUES ('PINESISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use PINES OISBN web service in the Editions tab on the detail pages.','YesNo')");
732 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
733 VALUES ('ThingISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use the ThingISBN web service in the Editions tab on the detail pages.','YesNo')");
734 print "Upgrade to $DBversion done (adding services throttle table and sysprefs for xISBN)\n";
735 SetVersion ($DBversion);
738 $DBversion = "3.00.00.031";
739 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
741 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryStemming',1,'If ON, enables query stemming',NULL,'YesNo')");
742 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryFuzzy',1,'If ON, enables fuzzy option for searches',NULL,'YesNo')");
743 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryWeightFields',1,'If ON, enables field weighting',NULL,'YesNo')");
744 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('WebBasedSelfCheck',0,'If ON, enables the web-based self-check system',NULL,'YesNo')");
745 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('numSearchResults',20,'Specify the maximum number of results to display on a page of results',NULL,'free')");
746 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACnumSearchResults',20,'Specify the maximum number of results to display on a page of results',NULL,'free')");
747 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('maxItemsInSearchResults',20,'Specify the maximum number of items to display for each result on a page of results',NULL,'free')");
748 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('defaultSortField',NULL,'Specify the default field used for sorting','relevance|popularity|call_number|pubdate|acqdate|title|author','Choice')");
749 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('defaultSortOrder',NULL,'Specify the default sort order','asc|dsc|az|za','Choice')");
750 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACdefaultSortField',NULL,'Specify the default field used for sorting','relevance|popularity|call_number|pubdate|acqdate|title|author','Choice')");
751 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACdefaultSortOrder',NULL,'Specify the default sort order','asc|dsc|za|az','Choice')");
752 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('staffClientBaseURL','','Specify the base URL of the staff client',NULL,'free')");
753 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('minPasswordLength',3,'Specify the minimum length of a patron/staff password',NULL,'free')");
754 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('noItemTypeImages',0,'If ON, disables item-type images',NULL,'YesNo')");
755 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('emailLibrarianWhenHoldIsPlaced',0,'If ON, emails the librarian whenever a hold is placed',NULL,'YesNo')");
756 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('holdCancelLength','','Specify how many days before a hold is canceled',NULL,'free')");
757 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('libraryAddress','','The address to use for printing receipts, overdues, etc. if different than physical address',NULL,'free')");
758 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('finesMode','test','Choose the fines mode, test or production','test|production','Choice')");
759 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('globalDueDate','','If set, allows a global static due date for all checkouts',NULL,'free')");
760 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeInputFilter','','If set, allows specification of a item barcode input filter','cuecat','Choice')");
761 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('singleBranchMode',0,'Operate in Single-branch mode, hide branch selection in the OPAC',NULL,'YesNo')");
762 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('URLLinkText','','Text to display as the link anchor in the OPAC',NULL,'free')");
763 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACSubscriptionDisplay','economical','Specify how to display subscription information in the OPAC','economical|off|full','Choice')");
764 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACDisplayExtendedSubInfo',1,'If ON, extended subscription information is displayed in the OPAC',NULL,'YesNo')");
765 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACViewOthersSuggestions',0,'If ON, allows all suggestions to be displayed in the OPAC',NULL,'YesNo')");
766 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACURLOpenInNewWindow',0,'If ON, URLs in the OPAC open in a new window',NULL,'YesNo')");
767 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACUserCSS',0,'Add CSS to be included in the OPAC',NULL,'free')");
769 print "Upgrade to $DBversion done (adding additional system preference)\n";
770 SetVersion ($DBversion);
773 $DBversion = "3.00.00.032";
774 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
775 $dbh->do("UPDATE `marc_subfield_structure` SET `kohafield` = 'items.wthdrawn' WHERE `kohafield` = 'items.withdrawn'");
776 print "Upgrade to $DBversion done (fixed MARC framework references to items.withdrawn)\n";
777 SetVersion ($DBversion);
780 $DBversion = "3.00.00.033";
781 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
782 $dbh->do("INSERT INTO `userflags` VALUES(17,'staffaccess','Modify login / permissions for staff users',0)");
783 print "Upgrade to $DBversion done (Adding permissions flag for staff member access modification. )\n";
784 SetVersion ($DBversion);
787 $DBversion = "3.00.00.034";
788 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
789 $dbh->do("ALTER TABLE `virtualshelves` ADD COLUMN `sortfield` VARCHAR(16) ");
790 print "Upgrade to $DBversion done (Adding sortfield for Virtual Shelves. )\n";
791 SetVersion ($DBversion);
794 $DBversion = "3.00.00.035";
795 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
796 $dbh->do("UPDATE marc_subfield_structure
797 SET authorised_value = 'cn_source'
798 WHERE kohafield IN ('items.cn_source', 'biblioitems.cn_source')
799 AND (authorised_value is NULL OR authorised_value = '')");
800 print "Upgrade to $DBversion done (MARC frameworks: make classification source a drop-down)\n";
801 SetVersion ($DBversion);
804 $DBversion = "3.00.00.036";
805 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
806 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACItemsResultsDisplay','statuses','statuses : show only the status of items in result list. itemdisplay : show full location of items (branch+location+callnumber) as in staff interface','statuses|itemdetails','Choice');");
807 print "Upgrade to $DBversion done (OPACItemsResultsDisplay systempreference added)\n";
808 SetVersion ($DBversion);
811 $DBversion = "3.00.00.037";
812 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
813 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactfirstname` varchar(255)");
814 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactsurname` varchar(255)");
815 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress1` varchar(255)");
816 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress2` varchar(255)");
817 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress3` varchar(255)");
818 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactzipcode` varchar(50)");
819 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactphone` varchar(50)");
820 print "Upgrade to $DBversion done (Adding Alternative Contact Person information to borrowers table)\n";
821 SetVersion ($DBversion);
824 $DBversion = "3.00.00.038";
825 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
826 $dbh->do("UPDATE `systempreferences` set explanation='Choose the fines mode, off, test (emails admin report) or production (accrue overdue fines). Requires fines cron script' , options='off|test|production' where variable='finesMode'");
827 $dbh->do("DELETE FROM `systempreferences` WHERE variable='hideBiblioNumber'");
828 print "Upgrade to $DBversion done ('alter finesMode systempreference, remove superfluous syspref.')\n";
829 SetVersion ($DBversion);
832 $DBversion = "3.00.00.039";
833 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
834 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('uppercasesurnames',0,'If ON, surnames are converted to upper case in patron entry form',NULL,'YesNo')");
835 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('CircControl','ItemHomeLibrary','Specify the agency that controls the circulation and fines policy','PickupLibrary|PatronLibrary|ItemHomeLibrary','Choice')");
836 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('finesCalendar','noFinesWhenClosed','Specify whether to use the Calendar in calculating duedates and fines','ignoreCalendar|noFinesWhenClosed','Choice')");
837 # $dbh->do("DELETE FROM `systempreferences` WHERE variable='HomeOrHoldingBranch'"); # Bug #2752
838 print "Upgrade to $DBversion done ('add circ sysprefs CircControl, finesCalendar, and uppercasesurnames, and delete HomeOrHoldingBranch.')\n";
839 SetVersion ($DBversion);
842 $DBversion = "3.00.00.040";
843 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
844 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('previousIssuesDefaultSortOrder','asc','Specify the sort order of Previous Issues on the circulation page','asc|desc','Choice')");
845 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('todaysIssuesDefaultSortOrder','desc','Specify the sort order of Todays Issues on the circulation page','asc|desc','Choice')");
846 print "Upgrade to $DBversion done ('add circ sysprefs todaysIssuesDefaultSortOrder and previousIssuesDefaultSortOrder.')\n";
847 SetVersion ($DBversion);
851 $DBversion = "3.00.00.041";
852 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
853 # Strictly speaking it is not necessary to explicitly change
854 # NULL values to 0, because the ALTER TABLE statement will do that.
855 # However, setting them first avoids a warning.
856 $dbh->do("UPDATE items SET notforloan = 0 WHERE notforloan IS NULL");
857 $dbh->do("UPDATE items SET damaged = 0 WHERE damaged IS NULL");
858 $dbh->do("UPDATE items SET itemlost = 0 WHERE itemlost IS NULL");
859 $dbh->do("UPDATE items SET wthdrawn = 0 WHERE wthdrawn IS NULL");
860 $dbh->do("ALTER TABLE items
861 MODIFY notforloan tinyint(1) NOT NULL default 0,
862 MODIFY damaged tinyint(1) NOT NULL default 0,
863 MODIFY itemlost tinyint(1) NOT NULL default 0,
864 MODIFY wthdrawn tinyint(1) NOT NULL default 0");
865 $dbh->do("UPDATE deleteditems SET notforloan = 0 WHERE notforloan IS NULL");
866 $dbh->do("UPDATE deleteditems SET damaged = 0 WHERE damaged IS NULL");
867 $dbh->do("UPDATE deleteditems SET itemlost = 0 WHERE itemlost IS NULL");
868 $dbh->do("UPDATE deleteditems SET wthdrawn = 0 WHERE wthdrawn IS NULL");
869 $dbh->do("ALTER TABLE deleteditems
870 MODIFY notforloan tinyint(1) NOT NULL default 0,
871 MODIFY damaged tinyint(1) NOT NULL default 0,
872 MODIFY itemlost tinyint(1) NOT NULL default 0,
873 MODIFY wthdrawn tinyint(1) NOT NULL default 0");
874 print "Upgrade to $DBversion done (disallow NULL in several item status columns)\n";
875 SetVersion ($DBversion);
878 $DBversion = "3.00.00.04";
879 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
880 $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
881 print "Upgrade to $DBversion done (disallow NULL in aqbooksellers.name; part of fix for bug 1251)\n";
882 SetVersion ($DBversion);
885 $DBversion = "3.00.00.043";
886 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
887 $dbh->do("ALTER TABLE `currency` ADD `symbol` varchar(5) default NULL AFTER currency, ADD `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP AFTER symbol");
888 print "Upgrade to $DBversion done (currency table: add symbol and timestamp columns)\n";
889 SetVersion ($DBversion);
892 $DBversion = "3.00.00.044";
893 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
894 $dbh->do("ALTER TABLE deletedborrowers
895 ADD `altcontactfirstname` varchar(255) default NULL,
896 ADD `altcontactsurname` varchar(255) default NULL,
897 ADD `altcontactaddress1` varchar(255) default NULL,
898 ADD `altcontactaddress2` varchar(255) default NULL,
899 ADD `altcontactaddress3` varchar(255) default NULL,
900 ADD `altcontactzipcode` varchar(50) default NULL,
901 ADD `altcontactphone` varchar(50) default NULL
903 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
904 ('OPACBaseURL',NULL,'Specify the Base URL of the OPAC, e.g., opac.mylibrary.com, the http:// will be added automatically by Koha.',NULL,'Free'),
905 ('language','en','Set the default language in the staff client.',NULL,'Languages'),
906 ('QueryAutoTruncate',1,'If ON, query truncation is enabled by default',NULL,'YesNo'),
907 ('QueryRemoveStopwords',0,'If ON, stopwords listed in the Administration area will be removed from queries',NULL,'YesNo')
909 print "Upgrade to $DBversion done (syncing deletedborrowers table with borrowers table)\n";
910 SetVersion ($DBversion);
913 #-- http://www.w3.org/International/articles/language-tags/
916 $DBversion = "3.00.00.045";
917 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
919 CREATE TABLE language_subtag_registry (
921 type varchar(25), -- language-script-region-variant-extension-privateuse
922 description varchar(25), -- only one of the possible descriptions for ease of reference, see language_descriptions for the complete list
924 KEY `subtag` (`subtag`)
925 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
927 #-- TODO: add suppress_scripts
928 #-- this maps three letter codes defined in iso639.2 back to their
929 #-- two letter equivilents in rfc4646 (LOC maintains iso639+)
930 $dbh->do("CREATE TABLE language_rfc4646_to_iso639 (
931 rfc4646_subtag varchar(25),
932 iso639_2_code varchar(25),
933 KEY `rfc4646_subtag` (`rfc4646_subtag`)
934 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
936 $dbh->do("CREATE TABLE language_descriptions (
940 description varchar(255),
942 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
944 #-- bi-directional support, keyed by script subcode
945 $dbh->do("CREATE TABLE language_script_bidi (
946 rfc4646_subtag varchar(25), -- script subtag, Arab, Hebr, etc.
947 bidi varchar(3), -- rtl ltr
948 KEY `rfc4646_subtag` (`rfc4646_subtag`)
949 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
951 #-- BIDI Stuff, Arabic and Hebrew
952 $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
953 VALUES( 'Arab', 'rtl')");
954 $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
955 VALUES( 'Hebr', 'rtl')");
957 #-- TODO: need to map language subtags to script subtags for detection
958 #-- of bidi when script is not specified (like ar, he)
959 $dbh->do("CREATE TABLE language_script_mapping (
960 language_subtag varchar(25),
961 script_subtag varchar(25),
962 KEY `language_subtag` (`language_subtag`)
963 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
965 #-- Default mappings between script and language subcodes
966 $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
967 VALUES( 'ar', 'Arab')");
968 $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
969 VALUES( 'he', 'Hebr')");
971 print "Upgrade to $DBversion done (adding language subtag registry and basic BiDi support NOTE: You should import the subtag registry SQL)\n";
972 SetVersion ($DBversion);
975 $DBversion = "3.00.00.046";
976 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
977 $dbh->do("ALTER TABLE `subscription` CHANGE `numberlength` `numberlength` int(11) default '0' ,
978 CHANGE `weeklength` `weeklength` int(11) default '0'");
979 $dbh->do("CREATE TABLE `serialitems` (`serialid` int(11) NOT NULL, `itemnumber` int(11) NOT NULL, UNIQUE KEY `serialididx` (`serialid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
980 $dbh->do("INSERT INTO `serialitems` SELECT `serialid`,`itemnumber` from serial where NOT ISNULL(itemnumber) && itemnumber <> '' && itemnumber NOT LIKE '%,%'");
981 print "Upgrade to $DBversion done (Add serialitems table to link serial issues to items. )\n";
982 SetVersion ($DBversion);
985 $DBversion = "3.00.00.047";
986 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
987 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacRenewalAllowed',0,'If ON, users can renew their issues directly from their OPAC account',NULL,'YesNo');");
988 print "Upgrade to $DBversion done ( Added OpacRenewalAllowed syspref )\n";
989 SetVersion ($DBversion);
992 $DBversion = "3.00.00.048";
993 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
994 $dbh->do("ALTER TABLE `items` ADD `more_subfields_xml` longtext default NULL AFTER `itype`");
995 print "Upgrade to $DBversion done (added items.more_subfields_xml)\n";
996 SetVersion ($DBversion);
999 $DBversion = "3.00.00.049";
1000 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1001 $dbh->do("ALTER TABLE `z3950servers` ADD `encoding` text default NULL AFTER type ");
1002 print "Upgrade to $DBversion done ( Added encoding field to z3950servers table )\n";
1003 SetVersion ($DBversion);
1006 $DBversion = "3.00.00.050";
1007 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1008 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHighlightedWords','0','If Set, query matched terms are highlighted in OPAC',NULL,'YesNo');");
1009 print "Upgrade to $DBversion done ( Added OpacHighlightedWords syspref )\n";
1010 SetVersion ($DBversion);
1013 $DBversion = "3.00.00.051";
1014 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1015 $dbh->do("UPDATE systempreferences SET explanation = 'Define the current theme for the OPAC interface.' WHERE variable = 'opacthemes';");
1016 print "Upgrade to $DBversion done ( Corrected opacthemes explanation. )\n";
1017 SetVersion ($DBversion);
1020 $DBversion = "3.00.00.052";
1021 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1022 $dbh->do("ALTER TABLE `deleteditems` ADD `more_subfields_xml` LONGTEXT DEFAULT NULL AFTER `itype`");
1023 print "Upgrade to $DBversion done ( Adding missing column to deleteditems table. )\n";
1024 SetVersion ($DBversion);
1027 $DBversion = "3.00.00.053";
1028 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1029 $dbh->do("CREATE TABLE `printers_profile` (
1030 `prof_id` int(4) NOT NULL auto_increment,
1031 `printername` varchar(40) NOT NULL,
1032 `tmpl_id` int(4) NOT NULL,
1033 `paper_bin` varchar(20) NOT NULL,
1034 `offset_horz` float default NULL,
1035 `offset_vert` float default NULL,
1036 `creep_horz` float default NULL,
1037 `creep_vert` float default NULL,
1038 `unit` char(20) NOT NULL default 'POINT',
1039 PRIMARY KEY (`prof_id`),
1040 UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
1041 CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
1042 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1043 $dbh->do("CREATE TABLE `labels_profile` (
1044 `tmpl_id` int(4) NOT NULL,
1045 `prof_id` int(4) NOT NULL,
1046 UNIQUE KEY `tmpl_id` (`tmpl_id`),
1047 UNIQUE KEY `prof_id` (`prof_id`)
1048 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1049 print "Upgrade to $DBversion done ( Printer Profile tables added )\n";
1050 SetVersion ($DBversion);
1053 $DBversion = "3.00.00.054";
1054 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1055 $dbh->do("UPDATE systempreferences SET options = 'incremental|annual|hbyymmincr|OFF', explanation = 'Used to autogenerate a barcode: incremental will be of the form 1, 2, 3; annual of the form 2007-0001, 2007-0002; hbyymmincr of the form HB08010001 where HB = Home Branch' WHERE variable = 'autoBarcode';");
1056 print "Upgrade to $DBversion done ( Added another barcode autogeneration sequence to barcode.pl. )\n";
1057 SetVersion ($DBversion);
1060 $DBversion = "3.00.00.055";
1061 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1062 $dbh->do("ALTER TABLE `zebraqueue` ADD KEY `zebraqueue_lookup` (`server`, `biblio_auth_number`, `operation`, `done`)");
1063 print "Upgrade to $DBversion done ( Added index on zebraqueue. )\n";
1064 SetVersion ($DBversion);
1066 $DBversion = "3.00.00.056";
1067 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1068 if (C4::Context->preference("marcflavour") eq 'UNIMARC') {
1069 $dbh->do("INSERT INTO `marc_subfield_structure` (`tagfield`, `tagsubfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `kohafield`, `tab`, `authorised_value` , `authtypecode`, `value_builder`, `isurl`, `hidden`, `frameworkcode`, `seealso`, `link`, `defaultvalue`) VALUES ('995', 'v', 'Note sur le N° de périodique','Note sur le N° de périodique', 0, 0, 'items.enumchron', 10, '', '', '', 0, 0, '', '', '', NULL) ");
1071 $dbh->do("INSERT INTO `marc_subfield_structure` (`tagfield`, `tagsubfield`, `liblibrarian`, `libopac`, `repeatable`, `mandatory`, `kohafield`, `tab`, `authorised_value` , `authtypecode`, `value_builder`, `isurl`, `hidden`, `frameworkcode`, `seealso`, `link`, `defaultvalue`) VALUES ('952', 'h', 'Serial Enumeration / chronology','Serial Enumeration / chronology', 0, 0, 'items.enumchron', 10, '', '', '', 0, 0, '', '', '', NULL) ");
1073 $dbh->do("ALTER TABLE `items` ADD `enumchron` VARCHAR(80) DEFAULT NULL;");
1074 print "Upgrade to $DBversion done ( Added item.enumchron column, and framework map to 952h )\n";
1075 SetVersion ($DBversion);
1078 $DBversion = "3.00.00.057";
1079 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1080 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH','0','if ON, OAI-PMH server is enabled',NULL,'YesNo');");
1081 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:archiveID','KOHA-OAI-TEST','OAI-PMH archive identification',NULL,'Free');");
1082 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:MaxCount','50','OAI-PMH maximum number of records by answer to ListRecords and ListIdentifiers queries',NULL,'Integer');");
1083 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:Set','SET,Experimental set\r\nSET:SUBSET,Experimental subset','OAI-PMH exported set, the set name is followed by a comma and a short description, one set by line',NULL,'Free');");
1084 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:Subset',\"itemtype='BOOK'\",'Restrict answer to matching raws of the biblioitems table (experimental)',NULL,'Free');");
1085 SetVersion ($DBversion);
1088 $DBversion = "3.00.00.058";
1089 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1090 $dbh->do("ALTER TABLE `opac_news`
1091 CHANGE `lang` `lang` VARCHAR( 25 )
1093 COLLATE utf8_general_ci
1094 NOT NULL default ''");
1095 print "Upgrade to $DBversion done ( lang field in opac_news made longer )\n";
1096 SetVersion ($DBversion);
1099 $DBversion = "3.00.00.059";
1100 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1102 $dbh->do("CREATE TABLE IF NOT EXISTS `labels_templates` (
1103 `tmpl_id` int(4) NOT NULL auto_increment,
1104 `tmpl_code` char(100) default '',
1105 `tmpl_desc` char(100) default '',
1106 `page_width` float default '0',
1107 `page_height` float default '0',
1108 `label_width` float default '0',
1109 `label_height` float default '0',
1110 `topmargin` float default '0',
1111 `leftmargin` float default '0',
1112 `cols` int(2) default '0',
1113 `rows` int(2) default '0',
1114 `colgap` float default '0',
1115 `rowgap` float default '0',
1116 `active` int(1) default NULL,
1117 `units` char(20) default 'PX',
1118 `fontsize` int(4) NOT NULL default '3',
1119 PRIMARY KEY (`tmpl_id`)
1120 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1121 $dbh->do("CREATE TABLE IF NOT EXISTS `printers_profile` (
1122 `prof_id` int(4) NOT NULL auto_increment,
1123 `printername` varchar(40) NOT NULL,
1124 `tmpl_id` int(4) NOT NULL,
1125 `paper_bin` varchar(20) NOT NULL,
1126 `offset_horz` float default NULL,
1127 `offset_vert` float default NULL,
1128 `creep_horz` float default NULL,
1129 `creep_vert` float default NULL,
1130 `unit` char(20) NOT NULL default 'POINT',
1131 PRIMARY KEY (`prof_id`),
1132 UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
1133 CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
1134 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1135 print "Upgrade to $DBversion done ( Added labels_templates table if it did not exist. )\n";
1136 SetVersion ($DBversion);
1139 $DBversion = "3.00.00.060";
1140 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1141 $dbh->do("CREATE TABLE IF NOT EXISTS `patronimage` (
1142 `cardnumber` varchar(16) NOT NULL,
1143 `mimetype` varchar(15) NOT NULL,
1144 `imagefile` mediumblob NOT NULL,
1145 PRIMARY KEY (`cardnumber`),
1146 CONSTRAINT `patronimage_fk1` FOREIGN KEY (`cardnumber`) REFERENCES `borrowers` (`cardnumber`) ON DELETE CASCADE ON UPDATE CASCADE
1147 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1148 print "Upgrade to $DBversion done ( Added patronimage table. )\n";
1149 SetVersion ($DBversion);
1152 $DBversion = "3.00.00.061";
1153 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1154 $dbh->do("ALTER TABLE labels_templates ADD COLUMN font char(10) NOT NULL DEFAULT 'TR';");
1155 print "Upgrade to $DBversion done ( Added font column to labels_templates )\n";
1156 SetVersion ($DBversion);
1159 $DBversion = "3.00.00.062";
1160 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1161 $dbh->do("CREATE TABLE `old_issues` (
1162 `borrowernumber` int(11) default NULL,
1163 `itemnumber` int(11) default NULL,
1164 `date_due` date default NULL,
1165 `branchcode` varchar(10) default NULL,
1166 `issuingbranch` varchar(18) default NULL,
1167 `returndate` date default NULL,
1168 `lastreneweddate` date default NULL,
1169 `return` varchar(4) default NULL,
1170 `renewals` tinyint(4) default NULL,
1171 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1172 `issuedate` date default NULL,
1173 KEY `old_issuesborridx` (`borrowernumber`),
1174 KEY `old_issuesitemidx` (`itemnumber`),
1175 KEY `old_bordate` (`borrowernumber`,`timestamp`),
1176 CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1177 ON DELETE SET NULL ON UPDATE SET NULL,
1178 CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1179 ON DELETE SET NULL ON UPDATE SET NULL
1180 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1181 $dbh->do("CREATE TABLE `old_reserves` (
1182 `borrowernumber` int(11) default NULL,
1183 `reservedate` date default NULL,
1184 `biblionumber` int(11) default NULL,
1185 `constrainttype` varchar(1) default NULL,
1186 `branchcode` varchar(10) default NULL,
1187 `notificationdate` date default NULL,
1188 `reminderdate` date default NULL,
1189 `cancellationdate` date default NULL,
1190 `reservenotes` mediumtext,
1191 `priority` smallint(6) default NULL,
1192 `found` varchar(1) default NULL,
1193 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1194 `itemnumber` int(11) default NULL,
1195 `waitingdate` date default NULL,
1196 KEY `old_reserves_borrowernumber` (`borrowernumber`),
1197 KEY `old_reserves_biblionumber` (`biblionumber`),
1198 KEY `old_reserves_itemnumber` (`itemnumber`),
1199 KEY `old_reserves_branchcode` (`branchcode`),
1200 CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1201 ON DELETE SET NULL ON UPDATE SET NULL,
1202 CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
1203 ON DELETE SET NULL ON UPDATE SET NULL,
1204 CONSTRAINT `old_reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1205 ON DELETE SET NULL ON UPDATE SET NULL
1206 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1208 # move closed transactions to old_* tables
1209 $dbh->do("INSERT INTO old_issues SELECT * FROM issues WHERE returndate IS NOT NULL");
1210 $dbh->do("DELETE FROM issues WHERE returndate IS NOT NULL");
1211 $dbh->do("INSERT INTO old_reserves SELECT * FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
1212 $dbh->do("DELETE FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
1214 print "Upgrade to $DBversion done ( Added old_issues and old_reserves tables )\n";
1215 SetVersion ($DBversion);
1218 $DBversion = "3.00.00.063";
1219 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1220 $dbh->do("ALTER TABLE deleteditems
1221 CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT DEFAULT NULL,
1222 ADD COLUMN enumchron VARCHAR(80) DEFAULT NULL AFTER more_subfields_xml,
1223 ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
1224 $dbh->do("ALTER TABLE items
1225 CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT,
1226 ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
1227 print "Upgrade to $DBversion done ( Changed items.booksellerid and deleteditems.booksellerid to MEDIUMTEXT and added missing items.copynumber and deleteditems.copynumber to fix Bug 1927)\n";
1228 SetVersion ($DBversion);
1231 $DBversion = "3.00.00.064";
1232 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1233 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AmazonLocale','US','Use to set the Locale of your Amazon.com Web Services','US|CA|DE|FR|JP|UK','Choice');");
1234 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSAccessKeyID','','See: http://aws.amazon.com','','free');");
1235 $dbh->do("DELETE FROM `systempreferences` WHERE variable='AmazonDevKey';");
1236 $dbh->do("DELETE FROM `systempreferences` WHERE variable='XISBNAmazonSimilarItems';");
1237 $dbh->do("DELETE FROM `systempreferences` WHERE variable='OPACXISBNAmazonSimilarItems';");
1238 print "Upgrade to $DBversion done (IMPORTANT: Upgrading to Amazon.com Associates Web Service 4.0 ) \n";
1239 SetVersion ($DBversion);
1242 $DBversion = "3.00.00.065";
1243 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1244 $dbh->do("CREATE TABLE `patroncards` (
1245 `cardid` int(11) NOT NULL auto_increment,
1246 `batch_id` varchar(10) NOT NULL default '1',
1247 `borrowernumber` int(11) NOT NULL,
1248 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1249 PRIMARY KEY (`cardid`),
1250 KEY `patroncards_ibfk_1` (`borrowernumber`),
1251 CONSTRAINT `patroncards_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1252 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1253 print "Upgrade to $DBversion done (Adding patroncards table for patroncards generation feature. ) \n";
1254 SetVersion ($DBversion);
1257 $DBversion = "3.00.00.066";
1258 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1259 $dbh->do("ALTER TABLE `virtualshelfcontents` MODIFY `dateadded` timestamp NOT NULL
1260 DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;
1262 print "Upgrade to $DBversion done (fix for bug 1873: virtualshelfcontents dateadded column empty. ) \n";
1263 SetVersion ($DBversion);
1266 $DBversion = "3.00.00.067";
1267 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1268 $dbh->do("UPDATE systempreferences SET explanation = 'Enable patron images for the Staff Client', type = 'YesNo' WHERE variable = 'patronimages'");
1269 print "Upgrade to $DBversion done (Updating patronimages syspref to reflect current kohastructure.sql. ) \n";
1270 SetVersion ($DBversion);
1273 $DBversion = "3.00.00.068";
1274 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1275 $dbh->do("CREATE TABLE `permissions` (
1276 `module_bit` int(11) NOT NULL DEFAULT 0,
1277 `code` varchar(30) DEFAULT NULL,
1278 `description` varchar(255) DEFAULT NULL,
1279 PRIMARY KEY (`module_bit`, `code`),
1280 CONSTRAINT `permissions_ibfk_1` FOREIGN KEY (`module_bit`) REFERENCES `userflags` (`bit`)
1281 ON DELETE CASCADE ON UPDATE CASCADE
1282 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1283 $dbh->do("CREATE TABLE `user_permissions` (
1284 `borrowernumber` int(11) NOT NULL DEFAULT 0,
1285 `module_bit` int(11) NOT NULL DEFAULT 0,
1286 `code` varchar(30) DEFAULT NULL,
1287 CONSTRAINT `user_permissions_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1288 ON DELETE CASCADE ON UPDATE CASCADE,
1289 CONSTRAINT `user_permissions_ibfk_2` FOREIGN KEY (`module_bit`, `code`)
1290 REFERENCES `permissions` (`module_bit`, `code`)
1291 ON DELETE CASCADE ON UPDATE CASCADE
1292 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1294 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES
1295 (13, 'edit_news', 'Write news for the OPAC and staff interfaces'),
1296 (13, 'label_creator', 'Create printable labels and barcodes from catalog and patron data'),
1297 (13, 'edit_calendar', 'Define days when the library is closed'),
1298 (13, 'moderate_comments', 'Moderate patron comments'),
1299 (13, 'edit_notices', 'Define notices'),
1300 (13, 'edit_notice_status_triggers', 'Set notice/status triggers for overdue items'),
1301 (13, 'view_system_logs', 'Browse the system logs'),
1302 (13, 'inventory', 'Perform inventory (stocktaking) of your catalogue'),
1303 (13, 'stage_marc_import', 'Stage MARC records into the reservoir'),
1304 (13, 'manage_staged_marc', 'Managed staged MARC records, including completing and reversing imports'),
1305 (13, 'export_catalog', 'Export bibliographic and holdings data'),
1306 (13, 'import_patrons', 'Import patron data'),
1307 (13, 'delete_anonymize_patrons', 'Delete old borrowers and anonymize circulation history (deletes borrower reading history)'),
1308 (13, 'batch_upload_patron_images', 'Upload patron images in batch or one at a time'),
1309 (13, 'schedule_tasks', 'Schedule tasks to run')");
1311 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('GranularPermissions','0','Use detailed staff user permissions',NULL,'YesNo')");
1313 print "Upgrade to $DBversion done (adding permissions and user_permissions tables and GranularPermissions syspref) \n";
1314 SetVersion ($DBversion);
1316 $DBversion = "3.00.00.069";
1317 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1318 $dbh->do("ALTER TABLE labels_conf CHANGE COLUMN class classification int(1) DEFAULT NULL;");
1319 print "Upgrade to $DBversion done ( Correcting columname in labels_conf )\n";
1320 SetVersion ($DBversion);
1323 $DBversion = "3.00.00.070";
1324 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1325 $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='yuipath'");
1327 my ($value) = $sth->fetchrow;
1328 $value =~ s/2.3.1/2.5.1/;
1329 $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='yuipath';");
1330 print "Update yuipath syspref to 2.5.1 if necessary\n";
1331 SetVersion ($DBversion);
1334 $DBversion = "3.00.00.071";
1335 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1336 $dbh->do(" ALTER TABLE `subscription` ADD `serialsadditems` TINYINT( 1 ) NOT NULL DEFAULT '0';");
1337 # fill the new field with the previous systempreference value, then drop the syspref
1338 my $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='serialsadditems'");
1340 my ($serialsadditems) = $sth->fetchrow();
1341 $dbh->do("UPDATE subscription SET serialsadditems=$serialsadditems");
1342 $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
1343 print "Upgrade to $DBversion done ( moving serialsadditems from syspref to subscription )\n";
1344 SetVersion ($DBversion);
1347 $DBversion = "3.00.00.072";
1348 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1349 $dbh->do("ALTER TABLE labels_conf ADD COLUMN formatstring mediumtext DEFAULT NULL AFTER printingtype");
1350 print "Upgrade to $DBversion done ( Adding format string to labels generator. )\n";
1351 SetVersion ($DBversion);
1354 $DBversion = "3.00.00.073";
1355 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1356 $dbh->do("DROP TABLE IF EXISTS `tags_all`;");
1358 CREATE TABLE `tags_all` (
1359 `tag_id` int(11) NOT NULL auto_increment,
1360 `borrowernumber` int(11) NOT NULL,
1361 `biblionumber` int(11) NOT NULL,
1362 `term` varchar(255) NOT NULL,
1363 `language` int(4) default NULL,
1364 `date_created` datetime NOT NULL,
1365 PRIMARY KEY (`tag_id`),
1366 KEY `tags_borrowers_fk_1` (`borrowernumber`),
1367 KEY `tags_biblionumber_fk_1` (`biblionumber`),
1368 CONSTRAINT `tags_borrowers_fk_1` FOREIGN KEY (`borrowernumber`)
1369 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1370 CONSTRAINT `tags_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
1371 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1372 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1374 $dbh->do("DROP TABLE IF EXISTS `tags_approval`;");
1376 CREATE TABLE `tags_approval` (
1377 `term` varchar(255) NOT NULL,
1378 `approved` int(1) NOT NULL default '0',
1379 `date_approved` datetime default NULL,
1380 `approved_by` int(11) default NULL,
1381 `weight_total` int(9) NOT NULL default '1',
1382 PRIMARY KEY (`term`),
1383 KEY `tags_approval_borrowers_fk_1` (`approved_by`),
1384 CONSTRAINT `tags_approval_borrowers_fk_1` FOREIGN KEY (`approved_by`)
1385 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1386 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1388 $dbh->do("DROP TABLE IF EXISTS `tags_index`;");
1390 CREATE TABLE `tags_index` (
1391 `term` varchar(255) NOT NULL,
1392 `biblionumber` int(11) NOT NULL,
1393 `weight` int(9) NOT NULL default '1',
1394 PRIMARY KEY (`term`,`biblionumber`),
1395 KEY `tags_index_biblionumber_fk_1` (`biblionumber`),
1396 CONSTRAINT `tags_index_term_fk_1` FOREIGN KEY (`term`)
1397 REFERENCES `tags_approval` (`term`) ON DELETE CASCADE ON UPDATE CASCADE,
1398 CONSTRAINT `tags_index_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
1399 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1400 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1403 INSERT INTO `systempreferences` VALUES
1404 ('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=',''),
1405 ('BakerTaylorEnabled','0','','Enable or disable all Baker & Taylor features.','YesNo'),
1406 ('BakerTaylorPassword','','','Baker & Taylor Password for Content Cafe (external content)','Textarea'),
1407 ('BakerTaylorUsername','','','Baker & Taylor Username for Content Cafe (external content)','Textarea'),
1408 ('TagsEnabled','1','','Enables or disables all tagging features. This is the main switch for tags.','YesNo'),
1409 ('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.',''),
1410 ('TagsInputOnDetail','1','','Allow users to input tags from the detail page.', 'YesNo'),
1411 ('TagsInputOnList', '0','','Allow users to input tags from the search results list.', 'YesNo'),
1412 ('TagsModeration', NULL,'','Require tags from patrons to be approved before becoming visible.','YesNo'),
1413 ('TagsShowOnDetail','10','','Number of tags to display on detail page. 0 is off.', 'Integer'),
1414 ('TagsShowOnList', '6','','Number of tags to display on search results list. 0 is off.','Integer')
1416 print "Upgrade to $DBversion done (Baker/Taylor,Tags: sysprefs and tables (tags_all, tags_index, tags_approval)) \n";
1417 SetVersion ($DBversion);
1420 $DBversion = "3.00.00.074";
1421 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1422 $dbh->do( q(update itemtypes set imageurl = concat( 'npl/', imageurl )
1423 where imageurl not like 'http%'
1424 and imageurl is not NULL
1425 and imageurl != '') );
1426 print "Upgrade to $DBversion done (updating imagetype.imageurls to reflect new icon locations.)\n";
1427 SetVersion ($DBversion);
1430 $DBversion = "3.00.00.075";
1431 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1432 $dbh->do( q(alter table authorised_values add imageurl varchar(200) default NULL) );
1433 print "Upgrade to $DBversion done (adding imageurl field to authorised_values table)\n";
1434 SetVersion ($DBversion);
1437 $DBversion = "3.00.00.076";
1438 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1439 $dbh->do("ALTER TABLE import_batches
1440 ADD COLUMN nomatch_action enum('create_new', 'ignore') NOT NULL default 'create_new' AFTER overlay_action");
1441 $dbh->do("ALTER TABLE import_batches
1442 ADD COLUMN item_action enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore')
1443 NOT NULL default 'always_add' AFTER nomatch_action");
1444 $dbh->do("ALTER TABLE import_batches
1445 MODIFY overlay_action enum('replace', 'create_new', 'use_template', 'ignore')
1446 NOT NULL default 'create_new'");
1447 $dbh->do("ALTER TABLE import_records
1448 MODIFY status enum('error', 'staged', 'imported', 'reverted', 'items_reverted',
1449 'ignored') NOT NULL default 'staged'");
1450 $dbh->do("ALTER TABLE import_items
1451 MODIFY status enum('error', 'staged', 'imported', 'reverted', 'ignored') NOT NULL default 'staged'");
1453 print "Upgrade to $DBversion done (changes to import_batches and import_records)\n";
1454 SetVersion ($DBversion);
1457 $DBversion = "3.00.00.077";
1458 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1459 # drop these tables only if they exist and none of them are empty
1460 # these tables are not defined in the packaged 2.2.9, but since it is believed
1461 # that at least one library may be using them in a post-2.2.9 but pre-3.0 Koha,
1462 # some care is taken.
1463 my ($print_error) = $dbh->{PrintError};
1464 $dbh->{PrintError} = 0;
1465 my ($raise_error) = $dbh->{RaiseError};
1466 $dbh->{RaiseError} = 1;
1470 eval { $count = $dbh->do("SELECT 1 FROM categorytable"); };
1474 eval { $count = $dbh->do("SELECT 1 FROM mediatypetable"); };
1478 eval { $count = $dbh->do("SELECT 1 FROM subcategorytable"); };
1484 $dbh->do("DROP TABLE IF EXISTS `categorytable`");
1485 $dbh->do("DROP TABLE IF EXISTS `mediatypetable`");
1486 $dbh->do("DROP TABLE IF EXISTS `subcategorytable`");
1489 $dbh->{PrintError} = $print_error;
1490 $dbh->{RaiseError} = $raise_error;
1491 print "Upgrade to $DBversion done (drop categorytable, subcategorytable, and mediatypetable)\n";
1492 SetVersion ($DBversion);
1495 $DBversion = "3.00.00.078";
1496 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1497 my ($print_error) = $dbh->{PrintError};
1498 $dbh->{PrintError} = 0;
1500 unless ($dbh->do("SELECT 1 FROM browser")) {
1501 $dbh->{PrintError} = $print_error;
1502 $dbh->do("CREATE TABLE `browser` (
1503 `level` int(11) NOT NULL,
1504 `classification` varchar(20) NOT NULL,
1505 `description` varchar(255) NOT NULL,
1506 `number` bigint(20) NOT NULL,
1507 `endnode` tinyint(4) NOT NULL
1508 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1510 $dbh->{PrintError} = $print_error;
1511 print "Upgrade to $DBversion done (add browser table if not already present)\n";
1512 SetVersion ($DBversion);
1515 $DBversion = "3.00.00.079";
1516 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1517 my ($print_error) = $dbh->{PrintError};
1518 $dbh->{PrintError} = 0;
1520 $dbh->do("INSERT INTO `systempreferences` (variable, value,options,type, explanation)VALUES
1521 ('AddPatronLists','categorycode','categorycode|category_type','Choice','Allow user to choose what list to pick up from when adding patrons')");
1522 print "Upgrade to $DBversion done (add browser table if not already present)\n";
1523 SetVersion ($DBversion);
1526 $DBversion = "3.00.00.080";
1527 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1528 $dbh->do("ALTER TABLE subscription CHANGE monthlength monthlength int(11) default '0'");
1529 $dbh->do("ALTER TABLE deleteditems MODIFY marc LONGBLOB AFTER copynumber");
1530 $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
1531 print "Upgrade to $DBversion done (catch up on DB schema changes since alpha and beta)\n";
1532 SetVersion ($DBversion);
1535 $DBversion = "3.00.00.081";
1536 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1537 $dbh->do("CREATE TABLE `borrower_attribute_types` (
1538 `code` varchar(10) NOT NULL,
1539 `description` varchar(255) NOT NULL,
1540 `repeatable` tinyint(1) NOT NULL default 0,
1541 `unique_id` tinyint(1) NOT NULL default 0,
1542 `opac_display` tinyint(1) NOT NULL default 0,
1543 `password_allowed` tinyint(1) NOT NULL default 0,
1544 `staff_searchable` tinyint(1) NOT NULL default 0,
1545 `authorised_value_category` varchar(10) default NULL,
1546 PRIMARY KEY (`code`)
1547 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1548 $dbh->do("CREATE TABLE `borrower_attributes` (
1549 `borrowernumber` int(11) NOT NULL,
1550 `code` varchar(10) NOT NULL,
1551 `attribute` varchar(30) default NULL,
1552 `password` varchar(30) default NULL,
1553 KEY `borrowernumber` (`borrowernumber`),
1554 KEY `code_attribute` (`code`, `attribute`),
1555 CONSTRAINT `borrower_attributes_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1556 ON DELETE CASCADE ON UPDATE CASCADE,
1557 CONSTRAINT `borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`)
1558 ON DELETE CASCADE ON UPDATE CASCADE
1559 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1560 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ExtendedPatronAttributes','0','Use extended patron IDs and attributes',NULL,'YesNo')");
1561 print "Upgrade to $DBversion done (added borrower_attributes and borrower_attribute_types)\n";
1562 SetVersion ($DBversion);
1565 $DBversion = "3.00.00.082";
1566 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1567 $dbh->do( q(alter table accountlines add column lastincrement decimal(28,6) default NULL) );
1568 print "Upgrade to $DBversion done (adding lastincrement column to accountlines table)\n";
1569 SetVersion ($DBversion);
1572 $DBversion = "3.00.00.083";
1573 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1574 $dbh->do( qq(UPDATE systempreferences SET value='local' where variable='yuipath' and value like "%/intranet-tmpl/prog/%"));
1575 print "Upgrade to $DBversion done (Changing yuipath behaviour in managing a local value)\n";
1576 SetVersion ($DBversion);
1578 $DBversion = "3.00.00.084";
1579 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1580 $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')");
1581 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GoogleJackets','0','if ON, displays jacket covers from Google Books API',NULL,'YesNo')");
1582 print "Upgrade to $DBversion done (add new sysprefs)\n";
1583 SetVersion ($DBversion);
1586 $DBversion = "3.00.00.085";
1587 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1588 if (C4::Context->preference("marcflavour") eq 'MARC21') {
1589 $dbh->do("UPDATE marc_subfield_structure SET tab = 0 WHERE tab = 9 AND tagfield = '037'");
1590 $dbh->do("UPDATE marc_subfield_structure SET tab = 1 WHERE tab = 6 AND tagfield in ('100', '110', '111', '130')");
1591 $dbh->do("UPDATE marc_subfield_structure SET tab = 2 WHERE tab = 6 AND tagfield in ('240', '243')");
1592 $dbh->do("UPDATE marc_subfield_structure SET tab = 4 WHERE tab = 6 AND tagfield in ('400', '410', '411', '440')");
1593 $dbh->do("UPDATE marc_subfield_structure SET tab = 5 WHERE tab = 9 AND tagfield = '584'");
1594 $dbh->do("UPDATE marc_subfield_structure SET tab = 7 WHERE tab = -6 AND tagfield = '760'");
1596 print "Upgrade to $DBversion done (move editing tab of various MARC21 subfields)\n";
1597 SetVersion ($DBversion);
1600 $DBversion = "3.00.00.086";
1601 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1603 "CREATE TABLE `tmp_holdsqueue` (
1604 `biblionumber` int(11) default NULL,
1605 `itemnumber` int(11) default NULL,
1606 `barcode` varchar(20) default NULL,
1607 `surname` mediumtext NOT NULL,
1610 `borrowernumber` int(11) NOT NULL,
1611 `cardnumber` varchar(16) default NULL,
1612 `reservedate` date default NULL,
1614 `itemcallnumber` varchar(30) default NULL,
1615 `holdingbranch` varchar(10) default NULL,
1616 `pickbranch` varchar(10) default NULL,
1618 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1620 $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')");
1621 $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')");
1623 print "Upgrade to $DBversion done (Table structure for table `tmp_holdsqueue`)\n";
1624 SetVersion ($DBversion);
1627 $DBversion = "3.00.00.087";
1628 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1629 $dbh->do("INSERT INTO `systempreferences` VALUES ('AutoEmailOpacUser','0','','Sends notification emails containing new account details to patrons - when account is created.','YesNo')" );
1630 $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')");
1631 print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
1632 SetVersion ($DBversion);
1635 $DBversion = "3.00.00.088";
1636 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1637 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('OPACShelfBrowser','1','','Enable/disable Shelf Browser on item details page','YesNo')");
1638 $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')");
1639 $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')");
1640 $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')");
1641 print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
1642 SetVersion ($DBversion);
1645 $DBversion = "3.00.00.089";
1646 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1647 $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')");
1648 print "Upgrade to $DBversion done (added new AdvancedSearchTypes syspref)\n";
1649 SetVersion ($DBversion);
1652 $DBversion = "3.00.00.090";
1653 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1655 CREATE TABLE `branch_borrower_circ_rules` (
1656 `branchcode` VARCHAR(10) NOT NULL,
1657 `categorycode` VARCHAR(10) NOT NULL,
1658 `maxissueqty` int(4) default NULL,
1659 PRIMARY KEY (`categorycode`, `branchcode`),
1660 CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
1661 ON DELETE CASCADE ON UPDATE CASCADE,
1662 CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
1663 ON DELETE CASCADE ON UPDATE CASCADE
1664 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1667 CREATE TABLE `default_borrower_circ_rules` (
1668 `categorycode` VARCHAR(10) NOT NULL,
1669 `maxissueqty` int(4) default NULL,
1670 PRIMARY KEY (`categorycode`),
1671 CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
1672 ON DELETE CASCADE ON UPDATE CASCADE
1673 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1676 CREATE TABLE `default_branch_circ_rules` (
1677 `branchcode` VARCHAR(10) NOT NULL,
1678 `maxissueqty` int(4) default NULL,
1679 PRIMARY KEY (`branchcode`),
1680 CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
1681 ON DELETE CASCADE ON UPDATE CASCADE
1682 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1685 CREATE TABLE `default_circ_rules` (
1686 `singleton` enum('singleton') NOT NULL default 'singleton',
1687 `maxissueqty` int(4) default NULL,
1688 PRIMARY KEY (`singleton`)
1689 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1691 print "Upgrade to $DBversion done (added several circ rules tables)\n";
1692 SetVersion ($DBversion);
1696 $DBversion = "3.00.00.091";
1697 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1698 $dbh->do(<<'END_SQL');
1699 ALTER TABLE borrowers
1700 ADD `smsalertnumber` varchar(50) default NULL
1703 $dbh->do(<<'END_SQL');
1704 CREATE TABLE `message_attributes` (
1705 `message_attribute_id` int(11) NOT NULL auto_increment,
1706 `message_name` varchar(20) NOT NULL default '',
1707 `takes_days` tinyint(1) NOT NULL default '0',
1708 PRIMARY KEY (`message_attribute_id`),
1709 UNIQUE KEY `message_name` (`message_name`)
1710 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1713 $dbh->do(<<'END_SQL');
1714 CREATE TABLE `message_transport_types` (
1715 `message_transport_type` varchar(20) NOT NULL,
1716 PRIMARY KEY (`message_transport_type`)
1717 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1720 $dbh->do(<<'END_SQL');
1721 CREATE TABLE `message_transports` (
1722 `message_attribute_id` int(11) NOT NULL,
1723 `message_transport_type` varchar(20) NOT NULL,
1724 `is_digest` tinyint(1) NOT NULL default '0',
1725 `letter_module` varchar(20) NOT NULL default '',
1726 `letter_code` varchar(20) NOT NULL default '',
1727 PRIMARY KEY (`message_attribute_id`,`message_transport_type`,`is_digest`),
1728 KEY `message_transport_type` (`message_transport_type`),
1729 KEY `letter_module` (`letter_module`,`letter_code`),
1730 CONSTRAINT `message_transports_ibfk_1` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1731 CONSTRAINT `message_transports_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE,
1732 CONSTRAINT `message_transports_ibfk_3` FOREIGN KEY (`letter_module`, `letter_code`) REFERENCES `letter` (`module`, `code`) ON DELETE CASCADE ON UPDATE CASCADE
1733 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1736 $dbh->do(<<'END_SQL');
1737 CREATE TABLE `borrower_message_preferences` (
1738 `borrower_message_preference_id` int(11) NOT NULL auto_increment,
1739 `borrowernumber` int(11) NOT NULL default '0',
1740 `message_attribute_id` int(11) default '0',
1741 `days_in_advance` int(11) default '0',
1742 `wants_digets` tinyint(1) NOT NULL default '0',
1743 PRIMARY KEY (`borrower_message_preference_id`),
1744 KEY `borrowernumber` (`borrowernumber`),
1745 KEY `message_attribute_id` (`message_attribute_id`),
1746 CONSTRAINT `borrower_message_preferences_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1747 CONSTRAINT `borrower_message_preferences_ibfk_2` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE
1748 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1751 $dbh->do(<<'END_SQL');
1752 CREATE TABLE `borrower_message_transport_preferences` (
1753 `borrower_message_preference_id` int(11) NOT NULL default '0',
1754 `message_transport_type` varchar(20) NOT NULL default '0',
1755 PRIMARY KEY (`borrower_message_preference_id`,`message_transport_type`),
1756 KEY `message_transport_type` (`message_transport_type`),
1757 CONSTRAINT `borrower_message_transport_preferences_ibfk_1` FOREIGN KEY (`borrower_message_preference_id`) REFERENCES `borrower_message_preferences` (`borrower_message_preference_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1758 CONSTRAINT `borrower_message_transport_preferences_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE
1759 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1762 $dbh->do(<<'END_SQL');
1763 CREATE TABLE `message_queue` (
1764 `message_id` int(11) NOT NULL auto_increment,
1765 `borrowernumber` int(11) NOT NULL,
1768 `message_transport_type` varchar(20) NOT NULL,
1769 `status` enum('sent','pending','failed','deleted') NOT NULL default 'pending',
1770 `time_queued` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1771 KEY `message_id` (`message_id`),
1772 KEY `borrowernumber` (`borrowernumber`),
1773 KEY `message_transport_type` (`message_transport_type`),
1774 CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1775 CONSTRAINT `messageq_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE RESTRICT ON UPDATE CASCADE
1776 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1779 $dbh->do(<<'END_SQL');
1780 INSERT INTO `systempreferences`
1781 (variable,value,explanation,options,type)
1783 ('EnhancedMessagingPreferences',0,'If ON, allows patrons to select to receive additional messages about items due or nearly due.','','YesNo')
1786 $dbh->do( <<'END_SQL');
1787 INSERT INTO `letter`
1788 (module, code, name, title, content)
1790 ('circulation','DUE','Item Due Reminder','Item Due Reminder','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item is now due:\r\n\r\n<<biblio.title>> by <<biblio.author>>'),
1791 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You have <<count>> items due'),
1792 ('circulation','PREDUE','Advance Notice of Item Due','Advance Notice of Item Due','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThe following item will be due soon:\r\n\r\n<<biblio.title>> by <<biblio.author>>'),
1793 ('circulation','PREDUEDGST','Advance Notice of Item Due (Digest)','Advance Notice of Item Due','You have <<count>> items due soon'),
1794 ('circulation','EVENT','Upcoming Library Event','Upcoming Library Event','Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nThis is a reminder of an upcoming library event in which you have expressed interest.');
1798 'installer/data/mysql/en/mandatory/message_transport_types.sql',
1799 'installer/data/mysql/en/optional/sample_notices_message_attributes.sql',
1800 'installer/data/mysql/en/optional/sample_notices_message_transports.sql',
1803 my $installer = C4::Installer->new();
1804 foreach my $script ( @sql_scripts ) {
1805 my $full_path = $installer->get_file_path_from_name($script);
1806 my $error = $installer->load_sql($full_path);
1807 warn $error if $error;
1810 print "Upgrade to $DBversion done (Table structure for table `message_queue`, `message_transport_types`, `message_attributes`, `message_transports`, `borrower_message_preferences`, and `borrower_message_transport_preferences`. Alter `borrowers` table,\n";
1811 SetVersion ($DBversion);
1814 $DBversion = "3.00.00.092";
1815 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1816 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowOnShelfHolds', '0', '', 'Allow hold requests to be placed on items that are not on loan', 'YesNo')");
1817 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Allow hold requests to be placed on damaged items', 'YesNo')");
1818 print "Upgrade to $DBversion done (added new AllowOnShelfHolds syspref)\n";
1819 SetVersion ($DBversion);
1822 $DBversion = "3.00.00.093";
1823 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1824 $dbh->do("ALTER TABLE `items` MODIFY COLUMN `copynumber` VARCHAR(32) DEFAULT NULL");
1825 $dbh->do("ALTER TABLE `deleteditems` MODIFY COLUMN `copynumber` VARCHAR(32) DEFAULT NULL");
1826 print "Upgrade to $DBversion done (Change data type of items.copynumber to allow free text)\n";
1827 SetVersion ($DBversion);
1830 $DBversion = "3.00.00.094";
1831 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1832 $dbh->do("ALTER TABLE `marc_subfield_structure` MODIFY `tagsubfield` VARCHAR(1) NOT NULL DEFAULT '' COLLATE utf8_bin");
1833 print "Upgrade to $DBversion done (Change Collation of marc_subfield_structure to allow mixed case in subfield labels.)\n";
1834 SetVersion ($DBversion);
1837 $DBversion = "3.00.00.095";
1838 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1839 if (C4::Context->preference("marcflavour") eq 'MARC21') {
1840 $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'MEETI_NAME' WHERE authtypecode = 'Meeting Name'");
1841 $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'CORPO_NAME' WHERE authtypecode = 'CORP0_NAME'");
1843 print "Upgrade to $DBversion done (fix invalid authority types in MARC21 frameworks [bug 2254])\n";
1844 SetVersion ($DBversion);
1847 $DBversion = "3.00.00.096";
1848 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1849 $sth = $dbh->prepare("SHOW COLUMNS FROM borrower_message_preferences LIKE 'wants_digets'");
1851 if (my $row = $sth->fetchrow_hashref) {
1852 $dbh->do("ALTER TABLE borrower_message_preferences CHANGE wants_digets wants_digest tinyint(1) NOT NULL default 0");
1854 print "Upgrade to $DBversion done (fix name borrower_message_preferences.wants_digest)\n";
1855 SetVersion ($DBversion);
1858 $DBversion = '3.00.00.097';
1859 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1861 $dbh->do('ALTER TABLE message_queue ADD to_address mediumtext default NULL');
1862 $dbh->do('ALTER TABLE message_queue ADD from_address mediumtext default NULL');
1863 $dbh->do('ALTER TABLE message_queue ADD content_type text');
1864 $dbh->do('ALTER TABLE message_queue CHANGE borrowernumber borrowernumber int(11) default NULL');
1866 print "Upgrade to $DBversion done (updating 4 fields in message_queue table)\n";
1867 SetVersion($DBversion);
1870 $DBversion = '3.00.00.098';
1871 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1873 $dbh->do(q(DELETE FROM message_transport_types WHERE message_transport_type = 'rss'));
1874 $dbh->do(q(DELETE FROM message_transports WHERE message_transport_type = 'rss'));
1876 print "Upgrade to $DBversion done (removing unused RSS message_transport_type)\n";
1877 SetVersion($DBversion);
1880 $DBversion = '3.00.00.099';
1881 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1882 $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES('OpacSuppression', '0', '', 'Turn ON the OPAC Suppression feature, requires further setup, ask your system administrator for details', 'YesNo')");
1883 print "Upgrade to $DBversion done (Adding OpacSuppression syspref)\n";
1884 SetVersion($DBversion);
1887 $DBversion = '3.00.00.100';
1888 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1889 $dbh->do('ALTER TABLE virtualshelves ADD COLUMN lastmodified timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP');
1890 print "Upgrade to $DBversion done (Adding lastmodified column to virtualshelves)\n";
1891 SetVersion($DBversion);
1894 $DBversion = '3.00.00.101';
1895 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1896 $dbh->do('ALTER TABLE `overduerules` CHANGE `categorycode` `categorycode` VARCHAR(10) NOT NULL');
1897 $dbh->do('ALTER TABLE `deletedborrowers` CHANGE `categorycode` `categorycode` VARCHAR(10) NOT NULL');
1898 print "Upgrade to $DBversion done (Updating columnd definitions for patron category codes in notice/statsu triggers and deletedborrowers tables.)\n";
1899 SetVersion($DBversion);
1902 $DBversion = '3.00.00.102';
1903 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1904 $dbh->do('ALTER TABLE serialitems MODIFY `serialid` int(11) NOT NULL AFTER itemnumber' );
1905 $dbh->do('ALTER TABLE serialitems DROP KEY serialididx' );
1906 $dbh->do('ALTER TABLE serialitems ADD CONSTRAINT UNIQUE KEY serialitemsidx (itemnumber)' );
1907 # before setting constraint, delete any unvalid data
1908 $dbh->do('DELETE from serialitems WHERE serialid not in (SELECT serial.serialid FROM serial)');
1909 $dbh->do('ALTER TABLE serialitems ADD CONSTRAINT serialitems_sfk_1 FOREIGN KEY (serialid) REFERENCES serial (serialid) ON DELETE CASCADE ON UPDATE CASCADE' );
1910 print "Upgrade to $DBversion done (Updating serialitems table to allow for multiple items per serial fixing kohabug 2380)\n";
1911 SetVersion($DBversion);
1914 $DBversion = "3.00.00.103";
1915 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1916 $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
1917 print "Upgrade to $DBversion done ( Verifying the removal of serialsadditems from syspref fixing kohabug 2219)\n";
1918 SetVersion ($DBversion);
1921 $DBversion = "3.00.00.104";
1922 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1923 $dbh->do("DELETE FROM systempreferences WHERE variable='noOPACHolds'");
1924 print "Upgrade to $DBversion done (remove superseded 'noOPACHolds' system preference per bug 2413)\n";
1925 SetVersion ($DBversion);
1928 $DBversion = '3.00.00.105';
1929 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
1931 # it is possible that this syspref is already defined since the feature was added some time ago.
1932 unless ( $dbh->do(q(SELECT variable FROM systempreferences WHERE variable = 'SMSSendDriver')) ) {
1933 $dbh->do(<<'END_SQL');
1934 INSERT INTO `systempreferences`
1935 (variable,value,explanation,options,type)
1937 ('SMSSendDriver','','Sets which SMS::Send driver is used to send SMS messages.','','free')
1940 print "Upgrade to $DBversion done (added SMSSendDriver system preference)\n";
1941 SetVersion($DBversion);
1944 $DBversion = "3.00.00.106";
1945 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1946 $dbh->do("DELETE FROM systempreferences WHERE variable='noOPACHolds'");
1948 # db revision 105 didn't apply correctly, so we're rolling this into 106
1949 $dbh->do("INSERT INTO `systempreferences`
1950 (variable,value,explanation,options,type)
1952 ('SMSSendDriver','','Sets which SMS::Send driver is used to send SMS messages.','','free')");
1954 print "Upgrade to $DBversion done (remove default '0000-00-00' in subscriptionhistory.enddate field)\n";
1955 $dbh->do("ALTER TABLE `subscriptionhistory` CHANGE `enddate` `enddate` DATE NULL DEFAULT NULL ");
1956 $dbh->do("UPDATE subscriptionhistory SET enddate=NULL WHERE enddate='0000-00-00'");
1957 SetVersion ($DBversion);
1960 $DBversion = '3.00.00.107';
1961 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1962 $dbh->do(<<'END_SQL');
1963 UPDATE systempreferences
1964 SET explanation = CONCAT( explanation, '. WARNING: this feature is very resource consuming on collections with large numbers of items.' )
1965 WHERE variable = 'OPACShelfBrowser'
1966 AND explanation NOT LIKE '%WARNING%'
1968 $dbh->do(<<'END_SQL');
1969 UPDATE systempreferences
1970 SET explanation = CONCAT( explanation, '. WARNING: this feature is very resource consuming.' )
1971 WHERE variable = 'CataloguingLog'
1972 AND explanation NOT LIKE '%WARNING%'
1974 $dbh->do(<<'END_SQL');
1975 UPDATE systempreferences
1976 SET explanation = CONCAT( explanation, '. WARNING: using NoZebra on even modest sized collections is very slow.' )
1977 WHERE variable = 'NoZebra'
1978 AND explanation NOT LIKE '%WARNING%'
1980 print "Upgrade to $DBversion done (warning added to OPACShelfBrowser system preference)\n";
1981 SetVersion ($DBversion);
1984 $DBversion = '3.01.00.000';
1985 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1986 print "Upgrade to $DBversion done (start of 3.1)\n";
1987 SetVersion ($DBversion);
1990 $DBversion = '3.01.00.001';
1991 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1993 CREATE TABLE hold_fill_targets (
1994 `borrowernumber` int(11) NOT NULL,
1995 `biblionumber` int(11) NOT NULL,
1996 `itemnumber` int(11) NOT NULL,
1997 `source_branchcode` varchar(10) default NULL,
1998 `item_level_request` tinyint(4) NOT NULL default 0,
1999 PRIMARY KEY `itemnumber` (`itemnumber`),
2000 KEY `bib_branch` (`biblionumber`, `source_branchcode`),
2001 CONSTRAINT `hold_fill_targets_ibfk_1` FOREIGN KEY (`borrowernumber`)
2002 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2003 CONSTRAINT `hold_fill_targets_ibfk_2` FOREIGN KEY (`biblionumber`)
2004 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2005 CONSTRAINT `hold_fill_targets_ibfk_3` FOREIGN KEY (`itemnumber`)
2006 REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2007 CONSTRAINT `hold_fill_targets_ibfk_4` FOREIGN KEY (`source_branchcode`)
2008 REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2009 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2012 ALTER TABLE tmp_holdsqueue
2013 ADD item_level_request tinyint(4) NOT NULL default 0
2016 print "Upgrade to $DBversion done (add hold_fill_targets table and a column to tmp_holdsqueue)\n";
2017 SetVersion($DBversion);
2020 $DBversion = '3.01.00.002';
2021 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2022 # use statistics where available
2024 ALTER TABLE statistics ADD KEY tmp_stats (type, itemnumber, borrowernumber)
2029 SELECT max(datetime)
2031 WHERE type = 'issue'
2032 AND itemnumber = iss.itemnumber
2033 AND borrowernumber = iss.borrowernumber
2035 WHERE issuedate IS NULL;
2037 $dbh->do("ALTER TABLE statistics DROP KEY tmp_stats");
2039 # default to last renewal date
2042 SET issuedate = lastreneweddate
2043 WHERE issuedate IS NULL
2044 and lastreneweddate IS NOT NULL
2047 my $num_bad_issuedates = $dbh->selectrow_array("SELECT COUNT(*) FROM issues WHERE issuedate IS NULL");
2048 if ($num_bad_issuedates > 0) {
2049 print STDERR "After the upgrade to $DBversion, there are still $num_bad_issuedates loan(s) with a NULL (blank) loan date. ",
2050 "Please check the issues table in your database.";
2052 print "Upgrade to $DBversion done (bug 2582: set null issues.issuedate to lastreneweddate)\n";
2053 SetVersion($DBversion);
2056 $DBversion = "3.01.00.003";
2057 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2058 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowRenewalLimitOverride', '0', 'if ON, allows renewal limits to be overridden on the circulation screen',NULL,'YesNo')");
2059 print "Upgrade to $DBversion done (add new syspref)\n";
2060 SetVersion ($DBversion);
2063 $DBversion = '3.01.00.004';
2064 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2065 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACDisplayRequestPriority','0','Show patrons the priority level on holds in the OPAC','','YesNo')");
2066 print "Upgrade to $DBversion done (added OPACDisplayRequestPriority system preference)\n";
2067 SetVersion ($DBversion);
2070 $DBversion = '3.01.00.005';
2071 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2073 INSERT INTO `letter` (module, code, name, title, content)
2074 VALUES('reserves', 'HOLD', 'Hold Available for Pickup', 'Hold Available for Pickup at <<branches.branchname>>', 'Dear <<borrowers.firstname>> <<borrowers.surname>>,\r\n\r\nYou have a hold available for pickup as of <<reserves.waitingdate>>:\r\n\r\nTitle: <<biblio.title>>\r\nAuthor: <<biblio.author>>\r\nCopy: <<items.copynumber>>\r\nLocation: <<branches.branchname>>\r\n<<branches.branchaddress1>>\r\n<<branches.branchaddress2>>\r\n<<branches.branchaddress3>>')
2076 $dbh->do("INSERT INTO `message_attributes` (message_attribute_id, message_name, takes_days) values(4, 'Hold Filled', 0)");
2077 $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'sms', 0, 'reserves', 'HOLD')");
2078 $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'email', 0, 'reserves', 'HOLD')");
2079 print "Upgrade to $DBversion done (Add letter for holds notifications)\n";
2080 SetVersion ($DBversion);
2083 $DBversion = '3.01.00.006';
2084 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2085 $dbh->do("ALTER TABLE `biblioitems` ADD KEY issn (issn)");
2086 print "Upgrade to $DBversion done (add index on biblioitems.issn)\n";
2087 SetVersion ($DBversion);
2090 $DBversion = "3.01.00.007";
2091 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2092 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetmainUserblock'");
2093 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetuserjs'");
2094 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacheader'");
2095 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacMainUserBlock'");
2096 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacNav'");
2097 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacuserjs'");
2098 $dbh->do("UPDATE `systempreferences` SET options='30|10', type='Textarea' WHERE variable='OAI-PMH:Set'");
2099 $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetstylesheet'");
2100 $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetcolorstylesheet'");
2101 $dbh->do("UPDATE `systempreferences` SET options='10' WHERE variable='globalDueDate'");
2102 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='numSearchResults'");
2103 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='OPACnumSearchResults'");
2104 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='ReservesMaxPickupDelay'");
2105 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='TransfersMaxDaysWarning'");
2106 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='StaticHoldsQueueWeight'");
2107 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='holdCancelLength'");
2108 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='XISBNDailyLimit'");
2109 $dbh->do("UPDATE `systempreferences` SET type='Float' WHERE variable='gist'");
2110 $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorUsername'");
2111 $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorPassword'");
2112 $dbh->do("UPDATE `systempreferences` SET type='Textarea', options='70|10' WHERE variable='ISBD'");
2113 $dbh->do("UPDATE `systempreferences` SET type='Textarea', options='70|10', explanation='Enter a specific hash for NoZebra indexes. Enter : \\\'indexname\\\' => \\\'100a,245a,500*\\\',\\\'index2\\\' => \\\'...\\\'' WHERE variable='NoZebraIndexes'");
2114 print "Upgrade to $DBversion done (fix display of many sysprefs)\n";
2115 SetVersion ($DBversion);
2118 $DBversion = '3.01.00.008';
2119 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2121 $dbh->do("CREATE TABLE branch_transfer_limits (
2122 limitId int(8) NOT NULL auto_increment,
2123 toBranch varchar(4) NOT NULL,
2124 fromBranch varchar(4) NOT NULL,
2125 itemtype varchar(4) NOT NULL,
2126 PRIMARY KEY (limitId)
2127 ) ENGINE=InnoDB DEFAULT CHARSET=utf8"
2130 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'UseBranchTransferLimits', '0', '', 'If ON, Koha will will use the rules defined in branch_transfer_limits to decide if an item transfer should be allowed.', 'YesNo')");
2132 print "Upgrade to $DBversion done (added branch_transfer_limits table and UseBranchTransferLimits system preference)\n";
2133 SetVersion ($DBversion);
2136 $DBversion = "3.01.00.009";
2137 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2138 $dbh->do("ALTER TABLE permissions MODIFY `code` varchar(64) DEFAULT NULL");
2139 $dbh->do("ALTER TABLE user_permissions MODIFY `code` varchar(64) DEFAULT NULL");
2140 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'circulate_remaining_permissions', 'Remaining circulation permissions')");
2141 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'override_renewals', 'Override blocked renewals')");
2142 print "Upgrade to $DBversion done (added subpermissions for circulate permission)\n";
2145 $DBversion = '3.01.00.010';
2146 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2147 $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `attribute` VARCHAR(64) DEFAULT NULL");
2148 $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `password` VARCHAR(64) DEFAULT NULL");
2149 print "Upgrade to $DBversion done (bug 2687: increase length of borrower attribute fields)\n";
2150 SetVersion ($DBversion);
2153 $DBversion = '3.01.00.011';
2154 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2156 # Yes, the old value was ^M terminated.
2157 my $bad_value = "function prepareEmailPopup(){\r\n if (!document.getElementById) return false;\r\n if (!document.getElementById('reserveemail')) return false;\r\n rsvlink = document.getElementById('reserveemail');\r\n rsvlink.onclick = function() {\r\n doReservePopup();\r\n return false;\r\n }\r\n}\r\n\r\nfunction doReservePopup(){\r\n}\r\n\r\nfunction prepareReserveList(){\r\n}\r\n\r\naddLoadEvent(prepareEmailPopup);\r\naddLoadEvent(prepareReserveList);";
2159 my $intranetuserjs = C4::Context->preference('intranetuserjs');
2160 if ($intranetuserjs and $intranetuserjs eq $bad_value) {
2161 my $sql = <<'END_SQL';
2162 UPDATE systempreferences
2164 WHERE variable = 'intranetuserjs'
2168 print "Upgrade to $DBversion done (removed bogus intranetuserjs syspref)\n";
2169 SetVersion($DBversion);
2172 $DBversion = "3.01.00.012";
2173 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2174 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowHoldPolicyOverride', '0', 'Allow staff to override hold policies when placing holds',NULL,'YesNo')");
2176 CREATE TABLE `branch_item_rules` (
2177 `branchcode` varchar(10) NOT NULL,
2178 `itemtype` varchar(10) NOT NULL,
2179 `holdallowed` tinyint(1) default NULL,
2180 PRIMARY KEY (`itemtype`,`branchcode`),
2181 KEY `branch_item_rules_ibfk_2` (`branchcode`),
2182 CONSTRAINT `branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE,
2183 CONSTRAINT `branch_item_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2184 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2187 CREATE TABLE `default_branch_item_rules` (
2188 `itemtype` varchar(10) NOT NULL,
2189 `holdallowed` tinyint(1) default NULL,
2190 PRIMARY KEY (`itemtype`),
2191 CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE
2192 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2195 ALTER TABLE default_branch_circ_rules
2196 ADD COLUMN holdallowed tinyint(1) NULL
2199 ALTER TABLE default_circ_rules
2200 ADD COLUMN holdallowed tinyint(1) NULL
2202 print "Upgrade to $DBversion done (Add tables and system preferences for holds policies)\n";
2203 SetVersion ($DBversion);
2206 $DBversion = '3.01.00.013';
2207 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2209 CREATE TABLE item_circulation_alert_preferences (
2210 id int(11) AUTO_INCREMENT,
2211 branchcode varchar(10) NOT NULL,
2212 categorycode varchar(10) NOT NULL,
2213 item_type varchar(10) NOT NULL,
2214 notification varchar(16) NOT NULL,
2216 KEY (branchcode, categorycode, item_type, notification)
2217 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2220 $dbh->do(q{ ALTER TABLE `message_queue` ADD metadata text DEFAULT NULL AFTER content; });
2221 $dbh->do(q{ ALTER TABLE `message_queue` ADD letter_code varchar(64) DEFAULT NULL AFTER metadata; });
2224 INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES
2225 ('circulation','CHECKIN','Item Check-in','Check-ins','The following items have been checked in:\r\n----\r\n<<biblio.title>>\r\n----\r\nThank you.');
2228 INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES
2229 ('circulation','CHECKOUT','Item Checkout','Checkouts','The following items have been checked out:\r\n----\r\n<<biblio.title>>\r\n----\r\nThank you for visiting <<branches.branchname>>.');
2232 $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (5, 'Item Check-in', 0);});
2233 $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (6, 'Item Checkout', 0);});
2235 $dbh->do(q{INSERT INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES (5, 'email', 0, 'circulation', 'CHECKIN');});
2236 $dbh->do(q{INSERT INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES (5, 'sms', 0, 'circulation', 'CHECKIN');});
2237 $dbh->do(q{INSERT INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES (6, 'email', 0, 'circulation', 'CHECKOUT');});
2238 $dbh->do(q{INSERT INTO message_transports (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) VALUES (6, 'sms', 0, 'circulation', 'CHECKOUT');});
2240 print "Upgrade to $DBversion done (data for Email Checkout Slips project)\n";
2241 SetVersion ($DBversion);
2244 $DBversion = "3.01.00.014";
2245 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2246 $dbh->do("ALTER TABLE `branch_transfer_limits` CHANGE `itemtype` `itemtype` VARCHAR( 4 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL");
2247 $dbh->do("ALTER TABLE `branch_transfer_limits` ADD `ccode` VARCHAR( 10 ) NULL ;");
2248 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2250 'BranchTransferLimitsType', 'ccode', 'itemtype|ccode', 'When using branch transfer limits, choose whether to limit by itemtype or collection code.', 'Choice'
2253 print "Upgrade to $DBversion done ( Updated table for Branch Transfer Limits)\n";
2254 SetVersion ($DBversion);
2257 $DBversion = '3.01.00.015';
2258 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2259 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsClientCode', '0', 'Client Code for using Syndetics Solutions content','','free')");
2261 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEnabled', '0', 'Turn on Syndetics Enhanced Content','','YesNo')");
2263 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsCoverImages', '0', 'Display Cover Images from Syndetics','','YesNo')");
2265 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsTOC', '0', 'Display Table of Content information from Syndetics','','YesNo')");
2267 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSummary', '0', 'Display Summary Information from Syndetics','','YesNo')");
2269 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEditions', '0', 'Display Editions from Syndetics','','YesNo')");
2271 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsExcerpt', '0', 'Display Excerpts and first chapters on OPAC from Syndetics','','YesNo')");
2273 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsReviews', '0', 'Display Reviews on OPAC from Syndetics','','YesNo')");
2275 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAuthorNotes', '0', 'Display Notes about the Author on OPAC from Syndetics','','YesNo')");
2277 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAwards', '0', 'Display Awards on OPAC from Syndetics','','YesNo')");
2279 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSeries', '0', 'Display Series information on OPAC from Syndetics','','YesNo')");
2281 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsCoverImageSize', 'MC', 'Choose the size of the Syndetics Cover Image to display on the OPAC detail page, MC is Medium, LC is Large','MC|LC','Choice')");
2283 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonCoverImages', '0', 'Display cover images on OPAC from Amazon Web Services','','YesNo')");
2285 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonCoverImages', '0', 'Display Cover Images in Staff Client from Amazon Web Services','','YesNo')");
2287 $dbh->do("UPDATE systempreferences SET variable='AmazonEnabled' WHERE variable = 'AmazonContent'");
2289 $dbh->do("UPDATE systempreferences SET variable='OPACAmazonEnabled' WHERE variable = 'OPACAmazonContent'");
2291 print "Upgrade to $DBversion done (added Syndetics Enhanced Content system preferences)\n";
2292 SetVersion ($DBversion);
2295 $DBversion = "3.01.00.016";
2296 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2297 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('Babeltheque',0,'Turn ON Babeltheque content - See babeltheque.com to subscribe to this service','','YesNo')");
2298 print "Upgrade to $DBversion done (Added Babeltheque syspref)\n";
2299 SetVersion ($DBversion);
2302 $DBversion = "3.01.00.017";
2303 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2304 $dbh->do("ALTER TABLE `subscription` ADD `staffdisplaycount` VARCHAR(10) NULL;");
2305 $dbh->do("ALTER TABLE `subscription` ADD `opacdisplaycount` VARCHAR(10) NULL;");
2306 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2308 'StaffSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the Staff client', 'Integer'
2310 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2312 'OPACSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the OPAC', 'Integer'
2315 print "Upgrade to $DBversion done ( Updated table for Serials Display)\n";
2316 SetVersion ($DBversion);
2319 $DBversion = "3.01.00.018";
2320 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2321 $dbh->do("ALTER TABLE deletedborrowers ADD `smsalertnumber` varchar(50) default NULL");
2322 print "Upgrade to $DBversion done (added deletedborrowers.smsalertnumber, missed in 3.00.00.091)\n";
2323 SetVersion ($DBversion);
2326 $DBversion = "3.01.00.019";
2327 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2328 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACShowCheckoutName','0','Displays in the OPAC the name of patron who has checked out the material. WARNING: Most sites should leave this off. It is intended for corporate or special sites which need to track who has the item.','','YesNo')");
2329 print "Upgrade to $DBversion done (adding OPACShowCheckoutName systempref)\n";
2330 SetVersion ($DBversion);
2333 $DBversion = "3.01.00.020";
2334 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2335 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesID','','See:http://librarything.com/forlibraries/','','free')");
2336 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesEnabled','0','Enable or Disable Library Thing for Libraries Features','','YesNo')");
2337 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesTabbedView','0','Put LibraryThingForLibraries Content in Tabs.','','YesNo')");
2338 print "Upgrade to $DBversion done (adding LibraryThing for Libraries sysprefs)\n";
2339 SetVersion ($DBversion);
2342 $DBversion = "3.01.00.021";
2343 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2344 my $enable_reviews = C4::Context->preference('OPACAmazonEnabled') ? '1' : '0';
2345 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonReviews', '$enable_reviews', 'Display Amazon readers reviews on OPAC','','YesNo')");
2346 print "Upgrade to $DBversion done (adding OPACAmazonReviews syspref)\n";
2347 SetVersion ($DBversion);
2350 $DBversion = '3.01.00.022';
2351 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2352 $dbh->do("ALTER TABLE `labels_conf` MODIFY COLUMN `formatstring` mediumtext DEFAULT NULL");
2353 print "Upgrade to $DBversion done (bug 2945: increase size of labels_conf.formatstring)\n";
2354 SetVersion ($DBversion);
2357 $DBversion = '3.01.00.023';
2358 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2359 $dbh->do("ALTER TABLE biblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2360 $dbh->do("ALTER TABLE deletedbiblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2361 $dbh->do("ALTER TABLE import_biblios MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2362 $dbh->do("ALTER TABLE suggestions MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2363 print "Upgrade to $DBversion done (bug 2765: increase width of isbn column in several tables)\n";
2364 SetVersion ($DBversion);
2367 $DBversion = "3.01.00.024";
2368 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2369 $dbh->do("ALTER TABLE labels MODIFY COLUMN batch_id int(10) NOT NULL default 1;");
2370 print "Upgrade to $DBversion done (change labels.batch_id from varchar to int)\n";
2371 SetVersion ($DBversion);
2374 $DBversion = '3.01.00.025';
2375 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2376 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'ceilingDueDate', '', '', 'If set, date due will not be past this date. Enter date according to the dateformat System Preference', 'free')");
2378 print "Upgrade to $DBversion done (added ceilingDueDate system preference)\n";
2379 SetVersion ($DBversion);
2382 $DBversion = '3.01.00.026';
2383 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2384 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'numReturnedItemsToShow', '20', '', 'Number of returned items to show on the check-in page', 'Integer')");
2386 print "Upgrade to $DBversion done (added numReturnedItemsToShow system preference)\n";
2387 SetVersion ($DBversion);
2390 $DBversion = '3.01.00.027';
2391 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2392 $dbh->do("ALTER TABLE zebraqueue CHANGE `biblio_auth_number` `biblio_auth_number` bigint(20) unsigned NOT NULL default 0");
2393 print "Upgrade to $DBversion done (Increased size of zebraqueue biblio_auth_number to address bug 3148.)\n";
2394 SetVersion ($DBversion);
2397 $DBversion = '3.01.00.028';
2398 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2399 my $enable_reviews = C4::Context->preference('AmazonEnabled') ? '1' : '0';
2400 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonReviews', '$enable_reviews', 'Display Amazon reviews on staff interface','','YesNo')");
2401 print "Upgrade to $DBversion done (added AmazonReviews)\n";
2402 SetVersion ($DBversion);
2405 $DBversion = '3.01.00.029';
2406 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2407 $dbh->do(q( UPDATE language_rfc4646_to_iso639
2408 SET iso639_2_code = 'spa'
2409 WHERE rfc4646_subtag = 'es'
2410 AND iso639_2_code = 'rus' )
2412 print "Upgrade to $DBversion done (fixed bug 2599: using Spanish search limit retrieves Russian results)\n";
2413 SetVersion ($DBversion);
2416 $DBversion = "3.01.00.030";
2417 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2418 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'AllowNotForLoanOverride', '0', '', 'If ON, Koha will allow the librarian to loan a not for loan item.', 'YesNo')");
2419 print "Upgrade to $DBversion done (added AllowNotForLoanOverride system preference)\n";
2420 SetVersion ($DBversion);
2423 $DBversion = "3.01.00.031";
2424 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2425 $dbh->do("ALTER TABLE branch_transfer_limits
2426 MODIFY toBranch varchar(10) NOT NULL,
2427 MODIFY fromBranch varchar(10) NOT NULL,
2428 MODIFY itemtype varchar(10) NULL");
2429 print "Upgrade to $DBversion done (fix column widths in branch_transfer_limits)\n";
2430 SetVersion ($DBversion);
2433 $DBversion = "3.01.00.032";
2434 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2435 $dbh->do(<<ENDOFRENEWAL);
2436 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RenewalPeriodBase', 'now', 'Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','date_due|now','Choice');
2438 print "Upgrade to $DBversion done (Change the field)\n";
2439 SetVersion ($DBversion);
2442 $DBversion = "3.01.00.033";
2443 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2445 ALTER TABLE borrower_message_preferences
2446 MODIFY borrowernumber int(11) default NULL,
2447 ADD categorycode varchar(10) default NULL AFTER borrowernumber,
2448 ADD KEY `categorycode` (`categorycode`),
2449 ADD CONSTRAINT `borrower_message_preferences_ibfk_3`
2450 FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
2451 ON DELETE CASCADE ON UPDATE CASCADE
2453 print "Upgrade to $DBversion done (DB changes to allow patron category defaults for messaging preferences)\n";
2454 SetVersion ($DBversion);
2457 $DBversion = "3.01.00.034";
2458 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2459 $dbh->do("ALTER TABLE `subscription` ADD COLUMN `graceperiod` INT(11) NOT NULL default '0';");
2460 print "Upgrade to $DBversion done (Adding graceperiod column to subscription table)\n";
2461 SetVersion ($DBversion);
2464 $DBversion = '3.01.00.035';
2465 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2466 $dbh->do(q{ ALTER TABLE `subscription` ADD location varchar(80) NULL DEFAULT '' AFTER callnumber; });
2467 print "Upgrade to $DBversion done (Adding location to subscription table)\n";
2468 SetVersion ($DBversion);
2471 $DBversion = '3.01.00.036';
2472 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2473 $dbh->do("UPDATE systempreferences SET explanation = 'Choose the default detail view in the staff interface; choose between normal, labeled_marc, marc or isbd'
2474 WHERE variable = 'IntranetBiblioDefaultView'
2475 AND explanation = 'IntranetBiblioDefaultView'");
2476 $dbh->do("UPDATE systempreferences SET type = 'Choice', options = 'normal|marc|isbd|labeled_marc'
2477 WHERE variable = 'IntranetBiblioDefaultView'");
2478 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewISBD','1','Allow display of ISBD view of bibiographic records','','YesNo')");
2479 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Allow display of labeled MARC view of bibiographic records','','YesNo')");
2480 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Allow display of MARC view of bibiographic records','','YesNo')");
2481 print "Upgrade to $DBversion done (new viewISBD, viewLabeledMARC, viewMARC sysprefs and tweak IntranetBiblioDefaultView)\n";
2482 SetVersion ($DBversion);
2485 $DBversion = '3.01.00.037';
2486 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2487 $dbh->do('ALTER TABLE authorised_values ADD KEY `lib` (`lib`)');
2488 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Do not run overdue report until filter selected','','YesNo')");
2489 SetVersion ($DBversion);
2490 print "Upgrade to $DBversion done (added FilterBeforeOverdueReport syspref and new index on authorised_values)\n";
2493 $DBversion = "3.01.00.038";
2494 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2495 # update branches table
2497 $dbh->do("ALTER TABLE branches ADD `branchzip` varchar(25) default NULL AFTER `branchaddress3`");
2498 $dbh->do("ALTER TABLE branches ADD `branchcity` mediumtext AFTER `branchzip`");
2499 $dbh->do("ALTER TABLE branches ADD `branchcountry` text AFTER `branchcity`");
2500 $dbh->do("ALTER TABLE branches ADD `branchurl` mediumtext AFTER `branchemail`");
2501 $dbh->do("ALTER TABLE branches ADD `branchnotes` mediumtext AFTER `branchprinter`");
2502 print "Upgrade to $DBversion done (add ZIP, city, country, URL, and notes column to branches)\n";
2503 SetVersion ($DBversion);
2506 $DBversion = '3.01.00.039';
2507 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2508 $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelFormat', '<itemcallnumber><copynumber>', '30|10', 'This preference defines the format for the quick spine label printer. Just list the fields you would like to see in the order you would like to see them, surrounded by <>, for example <itemcallnumber>.', 'Textarea')");
2509 $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('SpineLabelAutoPrint', '0', '', 'If this setting is turned on, a print dialog will automatically pop up for the quick spine label printer.', 'YesNo')");
2510 SetVersion ($DBversion);
2511 print "Upgrade to $DBversion done (added SpineLabelFormat and SpineLabelAutoPrint sysprefs)\n";
2514 $DBversion = '3.01.00.040';
2515 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2516 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('AllowHoldDateInFuture','0','If set a date field is displayed on the Hold screen of the Staff Interface, allowing the hold date to be set in the future.','','YesNo')");
2517 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('OPACAllowHoldDateInFuture','0','If set, along with the AllowHoldDateInFuture system preference, OPAC users can set the date of a hold to be in the future.','','YesNo')");
2518 SetVersion ($DBversion);
2519 print "Upgrade to $DBversion done (AllowHoldDateInFuture and OPACAllowHoldDateInFuture sysprefs)\n";
2522 $DBversion = '3.01.00.041';
2523 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2524 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSPrivateKey','','See: http://aws.amazon.com. Note that this is required after 2009/08/15 in order to retrieve any enhanced content other than book covers from Amazon.','','free')");
2525 SetVersion ($DBversion);
2526 print "Upgrade to $DBversion done (added AWSPrivateKey syspref - note that if you use enhanced content from Amazon, this should be set right away.)\n";
2529 $DBversion = '3.01.00.042';
2530 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2531 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACFineNoRenewals','99999','Fine Limit above which user canmot renew books via OPAC','','Integer')");
2532 SetVersion ($DBversion);
2533 print "Upgrade to $DBversion done (added OPACFineNoRenewals syspref)\n";
2536 $DBversion = '3.01.00.043';
2537 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2538 $dbh->do('ALTER TABLE items ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location');
2539 $dbh->do('UPDATE items SET permanent_location = location');
2540 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'NewItemsDefaultLocation', '', '', 'If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )', '')");
2541 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'InProcessingToShelvingCart', '0', '', 'If set, when any item with a location code of PROC is ''checked in'', it''s location code will be changed to CART.', 'YesNo')");
2542 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'ReturnToShelvingCart', '0', '', 'If set, when any item is ''checked in'', it''s location code will be changed to CART.', 'YesNo')");
2543 SetVersion ($DBversion);
2544 print "Upgrade to $DBversion done (amended Item added NewItemsDefaultLocation, InProcessingToShelvingCart, ReturnToShelvingCart sysprefs)\n";
2547 $DBversion = '3.01.00.044';
2548 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2549 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES( 'DisplayClearScreenButton', '0', 'If set to yes, a clear screen button will appear on the circulation page.', 'If set to yes, a clear screen button will appear on the circulation page.', 'YesNo')");
2550 SetVersion ($DBversion);
2551 print "Upgrade to $DBversion done (added DisplayClearScreenButton system preference)\n";
2554 $DBversion = '3.01.00.045';
2555 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2556 $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('HidePatronName', '0', '', 'If this is switched on, patron''s cardnumber will be shown instead of their name on the holds and catalog screens', 'YesNo')");
2557 SetVersion ($DBversion);
2558 print "Upgrade to $DBversion done (added a preference to hide the patrons name in the staff catalog)\n";
2561 $DBversion = "3.01.00.046";
2562 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2563 # update borrowers table
2565 $dbh->do("ALTER TABLE borrowers ADD `country` text AFTER zipcode");
2566 $dbh->do("ALTER TABLE borrowers ADD `B_country` text AFTER B_zipcode");
2567 $dbh->do("ALTER TABLE deletedborrowers ADD `country` text AFTER zipcode");
2568 $dbh->do("ALTER TABLE deletedborrowers ADD `B_country` text AFTER B_zipcode");
2569 print "Upgrade to $DBversion done (add country and B_country to borrowers)\n";
2570 SetVersion ($DBversion);
2573 $DBversion = '3.01.00.047';
2574 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2575 $dbh->do("ALTER TABLE items MODIFY itemcallnumber varchar(255);");
2576 $dbh->do("ALTER TABLE deleteditems MODIFY itemcallnumber varchar(255);");
2577 $dbh->do("ALTER TABLE tmp_holdsqueue MODIFY itemcallnumber varchar(255);");
2578 SetVersion ($DBversion);
2579 print " Upgrade to $DBversion done (bug 2761: change max length of itemcallnumber to 255 from 30)\n";
2582 $DBversion = '3.01.00.048';
2583 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2584 $dbh->do("UPDATE userflags SET flagdesc='View Catalog (Librarian Interface)' WHERE bit=2;");
2585 $dbh->do("UPDATE userflags SET flagdesc='Edit Catalog (Modify bibliographic/holdings data)' WHERE bit=9;");
2586 $dbh->do("UPDATE userflags SET flagdesc='Allow to edit authorities' WHERE bit=14;");
2587 $dbh->do("UPDATE userflags SET flagdesc='Allow to access to the reports module' WHERE bit=16;");
2588 $dbh->do("UPDATE userflags SET flagdesc='Allow to manage serials subscriptions' WHERE bit=15;");
2589 SetVersion ($DBversion);
2590 print " Upgrade to $DBversion done (bug 2611: fix spelling/capitalization in permission flag descriptions)\n";
2593 $DBversion = '3.01.00.049';
2594 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2595 $dbh->do("UPDATE permissions SET description = 'Perform inventory (stocktaking) of your catalog' WHERE code = 'inventory';");
2596 SetVersion ($DBversion);
2597 print "Upgrade to $DBversion done (bug 2611: changed catalogue to catalog per the standard)\n";
2600 $DBversion = '3.01.00.050';
2601 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2602 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OPACSearchForTitleIn','<li class=\"yuimenuitem\">\n<a target=\"_blank\" class=\"yuimenuitemlabel\" href=\"http://worldcat.org/search?q=TITLE\">Other Libraries (WorldCat)</a></li>\n<li class=\"yuimenuitem\">\n<a class=\"yuimenuitemlabel\" href=\"http://www.scholar.google.com/scholar?q=TITLE\" target=\"_blank\">Other Databases (Google Scholar)</a></li>\n<li class=\"yuimenuitem\">\n<a class=\"yuimenuitemlabel\" href=\"http://www.bookfinder.com/search/?author=AUTHOR&title=TITLE&st=xl&ac=qr\" target=\"_blank\">Online Stores (Bookfinder.com)</a></li>','Enter the HTML that will appear in the ''Search for this title in'' box on the detail page in the OPAC. Enter TITLE, AUTHOR, or ISBN in place of their respective variables in the URL. Leave blank to disable ''More Searches'' menu.','70|10','Textarea');");
2603 SetVersion ($DBversion);
2604 print "Upgrade to $DBversion done (bug 1934: Add OPACSearchForTitleIn syspref)\n";
2607 $DBversion = '3.01.00.051';
2608 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2609 $dbh->do("UPDATE systempreferences SET explanation='Fine limit above which user cannot renew books via OPAC' WHERE variable='OPACFineNoRenewals';");
2610 $dbh->do("UPDATE systempreferences SET explanation='If set to ON, a clear screen button will appear on the circulation page.' WHERE variable='DisplayClearScreenButton';");
2611 SetVersion ($DBversion);
2612 print "Upgrade to $DBversion done (fixed typos in new sysprefs)\n";
2615 $DBversion = '3.01.00.052';
2616 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2617 $dbh->do('ALTER TABLE deleteditems ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location');
2618 SetVersion ($DBversion);
2619 print "Upgrade to $DBversion done (bug 3481: add permanent_location column to deleteditems)\n";
2622 $DBversion = '3.01.00.053';
2623 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2624 my $upgrade_script = C4::Context->config("intranetdir") . "/installer/data/mysql/labels_upgrade.pl";
2625 system("perl $upgrade_script");
2626 print "Upgrade to $DBversion done (Migrated labels tables and data to new schema.) NOTE: All existing label batches have been assigned to the first branch in the list of branches. This is ONLY true of migrated label batches.\n";
2627 SetVersion ($DBversion);
2630 $DBversion = '3.01.00.054';
2631 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2632 $dbh->do("ALTER TABLE borrowers ADD `B_address2` text AFTER B_address");
2633 $dbh->do("ALTER TABLE borrowers ADD `altcontactcountry` text AFTER altcontactzipcode");
2634 $dbh->do("ALTER TABLE deletedborrowers ADD `B_address2` text AFTER B_address");
2635 $dbh->do("ALTER TABLE deletedborrowers ADD `altcontactcountry` text AFTER altcontactzipcode");
2636 SetVersion ($DBversion);
2637 print "Upgrade to $DBversion done (bug 1600, bug 3454: add altcontactcountry and B_address2 to borrowers and deletedborrowers)\n";
2640 $DBversion = '3.01.00.055';
2641 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2642 $dbh->do(qq|UPDATE systempreferences set explanation='Enter the HTML that will appear in the ''Search for this title in'' box on the detail page in the OPAC. Enter {TITLE}, {AUTHOR}, or {ISBN} in place of their respective variables in the URL. Leave blank to disable ''More Searches'' menu.', value='<li><a href="http://worldcat.org/search?q={TITLE}" target="_blank">Other Libraries (WorldCat)</a></li>\n<li><a href="http://www.scholar.google.com/scholar?q={TITLE}" target="_blank">Other Databases (Google Scholar)</a></li>\n<li><a href="http://www.bookfinder.com/search/?author={AUTHOR}&title={TITLE}&st=xl&ac=qr" target="_blank">Online Stores (Bookfinder.com)</a></li>' WHERE variable='OPACSearchForTitleIn'|);
2643 SetVersion ($DBversion);
2644 print "Upgrade to $DBversion done (changed OPACSearchForTitleIn per requests in bug 1934)\n";
2647 $DBversion = '3.01.00.056';
2648 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2649 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OPACPatronDetails','1','If OFF the patron details tab in the OPAC is disabled.','','YesNo');");
2650 SetVersion ($DBversion);
2651 print "Upgrade to $DBversion done (Bug 1172 : Add OPACPatronDetails syspref)\n";
2654 $DBversion = '3.01.00.057';
2655 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2656 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OPACFinesTab','1','If OFF the patron fines tab in the OPAC is disabled.','','YesNo');");
2657 SetVersion ($DBversion);
2658 print "Upgrade to $DBversion done (Bug 2576 : Add OPACFinesTab syspref)\n";
2661 $DBversion = '3.01.00.058';
2662 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2663 $dbh->do("ALTER TABLE `language_subtag_registry` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2664 $dbh->do("ALTER TABLE `language_rfc4646_to_iso639` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2665 $dbh->do("ALTER TABLE `language_descriptions` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2666 SetVersion ($DBversion);
2667 print "Upgrade to $DBversion done (Added primary keys to language tables)\n";
2670 $DBversion = '3.01.00.059';
2671 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2672 $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type)VALUES('DisplayOPACiconsXSLT', '1', '', 'If ON, displays the format, audience, type icons in XSLT MARC21 results and display pages.', 'YesNo')");
2673 SetVersion ($DBversion);
2674 print "Upgrade to $DBversion done (added DisplayOPACiconsXSLT sysprefs)\n";
2677 $DBversion = '3.01.00.060';
2678 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2679 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo');");
2680 $dbh->do('DROP TABLE IF EXISTS messages');
2681 $dbh->do("CREATE TABLE messages ( `message_id` int(11) NOT NULL auto_increment,
2682 `borrowernumber` int(11) NOT NULL,
2683 `branchcode` varchar(4) default NULL,
2684 `message_type` varchar(1) NOT NULL,
2685 `message` text NOT NULL,
2686 `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
2687 PRIMARY KEY (`message_id`)
2688 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
2690 print "Upgrade to $DBversion done ( Added AllowAllMessageDeletion syspref and messages table )\n";
2691 SetVersion ($DBversion);
2694 $DBversion = '3.01.00.061';
2695 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2696 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('ShowPatronImageInWebBasedSelfCheck', '0', 'If ON, displays patron image when a patron uses web-based self-checkout', '', 'YesNo')");
2697 print "Upgrade to $DBversion done ( Added ShowPatronImageInWebBasedSelfCheck system preference )\n";
2698 SetVersion ($DBversion);
2701 $DBversion = "3.01.00.062";
2702 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2703 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'manage_csv_profiles', 'Manage CSV export profiles')");
2705 CREATE TABLE `export_format` (
2706 `export_format_id` int(11) NOT NULL auto_increment,
2707 `profile` varchar(255) NOT NULL,
2708 `description` mediumtext NOT NULL,
2709 `marcfields` mediumtext NOT NULL,
2710 PRIMARY KEY (`export_format_id`)
2711 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used for CSV export';
2713 print "Upgrade to $DBversion done (added csv export profiles)\n";
2716 $DBversion = "3.01.00.063";
2717 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2719 CREATE TABLE `fieldmapping` (
2720 `id` int(11) NOT NULL auto_increment,
2721 `field` varchar(255) NOT NULL,
2722 `frameworkcode` char(4) NOT NULL default '',
2723 `fieldcode` char(3) NOT NULL,
2724 `subfieldcode` char(1) NOT NULL,
2726 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2728 SetVersion ($DBversion);print "Upgrade to $DBversion done (Created table fieldmapping)\n";print "Upgrade to 3.01.00.064 done (Version number skipped: nothing done)\n";
2731 $DBversion = '3.01.00.065';
2732 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2733 $dbh->do('ALTER TABLE issuingrules ADD COLUMN `renewalsallowed` smallint(6) NOT NULL default "0" AFTER `issuelength`;');
2734 $sth = $dbh->prepare("SELECT itemtype, renewalsallowed FROM itemtypes");
2737 my $sthupd = $dbh->prepare("UPDATE issuingrules SET renewalsallowed = ? WHERE itemtype = ?");
2739 while(my $row = $sth->fetchrow_hashref){
2740 $sthupd->execute($row->{renewalsallowed}, $row->{itemtype});
2743 $dbh->do('ALTER TABLE itemtypes DROP COLUMN `renewalsallowed`;');
2745 SetVersion ($DBversion);
2746 print "Upgrade to $DBversion done (Moving allowed renewals from itemtypes to issuingrule)\n";
2749 $DBversion = '3.01.00.066';
2750 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2751 $dbh->do('ALTER TABLE issuingrules ADD COLUMN `reservesallowed` smallint(6) NOT NULL default "0" AFTER `renewalsallowed`;');
2753 my $maxreserves = C4::Context->preference('maxreserves');
2754 $sth = $dbh->prepare('UPDATE issuingrules SET reservesallowed = ?;');
2755 $sth->execute($maxreserves);
2757 $dbh->do('DELETE FROM systempreferences WHERE variable = "maxreserves";');
2759 $dbh->do("INSERT INTO systempreferences (variable,value, options, explanation, type) VALUES('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice')");
2761 SetVersion ($DBversion);
2762 print "Upgrade to $DBversion done (Moving max allowed reserves from system preference to issuingrule)\n";
2765 $DBversion = "3.01.00.067";
2766 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2767 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchmod', 'Perform batch modification of items')");
2768 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchdel', 'Perform batch deletion of items')");
2769 print "Upgrade to $DBversion done (added permissions for batch modification and deletion)\n";
2770 SetVersion ($DBversion);
2773 $DBversion = "3.01.00.068";
2774 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2775 $dbh->do("ALTER TABLE issuingrules ADD COLUMN `finedays` int(11) default NULL AFTER `fine` ");
2776 print "Upgrade to $DBversion done (Adding finedays in issuingrules table)\n";
2777 SetVersion ($DBversion);
2781 $DBversion = "3.01.00.069";
2782 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2783 $dbh->do("INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('EnableOpacSearchHistory', '1', '', 'Enable or disable opac search history', 'YesNo')");
2785 my $create = <<SEARCHHIST;
2786 CREATE TABLE IF NOT EXISTS `search_history` (
2787 `userid` int(11) NOT NULL,
2788 `sessionid` varchar(32) NOT NULL,
2789 `query_desc` varchar(255) NOT NULL,
2790 `query_cgi` varchar(255) NOT NULL,
2791 `total` int(11) NOT NULL,
2792 `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
2793 KEY `userid` (`userid`),
2794 KEY `sessionid` (`sessionid`)
2795 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Opac search history results';
2799 print "Upgrade to $DBversion done (added OPAC search history preference and table)\n";
2802 $DBversion = "3.01.00.070";
2803 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2804 $dbh->do("ALTER TABLE authorised_values ADD COLUMN `lib_opac` VARCHAR(80) default NULL AFTER `lib`");
2805 print "Upgrade to $DBversion done (Added a lib_opac field in authorised_values table)\n";
2808 $DBversion = "3.01.00.071";
2809 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2810 $dbh->do("ALTER TABLE `subscription` ADD `enddate` date default NULL");
2811 $dbh->do("ALTER TABLE subscriptionhistory CHANGE enddate histenddate DATE default NULL");
2812 print "Upgrade to $DBversion done ( Adding enddate to subscription)\n";
2815 # Acquisitions update
2817 $DBversion = "3.01.00.072";
2818 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2819 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacPrivacy', '0', 'if ON, allows patrons to define their privacy rules (reading history)',NULL,'YesNo')");
2820 # create a new syspref for the 'Mr anonymous' patron
2821 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AnonymousPatron', '0', \"Set the identifier (borrowernumber) of the 'Mister anonymous' patron. Used for Suggestion and reading history privacy\",NULL,'')");
2822 # fill AnonymousPatron with AnonymousSuggestion value (copy)
2823 my $sth=$dbh->prepare("SELECT value FROM systempreferences WHERE variable='AnonSuggestions'");
2825 my ($value) = $sth->fetchrow() || 0;
2826 $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='AnonymousPatron'");
2827 # set AnonymousSuggestion do YesNo
2828 # 1st, set the value (1/True if it had a borrowernumber)
2829 $dbh->do("UPDATE systempreferences SET value=1 WHERE variable='AnonSuggestions' AND value>0");
2830 # 2nd, change the type to Choice
2831 $dbh->do("UPDATE systempreferences SET type='YesNo' WHERE variable='AnonSuggestions'");
2832 # borrower reading record privacy : 0 : forever, 1 : laws, 2 : don't keep at all
2833 $dbh->do("ALTER TABLE `borrowers` ADD `privacy` INTEGER NOT NULL DEFAULT 1;");
2834 print "Upgrade to $DBversion done (add new syspref and column in borrowers)\n";
2835 SetVersion ($DBversion);
2838 $DBversion = '3.01.00.073';
2839 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2840 $dbh->do('SET FOREIGN_KEY_CHECKS=0 ');
2841 $dbh->do(<<'END_SQL');
2842 CREATE TABLE IF NOT EXISTS `aqcontract` (
2843 `contractnumber` int(11) NOT NULL auto_increment,
2844 `contractstartdate` date default NULL,
2845 `contractenddate` date default NULL,
2846 `contractname` varchar(50) default NULL,
2847 `contractdescription` mediumtext,
2848 `booksellerid` int(11) not NULL,
2849 PRIMARY KEY (`contractnumber`),
2850 CONSTRAINT `booksellerid_fk1` FOREIGN KEY (`booksellerid`)
2851 REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
2852 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
2854 $dbh->do('SET FOREIGN_KEY_CHECKS=1 ');
2855 print "Upgrade to $DBversion done (adding aqcontract table)\n";
2856 SetVersion ($DBversion);
2859 $DBversion = '3.01.00.074';
2860 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2861 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `basketname` varchar(50) default NULL AFTER `basketno`");
2862 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `note` mediumtext AFTER `basketname`");
2863 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `booksellernote` mediumtext AFTER `note`");
2864 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `contractnumber` int(11) AFTER `booksellernote`");
2865 $dbh->do("ALTER TABLE `aqbasket` ADD FOREIGN KEY (`contractnumber`) REFERENCES `aqcontract` (`contractnumber`)");
2866 print "Upgrade to $DBversion done (edit aqbasket table done)\n";
2867 SetVersion ($DBversion);
2870 $DBversion = '3.01.00.075';
2871 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2872 $dbh->do("ALTER TABLE `aqorders` ADD COLUMN `uncertainprice` tinyint(1)");
2874 print "Upgrade to $DBversion done (adding uncertainprices)\n";
2875 SetVersion ($DBversion);
2878 $DBversion = '3.01.00.076';
2879 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2880 $dbh->do('SET FOREIGN_KEY_CHECKS=0 ');
2881 $dbh->do("CREATE TABLE IF NOT EXISTS `aqbasketgroups` (
2882 `id` int(11) NOT NULL auto_increment,
2883 `name` varchar(50) default NULL,
2884 `closed` tinyint(1) default NULL,
2885 `booksellerid` int(11) NOT NULL,
2887 KEY `booksellerid` (`booksellerid`),
2888 CONSTRAINT `aqbasketgroups_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
2889 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
2890 $dbh->do("ALTER TABLE aqbasket ADD COLUMN `basketgroupid` int(11)");
2891 $dbh->do("ALTER TABLE aqbasket ADD FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE ON DELETE SET NULL");
2892 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('pdfformat','pdfformat::layout2pages','Controls what script is used for printing (basketgroups)','','free')");
2893 $dbh->do('SET FOREIGN_KEY_CHECKS=1 ');
2894 print "Upgrade to $DBversion done (adding basketgroups)\n";
2895 SetVersion ($DBversion);
2897 $DBversion = '3.01.00.077';
2898 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2900 $dbh->do("SET FOREIGN_KEY_CHECKS=0 ");
2901 # create a mapping table holding the info we need to match orders to budgets
2902 $dbh->do('DROP TABLE IF EXISTS fundmapping');
2904 q|CREATE TABLE fundmapping AS
2905 SELECT aqorderbreakdown.ordernumber, branchcode, bookfundid, budgetdate, entrydate
2906 FROM aqorderbreakdown JOIN aqorders ON aqorderbreakdown.ordernumber = aqorders.ordernumber|);
2907 # match the new type of the corresponding field
2908 $dbh->do('ALTER TABLE fundmapping modify column bookfundid varchar(30)');
2909 # System did not ensure budgetdate was valid historically
2910 $dbh->do(q|UPDATE fundmapping SET budgetdate = entrydate WHERE budgetdate = '0000-00-00' OR budgetdate IS NULL|);
2911 # We save the map in fundmapping in case you need later processing
2912 $dbh->do(q|ALTER TABLE fundmapping add column aqbudgetid integer|);
2913 # these can speed processing up
2914 $dbh->do(q|CREATE INDEX fundmaporder ON fundmapping (ordernumber)|);
2915 $dbh->do(q|CREATE INDEX fundmapid ON fundmapping (bookfundid)|);
2917 $dbh->do("DROP TABLE IF EXISTS `aqbudgetperiods` ");
2920 CREATE TABLE `aqbudgetperiods` (
2921 `budget_period_id` int(11) NOT NULL auto_increment,
2922 `budget_period_startdate` date NOT NULL,
2923 `budget_period_enddate` date NOT NULL,
2924 `budget_period_active` tinyint(1) default '0',
2925 `budget_period_description` mediumtext,
2926 `budget_period_locked` tinyint(1) default NULL,
2927 `sort1_authcat` varchar(10) default NULL,
2928 `sort2_authcat` varchar(10) default NULL,
2929 PRIMARY KEY (`budget_period_id`)
2930 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |);
2932 $dbh->do(<<ADDPERIODS);
2933 INSERT INTO aqbudgetperiods (budget_period_startdate,budget_period_enddate,budget_period_active,budget_period_description,budget_period_locked)
2934 SELECT DISTINCT startdate, enddate, NOW() BETWEEN startdate and enddate, concat(startdate," ",enddate),NOT NOW() BETWEEN startdate AND enddate from aqbudget
2936 # SORRY , NO AQBUDGET/AQBOOKFUND -> AQBUDGETS IMPORT JUST YET,
2937 # BUT A NEW CLEAN AQBUDGETS TABLE CREATE FOR NOW..
2938 # DROP TABLE IF EXISTS `aqbudget`;
2939 #CREATE TABLE `aqbudget` (
2940 # `bookfundid` varchar(10) NOT NULL default ',
2941 # `startdate` date NOT NULL default 0,
2942 # `enddate` date default NULL,
2943 # `budgetamount` decimal(13,2) default NULL,
2944 # `aqbudgetid` tinyint(4) NOT NULL auto_increment,
2945 # `branchcode` varchar(10) default NULL,
2946 DropAllForeignKeys('aqbudget');
2947 #$dbh->do("drop table aqbudget;");
2950 my $maxbudgetid = $dbh->selectcol_arrayref(<<IDsBUDGET);
2951 SELECT MAX(aqbudgetid) from aqbudget
2954 $$maxbudgetid[0] = 0 if !$$maxbudgetid[0];
2956 $dbh->do(<<BUDGETAUTOINCREMENT);
2957 ALTER TABLE aqbudget AUTO_INCREMENT=$$maxbudgetid[0]
2960 $dbh->do(<<BUDGETNAME);
2961 ALTER TABLE aqbudget RENAME `aqbudgets`
2964 $dbh->do(<<BUDGETS);
2965 ALTER TABLE `aqbudgets`
2966 CHANGE COLUMN aqbudgetid `budget_id` int(11) NOT NULL AUTO_INCREMENT,
2967 CHANGE COLUMN branchcode `budget_branchcode` varchar(10) default NULL,
2968 CHANGE COLUMN budgetamount `budget_amount` decimal(28,6) NOT NULL default '0.00',
2969 CHANGE COLUMN bookfundid `budget_code` varchar(30) default NULL,
2970 ADD COLUMN `budget_parent_id` int(11) default NULL,
2971 ADD COLUMN `budget_name` varchar(80) default NULL,
2972 ADD COLUMN `budget_encumb` decimal(28,6) default '0.00',
2973 ADD COLUMN `budget_expend` decimal(28,6) default '0.00',
2974 ADD COLUMN `budget_notes` mediumtext,
2975 ADD COLUMN `budget_description` mediumtext,
2976 ADD COLUMN `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2977 ADD COLUMN `budget_amount_sublevel` decimal(28,6) AFTER `budget_amount`,
2978 ADD COLUMN `budget_period_id` int(11) default NULL,
2979 ADD COLUMN `sort1_authcat` varchar(80) default NULL,
2980 ADD COLUMN `sort2_authcat` varchar(80) default NULL,
2981 ADD COLUMN `budget_owner_id` int(11) default NULL,
2982 ADD COLUMN `budget_permission` int(1) default '0';
2985 $dbh->do(<<BUDGETCONSTRAINTS);
2986 ALTER TABLE `aqbudgets`
2987 ADD CONSTRAINT `aqbudgets_ifbk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON DELETE CASCADE ON UPDATE CASCADE
2989 # $dbh->do(<<BUDGETPKDROP);
2990 #ALTER TABLE `aqbudgets`
2993 # $dbh->do(<<BUDGETPKADD);
2994 #ALTER TABLE `aqbudgets`
2995 # ADD PRIMARY KEY budget_id
2999 my $query_period= $dbh->prepare(qq|SELECT budget_period_id from aqbudgetperiods where budget_period_startdate=? and budget_period_enddate=?|);
3000 my $query_bookfund= $dbh->prepare(qq|SELECT * from aqbookfund where bookfundid=?|);
3001 my $selectbudgets=$dbh->prepare(qq|SELECT * from aqbudgets|);
3002 my $updatebudgets=$dbh->prepare(qq|UPDATE aqbudgets SET budget_period_id= ? , budget_name=?, budget_branchcode=? where budget_id=?|);
3003 $selectbudgets->execute;
3004 while (my $databudget=$selectbudgets->fetchrow_hashref){
3005 $query_period->execute ($$databudget{startdate},$$databudget{enddate});
3006 my ($budgetperiodid)=$query_period->fetchrow;
3007 $query_bookfund->execute ($$databudget{budget_code});
3008 my $databf=$query_bookfund->fetchrow_hashref;
3009 my $branchcode=$$databudget{budget_branchcode}||$$databf{branchcode};
3010 $updatebudgets->execute($budgetperiodid,$$databf{bookfundname},$branchcode,$$databudget{budget_id});
3012 $dbh->do(<<BUDGETDROPDATES);
3013 ALTER TABLE `aqbudgets`
3019 $dbh->do("DROP TABLE IF EXISTS `aqbudgets_planning` ");
3020 $dbh->do("CREATE TABLE `aqbudgets_planning` (
3021 `plan_id` int(11) NOT NULL auto_increment,
3022 `budget_id` int(11) NOT NULL,
3023 `budget_period_id` int(11) NOT NULL,
3024 `estimated_amount` decimal(28,6) default NULL,
3025 `authcat` varchar(30) NOT NULL,
3026 `authvalue` varchar(30) NOT NULL,
3027 `display` tinyint(1) DEFAULT 1,
3028 PRIMARY KEY (`plan_id`),
3029 CONSTRAINT `aqbudgets_planning_ifbk_1` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
3030 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
3032 $dbh->do("ALTER TABLE `aqorders`
3033 ADD COLUMN `budget_id` tinyint(4) NOT NULL,
3034 ADD COLUMN `budgetgroup_id` int(11) NOT NULL,
3035 ADD COLUMN `sort1_authcat` varchar(10) default NULL,