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 under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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!
42 use MARC::File::XML ( BinaryEncoding => 'utf8' );
44 # FIXME - The user might be installing a new database, so can't rely
45 # on /etc/koha.conf anyway.
52 %existingtables, # tables already in database
56 $type, $null, $key, $default, $extra,
57 $prefitem, # preference item in systempreferences table
64 my $dbh = C4::Context->dbh;
65 $|=1; # flushes output
68 # Record the version we are coming from
70 my $original_version = C4::Context->preference("Version");
72 # Deal with virtualshelves
73 my $DBversion = "3.00.00.001";
74 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
75 # update virtualshelves table to
77 $dbh->do("ALTER TABLE `bookshelf` RENAME `virtualshelves`");
78 $dbh->do("ALTER TABLE `shelfcontents` RENAME `virtualshelfcontents`");
79 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD `biblionumber` INT( 11 ) NOT NULL default '0' AFTER shelfnumber");
80 $dbh->do("UPDATE `virtualshelfcontents` SET biblionumber=(SELECT biblionumber FROM items WHERE items.itemnumber=virtualshelfcontents.itemnumber)");
81 # drop all foreign keys : otherwise, we can't drop itemnumber field.
82 DropAllForeignKeys('virtualshelfcontents');
83 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD KEY biblionumber (biblionumber)");
84 # create the new foreign keys (on biblionumber)
85 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `virtualshelfcontents_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE");
86 # re-create the foreign key on virtualshelf
87 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `shelfcontents_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE");
88 $dbh->do("ALTER TABLE `virtualshelfcontents` DROP `itemnumber`");
89 print "Upgrade to $DBversion done (virtualshelves)\n";
90 SetVersion ($DBversion);
94 $DBversion = "3.00.00.002";
95 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
96 $dbh->do("DROP TABLE sessions");
97 $dbh->do("CREATE TABLE `sessions` (
98 `id` varchar(32) NOT NULL,
99 `a_session` text NOT NULL,
100 UNIQUE KEY `id` (`id`)
101 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
102 print "Upgrade to $DBversion done (sessions uses CGI::session, new table structure for sessions)\n";
103 SetVersion ($DBversion);
107 $DBversion = "3.00.00.003";
108 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
109 if (C4::Context->preference("opaclanguages") eq "fr") {
110 $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')");
112 $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')");
114 print "Upgrade to $DBversion done (adding ReservesNeedReturns systempref, in circulation)\n";
115 SetVersion ($DBversion);
119 $DBversion = "3.00.00.004";
120 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
121 $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')");
122 print "Upgrade to $DBversion done (adding DebugLevel systempref, in 'Admin' tab)\n";
123 SetVersion ($DBversion);
126 $DBversion = "3.00.00.005";
127 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
128 $dbh->do("CREATE TABLE `tags` (
129 `entry` varchar(255) NOT NULL default '',
130 `weight` bigint(20) NOT NULL default 0,
131 PRIMARY KEY (`entry`)
132 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
134 $dbh->do("CREATE TABLE `nozebra` (
135 `server` varchar(20) NOT NULL,
136 `indexname` varchar(40) NOT NULL,
137 `value` varchar(250) NOT NULL,
138 `biblionumbers` longtext NOT NULL,
139 KEY `indexname` (`server`,`indexname`),
140 KEY `value` (`server`,`value`))
141 ENGINE=InnoDB DEFAULT CHARSET=utf8;
143 print "Upgrade to $DBversion done (adding tags and nozebra tables )\n";
144 SetVersion ($DBversion);
147 $DBversion = "3.00.00.006";
148 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
149 $dbh->do("UPDATE issues SET issuedate=timestamp WHERE issuedate='0000-00-00'");
150 print "Upgrade to $DBversion done (filled issues.issuedate with timestamp)\n";
151 SetVersion ($DBversion);
154 $DBversion = "3.00.00.007";
155 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
156 $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')");
157 print "Upgrade to $DBversion done (set SessionStorage variable)\n";
158 SetVersion ($DBversion);
161 $DBversion = "3.00.00.008";
162 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
163 $dbh->do("ALTER TABLE `biblio` ADD `datecreated` DATE NOT NULL AFTER `timestamp` ;");
164 $dbh->do("UPDATE biblio SET datecreated=timestamp");
165 print "Upgrade to $DBversion done (biblio creation date)\n";
166 SetVersion ($DBversion);
169 $DBversion = "3.00.00.009";
170 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
172 # Create backups of call number columns
173 # in case default migration needs to be customized
175 # UPGRADE NOTE: temp_upg_biblioitems_call_num should be dropped
176 # after call numbers have been transformed to the new structure
178 # Not bothering to do the same with deletedbiblioitems -- assume
179 # default is good enough.
180 $dbh->do("CREATE TABLE `temp_upg_biblioitems_call_num` AS
181 SELECT `biblioitemnumber`, `biblionumber`,
182 `classification`, `dewey`, `subclass`,
184 FROM `biblioitems`");
186 # biblioitems changes
187 $dbh->do("ALTER TABLE `biblioitems` CHANGE COLUMN `volumeddesc` `volumedesc` TEXT,
188 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
189 ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
190 ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
191 ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
192 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
193 ADD `totalissues` INT(10) AFTER `cn_sort`");
195 # default mapping of call number columns:
196 # cn_class = concatentation of classification + dewey,
197 # trimmed to fit -- assumes that most users do not
198 # populate both classification and dewey in a single record
200 # cn_source = left null
203 # After upgrade, cn_sort will have to be set based on whatever
204 # default call number scheme user sets as a preference. Misc
205 # script will be added at some point to do that.
207 $dbh->do("UPDATE `biblioitems`
208 SET cn_class = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
213 # Now drop the old call number columns
214 $dbh->do("ALTER TABLE `biblioitems` DROP COLUMN `classification`,
216 DROP COLUMN `subclass`,
217 DROP COLUMN `lcsort`,
218 DROP COLUMN `ccode`");
220 # deletedbiblio changes
221 $dbh->do("ALTER TABLE `deletedbiblio` ALTER COLUMN `frameworkcode` SET DEFAULT '',
223 ADD `datecreated` DATE NOT NULL AFTER `timestamp`");
224 $dbh->do("UPDATE deletedbiblio SET datecreated = timestamp");
226 # deletedbiblioitems changes
227 $dbh->do("ALTER TABLE `deletedbiblioitems`
228 MODIFY `publicationyear` TEXT,
229 CHANGE `volumeddesc` `volumedesc` TEXT,
230 MODIFY `collectiontitle` MEDIUMTEXT DEFAULT NULL AFTER `volumedesc`,
231 MODIFY `collectionissn` TEXT DEFAULT NULL AFTER `collectiontitle`,
232 MODIFY `collectionvolume` MEDIUMTEXT DEFAULT NULL AFTER `collectionissn`,
233 MODIFY `editionstatement` TEXT DEFAULT NULL AFTER `collectionvolume`,
234 MODIFY `editionresponsibility` TEXT DEFAULT NULL AFTER `editionstatement`,
235 MODIFY `place` VARCHAR(255) DEFAULT NULL AFTER `size`,
236 MODIFY `marc` LONGBLOB,
237 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `url`,
238 ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
239 ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
240 ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
241 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
242 ADD `totalissues` INT(10) AFTER `cn_sort`,
243 ADD `marcxml` LONGTEXT NOT NULL AFTER `totalissues`,
244 ADD KEY `isbn` (`isbn`),
245 ADD KEY `publishercode` (`publishercode`)
248 $dbh->do("UPDATE `deletedbiblioitems`
249 SET `cn_class` = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
250 `cn_item` = `subclass`,
253 $dbh->do("ALTER TABLE `deletedbiblioitems`
254 DROP COLUMN `classification`,
256 DROP COLUMN `subclass`,
257 DROP COLUMN `lcsort`,
261 # deleteditems changes
262 $dbh->do("ALTER TABLE `deleteditems`
263 MODIFY `barcode` VARCHAR(20) DEFAULT NULL,
264 MODIFY `price` DECIMAL(8,2) DEFAULT NULL,
265 MODIFY `replacementprice` DECIMAL(8,2) DEFAULT NULL,
267 MODIFY `itemcallnumber` VARCHAR(30) DEFAULT NULL AFTER `wthdrawn`,
268 MODIFY `holdingbranch` VARCHAR(10) DEFAULT NULL,
270 MODIFY `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP AFTER `paidfor`,
272 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
273 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
274 ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
275 ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
276 ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`,
277 MODIFY `marc` LONGBLOB AFTER `uri`,
279 DROP KEY `itembarcodeidx`,
280 DROP KEY `itembinoidx`,
281 DROP KEY `itembibnoidx`,
282 ADD UNIQUE KEY `delitembarcodeidx` (`barcode`),
283 ADD KEY `delitembinoidx` (`biblioitemnumber`),
284 ADD KEY `delitembibnoidx` (`biblionumber`),
285 ADD KEY `delhomebranch` (`homebranch`),
286 ADD KEY `delholdingbranch` (`holdingbranch`)");
287 $dbh->do("UPDATE deleteditems SET `ccode` = `itype`");
288 $dbh->do("ALTER TABLE deleteditems DROP `itype`");
289 $dbh->do("UPDATE `deleteditems` SET `cn_sort` = `itemcallnumber`");
292 $dbh->do("ALTER TABLE `items` ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
293 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
294 ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
295 ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
296 ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`
298 $dbh->do("ALTER TABLE `items`
299 DROP KEY `itembarcodeidx`,
300 ADD UNIQUE KEY `itembarcodeidx` (`barcode`)");
302 # map items.itype to items.ccode and
303 # set cn_sort to itemcallnumber -- as with biblioitems.cn_sort,
304 # will have to be subsequently updated per user's default
305 # classification scheme
306 $dbh->do("UPDATE `items` SET `cn_sort` = `itemcallnumber`,
309 $dbh->do("ALTER TABLE `items` DROP `cutterextra`,
312 print "Upgrade to $DBversion done (major changes to biblio, biblioitems, items, and deleted* versions of same\n";
313 SetVersion ($DBversion);
316 $DBversion = "3.00.00.010";
317 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
318 $dbh->do("CREATE INDEX `userid` ON borrowers (`userid`) ");
319 print "Upgrade to $DBversion done (userid index added)\n";
320 SetVersion ($DBversion);
323 $DBversion = "3.00.00.011";
324 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
325 $dbh->do("ALTER TABLE `branchcategories` CHANGE `categorycode` `categorycode` varchar(10) ");
326 $dbh->do("ALTER TABLE `branchcategories` CHANGE `categoryname` `categoryname` varchar(32) ");
327 $dbh->do("ALTER TABLE `branchcategories` ADD COLUMN `categorytype` varchar(16) ");
328 $dbh->do("UPDATE `branchcategories` SET `categorytype` = 'properties'");
329 $dbh->do("ALTER TABLE `branchrelations` CHANGE `categorycode` `categorycode` varchar(10) ");
330 print "Upgrade to $DBversion done (added branchcategory type)\n";
331 SetVersion ($DBversion);
334 $DBversion = "3.00.00.012";
335 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
336 $dbh->do("CREATE TABLE `class_sort_rules` (
337 `class_sort_rule` varchar(10) NOT NULL default '',
338 `description` mediumtext,
339 `sort_routine` varchar(30) NOT NULL default '',
340 PRIMARY KEY (`class_sort_rule`),
341 UNIQUE KEY `class_sort_rule_idx` (`class_sort_rule`)
342 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
343 $dbh->do("CREATE TABLE `class_sources` (
344 `cn_source` varchar(10) NOT NULL default '',
345 `description` mediumtext,
346 `used` tinyint(4) NOT NULL default 0,
347 `class_sort_rule` varchar(10) NOT NULL default '',
348 PRIMARY KEY (`cn_source`),
349 UNIQUE KEY `cn_source_idx` (`cn_source`),
350 KEY `used_idx` (`used`),
351 CONSTRAINT `class_source_ibfk_1` FOREIGN KEY (`class_sort_rule`)
352 REFERENCES `class_sort_rules` (`class_sort_rule`)
353 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
354 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type)
355 VALUES('DefaultClassificationSource','ddc',
356 'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.', NULL,'free')");
357 $dbh->do("INSERT INTO `class_sort_rules` (`class_sort_rule`, `description`, `sort_routine`) VALUES
358 ('dewey', 'Default filing rules for DDC', 'Dewey'),
359 ('lcc', 'Default filing rules for LCC', 'LCC'),
360 ('generic', 'Generic call number filing rules', 'Generic')");
361 $dbh->do("INSERT INTO `class_sources` (`cn_source`, `description`, `used`, `class_sort_rule`) VALUES
362 ('ddc', 'Dewey Decimal Classification', 1, 'dewey'),
363 ('lcc', 'Library of Congress Classification', 1, 'lcc'),
364 ('udc', 'Universal Decimal Classification', 0, 'generic'),
365 ('sudocs', 'SuDoc Classification (U.S. GPO)', 0, 'generic'),
366 ('z', 'Other/Generic Classification Scheme', 0, 'generic')");
367 print "Upgrade to $DBversion done (classification sources added)\n";
368 SetVersion ($DBversion);
371 $DBversion = "3.00.00.013";
372 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
373 $dbh->do("CREATE TABLE `import_batches` (
374 `import_batch_id` int(11) NOT NULL auto_increment,
375 `template_id` int(11) default NULL,
376 `branchcode` varchar(10) default NULL,
377 `num_biblios` int(11) NOT NULL default 0,
378 `num_items` int(11) NOT NULL default 0,
379 `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
380 `overlay_action` enum('replace', 'create_new', 'use_template') NOT NULL default 'create_new',
381 `import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging',
382 `batch_type` enum('batch', 'z3950') NOT NULL default 'batch',
383 `file_name` varchar(100),
384 `comments` mediumtext,
385 PRIMARY KEY (`import_batch_id`),
386 KEY `branchcode` (`branchcode`)
387 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
388 $dbh->do("CREATE TABLE `import_records` (
389 `import_record_id` int(11) NOT NULL auto_increment,
390 `import_batch_id` int(11) NOT NULL,
391 `branchcode` varchar(10) default NULL,
392 `record_sequence` int(11) NOT NULL default 0,
393 `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
394 `import_date` DATE default NULL,
395 `marc` longblob NOT NULL,
396 `marcxml` longtext NOT NULL,
397 `marcxml_old` longtext NOT NULL,
398 `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio',
399 `overlay_status` enum('no_match', 'auto_match', 'manual_match', 'match_applied') NOT NULL default 'no_match',
400 `status` enum('error', 'staged', 'imported', 'reverted', 'items_reverted') NOT NULL default 'staged',
401 `import_error` mediumtext,
402 `encoding` varchar(40) NOT NULL default '',
403 `z3950random` varchar(40) default NULL,
404 PRIMARY KEY (`import_record_id`),
405 CONSTRAINT `import_records_ifbk_1` FOREIGN KEY (`import_batch_id`)
406 REFERENCES `import_batches` (`import_batch_id`) ON DELETE CASCADE ON UPDATE CASCADE,
407 KEY `branchcode` (`branchcode`),
408 KEY `batch_sequence` (`import_batch_id`, `record_sequence`)
409 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
410 $dbh->do("CREATE TABLE `import_record_matches` (
411 `import_record_id` int(11) NOT NULL,
412 `candidate_match_id` int(11) NOT NULL,
413 `score` int(11) NOT NULL default 0,
414 CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`)
415 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
416 KEY `record_score` (`import_record_id`, `score`)
417 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
418 $dbh->do("CREATE TABLE `import_biblios` (
419 `import_record_id` int(11) NOT NULL,
420 `matched_biblionumber` int(11) default NULL,
421 `control_number` varchar(25) default NULL,
422 `original_source` varchar(25) default NULL,
423 `title` varchar(128) default NULL,
424 `author` varchar(80) default NULL,
425 `isbn` varchar(14) default NULL,
426 `issn` varchar(9) default NULL,
427 `has_items` tinyint(1) NOT NULL default 0,
428 CONSTRAINT `import_biblios_ibfk_1` FOREIGN KEY (`import_record_id`)
429 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
430 KEY `matched_biblionumber` (`matched_biblionumber`),
431 KEY `title` (`title`),
433 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
434 $dbh->do("CREATE TABLE `import_items` (
435 `import_items_id` int(11) NOT NULL auto_increment,
436 `import_record_id` int(11) NOT NULL,
437 `itemnumber` int(11) default NULL,
438 `branchcode` varchar(10) default NULL,
439 `status` enum('error', 'staged', 'imported', 'reverted') NOT NULL default 'staged',
440 `marcxml` longtext NOT NULL,
441 `import_error` mediumtext,
442 PRIMARY KEY (`import_items_id`),
443 CONSTRAINT `import_items_ibfk_1` FOREIGN KEY (`import_record_id`)
444 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
445 KEY `itemnumber` (`itemnumber`),
446 KEY `branchcode` (`branchcode`)
447 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
449 $dbh->do("INSERT INTO `import_batches`
450 (`overlay_action`, `import_status`, `batch_type`, `file_name`)
451 SELECT distinct 'create_new', 'staged', 'z3950', `file`
452 FROM `marc_breeding`");
454 $dbh->do("INSERT INTO `import_records`
455 (`import_batch_id`, `import_record_id`, `record_sequence`, `marc`, `record_type`, `status`,
456 `encoding`, `z3950random`, `marcxml`, `marcxml_old`)
457 SELECT `import_batch_id`, `id`, 1, `marc`, 'biblio', 'staged', `encoding`, `z3950random`, '', ''
459 JOIN `import_batches` ON (`file_name` = `file`)");
461 $dbh->do("INSERT INTO `import_biblios`
462 (`import_record_id`, `title`, `author`, `isbn`)
463 SELECT `import_record_id`, `title`, `author`, `isbn`
465 JOIN `import_records` ON (`import_record_id` = `id`)");
467 $dbh->do("UPDATE `import_batches`
468 SET `num_biblios` = (
470 FROM `import_records`
471 WHERE `import_batch_id` = `import_batches`.`import_batch_id`
474 $dbh->do("DROP TABLE `marc_breeding`");
476 print "Upgrade to $DBversion done (import_batches et al. added)\n";
477 SetVersion ($DBversion);
480 $DBversion = "3.00.00.014";
481 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
482 $dbh->do("ALTER TABLE subscription ADD lastbranch VARCHAR(4)");
483 print "Upgrade to $DBversion done (userid index added)\n";
484 SetVersion ($DBversion);
487 $DBversion = "3.00.00.015";
488 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
489 $dbh->do("CREATE TABLE `saved_sql` (
490 `id` int(11) NOT NULL auto_increment,
491 `borrowernumber` int(11) default NULL,
492 `date_created` datetime default NULL,
493 `last_modified` datetime default NULL,
495 `last_run` datetime default NULL,
496 `report_name` varchar(255) default NULL,
497 `type` varchar(255) default NULL,
500 KEY boridx (`borrowernumber`)
501 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
502 $dbh->do("CREATE TABLE `saved_reports` (
503 `id` int(11) NOT NULL auto_increment,
504 `report_id` int(11) default NULL,
506 `date_run` datetime default NULL,
508 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
509 print "Upgrade to $DBversion done (saved_sql and saved_reports added)\n";
510 SetVersion ($DBversion);
513 $DBversion = "3.00.00.016";
514 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
515 $dbh->do(" CREATE TABLE reports_dictionary (
516 id int(11) NOT NULL auto_increment,
517 name varchar(255) default NULL,
519 date_created datetime default NULL,
520 date_modified datetime default NULL,
522 area int(11) default NULL,
524 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
525 print "Upgrade to $DBversion done (reports_dictionary) added)\n";
526 SetVersion ($DBversion);
529 $DBversion = "3.00.00.017";
530 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
531 $dbh->do("ALTER TABLE action_logs DROP PRIMARY KEY");
532 $dbh->do("ALTER TABLE action_logs ADD KEY timestamp (timestamp,user)");
533 $dbh->do("ALTER TABLE action_logs ADD action_id INT(11) NOT NULL FIRST");
534 $dbh->do("UPDATE action_logs SET action_id = if (\@a, \@a:=\@a+1, \@a:=1)");
535 $dbh->do("ALTER TABLE action_logs MODIFY action_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY");
536 print "Upgrade to $DBversion done (added column to action_logs)\n";
537 SetVersion ($DBversion);
540 $DBversion = "3.00.00.018";
541 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
542 $dbh->do("ALTER TABLE `zebraqueue`
543 ADD `done` INT NOT NULL DEFAULT '0',
544 ADD `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ;
546 print "Upgrade to $DBversion done (adding timestamp and done columns to zebraque table to improve problem tracking) added)\n";
547 SetVersion ($DBversion);
550 $DBversion = "3.00.00.019";
551 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
552 $dbh->do("ALTER TABLE biblio MODIFY biblionumber INT(11) NOT NULL AUTO_INCREMENT");
553 $dbh->do("ALTER TABLE biblioitems MODIFY biblioitemnumber INT(11) NOT NULL AUTO_INCREMENT");
554 $dbh->do("ALTER TABLE items MODIFY itemnumber INT(11) NOT NULL AUTO_INCREMENT");
555 print "Upgrade to $DBversion done (made bib/item PKs auto_increment)\n";
556 SetVersion ($DBversion);
559 $DBversion = "3.00.00.020";
560 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
561 $dbh->do("ALTER TABLE deleteditems
562 DROP KEY `delitembarcodeidx`,
563 ADD KEY `delitembarcodeidx` (`barcode`)");
564 print "Upgrade to $DBversion done (dropped uniqueness of key on deleteditems.barcode)\n";
565 SetVersion ($DBversion);
568 $DBversion = "3.00.00.021";
569 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
570 $dbh->do("ALTER TABLE items CHANGE homebranch homebranch VARCHAR(10)");
571 $dbh->do("ALTER TABLE deleteditems CHANGE homebranch homebranch VARCHAR(10)");
572 $dbh->do("ALTER TABLE statistics CHANGE branch branch VARCHAR(10)");
573 $dbh->do("ALTER TABLE subscription CHANGE lastbranch lastbranch VARCHAR(10)");
574 print "Upgrade to $DBversion done (extended missed branchcode columns to 10 chars)\n";
575 SetVersion ($DBversion);
578 $DBversion = "3.00.00.022";
579 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
580 $dbh->do("ALTER TABLE items
581 ADD `damaged` tinyint(1) default NULL AFTER notforloan");
582 $dbh->do("ALTER TABLE deleteditems
583 ADD `damaged` tinyint(1) default NULL AFTER notforloan");
584 print "Upgrade to $DBversion done (adding damaged column to items table)\n";
585 SetVersion ($DBversion);
588 $DBversion = "3.00.00.023";
589 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
590 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
591 VALUES ('yuipath','http://yui.yahooapis.com/2.3.1/build','Insert the path to YUI libraries','','free')");
592 print "Upgrade to $DBversion done (adding new system preference for controlling YUI path)\n";
593 SetVersion ($DBversion);
595 $DBversion = "3.00.00.024";
596 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
597 $dbh->do("ALTER TABLE biblioitems CHANGE itemtype itemtype VARCHAR(10)");
598 print "Upgrade to $DBversion done (changing itemtype to (10))\n";
599 SetVersion ($DBversion);
602 $DBversion = "3.00.00.025";
603 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
604 $dbh->do("ALTER TABLE items ADD COLUMN itype VARCHAR(10)");
605 $dbh->do("ALTER TABLE deleteditems ADD COLUMN itype VARCHAR(10) AFTER uri");
606 if(C4::Context->preference('item-level_itypes')){
607 $dbh->do('update items,biblioitems set items.itype=biblioitems.itemtype where items.biblionumber=biblioitems.biblionumber and itype is null');
609 print "Upgrade to $DBversion done (reintroduce items.itype - fill from itemtype)\n ";
610 SetVersion ($DBversion);
613 $DBversion = "3.00.00.026";
614 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
615 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
616 VALUES ('HomeOrHoldingBranch','homebranch','homebranch|holdingbranch','With independent branches turned on this decides whether to check the items holdingbranch or homebranch at circulatilon','choice')");
617 print "Upgrade to $DBversion done (adding new system preference for choosing whether homebranch or holdingbranch is checked in circulation)\n";
618 SetVersion ($DBversion);
621 $DBversion = "3.00.00.027";
622 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
623 $dbh->do("CREATE TABLE `marc_matchers` (
624 `matcher_id` int(11) NOT NULL auto_increment,
625 `code` varchar(10) NOT NULL default '',
626 `description` varchar(255) NOT NULL default '',
627 `record_type` varchar(10) NOT NULL default 'biblio',
628 `threshold` int(11) NOT NULL default 0,
629 PRIMARY KEY (`matcher_id`),
631 KEY `record_type` (`record_type`)
632 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
633 $dbh->do("CREATE TABLE `matchpoints` (
634 `matcher_id` int(11) NOT NULL,
635 `matchpoint_id` int(11) NOT NULL auto_increment,
636 `search_index` varchar(30) NOT NULL default '',
637 `score` int(11) NOT NULL default 0,
638 PRIMARY KEY (`matchpoint_id`),
639 CONSTRAINT `matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
640 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE
641 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
642 $dbh->do("CREATE TABLE `matchpoint_components` (
643 `matchpoint_id` int(11) NOT NULL,
644 `matchpoint_component_id` int(11) NOT NULL auto_increment,
645 sequence int(11) NOT NULL default 0,
646 tag varchar(3) NOT NULL default '',
647 subfields varchar(40) NOT NULL default '',
648 offset int(4) NOT NULL default 0,
649 length int(4) NOT NULL default 0,
650 PRIMARY KEY (`matchpoint_component_id`),
651 KEY `by_sequence` (`matchpoint_id`, `sequence`),
652 CONSTRAINT `matchpoint_components_ifbk_1` FOREIGN KEY (`matchpoint_id`)
653 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
654 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
655 $dbh->do("CREATE TABLE `matchpoint_component_norms` (
656 `matchpoint_component_id` int(11) NOT NULL,
657 `sequence` int(11) NOT NULL default 0,
658 `norm_routine` varchar(50) NOT NULL default '',
659 KEY `matchpoint_component_norms` (`matchpoint_component_id`, `sequence`),
660 CONSTRAINT `matchpoint_component_norms_ifbk_1` FOREIGN KEY (`matchpoint_component_id`)
661 REFERENCES `matchpoint_components` (`matchpoint_component_id`) ON DELETE CASCADE ON UPDATE CASCADE
662 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
663 $dbh->do("CREATE TABLE `matcher_matchpoints` (
664 `matcher_id` int(11) NOT NULL,
665 `matchpoint_id` int(11) NOT NULL,
666 CONSTRAINT `matcher_matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
667 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
668 CONSTRAINT `matcher_matchpoints_ifbk_2` FOREIGN KEY (`matchpoint_id`)
669 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
670 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
671 $dbh->do("CREATE TABLE `matchchecks` (
672 `matcher_id` int(11) NOT NULL,
673 `matchcheck_id` int(11) NOT NULL auto_increment,
674 `source_matchpoint_id` int(11) NOT NULL,
675 `target_matchpoint_id` int(11) NOT NULL,
676 PRIMARY KEY (`matchcheck_id`),
677 CONSTRAINT `matcher_matchchecks_ifbk_1` FOREIGN KEY (`matcher_id`)
678 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
679 CONSTRAINT `matcher_matchchecks_ifbk_2` FOREIGN KEY (`source_matchpoint_id`)
680 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE,
681 CONSTRAINT `matcher_matchchecks_ifbk_3` FOREIGN KEY (`target_matchpoint_id`)
682 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
683 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
684 print "Upgrade to $DBversion done (added C4::Matcher serialization tables)\n ";
685 SetVersion ($DBversion);
688 $DBversion = "3.00.00.028";
689 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
690 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
691 VALUES ('canreservefromotherbranches','1','','With Independent branches on, can a user from one library reserve an item from another library','YesNo')");
692 print "Upgrade to $DBversion done (adding new system preference for changing reserve/holds behaviour with independent branches)\n";
693 SetVersion ($DBversion);
697 $DBversion = "3.00.00.029";
698 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
699 $dbh->do("ALTER TABLE `import_batches` ADD `matcher_id` int(11) NULL AFTER `import_batch_id`");
700 print "Upgrade to $DBversion done (adding matcher_id to import_batches)\n";
701 SetVersion ($DBversion);
704 $DBversion = "3.00.00.030";
705 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
707 CREATE TABLE services_throttle (
708 service_type varchar(10) NOT NULL default '',
709 service_count varchar(45) default NULL,
710 PRIMARY KEY (service_type)
711 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
713 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
714 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')");
715 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
716 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')");
717 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
718 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')");
719 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
720 VALUES ('XISBNDailyLimit',499,'','The xISBN Web service is free for non-commercial use when usage does not exceed 500 requests per day','free')");
721 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
722 VALUES ('PINESISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use PINES OISBN web service in the Editions tab on the detail pages.','YesNo')");
723 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
724 VALUES ('ThingISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use the ThingISBN web service in the Editions tab on the detail pages.','YesNo')");
725 print "Upgrade to $DBversion done (adding services throttle table and sysprefs for xISBN)\n";
726 SetVersion ($DBversion);
729 $DBversion = "3.00.00.031";
730 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
732 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryStemming',1,'If ON, enables query stemming',NULL,'YesNo')");
733 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryFuzzy',1,'If ON, enables fuzzy option for searches',NULL,'YesNo')");
734 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryWeightFields',1,'If ON, enables field weighting',NULL,'YesNo')");
735 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('WebBasedSelfCheck',0,'If ON, enables the web-based self-check system',NULL,'YesNo')");
736 $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')");
737 $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')");
738 $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')");
739 $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')");
740 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('defaultSortOrder',NULL,'Specify the default sort order','asc|dsc|az|za','Choice')");
741 $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')");
742 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACdefaultSortOrder',NULL,'Specify the default sort order','asc|dsc|za|az','Choice')");
743 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('staffClientBaseURL','','Specify the base URL of the staff client',NULL,'free')");
744 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('minPasswordLength',3,'Specify the minimum length of a patron/staff password',NULL,'free')");
745 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('noItemTypeImages',0,'If ON, disables item-type images',NULL,'YesNo')");
746 $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')");
747 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('holdCancelLength','','Specify how many days before a hold is canceled',NULL,'free')");
748 $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')");
749 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('finesMode','test','Choose the fines mode, test or production','test|production','Choice')");
750 $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')");
751 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeInputFilter','','If set, allows specification of a item barcode input filter','cuecat','Choice')");
752 $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')");
753 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('URLLinkText','','Text to display as the link anchor in the OPAC',NULL,'free')");
754 $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')");
755 $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')");
756 $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')");
757 $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')");
758 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACUserCSS',0,'Add CSS to be included in the OPAC',NULL,'free')");
760 print "Upgrade to $DBversion done (adding additional system preference)\n";
761 SetVersion ($DBversion);
764 $DBversion = "3.00.00.032";
765 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
766 $dbh->do("UPDATE `marc_subfield_structure` SET `kohafield` = 'items.wthdrawn' WHERE `kohafield` = 'items.withdrawn'");
767 print "Upgrade to $DBversion done (fixed MARC framework references to items.withdrawn)\n";
768 SetVersion ($DBversion);
771 $DBversion = "3.00.00.033";
772 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
773 $dbh->do("INSERT INTO `userflags` VALUES(17,'staffaccess','Modify login / permissions for staff users',0)");
774 print "Upgrade to $DBversion done (Adding permissions flag for staff member access modification. )\n";
775 SetVersion ($DBversion);
778 $DBversion = "3.00.00.034";
779 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
780 $dbh->do("ALTER TABLE `virtualshelves` ADD COLUMN `sortfield` VARCHAR(16) ");
781 print "Upgrade to $DBversion done (Adding sortfield for Virtual Shelves. )\n";
782 SetVersion ($DBversion);
785 $DBversion = "3.00.00.035";
786 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
787 $dbh->do("UPDATE marc_subfield_structure
788 SET authorised_value = 'cn_source'
789 WHERE kohafield IN ('items.cn_source', 'biblioitems.cn_source')
790 AND (authorised_value is NULL OR authorised_value = '')");
791 print "Upgrade to $DBversion done (MARC frameworks: make classification source a drop-down)\n";
792 SetVersion ($DBversion);
795 $DBversion = "3.00.00.036";
796 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
797 $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');");
798 print "Upgrade to $DBversion done (OPACItemsResultsDisplay systempreference added)\n";
799 SetVersion ($DBversion);
802 $DBversion = "3.00.00.037";
803 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
804 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactfirstname` varchar(255)");
805 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactsurname` varchar(255)");
806 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress1` varchar(255)");
807 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress2` varchar(255)");
808 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress3` varchar(255)");
809 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactzipcode` varchar(50)");
810 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactphone` varchar(50)");
811 print "Upgrade to $DBversion done (Adding Alternative Contact Person information to borrowers table)\n";
812 SetVersion ($DBversion);
815 $DBversion = "3.00.00.038";
816 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
817 $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'");
818 $dbh->do("DELETE FROM `systempreferences` WHERE variable='hideBiblioNumber'");
819 print "Upgrade to $DBversion done ('alter finesMode systempreference, remove superfluous syspref.')\n";
820 SetVersion ($DBversion);
823 $DBversion = "3.00.00.039";
824 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
825 $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')");
826 $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')");
827 $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')");
828 # $dbh->do("DELETE FROM `systempreferences` WHERE variable='HomeOrHoldingBranch'"); # Bug #2752
829 print "Upgrade to $DBversion done ('add circ sysprefs CircControl, finesCalendar, and uppercasesurnames, and delete HomeOrHoldingBranch.')\n";
830 SetVersion ($DBversion);
833 $DBversion = "3.00.00.040";
834 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
835 $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')");
836 $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')");
837 print "Upgrade to $DBversion done ('add circ sysprefs todaysIssuesDefaultSortOrder and previousIssuesDefaultSortOrder.')\n";
838 SetVersion ($DBversion);
842 $DBversion = "3.00.00.041";
843 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
844 # Strictly speaking it is not necessary to explicitly change
845 # NULL values to 0, because the ALTER TABLE statement will do that.
846 # However, setting them first avoids a warning.
847 $dbh->do("UPDATE items SET notforloan = 0 WHERE notforloan IS NULL");
848 $dbh->do("UPDATE items SET damaged = 0 WHERE damaged IS NULL");
849 $dbh->do("UPDATE items SET itemlost = 0 WHERE itemlost IS NULL");
850 $dbh->do("UPDATE items SET wthdrawn = 0 WHERE wthdrawn IS NULL");
851 $dbh->do("ALTER TABLE items
852 MODIFY notforloan tinyint(1) NOT NULL default 0,
853 MODIFY damaged tinyint(1) NOT NULL default 0,
854 MODIFY itemlost tinyint(1) NOT NULL default 0,
855 MODIFY wthdrawn tinyint(1) NOT NULL default 0");
856 $dbh->do("UPDATE deleteditems SET notforloan = 0 WHERE notforloan IS NULL");
857 $dbh->do("UPDATE deleteditems SET damaged = 0 WHERE damaged IS NULL");
858 $dbh->do("UPDATE deleteditems SET itemlost = 0 WHERE itemlost IS NULL");
859 $dbh->do("UPDATE deleteditems SET wthdrawn = 0 WHERE wthdrawn IS NULL");
860 $dbh->do("ALTER TABLE deleteditems
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 print "Upgrade to $DBversion done (disallow NULL in several item status columns)\n";
866 SetVersion ($DBversion);
869 $DBversion = "3.00.00.04";
870 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
871 $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
872 print "Upgrade to $DBversion done (disallow NULL in aqbooksellers.name; part of fix for bug 1251)\n";
873 SetVersion ($DBversion);
876 $DBversion = "3.00.00.043";
877 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
878 $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");
879 print "Upgrade to $DBversion done (currency table: add symbol and timestamp columns)\n";
880 SetVersion ($DBversion);
883 $DBversion = "3.00.00.044";
884 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
885 $dbh->do("ALTER TABLE deletedborrowers
886 ADD `altcontactfirstname` varchar(255) default NULL,
887 ADD `altcontactsurname` varchar(255) default NULL,
888 ADD `altcontactaddress1` varchar(255) default NULL,
889 ADD `altcontactaddress2` varchar(255) default NULL,
890 ADD `altcontactaddress3` varchar(255) default NULL,
891 ADD `altcontactzipcode` varchar(50) default NULL,
892 ADD `altcontactphone` varchar(50) default NULL
894 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
895 ('OPACBaseURL',NULL,'Specify the Base URL of the OPAC, e.g., opac.mylibrary.com, the http:// will be added automatically by Koha.',NULL,'Free'),
896 ('language','en','Set the default language in the staff client.',NULL,'Languages'),
897 ('QueryAutoTruncate',1,'If ON, query truncation is enabled by default',NULL,'YesNo'),
898 ('QueryRemoveStopwords',0,'If ON, stopwords listed in the Administration area will be removed from queries',NULL,'YesNo')
900 print "Upgrade to $DBversion done (syncing deletedborrowers table with borrowers table)\n";
901 SetVersion ($DBversion);
904 #-- http://www.w3.org/International/articles/language-tags/
907 $DBversion = "3.00.00.045";
908 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
910 CREATE TABLE language_subtag_registry (
912 type varchar(25), -- language-script-region-variant-extension-privateuse
913 description varchar(25), -- only one of the possible descriptions for ease of reference, see language_descriptions for the complete list
915 KEY `subtag` (`subtag`)
916 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
918 #-- TODO: add suppress_scripts
919 #-- this maps three letter codes defined in iso639.2 back to their
920 #-- two letter equivilents in rfc4646 (LOC maintains iso639+)
921 $dbh->do("CREATE TABLE language_rfc4646_to_iso639 (
922 rfc4646_subtag varchar(25),
923 iso639_2_code varchar(25),
924 KEY `rfc4646_subtag` (`rfc4646_subtag`)
925 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
927 $dbh->do("CREATE TABLE language_descriptions (
931 description varchar(255),
933 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
935 #-- bi-directional support, keyed by script subcode
936 $dbh->do("CREATE TABLE language_script_bidi (
937 rfc4646_subtag varchar(25), -- script subtag, Arab, Hebr, etc.
938 bidi varchar(3), -- rtl ltr
939 KEY `rfc4646_subtag` (`rfc4646_subtag`)
940 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
942 #-- BIDI Stuff, Arabic and Hebrew
943 $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
944 VALUES( 'Arab', 'rtl')");
945 $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
946 VALUES( 'Hebr', 'rtl')");
948 #-- TODO: need to map language subtags to script subtags for detection
949 #-- of bidi when script is not specified (like ar, he)
950 $dbh->do("CREATE TABLE language_script_mapping (
951 language_subtag varchar(25),
952 script_subtag varchar(25),
953 KEY `language_subtag` (`language_subtag`)
954 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
956 #-- Default mappings between script and language subcodes
957 $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
958 VALUES( 'ar', 'Arab')");
959 $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
960 VALUES( 'he', 'Hebr')");
962 print "Upgrade to $DBversion done (adding language subtag registry and basic BiDi support NOTE: You should import the subtag registry SQL)\n";
963 SetVersion ($DBversion);
966 $DBversion = "3.00.00.046";
967 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
968 $dbh->do("ALTER TABLE `subscription` CHANGE `numberlength` `numberlength` int(11) default '0' ,
969 CHANGE `weeklength` `weeklength` int(11) default '0'");
970 $dbh->do("CREATE TABLE `serialitems` (`serialid` int(11) NOT NULL, `itemnumber` int(11) NOT NULL, UNIQUE KEY `serialididx` (`serialid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
971 $dbh->do("INSERT INTO `serialitems` SELECT `serialid`,`itemnumber` from serial where NOT ISNULL(itemnumber) && itemnumber <> '' && itemnumber NOT LIKE '%,%'");
972 print "Upgrade to $DBversion done (Add serialitems table to link serial issues to items. )\n";
973 SetVersion ($DBversion);
976 $DBversion = "3.00.00.047";
977 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
978 $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');");
979 print "Upgrade to $DBversion done ( Added OpacRenewalAllowed syspref )\n";
980 SetVersion ($DBversion);
983 $DBversion = "3.00.00.048";
984 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
985 $dbh->do("ALTER TABLE `items` ADD `more_subfields_xml` longtext default NULL AFTER `itype`");
986 print "Upgrade to $DBversion done (added items.more_subfields_xml)\n";
987 SetVersion ($DBversion);
990 $DBversion = "3.00.00.049";
991 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
992 $dbh->do("ALTER TABLE `z3950servers` ADD `encoding` text default NULL AFTER type ");
993 print "Upgrade to $DBversion done ( Added encoding field to z3950servers table )\n";
994 SetVersion ($DBversion);
997 $DBversion = "3.00.00.050";
998 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
999 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHighlightedWords','0','If Set, query matched terms are highlighted in OPAC',NULL,'YesNo');");
1000 print "Upgrade to $DBversion done ( Added OpacHighlightedWords syspref )\n";
1001 SetVersion ($DBversion);
1004 $DBversion = "3.00.00.051";
1005 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1006 $dbh->do("UPDATE systempreferences SET explanation = 'Define the current theme for the OPAC interface.' WHERE variable = 'opacthemes';");
1007 print "Upgrade to $DBversion done ( Corrected opacthemes explanation. )\n";
1008 SetVersion ($DBversion);
1011 $DBversion = "3.00.00.052";
1012 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1013 $dbh->do("ALTER TABLE `deleteditems` ADD `more_subfields_xml` LONGTEXT DEFAULT NULL AFTER `itype`");
1014 print "Upgrade to $DBversion done ( Adding missing column to deleteditems table. )\n";
1015 SetVersion ($DBversion);
1018 $DBversion = "3.00.00.053";
1019 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1020 $dbh->do("CREATE TABLE `printers_profile` (
1021 `prof_id` int(4) NOT NULL auto_increment,
1022 `printername` varchar(40) NOT NULL,
1023 `tmpl_id` int(4) NOT NULL,
1024 `paper_bin` varchar(20) NOT NULL,
1025 `offset_horz` float default NULL,
1026 `offset_vert` float default NULL,
1027 `creep_horz` float default NULL,
1028 `creep_vert` float default NULL,
1029 `unit` char(20) NOT NULL default 'POINT',
1030 PRIMARY KEY (`prof_id`),
1031 UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
1032 CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
1033 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1034 $dbh->do("CREATE TABLE `labels_profile` (
1035 `tmpl_id` int(4) NOT NULL,
1036 `prof_id` int(4) NOT NULL,
1037 UNIQUE KEY `tmpl_id` (`tmpl_id`),
1038 UNIQUE KEY `prof_id` (`prof_id`)
1039 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1040 print "Upgrade to $DBversion done ( Printer Profile tables added )\n";
1041 SetVersion ($DBversion);
1044 $DBversion = "3.00.00.054";
1045 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1046 $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';");
1047 print "Upgrade to $DBversion done ( Added another barcode autogeneration sequence to barcode.pl. )\n";
1048 SetVersion ($DBversion);
1051 $DBversion = "3.00.00.055";
1052 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1053 $dbh->do("ALTER TABLE `zebraqueue` ADD KEY `zebraqueue_lookup` (`server`, `biblio_auth_number`, `operation`, `done`)");
1054 print "Upgrade to $DBversion done ( Added index on zebraqueue. )\n";
1055 SetVersion ($DBversion);
1057 $DBversion = "3.00.00.056";
1058 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1059 if (C4::Context->preference("marcflavour") eq 'UNIMARC') {
1060 $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) ");
1062 $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) ");
1064 $dbh->do("ALTER TABLE `items` ADD `enumchron` VARCHAR(80) DEFAULT NULL;");
1065 print "Upgrade to $DBversion done ( Added item.enumchron column, and framework map to 952h )\n";
1066 SetVersion ($DBversion);
1069 $DBversion = "3.00.00.057";
1070 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1071 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH','0','if ON, OAI-PMH server is enabled',NULL,'YesNo');");
1072 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:archiveID','KOHA-OAI-TEST','OAI-PMH archive identification',NULL,'Free');");
1073 $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');");
1074 $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');");
1075 $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');");
1076 SetVersion ($DBversion);
1079 $DBversion = "3.00.00.058";
1080 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1081 $dbh->do("ALTER TABLE `opac_news`
1082 CHANGE `lang` `lang` VARCHAR( 25 )
1084 COLLATE utf8_general_ci
1085 NOT NULL default ''");
1086 print "Upgrade to $DBversion done ( lang field in opac_news made longer )\n";
1087 SetVersion ($DBversion);
1090 $DBversion = "3.00.00.059";
1091 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1093 $dbh->do("CREATE TABLE IF NOT EXISTS `labels_templates` (
1094 `tmpl_id` int(4) NOT NULL auto_increment,
1095 `tmpl_code` char(100) default '',
1096 `tmpl_desc` char(100) default '',
1097 `page_width` float default '0',
1098 `page_height` float default '0',
1099 `label_width` float default '0',
1100 `label_height` float default '0',
1101 `topmargin` float default '0',
1102 `leftmargin` float default '0',
1103 `cols` int(2) default '0',
1104 `rows` int(2) default '0',
1105 `colgap` float default '0',
1106 `rowgap` float default '0',
1107 `active` int(1) default NULL,
1108 `units` char(20) default 'PX',
1109 `fontsize` int(4) NOT NULL default '3',
1110 PRIMARY KEY (`tmpl_id`)
1111 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1112 $dbh->do("CREATE TABLE IF NOT EXISTS `printers_profile` (
1113 `prof_id` int(4) NOT NULL auto_increment,
1114 `printername` varchar(40) NOT NULL,
1115 `tmpl_id` int(4) NOT NULL,
1116 `paper_bin` varchar(20) NOT NULL,
1117 `offset_horz` float default NULL,
1118 `offset_vert` float default NULL,
1119 `creep_horz` float default NULL,
1120 `creep_vert` float default NULL,
1121 `unit` char(20) NOT NULL default 'POINT',
1122 PRIMARY KEY (`prof_id`),
1123 UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
1124 CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
1125 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1126 print "Upgrade to $DBversion done ( Added labels_templates table if it did not exist. )\n";
1127 SetVersion ($DBversion);
1130 $DBversion = "3.00.00.060";
1131 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1132 $dbh->do("CREATE TABLE IF NOT EXISTS `patronimage` (
1133 `cardnumber` varchar(16) NOT NULL,
1134 `mimetype` varchar(15) NOT NULL,
1135 `imagefile` mediumblob NOT NULL,
1136 PRIMARY KEY (`cardnumber`),
1137 CONSTRAINT `patronimage_fk1` FOREIGN KEY (`cardnumber`) REFERENCES `borrowers` (`cardnumber`) ON DELETE CASCADE ON UPDATE CASCADE
1138 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1139 print "Upgrade to $DBversion done ( Added patronimage table. )\n";
1140 SetVersion ($DBversion);
1143 $DBversion = "3.00.00.061";
1144 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1145 $dbh->do("ALTER TABLE labels_templates ADD COLUMN font char(10) NOT NULL DEFAULT 'TR';");
1146 print "Upgrade to $DBversion done ( Added font column to labels_templates )\n";
1147 SetVersion ($DBversion);
1150 $DBversion = "3.00.00.062";
1151 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1152 $dbh->do("CREATE TABLE `old_issues` (
1153 `borrowernumber` int(11) default NULL,
1154 `itemnumber` int(11) default NULL,
1155 `date_due` date default NULL,
1156 `branchcode` varchar(10) default NULL,
1157 `issuingbranch` varchar(18) default NULL,
1158 `returndate` date default NULL,
1159 `lastreneweddate` date default NULL,
1160 `return` varchar(4) default NULL,
1161 `renewals` tinyint(4) default NULL,
1162 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1163 `issuedate` date default NULL,
1164 KEY `old_issuesborridx` (`borrowernumber`),
1165 KEY `old_issuesitemidx` (`itemnumber`),
1166 KEY `old_bordate` (`borrowernumber`,`timestamp`),
1167 CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1168 ON DELETE SET NULL ON UPDATE SET NULL,
1169 CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1170 ON DELETE SET NULL ON UPDATE SET NULL
1171 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1172 $dbh->do("CREATE TABLE `old_reserves` (
1173 `borrowernumber` int(11) default NULL,
1174 `reservedate` date default NULL,
1175 `biblionumber` int(11) default NULL,
1176 `constrainttype` varchar(1) default NULL,
1177 `branchcode` varchar(10) default NULL,
1178 `notificationdate` date default NULL,
1179 `reminderdate` date default NULL,
1180 `cancellationdate` date default NULL,
1181 `reservenotes` mediumtext,
1182 `priority` smallint(6) default NULL,
1183 `found` varchar(1) default NULL,
1184 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1185 `itemnumber` int(11) default NULL,
1186 `waitingdate` date default NULL,
1187 KEY `old_reserves_borrowernumber` (`borrowernumber`),
1188 KEY `old_reserves_biblionumber` (`biblionumber`),
1189 KEY `old_reserves_itemnumber` (`itemnumber`),
1190 KEY `old_reserves_branchcode` (`branchcode`),
1191 CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1192 ON DELETE SET NULL ON UPDATE SET NULL,
1193 CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
1194 ON DELETE SET NULL ON UPDATE SET NULL,
1195 CONSTRAINT `old_reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1196 ON DELETE SET NULL ON UPDATE SET NULL
1197 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1199 # move closed transactions to old_* tables
1200 $dbh->do("INSERT INTO old_issues SELECT * FROM issues WHERE returndate IS NOT NULL");
1201 $dbh->do("DELETE FROM issues WHERE returndate IS NOT NULL");
1202 $dbh->do("INSERT INTO old_reserves SELECT * FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
1203 $dbh->do("DELETE FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
1205 print "Upgrade to $DBversion done ( Added old_issues and old_reserves tables )\n";
1206 SetVersion ($DBversion);
1209 $DBversion = "3.00.00.063";
1210 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1211 $dbh->do("ALTER TABLE deleteditems
1212 CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT DEFAULT NULL,
1213 ADD COLUMN enumchron VARCHAR(80) DEFAULT NULL AFTER more_subfields_xml,
1214 ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
1215 $dbh->do("ALTER TABLE items
1216 CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT,
1217 ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
1218 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";
1219 SetVersion ($DBversion);
1222 $DBversion = "3.00.00.064";
1223 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1224 $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');");
1225 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSAccessKeyID','','See: http://aws.amazon.com','','free');");
1226 $dbh->do("DELETE FROM `systempreferences` WHERE variable='AmazonDevKey';");
1227 $dbh->do("DELETE FROM `systempreferences` WHERE variable='XISBNAmazonSimilarItems';");
1228 $dbh->do("DELETE FROM `systempreferences` WHERE variable='OPACXISBNAmazonSimilarItems';");
1229 print "Upgrade to $DBversion done (IMPORTANT: Upgrading to Amazon.com Associates Web Service 4.0 ) \n";
1230 SetVersion ($DBversion);
1233 $DBversion = "3.00.00.065";
1234 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1235 $dbh->do("CREATE TABLE `patroncards` (
1236 `cardid` int(11) NOT NULL auto_increment,
1237 `batch_id` varchar(10) NOT NULL default '1',
1238 `borrowernumber` int(11) NOT NULL,
1239 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1240 PRIMARY KEY (`cardid`),
1241 KEY `patroncards_ibfk_1` (`borrowernumber`),
1242 CONSTRAINT `patroncards_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1243 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1244 print "Upgrade to $DBversion done (Adding patroncards table for patroncards generation feature. ) \n";
1245 SetVersion ($DBversion);
1248 $DBversion = "3.00.00.066";
1249 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1250 $dbh->do("ALTER TABLE `virtualshelfcontents` MODIFY `dateadded` timestamp NOT NULL
1251 DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;
1253 print "Upgrade to $DBversion done (fix for bug 1873: virtualshelfcontents dateadded column empty. ) \n";
1254 SetVersion ($DBversion);
1257 $DBversion = "3.00.00.067";
1258 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1259 $dbh->do("UPDATE systempreferences SET explanation = 'Enable patron images for the Staff Client', type = 'YesNo' WHERE variable = 'patronimages'");
1260 print "Upgrade to $DBversion done (Updating patronimages syspref to reflect current kohastructure.sql. ) \n";
1261 SetVersion ($DBversion);
1264 $DBversion = "3.00.00.068";
1265 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1266 $dbh->do("CREATE TABLE `permissions` (
1267 `module_bit` int(11) NOT NULL DEFAULT 0,
1268 `code` varchar(30) DEFAULT NULL,
1269 `description` varchar(255) DEFAULT NULL,
1270 PRIMARY KEY (`module_bit`, `code`),
1271 CONSTRAINT `permissions_ibfk_1` FOREIGN KEY (`module_bit`) REFERENCES `userflags` (`bit`)
1272 ON DELETE CASCADE ON UPDATE CASCADE
1273 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1274 $dbh->do("CREATE TABLE `user_permissions` (
1275 `borrowernumber` int(11) NOT NULL DEFAULT 0,
1276 `module_bit` int(11) NOT NULL DEFAULT 0,
1277 `code` varchar(30) DEFAULT NULL,
1278 CONSTRAINT `user_permissions_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1279 ON DELETE CASCADE ON UPDATE CASCADE,
1280 CONSTRAINT `user_permissions_ibfk_2` FOREIGN KEY (`module_bit`, `code`)
1281 REFERENCES `permissions` (`module_bit`, `code`)
1282 ON DELETE CASCADE ON UPDATE CASCADE
1283 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1285 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES
1286 (13, 'edit_news', 'Write news for the OPAC and staff interfaces'),
1287 (13, 'label_creator', 'Create printable labels and barcodes from catalog and patron data'),
1288 (13, 'edit_calendar', 'Define days when the library is closed'),
1289 (13, 'moderate_comments', 'Moderate patron comments'),
1290 (13, 'edit_notices', 'Define notices'),
1291 (13, 'edit_notice_status_triggers', 'Set notice/status triggers for overdue items'),
1292 (13, 'view_system_logs', 'Browse the system logs'),
1293 (13, 'inventory', 'Perform inventory (stocktaking) of your catalogue'),
1294 (13, 'stage_marc_import', 'Stage MARC records into the reservoir'),
1295 (13, 'manage_staged_marc', 'Managed staged MARC records, including completing and reversing imports'),
1296 (13, 'export_catalog', 'Export bibliographic and holdings data'),
1297 (13, 'import_patrons', 'Import patron data'),
1298 (13, 'delete_anonymize_patrons', 'Delete old borrowers and anonymize circulation history (deletes borrower reading history)'),
1299 (13, 'batch_upload_patron_images', 'Upload patron images in batch or one at a time'),
1300 (13, 'schedule_tasks', 'Schedule tasks to run')");
1302 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('GranularPermissions','0','Use detailed staff user permissions',NULL,'YesNo')");
1304 print "Upgrade to $DBversion done (adding permissions and user_permissions tables and GranularPermissions syspref) \n";
1305 SetVersion ($DBversion);
1307 $DBversion = "3.00.00.069";
1308 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1309 $dbh->do("ALTER TABLE labels_conf CHANGE COLUMN class classification int(1) DEFAULT NULL;");
1310 print "Upgrade to $DBversion done ( Correcting columname in labels_conf )\n";
1311 SetVersion ($DBversion);
1314 $DBversion = "3.00.00.070";
1315 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1316 $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='yuipath'");
1318 my ($value) = $sth->fetchrow;
1319 $value =~ s/2.3.1/2.5.1/;
1320 $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='yuipath';");
1321 print "Update yuipath syspref to 2.5.1 if necessary\n";
1322 SetVersion ($DBversion);
1325 $DBversion = "3.00.00.071";
1326 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1327 $dbh->do(" ALTER TABLE `subscription` ADD `serialsadditems` TINYINT( 1 ) NOT NULL DEFAULT '0';");
1328 # fill the new field with the previous systempreference value, then drop the syspref
1329 my $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='serialsadditems'");
1331 my ($serialsadditems) = $sth->fetchrow();
1332 $dbh->do("UPDATE subscription SET serialsadditems=$serialsadditems");
1333 $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
1334 print "Upgrade to $DBversion done ( moving serialsadditems from syspref to subscription )\n";
1335 SetVersion ($DBversion);
1338 $DBversion = "3.00.00.072";
1339 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1340 $dbh->do("ALTER TABLE labels_conf ADD COLUMN formatstring mediumtext DEFAULT NULL AFTER printingtype");
1341 print "Upgrade to $DBversion done ( Adding format string to labels generator. )\n";
1342 SetVersion ($DBversion);
1345 $DBversion = "3.00.00.073";
1346 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1347 $dbh->do("DROP TABLE IF EXISTS `tags_all`;");
1349 CREATE TABLE `tags_all` (
1350 `tag_id` int(11) NOT NULL auto_increment,
1351 `borrowernumber` int(11) NOT NULL,
1352 `biblionumber` int(11) NOT NULL,
1353 `term` varchar(255) NOT NULL,
1354 `language` int(4) default NULL,
1355 `date_created` datetime NOT NULL,
1356 PRIMARY KEY (`tag_id`),
1357 KEY `tags_borrowers_fk_1` (`borrowernumber`),
1358 KEY `tags_biblionumber_fk_1` (`biblionumber`),
1359 CONSTRAINT `tags_borrowers_fk_1` FOREIGN KEY (`borrowernumber`)
1360 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1361 CONSTRAINT `tags_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
1362 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1363 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1365 $dbh->do("DROP TABLE IF EXISTS `tags_approval`;");
1367 CREATE TABLE `tags_approval` (
1368 `term` varchar(255) NOT NULL,
1369 `approved` int(1) NOT NULL default '0',
1370 `date_approved` datetime default NULL,
1371 `approved_by` int(11) default NULL,
1372 `weight_total` int(9) NOT NULL default '1',
1373 PRIMARY KEY (`term`),
1374 KEY `tags_approval_borrowers_fk_1` (`approved_by`),
1375 CONSTRAINT `tags_approval_borrowers_fk_1` FOREIGN KEY (`approved_by`)
1376 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1377 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1379 $dbh->do("DROP TABLE IF EXISTS `tags_index`;");
1381 CREATE TABLE `tags_index` (
1382 `term` varchar(255) NOT NULL,
1383 `biblionumber` int(11) NOT NULL,
1384 `weight` int(9) NOT NULL default '1',
1385 PRIMARY KEY (`term`,`biblionumber`),
1386 KEY `tags_index_biblionumber_fk_1` (`biblionumber`),
1387 CONSTRAINT `tags_index_term_fk_1` FOREIGN KEY (`term`)
1388 REFERENCES `tags_approval` (`term`) ON DELETE CASCADE ON UPDATE CASCADE,
1389 CONSTRAINT `tags_index_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
1390 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1391 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1394 INSERT INTO `systempreferences` VALUES
1395 ('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=',''),
1396 ('BakerTaylorEnabled','0','','Enable or disable all Baker & Taylor features.','YesNo'),
1397 ('BakerTaylorPassword','','','Baker & Taylor Password for Content Cafe (external content)','Textarea'),
1398 ('BakerTaylorUsername','','','Baker & Taylor Username for Content Cafe (external content)','Textarea'),
1399 ('TagsEnabled','1','','Enables or disables all tagging features. This is the main switch for tags.','YesNo'),
1400 ('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.',''),
1401 ('TagsInputOnDetail','1','','Allow users to input tags from the detail page.', 'YesNo'),
1402 ('TagsInputOnList', '0','','Allow users to input tags from the search results list.', 'YesNo'),
1403 ('TagsModeration', NULL,'','Require tags from patrons to be approved before becoming visible.','YesNo'),
1404 ('TagsShowOnDetail','10','','Number of tags to display on detail page. 0 is off.', 'Integer'),
1405 ('TagsShowOnList', '6','','Number of tags to display on search results list. 0 is off.','Integer')
1407 print "Upgrade to $DBversion done (Baker/Taylor,Tags: sysprefs and tables (tags_all, tags_index, tags_approval)) \n";
1408 SetVersion ($DBversion);
1411 $DBversion = "3.00.00.074";
1412 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1413 $dbh->do( q(update itemtypes set imageurl = concat( 'npl/', imageurl )
1414 where imageurl not like 'http%'
1415 and imageurl is not NULL
1416 and imageurl != '') );
1417 print "Upgrade to $DBversion done (updating imagetype.imageurls to reflect new icon locations.)\n";
1418 SetVersion ($DBversion);
1421 $DBversion = "3.00.00.075";
1422 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1423 $dbh->do( q(alter table authorised_values add imageurl varchar(200) default NULL) );
1424 print "Upgrade to $DBversion done (adding imageurl field to authorised_values table)\n";
1425 SetVersion ($DBversion);
1428 $DBversion = "3.00.00.076";
1429 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1430 $dbh->do("ALTER TABLE import_batches
1431 ADD COLUMN nomatch_action enum('create_new', 'ignore') NOT NULL default 'create_new' AFTER overlay_action");
1432 $dbh->do("ALTER TABLE import_batches
1433 ADD COLUMN item_action enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore')
1434 NOT NULL default 'always_add' AFTER nomatch_action");
1435 $dbh->do("ALTER TABLE import_batches
1436 MODIFY overlay_action enum('replace', 'create_new', 'use_template', 'ignore')
1437 NOT NULL default 'create_new'");
1438 $dbh->do("ALTER TABLE import_records
1439 MODIFY status enum('error', 'staged', 'imported', 'reverted', 'items_reverted',
1440 'ignored') NOT NULL default 'staged'");
1441 $dbh->do("ALTER TABLE import_items
1442 MODIFY status enum('error', 'staged', 'imported', 'reverted', 'ignored') NOT NULL default 'staged'");
1444 print "Upgrade to $DBversion done (changes to import_batches and import_records)\n";
1445 SetVersion ($DBversion);
1448 $DBversion = "3.00.00.077";
1449 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1450 # drop these tables only if they exist and none of them are empty
1451 # these tables are not defined in the packaged 2.2.9, but since it is believed
1452 # that at least one library may be using them in a post-2.2.9 but pre-3.0 Koha,
1453 # some care is taken.
1454 my ($print_error) = $dbh->{PrintError};
1455 $dbh->{PrintError} = 0;
1456 my ($raise_error) = $dbh->{RaiseError};
1457 $dbh->{RaiseError} = 1;
1461 eval { $count = $dbh->do("SELECT 1 FROM categorytable"); };
1465 eval { $count = $dbh->do("SELECT 1 FROM mediatypetable"); };
1469 eval { $count = $dbh->do("SELECT 1 FROM subcategorytable"); };
1475 $dbh->do("DROP TABLE IF EXISTS `categorytable`");
1476 $dbh->do("DROP TABLE IF EXISTS `mediatypetable`");
1477 $dbh->do("DROP TABLE IF EXISTS `subcategorytable`");
1480 $dbh->{PrintError} = $print_error;
1481 $dbh->{RaiseError} = $raise_error;
1482 print "Upgrade to $DBversion done (drop categorytable, subcategorytable, and mediatypetable)\n";
1483 SetVersion ($DBversion);
1486 $DBversion = "3.00.00.078";
1487 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1488 my ($print_error) = $dbh->{PrintError};
1489 $dbh->{PrintError} = 0;
1491 unless ($dbh->do("SELECT 1 FROM browser")) {
1492 $dbh->{PrintError} = $print_error;
1493 $dbh->do("CREATE TABLE `browser` (
1494 `level` int(11) NOT NULL,
1495 `classification` varchar(20) NOT NULL,
1496 `description` varchar(255) NOT NULL,
1497 `number` bigint(20) NOT NULL,
1498 `endnode` tinyint(4) NOT NULL
1499 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1501 $dbh->{PrintError} = $print_error;
1502 print "Upgrade to $DBversion done (add browser table if not already present)\n";
1503 SetVersion ($DBversion);
1506 $DBversion = "3.00.00.079";
1507 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1508 my ($print_error) = $dbh->{PrintError};
1509 $dbh->{PrintError} = 0;
1511 $dbh->do("INSERT INTO `systempreferences` (variable, value,options,type, explanation)VALUES
1512 ('AddPatronLists','categorycode','categorycode|category_type','Choice','Allow user to choose what list to pick up from when adding patrons')");
1513 print "Upgrade to $DBversion done (add browser table if not already present)\n";
1514 SetVersion ($DBversion);
1517 $DBversion = "3.00.00.080";
1518 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1519 $dbh->do("ALTER TABLE subscription CHANGE monthlength monthlength int(11) default '0'");
1520 $dbh->do("ALTER TABLE deleteditems MODIFY marc LONGBLOB AFTER copynumber");
1521 $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
1522 print "Upgrade to $DBversion done (catch up on DB schema changes since alpha and beta)\n";
1523 SetVersion ($DBversion);
1526 $DBversion = "3.00.00.081";
1527 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1528 $dbh->do("CREATE TABLE `borrower_attribute_types` (
1529 `code` varchar(10) NOT NULL,
1530 `description` varchar(255) NOT NULL,
1531 `repeatable` tinyint(1) NOT NULL default 0,
1532 `unique_id` tinyint(1) NOT NULL default 0,
1533 `opac_display` tinyint(1) NOT NULL default 0,
1534 `password_allowed` tinyint(1) NOT NULL default 0,
1535 `staff_searchable` tinyint(1) NOT NULL default 0,
1536 `authorised_value_category` varchar(10) default NULL,
1537 PRIMARY KEY (`code`)
1538 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1539 $dbh->do("CREATE TABLE `borrower_attributes` (
1540 `borrowernumber` int(11) NOT NULL,
1541 `code` varchar(10) NOT NULL,
1542 `attribute` varchar(30) default NULL,
1543 `password` varchar(30) default NULL,
1544 KEY `borrowernumber` (`borrowernumber`),
1545 KEY `code_attribute` (`code`, `attribute`),
1546 CONSTRAINT `borrower_attributes_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1547 ON DELETE CASCADE ON UPDATE CASCADE,
1548 CONSTRAINT `borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`)
1549 ON DELETE CASCADE ON UPDATE CASCADE
1550 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1551 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ExtendedPatronAttributes','0','Use extended patron IDs and attributes',NULL,'YesNo')");
1552 print "Upgrade to $DBversion done (added borrower_attributes and borrower_attribute_types)\n";
1553 SetVersion ($DBversion);
1556 $DBversion = "3.00.00.082";
1557 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1558 $dbh->do( q(alter table accountlines add column lastincrement decimal(28,6) default NULL) );
1559 print "Upgrade to $DBversion done (adding lastincrement column to accountlines table)\n";
1560 SetVersion ($DBversion);
1563 $DBversion = "3.00.00.083";
1564 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1565 $dbh->do( qq(UPDATE systempreferences SET value='local' where variable='yuipath' and value like "%/intranet-tmpl/prog/%"));
1566 print "Upgrade to $DBversion done (Changing yuipath behaviour in managing a local value)\n";
1567 SetVersion ($DBversion);
1569 $DBversion = "3.00.00.084";
1570 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1571 $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')");
1572 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GoogleJackets','0','if ON, displays jacket covers from Google Books API',NULL,'YesNo')");
1573 print "Upgrade to $DBversion done (add new sysprefs)\n";
1574 SetVersion ($DBversion);
1577 $DBversion = "3.00.00.085";
1578 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1579 if (C4::Context->preference("marcflavour") eq 'MARC21') {
1580 $dbh->do("UPDATE marc_subfield_structure SET tab = 0 WHERE tab = 9 AND tagfield = '037'");
1581 $dbh->do("UPDATE marc_subfield_structure SET tab = 1 WHERE tab = 6 AND tagfield in ('100', '110', '111', '130')");
1582 $dbh->do("UPDATE marc_subfield_structure SET tab = 2 WHERE tab = 6 AND tagfield in ('240', '243')");
1583 $dbh->do("UPDATE marc_subfield_structure SET tab = 4 WHERE tab = 6 AND tagfield in ('400', '410', '411', '440')");
1584 $dbh->do("UPDATE marc_subfield_structure SET tab = 5 WHERE tab = 9 AND tagfield = '584'");
1585 $dbh->do("UPDATE marc_subfield_structure SET tab = 7 WHERE tab = -6 AND tagfield = '760'");
1587 print "Upgrade to $DBversion done (move editing tab of various MARC21 subfields)\n";
1588 SetVersion ($DBversion);
1591 $DBversion = "3.00.00.086";
1592 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1594 "CREATE TABLE `tmp_holdsqueue` (
1595 `biblionumber` int(11) default NULL,
1596 `itemnumber` int(11) default NULL,
1597 `barcode` varchar(20) default NULL,
1598 `surname` mediumtext NOT NULL,
1601 `borrowernumber` int(11) NOT NULL,
1602 `cardnumber` varchar(16) default NULL,
1603 `reservedate` date default NULL,
1605 `itemcallnumber` varchar(30) default NULL,
1606 `holdingbranch` varchar(10) default NULL,
1607 `pickbranch` varchar(10) default NULL,
1609 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1611 $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')");
1612 $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')");
1614 print "Upgrade to $DBversion done (Table structure for table `tmp_holdsqueue`)\n";
1615 SetVersion ($DBversion);
1618 $DBversion = "3.00.00.087";
1619 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1620 $dbh->do("INSERT INTO `systempreferences` VALUES ('AutoEmailOpacUser','0','','Sends notification emails containing new account details to patrons - when account is created.','YesNo')" );
1621 $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')");
1622 print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
1623 SetVersion ($DBversion);
1626 $DBversion = "3.00.00.088";
1627 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1628 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('OPACShelfBrowser','1','','Enable/disable Shelf Browser on item details page','YesNo')");
1629 $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')");
1630 $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')");
1631 $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')");
1632 print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
1633 SetVersion ($DBversion);
1636 $DBversion = "3.00.00.089";
1637 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1638 $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')");
1639 print "Upgrade to $DBversion done (added new AdvancedSearchTypes syspref)\n";
1640 SetVersion ($DBversion);
1643 $DBversion = "3.00.00.090";
1644 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1646 CREATE TABLE `branch_borrower_circ_rules` (
1647 `branchcode` VARCHAR(10) NOT NULL,
1648 `categorycode` VARCHAR(10) NOT NULL,
1649 `maxissueqty` int(4) default NULL,
1650 PRIMARY KEY (`categorycode`, `branchcode`),
1651 CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
1652 ON DELETE CASCADE ON UPDATE CASCADE,
1653 CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
1654 ON DELETE CASCADE ON UPDATE CASCADE
1655 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1658 CREATE TABLE `default_borrower_circ_rules` (
1659 `categorycode` VARCHAR(10) NOT NULL,
1660 `maxissueqty` int(4) default NULL,
1661 PRIMARY KEY (`categorycode`),
1662 CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
1663 ON DELETE CASCADE ON UPDATE CASCADE
1664 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1667 CREATE TABLE `default_branch_circ_rules` (
1668 `branchcode` VARCHAR(10) NOT NULL,
1669 `maxissueqty` int(4) default NULL,
1670 PRIMARY KEY (`branchcode`),
1671 CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
1672 ON DELETE CASCADE ON UPDATE CASCADE
1673 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1676 CREATE TABLE `default_circ_rules` (
1677 `singleton` enum('singleton') NOT NULL default 'singleton',
1678 `maxissueqty` int(4) default NULL,
1679 PRIMARY KEY (`singleton`)
1680 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1682 print "Upgrade to $DBversion done (added several circ rules tables)\n";
1683 SetVersion ($DBversion);
1687 $DBversion = "3.00.00.091";
1688 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1689 $dbh->do(<<'END_SQL');
1690 ALTER TABLE borrowers
1691 ADD `smsalertnumber` varchar(50) default NULL
1694 $dbh->do(<<'END_SQL');
1695 CREATE TABLE `message_attributes` (
1696 `message_attribute_id` int(11) NOT NULL auto_increment,
1697 `message_name` varchar(20) NOT NULL default '',
1698 `takes_days` tinyint(1) NOT NULL default '0',
1699 PRIMARY KEY (`message_attribute_id`),
1700 UNIQUE KEY `message_name` (`message_name`)
1701 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1704 $dbh->do(<<'END_SQL');
1705 CREATE TABLE `message_transport_types` (
1706 `message_transport_type` varchar(20) NOT NULL,
1707 PRIMARY KEY (`message_transport_type`)
1708 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1711 $dbh->do(<<'END_SQL');
1712 CREATE TABLE `message_transports` (
1713 `message_attribute_id` int(11) NOT NULL,
1714 `message_transport_type` varchar(20) NOT NULL,
1715 `is_digest` tinyint(1) NOT NULL default '0',
1716 `letter_module` varchar(20) NOT NULL default '',
1717 `letter_code` varchar(20) NOT NULL default '',
1718 PRIMARY KEY (`message_attribute_id`,`message_transport_type`,`is_digest`),
1719 KEY `message_transport_type` (`message_transport_type`),
1720 KEY `letter_module` (`letter_module`,`letter_code`),
1721 CONSTRAINT `message_transports_ibfk_1` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1722 CONSTRAINT `message_transports_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE,
1723 CONSTRAINT `message_transports_ibfk_3` FOREIGN KEY (`letter_module`, `letter_code`) REFERENCES `letter` (`module`, `code`) ON DELETE CASCADE ON UPDATE CASCADE
1724 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1727 $dbh->do(<<'END_SQL');
1728 CREATE TABLE `borrower_message_preferences` (
1729 `borrower_message_preference_id` int(11) NOT NULL auto_increment,
1730 `borrowernumber` int(11) NOT NULL default '0',
1731 `message_attribute_id` int(11) default '0',
1732 `days_in_advance` int(11) default '0',
1733 `wants_digets` tinyint(1) NOT NULL default '0',
1734 PRIMARY KEY (`borrower_message_preference_id`),
1735 KEY `borrowernumber` (`borrowernumber`),
1736 KEY `message_attribute_id` (`message_attribute_id`),
1737 CONSTRAINT `borrower_message_preferences_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1738 CONSTRAINT `borrower_message_preferences_ibfk_2` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE
1739 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1742 $dbh->do(<<'END_SQL');
1743 CREATE TABLE `borrower_message_transport_preferences` (
1744 `borrower_message_preference_id` int(11) NOT NULL default '0',
1745 `message_transport_type` varchar(20) NOT NULL default '0',
1746 PRIMARY KEY (`borrower_message_preference_id`,`message_transport_type`),
1747 KEY `message_transport_type` (`message_transport_type`),
1748 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,
1749 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
1750 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1753 $dbh->do(<<'END_SQL');
1754 CREATE TABLE `message_queue` (
1755 `message_id` int(11) NOT NULL auto_increment,
1756 `borrowernumber` int(11) NOT NULL,
1759 `message_transport_type` varchar(20) NOT NULL,
1760 `status` enum('sent','pending','failed','deleted') NOT NULL default 'pending',
1761 `time_queued` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1762 KEY `message_id` (`message_id`),
1763 KEY `borrowernumber` (`borrowernumber`),
1764 KEY `message_transport_type` (`message_transport_type`),
1765 CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1766 CONSTRAINT `messageq_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE RESTRICT ON UPDATE CASCADE
1767 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1770 $dbh->do(<<'END_SQL');
1771 INSERT INTO `systempreferences`
1772 (variable,value,explanation,options,type)
1774 ('EnhancedMessagingPreferences',0,'If ON, allows patrons to select to receive additional messages about items due or nearly due.','','YesNo')
1777 $dbh->do( <<'END_SQL');
1778 INSERT INTO `letter`
1779 (module, code, name, title, content)
1781 ('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>>'),
1782 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You have <<count>> items due'),
1783 ('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>>'),
1784 ('circulation','PREDUEDGST','Advance Notice of Item Due (Digest)','Advance Notice of Item Due','You have <<count>> items due soon'),
1785 ('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.');
1789 'installer/data/mysql/en/mandatory/message_transport_types.sql',
1790 'installer/data/mysql/en/optional/sample_notices_message_attributes.sql',
1791 'installer/data/mysql/en/optional/sample_notices_message_transports.sql',
1794 my $installer = C4::Installer->new();
1795 foreach my $script ( @sql_scripts ) {
1796 my $full_path = $installer->get_file_path_from_name($script);
1797 my $error = $installer->load_sql($full_path);
1798 warn $error if $error;
1801 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";
1802 SetVersion ($DBversion);
1805 $DBversion = "3.00.00.092";
1806 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1807 $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')");
1808 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Allow hold requests to be placed on damaged items', 'YesNo')");
1809 print "Upgrade to $DBversion done (added new AllowOnShelfHolds syspref)\n";
1810 SetVersion ($DBversion);
1813 $DBversion = "3.00.00.093";
1814 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1815 $dbh->do("ALTER TABLE `items` MODIFY COLUMN `copynumber` VARCHAR(32) DEFAULT NULL");
1816 $dbh->do("ALTER TABLE `deleteditems` MODIFY COLUMN `copynumber` VARCHAR(32) DEFAULT NULL");
1817 print "Upgrade to $DBversion done (Change data type of items.copynumber to allow free text)\n";
1818 SetVersion ($DBversion);
1821 $DBversion = "3.00.00.094";
1822 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1823 $dbh->do("ALTER TABLE `marc_subfield_structure` MODIFY `tagsubfield` VARCHAR(1) NOT NULL DEFAULT '' COLLATE utf8_bin");
1824 print "Upgrade to $DBversion done (Change Collation of marc_subfield_structure to allow mixed case in subfield labels.)\n";
1825 SetVersion ($DBversion);
1828 $DBversion = "3.00.00.095";
1829 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1830 if (C4::Context->preference("marcflavour") eq 'MARC21') {
1831 $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'MEETI_NAME' WHERE authtypecode = 'Meeting Name'");
1832 $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'CORPO_NAME' WHERE authtypecode = 'CORP0_NAME'");
1834 print "Upgrade to $DBversion done (fix invalid authority types in MARC21 frameworks [bug 2254])\n";
1835 SetVersion ($DBversion);
1838 $DBversion = "3.00.00.096";
1839 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1840 $sth = $dbh->prepare("SHOW COLUMNS FROM borrower_message_preferences LIKE 'wants_digets'");
1842 if (my $row = $sth->fetchrow_hashref) {
1843 $dbh->do("ALTER TABLE borrower_message_preferences CHANGE wants_digets wants_digest tinyint(1) NOT NULL default 0");
1845 print "Upgrade to $DBversion done (fix name borrower_message_preferences.wants_digest)\n";
1846 SetVersion ($DBversion);
1849 $DBversion = '3.00.00.097';
1850 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1852 $dbh->do('ALTER TABLE message_queue ADD to_address mediumtext default NULL');
1853 $dbh->do('ALTER TABLE message_queue ADD from_address mediumtext default NULL');
1854 $dbh->do('ALTER TABLE message_queue ADD content_type text');
1855 $dbh->do('ALTER TABLE message_queue CHANGE borrowernumber borrowernumber int(11) default NULL');
1857 print "Upgrade to $DBversion done (updating 4 fields in message_queue table)\n";
1858 SetVersion($DBversion);
1861 $DBversion = '3.00.00.098';
1862 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1864 $dbh->do(q(DELETE FROM message_transport_types WHERE message_transport_type = 'rss'));
1865 $dbh->do(q(DELETE FROM message_transports WHERE message_transport_type = 'rss'));
1867 print "Upgrade to $DBversion done (removing unused RSS message_transport_type)\n";
1868 SetVersion($DBversion);
1871 $DBversion = '3.00.00.099';
1872 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1873 $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')");
1874 print "Upgrade to $DBversion done (Adding OpacSuppression syspref)\n";
1875 SetVersion($DBversion);
1878 $DBversion = '3.00.00.100';
1879 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1880 $dbh->do('ALTER TABLE virtualshelves ADD COLUMN lastmodified timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP');
1881 print "Upgrade to $DBversion done (Adding lastmodified column to virtualshelves)\n";
1882 SetVersion($DBversion);
1885 $DBversion = '3.00.00.101';
1886 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1887 $dbh->do('ALTER TABLE `overduerules` CHANGE `categorycode` `categorycode` VARCHAR(10) NOT NULL');
1888 $dbh->do('ALTER TABLE `deletedborrowers` CHANGE `categorycode` `categorycode` VARCHAR(10) NOT NULL');
1889 print "Upgrade to $DBversion done (Updating columnd definitions for patron category codes in notice/statsu triggers and deletedborrowers tables.)\n";
1890 SetVersion($DBversion);
1893 $DBversion = '3.00.00.102';
1894 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1895 $dbh->do('ALTER TABLE serialitems MODIFY `serialid` int(11) NOT NULL AFTER itemnumber' );
1896 $dbh->do('ALTER TABLE serialitems DROP KEY serialididx' );
1897 $dbh->do('ALTER TABLE serialitems ADD CONSTRAINT UNIQUE KEY serialitemsidx (itemnumber)' );
1898 # before setting constraint, delete any unvalid data
1899 $dbh->do('DELETE from serialitems WHERE serialid not in (SELECT serial.serialid FROM serial)');
1900 $dbh->do('ALTER TABLE serialitems ADD CONSTRAINT serialitems_sfk_1 FOREIGN KEY (serialid) REFERENCES serial (serialid) ON DELETE CASCADE ON UPDATE CASCADE' );
1901 print "Upgrade to $DBversion done (Updating serialitems table to allow for multiple items per serial fixing kohabug 2380)\n";
1902 SetVersion($DBversion);
1905 $DBversion = "3.00.00.103";
1906 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1907 $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
1908 print "Upgrade to $DBversion done ( Verifying the removal of serialsadditems from syspref fixing kohabug 2219)\n";
1909 SetVersion ($DBversion);
1912 $DBversion = "3.00.00.104";
1913 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1914 $dbh->do("DELETE FROM systempreferences WHERE variable='noOPACHolds'");
1915 print "Upgrade to $DBversion done (remove superseded 'noOPACHolds' system preference per bug 2413)\n";
1916 SetVersion ($DBversion);
1919 $DBversion = '3.00.00.105';
1920 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
1922 # it is possible that this syspref is already defined since the feature was added some time ago.
1923 unless ( $dbh->do(q(SELECT variable FROM systempreferences WHERE variable = 'SMSSendDriver')) ) {
1924 $dbh->do(<<'END_SQL');
1925 INSERT INTO `systempreferences`
1926 (variable,value,explanation,options,type)
1928 ('SMSSendDriver','','Sets which SMS::Send driver is used to send SMS messages.','','free')
1931 print "Upgrade to $DBversion done (added SMSSendDriver system preference)\n";
1932 SetVersion($DBversion);
1935 $DBversion = "3.00.00.106";
1936 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1937 $dbh->do("DELETE FROM systempreferences WHERE variable='noOPACHolds'");
1939 # db revision 105 didn't apply correctly, so we're rolling this into 106
1940 $dbh->do("INSERT INTO `systempreferences`
1941 (variable,value,explanation,options,type)
1943 ('SMSSendDriver','','Sets which SMS::Send driver is used to send SMS messages.','','free')");
1945 print "Upgrade to $DBversion done (remove default '0000-00-00' in subscriptionhistory.enddate field)\n";
1946 $dbh->do("ALTER TABLE `subscriptionhistory` CHANGE `enddate` `enddate` DATE NULL DEFAULT NULL ");
1947 $dbh->do("UPDATE subscriptionhistory SET enddate=NULL WHERE enddate='0000-00-00'");
1948 SetVersion ($DBversion);
1951 $DBversion = '3.00.00.107';
1952 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1953 $dbh->do(<<'END_SQL');
1954 UPDATE systempreferences
1955 SET explanation = CONCAT( explanation, '. WARNING: this feature is very resource consuming on collections with large numbers of items.' )
1956 WHERE variable = 'OPACShelfBrowser'
1957 AND explanation NOT LIKE '%WARNING%'
1959 $dbh->do(<<'END_SQL');
1960 UPDATE systempreferences
1961 SET explanation = CONCAT( explanation, '. WARNING: this feature is very resource consuming.' )
1962 WHERE variable = 'CataloguingLog'
1963 AND explanation NOT LIKE '%WARNING%'
1965 $dbh->do(<<'END_SQL');
1966 UPDATE systempreferences
1967 SET explanation = CONCAT( explanation, '. WARNING: using NoZebra on even modest sized collections is very slow.' )
1968 WHERE variable = 'NoZebra'
1969 AND explanation NOT LIKE '%WARNING%'
1971 print "Upgrade to $DBversion done (warning added to OPACShelfBrowser system preference)\n";
1972 SetVersion ($DBversion);
1975 $DBversion = '3.01.00.000';
1976 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1977 print "Upgrade to $DBversion done (start of 3.1)\n";
1978 SetVersion ($DBversion);
1981 $DBversion = '3.01.00.001';
1982 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1984 CREATE TABLE hold_fill_targets (
1985 `borrowernumber` int(11) NOT NULL,
1986 `biblionumber` int(11) NOT NULL,
1987 `itemnumber` int(11) NOT NULL,
1988 `source_branchcode` varchar(10) default NULL,
1989 `item_level_request` tinyint(4) NOT NULL default 0,
1990 PRIMARY KEY `itemnumber` (`itemnumber`),
1991 KEY `bib_branch` (`biblionumber`, `source_branchcode`),
1992 CONSTRAINT `hold_fill_targets_ibfk_1` FOREIGN KEY (`borrowernumber`)
1993 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1994 CONSTRAINT `hold_fill_targets_ibfk_2` FOREIGN KEY (`biblionumber`)
1995 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1996 CONSTRAINT `hold_fill_targets_ibfk_3` FOREIGN KEY (`itemnumber`)
1997 REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1998 CONSTRAINT `hold_fill_targets_ibfk_4` FOREIGN KEY (`source_branchcode`)
1999 REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2000 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2003 ALTER TABLE tmp_holdsqueue
2004 ADD item_level_request tinyint(4) NOT NULL default 0
2007 print "Upgrade to $DBversion done (add hold_fill_targets table and a column to tmp_holdsqueue)\n";
2008 SetVersion($DBversion);
2011 $DBversion = '3.01.00.002';
2012 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2013 # use statistics where available
2015 ALTER TABLE statistics ADD KEY tmp_stats (type, itemnumber, borrowernumber)
2020 SELECT max(datetime)
2022 WHERE type = 'issue'
2023 AND itemnumber = iss.itemnumber
2024 AND borrowernumber = iss.borrowernumber
2026 WHERE issuedate IS NULL;
2028 $dbh->do("ALTER TABLE statistics DROP KEY tmp_stats");
2030 # default to last renewal date
2033 SET issuedate = lastreneweddate
2034 WHERE issuedate IS NULL
2035 and lastreneweddate IS NOT NULL
2038 my $num_bad_issuedates = $dbh->selectrow_array("SELECT COUNT(*) FROM issues WHERE issuedate IS NULL");
2039 if ($num_bad_issuedates > 0) {
2040 print STDERR "After the upgrade to $DBversion, there are still $num_bad_issuedates loan(s) with a NULL (blank) loan date. ",
2041 "Please check the issues table in your database.";
2043 print "Upgrade to $DBversion done (bug 2582: set null issues.issuedate to lastreneweddate)\n";
2044 SetVersion($DBversion);
2047 $DBversion = "3.01.00.003";
2048 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2049 $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')");
2050 print "Upgrade to $DBversion done (add new syspref)\n";
2051 SetVersion ($DBversion);
2054 $DBversion = '3.01.00.004';
2055 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2056 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACDisplayRequestPriority','0','Show patrons the priority level on holds in the OPAC','','YesNo')");
2057 print "Upgrade to $DBversion done (added OPACDisplayRequestPriority system preference)\n";
2058 SetVersion ($DBversion);
2061 $DBversion = '3.01.00.005';
2062 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2064 INSERT INTO `letter` (module, code, name, title, content)
2065 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>>')
2067 $dbh->do("INSERT INTO `message_attributes` (message_attribute_id, message_name, takes_days) values(4, 'Hold Filled', 0)");
2068 $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'sms', 0, 'reserves', 'HOLD')");
2069 $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'email', 0, 'reserves', 'HOLD')");
2070 print "Upgrade to $DBversion done (Add letter for holds notifications)\n";
2071 SetVersion ($DBversion);
2074 $DBversion = '3.01.00.006';
2075 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2076 $dbh->do("ALTER TABLE `biblioitems` ADD KEY issn (issn)");
2077 print "Upgrade to $DBversion done (add index on biblioitems.issn)\n";
2078 SetVersion ($DBversion);
2081 $DBversion = "3.01.00.007";
2082 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2083 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetmainUserblock'");
2084 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetuserjs'");
2085 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacheader'");
2086 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacMainUserBlock'");
2087 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacNav'");
2088 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacuserjs'");
2089 $dbh->do("UPDATE `systempreferences` SET options='30|10', type='Textarea' WHERE variable='OAI-PMH:Set'");
2090 $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetstylesheet'");
2091 $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetcolorstylesheet'");
2092 $dbh->do("UPDATE `systempreferences` SET options='10' WHERE variable='globalDueDate'");
2093 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='numSearchResults'");
2094 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='OPACnumSearchResults'");
2095 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='ReservesMaxPickupDelay'");
2096 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='TransfersMaxDaysWarning'");
2097 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='StaticHoldsQueueWeight'");
2098 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='holdCancelLength'");
2099 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='XISBNDailyLimit'");
2100 $dbh->do("UPDATE `systempreferences` SET type='Float' WHERE variable='gist'");
2101 $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorUsername'");
2102 $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorPassword'");
2103 $dbh->do("UPDATE `systempreferences` SET type='Textarea', options='70|10' WHERE variable='ISBD'");
2104 $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'");
2105 print "Upgrade to $DBversion done (fix display of many sysprefs)\n";
2106 SetVersion ($DBversion);
2109 $DBversion = '3.01.00.008';
2110 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2112 $dbh->do("CREATE TABLE branch_transfer_limits (
2113 limitId int(8) NOT NULL auto_increment,
2114 toBranch varchar(4) NOT NULL,
2115 fromBranch varchar(4) NOT NULL,
2116 itemtype varchar(4) NOT NULL,
2117 PRIMARY KEY (limitId)
2118 ) ENGINE=InnoDB DEFAULT CHARSET=utf8"
2121 $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')");
2123 print "Upgrade to $DBversion done (added branch_transfer_limits table and UseBranchTransferLimits system preference)\n";
2124 SetVersion ($DBversion);
2127 $DBversion = "3.01.00.009";
2128 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2129 $dbh->do("ALTER TABLE permissions MODIFY `code` varchar(64) DEFAULT NULL");
2130 $dbh->do("ALTER TABLE user_permissions MODIFY `code` varchar(64) DEFAULT NULL");
2131 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'circulate_remaining_permissions', 'Remaining circulation permissions')");
2132 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'override_renewals', 'Override blocked renewals')");
2133 print "Upgrade to $DBversion done (added subpermissions for circulate permission)\n";
2136 $DBversion = '3.01.00.010';
2137 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2138 $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `attribute` VARCHAR(64) DEFAULT NULL");
2139 $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `password` VARCHAR(64) DEFAULT NULL");
2140 print "Upgrade to $DBversion done (bug 2687: increase length of borrower attribute fields)\n";
2141 SetVersion ($DBversion);
2144 $DBversion = '3.01.00.011';
2145 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2147 # Yes, the old value was ^M terminated.
2148 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);";
2150 my $intranetuserjs = C4::Context->preference('intranetuserjs');
2151 if ($intranetuserjs and $intranetuserjs eq $bad_value) {
2152 my $sql = <<'END_SQL';
2153 UPDATE systempreferences
2155 WHERE variable = 'intranetuserjs'
2159 print "Upgrade to $DBversion done (removed bogus intranetuserjs syspref)\n";
2160 SetVersion($DBversion);
2163 $DBversion = "3.01.00.012";
2164 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2165 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowHoldPolicyOverride', '0', 'Allow staff to override hold policies when placing holds',NULL,'YesNo')");
2167 CREATE TABLE `branch_item_rules` (
2168 `branchcode` varchar(10) NOT NULL,
2169 `itemtype` varchar(10) NOT NULL,
2170 `holdallowed` tinyint(1) default NULL,
2171 PRIMARY KEY (`itemtype`,`branchcode`),
2172 KEY `branch_item_rules_ibfk_2` (`branchcode`),
2173 CONSTRAINT `branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE,
2174 CONSTRAINT `branch_item_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2175 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2178 CREATE TABLE `default_branch_item_rules` (
2179 `itemtype` varchar(10) NOT NULL,
2180 `holdallowed` tinyint(1) default NULL,
2181 PRIMARY KEY (`itemtype`),
2182 CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE
2183 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2186 ALTER TABLE default_branch_circ_rules
2187 ADD COLUMN holdallowed tinyint(1) NULL
2190 ALTER TABLE default_circ_rules
2191 ADD COLUMN holdallowed tinyint(1) NULL
2193 print "Upgrade to $DBversion done (Add tables and system preferences for holds policies)\n";
2194 SetVersion ($DBversion);
2197 $DBversion = '3.01.00.013';
2198 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2200 CREATE TABLE item_circulation_alert_preferences (
2201 id int(11) AUTO_INCREMENT,
2202 branchcode varchar(10) NOT NULL,
2203 categorycode varchar(10) NOT NULL,
2204 item_type varchar(10) NOT NULL,
2205 notification varchar(16) NOT NULL,
2207 KEY (branchcode, categorycode, item_type, notification)
2208 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2211 $dbh->do(q{ ALTER TABLE `message_queue` ADD metadata text DEFAULT NULL AFTER content; });
2212 $dbh->do(q{ ALTER TABLE `message_queue` ADD letter_code varchar(64) DEFAULT NULL AFTER metadata; });
2215 INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES
2216 ('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.');
2219 INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES
2220 ('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>>.');
2223 $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (5, 'Item Check-in', 0);});
2224 $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (6, 'Item Checkout', 0);});
2226 $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');});
2227 $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');});
2228 $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');});
2229 $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');});
2231 print "Upgrade to $DBversion done (data for Email Checkout Slips project)\n";
2232 SetVersion ($DBversion);
2235 $DBversion = "3.01.00.014";
2236 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2237 $dbh->do("ALTER TABLE `branch_transfer_limits` CHANGE `itemtype` `itemtype` VARCHAR( 4 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL");
2238 $dbh->do("ALTER TABLE `branch_transfer_limits` ADD `ccode` VARCHAR( 10 ) NULL ;");
2239 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2241 'BranchTransferLimitsType', 'ccode', 'itemtype|ccode', 'When using branch transfer limits, choose whether to limit by itemtype or collection code.', 'Choice'
2244 print "Upgrade to $DBversion done ( Updated table for Branch Transfer Limits)\n";
2245 SetVersion ($DBversion);
2248 $DBversion = '3.01.00.015';
2249 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2250 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsClientCode', '0', 'Client Code for using Syndetics Solutions content','','free')");
2252 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEnabled', '0', 'Turn on Syndetics Enhanced Content','','YesNo')");
2254 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsCoverImages', '0', 'Display Cover Images from Syndetics','','YesNo')");
2256 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsTOC', '0', 'Display Table of Content information from Syndetics','','YesNo')");
2258 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSummary', '0', 'Display Summary Information from Syndetics','','YesNo')");
2260 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEditions', '0', 'Display Editions from Syndetics','','YesNo')");
2262 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsExcerpt', '0', 'Display Excerpts and first chapters on OPAC from Syndetics','','YesNo')");
2264 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsReviews', '0', 'Display Reviews on OPAC from Syndetics','','YesNo')");
2266 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAuthorNotes', '0', 'Display Notes about the Author on OPAC from Syndetics','','YesNo')");
2268 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAwards', '0', 'Display Awards on OPAC from Syndetics','','YesNo')");
2270 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSeries', '0', 'Display Series information on OPAC from Syndetics','','YesNo')");
2272 $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')");
2274 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonCoverImages', '0', 'Display cover images on OPAC from Amazon Web Services','','YesNo')");
2276 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonCoverImages', '0', 'Display Cover Images in Staff Client from Amazon Web Services','','YesNo')");
2278 $dbh->do("UPDATE systempreferences SET variable='AmazonEnabled' WHERE variable = 'AmazonContent'");
2280 $dbh->do("UPDATE systempreferences SET variable='OPACAmazonEnabled' WHERE variable = 'OPACAmazonContent'");
2282 print "Upgrade to $DBversion done (added Syndetics Enhanced Content system preferences)\n";
2283 SetVersion ($DBversion);
2286 $DBversion = "3.01.00.016";
2287 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2288 $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')");
2289 print "Upgrade to $DBversion done (Added Babeltheque syspref)\n";
2290 SetVersion ($DBversion);
2293 $DBversion = "3.01.00.017";
2294 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2295 $dbh->do("ALTER TABLE `subscription` ADD `staffdisplaycount` VARCHAR(10) NULL;");
2296 $dbh->do("ALTER TABLE `subscription` ADD `opacdisplaycount` VARCHAR(10) NULL;");
2297 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2299 'StaffSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the Staff client', 'Integer'
2301 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2303 'OPACSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the OPAC', 'Integer'
2306 print "Upgrade to $DBversion done ( Updated table for Serials Display)\n";
2307 SetVersion ($DBversion);
2310 $DBversion = "3.01.00.018";
2311 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2312 $dbh->do("ALTER TABLE deletedborrowers ADD `smsalertnumber` varchar(50) default NULL");
2313 print "Upgrade to $DBversion done (added deletedborrowers.smsalertnumber, missed in 3.00.00.091)\n";
2314 SetVersion ($DBversion);
2317 $DBversion = "3.01.00.019";
2318 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2319 $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')");
2320 print "Upgrade to $DBversion done (adding OPACShowCheckoutName systempref)\n";
2321 SetVersion ($DBversion);
2324 $DBversion = "3.01.00.020";
2325 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2326 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesID','','See:http://librarything.com/forlibraries/','','free')");
2327 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesEnabled','0','Enable or Disable Library Thing for Libraries Features','','YesNo')");
2328 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesTabbedView','0','Put LibraryThingForLibraries Content in Tabs.','','YesNo')");
2329 print "Upgrade to $DBversion done (adding LibraryThing for Libraries sysprefs)\n";
2330 SetVersion ($DBversion);
2333 $DBversion = "3.01.00.021";
2334 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2335 my $enable_reviews = C4::Context->preference('OPACAmazonEnabled') ? '1' : '0';
2336 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonReviews', '$enable_reviews', 'Display Amazon readers reviews on OPAC','','YesNo')");
2337 print "Upgrade to $DBversion done (adding OPACAmazonReviews syspref)\n";
2338 SetVersion ($DBversion);
2341 $DBversion = '3.01.00.022';
2342 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2343 $dbh->do("ALTER TABLE `labels_conf` MODIFY COLUMN `formatstring` mediumtext DEFAULT NULL");
2344 print "Upgrade to $DBversion done (bug 2945: increase size of labels_conf.formatstring)\n";
2345 SetVersion ($DBversion);
2348 $DBversion = '3.01.00.023';
2349 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2350 $dbh->do("ALTER TABLE biblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2351 $dbh->do("ALTER TABLE deletedbiblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2352 $dbh->do("ALTER TABLE import_biblios MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2353 $dbh->do("ALTER TABLE suggestions MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2354 print "Upgrade to $DBversion done (bug 2765: increase width of isbn column in several tables)\n";
2355 SetVersion ($DBversion);
2358 $DBversion = "3.01.00.024";
2359 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2360 $dbh->do("ALTER TABLE labels MODIFY COLUMN batch_id int(10) NOT NULL default 1;");
2361 print "Upgrade to $DBversion done (change labels.batch_id from varchar to int)\n";
2362 SetVersion ($DBversion);
2365 $DBversion = '3.01.00.025';
2366 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2367 $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')");
2369 print "Upgrade to $DBversion done (added ceilingDueDate system preference)\n";
2370 SetVersion ($DBversion);
2373 $DBversion = '3.01.00.026';
2374 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2375 $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')");
2377 print "Upgrade to $DBversion done (added numReturnedItemsToShow system preference)\n";
2378 SetVersion ($DBversion);
2381 $DBversion = '3.01.00.027';
2382 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2383 $dbh->do("ALTER TABLE zebraqueue CHANGE `biblio_auth_number` `biblio_auth_number` bigint(20) unsigned NOT NULL default 0");
2384 print "Upgrade to $DBversion done (Increased size of zebraqueue biblio_auth_number to address bug 3148.)\n";
2385 SetVersion ($DBversion);
2388 $DBversion = '3.01.00.028';
2389 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2390 my $enable_reviews = C4::Context->preference('AmazonEnabled') ? '1' : '0';
2391 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonReviews', '$enable_reviews', 'Display Amazon reviews on staff interface','','YesNo')");
2392 print "Upgrade to $DBversion done (added AmazonReviews)\n";
2393 SetVersion ($DBversion);
2396 $DBversion = '3.01.00.029';
2397 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2398 $dbh->do(q( UPDATE language_rfc4646_to_iso639
2399 SET iso639_2_code = 'spa'
2400 WHERE rfc4646_subtag = 'es'
2401 AND iso639_2_code = 'rus' )
2403 print "Upgrade to $DBversion done (fixed bug 2599: using Spanish search limit retrieves Russian results)\n";
2404 SetVersion ($DBversion);
2407 $DBversion = "3.01.00.030";
2408 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2409 $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')");
2410 print "Upgrade to $DBversion done (added AllowNotForLoanOverride system preference)\n";
2411 SetVersion ($DBversion);
2414 $DBversion = "3.01.00.031";
2415 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2416 $dbh->do("ALTER TABLE branch_transfer_limits
2417 MODIFY toBranch varchar(10) NOT NULL,
2418 MODIFY fromBranch varchar(10) NOT NULL,
2419 MODIFY itemtype varchar(10) NULL");
2420 print "Upgrade to $DBversion done (fix column widths in branch_transfer_limits)\n";
2421 SetVersion ($DBversion);
2424 $DBversion = "3.01.00.032";
2425 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2426 $dbh->do(<<ENDOFRENEWAL);
2427 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');
2429 print "Upgrade to $DBversion done (Change the field)\n";
2430 SetVersion ($DBversion);
2433 $DBversion = "3.01.00.033";
2434 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2436 ALTER TABLE borrower_message_preferences
2437 MODIFY borrowernumber int(11) default NULL,
2438 ADD categorycode varchar(10) default NULL AFTER borrowernumber,
2439 ADD KEY `categorycode` (`categorycode`),
2440 ADD CONSTRAINT `borrower_message_preferences_ibfk_3`
2441 FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
2442 ON DELETE CASCADE ON UPDATE CASCADE
2444 print "Upgrade to $DBversion done (DB changes to allow patron category defaults for messaging preferences)\n";
2445 SetVersion ($DBversion);
2448 $DBversion = "3.01.00.034";
2449 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2450 $dbh->do("ALTER TABLE `subscription` ADD COLUMN `graceperiod` INT(11) NOT NULL default '0';");
2451 print "Upgrade to $DBversion done (Adding graceperiod column to subscription table)\n";
2452 SetVersion ($DBversion);
2455 $DBversion = '3.01.00.035';
2456 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2457 $dbh->do(q{ ALTER TABLE `subscription` ADD location varchar(80) NULL DEFAULT '' AFTER callnumber; });
2458 print "Upgrade to $DBversion done (Adding location to subscription table)\n";
2459 SetVersion ($DBversion);
2462 $DBversion = '3.01.00.036';
2463 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2464 $dbh->do("UPDATE systempreferences SET explanation = 'Choose the default detail view in the staff interface; choose between normal, labeled_marc, marc or isbd'
2465 WHERE variable = 'IntranetBiblioDefaultView'
2466 AND explanation = 'IntranetBiblioDefaultView'");
2467 $dbh->do("UPDATE systempreferences SET type = 'Choice', options = 'normal|marc|isbd|labeled_marc'
2468 WHERE variable = 'IntranetBiblioDefaultView'");
2469 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewISBD','1','Allow display of ISBD view of bibiographic records','','YesNo')");
2470 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Allow display of labeled MARC view of bibiographic records','','YesNo')");
2471 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Allow display of MARC view of bibiographic records','','YesNo')");
2472 print "Upgrade to $DBversion done (new viewISBD, viewLabeledMARC, viewMARC sysprefs and tweak IntranetBiblioDefaultView)\n";
2473 SetVersion ($DBversion);
2476 $DBversion = '3.01.00.037';
2477 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2478 $dbh->do('ALTER TABLE authorised_values ADD KEY `lib` (`lib`)');
2479 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Do not run overdue report until filter selected','','YesNo')");
2480 SetVersion ($DBversion);
2481 print "Upgrade to $DBversion done (added FilterBeforeOverdueReport syspref and new index on authorised_values)\n";
2484 $DBversion = "3.01.00.038";
2485 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2486 # update branches table
2488 $dbh->do("ALTER TABLE branches ADD `branchzip` varchar(25) default NULL AFTER `branchaddress3`");
2489 $dbh->do("ALTER TABLE branches ADD `branchcity` mediumtext AFTER `branchzip`");
2490 $dbh->do("ALTER TABLE branches ADD `branchcountry` text AFTER `branchcity`");
2491 $dbh->do("ALTER TABLE branches ADD `branchurl` mediumtext AFTER `branchemail`");
2492 $dbh->do("ALTER TABLE branches ADD `branchnotes` mediumtext AFTER `branchprinter`");
2493 print "Upgrade to $DBversion done (add ZIP, city, country, URL, and notes column to branches)\n";
2494 SetVersion ($DBversion);
2497 $DBversion = '3.01.00.039';
2498 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2499 $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')");
2500 $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')");
2501 SetVersion ($DBversion);
2502 print "Upgrade to $DBversion done (added SpineLabelFormat and SpineLabelAutoPrint sysprefs)\n";
2505 $DBversion = '3.01.00.040';
2506 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2507 $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')");
2508 $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')");
2509 SetVersion ($DBversion);
2510 print "Upgrade to $DBversion done (AllowHoldDateInFuture and OPACAllowHoldDateInFuture sysprefs)\n";
2513 $DBversion = '3.01.00.041';
2514 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2515 $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')");
2516 SetVersion ($DBversion);
2517 print "Upgrade to $DBversion done (added AWSPrivateKey syspref - note that if you use enhanced content from Amazon, this should be set right away.)\n";
2520 $DBversion = '3.01.00.042';
2521 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2522 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACFineNoRenewals','99999','Fine Limit above which user canmot renew books via OPAC','','Integer')");
2523 SetVersion ($DBversion);
2524 print "Upgrade to $DBversion done (added OPACFineNoRenewals syspref)\n";
2527 $DBversion = '3.01.00.043';
2528 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2529 $dbh->do('ALTER TABLE items ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location');
2530 $dbh->do('UPDATE items SET permanent_location = location');
2531 $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 )', '')");
2532 $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')");
2533 $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')");
2534 SetVersion ($DBversion);
2535 print "Upgrade to $DBversion done (amended Item added NewItemsDefaultLocation, InProcessingToShelvingCart, ReturnToShelvingCart sysprefs)\n";
2538 $DBversion = '3.01.00.044';
2539 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2540 $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')");
2541 SetVersion ($DBversion);
2542 print "Upgrade to $DBversion done (added DisplayClearScreenButton system preference)\n";
2545 $DBversion = '3.01.00.045';
2546 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2547 $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')");
2548 SetVersion ($DBversion);
2549 print "Upgrade to $DBversion done (added a preference to hide the patrons name in the staff catalog)\n";
2552 $DBversion = "3.01.00.046";
2553 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2554 # update borrowers table
2556 $dbh->do("ALTER TABLE borrowers ADD `country` text AFTER zipcode");
2557 $dbh->do("ALTER TABLE borrowers ADD `B_country` text AFTER B_zipcode");
2558 $dbh->do("ALTER TABLE deletedborrowers ADD `country` text AFTER zipcode");
2559 $dbh->do("ALTER TABLE deletedborrowers ADD `B_country` text AFTER B_zipcode");
2560 print "Upgrade to $DBversion done (add country and B_country to borrowers)\n";
2561 SetVersion ($DBversion);
2564 $DBversion = '3.01.00.047';
2565 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2566 $dbh->do("ALTER TABLE items MODIFY itemcallnumber varchar(255);");
2567 $dbh->do("ALTER TABLE deleteditems MODIFY itemcallnumber varchar(255);");
2568 $dbh->do("ALTER TABLE tmp_holdsqueue MODIFY itemcallnumber varchar(255);");
2569 SetVersion ($DBversion);
2570 print " Upgrade to $DBversion done (bug 2761: change max length of itemcallnumber to 255 from 30)\n";
2573 $DBversion = '3.01.00.048';
2574 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2575 $dbh->do("UPDATE userflags SET flagdesc='View Catalog (Librarian Interface)' WHERE bit=2;");
2576 $dbh->do("UPDATE userflags SET flagdesc='Edit Catalog (Modify bibliographic/holdings data)' WHERE bit=9;");
2577 $dbh->do("UPDATE userflags SET flagdesc='Allow to edit authorities' WHERE bit=14;");
2578 $dbh->do("UPDATE userflags SET flagdesc='Allow to access to the reports module' WHERE bit=16;");
2579 $dbh->do("UPDATE userflags SET flagdesc='Allow to manage serials subscriptions' WHERE bit=15;");
2580 SetVersion ($DBversion);
2581 print " Upgrade to $DBversion done (bug 2611: fix spelling/capitalization in permission flag descriptions)\n";
2584 $DBversion = '3.01.00.049';
2585 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2586 $dbh->do("UPDATE permissions SET description = 'Perform inventory (stocktaking) of your catalog' WHERE code = 'inventory';");
2587 SetVersion ($DBversion);
2588 print "Upgrade to $DBversion done (bug 2611: changed catalogue to catalog per the standard)\n";
2591 $DBversion = '3.01.00.050';
2592 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2593 $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');");
2594 SetVersion ($DBversion);
2595 print "Upgrade to $DBversion done (bug 1934: Add OPACSearchForTitleIn syspref)\n";
2598 $DBversion = '3.01.00.051';
2599 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2600 $dbh->do("UPDATE systempreferences SET explanation='Fine limit above which user cannot renew books via OPAC' WHERE variable='OPACFineNoRenewals';");
2601 $dbh->do("UPDATE systempreferences SET explanation='If set to ON, a clear screen button will appear on the circulation page.' WHERE variable='DisplayClearScreenButton';");
2602 SetVersion ($DBversion);
2603 print "Upgrade to $DBversion done (fixed typos in new sysprefs)\n";
2606 $DBversion = '3.01.00.052';
2607 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2608 $dbh->do('ALTER TABLE deleteditems ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location');
2609 SetVersion ($DBversion);
2610 print "Upgrade to $DBversion done (bug 3481: add permanent_location column to deleteditems)\n";
2613 $DBversion = '3.01.00.053';
2614 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2615 my $upgrade_script = C4::Context->config("intranetdir") . "/installer/data/mysql/labels_upgrade.pl";
2616 system("perl $upgrade_script");
2617 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";
2618 SetVersion ($DBversion);
2621 $DBversion = '3.01.00.054';
2622 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2623 $dbh->do("ALTER TABLE borrowers ADD `B_address2` text AFTER B_address");
2624 $dbh->do("ALTER TABLE borrowers ADD `altcontactcountry` text AFTER altcontactzipcode");
2625 $dbh->do("ALTER TABLE deletedborrowers ADD `B_address2` text AFTER B_address");
2626 $dbh->do("ALTER TABLE deletedborrowers ADD `altcontactcountry` text AFTER altcontactzipcode");
2627 SetVersion ($DBversion);
2628 print "Upgrade to $DBversion done (bug 1600, bug 3454: add altcontactcountry and B_address2 to borrowers and deletedborrowers)\n";
2631 $DBversion = '3.01.00.055';
2632 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2633 $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'|);
2634 SetVersion ($DBversion);
2635 print "Upgrade to $DBversion done (changed OPACSearchForTitleIn per requests in bug 1934)\n";
2638 $DBversion = '3.01.00.056';
2639 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2640 $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');");
2641 SetVersion ($DBversion);
2642 print "Upgrade to $DBversion done (Bug 1172 : Add OPACPatronDetails syspref)\n";
2645 $DBversion = '3.01.00.057';
2646 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2647 $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');");
2648 SetVersion ($DBversion);
2649 print "Upgrade to $DBversion done (Bug 2576 : Add OPACFinesTab syspref)\n";
2652 $DBversion = '3.01.00.058';
2653 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2654 $dbh->do("ALTER TABLE `language_subtag_registry` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2655 $dbh->do("ALTER TABLE `language_rfc4646_to_iso639` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2656 $dbh->do("ALTER TABLE `language_descriptions` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2657 SetVersion ($DBversion);
2658 print "Upgrade to $DBversion done (Added primary keys to language tables)\n";
2661 $DBversion = '3.01.00.059';
2662 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2663 $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')");
2664 SetVersion ($DBversion);
2665 print "Upgrade to $DBversion done (added DisplayOPACiconsXSLT sysprefs)\n";
2668 $DBversion = '3.01.00.060';
2669 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2670 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo');");
2671 $dbh->do('DROP TABLE IF EXISTS messages');
2672 $dbh->do("CREATE TABLE messages ( `message_id` int(11) NOT NULL auto_increment,
2673 `borrowernumber` int(11) NOT NULL,
2674 `branchcode` varchar(4) default NULL,
2675 `message_type` varchar(1) NOT NULL,
2676 `message` text NOT NULL,
2677 `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
2678 PRIMARY KEY (`message_id`)
2679 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
2681 print "Upgrade to $DBversion done ( Added AllowAllMessageDeletion syspref and messages table )\n";
2682 SetVersion ($DBversion);
2685 $DBversion = '3.01.00.061';
2686 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2687 $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')");
2688 print "Upgrade to $DBversion done ( Added ShowPatronImageInWebBasedSelfCheck system preference )\n";
2689 SetVersion ($DBversion);
2692 $DBversion = "3.01.00.062";
2693 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2694 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'manage_csv_profiles', 'Manage CSV export profiles')");
2696 CREATE TABLE `export_format` (
2697 `export_format_id` int(11) NOT NULL auto_increment,
2698 `profile` varchar(255) NOT NULL,
2699 `description` mediumtext NOT NULL,
2700 `marcfields` mediumtext NOT NULL,
2701 PRIMARY KEY (`export_format_id`)
2702 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used for CSV export';
2704 print "Upgrade to $DBversion done (added csv export profiles)\n";
2707 $DBversion = "3.01.00.063";
2708 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2710 CREATE TABLE `fieldmapping` (
2711 `id` int(11) NOT NULL auto_increment,
2712 `field` varchar(255) NOT NULL,
2713 `frameworkcode` char(4) NOT NULL default '',
2714 `fieldcode` char(3) NOT NULL,
2715 `subfieldcode` char(1) NOT NULL,
2717 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2719 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";
2722 $DBversion = '3.01.00.065';
2723 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2724 $dbh->do('ALTER TABLE issuingrules ADD COLUMN `renewalsallowed` smallint(6) NOT NULL default "0" AFTER `issuelength`;');
2725 $sth = $dbh->prepare("SELECT itemtype, renewalsallowed FROM itemtypes");
2728 my $sthupd = $dbh->prepare("UPDATE issuingrules SET renewalsallowed = ? WHERE itemtype = ?");
2730 while(my $row = $sth->fetchrow_hashref){
2731 $sthupd->execute($row->{renewalsallowed}, $row->{itemtype});
2734 $dbh->do('ALTER TABLE itemtypes DROP COLUMN `renewalsallowed`;');
2736 SetVersion ($DBversion);
2737 print "Upgrade to $DBversion done (Moving allowed renewals from itemtypes to issuingrule)\n";
2740 $DBversion = '3.01.00.066';
2741 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2742 $dbh->do('ALTER TABLE issuingrules ADD COLUMN `reservesallowed` smallint(6) NOT NULL default "0" AFTER `renewalsallowed`;');
2744 my $maxreserves = C4::Context->preference('maxreserves');
2745 $sth = $dbh->prepare('UPDATE issuingrules SET reservesallowed = ?;');
2746 $sth->execute($maxreserves);
2748 $dbh->do('DELETE FROM systempreferences WHERE variable = "maxreserves";');
2750 $dbh->do("INSERT INTO systempreferences (variable,value, options, explanation, type) VALUES('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice')");
2752 SetVersion ($DBversion);
2753 print "Upgrade to $DBversion done (Moving max allowed reserves from system preference to issuingrule)\n";
2756 $DBversion = "3.01.00.067";
2757 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2758 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchmod', 'Perform batch modification of items')");
2759 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchdel', 'Perform batch deletion of items')");
2760 print "Upgrade to $DBversion done (added permissions for batch modification and deletion)\n";
2761 SetVersion ($DBversion);
2764 $DBversion = "3.01.00.068";
2765 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2766 $dbh->do("ALTER TABLE issuingrules ADD COLUMN `finedays` int(11) default NULL AFTER `fine` ");
2767 print "Upgrade to $DBversion done (Adding finedays in issuingrules table)\n";
2768 SetVersion ($DBversion);
2772 $DBversion = "3.01.00.069";
2773 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2774 $dbh->do("INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('EnableOpacSearchHistory', '1', '', 'Enable or disable opac search history', 'YesNo')");
2776 my $create = <<SEARCHHIST;
2777 CREATE TABLE IF NOT EXISTS `search_history` (
2778 `userid` int(11) NOT NULL,
2779 `sessionid` varchar(32) NOT NULL,
2780 `query_desc` varchar(255) NOT NULL,
2781 `query_cgi` varchar(255) NOT NULL,
2782 `total` int(11) NOT NULL,
2783 `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
2784 KEY `userid` (`userid`),
2785 KEY `sessionid` (`sessionid`)
2786 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Opac search history results';
2790 print "Upgrade to $DBversion done (added OPAC search history preference and table)\n";
2793 $DBversion = "3.01.00.070";
2794 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2795 $dbh->do("ALTER TABLE authorised_values ADD COLUMN `lib_opac` VARCHAR(80) default NULL AFTER `lib`");
2796 print "Upgrade to $DBversion done (Added a lib_opac field in authorised_values table)\n";
2799 $DBversion = "3.01.00.071";
2800 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2801 $dbh->do("ALTER TABLE `subscription` ADD `enddate` date default NULL");
2802 $dbh->do("ALTER TABLE subscriptionhistory CHANGE enddate histenddate DATE default NULL");
2803 print "Upgrade to $DBversion done ( Adding enddate to subscription)\n";
2806 # Acquisitions update
2808 $DBversion = "3.01.00.072";
2809 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2810 $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')");
2811 # create a new syspref for the 'Mr anonymous' patron
2812 $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,'')");
2813 # fill AnonymousPatron with AnonymousSuggestion value (copy)
2814 my $sth=$dbh->prepare("SELECT value FROM systempreferences WHERE variable='AnonSuggestions'");
2816 my ($value) = $sth->fetchrow() || 0;
2817 $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='AnonymousPatron'");
2818 # set AnonymousSuggestion do YesNo
2819 # 1st, set the value (1/True if it had a borrowernumber)
2820 $dbh->do("UPDATE systempreferences SET value=1 WHERE variable='AnonSuggestions' AND value>0");
2821 # 2nd, change the type to Choice
2822 $dbh->do("UPDATE systempreferences SET type='YesNo' WHERE variable='AnonSuggestions'");
2823 # borrower reading record privacy : 0 : forever, 1 : laws, 2 : don't keep at all
2824 $dbh->do("ALTER TABLE `borrowers` ADD `privacy` INTEGER NOT NULL DEFAULT 1;");
2825 print "Upgrade to $DBversion done (add new syspref and column in borrowers)\n";
2826 SetVersion ($DBversion);
2829 $DBversion = '3.01.00.073';
2830 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2831 $dbh->do('SET FOREIGN_KEY_CHECKS=0 ');
2832 $dbh->do(<<'END_SQL');
2833 CREATE TABLE IF NOT EXISTS `aqcontract` (
2834 `contractnumber` int(11) NOT NULL auto_increment,
2835 `contractstartdate` date default NULL,
2836 `contractenddate` date default NULL,
2837 `contractname` varchar(50) default NULL,
2838 `contractdescription` mediumtext,
2839 `booksellerid` int(11) not NULL,
2840 PRIMARY KEY (`contractnumber`),
2841 CONSTRAINT `booksellerid_fk1` FOREIGN KEY (`booksellerid`)
2842 REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
2843 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
2845 $dbh->do('SET FOREIGN_KEY_CHECKS=1 ');
2846 print "Upgrade to $DBversion done (adding aqcontract table)\n";
2847 SetVersion ($DBversion);
2850 $DBversion = '3.01.00.074';
2851 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2852 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `basketname` varchar(50) default NULL AFTER `basketno`");
2853 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `note` mediumtext AFTER `basketname`");
2854 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `booksellernote` mediumtext AFTER `note`");
2855 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `contractnumber` int(11) AFTER `booksellernote`");
2856 $dbh->do("ALTER TABLE `aqbasket` ADD FOREIGN KEY (`contractnumber`) REFERENCES `aqcontract` (`contractnumber`)");
2857 print "Upgrade to $DBversion done (edit aqbasket table done)\n";
2858 SetVersion ($DBversion);
2861 $DBversion = '3.01.00.075';
2862 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2863 $dbh->do("ALTER TABLE `aqorders` ADD COLUMN `uncertainprice` tinyint(1)");
2865 print "Upgrade to $DBversion done (adding uncertainprices)\n";
2866 SetVersion ($DBversion);
2869 $DBversion = '3.01.00.076';
2870 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2871 $dbh->do('SET FOREIGN_KEY_CHECKS=0 ');
2872 $dbh->do("CREATE TABLE IF NOT EXISTS `aqbasketgroups` (
2873 `id` int(11) NOT NULL auto_increment,
2874 `name` varchar(50) default NULL,
2875 `closed` tinyint(1) default NULL,
2876 `booksellerid` int(11) NOT NULL,
2878 KEY `booksellerid` (`booksellerid`),
2879 CONSTRAINT `aqbasketgroups_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
2880 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
2881 $dbh->do("ALTER TABLE aqbasket ADD COLUMN `basketgroupid` int(11)");
2882 $dbh->do("ALTER TABLE aqbasket ADD FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE ON DELETE SET NULL");
2883 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('pdfformat','pdfformat::layout2pages','Controls what script is used for printing (basketgroups)','','free')");
2884 $dbh->do('SET FOREIGN_KEY_CHECKS=1 ');
2885 print "Upgrade to $DBversion done (adding basketgroups)\n";
2886 SetVersion ($DBversion);
2888 $DBversion = '3.01.00.077';
2889 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2891 $dbh->do("SET FOREIGN_KEY_CHECKS=0 ");
2892 # create a mapping table holding the info we need to match orders to budgets
2893 $dbh->do('DROP TABLE IF EXISTS fundmapping');
2895 q|CREATE TABLE fundmapping AS
2896 SELECT aqorderbreakdown.ordernumber, branchcode, bookfundid, budgetdate, entrydate
2897 FROM aqorderbreakdown JOIN aqorders ON aqorderbreakdown.ordernumber = aqorders.ordernumber|);
2898 # match the new type of the corresponding field
2899 $dbh->do('ALTER TABLE fundmapping modify column bookfundid varchar(30)');
2900 # System did not ensure budgetdate was valid historically
2901 $dbh->do(q|UPDATE fundmapping SET budgetdate = entrydate WHERE budgetdate = '0000-00-00' OR budgetdate IS NULL|);
2902 # We save the map in fundmapping in case you need later processing
2903 $dbh->do(q|ALTER TABLE fundmapping add column aqbudgetid integer|);
2904 # these can speed processing up
2905 $dbh->do(q|CREATE INDEX fundmaporder ON fundmapping (ordernumber)|);
2906 $dbh->do(q|CREATE INDEX fundmapid ON fundmapping (bookfundid)|);
2908 $dbh->do("DROP TABLE IF EXISTS `aqbudgetperiods` ");
2911 CREATE TABLE `aqbudgetperiods` (
2912 `budget_period_id` int(11) NOT NULL auto_increment,
2913 `budget_period_startdate` date NOT NULL,
2914 `budget_period_enddate` date NOT NULL,
2915 `budget_period_active` tinyint(1) default '0',
2916 `budget_period_description` mediumtext,
2917 `budget_period_locked` tinyint(1) default NULL,
2918 `sort1_authcat` varchar(10) default NULL,
2919 `sort2_authcat` varchar(10) default NULL,
2920 PRIMARY KEY (`budget_period_id`)
2921 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |);
2923 $dbh->do(<<ADDPERIODS);
2924 INSERT INTO aqbudgetperiods (budget_period_startdate,budget_period_enddate,budget_period_active,budget_period_description,budget_period_locked)
2925 SELECT DISTINCT startdate, enddate, NOW() BETWEEN startdate and enddate, concat(startdate," ",enddate),NOT NOW() BETWEEN startdate AND enddate from aqbudget
2927 # SORRY , NO AQBUDGET/AQBOOKFUND -> AQBUDGETS IMPORT JUST YET,
2928 # BUT A NEW CLEAN AQBUDGETS TABLE CREATE FOR NOW..
2929 # DROP TABLE IF EXISTS `aqbudget`;
2930 #CREATE TABLE `aqbudget` (
2931 # `bookfundid` varchar(10) NOT NULL default ',
2932 # `startdate` date NOT NULL default 0,
2933 # `enddate` date default NULL,
2934 # `budgetamount` decimal(13,2) default NULL,
2935 # `aqbudgetid` tinyint(4) NOT NULL auto_increment,
2936 # `branchcode` varchar(10) default NULL,
2937 DropAllForeignKeys('aqbudget');
2938 #$dbh->do("drop table aqbudget;");
2941 my $maxbudgetid = $dbh->selectcol_arrayref(<<IDsBUDGET);
2942 SELECT MAX(aqbudgetid) from aqbudget
2945 $$maxbudgetid[0] = 0 if !$$maxbudgetid[0];
2947 $dbh->do(<<BUDGETAUTOINCREMENT);
2948 ALTER TABLE aqbudget AUTO_INCREMENT=$$maxbudgetid[0]
2951 $dbh->do(<<BUDGETNAME);
2952 ALTER TABLE aqbudget RENAME `aqbudgets`
2955 $dbh->do(<<BUDGETS);
2956 ALTER TABLE `aqbudgets`
2957 CHANGE COLUMN aqbudgetid `budget_id` int(11) NOT NULL AUTO_INCREMENT,
2958 CHANGE COLUMN branchcode `budget_branchcode` varchar(10) default NULL,
2959 CHANGE COLUMN budgetamount `budget_amount` decimal(28,6) NOT NULL default '0.00',
2960 CHANGE COLUMN bookfundid `budget_code` varchar(30) default NULL,
2961 ADD COLUMN `budget_parent_id` int(11) default NULL,
2962 ADD COLUMN `budget_name` varchar(80) default NULL,
2963 ADD COLUMN `budget_encumb` decimal(28,6) default '0.00',
2964 ADD COLUMN `budget_expend` decimal(28,6) default '0.00',
2965 ADD COLUMN `budget_notes` mediumtext,
2966 ADD COLUMN `budget_description` mediumtext,
2967 ADD COLUMN `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2968 ADD COLUMN `budget_amount_sublevel` decimal(28,6) AFTER `budget_amount`,
2969 ADD COLUMN `budget_period_id` int(11) default NULL,
2970 ADD COLUMN `sort1_authcat` varchar(80) default NULL,
2971 ADD COLUMN `sort2_authcat` varchar(80) default NULL,
2972 ADD COLUMN `budget_owner_id` int(11) default NULL,
2973 ADD COLUMN `budget_permission` int(1) default '0';
2976 $dbh->do(<<BUDGETCONSTRAINTS);
2977 ALTER TABLE `aqbudgets`
2978 ADD CONSTRAINT `aqbudgets_ifbk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON DELETE CASCADE ON UPDATE CASCADE
2980 # $dbh->do(<<BUDGETPKDROP);
2981 #ALTER TABLE `aqbudgets`
2984 # $dbh->do(<<BUDGETPKADD);
2985 #ALTER TABLE `aqbudgets`
2986 # ADD PRIMARY KEY budget_id
2990 my $query_period= $dbh->prepare(qq|SELECT budget_period_id from aqbudgetperiods where budget_period_startdate=? and budget_period_enddate=?|);
2991 my $query_bookfund= $dbh->prepare(qq|SELECT * from aqbookfund where bookfundid=?|);
2992 my $selectbudgets=$dbh->prepare(qq|SELECT * from aqbudgets|);
2993 my $updatebudgets=$dbh->prepare(qq|UPDATE aqbudgets SET budget_period_id= ? , budget_name=?, budget_branchcode=? where budget_id=?|);
2994 $selectbudgets->execute;
2995 while (my $databudget=$selectbudgets->fetchrow_hashref){
2996 $query_period->execute ($$databudget{startdate},$$databudget{enddate});
2997 my ($budgetperiodid)=$query_period->fetchrow;
2998 $query_bookfund->execute ($$databudget{budget_code});
2999 my $databf=$query_bookfund->fetchrow_hashref;
3000 my $branchcode=$$databudget{budget_branchcode}||$$databf{branchcode};
3001 $updatebudgets->execute($budgetperiodid,$$databf{bookfundname},$branchcode,$$databudget{budget_id});
3003 $dbh->do(<<BUDGETDROPDATES);
3004 ALTER TABLE `aqbudgets`
3010 $dbh->do("DROP TABLE IF EXISTS `aqbudgets_planning` ");
3011 $dbh->do("CREATE TABLE `aqbudgets_planning` (
3012 `plan_id` int(11) NOT NULL auto_increment,
3013 `budget_id` int(11) NOT NULL,
3014 `budget_period_id` int(11) NOT NULL,
3015 `estimated_amount` decimal(28,6) default NULL,
3016 `authcat` varchar(30) NOT NULL,
3017 `authvalue` varchar(30) NOT NULL,
3018 `display` tinyint(1) DEFAULT 1,
3019 PRIMARY KEY (`plan_id`),
3020 CONSTRAINT `aqbudgets_planning_ifbk_1` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
3021 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
3023 $dbh->do("ALTER TABLE `aqorders`
3024 ADD COLUMN `budget_id` tinyint(4) NOT NULL,
3025 ADD COLUMN `budgetgroup_id` int(11) NOT NULL,
3026 ADD COLUMN `sort1_authcat` varchar(10) default NULL,
3027 ADD COLUMN `sort2_authcat` varchar(10) default NULL" );
3028 # We need to map the orders to the budgets
3029 # For Historic reasons this is more complex than it should be on occasions
3030 my $budg_arr = $dbh->selectall_arrayref(
3031 q|SELECT aqbudgets.budget_id, aqbudgets.budget_code, aqbudgetperiods.budget_period_startdate,
3032 aqbudgetperiods.budget_period_enddate
3033 FROM aqbudgets JOIN aqbudgetperiods ON aqbudgets.budget_period_id = aqbudgetperiods.budget_period_id
3034 ORDER BY budget_code, budget_period_startdate|, { Slice => {} });
3035 # We arbitarily order on start date, this means if you have overlapping periods the order will be
3036 # linked to the latest matching budget YMMV
3037 my $b_sth = $dbh->prepare(
3038 'UPDATE fundmapping set aqbudgetid = ? where bookfundid =? AND budgetdate >= ? AND budgetdate <= ?');
3039 for my $b ( @{$budg_arr}) {
3040 $b_sth->execute($b->{budget_id}, $b->{budget_code}, $b->{budget_period_startdate}, $b->{budget_period_enddate});
3042 # move the budgetids to aqorders
3043 $dbh->do(q|UPDATE aqorders, fundmapping SET aqorders.budget_id = fundmapping.aqbudgetid
3044 WHERE aqorders.ordernumber = fundmapping.ordernumber AND fundmapping.aqbudgetid IS NOT NULL|);
3045 # NB fundmapping is left as an accontants trail also if you have budgetids that werent set
3046 # you can decide what to do with them
3049 q|UPDATE aqorders, aqbudgets SET aqorders.budgetgroup_id = aqbudgets.budget_period_id
3050 WHERE aqorders.budget_id = aqbudgets.budget_id|);
3051 # cannot do until aqorderbreakdown removed
3052 # $dbh->do("DROP TABLE aqbookfund ");
3053 # $dbh->do("ALTER TABLE aqorders ADD FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON UPDATE CASCADE " ); ????
3054 $dbh->do("SET FOREIGN_KEY_CHECKS=1 ");
3056 print "Upgrade to $DBversion done (Adding new aqbudgetperiods, aqbudgets and aqbudget_planning tables )\n";
3057 SetVersion ($DBversion);
3062 $DBversion = '3.01.00.078';
3063 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
3064 $dbh->do("ALTER TABLE aqbudgetperiods ADD COLUMN budget_period_total decimal(28,6)");
3065 print "Upgrade to $DBversion done (adds 'budget_period_total' column to aqbudgetperiods table)\n";
3066 SetVersion($DBversion);
3070 $DBversion = '3.01.00.079';
3071 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
3072 $dbh->do("ALTER TABLE currency ADD COLUMN active tinyint(1)");
3074 print "Upgrade to $DBversion done (adds 'active' column to currencies table)\n";
3075 SetVersion($DBversion);
3078 $DBversion = '3.01.00.080';
3079 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
3080 $dbh->do(<<BUDG_PERM );
3081 INSERT INTO permissions (module_bit, code, description) VALUES
3082 (11, 'vendors_manage', 'Manage vendors'),
3083 (11, 'contracts_manage', 'Manage contracts'),
3084 (11, 'period_manage', 'Manage periods'),
3085 (11, 'budget_manage', 'Manage budgets'),
3086 (11, 'budget_modify', "Modify budget (can't create lines but can modify existing ones)"),
3087 (11, 'planning_manage', 'Manage budget plannings'),
3088 (11, 'order_manage', 'Manage orders & basket'),
3089 (11, 'group_manage', 'Manage orders & basketgroups'),
3090 (11, 'order_receive', 'Manage orders & basket'),
3091 (11, 'budget_add_del', "Add and delete budgets (but can't modify budgets)");
3094 print "Upgrade to $DBversion done (adds permissions for the acquisitions module)\n";
3095 SetVersion($DBversion);
3099 $DBversion = '3.01.00.081';
3100 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
3101 $dbh->do("ALTER TABLE aqbooksellers ADD COLUMN `gstrate` decimal(6,4) default NULL");
3102 if (my $gist=C4::Context->preference("gist")){
3103 my $sql=$dbh->prepare("UPDATE aqbooksellers set `gstrate`=? ");
3104 $sql->execute($gist) ;
3106 print "Upgrade to $DBversion done (added per-supplier gstrate setting)\n";
3107 SetVersion($DBversion);
3110 $DBversion = "3.01.00.082";
3111 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3112 if (C4::Context->preference("opaclanguages") eq "fr") {
3113 $dbh->do(qq#INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AcqCreateItem','ordering',"Définit quand l'exemplaire est créé : à la commande, à la livraison, au catalogage",'ordering|receiving|cataloguing','Choice')#);
3115 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AcqCreateItem','ordering','Define when the item is created : when ordering, when receiving, or in cataloguing module','ordering|receiving|cataloguing','Choice')");
3117 print "Upgrade to $DBversion done (adding ReservesNeedReturns systempref, in circulation)\n";
3118 SetVersion ($DBversion);
3121 $DBversion = "3.01.00.083";
3122 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3124 CREATE TABLE `aqorders_items` (
3125 `ordernumber` int(11) NOT NULL,
3126 `itemnumber` int(11) NOT NULL,
3127 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
3128 PRIMARY KEY (`itemnumber`),
3129 KEY `ordernumber` (`ordernumber`)
3130 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
3133 $dbh->do(qq| DROP TABLE aqorderbreakdown |);
3134 $dbh->do('DROP TABLE aqbookfund');
3135 print "Upgrade to $DBversion done (New aqorders_items table for acqui)\n";
3136 SetVersion ($DBversion);
3139 $DBversion = "3.01.00.084";
3140 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3141 $dbh->do( qq# INSERT INTO `systempreferences` VALUES ('CurrencyFormat','US','US|FR','Determines the display format of currencies. eg: ''36000'' is displayed as ''360 000,00'' in ''FR'' or 360,000.00'' in ''US''.','Choice') #);
3143 print "Upgrade to $DBversion done (CurrencyFormat syspref added)\n";
3144 SetVersion ($DBversion);
3147 $DBversion = "3.01.00.085";
3148 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3149 $dbh->do("ALTER table aqorders drop column title");
3150 $dbh->do("ALTER TABLE `aqorders` CHANGE `budget_id` `budget_id` INT( 11 ) NOT NULL");
3151 print "Upgrade to $DBversion done update budget_id size that should not be a tinyint\n";
3152 SetVersion ($DBversion);
3155 $DBversion = "3.01.00.086";
3156 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3157 $dbh->do(<<SUGGESTIONS);
3158 ALTER table suggestions
3159 ADD budgetid INT(11),
3160 ADD branchcode VARCHAR(10) default NULL,
3161 ADD acceptedby INT(11) default NULL,
3162 ADD accepteddate date default NULL,
3163 ADD suggesteddate date default NULL,
3164 ADD manageddate date default NULL,
3165 ADD rejectedby INT(11) default NULL,
3166 ADD rejecteddate date default NULL,
3167 ADD collectiontitle text default NULL,
3168 ADD itemtype VARCHAR(30) default NULL
3171 print "Upgrade to $DBversion done (Suggestions)\n";
3172 SetVersion ($DBversion);
3175 $DBversion = "3.01.00.087";
3176 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3177 $dbh->do("ALTER table aqbudgets drop column budget_amount_sublevel;");
3178 print "Upgrade to $DBversion done (Drop column budget_amount_sublevel from aqbudgets)\n";
3179 SetVersion ($DBversion);
3182 $DBversion = "3.01.00.088";
3183 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3184 $dbh->do( qq# INSERT INTO `systempreferences` VALUES ('intranetbookbag','1','','If ON, enables display of Cart feature in the intranet','YesNo') #);
3186 print "Upgrade to $DBversion done (intranetbookbag syspref added)\n";
3187 SetVersion ($DBversion);
3190 $DBversion = "3.01.00.090";
3191 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3193 INSERT INTO `permissions` (`module_bit`, `code`, `description`) VALUES
3194 (16, 'execute_reports', 'Execute SQL reports'),
3195 (16, 'create_reports', 'Create SQL Reports')
3198 print "Upgrade to $DBversion done (granular permissions for guided reports added)\n";
3199 SetVersion ($DBversion);
3202 $DBversion = "3.01.00.091";
3203 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3205 UPDATE `systempreferences` SET `options` = 'holdings|serialcollection|subscriptions'
3206 WHERE `systempreferences`.`variable` = 'opacSerialDefaultTab' LIMIT 1
3209 print "Upgrade to $DBversion done (opac-detail default tag updated)\n";
3210 SetVersion ($DBversion);
3213 $DBversion = "3.01.00.092";
3214 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3215 if (C4::Context->preference("opaclanguages") =~ /fr/) {
3217 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('RoutingListAddReserves','1','Si activé, des reservations sont automatiquement créées pour chaque lecteur de la liste de circulation d''un numéro de périodique','','YesNo');
3221 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('RoutingListAddReserves','1','If ON the patrons on routing lists are automatically added to holds on the issue.','','YesNo');
3224 print "Upgrade to $DBversion done (Added RoutingListAddReserves syspref)\n";
3225 SetVersion ($DBversion);
3228 $DBversion = "3.01.00.093";
3229 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3231 ALTER TABLE biblioitems ADD INDEX issn_idx (issn);
3233 print "Upgrade to $DBversion done (added index to ISSN)\n";
3234 SetVersion ($DBversion);
3237 $DBversion = "3.01.00.094";
3238 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3240 ALTER TABLE aqbasketgroups ADD deliveryplace VARCHAR(10) default NULL, ADD deliverycomment VARCHAR(255) default NULL;
3243 print "Upgrade to $DBversion done (adding deliveryplace deliverycomment to basketgroups)\n";
3244 SetVersion ($DBversion);
3247 $DBversion = "3.01.00.095";
3248 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3250 ALTER TABLE items ADD stocknumber VARCHAR(32) DEFAULT NULL COMMENT "stores the inventory number";
3253 ALTER TABLE items ADD UNIQUE INDEX itemsstocknumberidx (stocknumber);
3256 ALTER TABLE deleteditems ADD stocknumber VARCHAR(32) DEFAULT NULL COMMENT "stores the inventory number of deleted items";
3259 ALTER TABLE deleteditems ADD UNIQUE INDEX deleteditemsstocknumberidx (stocknumber);
3261 if (C4::Context->preference('marcflavour') eq 'UNIMARC'){
3263 INSERT IGNORE INTO marc_subfield_structure (frameworkcode,tagfield, tagsubfield, tab, repeatable, mandatory,kohafield)
3264 SELECT DISTINCT (frameworkcode),995,"j",10,0,0,"items.stocknumber" from biblio_framework ;
3266 #Previously, copynumber was used as stocknumber
3268 UPDATE items set stocknumber=copynumber;
3271 UPDATE items set copynumber=NULL;
3274 print "Upgrade to $DBversion done (stocknumber field added)\n";
3275 SetVersion ($DBversion);
3278 $DBversion = "3.01.00.096";
3279 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3280 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OrderPdfTemplate','','Uploads a PDF template to use for printing baskets','NULL','Upload')");
3281 $dbh->do("UPDATE systempreferences SET variable='OrderPdfFormat' WHERE variable='pdfformat'");
3282 print "Upgrade to $DBversion done (PDF orders system preferences added and updated)\n";
3283 SetVersion ($DBversion);
3286 $DBversion = "3.01.00.097";
3287 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3289 ALTER TABLE aqbasketgroups ADD billingplace VARCHAR(10) NOT NULL AFTER deliverycomment;
3292 print "Upgrade to $DBversion done (Adding billingplace to aqbasketgroups)\n";
3293 SetVersion ($DBversion);
3296 $DBversion = "3.01.00.098";
3297 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3299 ALTER TABLE auth_subfield_structure MODIFY frameworkcode VARCHAR(10) NULL;
3302 print "Upgrade to $DBversion done (changing frameworkcode length in auth_subfield_structure)\n";
3303 SetVersion ($DBversion);
3306 $DBversion = "3.01.00.099";
3307 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3309 INSERT INTO `permissions` (`module_bit`, `code`, `description`) VALUES
3310 (9, 'edit_catalogue', 'Edit catalogue'),
3311 (9, 'fast_cataloging', 'Fast cataloging')
3314 print "Upgrade to $DBversion done (granular permissions for cataloging added)\n";
3315 SetVersion ($DBversion);
3318 $DBversion = "3.01.00.100";
3319 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3320 $dbh->do("INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('casAuthentication', '0', '', 'Enable or disable CAS authentication', 'YesNo'), ('casLogout', '1', '', 'Does a logout from Koha should also log out of CAS ?', 'YesNo'), ('casServerUrl', 'https://localhost:8443/cas', '', 'URL of the cas server', 'Free')");
3321 print "Upgrade to $DBversion done (added CAS authentication system preferences)\n";
3322 SetVersion ($DBversion);
3325 $DBversion = "3.01.00.101";
3326 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3328 "INSERT INTO systempreferences
3329 (variable, value, options, explanation, type)
3331 'OverdueNoticeBcc', '', '',
3332 'Email address to Bcc outgoing notices sent by email',
3335 print "Upgrade to $DBversion done (added OverdueNoticeBcc system preferences)\n";
3336 SetVersion ($DBversion);
3338 $DBversion = "3.01.00.102";
3339 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3341 "UPDATE permissions set description = 'Edit catalog (Modify bibliographic/holdings data)' where module_bit = 9 and code = 'edit_catalogue'"
3343 print "Upgrade to $DBversion done (fixed spelling error in edit_catalogue permission)\n";
3344 SetVersion ($DBversion);
3347 $DBversion = "3.01.00.103";
3348 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3349 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES (13, 'moderate_tags', 'Moderate patron tags')");
3350 print "Upgrade to $DBversion done (adding patron permissions for tags tool)\n";
3351 SetVersion ($DBversion);
3354 $DBversion = "3.01.00.104";
3355 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3357 my ($maninv_count, $borrnotes_count);
3358 eval { $maninv_count = $dbh->do("SELECT 1 FROM authorised_values WHERE category='MANUAL_INV'"); };
3359 if ($maninv_count == 0) {
3360 $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('MANUAL_INV','Copier Fees','.25')");
3362 eval { $borrnotes_count = $dbh->do("SELECT 1 FROM authorised_values WHERE category='BOR_NOTES'"); };
3363 if ($borrnotes_count == 0) {
3364 $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('BOR_NOTES','ADDR','Address Notes')");
3367 $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('LOC','CART','Book Cart')");
3368 $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('LOC','PROC','Processing Center')");
3370 print "Upgrade to $DBversion done ( add defaults to authorized values for MANUAL_INV and BOR_NOTES and add new default LOC authorized values for shelf to cart processing )\n";
3371 SetVersion ($DBversion);
3375 $DBversion = "3.01.00.105";
3376 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3378 CREATE TABLE `collections` (
3379 `colId` int(11) NOT NULL auto_increment,
3380 `colTitle` varchar(100) NOT NULL default '',
3381 `colDesc` text NOT NULL,
3382 `colBranchcode` varchar(4) default NULL COMMENT 'branchcode for branch where item should be held.',
3383 PRIMARY KEY (`colId`)
3384 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3388 CREATE TABLE `collections_tracking` (
3389 `ctId` int(11) NOT NULL auto_increment,
3390 `colId` int(11) NOT NULL default '0' COMMENT 'collections.colId',
3391 `itemnumber` int(11) NOT NULL default '0' COMMENT 'items.itemnumber',
3392 PRIMARY KEY (`ctId`)
3393 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3396 INSERT INTO permissions (module_bit, code, description)
3397 VALUES ( 13, 'rotating_collections', 'Manage Rotating collections')" );
3398 print "Upgrade to $DBversion done (added collection and collection_tracking tables for rotating collections functionality)\n";
3399 SetVersion ($DBversion);
3401 $DBversion = "3.01.00.106";
3402 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3403 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ( 'OpacAddMastheadLibraryPulldown', '0', '', 'Adds a pulldown menu to select the library to search on the opac masthead.', 'YesNo' )");
3404 print "Upgrade to $DBversion done (added OpacAddMastheadLibraryPulldown system preferences)\n";
3405 SetVersion ($DBversion);
3408 $DBversion = '3.01.00.107';
3409 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3410 my $upgrade_script = C4::Context->config("intranetdir") . "/installer/data/mysql/patroncards_upgrade.pl";
3411 system("perl $upgrade_script");
3412 print "Upgrade to $DBversion done (Migrated labels and patroncards tables and data to new schema.)\n";
3413 SetVersion ($DBversion);
3416 $DBversion = '3.01.00.108';
3417 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3419 ALTER TABLE `export_format` ADD `csv_separator` VARCHAR( 2 ) NOT NULL AFTER `marcfields` ,
3420 ADD `field_separator` VARCHAR( 2 ) NOT NULL AFTER `csv_separator` ,
3421 ADD `subfield_separator` VARCHAR( 2 ) NOT NULL AFTER `field_separator`
3423 print "Upgrade to $DBversion done (added separators for csv export)\n";
3424 SetVersion ($DBversion);
3427 $DBversion = "3.01.00.109";
3428 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3430 ALTER TABLE `export_format` ADD `encoding` VARCHAR(255) NOT NULL AFTER `subfield_separator`
3432 print "Upgrade to $DBversion done (added encoding for csv export)\n";
3433 SetVersion ($DBversion);
3436 $DBversion = '3.01.00.110';
3437 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3438 $dbh->do('ALTER TABLE `categories` ADD COLUMN `enrolmentperioddate` DATE NULL DEFAULT NULL AFTER `enrolmentperiod`');
3439 print "Upgrade to $DBversion done (Add enrolment period date support)\n";
3440 SetVersion ($DBversion);
3443 $DBversion = '3.01.00.111';
3444 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3445 print "Upgrade to $DBversion done (mark DBrev for 3.2-alpha release)\n";
3446 SetVersion ($DBversion);
3449 $DBversion = '3.01.00.112';
3450 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3451 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('SpineLabelShowPrintOnBibDetails', '0', '', 'If turned on, a \"Print Label\" link will appear for each item on the bib details page in the staff interface.', 'YesNo');");
3452 print "Upgrade to $DBversion done ( added Show Spine Label Printer on Bib Items Details preferences )\n";
3453 SetVersion ($DBversion);
3456 $DBversion = '3.01.00.113';
3457 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3458 my $value = C4::Context->preference("XSLTResultsDisplay");
3460 "INSERT INTO systempreferences (variable,value,type)
3461 VALUES('OPACXSLTResultsDisplay',?,'YesNo')", {}, $value ? 1 : 0);
3462 $value = C4::Context->preference("XSLTDetailsDisplay");
3464 "INSERT INTO systempreferences (variable,value,type)
3465 VALUES('OPACXSLTDetailsDisplay',?,'YesNo')", {}, $value ? 1 : 0);
3466 print "Upgrade to $DBversion done (added two new syspref: OPACXSLTResultsDisplay and OPACXSLTDetailDisplay). You may have to go in Admin > System preference to tweak XSLT related syspref both in OPAC and Search tabs.\n";
3467 SetVersion ($DBversion);
3470 $DBversion = '3.01.00.114';
3471 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3472 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('AutoSelfCheckAllowed', '0', 'For corporate and special libraries which want web-based self-check available from any PC without the need for a manual staff login. Most libraries will want to leave this turned off. If on, requires self-check ID and password to be entered in AutoSelfCheckID and AutoSelfCheckPass sysprefs.', '', 'YesNo')");
3473 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AutoSelfCheckID','','Staff ID with circulation rights to be used for automatic web-based self-check. Only applies if AutoSelfCheckAllowed syspref is turned on.','','free')");
3474 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AutoSelfCheckPass','','Password to be used for automatic web-based self-check. Only applies if AutoSelfCheckAllowed syspref is turned on.','','free')");
3475 print "Upgrade to $DBversion done ( Added AutoSelfCheckAllowed, AutoSelfCheckID, and AutoShelfCheckPass system preference )\n";
3476 SetVersion ($DBversion);
3479 $DBversion = '3.01.00.115';
3480 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3481 $dbh->do('UPDATE aqorders SET quantityreceived = 0 WHERE quantityreceived IS NULL');
3482 $dbh->do('ALTER TABLE aqorders MODIFY COLUMN quantityreceived smallint(6) NOT NULL DEFAULT 0');
3483 print "Upgrade to $DBversion done ( Default aqorders.quantityreceived to 0 )\n";
3484 SetVersion ($DBversion);
3487 $DBversion = '3.01.00.116';
3488 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3489 if (C4::Context->preference('OrderPdfFormat') eq 'pdfformat::example'){
3490 $dbh->do("UPDATE `systempreferences` set value='pdfformat::layout2pages' WHERE variable='OrderPdfFormat'");
3492 print "Upgrade to $DBversion done (corrected default OrderPdfFormat value if still set wrong )\n";