5 # This script checks for required updates to the database.
7 # Parts copyright Catalyst IT 2011
9 # Part of the Koha Library Software www.koha-community.org
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 # - Would also be a good idea to offer to do a backup at this time...
27 # NOTE: If you do something more than once in here, make it table driven.
29 # NOTE: Please keep the version in kohaversion.pl up-to-date!
43 use MARC::File::XML ( BinaryEncoding => 'utf8' );
45 # FIXME - The user might be installing a new database, so can't rely
46 # on /etc/koha.conf anyway.
53 %existingtables, # tables already in database
57 $type, $null, $key, $default, $extra,
58 $prefitem, # preference item in systempreferences table
65 my $dbh = C4::Context->dbh;
66 $|=1; # flushes output
68 local $dbh->{RaiseError} = 0;
70 # Record the version we are coming from
72 my $original_version = C4::Context->preference("Version");
74 # Deal with virtualshelves
75 my $DBversion = "3.00.00.001";
76 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
77 # update virtualshelves table to
79 $dbh->do("ALTER TABLE `bookshelf` RENAME `virtualshelves`");
80 $dbh->do("ALTER TABLE `shelfcontents` RENAME `virtualshelfcontents`");
81 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD `biblionumber` INT( 11 ) NOT NULL default '0' AFTER shelfnumber");
82 $dbh->do("UPDATE `virtualshelfcontents` SET biblionumber=(SELECT biblionumber FROM items WHERE items.itemnumber=virtualshelfcontents.itemnumber)");
83 # drop all foreign keys : otherwise, we can't drop itemnumber field.
84 DropAllForeignKeys('virtualshelfcontents');
85 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD KEY biblionumber (biblionumber)");
86 # create the new foreign keys (on biblionumber)
87 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `virtualshelfcontents_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE");
88 # re-create the foreign key on virtualshelf
89 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `shelfcontents_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE");
90 $dbh->do("ALTER TABLE `virtualshelfcontents` DROP `itemnumber`");
91 print "Upgrade to $DBversion done (virtualshelves)\n";
92 SetVersion ($DBversion);
96 $DBversion = "3.00.00.002";
97 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
98 $dbh->do("DROP TABLE sessions");
99 $dbh->do("CREATE TABLE `sessions` (
100 `id` varchar(32) NOT NULL,
101 `a_session` text NOT NULL,
102 UNIQUE KEY `id` (`id`)
103 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
104 print "Upgrade to $DBversion done (sessions uses CGI::session, new table structure for sessions)\n";
105 SetVersion ($DBversion);
109 $DBversion = "3.00.00.003";
110 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
111 if (C4::Context->preference("opaclanguages") eq "fr") {
112 $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')");
114 $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')");
116 print "Upgrade to $DBversion done (adding ReservesNeedReturns systempref, in circulation)\n";
117 SetVersion ($DBversion);
121 $DBversion = "3.00.00.004";
122 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
123 $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')");
124 print "Upgrade to $DBversion done (adding DebugLevel systempref, in 'Admin' tab)\n";
125 SetVersion ($DBversion);
128 $DBversion = "3.00.00.005";
129 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
130 $dbh->do("CREATE TABLE `tags` (
131 `entry` varchar(255) NOT NULL default '',
132 `weight` bigint(20) NOT NULL default 0,
133 PRIMARY KEY (`entry`)
134 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
136 $dbh->do("CREATE TABLE `nozebra` (
137 `server` varchar(20) NOT NULL,
138 `indexname` varchar(40) NOT NULL,
139 `value` varchar(250) NOT NULL,
140 `biblionumbers` longtext NOT NULL,
141 KEY `indexname` (`server`,`indexname`),
142 KEY `value` (`server`,`value`))
143 ENGINE=InnoDB DEFAULT CHARSET=utf8;
145 print "Upgrade to $DBversion done (adding tags and nozebra tables )\n";
146 SetVersion ($DBversion);
149 $DBversion = "3.00.00.006";
150 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
151 $dbh->do("UPDATE issues SET issuedate=timestamp WHERE issuedate='0000-00-00'");
152 print "Upgrade to $DBversion done (filled issues.issuedate with timestamp)\n";
153 SetVersion ($DBversion);
156 $DBversion = "3.00.00.007";
157 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
158 $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')");
159 print "Upgrade to $DBversion done (set SessionStorage variable)\n";
160 SetVersion ($DBversion);
163 $DBversion = "3.00.00.008";
164 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
165 $dbh->do("ALTER TABLE `biblio` ADD `datecreated` DATE NOT NULL AFTER `timestamp` ;");
166 $dbh->do("UPDATE biblio SET datecreated=timestamp");
167 print "Upgrade to $DBversion done (biblio creation date)\n";
168 SetVersion ($DBversion);
171 $DBversion = "3.00.00.009";
172 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
174 # Create backups of call number columns
175 # in case default migration needs to be customized
177 # UPGRADE NOTE: temp_upg_biblioitems_call_num should be dropped
178 # after call numbers have been transformed to the new structure
180 # Not bothering to do the same with deletedbiblioitems -- assume
181 # default is good enough.
182 $dbh->do("CREATE TABLE `temp_upg_biblioitems_call_num` AS
183 SELECT `biblioitemnumber`, `biblionumber`,
184 `classification`, `dewey`, `subclass`,
186 FROM `biblioitems`");
188 # biblioitems changes
189 $dbh->do("ALTER TABLE `biblioitems` CHANGE COLUMN `volumeddesc` `volumedesc` TEXT,
190 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
191 ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
192 ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
193 ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
194 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
195 ADD `totalissues` INT(10) AFTER `cn_sort`");
197 # default mapping of call number columns:
198 # cn_class = concatentation of classification + dewey,
199 # trimmed to fit -- assumes that most users do not
200 # populate both classification and dewey in a single record
202 # cn_source = left null
205 # After upgrade, cn_sort will have to be set based on whatever
206 # default call number scheme user sets as a preference. Misc
207 # script will be added at some point to do that.
209 $dbh->do("UPDATE `biblioitems`
210 SET cn_class = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
215 # Now drop the old call number columns
216 $dbh->do("ALTER TABLE `biblioitems` DROP COLUMN `classification`,
218 DROP COLUMN `subclass`,
219 DROP COLUMN `lcsort`,
220 DROP COLUMN `ccode`");
222 # deletedbiblio changes
223 $dbh->do("ALTER TABLE `deletedbiblio` ALTER COLUMN `frameworkcode` SET DEFAULT '',
225 ADD `datecreated` DATE NOT NULL AFTER `timestamp`");
226 $dbh->do("UPDATE deletedbiblio SET datecreated = timestamp");
228 # deletedbiblioitems changes
229 $dbh->do("ALTER TABLE `deletedbiblioitems`
230 MODIFY `publicationyear` TEXT,
231 CHANGE `volumeddesc` `volumedesc` TEXT,
232 MODIFY `collectiontitle` MEDIUMTEXT DEFAULT NULL AFTER `volumedesc`,
233 MODIFY `collectionissn` TEXT DEFAULT NULL AFTER `collectiontitle`,
234 MODIFY `collectionvolume` MEDIUMTEXT DEFAULT NULL AFTER `collectionissn`,
235 MODIFY `editionstatement` TEXT DEFAULT NULL AFTER `collectionvolume`,
236 MODIFY `editionresponsibility` TEXT DEFAULT NULL AFTER `editionstatement`,
237 MODIFY `place` VARCHAR(255) DEFAULT NULL AFTER `size`,
238 MODIFY `marc` LONGBLOB,
239 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `url`,
240 ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
241 ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
242 ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
243 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
244 ADD `totalissues` INT(10) AFTER `cn_sort`,
245 ADD `marcxml` LONGTEXT NOT NULL AFTER `totalissues`,
246 ADD KEY `isbn` (`isbn`),
247 ADD KEY `publishercode` (`publishercode`)
250 $dbh->do("UPDATE `deletedbiblioitems`
251 SET `cn_class` = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
252 `cn_item` = `subclass`,
255 $dbh->do("ALTER TABLE `deletedbiblioitems`
256 DROP COLUMN `classification`,
258 DROP COLUMN `subclass`,
259 DROP COLUMN `lcsort`,
263 # deleteditems changes
264 $dbh->do("ALTER TABLE `deleteditems`
265 MODIFY `barcode` VARCHAR(20) DEFAULT NULL,
266 MODIFY `price` DECIMAL(8,2) DEFAULT NULL,
267 MODIFY `replacementprice` DECIMAL(8,2) DEFAULT NULL,
269 MODIFY `itemcallnumber` VARCHAR(30) DEFAULT NULL AFTER `wthdrawn`,
270 MODIFY `holdingbranch` VARCHAR(10) DEFAULT NULL,
272 MODIFY `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP AFTER `paidfor`,
274 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
275 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
276 ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
277 ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
278 ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`,
279 MODIFY `marc` LONGBLOB AFTER `uri`,
281 DROP KEY `itembarcodeidx`,
282 DROP KEY `itembinoidx`,
283 DROP KEY `itembibnoidx`,
284 ADD UNIQUE KEY `delitembarcodeidx` (`barcode`),
285 ADD KEY `delitembinoidx` (`biblioitemnumber`),
286 ADD KEY `delitembibnoidx` (`biblionumber`),
287 ADD KEY `delhomebranch` (`homebranch`),
288 ADD KEY `delholdingbranch` (`holdingbranch`)");
289 $dbh->do("UPDATE deleteditems SET `ccode` = `itype`");
290 $dbh->do("ALTER TABLE deleteditems DROP `itype`");
291 $dbh->do("UPDATE `deleteditems` SET `cn_sort` = `itemcallnumber`");
294 $dbh->do("ALTER TABLE `items` ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
295 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
296 ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
297 ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
298 ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`
300 $dbh->do("ALTER TABLE `items`
301 DROP KEY `itembarcodeidx`,
302 ADD UNIQUE KEY `itembarcodeidx` (`barcode`)");
304 # map items.itype to items.ccode and
305 # set cn_sort to itemcallnumber -- as with biblioitems.cn_sort,
306 # will have to be subsequently updated per user's default
307 # classification scheme
308 $dbh->do("UPDATE `items` SET `cn_sort` = `itemcallnumber`,
311 $dbh->do("ALTER TABLE `items` DROP `cutterextra`,
314 print "Upgrade to $DBversion done (major changes to biblio, biblioitems, items, and deleted* versions of same\n";
315 SetVersion ($DBversion);
318 $DBversion = "3.00.00.010";
319 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
320 $dbh->do("CREATE INDEX `userid` ON borrowers (`userid`) ");
321 print "Upgrade to $DBversion done (userid index added)\n";
322 SetVersion ($DBversion);
325 $DBversion = "3.00.00.011";
326 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
327 $dbh->do("ALTER TABLE `branchcategories` CHANGE `categorycode` `categorycode` varchar(10) ");
328 $dbh->do("ALTER TABLE `branchcategories` CHANGE `categoryname` `categoryname` varchar(32) ");
329 $dbh->do("ALTER TABLE `branchcategories` ADD COLUMN `categorytype` varchar(16) ");
330 $dbh->do("UPDATE `branchcategories` SET `categorytype` = 'properties'");
331 $dbh->do("ALTER TABLE `branchrelations` CHANGE `categorycode` `categorycode` varchar(10) ");
332 print "Upgrade to $DBversion done (added branchcategory type)\n";
333 SetVersion ($DBversion);
336 $DBversion = "3.00.00.012";
337 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
338 $dbh->do("CREATE TABLE `class_sort_rules` (
339 `class_sort_rule` varchar(10) NOT NULL default '',
340 `description` mediumtext,
341 `sort_routine` varchar(30) NOT NULL default '',
342 PRIMARY KEY (`class_sort_rule`),
343 UNIQUE KEY `class_sort_rule_idx` (`class_sort_rule`)
344 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
345 $dbh->do("CREATE TABLE `class_sources` (
346 `cn_source` varchar(10) NOT NULL default '',
347 `description` mediumtext,
348 `used` tinyint(4) NOT NULL default 0,
349 `class_sort_rule` varchar(10) NOT NULL default '',
350 PRIMARY KEY (`cn_source`),
351 UNIQUE KEY `cn_source_idx` (`cn_source`),
352 KEY `used_idx` (`used`),
353 CONSTRAINT `class_source_ibfk_1` FOREIGN KEY (`class_sort_rule`)
354 REFERENCES `class_sort_rules` (`class_sort_rule`)
355 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
356 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type)
357 VALUES('DefaultClassificationSource','ddc',
358 'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.', NULL,'free')");
359 $dbh->do("INSERT INTO `class_sort_rules` (`class_sort_rule`, `description`, `sort_routine`) VALUES
360 ('dewey', 'Default filing rules for DDC', 'Dewey'),
361 ('lcc', 'Default filing rules for LCC', 'LCC'),
362 ('generic', 'Generic call number filing rules', 'Generic')");
363 $dbh->do("INSERT INTO `class_sources` (`cn_source`, `description`, `used`, `class_sort_rule`) VALUES
364 ('ddc', 'Dewey Decimal Classification', 1, 'dewey'),
365 ('lcc', 'Library of Congress Classification', 1, 'lcc'),
366 ('udc', 'Universal Decimal Classification', 0, 'generic'),
367 ('sudocs', 'SuDoc Classification (U.S. GPO)', 0, 'generic'),
368 ('z', 'Other/Generic Classification Scheme', 0, 'generic')");
369 print "Upgrade to $DBversion done (classification sources added)\n";
370 SetVersion ($DBversion);
373 $DBversion = "3.00.00.013";
374 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
375 $dbh->do("CREATE TABLE `import_batches` (
376 `import_batch_id` int(11) NOT NULL auto_increment,
377 `template_id` int(11) default NULL,
378 `branchcode` varchar(10) default NULL,
379 `num_biblios` int(11) NOT NULL default 0,
380 `num_items` int(11) NOT NULL default 0,
381 `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
382 `overlay_action` enum('replace', 'create_new', 'use_template') NOT NULL default 'create_new',
383 `import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging',
384 `batch_type` enum('batch', 'z3950') NOT NULL default 'batch',
385 `file_name` varchar(100),
386 `comments` mediumtext,
387 PRIMARY KEY (`import_batch_id`),
388 KEY `branchcode` (`branchcode`)
389 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
390 $dbh->do("CREATE TABLE `import_records` (
391 `import_record_id` int(11) NOT NULL auto_increment,
392 `import_batch_id` int(11) NOT NULL,
393 `branchcode` varchar(10) default NULL,
394 `record_sequence` int(11) NOT NULL default 0,
395 `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
396 `import_date` DATE default NULL,
397 `marc` longblob NOT NULL,
398 `marcxml` longtext NOT NULL,
399 `marcxml_old` longtext NOT NULL,
400 `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio',
401 `overlay_status` enum('no_match', 'auto_match', 'manual_match', 'match_applied') NOT NULL default 'no_match',
402 `status` enum('error', 'staged', 'imported', 'reverted', 'items_reverted') NOT NULL default 'staged',
403 `import_error` mediumtext,
404 `encoding` varchar(40) NOT NULL default '',
405 `z3950random` varchar(40) default NULL,
406 PRIMARY KEY (`import_record_id`),
407 CONSTRAINT `import_records_ifbk_1` FOREIGN KEY (`import_batch_id`)
408 REFERENCES `import_batches` (`import_batch_id`) ON DELETE CASCADE ON UPDATE CASCADE,
409 KEY `branchcode` (`branchcode`),
410 KEY `batch_sequence` (`import_batch_id`, `record_sequence`)
411 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
412 $dbh->do("CREATE TABLE `import_record_matches` (
413 `import_record_id` int(11) NOT NULL,
414 `candidate_match_id` int(11) NOT NULL,
415 `score` int(11) NOT NULL default 0,
416 CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`)
417 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
418 KEY `record_score` (`import_record_id`, `score`)
419 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
420 $dbh->do("CREATE TABLE `import_biblios` (
421 `import_record_id` int(11) NOT NULL,
422 `matched_biblionumber` int(11) default NULL,
423 `control_number` varchar(25) default NULL,
424 `original_source` varchar(25) default NULL,
425 `title` varchar(128) default NULL,
426 `author` varchar(80) default NULL,
427 `isbn` varchar(14) default NULL,
428 `issn` varchar(9) default NULL,
429 `has_items` tinyint(1) NOT NULL default 0,
430 CONSTRAINT `import_biblios_ibfk_1` FOREIGN KEY (`import_record_id`)
431 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
432 KEY `matched_biblionumber` (`matched_biblionumber`),
433 KEY `title` (`title`),
435 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
436 $dbh->do("CREATE TABLE `import_items` (
437 `import_items_id` int(11) NOT NULL auto_increment,
438 `import_record_id` int(11) NOT NULL,
439 `itemnumber` int(11) default NULL,
440 `branchcode` varchar(10) default NULL,
441 `status` enum('error', 'staged', 'imported', 'reverted') NOT NULL default 'staged',
442 `marcxml` longtext NOT NULL,
443 `import_error` mediumtext,
444 PRIMARY KEY (`import_items_id`),
445 CONSTRAINT `import_items_ibfk_1` FOREIGN KEY (`import_record_id`)
446 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
447 KEY `itemnumber` (`itemnumber`),
448 KEY `branchcode` (`branchcode`)
449 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
451 $dbh->do("INSERT INTO `import_batches`
452 (`overlay_action`, `import_status`, `batch_type`, `file_name`)
453 SELECT distinct 'create_new', 'staged', 'z3950', `file`
454 FROM `marc_breeding`");
456 $dbh->do("INSERT INTO `import_records`
457 (`import_batch_id`, `import_record_id`, `record_sequence`, `marc`, `record_type`, `status`,
458 `encoding`, `z3950random`, `marcxml`, `marcxml_old`)
459 SELECT `import_batch_id`, `id`, 1, `marc`, 'biblio', 'staged', `encoding`, `z3950random`, '', ''
461 JOIN `import_batches` ON (`file_name` = `file`)");
463 $dbh->do("INSERT INTO `import_biblios`
464 (`import_record_id`, `title`, `author`, `isbn`)
465 SELECT `import_record_id`, `title`, `author`, `isbn`
467 JOIN `import_records` ON (`import_record_id` = `id`)");
469 $dbh->do("UPDATE `import_batches`
470 SET `num_biblios` = (
472 FROM `import_records`
473 WHERE `import_batch_id` = `import_batches`.`import_batch_id`
476 $dbh->do("DROP TABLE `marc_breeding`");
478 print "Upgrade to $DBversion done (import_batches et al. added)\n";
479 SetVersion ($DBversion);
482 $DBversion = "3.00.00.014";
483 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
484 $dbh->do("ALTER TABLE subscription ADD lastbranch VARCHAR(4)");
485 print "Upgrade to $DBversion done (userid index added)\n";
486 SetVersion ($DBversion);
489 $DBversion = "3.00.00.015";
490 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
491 $dbh->do("CREATE TABLE `saved_sql` (
492 `id` int(11) NOT NULL auto_increment,
493 `borrowernumber` int(11) default NULL,
494 `date_created` datetime default NULL,
495 `last_modified` datetime default NULL,
497 `last_run` datetime default NULL,
498 `report_name` varchar(255) default NULL,
499 `type` varchar(255) default NULL,
502 KEY boridx (`borrowernumber`)
503 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
504 $dbh->do("CREATE TABLE `saved_reports` (
505 `id` int(11) NOT NULL auto_increment,
506 `report_id` int(11) default NULL,
508 `date_run` datetime default NULL,
510 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
511 print "Upgrade to $DBversion done (saved_sql and saved_reports added)\n";
512 SetVersion ($DBversion);
515 $DBversion = "3.00.00.016";
516 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
517 $dbh->do(" CREATE TABLE reports_dictionary (
518 id int(11) NOT NULL auto_increment,
519 name varchar(255) default NULL,
521 date_created datetime default NULL,
522 date_modified datetime default NULL,
524 area int(11) default NULL,
526 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
527 print "Upgrade to $DBversion done (reports_dictionary) added)\n";
528 SetVersion ($DBversion);
531 $DBversion = "3.00.00.017";
532 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
533 $dbh->do("ALTER TABLE action_logs DROP PRIMARY KEY");
534 $dbh->do("ALTER TABLE action_logs ADD KEY timestamp (timestamp,user)");
535 $dbh->do("ALTER TABLE action_logs ADD action_id INT(11) NOT NULL FIRST");
536 $dbh->do("UPDATE action_logs SET action_id = if (\@a, \@a:=\@a+1, \@a:=1)");
537 $dbh->do("ALTER TABLE action_logs MODIFY action_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY");
538 print "Upgrade to $DBversion done (added column to action_logs)\n";
539 SetVersion ($DBversion);
542 $DBversion = "3.00.00.018";
543 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
544 $dbh->do("ALTER TABLE `zebraqueue`
545 ADD `done` INT NOT NULL DEFAULT '0',
546 ADD `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ;
548 print "Upgrade to $DBversion done (adding timestamp and done columns to zebraque table to improve problem tracking) added)\n";
549 SetVersion ($DBversion);
552 $DBversion = "3.00.00.019";
553 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
554 $dbh->do("ALTER TABLE biblio MODIFY biblionumber INT(11) NOT NULL AUTO_INCREMENT");
555 $dbh->do("ALTER TABLE biblioitems MODIFY biblioitemnumber INT(11) NOT NULL AUTO_INCREMENT");
556 $dbh->do("ALTER TABLE items MODIFY itemnumber INT(11) NOT NULL AUTO_INCREMENT");
557 print "Upgrade to $DBversion done (made bib/item PKs auto_increment)\n";
558 SetVersion ($DBversion);
561 $DBversion = "3.00.00.020";
562 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
563 $dbh->do("ALTER TABLE deleteditems
564 DROP KEY `delitembarcodeidx`,
565 ADD KEY `delitembarcodeidx` (`barcode`)");
566 print "Upgrade to $DBversion done (dropped uniqueness of key on deleteditems.barcode)\n";
567 SetVersion ($DBversion);
570 $DBversion = "3.00.00.021";
571 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
572 $dbh->do("ALTER TABLE items CHANGE homebranch homebranch VARCHAR(10)");
573 $dbh->do("ALTER TABLE deleteditems CHANGE homebranch homebranch VARCHAR(10)");
574 $dbh->do("ALTER TABLE statistics CHANGE branch branch VARCHAR(10)");
575 $dbh->do("ALTER TABLE subscription CHANGE lastbranch lastbranch VARCHAR(10)");
576 print "Upgrade to $DBversion done (extended missed branchcode columns to 10 chars)\n";
577 SetVersion ($DBversion);
580 $DBversion = "3.00.00.022";
581 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
582 $dbh->do("ALTER TABLE items
583 ADD `damaged` tinyint(1) default NULL AFTER notforloan");
584 $dbh->do("ALTER TABLE deleteditems
585 ADD `damaged` tinyint(1) default NULL AFTER notforloan");
586 print "Upgrade to $DBversion done (adding damaged column to items table)\n";
587 SetVersion ($DBversion);
590 $DBversion = "3.00.00.023";
591 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
592 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
593 VALUES ('yuipath','http://yui.yahooapis.com/2.3.1/build','Insert the path to YUI libraries','','free')");
594 print "Upgrade to $DBversion done (adding new system preference for controlling YUI path)\n";
595 SetVersion ($DBversion);
597 $DBversion = "3.00.00.024";
598 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
599 $dbh->do("ALTER TABLE biblioitems CHANGE itemtype itemtype VARCHAR(10)");
600 print "Upgrade to $DBversion done (changing itemtype to (10))\n";
601 SetVersion ($DBversion);
604 $DBversion = "3.00.00.025";
605 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
606 $dbh->do("ALTER TABLE items ADD COLUMN itype VARCHAR(10)");
607 $dbh->do("ALTER TABLE deleteditems ADD COLUMN itype VARCHAR(10) AFTER uri");
608 if(C4::Context->preference('item-level_itypes')){
609 $dbh->do('update items,biblioitems set items.itype=biblioitems.itemtype where items.biblionumber=biblioitems.biblionumber and itype is null');
611 print "Upgrade to $DBversion done (reintroduce items.itype - fill from itemtype)\n ";
612 SetVersion ($DBversion);
615 $DBversion = "3.00.00.026";
616 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
617 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
618 VALUES ('HomeOrHoldingBranch','homebranch','homebranch|holdingbranch','With independent branches turned on this decides whether to check the items holdingbranch or homebranch at circulatilon','choice')");
619 print "Upgrade to $DBversion done (adding new system preference for choosing whether homebranch or holdingbranch is checked in circulation)\n";
620 SetVersion ($DBversion);
623 $DBversion = "3.00.00.027";
624 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
625 $dbh->do("CREATE TABLE `marc_matchers` (
626 `matcher_id` int(11) NOT NULL auto_increment,
627 `code` varchar(10) NOT NULL default '',
628 `description` varchar(255) NOT NULL default '',
629 `record_type` varchar(10) NOT NULL default 'biblio',
630 `threshold` int(11) NOT NULL default 0,
631 PRIMARY KEY (`matcher_id`),
633 KEY `record_type` (`record_type`)
634 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
635 $dbh->do("CREATE TABLE `matchpoints` (
636 `matcher_id` int(11) NOT NULL,
637 `matchpoint_id` int(11) NOT NULL auto_increment,
638 `search_index` varchar(30) NOT NULL default '',
639 `score` int(11) NOT NULL default 0,
640 PRIMARY KEY (`matchpoint_id`),
641 CONSTRAINT `matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
642 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE
643 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
644 $dbh->do("CREATE TABLE `matchpoint_components` (
645 `matchpoint_id` int(11) NOT NULL,
646 `matchpoint_component_id` int(11) NOT NULL auto_increment,
647 sequence int(11) NOT NULL default 0,
648 tag varchar(3) NOT NULL default '',
649 subfields varchar(40) NOT NULL default '',
650 offset int(4) NOT NULL default 0,
651 length int(4) NOT NULL default 0,
652 PRIMARY KEY (`matchpoint_component_id`),
653 KEY `by_sequence` (`matchpoint_id`, `sequence`),
654 CONSTRAINT `matchpoint_components_ifbk_1` FOREIGN KEY (`matchpoint_id`)
655 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
656 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
657 $dbh->do("CREATE TABLE `matchpoint_component_norms` (
658 `matchpoint_component_id` int(11) NOT NULL,
659 `sequence` int(11) NOT NULL default 0,
660 `norm_routine` varchar(50) NOT NULL default '',
661 KEY `matchpoint_component_norms` (`matchpoint_component_id`, `sequence`),
662 CONSTRAINT `matchpoint_component_norms_ifbk_1` FOREIGN KEY (`matchpoint_component_id`)
663 REFERENCES `matchpoint_components` (`matchpoint_component_id`) ON DELETE CASCADE ON UPDATE CASCADE
664 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
665 $dbh->do("CREATE TABLE `matcher_matchpoints` (
666 `matcher_id` int(11) NOT NULL,
667 `matchpoint_id` int(11) NOT NULL,
668 CONSTRAINT `matcher_matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
669 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
670 CONSTRAINT `matcher_matchpoints_ifbk_2` FOREIGN KEY (`matchpoint_id`)
671 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
672 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
673 $dbh->do("CREATE TABLE `matchchecks` (
674 `matcher_id` int(11) NOT NULL,
675 `matchcheck_id` int(11) NOT NULL auto_increment,
676 `source_matchpoint_id` int(11) NOT NULL,
677 `target_matchpoint_id` int(11) NOT NULL,
678 PRIMARY KEY (`matchcheck_id`),
679 CONSTRAINT `matcher_matchchecks_ifbk_1` FOREIGN KEY (`matcher_id`)
680 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
681 CONSTRAINT `matcher_matchchecks_ifbk_2` FOREIGN KEY (`source_matchpoint_id`)
682 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE,
683 CONSTRAINT `matcher_matchchecks_ifbk_3` FOREIGN KEY (`target_matchpoint_id`)
684 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
685 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
686 print "Upgrade to $DBversion done (added C4::Matcher serialization tables)\n ";
687 SetVersion ($DBversion);
690 $DBversion = "3.00.00.028";
691 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
692 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
693 VALUES ('canreservefromotherbranches','1','','With Independent branches on, can a user from one library reserve an item from another library','YesNo')");
694 print "Upgrade to $DBversion done (adding new system preference for changing reserve/holds behaviour with independent branches)\n";
695 SetVersion ($DBversion);
699 $DBversion = "3.00.00.029";
700 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
701 $dbh->do("ALTER TABLE `import_batches` ADD `matcher_id` int(11) NULL AFTER `import_batch_id`");
702 print "Upgrade to $DBversion done (adding matcher_id to import_batches)\n";
703 SetVersion ($DBversion);
706 $DBversion = "3.00.00.030";
707 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
709 CREATE TABLE services_throttle (
710 service_type varchar(10) NOT NULL default '',
711 service_count varchar(45) default NULL,
712 PRIMARY KEY (service_type)
713 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
715 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
716 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')");
717 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
718 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')");
719 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
720 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')");
721 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
722 VALUES ('XISBNDailyLimit',499,'','The xISBN Web service is free for non-commercial use when usage does not exceed 500 requests per day','free')");
723 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
724 VALUES ('PINESISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use PINES OISBN web service in the Editions tab on the detail pages.','YesNo')");
725 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
726 VALUES ('ThingISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use the ThingISBN web service in the Editions tab on the detail pages.','YesNo')");
727 print "Upgrade to $DBversion done (adding services throttle table and sysprefs for xISBN)\n";
728 SetVersion ($DBversion);
731 $DBversion = "3.00.00.031";
732 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
734 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryStemming',1,'If ON, enables query stemming',NULL,'YesNo')");
735 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryFuzzy',1,'If ON, enables fuzzy option for searches',NULL,'YesNo')");
736 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryWeightFields',1,'If ON, enables field weighting',NULL,'YesNo')");
737 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('WebBasedSelfCheck',0,'If ON, enables the web-based self-check system',NULL,'YesNo')");
738 $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')");
739 $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')");
740 $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')");
741 $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')");
742 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('defaultSortOrder',NULL,'Specify the default sort order','asc|dsc|az|za','Choice')");
743 $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')");
744 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACdefaultSortOrder',NULL,'Specify the default sort order','asc|dsc|za|az','Choice')");
745 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('staffClientBaseURL','','Specify the base URL of the staff client',NULL,'free')");
746 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('minPasswordLength',3,'Specify the minimum length of a patron/staff password',NULL,'free')");
747 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('noItemTypeImages',0,'If ON, disables item-type images',NULL,'YesNo')");
748 $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')");
749 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('holdCancelLength','','Specify how many days before a hold is canceled',NULL,'free')");
750 $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')");
751 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('finesMode','test','Choose the fines mode, test or production','test|production','Choice')");
752 $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')");
753 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeInputFilter','','If set, allows specification of a item barcode input filter','cuecat','Choice')");
754 $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')");
755 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('URLLinkText','','Text to display as the link anchor in the OPAC',NULL,'free')");
756 $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')");
757 $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')");
758 $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')");
759 $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')");
760 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACUserCSS',0,'Add CSS to be included in the OPAC',NULL,'free')");
762 print "Upgrade to $DBversion done (adding additional system preference)\n";
763 SetVersion ($DBversion);
766 $DBversion = "3.00.00.032";
767 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
768 $dbh->do("UPDATE `marc_subfield_structure` SET `kohafield` = 'items.wthdrawn' WHERE `kohafield` = 'items.withdrawn'");
769 print "Upgrade to $DBversion done (fixed MARC framework references to items.withdrawn)\n";
770 SetVersion ($DBversion);
773 $DBversion = "3.00.00.033";
774 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
775 $dbh->do("INSERT INTO `userflags` VALUES(17,'staffaccess','Modify login / permissions for staff users',0)");
776 print "Upgrade to $DBversion done (Adding permissions flag for staff member access modification. )\n";
777 SetVersion ($DBversion);
780 $DBversion = "3.00.00.034";
781 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
782 $dbh->do("ALTER TABLE `virtualshelves` ADD COLUMN `sortfield` VARCHAR(16) ");
783 print "Upgrade to $DBversion done (Adding sortfield for Virtual Shelves. )\n";
784 SetVersion ($DBversion);
787 $DBversion = "3.00.00.035";
788 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
789 $dbh->do("UPDATE marc_subfield_structure
790 SET authorised_value = 'cn_source'
791 WHERE kohafield IN ('items.cn_source', 'biblioitems.cn_source')
792 AND (authorised_value is NULL OR authorised_value = '')");
793 print "Upgrade to $DBversion done (MARC frameworks: make classification source a drop-down)\n";
794 SetVersion ($DBversion);
797 $DBversion = "3.00.00.036";
798 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
799 $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');");
800 print "Upgrade to $DBversion done (OPACItemsResultsDisplay systempreference added)\n";
801 SetVersion ($DBversion);
804 $DBversion = "3.00.00.037";
805 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
806 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactfirstname` varchar(255)");
807 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactsurname` varchar(255)");
808 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress1` varchar(255)");
809 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress2` varchar(255)");
810 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress3` varchar(255)");
811 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactzipcode` varchar(50)");
812 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactphone` varchar(50)");
813 print "Upgrade to $DBversion done (Adding Alternative Contact Person information to borrowers table)\n";
814 SetVersion ($DBversion);
817 $DBversion = "3.00.00.038";
818 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
819 $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'");
820 $dbh->do("DELETE FROM `systempreferences` WHERE variable='hideBiblioNumber'");
821 print "Upgrade to $DBversion done ('alter finesMode systempreference, remove superfluous syspref.')\n";
822 SetVersion ($DBversion);
825 $DBversion = "3.00.00.039";
826 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
827 $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')");
828 $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')");
829 $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')");
830 # $dbh->do("DELETE FROM `systempreferences` WHERE variable='HomeOrHoldingBranch'"); # Bug #2752
831 print "Upgrade to $DBversion done ('add circ sysprefs CircControl, finesCalendar, and uppercasesurnames, and delete HomeOrHoldingBranch.')\n";
832 SetVersion ($DBversion);
835 $DBversion = "3.00.00.040";
836 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
837 $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')");
838 $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')");
839 print "Upgrade to $DBversion done ('add circ sysprefs todaysIssuesDefaultSortOrder and previousIssuesDefaultSortOrder.')\n";
840 SetVersion ($DBversion);
844 $DBversion = "3.00.00.041";
845 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
846 # Strictly speaking it is not necessary to explicitly change
847 # NULL values to 0, because the ALTER TABLE statement will do that.
848 # However, setting them first avoids a warning.
849 $dbh->do("UPDATE items SET notforloan = 0 WHERE notforloan IS NULL");
850 $dbh->do("UPDATE items SET damaged = 0 WHERE damaged IS NULL");
851 $dbh->do("UPDATE items SET itemlost = 0 WHERE itemlost IS NULL");
852 $dbh->do("UPDATE items SET wthdrawn = 0 WHERE wthdrawn IS NULL");
853 $dbh->do("ALTER TABLE items
854 MODIFY notforloan tinyint(1) NOT NULL default 0,
855 MODIFY damaged tinyint(1) NOT NULL default 0,
856 MODIFY itemlost tinyint(1) NOT NULL default 0,
857 MODIFY wthdrawn tinyint(1) NOT NULL default 0");
858 $dbh->do("UPDATE deleteditems SET notforloan = 0 WHERE notforloan IS NULL");
859 $dbh->do("UPDATE deleteditems SET damaged = 0 WHERE damaged IS NULL");
860 $dbh->do("UPDATE deleteditems SET itemlost = 0 WHERE itemlost IS NULL");
861 $dbh->do("UPDATE deleteditems SET wthdrawn = 0 WHERE wthdrawn IS NULL");
862 $dbh->do("ALTER TABLE deleteditems
863 MODIFY notforloan tinyint(1) NOT NULL default 0,
864 MODIFY damaged tinyint(1) NOT NULL default 0,
865 MODIFY itemlost tinyint(1) NOT NULL default 0,
866 MODIFY wthdrawn tinyint(1) NOT NULL default 0");
867 print "Upgrade to $DBversion done (disallow NULL in several item status columns)\n";
868 SetVersion ($DBversion);
871 $DBversion = "3.00.00.04";
872 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
873 $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
874 print "Upgrade to $DBversion done (disallow NULL in aqbooksellers.name; part of fix for bug 1251)\n";
875 SetVersion ($DBversion);
878 $DBversion = "3.00.00.043";
879 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
880 $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");
881 print "Upgrade to $DBversion done (currency table: add symbol and timestamp columns)\n";
882 SetVersion ($DBversion);
885 $DBversion = "3.00.00.044";
886 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
887 $dbh->do("ALTER TABLE deletedborrowers
888 ADD `altcontactfirstname` varchar(255) default NULL,
889 ADD `altcontactsurname` varchar(255) default NULL,
890 ADD `altcontactaddress1` varchar(255) default NULL,
891 ADD `altcontactaddress2` varchar(255) default NULL,
892 ADD `altcontactaddress3` varchar(255) default NULL,
893 ADD `altcontactzipcode` varchar(50) default NULL,
894 ADD `altcontactphone` varchar(50) default NULL
896 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
897 ('OPACBaseURL',NULL,'Specify the Base URL of the OPAC, e.g., opac.mylibrary.com, the http:// will be added automatically by Koha.',NULL,'Free'),
898 ('language','en','Set the default language in the staff client.',NULL,'Languages'),
899 ('QueryAutoTruncate',1,'If ON, query truncation is enabled by default',NULL,'YesNo'),
900 ('QueryRemoveStopwords',0,'If ON, stopwords listed in the Administration area will be removed from queries',NULL,'YesNo')
902 print "Upgrade to $DBversion done (syncing deletedborrowers table with borrowers table)\n";
903 SetVersion ($DBversion);
906 #-- http://www.w3.org/International/articles/language-tags/
909 $DBversion = "3.00.00.045";
910 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
912 CREATE TABLE language_subtag_registry (
914 type varchar(25), -- language-script-region-variant-extension-privateuse
915 description varchar(25), -- only one of the possible descriptions for ease of reference, see language_descriptions for the complete list
917 KEY `subtag` (`subtag`)
918 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
920 #-- TODO: add suppress_scripts
921 #-- this maps three letter codes defined in iso639.2 back to their
922 #-- two letter equivilents in rfc4646 (LOC maintains iso639+)
923 $dbh->do("CREATE TABLE language_rfc4646_to_iso639 (
924 rfc4646_subtag varchar(25),
925 iso639_2_code varchar(25),
926 KEY `rfc4646_subtag` (`rfc4646_subtag`)
927 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
929 $dbh->do("CREATE TABLE language_descriptions (
933 description varchar(255),
935 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
937 #-- bi-directional support, keyed by script subcode
938 $dbh->do("CREATE TABLE language_script_bidi (
939 rfc4646_subtag varchar(25), -- script subtag, Arab, Hebr, etc.
940 bidi varchar(3), -- rtl ltr
941 KEY `rfc4646_subtag` (`rfc4646_subtag`)
942 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
944 #-- BIDI Stuff, Arabic and Hebrew
945 $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
946 VALUES( 'Arab', 'rtl')");
947 $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
948 VALUES( 'Hebr', 'rtl')");
950 #-- TODO: need to map language subtags to script subtags for detection
951 #-- of bidi when script is not specified (like ar, he)
952 $dbh->do("CREATE TABLE language_script_mapping (
953 language_subtag varchar(25),
954 script_subtag varchar(25),
955 KEY `language_subtag` (`language_subtag`)
956 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
958 #-- Default mappings between script and language subcodes
959 $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
960 VALUES( 'ar', 'Arab')");
961 $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
962 VALUES( 'he', 'Hebr')");
964 print "Upgrade to $DBversion done (adding language subtag registry and basic BiDi support NOTE: You should import the subtag registry SQL)\n";
965 SetVersion ($DBversion);
968 $DBversion = "3.00.00.046";
969 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
970 $dbh->do("ALTER TABLE `subscription` CHANGE `numberlength` `numberlength` int(11) default '0' ,
971 CHANGE `weeklength` `weeklength` int(11) default '0'");
972 $dbh->do("CREATE TABLE `serialitems` (`serialid` int(11) NOT NULL, `itemnumber` int(11) NOT NULL, UNIQUE KEY `serialididx` (`serialid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
973 $dbh->do("INSERT INTO `serialitems` SELECT `serialid`,`itemnumber` from serial where NOT ISNULL(itemnumber) && itemnumber <> '' && itemnumber NOT LIKE '%,%'");
974 print "Upgrade to $DBversion done (Add serialitems table to link serial issues to items. )\n";
975 SetVersion ($DBversion);
978 $DBversion = "3.00.00.047";
979 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
980 $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');");
981 print "Upgrade to $DBversion done ( Added OpacRenewalAllowed syspref )\n";
982 SetVersion ($DBversion);
985 $DBversion = "3.00.00.048";
986 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
987 $dbh->do("ALTER TABLE `items` ADD `more_subfields_xml` longtext default NULL AFTER `itype`");
988 print "Upgrade to $DBversion done (added items.more_subfields_xml)\n";
989 SetVersion ($DBversion);
992 $DBversion = "3.00.00.049";
993 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
994 $dbh->do("ALTER TABLE `z3950servers` ADD `encoding` text default NULL AFTER type ");
995 print "Upgrade to $DBversion done ( Added encoding field to z3950servers table )\n";
996 SetVersion ($DBversion);
999 $DBversion = "3.00.00.050";
1000 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1001 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHighlightedWords','0','If Set, query matched terms are highlighted in OPAC',NULL,'YesNo');");
1002 print "Upgrade to $DBversion done ( Added OpacHighlightedWords syspref )\n";
1003 SetVersion ($DBversion);
1006 $DBversion = "3.00.00.051";
1007 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1008 $dbh->do("UPDATE systempreferences SET explanation = 'Define the current theme for the OPAC interface.' WHERE variable = 'opacthemes';");
1009 print "Upgrade to $DBversion done ( Corrected opacthemes explanation. )\n";
1010 SetVersion ($DBversion);
1013 $DBversion = "3.00.00.052";
1014 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1015 $dbh->do("ALTER TABLE `deleteditems` ADD `more_subfields_xml` LONGTEXT DEFAULT NULL AFTER `itype`");
1016 print "Upgrade to $DBversion done ( Adding missing column to deleteditems table. )\n";
1017 SetVersion ($DBversion);
1020 $DBversion = "3.00.00.053";
1021 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1022 $dbh->do("CREATE TABLE `printers_profile` (
1023 `prof_id` int(4) NOT NULL auto_increment,
1024 `printername` varchar(40) NOT NULL,
1025 `tmpl_id` int(4) NOT NULL,
1026 `paper_bin` varchar(20) NOT NULL,
1027 `offset_horz` float default NULL,
1028 `offset_vert` float default NULL,
1029 `creep_horz` float default NULL,
1030 `creep_vert` float default NULL,
1031 `unit` char(20) NOT NULL default 'POINT',
1032 PRIMARY KEY (`prof_id`),
1033 UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
1034 CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
1035 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1036 $dbh->do("CREATE TABLE `labels_profile` (
1037 `tmpl_id` int(4) NOT NULL,
1038 `prof_id` int(4) NOT NULL,
1039 UNIQUE KEY `tmpl_id` (`tmpl_id`),
1040 UNIQUE KEY `prof_id` (`prof_id`)
1041 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1042 print "Upgrade to $DBversion done ( Printer Profile tables added )\n";
1043 SetVersion ($DBversion);
1046 $DBversion = "3.00.00.054";
1047 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1048 $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';");
1049 print "Upgrade to $DBversion done ( Added another barcode autogeneration sequence to barcode.pl. )\n";
1050 SetVersion ($DBversion);
1053 $DBversion = "3.00.00.055";
1054 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1055 $dbh->do("ALTER TABLE `zebraqueue` ADD KEY `zebraqueue_lookup` (`server`, `biblio_auth_number`, `operation`, `done`)");
1056 print "Upgrade to $DBversion done ( Added index on zebraqueue. )\n";
1057 SetVersion ($DBversion);
1059 $DBversion = "3.00.00.056";
1060 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1061 if (C4::Context->preference("marcflavour") eq 'UNIMARC') {
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 ('995', 'v', 'Note sur le N° de périodique','Note sur le N° de périodique', 0, 0, 'items.enumchron', 10, '', '', '', 0, 0, '', '', '', NULL) ");
1064 $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) ");
1066 $dbh->do("ALTER TABLE `items` ADD `enumchron` VARCHAR(80) DEFAULT NULL;");
1067 print "Upgrade to $DBversion done ( Added item.enumchron column, and framework map to 952h )\n";
1068 SetVersion ($DBversion);
1071 $DBversion = "3.00.00.057";
1072 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1073 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH','0','if ON, OAI-PMH server is enabled',NULL,'YesNo');");
1074 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:archiveID','KOHA-OAI-TEST','OAI-PMH archive identification',NULL,'Free');");
1075 $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');");
1076 $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');");
1077 $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');");
1078 SetVersion ($DBversion);
1081 $DBversion = "3.00.00.058";
1082 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1083 $dbh->do("ALTER TABLE `opac_news`
1084 CHANGE `lang` `lang` VARCHAR( 25 )
1086 COLLATE utf8_general_ci
1087 NOT NULL default ''");
1088 print "Upgrade to $DBversion done ( lang field in opac_news made longer )\n";
1089 SetVersion ($DBversion);
1092 $DBversion = "3.00.00.059";
1093 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1095 $dbh->do("CREATE TABLE IF NOT EXISTS `labels_templates` (
1096 `tmpl_id` int(4) NOT NULL auto_increment,
1097 `tmpl_code` char(100) default '',
1098 `tmpl_desc` char(100) default '',
1099 `page_width` float default '0',
1100 `page_height` float default '0',
1101 `label_width` float default '0',
1102 `label_height` float default '0',
1103 `topmargin` float default '0',
1104 `leftmargin` float default '0',
1105 `cols` int(2) default '0',
1106 `rows` int(2) default '0',
1107 `colgap` float default '0',
1108 `rowgap` float default '0',
1109 `active` int(1) default NULL,
1110 `units` char(20) default 'PX',
1111 `fontsize` int(4) NOT NULL default '3',
1112 PRIMARY KEY (`tmpl_id`)
1113 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1114 $dbh->do("CREATE TABLE IF NOT EXISTS `printers_profile` (
1115 `prof_id` int(4) NOT NULL auto_increment,
1116 `printername` varchar(40) NOT NULL,
1117 `tmpl_id` int(4) NOT NULL,
1118 `paper_bin` varchar(20) NOT NULL,
1119 `offset_horz` float default NULL,
1120 `offset_vert` float default NULL,
1121 `creep_horz` float default NULL,
1122 `creep_vert` float default NULL,
1123 `unit` char(20) NOT NULL default 'POINT',
1124 PRIMARY KEY (`prof_id`),
1125 UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
1126 CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
1127 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1128 print "Upgrade to $DBversion done ( Added labels_templates table if it did not exist. )\n";
1129 SetVersion ($DBversion);
1132 $DBversion = "3.00.00.060";
1133 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1134 $dbh->do("CREATE TABLE IF NOT EXISTS `patronimage` (
1135 `cardnumber` varchar(16) NOT NULL,
1136 `mimetype` varchar(15) NOT NULL,
1137 `imagefile` mediumblob NOT NULL,
1138 PRIMARY KEY (`cardnumber`),
1139 CONSTRAINT `patronimage_fk1` FOREIGN KEY (`cardnumber`) REFERENCES `borrowers` (`cardnumber`) ON DELETE CASCADE ON UPDATE CASCADE
1140 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1141 print "Upgrade to $DBversion done ( Added patronimage table. )\n";
1142 SetVersion ($DBversion);
1145 $DBversion = "3.00.00.061";
1146 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1147 $dbh->do("ALTER TABLE labels_templates ADD COLUMN font char(10) NOT NULL DEFAULT 'TR';");
1148 print "Upgrade to $DBversion done ( Added font column to labels_templates )\n";
1149 SetVersion ($DBversion);
1152 $DBversion = "3.00.00.062";
1153 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1154 $dbh->do("CREATE TABLE `old_issues` (
1155 `borrowernumber` int(11) default NULL,
1156 `itemnumber` int(11) default NULL,
1157 `date_due` date default NULL,
1158 `branchcode` varchar(10) default NULL,
1159 `issuingbranch` varchar(18) default NULL,
1160 `returndate` date default NULL,
1161 `lastreneweddate` date default NULL,
1162 `return` varchar(4) default NULL,
1163 `renewals` tinyint(4) default NULL,
1164 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1165 `issuedate` date default NULL,
1166 KEY `old_issuesborridx` (`borrowernumber`),
1167 KEY `old_issuesitemidx` (`itemnumber`),
1168 KEY `old_bordate` (`borrowernumber`,`timestamp`),
1169 CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1170 ON DELETE SET NULL ON UPDATE SET NULL,
1171 CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1172 ON DELETE SET NULL ON UPDATE SET NULL
1173 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1174 $dbh->do("CREATE TABLE `old_reserves` (
1175 `borrowernumber` int(11) default NULL,
1176 `reservedate` date default NULL,
1177 `biblionumber` int(11) default NULL,
1178 `constrainttype` varchar(1) default NULL,
1179 `branchcode` varchar(10) default NULL,
1180 `notificationdate` date default NULL,
1181 `reminderdate` date default NULL,
1182 `cancellationdate` date default NULL,
1183 `reservenotes` mediumtext,
1184 `priority` smallint(6) default NULL,
1185 `found` varchar(1) default NULL,
1186 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1187 `itemnumber` int(11) default NULL,
1188 `waitingdate` date default NULL,
1189 KEY `old_reserves_borrowernumber` (`borrowernumber`),
1190 KEY `old_reserves_biblionumber` (`biblionumber`),
1191 KEY `old_reserves_itemnumber` (`itemnumber`),
1192 KEY `old_reserves_branchcode` (`branchcode`),
1193 CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1194 ON DELETE SET NULL ON UPDATE SET NULL,
1195 CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
1196 ON DELETE SET NULL ON UPDATE SET NULL,
1197 CONSTRAINT `old_reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1198 ON DELETE SET NULL ON UPDATE SET NULL
1199 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1201 # move closed transactions to old_* tables
1202 $dbh->do("INSERT INTO old_issues SELECT * FROM issues WHERE returndate IS NOT NULL");
1203 $dbh->do("DELETE FROM issues WHERE returndate IS NOT NULL");
1204 $dbh->do("INSERT INTO old_reserves SELECT * FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
1205 $dbh->do("DELETE FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
1207 print "Upgrade to $DBversion done ( Added old_issues and old_reserves tables )\n";
1208 SetVersion ($DBversion);
1211 $DBversion = "3.00.00.063";
1212 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1213 $dbh->do("ALTER TABLE deleteditems
1214 CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT DEFAULT NULL,
1215 ADD COLUMN enumchron VARCHAR(80) DEFAULT NULL AFTER more_subfields_xml,
1216 ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
1217 $dbh->do("ALTER TABLE items
1218 CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT,
1219 ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
1220 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";
1221 SetVersion ($DBversion);
1224 $DBversion = "3.00.00.064";
1225 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1226 $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');");
1227 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSAccessKeyID','','See: http://aws.amazon.com','','free');");
1228 $dbh->do("DELETE FROM `systempreferences` WHERE variable='AmazonDevKey';");
1229 $dbh->do("DELETE FROM `systempreferences` WHERE variable='XISBNAmazonSimilarItems';");
1230 $dbh->do("DELETE FROM `systempreferences` WHERE variable='OPACXISBNAmazonSimilarItems';");
1231 print "Upgrade to $DBversion done (IMPORTANT: Upgrading to Amazon.com Associates Web Service 4.0 ) \n";
1232 SetVersion ($DBversion);
1235 $DBversion = "3.00.00.065";
1236 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1237 $dbh->do("CREATE TABLE `patroncards` (
1238 `cardid` int(11) NOT NULL auto_increment,
1239 `batch_id` varchar(10) NOT NULL default '1',
1240 `borrowernumber` int(11) NOT NULL,
1241 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1242 PRIMARY KEY (`cardid`),
1243 KEY `patroncards_ibfk_1` (`borrowernumber`),
1244 CONSTRAINT `patroncards_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1245 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1246 print "Upgrade to $DBversion done (Adding patroncards table for patroncards generation feature. ) \n";
1247 SetVersion ($DBversion);
1250 $DBversion = "3.00.00.066";
1251 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1252 $dbh->do("ALTER TABLE `virtualshelfcontents` MODIFY `dateadded` timestamp NOT NULL
1253 DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;
1255 print "Upgrade to $DBversion done (fix for bug 1873: virtualshelfcontents dateadded column empty. ) \n";
1256 SetVersion ($DBversion);
1259 $DBversion = "3.00.00.067";
1260 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1261 $dbh->do("UPDATE systempreferences SET explanation = 'Enable patron images for the Staff Client', type = 'YesNo' WHERE variable = 'patronimages'");
1262 print "Upgrade to $DBversion done (Updating patronimages syspref to reflect current kohastructure.sql. ) \n";
1263 SetVersion ($DBversion);
1266 $DBversion = "3.00.00.068";
1267 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1268 $dbh->do("CREATE TABLE `permissions` (
1269 `module_bit` int(11) NOT NULL DEFAULT 0,
1270 `code` varchar(30) DEFAULT NULL,
1271 `description` varchar(255) DEFAULT NULL,
1272 PRIMARY KEY (`module_bit`, `code`),
1273 CONSTRAINT `permissions_ibfk_1` FOREIGN KEY (`module_bit`) REFERENCES `userflags` (`bit`)
1274 ON DELETE CASCADE ON UPDATE CASCADE
1275 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1276 $dbh->do("CREATE TABLE `user_permissions` (
1277 `borrowernumber` int(11) NOT NULL DEFAULT 0,
1278 `module_bit` int(11) NOT NULL DEFAULT 0,
1279 `code` varchar(30) DEFAULT NULL,
1280 CONSTRAINT `user_permissions_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1281 ON DELETE CASCADE ON UPDATE CASCADE,
1282 CONSTRAINT `user_permissions_ibfk_2` FOREIGN KEY (`module_bit`, `code`)
1283 REFERENCES `permissions` (`module_bit`, `code`)
1284 ON DELETE CASCADE ON UPDATE CASCADE
1285 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1287 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES
1288 (13, 'edit_news', 'Write news for the OPAC and staff interfaces'),
1289 (13, 'label_creator', 'Create printable labels and barcodes from catalog and patron data'),
1290 (13, 'edit_calendar', 'Define days when the library is closed'),
1291 (13, 'moderate_comments', 'Moderate patron comments'),
1292 (13, 'edit_notices', 'Define notices'),
1293 (13, 'edit_notice_status_triggers', 'Set notice/status triggers for overdue items'),
1294 (13, 'view_system_logs', 'Browse the system logs'),
1295 (13, 'inventory', 'Perform inventory (stocktaking) of your catalogue'),
1296 (13, 'stage_marc_import', 'Stage MARC records into the reservoir'),
1297 (13, 'manage_staged_marc', 'Managed staged MARC records, including completing and reversing imports'),
1298 (13, 'export_catalog', 'Export bibliographic and holdings data'),
1299 (13, 'import_patrons', 'Import patron data'),
1300 (13, 'delete_anonymize_patrons', 'Delete old borrowers and anonymize circulation history (deletes borrower reading history)'),
1301 (13, 'batch_upload_patron_images', 'Upload patron images in batch or one at a time'),
1302 (13, 'schedule_tasks', 'Schedule tasks to run')");
1304 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('GranularPermissions','0','Use detailed staff user permissions',NULL,'YesNo')");
1306 print "Upgrade to $DBversion done (adding permissions and user_permissions tables and GranularPermissions syspref) \n";
1307 SetVersion ($DBversion);
1309 $DBversion = "3.00.00.069";
1310 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1311 $dbh->do("ALTER TABLE labels_conf CHANGE COLUMN class classification int(1) DEFAULT NULL;");
1312 print "Upgrade to $DBversion done ( Correcting columname in labels_conf )\n";
1313 SetVersion ($DBversion);
1316 $DBversion = "3.00.00.070";
1317 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1318 $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='yuipath'");
1320 my ($value) = $sth->fetchrow;
1321 $value =~ s/2.3.1/2.5.1/;
1322 $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='yuipath';");
1323 print "Update yuipath syspref to 2.5.1 if necessary\n";
1324 SetVersion ($DBversion);
1327 $DBversion = "3.00.00.071";
1328 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1329 $dbh->do(" ALTER TABLE `subscription` ADD `serialsadditems` TINYINT( 1 ) NOT NULL DEFAULT '0';");
1330 # fill the new field with the previous systempreference value, then drop the syspref
1331 my $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='serialsadditems'");
1333 my ($serialsadditems) = $sth->fetchrow();
1334 $dbh->do("UPDATE subscription SET serialsadditems=$serialsadditems");
1335 $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
1336 print "Upgrade to $DBversion done ( moving serialsadditems from syspref to subscription )\n";
1337 SetVersion ($DBversion);
1340 $DBversion = "3.00.00.072";
1341 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1342 $dbh->do("ALTER TABLE labels_conf ADD COLUMN formatstring mediumtext DEFAULT NULL AFTER printingtype");
1343 print "Upgrade to $DBversion done ( Adding format string to labels generator. )\n";
1344 SetVersion ($DBversion);
1347 $DBversion = "3.00.00.073";
1348 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1349 $dbh->do("DROP TABLE IF EXISTS `tags_all`;");
1351 CREATE TABLE `tags_all` (
1352 `tag_id` int(11) NOT NULL auto_increment,
1353 `borrowernumber` int(11) NOT NULL,
1354 `biblionumber` int(11) NOT NULL,
1355 `term` varchar(255) NOT NULL,
1356 `language` int(4) default NULL,
1357 `date_created` datetime NOT NULL,
1358 PRIMARY KEY (`tag_id`),
1359 KEY `tags_borrowers_fk_1` (`borrowernumber`),
1360 KEY `tags_biblionumber_fk_1` (`biblionumber`),
1361 CONSTRAINT `tags_borrowers_fk_1` FOREIGN KEY (`borrowernumber`)
1362 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1363 CONSTRAINT `tags_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
1364 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1365 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1367 $dbh->do("DROP TABLE IF EXISTS `tags_approval`;");
1369 CREATE TABLE `tags_approval` (
1370 `term` varchar(255) NOT NULL,
1371 `approved` int(1) NOT NULL default '0',
1372 `date_approved` datetime default NULL,
1373 `approved_by` int(11) default NULL,
1374 `weight_total` int(9) NOT NULL default '1',
1375 PRIMARY KEY (`term`),
1376 KEY `tags_approval_borrowers_fk_1` (`approved_by`),
1377 CONSTRAINT `tags_approval_borrowers_fk_1` FOREIGN KEY (`approved_by`)
1378 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1379 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1381 $dbh->do("DROP TABLE IF EXISTS `tags_index`;");
1383 CREATE TABLE `tags_index` (
1384 `term` varchar(255) NOT NULL,
1385 `biblionumber` int(11) NOT NULL,
1386 `weight` int(9) NOT NULL default '1',
1387 PRIMARY KEY (`term`,`biblionumber`),
1388 KEY `tags_index_biblionumber_fk_1` (`biblionumber`),
1389 CONSTRAINT `tags_index_term_fk_1` FOREIGN KEY (`term`)
1390 REFERENCES `tags_approval` (`term`) ON DELETE CASCADE ON UPDATE CASCADE,
1391 CONSTRAINT `tags_index_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
1392 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1393 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1396 INSERT INTO `systempreferences` VALUES
1397 ('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=',''),
1398 ('BakerTaylorEnabled','0','','Enable or disable all Baker & Taylor features.','YesNo'),
1399 ('BakerTaylorPassword','','','Baker & Taylor Password for Content Cafe (external content)','Textarea'),
1400 ('BakerTaylorUsername','','','Baker & Taylor Username for Content Cafe (external content)','Textarea'),
1401 ('TagsEnabled','1','','Enables or disables all tagging features. This is the main switch for tags.','YesNo'),
1402 ('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.',''),
1403 ('TagsInputOnDetail','1','','Allow users to input tags from the detail page.', 'YesNo'),
1404 ('TagsInputOnList', '0','','Allow users to input tags from the search results list.', 'YesNo'),
1405 ('TagsModeration', NULL,'','Require tags from patrons to be approved before becoming visible.','YesNo'),
1406 ('TagsShowOnDetail','10','','Number of tags to display on detail page. 0 is off.', 'Integer'),
1407 ('TagsShowOnList', '6','','Number of tags to display on search results list. 0 is off.','Integer')
1409 print "Upgrade to $DBversion done (Baker/Taylor,Tags: sysprefs and tables (tags_all, tags_index, tags_approval)) \n";
1410 SetVersion ($DBversion);
1413 $DBversion = "3.00.00.074";
1414 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1415 $dbh->do( q(update itemtypes set imageurl = concat( 'npl/', imageurl )
1416 where imageurl not like 'http%'
1417 and imageurl is not NULL
1418 and imageurl != '') );
1419 print "Upgrade to $DBversion done (updating imagetype.imageurls to reflect new icon locations.)\n";
1420 SetVersion ($DBversion);
1423 $DBversion = "3.00.00.075";
1424 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1425 $dbh->do( q(alter table authorised_values add imageurl varchar(200) default NULL) );
1426 print "Upgrade to $DBversion done (adding imageurl field to authorised_values table)\n";
1427 SetVersion ($DBversion);
1430 $DBversion = "3.00.00.076";
1431 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1432 $dbh->do("ALTER TABLE import_batches
1433 ADD COLUMN nomatch_action enum('create_new', 'ignore') NOT NULL default 'create_new' AFTER overlay_action");
1434 $dbh->do("ALTER TABLE import_batches
1435 ADD COLUMN item_action enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore')
1436 NOT NULL default 'always_add' AFTER nomatch_action");
1437 $dbh->do("ALTER TABLE import_batches
1438 MODIFY overlay_action enum('replace', 'create_new', 'use_template', 'ignore')
1439 NOT NULL default 'create_new'");
1440 $dbh->do("ALTER TABLE import_records
1441 MODIFY status enum('error', 'staged', 'imported', 'reverted', 'items_reverted',
1442 'ignored') NOT NULL default 'staged'");
1443 $dbh->do("ALTER TABLE import_items
1444 MODIFY status enum('error', 'staged', 'imported', 'reverted', 'ignored') NOT NULL default 'staged'");
1446 print "Upgrade to $DBversion done (changes to import_batches and import_records)\n";
1447 SetVersion ($DBversion);
1450 $DBversion = "3.00.00.077";
1451 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1452 # drop these tables only if they exist and none of them are empty
1453 # these tables are not defined in the packaged 2.2.9, but since it is believed
1454 # that at least one library may be using them in a post-2.2.9 but pre-3.0 Koha,
1455 # some care is taken.
1456 my ($print_error) = $dbh->{PrintError};
1457 $dbh->{PrintError} = 0;
1458 my ($raise_error) = $dbh->{RaiseError};
1459 $dbh->{RaiseError} = 1;
1463 eval { $count = $dbh->do("SELECT 1 FROM categorytable"); };
1467 eval { $count = $dbh->do("SELECT 1 FROM mediatypetable"); };
1471 eval { $count = $dbh->do("SELECT 1 FROM subcategorytable"); };
1477 $dbh->do("DROP TABLE IF EXISTS `categorytable`");
1478 $dbh->do("DROP TABLE IF EXISTS `mediatypetable`");
1479 $dbh->do("DROP TABLE IF EXISTS `subcategorytable`");
1482 $dbh->{PrintError} = $print_error;
1483 $dbh->{RaiseError} = $raise_error;
1484 print "Upgrade to $DBversion done (drop categorytable, subcategorytable, and mediatypetable)\n";
1485 SetVersion ($DBversion);
1488 $DBversion = "3.00.00.078";
1489 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1490 my ($print_error) = $dbh->{PrintError};
1491 $dbh->{PrintError} = 0;
1493 unless ($dbh->do("SELECT 1 FROM browser")) {
1494 $dbh->{PrintError} = $print_error;
1495 $dbh->do("CREATE TABLE `browser` (
1496 `level` int(11) NOT NULL,
1497 `classification` varchar(20) NOT NULL,
1498 `description` varchar(255) NOT NULL,
1499 `number` bigint(20) NOT NULL,
1500 `endnode` tinyint(4) NOT NULL
1501 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1503 $dbh->{PrintError} = $print_error;
1504 print "Upgrade to $DBversion done (add browser table if not already present)\n";
1505 SetVersion ($DBversion);
1508 $DBversion = "3.00.00.079";
1509 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1510 my ($print_error) = $dbh->{PrintError};
1511 $dbh->{PrintError} = 0;
1513 $dbh->do("INSERT INTO `systempreferences` (variable, value,options,type, explanation)VALUES
1514 ('AddPatronLists','categorycode','categorycode|category_type','Choice','Allow user to choose what list to pick up from when adding patrons')");
1515 print "Upgrade to $DBversion done (add browser table if not already present)\n";
1516 SetVersion ($DBversion);
1519 $DBversion = "3.00.00.080";
1520 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1521 $dbh->do("ALTER TABLE subscription CHANGE monthlength monthlength int(11) default '0'");
1522 $dbh->do("ALTER TABLE deleteditems MODIFY marc LONGBLOB AFTER copynumber");
1523 $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
1524 print "Upgrade to $DBversion done (catch up on DB schema changes since alpha and beta)\n";
1525 SetVersion ($DBversion);
1528 $DBversion = "3.00.00.081";
1529 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1530 $dbh->do("CREATE TABLE `borrower_attribute_types` (
1531 `code` varchar(10) NOT NULL,
1532 `description` varchar(255) NOT NULL,
1533 `repeatable` tinyint(1) NOT NULL default 0,
1534 `unique_id` tinyint(1) NOT NULL default 0,
1535 `opac_display` tinyint(1) NOT NULL default 0,
1536 `password_allowed` tinyint(1) NOT NULL default 0,
1537 `staff_searchable` tinyint(1) NOT NULL default 0,
1538 `authorised_value_category` varchar(10) default NULL,
1539 PRIMARY KEY (`code`)
1540 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1541 $dbh->do("CREATE TABLE `borrower_attributes` (
1542 `borrowernumber` int(11) NOT NULL,
1543 `code` varchar(10) NOT NULL,
1544 `attribute` varchar(30) default NULL,
1545 `password` varchar(30) default NULL,
1546 KEY `borrowernumber` (`borrowernumber`),
1547 KEY `code_attribute` (`code`, `attribute`),
1548 CONSTRAINT `borrower_attributes_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1549 ON DELETE CASCADE ON UPDATE CASCADE,
1550 CONSTRAINT `borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`)
1551 ON DELETE CASCADE ON UPDATE CASCADE
1552 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1553 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ExtendedPatronAttributes','0','Use extended patron IDs and attributes',NULL,'YesNo')");
1554 print "Upgrade to $DBversion done (added borrower_attributes and borrower_attribute_types)\n";
1555 SetVersion ($DBversion);
1558 $DBversion = "3.00.00.082";
1559 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1560 $dbh->do( q(alter table accountlines add column lastincrement decimal(28,6) default NULL) );
1561 print "Upgrade to $DBversion done (adding lastincrement column to accountlines table)\n";
1562 SetVersion ($DBversion);
1565 $DBversion = "3.00.00.083";
1566 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1567 $dbh->do( qq(UPDATE systempreferences SET value='local' where variable='yuipath' and value like "%/intranet-tmpl/prog/%"));
1568 print "Upgrade to $DBversion done (Changing yuipath behaviour in managing a local value)\n";
1569 SetVersion ($DBversion);
1571 $DBversion = "3.00.00.084";
1572 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1573 $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')");
1574 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GoogleJackets','0','if ON, displays jacket covers from Google Books API',NULL,'YesNo')");
1575 print "Upgrade to $DBversion done (add new sysprefs)\n";
1576 SetVersion ($DBversion);
1579 $DBversion = "3.00.00.085";
1580 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1581 if (C4::Context->preference("marcflavour") eq 'MARC21') {
1582 $dbh->do("UPDATE marc_subfield_structure SET tab = 0 WHERE tab = 9 AND tagfield = '037'");
1583 $dbh->do("UPDATE marc_subfield_structure SET tab = 1 WHERE tab = 6 AND tagfield in ('100', '110', '111', '130')");
1584 $dbh->do("UPDATE marc_subfield_structure SET tab = 2 WHERE tab = 6 AND tagfield in ('240', '243')");
1585 $dbh->do("UPDATE marc_subfield_structure SET tab = 4 WHERE tab = 6 AND tagfield in ('400', '410', '411', '440')");
1586 $dbh->do("UPDATE marc_subfield_structure SET tab = 5 WHERE tab = 9 AND tagfield = '584'");
1587 $dbh->do("UPDATE marc_subfield_structure SET tab = 7 WHERE tab = -6 AND tagfield = '760'");
1589 print "Upgrade to $DBversion done (move editing tab of various MARC21 subfields)\n";
1590 SetVersion ($DBversion);
1593 $DBversion = "3.00.00.086";
1594 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1596 "CREATE TABLE `tmp_holdsqueue` (
1597 `biblionumber` int(11) default NULL,
1598 `itemnumber` int(11) default NULL,
1599 `barcode` varchar(20) default NULL,
1600 `surname` mediumtext NOT NULL,
1603 `borrowernumber` int(11) NOT NULL,
1604 `cardnumber` varchar(16) default NULL,
1605 `reservedate` date default NULL,
1607 `itemcallnumber` varchar(30) default NULL,
1608 `holdingbranch` varchar(10) default NULL,
1609 `pickbranch` varchar(10) default NULL,
1611 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1613 $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')");
1614 $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')");
1616 print "Upgrade to $DBversion done (Table structure for table `tmp_holdsqueue`)\n";
1617 SetVersion ($DBversion);
1620 $DBversion = "3.00.00.087";
1621 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1622 $dbh->do("INSERT INTO `systempreferences` VALUES ('AutoEmailOpacUser','0','','Sends notification emails containing new account details to patrons - when account is created.','YesNo')" );
1623 $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')");
1624 print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
1625 SetVersion ($DBversion);
1628 $DBversion = "3.00.00.088";
1629 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1630 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('OPACShelfBrowser','1','','Enable/disable Shelf Browser on item details page','YesNo')");
1631 $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')");
1632 $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')");
1633 $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')");
1634 print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
1635 SetVersion ($DBversion);
1638 $DBversion = "3.00.00.089";
1639 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1640 $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')");
1641 print "Upgrade to $DBversion done (added new AdvancedSearchTypes syspref)\n";
1642 SetVersion ($DBversion);
1645 $DBversion = "3.00.00.090";
1646 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1648 CREATE TABLE `branch_borrower_circ_rules` (
1649 `branchcode` VARCHAR(10) NOT NULL,
1650 `categorycode` VARCHAR(10) NOT NULL,
1651 `maxissueqty` int(4) default NULL,
1652 PRIMARY KEY (`categorycode`, `branchcode`),
1653 CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
1654 ON DELETE CASCADE ON UPDATE CASCADE,
1655 CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
1656 ON DELETE CASCADE ON UPDATE CASCADE
1657 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1660 CREATE TABLE `default_borrower_circ_rules` (
1661 `categorycode` VARCHAR(10) NOT NULL,
1662 `maxissueqty` int(4) default NULL,
1663 PRIMARY KEY (`categorycode`),
1664 CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
1665 ON DELETE CASCADE ON UPDATE CASCADE
1666 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1669 CREATE TABLE `default_branch_circ_rules` (
1670 `branchcode` VARCHAR(10) NOT NULL,
1671 `maxissueqty` int(4) default NULL,
1672 PRIMARY KEY (`branchcode`),
1673 CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
1674 ON DELETE CASCADE ON UPDATE CASCADE
1675 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1678 CREATE TABLE `default_circ_rules` (
1679 `singleton` enum('singleton') NOT NULL default 'singleton',
1680 `maxissueqty` int(4) default NULL,
1681 PRIMARY KEY (`singleton`)
1682 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1684 print "Upgrade to $DBversion done (added several circ rules tables)\n";
1685 SetVersion ($DBversion);
1689 $DBversion = "3.00.00.091";
1690 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1691 $dbh->do(<<'END_SQL');
1692 ALTER TABLE borrowers
1693 ADD `smsalertnumber` varchar(50) default NULL
1696 $dbh->do(<<'END_SQL');
1697 CREATE TABLE `message_attributes` (
1698 `message_attribute_id` int(11) NOT NULL auto_increment,
1699 `message_name` varchar(20) NOT NULL default '',
1700 `takes_days` tinyint(1) NOT NULL default '0',
1701 PRIMARY KEY (`message_attribute_id`),
1702 UNIQUE KEY `message_name` (`message_name`)
1703 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1706 $dbh->do(<<'END_SQL');
1707 CREATE TABLE `message_transport_types` (
1708 `message_transport_type` varchar(20) NOT NULL,
1709 PRIMARY KEY (`message_transport_type`)
1710 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1713 $dbh->do(<<'END_SQL');
1714 CREATE TABLE `message_transports` (
1715 `message_attribute_id` int(11) NOT NULL,
1716 `message_transport_type` varchar(20) NOT NULL,
1717 `is_digest` tinyint(1) NOT NULL default '0',
1718 `letter_module` varchar(20) NOT NULL default '',
1719 `letter_code` varchar(20) NOT NULL default '',
1720 PRIMARY KEY (`message_attribute_id`,`message_transport_type`,`is_digest`),
1721 KEY `message_transport_type` (`message_transport_type`),
1722 KEY `letter_module` (`letter_module`,`letter_code`),
1723 CONSTRAINT `message_transports_ibfk_1` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1724 CONSTRAINT `message_transports_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE,
1725 CONSTRAINT `message_transports_ibfk_3` FOREIGN KEY (`letter_module`, `letter_code`) REFERENCES `letter` (`module`, `code`) ON DELETE CASCADE ON UPDATE CASCADE
1726 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1729 $dbh->do(<<'END_SQL');
1730 CREATE TABLE `borrower_message_preferences` (
1731 `borrower_message_preference_id` int(11) NOT NULL auto_increment,
1732 `borrowernumber` int(11) NOT NULL default '0',
1733 `message_attribute_id` int(11) default '0',
1734 `days_in_advance` int(11) default '0',
1735 `wants_digets` tinyint(1) NOT NULL default '0',
1736 PRIMARY KEY (`borrower_message_preference_id`),
1737 KEY `borrowernumber` (`borrowernumber`),
1738 KEY `message_attribute_id` (`message_attribute_id`),
1739 CONSTRAINT `borrower_message_preferences_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1740 CONSTRAINT `borrower_message_preferences_ibfk_2` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE
1741 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1744 $dbh->do(<<'END_SQL');
1745 CREATE TABLE `borrower_message_transport_preferences` (
1746 `borrower_message_preference_id` int(11) NOT NULL default '0',
1747 `message_transport_type` varchar(20) NOT NULL default '0',
1748 PRIMARY KEY (`borrower_message_preference_id`,`message_transport_type`),
1749 KEY `message_transport_type` (`message_transport_type`),
1750 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,
1751 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
1752 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1755 $dbh->do(<<'END_SQL');
1756 CREATE TABLE `message_queue` (
1757 `message_id` int(11) NOT NULL auto_increment,
1758 `borrowernumber` int(11) NOT NULL,
1761 `message_transport_type` varchar(20) NOT NULL,
1762 `status` enum('sent','pending','failed','deleted') NOT NULL default 'pending',
1763 `time_queued` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1764 KEY `message_id` (`message_id`),
1765 KEY `borrowernumber` (`borrowernumber`),
1766 KEY `message_transport_type` (`message_transport_type`),
1767 CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1768 CONSTRAINT `messageq_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE RESTRICT ON UPDATE CASCADE
1769 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1772 $dbh->do(<<'END_SQL');
1773 INSERT INTO `systempreferences`
1774 (variable,value,explanation,options,type)
1776 ('EnhancedMessagingPreferences',0,'If ON, allows patrons to select to receive additional messages about items due or nearly due.','','YesNo')
1779 $dbh->do( <<'END_SQL');
1780 INSERT INTO `letter`
1781 (module, code, name, title, content)
1783 ('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>>'),
1784 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You have <<count>> items due'),
1785 ('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>>'),
1786 ('circulation','PREDUEDGST','Advance Notice of Item Due (Digest)','Advance Notice of Item Due','You have <<count>> items due soon'),
1787 ('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.');
1791 'installer/data/mysql/en/mandatory/message_transport_types.sql',
1792 'installer/data/mysql/en/optional/sample_notices_message_attributes.sql',
1793 'installer/data/mysql/en/optional/sample_notices_message_transports.sql',
1796 my $installer = C4::Installer->new();
1797 foreach my $script ( @sql_scripts ) {
1798 my $full_path = $installer->get_file_path_from_name($script);
1799 my $error = $installer->load_sql($full_path);
1800 warn $error if $error;
1803 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";
1804 SetVersion ($DBversion);
1807 $DBversion = "3.00.00.092";
1808 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1809 $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')");
1810 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Allow hold requests to be placed on damaged items', 'YesNo')");
1811 print "Upgrade to $DBversion done (added new AllowOnShelfHolds syspref)\n";
1812 SetVersion ($DBversion);
1815 $DBversion = "3.00.00.093";
1816 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1817 $dbh->do("ALTER TABLE `items` MODIFY COLUMN `copynumber` VARCHAR(32) DEFAULT NULL");
1818 $dbh->do("ALTER TABLE `deleteditems` MODIFY COLUMN `copynumber` VARCHAR(32) DEFAULT NULL");
1819 print "Upgrade to $DBversion done (Change data type of items.copynumber to allow free text)\n";
1820 SetVersion ($DBversion);
1823 $DBversion = "3.00.00.094";
1824 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1825 $dbh->do("ALTER TABLE `marc_subfield_structure` MODIFY `tagsubfield` VARCHAR(1) NOT NULL DEFAULT '' COLLATE utf8_bin");
1826 print "Upgrade to $DBversion done (Change Collation of marc_subfield_structure to allow mixed case in subfield labels.)\n";
1827 SetVersion ($DBversion);
1830 $DBversion = "3.00.00.095";
1831 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1832 if (C4::Context->preference("marcflavour") eq 'MARC21') {
1833 $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'MEETI_NAME' WHERE authtypecode = 'Meeting Name'");
1834 $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'CORPO_NAME' WHERE authtypecode = 'CORP0_NAME'");
1836 print "Upgrade to $DBversion done (fix invalid authority types in MARC21 frameworks [bug 2254])\n";
1837 SetVersion ($DBversion);
1840 $DBversion = "3.00.00.096";
1841 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1842 $sth = $dbh->prepare("SHOW COLUMNS FROM borrower_message_preferences LIKE 'wants_digets'");
1844 if (my $row = $sth->fetchrow_hashref) {
1845 $dbh->do("ALTER TABLE borrower_message_preferences CHANGE wants_digets wants_digest tinyint(1) NOT NULL default 0");
1847 print "Upgrade to $DBversion done (fix name borrower_message_preferences.wants_digest)\n";
1848 SetVersion ($DBversion);
1851 $DBversion = '3.00.00.097';
1852 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1854 $dbh->do('ALTER TABLE message_queue ADD to_address mediumtext default NULL');
1855 $dbh->do('ALTER TABLE message_queue ADD from_address mediumtext default NULL');
1856 $dbh->do('ALTER TABLE message_queue ADD content_type text');
1857 $dbh->do('ALTER TABLE message_queue CHANGE borrowernumber borrowernumber int(11) default NULL');
1859 print "Upgrade to $DBversion done (updating 4 fields in message_queue table)\n";
1860 SetVersion($DBversion);
1863 $DBversion = '3.00.00.098';
1864 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1866 $dbh->do(q(DELETE FROM message_transport_types WHERE message_transport_type = 'rss'));
1867 $dbh->do(q(DELETE FROM message_transports WHERE message_transport_type = 'rss'));
1869 print "Upgrade to $DBversion done (removing unused RSS message_transport_type)\n";
1870 SetVersion($DBversion);
1873 $DBversion = '3.00.00.099';
1874 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1875 $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')");
1876 print "Upgrade to $DBversion done (Adding OpacSuppression syspref)\n";
1877 SetVersion($DBversion);
1880 $DBversion = '3.00.00.100';
1881 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1882 $dbh->do('ALTER TABLE virtualshelves ADD COLUMN lastmodified timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP');
1883 print "Upgrade to $DBversion done (Adding lastmodified column to virtualshelves)\n";
1884 SetVersion($DBversion);
1887 $DBversion = '3.00.00.101';
1888 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1889 $dbh->do('ALTER TABLE `overduerules` CHANGE `categorycode` `categorycode` VARCHAR(10) NOT NULL');
1890 $dbh->do('ALTER TABLE `deletedborrowers` CHANGE `categorycode` `categorycode` VARCHAR(10) NOT NULL');
1891 print "Upgrade to $DBversion done (Updating columnd definitions for patron category codes in notice/statsu triggers and deletedborrowers tables.)\n";
1892 SetVersion($DBversion);
1895 $DBversion = '3.00.00.102';
1896 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1897 $dbh->do('ALTER TABLE serialitems MODIFY `serialid` int(11) NOT NULL AFTER itemnumber' );
1898 $dbh->do('ALTER TABLE serialitems DROP KEY serialididx' );
1899 $dbh->do('ALTER TABLE serialitems ADD CONSTRAINT UNIQUE KEY serialitemsidx (itemnumber)' );
1900 # before setting constraint, delete any unvalid data
1901 $dbh->do('DELETE from serialitems WHERE serialid not in (SELECT serial.serialid FROM serial)');
1902 $dbh->do('ALTER TABLE serialitems ADD CONSTRAINT serialitems_sfk_1 FOREIGN KEY (serialid) REFERENCES serial (serialid) ON DELETE CASCADE ON UPDATE CASCADE' );
1903 print "Upgrade to $DBversion done (Updating serialitems table to allow for multiple items per serial fixing kohabug 2380)\n";
1904 SetVersion($DBversion);
1907 $DBversion = "3.00.00.103";
1908 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1909 $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
1910 print "Upgrade to $DBversion done ( Verifying the removal of serialsadditems from syspref fixing kohabug 2219)\n";
1911 SetVersion ($DBversion);
1914 $DBversion = "3.00.00.104";
1915 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1916 $dbh->do("DELETE FROM systempreferences WHERE variable='noOPACHolds'");
1917 print "Upgrade to $DBversion done (remove superseded 'noOPACHolds' system preference per bug 2413)\n";
1918 SetVersion ($DBversion);
1921 $DBversion = '3.00.00.105';
1922 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
1924 # it is possible that this syspref is already defined since the feature was added some time ago.
1925 unless ( $dbh->do(q(SELECT variable FROM systempreferences WHERE variable = 'SMSSendDriver')) ) {
1926 $dbh->do(<<'END_SQL');
1927 INSERT INTO `systempreferences`
1928 (variable,value,explanation,options,type)
1930 ('SMSSendDriver','','Sets which SMS::Send driver is used to send SMS messages.','','free')
1933 print "Upgrade to $DBversion done (added SMSSendDriver system preference)\n";
1934 SetVersion($DBversion);
1937 $DBversion = "3.00.00.106";
1938 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1939 $dbh->do("DELETE FROM systempreferences WHERE variable='noOPACHolds'");
1941 # db revision 105 didn't apply correctly, so we're rolling this into 106
1942 $dbh->do("INSERT INTO `systempreferences`
1943 (variable,value,explanation,options,type)
1945 ('SMSSendDriver','','Sets which SMS::Send driver is used to send SMS messages.','','free')");
1947 print "Upgrade to $DBversion done (remove default '0000-00-00' in subscriptionhistory.enddate field)\n";
1948 $dbh->do("ALTER TABLE `subscriptionhistory` CHANGE `enddate` `enddate` DATE NULL DEFAULT NULL ");
1949 $dbh->do("UPDATE subscriptionhistory SET enddate=NULL WHERE enddate='0000-00-00'");
1950 SetVersion ($DBversion);
1953 $DBversion = '3.00.00.107';
1954 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1955 $dbh->do(<<'END_SQL');
1956 UPDATE systempreferences
1957 SET explanation = CONCAT( explanation, '. WARNING: this feature is very resource consuming on collections with large numbers of items.' )
1958 WHERE variable = 'OPACShelfBrowser'
1959 AND explanation NOT LIKE '%WARNING%'
1961 $dbh->do(<<'END_SQL');
1962 UPDATE systempreferences
1963 SET explanation = CONCAT( explanation, '. WARNING: this feature is very resource consuming.' )
1964 WHERE variable = 'CataloguingLog'
1965 AND explanation NOT LIKE '%WARNING%'
1967 $dbh->do(<<'END_SQL');
1968 UPDATE systempreferences
1969 SET explanation = CONCAT( explanation, '. WARNING: using NoZebra on even modest sized collections is very slow.' )
1970 WHERE variable = 'NoZebra'
1971 AND explanation NOT LIKE '%WARNING%'
1973 print "Upgrade to $DBversion done (warning added to OPACShelfBrowser system preference)\n";
1974 SetVersion ($DBversion);
1977 $DBversion = '3.01.00.000';
1978 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1979 print "Upgrade to $DBversion done (start of 3.1)\n";
1980 SetVersion ($DBversion);
1983 $DBversion = '3.01.00.001';
1984 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1986 CREATE TABLE hold_fill_targets (
1987 `borrowernumber` int(11) NOT NULL,
1988 `biblionumber` int(11) NOT NULL,
1989 `itemnumber` int(11) NOT NULL,
1990 `source_branchcode` varchar(10) default NULL,
1991 `item_level_request` tinyint(4) NOT NULL default 0,
1992 PRIMARY KEY `itemnumber` (`itemnumber`),
1993 KEY `bib_branch` (`biblionumber`, `source_branchcode`),
1994 CONSTRAINT `hold_fill_targets_ibfk_1` FOREIGN KEY (`borrowernumber`)
1995 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1996 CONSTRAINT `hold_fill_targets_ibfk_2` FOREIGN KEY (`biblionumber`)
1997 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1998 CONSTRAINT `hold_fill_targets_ibfk_3` FOREIGN KEY (`itemnumber`)
1999 REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2000 CONSTRAINT `hold_fill_targets_ibfk_4` FOREIGN KEY (`source_branchcode`)
2001 REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2002 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2005 ALTER TABLE tmp_holdsqueue
2006 ADD item_level_request tinyint(4) NOT NULL default 0
2009 print "Upgrade to $DBversion done (add hold_fill_targets table and a column to tmp_holdsqueue)\n";
2010 SetVersion($DBversion);
2013 $DBversion = '3.01.00.002';
2014 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2015 # use statistics where available
2017 ALTER TABLE statistics ADD KEY tmp_stats (type, itemnumber, borrowernumber)
2022 SELECT max(datetime)
2024 WHERE type = 'issue'
2025 AND itemnumber = iss.itemnumber
2026 AND borrowernumber = iss.borrowernumber
2028 WHERE issuedate IS NULL;
2030 $dbh->do("ALTER TABLE statistics DROP KEY tmp_stats");
2032 # default to last renewal date
2035 SET issuedate = lastreneweddate
2036 WHERE issuedate IS NULL
2037 and lastreneweddate IS NOT NULL
2040 my $num_bad_issuedates = $dbh->selectrow_array("SELECT COUNT(*) FROM issues WHERE issuedate IS NULL");
2041 if ($num_bad_issuedates > 0) {
2042 print STDERR "After the upgrade to $DBversion, there are still $num_bad_issuedates loan(s) with a NULL (blank) loan date. ",
2043 "Please check the issues table in your database.";
2045 print "Upgrade to $DBversion done (bug 2582: set null issues.issuedate to lastreneweddate)\n";
2046 SetVersion($DBversion);
2049 $DBversion = "3.01.00.003";
2050 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2051 $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')");
2052 print "Upgrade to $DBversion done (add new syspref)\n";
2053 SetVersion ($DBversion);
2056 $DBversion = '3.01.00.004';
2057 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2058 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACDisplayRequestPriority','0','Show patrons the priority level on holds in the OPAC','','YesNo')");
2059 print "Upgrade to $DBversion done (added OPACDisplayRequestPriority system preference)\n";
2060 SetVersion ($DBversion);
2063 $DBversion = '3.01.00.005';
2064 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2066 INSERT INTO `letter` (module, code, name, title, content)
2067 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>>')
2069 $dbh->do("INSERT INTO `message_attributes` (message_attribute_id, message_name, takes_days) values(4, 'Hold Filled', 0)");
2070 $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'sms', 0, 'reserves', 'HOLD')");
2071 $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'email', 0, 'reserves', 'HOLD')");
2072 print "Upgrade to $DBversion done (Add letter for holds notifications)\n";
2073 SetVersion ($DBversion);
2076 $DBversion = '3.01.00.006';
2077 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2078 $dbh->do("ALTER TABLE `biblioitems` ADD KEY issn (issn)");
2079 print "Upgrade to $DBversion done (add index on biblioitems.issn)\n";
2080 SetVersion ($DBversion);
2083 $DBversion = "3.01.00.007";
2084 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2085 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetmainUserblock'");
2086 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetuserjs'");
2087 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacheader'");
2088 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacMainUserBlock'");
2089 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacNav'");
2090 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacuserjs'");
2091 $dbh->do("UPDATE `systempreferences` SET options='30|10', type='Textarea' WHERE variable='OAI-PMH:Set'");
2092 $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetstylesheet'");
2093 $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetcolorstylesheet'");
2094 $dbh->do("UPDATE `systempreferences` SET options='10' WHERE variable='globalDueDate'");
2095 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='numSearchResults'");
2096 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='OPACnumSearchResults'");
2097 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='ReservesMaxPickupDelay'");
2098 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='TransfersMaxDaysWarning'");
2099 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='StaticHoldsQueueWeight'");
2100 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='holdCancelLength'");
2101 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='XISBNDailyLimit'");
2102 $dbh->do("UPDATE `systempreferences` SET type='Float' WHERE variable='gist'");
2103 $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorUsername'");
2104 $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorPassword'");
2105 $dbh->do("UPDATE `systempreferences` SET type='Textarea', options='70|10' WHERE variable='ISBD'");
2106 $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'");
2107 print "Upgrade to $DBversion done (fix display of many sysprefs)\n";
2108 SetVersion ($DBversion);
2111 $DBversion = '3.01.00.008';
2112 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2114 $dbh->do("CREATE TABLE branch_transfer_limits (
2115 limitId int(8) NOT NULL auto_increment,
2116 toBranch varchar(4) NOT NULL,
2117 fromBranch varchar(4) NOT NULL,
2118 itemtype varchar(4) NOT NULL,
2119 PRIMARY KEY (limitId)
2120 ) ENGINE=InnoDB DEFAULT CHARSET=utf8"
2123 $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')");
2125 print "Upgrade to $DBversion done (added branch_transfer_limits table and UseBranchTransferLimits system preference)\n";
2126 SetVersion ($DBversion);
2129 $DBversion = "3.01.00.009";
2130 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2131 $dbh->do("ALTER TABLE permissions MODIFY `code` varchar(64) DEFAULT NULL");
2132 $dbh->do("ALTER TABLE user_permissions MODIFY `code` varchar(64) DEFAULT NULL");
2133 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'circulate_remaining_permissions', 'Remaining circulation permissions')");
2134 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'override_renewals', 'Override blocked renewals')");
2135 print "Upgrade to $DBversion done (added subpermissions for circulate permission)\n";
2138 $DBversion = '3.01.00.010';
2139 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2140 $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `attribute` VARCHAR(64) DEFAULT NULL");
2141 $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `password` VARCHAR(64) DEFAULT NULL");
2142 print "Upgrade to $DBversion done (bug 2687: increase length of borrower attribute fields)\n";
2143 SetVersion ($DBversion);
2146 $DBversion = '3.01.00.011';
2147 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2149 # Yes, the old value was ^M terminated.
2150 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);";
2152 my $intranetuserjs = C4::Context->preference('intranetuserjs');
2153 if ($intranetuserjs and $intranetuserjs eq $bad_value) {
2154 my $sql = <<'END_SQL';
2155 UPDATE systempreferences
2157 WHERE variable = 'intranetuserjs'
2161 print "Upgrade to $DBversion done (removed bogus intranetuserjs syspref)\n";
2162 SetVersion($DBversion);
2165 $DBversion = "3.01.00.012";
2166 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2167 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowHoldPolicyOverride', '0', 'Allow staff to override hold policies when placing holds',NULL,'YesNo')");
2169 CREATE TABLE `branch_item_rules` (
2170 `branchcode` varchar(10) NOT NULL,
2171 `itemtype` varchar(10) NOT NULL,
2172 `holdallowed` tinyint(1) default NULL,
2173 PRIMARY KEY (`itemtype`,`branchcode`),
2174 KEY `branch_item_rules_ibfk_2` (`branchcode`),
2175 CONSTRAINT `branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE,
2176 CONSTRAINT `branch_item_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2177 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2180 CREATE TABLE `default_branch_item_rules` (
2181 `itemtype` varchar(10) NOT NULL,
2182 `holdallowed` tinyint(1) default NULL,
2183 PRIMARY KEY (`itemtype`),
2184 CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE
2185 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2188 ALTER TABLE default_branch_circ_rules
2189 ADD COLUMN holdallowed tinyint(1) NULL
2192 ALTER TABLE default_circ_rules
2193 ADD COLUMN holdallowed tinyint(1) NULL
2195 print "Upgrade to $DBversion done (Add tables and system preferences for holds policies)\n";
2196 SetVersion ($DBversion);
2199 $DBversion = '3.01.00.013';
2200 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2202 CREATE TABLE item_circulation_alert_preferences (
2203 id int(11) AUTO_INCREMENT,
2204 branchcode varchar(10) NOT NULL,
2205 categorycode varchar(10) NOT NULL,
2206 item_type varchar(10) NOT NULL,
2207 notification varchar(16) NOT NULL,
2209 KEY (branchcode, categorycode, item_type, notification)
2210 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2213 $dbh->do(q{ ALTER TABLE `message_queue` ADD metadata text DEFAULT NULL AFTER content; });
2214 $dbh->do(q{ ALTER TABLE `message_queue` ADD letter_code varchar(64) DEFAULT NULL AFTER metadata; });
2217 INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES
2218 ('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.');
2221 INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES
2222 ('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>>.');
2225 $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (5, 'Item Check-in', 0);});
2226 $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (6, 'Item Checkout', 0);});
2228 $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');});
2229 $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');});
2230 $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');});
2231 $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');});
2233 print "Upgrade to $DBversion done (data for Email Checkout Slips project)\n";
2234 SetVersion ($DBversion);
2237 $DBversion = "3.01.00.014";
2238 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2239 $dbh->do("ALTER TABLE `branch_transfer_limits` CHANGE `itemtype` `itemtype` VARCHAR( 4 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL");
2240 $dbh->do("ALTER TABLE `branch_transfer_limits` ADD `ccode` VARCHAR( 10 ) NULL ;");
2241 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2243 'BranchTransferLimitsType', 'ccode', 'itemtype|ccode', 'When using branch transfer limits, choose whether to limit by itemtype or collection code.', 'Choice'
2246 print "Upgrade to $DBversion done ( Updated table for Branch Transfer Limits)\n";
2247 SetVersion ($DBversion);
2250 $DBversion = '3.01.00.015';
2251 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2252 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsClientCode', '0', 'Client Code for using Syndetics Solutions content','','free')");
2254 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEnabled', '0', 'Turn on Syndetics Enhanced Content','','YesNo')");
2256 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsCoverImages', '0', 'Display Cover Images from Syndetics','','YesNo')");
2258 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsTOC', '0', 'Display Table of Content information from Syndetics','','YesNo')");
2260 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSummary', '0', 'Display Summary Information from Syndetics','','YesNo')");
2262 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEditions', '0', 'Display Editions from Syndetics','','YesNo')");
2264 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsExcerpt', '0', 'Display Excerpts and first chapters on OPAC from Syndetics','','YesNo')");
2266 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsReviews', '0', 'Display Reviews on OPAC from Syndetics','','YesNo')");
2268 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAuthorNotes', '0', 'Display Notes about the Author on OPAC from Syndetics','','YesNo')");
2270 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAwards', '0', 'Display Awards on OPAC from Syndetics','','YesNo')");
2272 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSeries', '0', 'Display Series information on OPAC from Syndetics','','YesNo')");
2274 $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')");
2276 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonCoverImages', '0', 'Display cover images on OPAC from Amazon Web Services','','YesNo')");
2278 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonCoverImages', '0', 'Display Cover Images in Staff Client from Amazon Web Services','','YesNo')");
2280 $dbh->do("UPDATE systempreferences SET variable='AmazonEnabled' WHERE variable = 'AmazonContent'");
2282 $dbh->do("UPDATE systempreferences SET variable='OPACAmazonEnabled' WHERE variable = 'OPACAmazonContent'");
2284 print "Upgrade to $DBversion done (added Syndetics Enhanced Content system preferences)\n";
2285 SetVersion ($DBversion);
2288 $DBversion = "3.01.00.016";
2289 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2290 $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')");
2291 print "Upgrade to $DBversion done (Added Babeltheque syspref)\n";
2292 SetVersion ($DBversion);
2295 $DBversion = "3.01.00.017";
2296 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2297 $dbh->do("ALTER TABLE `subscription` ADD `staffdisplaycount` VARCHAR(10) NULL;");
2298 $dbh->do("ALTER TABLE `subscription` ADD `opacdisplaycount` VARCHAR(10) NULL;");
2299 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2301 'StaffSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the Staff client', 'Integer'
2303 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2305 'OPACSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the OPAC', 'Integer'
2308 print "Upgrade to $DBversion done ( Updated table for Serials Display)\n";
2309 SetVersion ($DBversion);
2312 $DBversion = "3.01.00.018";
2313 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2314 $dbh->do("ALTER TABLE deletedborrowers ADD `smsalertnumber` varchar(50) default NULL");
2315 print "Upgrade to $DBversion done (added deletedborrowers.smsalertnumber, missed in 3.00.00.091)\n";
2316 SetVersion ($DBversion);
2319 $DBversion = "3.01.00.019";
2320 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2321 $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')");
2322 print "Upgrade to $DBversion done (adding OPACShowCheckoutName systempref)\n";
2323 SetVersion ($DBversion);
2326 $DBversion = "3.01.00.020";
2327 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2328 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesID','','See:http://librarything.com/forlibraries/','','free')");
2329 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesEnabled','0','Enable or Disable Library Thing for Libraries Features','','YesNo')");
2330 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesTabbedView','0','Put LibraryThingForLibraries Content in Tabs.','','YesNo')");
2331 print "Upgrade to $DBversion done (adding LibraryThing for Libraries sysprefs)\n";
2332 SetVersion ($DBversion);
2335 $DBversion = "3.01.00.021";
2336 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2337 my $enable_reviews = C4::Context->preference('OPACAmazonEnabled') ? '1' : '0';
2338 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonReviews', '$enable_reviews', 'Display Amazon readers reviews on OPAC','','YesNo')");
2339 print "Upgrade to $DBversion done (adding OPACAmazonReviews syspref)\n";
2340 SetVersion ($DBversion);
2343 $DBversion = '3.01.00.022';
2344 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2345 $dbh->do("ALTER TABLE `labels_conf` MODIFY COLUMN `formatstring` mediumtext DEFAULT NULL");
2346 print "Upgrade to $DBversion done (bug 2945: increase size of labels_conf.formatstring)\n";
2347 SetVersion ($DBversion);
2350 $DBversion = '3.01.00.023';
2351 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2352 $dbh->do("ALTER TABLE biblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2353 $dbh->do("ALTER TABLE deletedbiblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2354 $dbh->do("ALTER TABLE import_biblios MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2355 $dbh->do("ALTER TABLE suggestions MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2356 print "Upgrade to $DBversion done (bug 2765: increase width of isbn column in several tables)\n";
2357 SetVersion ($DBversion);
2360 $DBversion = "3.01.00.024";
2361 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2362 $dbh->do("ALTER TABLE labels MODIFY COLUMN batch_id int(10) NOT NULL default 1;");
2363 print "Upgrade to $DBversion done (change labels.batch_id from varchar to int)\n";
2364 SetVersion ($DBversion);
2367 $DBversion = '3.01.00.025';
2368 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2369 $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')");
2371 print "Upgrade to $DBversion done (added ceilingDueDate system preference)\n";
2372 SetVersion ($DBversion);
2375 $DBversion = '3.01.00.026';
2376 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2377 $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')");
2379 print "Upgrade to $DBversion done (added numReturnedItemsToShow system preference)\n";
2380 SetVersion ($DBversion);
2383 $DBversion = '3.01.00.027';
2384 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2385 $dbh->do("ALTER TABLE zebraqueue CHANGE `biblio_auth_number` `biblio_auth_number` bigint(20) unsigned NOT NULL default 0");
2386 print "Upgrade to $DBversion done (Increased size of zebraqueue biblio_auth_number to address bug 3148.)\n";
2387 SetVersion ($DBversion);
2390 $DBversion = '3.01.00.028';
2391 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2392 my $enable_reviews = C4::Context->preference('AmazonEnabled') ? '1' : '0';
2393 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonReviews', '$enable_reviews', 'Display Amazon reviews on staff interface','','YesNo')");
2394 print "Upgrade to $DBversion done (added AmazonReviews)\n";
2395 SetVersion ($DBversion);
2398 $DBversion = '3.01.00.029';
2399 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2400 $dbh->do(q( UPDATE language_rfc4646_to_iso639
2401 SET iso639_2_code = 'spa'
2402 WHERE rfc4646_subtag = 'es'
2403 AND iso639_2_code = 'rus' )
2405 print "Upgrade to $DBversion done (fixed bug 2599: using Spanish search limit retrieves Russian results)\n";
2406 SetVersion ($DBversion);
2409 $DBversion = "3.01.00.030";
2410 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2411 $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')");
2412 print "Upgrade to $DBversion done (added AllowNotForLoanOverride system preference)\n";
2413 SetVersion ($DBversion);
2416 $DBversion = "3.01.00.031";
2417 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2418 $dbh->do("ALTER TABLE branch_transfer_limits
2419 MODIFY toBranch varchar(10) NOT NULL,
2420 MODIFY fromBranch varchar(10) NOT NULL,
2421 MODIFY itemtype varchar(10) NULL");
2422 print "Upgrade to $DBversion done (fix column widths in branch_transfer_limits)\n";
2423 SetVersion ($DBversion);
2426 $DBversion = "3.01.00.032";
2427 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2428 $dbh->do(<<ENDOFRENEWAL);
2429 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');
2431 print "Upgrade to $DBversion done (Change the field)\n";
2432 SetVersion ($DBversion);
2435 $DBversion = "3.01.00.033";
2436 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2438 ALTER TABLE borrower_message_preferences
2439 MODIFY borrowernumber int(11) default NULL,
2440 ADD categorycode varchar(10) default NULL AFTER borrowernumber,
2441 ADD KEY `categorycode` (`categorycode`),
2442 ADD CONSTRAINT `borrower_message_preferences_ibfk_3`
2443 FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
2444 ON DELETE CASCADE ON UPDATE CASCADE
2446 print "Upgrade to $DBversion done (DB changes to allow patron category defaults for messaging preferences)\n";
2447 SetVersion ($DBversion);
2450 $DBversion = "3.01.00.034";
2451 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2452 $dbh->do("ALTER TABLE `subscription` ADD COLUMN `graceperiod` INT(11) NOT NULL default '0';");
2453 print "Upgrade to $DBversion done (Adding graceperiod column to subscription table)\n";
2454 SetVersion ($DBversion);
2457 $DBversion = '3.01.00.035';
2458 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2459 $dbh->do(q{ ALTER TABLE `subscription` ADD location varchar(80) NULL DEFAULT '' AFTER callnumber; });
2460 print "Upgrade to $DBversion done (Adding location to subscription table)\n";
2461 SetVersion ($DBversion);
2464 $DBversion = '3.01.00.036';
2465 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2466 $dbh->do("UPDATE systempreferences SET explanation = 'Choose the default detail view in the staff interface; choose between normal, labeled_marc, marc or isbd'
2467 WHERE variable = 'IntranetBiblioDefaultView'
2468 AND explanation = 'IntranetBiblioDefaultView'");
2469 $dbh->do("UPDATE systempreferences SET type = 'Choice', options = 'normal|marc|isbd|labeled_marc'
2470 WHERE variable = 'IntranetBiblioDefaultView'");
2471 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewISBD','1','Allow display of ISBD view of bibiographic records','','YesNo')");
2472 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Allow display of labeled MARC view of bibiographic records','','YesNo')");
2473 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Allow display of MARC view of bibiographic records','','YesNo')");
2474 print "Upgrade to $DBversion done (new viewISBD, viewLabeledMARC, viewMARC sysprefs and tweak IntranetBiblioDefaultView)\n";
2475 SetVersion ($DBversion);
2478 $DBversion = '3.01.00.037';
2479 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2480 $dbh->do('ALTER TABLE authorised_values ADD KEY `lib` (`lib`)');
2481 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Do not run overdue report until filter selected','','YesNo')");
2482 SetVersion ($DBversion);
2483 print "Upgrade to $DBversion done (added FilterBeforeOverdueReport syspref and new index on authorised_values)\n";
2486 $DBversion = "3.01.00.038";
2487 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2488 # update branches table
2490 $dbh->do("ALTER TABLE branches ADD `branchzip` varchar(25) default NULL AFTER `branchaddress3`");
2491 $dbh->do("ALTER TABLE branches ADD `branchcity` mediumtext AFTER `branchzip`");
2492 $dbh->do("ALTER TABLE branches ADD `branchcountry` text AFTER `branchcity`");
2493 $dbh->do("ALTER TABLE branches ADD `branchurl` mediumtext AFTER `branchemail`");
2494 $dbh->do("ALTER TABLE branches ADD `branchnotes` mediumtext AFTER `branchprinter`");
2495 print "Upgrade to $DBversion done (add ZIP, city, country, URL, and notes column to branches)\n";
2496 SetVersion ($DBversion);
2499 $DBversion = '3.01.00.039';
2500 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2501 $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')");
2502 $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')");
2503 SetVersion ($DBversion);
2504 print "Upgrade to $DBversion done (added SpineLabelFormat and SpineLabelAutoPrint sysprefs)\n";
2507 $DBversion = '3.01.00.040';
2508 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2509 $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')");
2510 $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')");
2511 SetVersion ($DBversion);
2512 print "Upgrade to $DBversion done (AllowHoldDateInFuture and OPACAllowHoldDateInFuture sysprefs)\n";
2515 $DBversion = '3.01.00.041';
2516 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2517 $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')");
2518 SetVersion ($DBversion);
2519 print "Upgrade to $DBversion done (added AWSPrivateKey syspref - note that if you use enhanced content from Amazon, this should be set right away.)\n";
2522 $DBversion = '3.01.00.042';
2523 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2524 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACFineNoRenewals','99999','Fine Limit above which user canmot renew books via OPAC','','Integer')");
2525 SetVersion ($DBversion);
2526 print "Upgrade to $DBversion done (added OPACFineNoRenewals syspref)\n";
2529 $DBversion = '3.01.00.043';
2530 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2531 $dbh->do('ALTER TABLE items ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location');
2532 $dbh->do('UPDATE items SET permanent_location = location');
2533 $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 )', '')");
2534 $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')");
2535 $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')");
2536 SetVersion ($DBversion);
2537 print "Upgrade to $DBversion done (amended Item added NewItemsDefaultLocation, InProcessingToShelvingCart, ReturnToShelvingCart sysprefs)\n";
2540 $DBversion = '3.01.00.044';
2541 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2542 $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')");
2543 SetVersion ($DBversion);
2544 print "Upgrade to $DBversion done (added DisplayClearScreenButton system preference)\n";
2547 $DBversion = '3.01.00.045';
2548 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2549 $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')");
2550 SetVersion ($DBversion);
2551 print "Upgrade to $DBversion done (added a preference to hide the patrons name in the staff catalog)\n";
2554 $DBversion = "3.01.00.046";
2555 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2556 # update borrowers table
2558 $dbh->do("ALTER TABLE borrowers ADD `country` text AFTER zipcode");
2559 $dbh->do("ALTER TABLE borrowers ADD `B_country` text AFTER B_zipcode");
2560 $dbh->do("ALTER TABLE deletedborrowers ADD `country` text AFTER zipcode");
2561 $dbh->do("ALTER TABLE deletedborrowers ADD `B_country` text AFTER B_zipcode");
2562 print "Upgrade to $DBversion done (add country and B_country to borrowers)\n";
2563 SetVersion ($DBversion);
2566 $DBversion = '3.01.00.047';
2567 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2568 $dbh->do("ALTER TABLE items MODIFY itemcallnumber varchar(255);");
2569 $dbh->do("ALTER TABLE deleteditems MODIFY itemcallnumber varchar(255);");
2570 $dbh->do("ALTER TABLE tmp_holdsqueue MODIFY itemcallnumber varchar(255);");
2571 SetVersion ($DBversion);
2572 print " Upgrade to $DBversion done (bug 2761: change max length of itemcallnumber to 255 from 30)\n";
2575 $DBversion = '3.01.00.048';
2576 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2577 $dbh->do("UPDATE userflags SET flagdesc='View Catalog (Librarian Interface)' WHERE bit=2;");
2578 $dbh->do("UPDATE userflags SET flagdesc='Edit Catalog (Modify bibliographic/holdings data)' WHERE bit=9;");
2579 $dbh->do("UPDATE userflags SET flagdesc='Allow to edit authorities' WHERE bit=14;");
2580 $dbh->do("UPDATE userflags SET flagdesc='Allow to access to the reports module' WHERE bit=16;");
2581 $dbh->do("UPDATE userflags SET flagdesc='Allow to manage serials subscriptions' WHERE bit=15;");
2582 SetVersion ($DBversion);
2583 print " Upgrade to $DBversion done (bug 2611: fix spelling/capitalization in permission flag descriptions)\n";
2586 $DBversion = '3.01.00.049';
2587 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2588 $dbh->do("UPDATE permissions SET description = 'Perform inventory (stocktaking) of your catalog' WHERE code = 'inventory';");
2589 SetVersion ($DBversion);
2590 print "Upgrade to $DBversion done (bug 2611: changed catalogue to catalog per the standard)\n";
2593 $DBversion = '3.01.00.050';
2594 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2595 $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');");
2596 SetVersion ($DBversion);
2597 print "Upgrade to $DBversion done (bug 1934: Add OPACSearchForTitleIn syspref)\n";
2600 $DBversion = '3.01.00.051';
2601 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2602 $dbh->do("UPDATE systempreferences SET explanation='Fine limit above which user cannot renew books via OPAC' WHERE variable='OPACFineNoRenewals';");
2603 $dbh->do("UPDATE systempreferences SET explanation='If set to ON, a clear screen button will appear on the circulation page.' WHERE variable='DisplayClearScreenButton';");
2604 SetVersion ($DBversion);
2605 print "Upgrade to $DBversion done (fixed typos in new sysprefs)\n";
2608 $DBversion = '3.01.00.052';
2609 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2610 $dbh->do('ALTER TABLE deleteditems ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location');
2611 SetVersion ($DBversion);
2612 print "Upgrade to $DBversion done (bug 3481: add permanent_location column to deleteditems)\n";
2615 $DBversion = '3.01.00.053';
2616 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2617 my $upgrade_script = C4::Context->config("intranetdir") . "/installer/data/mysql/labels_upgrade.pl";
2618 system("perl $upgrade_script");
2619 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";
2620 SetVersion ($DBversion);
2623 $DBversion = '3.01.00.054';
2624 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2625 $dbh->do("ALTER TABLE borrowers ADD `B_address2` text AFTER B_address");
2626 $dbh->do("ALTER TABLE borrowers ADD `altcontactcountry` text AFTER altcontactzipcode");
2627 $dbh->do("ALTER TABLE deletedborrowers ADD `B_address2` text AFTER B_address");
2628 $dbh->do("ALTER TABLE deletedborrowers ADD `altcontactcountry` text AFTER altcontactzipcode");
2629 SetVersion ($DBversion);
2630 print "Upgrade to $DBversion done (bug 1600, bug 3454: add altcontactcountry and B_address2 to borrowers and deletedborrowers)\n";
2633 $DBversion = '3.01.00.055';
2634 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2635 $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'|);
2636 SetVersion ($DBversion);
2637 print "Upgrade to $DBversion done (changed OPACSearchForTitleIn per requests in bug 1934)\n";
2640 $DBversion = '3.01.00.056';
2641 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2642 $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');");
2643 SetVersion ($DBversion);
2644 print "Upgrade to $DBversion done (Bug 1172 : Add OPACPatronDetails syspref)\n";
2647 $DBversion = '3.01.00.057';
2648 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2649 $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');");
2650 SetVersion ($DBversion);
2651 print "Upgrade to $DBversion done (Bug 2576 : Add OPACFinesTab syspref)\n";
2654 $DBversion = '3.01.00.058';
2655 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2656 $dbh->do("ALTER TABLE `language_subtag_registry` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2657 $dbh->do("ALTER TABLE `language_rfc4646_to_iso639` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2658 $dbh->do("ALTER TABLE `language_descriptions` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2659 SetVersion ($DBversion);
2660 print "Upgrade to $DBversion done (Added primary keys to language tables)\n";
2663 $DBversion = '3.01.00.059';
2664 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2665 $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')");
2666 SetVersion ($DBversion);
2667 print "Upgrade to $DBversion done (added DisplayOPACiconsXSLT sysprefs)\n";
2670 $DBversion = '3.01.00.060';
2671 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2672 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo');");
2673 $dbh->do('DROP TABLE IF EXISTS messages');
2674 $dbh->do("CREATE TABLE messages ( `message_id` int(11) NOT NULL auto_increment,
2675 `borrowernumber` int(11) NOT NULL,
2676 `branchcode` varchar(4) default NULL,
2677 `message_type` varchar(1) NOT NULL,
2678 `message` text NOT NULL,
2679 `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
2680 PRIMARY KEY (`message_id`)
2681 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
2683 print "Upgrade to $DBversion done ( Added AllowAllMessageDeletion syspref and messages table )\n";
2684 SetVersion ($DBversion);
2687 $DBversion = '3.01.00.061';
2688 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2689 $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')");
2690 print "Upgrade to $DBversion done ( Added ShowPatronImageInWebBasedSelfCheck system preference )\n";
2691 SetVersion ($DBversion);
2694 $DBversion = "3.01.00.062";
2695 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2696 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'manage_csv_profiles', 'Manage CSV export profiles')");
2698 CREATE TABLE `export_format` (
2699 `export_format_id` int(11) NOT NULL auto_increment,
2700 `profile` varchar(255) NOT NULL,
2701 `description` mediumtext NOT NULL,
2702 `marcfields` mediumtext NOT NULL,
2703 PRIMARY KEY (`export_format_id`)
2704 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used for CSV export';
2706 print "Upgrade to $DBversion done (added csv export profiles)\n";
2709 $DBversion = "3.01.00.063";
2710 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2712 CREATE TABLE `fieldmapping` (
2713 `id` int(11) NOT NULL auto_increment,
2714 `field` varchar(255) NOT NULL,
2715 `frameworkcode` char(4) NOT NULL default '',
2716 `fieldcode` char(3) NOT NULL,
2717 `subfieldcode` char(1) NOT NULL,
2719 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2721 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";
2724 $DBversion = '3.01.00.065';
2725 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2726 $dbh->do('ALTER TABLE issuingrules ADD COLUMN `renewalsallowed` smallint(6) NOT NULL default "0" AFTER `issuelength`;');
2727 $sth = $dbh->prepare("SELECT itemtype, renewalsallowed FROM itemtypes");
2730 my $sthupd = $dbh->prepare("UPDATE issuingrules SET renewalsallowed = ? WHERE itemtype = ?");
2732 while(my $row = $sth->fetchrow_hashref){
2733 $sthupd->execute($row->{renewalsallowed}, $row->{itemtype});
2736 $dbh->do('ALTER TABLE itemtypes DROP COLUMN `renewalsallowed`;');
2738 SetVersion ($DBversion);
2739 print "Upgrade to $DBversion done (Moving allowed renewals from itemtypes to issuingrule)\n";
2742 $DBversion = '3.01.00.066';
2743 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2744 $dbh->do('ALTER TABLE issuingrules ADD COLUMN `reservesallowed` smallint(6) NOT NULL default "0" AFTER `renewalsallowed`;');
2746 my $maxreserves = C4::Context->preference('maxreserves');
2747 $sth = $dbh->prepare('UPDATE issuingrules SET reservesallowed = ?;');
2748 $sth->execute($maxreserves);
2750 $dbh->do('DELETE FROM systempreferences WHERE variable = "maxreserves";');
2752 $dbh->do("INSERT INTO systempreferences (variable,value, options, explanation, type) VALUES('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice')");
2754 SetVersion ($DBversion);
2755 print "Upgrade to $DBversion done (Moving max allowed reserves from system preference to issuingrule)\n";
2758 $DBversion = "3.01.00.067";
2759 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2760 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchmod', 'Perform batch modification of items')");
2761 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchdel', 'Perform batch deletion of items')");
2762 print "Upgrade to $DBversion done (added permissions for batch modification and deletion)\n";
2763 SetVersion ($DBversion);
2766 $DBversion = "3.01.00.068";
2767 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2768 $dbh->do("ALTER TABLE issuingrules ADD COLUMN `finedays` int(11) default NULL AFTER `fine` ");
2769 print "Upgrade to $DBversion done (Adding finedays in issuingrules table)\n";
2770 SetVersion ($DBversion);
2774 $DBversion = "3.01.00.069";
2775 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2776 $dbh->do("INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('EnableOpacSearchHistory', '1', '', 'Enable or disable opac search history', 'YesNo')");
2778 my $create = <<SEARCHHIST;
2779 CREATE TABLE IF NOT EXISTS `search_history` (
2780 `userid` int(11) NOT NULL,
2781 `sessionid` varchar(32) NOT NULL,
2782 `query_desc` varchar(255) NOT NULL,
2783 `query_cgi` varchar(255) NOT NULL,
2784 `total` int(11) NOT NULL,
2785 `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
2786 KEY `userid` (`userid`),
2787 KEY `sessionid` (`sessionid`)
2788 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Opac search history results';
2792 print "Upgrade to $DBversion done (added OPAC search history preference and table)\n";
2795 $DBversion = "3.01.00.070";
2796 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2797 $dbh->do("ALTER TABLE authorised_values ADD COLUMN `lib_opac` VARCHAR(80) default NULL AFTER `lib`");
2798 print "Upgrade to $DBversion done (Added a lib_opac field in authorised_values table)\n";
2801 $DBversion = "3.01.00.071";
2802 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2803 $dbh->do("ALTER TABLE `subscription` ADD `enddate` date default NULL");
2804 $dbh->do("ALTER TABLE subscriptionhistory CHANGE enddate histenddate DATE default NULL");
2805 print "Upgrade to $DBversion done ( Adding enddate to subscription)\n";
2808 # Acquisitions update
2810 $DBversion = "3.01.00.072";
2811 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2812 $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')");
2813 # create a new syspref for the 'Mr anonymous' patron
2814 $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,'')");
2815 # fill AnonymousPatron with AnonymousSuggestion value (copy)
2816 my $sth=$dbh->prepare("SELECT value FROM systempreferences WHERE variable='AnonSuggestions'");
2818 my ($value) = $sth->fetchrow() || 0;
2819 $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='AnonymousPatron'");
2820 # set AnonymousSuggestion do YesNo
2821 # 1st, set the value (1/True if it had a borrowernumber)
2822 $dbh->do("UPDATE systempreferences SET value=1 WHERE variable='AnonSuggestions' AND value>0");
2823 # 2nd, change the type to Choice
2824 $dbh->do("UPDATE systempreferences SET type='YesNo' WHERE variable='AnonSuggestions'");
2825 # borrower reading record privacy : 0 : forever, 1 : laws, 2 : don't keep at all
2826 $dbh->do("ALTER TABLE `borrowers` ADD `privacy` INTEGER NOT NULL DEFAULT 1;");
2827 print "Upgrade to $DBversion done (add new syspref and column in borrowers)\n";
2828 SetVersion ($DBversion);
2831 $DBversion = '3.01.00.073';
2832 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2833 $dbh->do('SET FOREIGN_KEY_CHECKS=0 ');
2834 $dbh->do(<<'END_SQL');
2835 CREATE TABLE IF NOT EXISTS `aqcontract` (
2836 `contractnumber` int(11) NOT NULL auto_increment,
2837 `contractstartdate` date default NULL,
2838 `contractenddate` date default NULL,
2839 `contractname` varchar(50) default NULL,
2840 `contractdescription` mediumtext,
2841 `booksellerid` int(11) not NULL,
2842 PRIMARY KEY (`contractnumber`),
2843 CONSTRAINT `booksellerid_fk1` FOREIGN KEY (`booksellerid`)
2844 REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
2845 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
2847 $dbh->do('SET FOREIGN_KEY_CHECKS=1 ');
2848 print "Upgrade to $DBversion done (adding aqcontract table)\n";
2849 SetVersion ($DBversion);
2852 $DBversion = '3.01.00.074';
2853 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2854 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `basketname` varchar(50) default NULL AFTER `basketno`");
2855 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `note` mediumtext AFTER `basketname`");
2856 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `booksellernote` mediumtext AFTER `note`");
2857 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `contractnumber` int(11) AFTER `booksellernote`");
2858 $dbh->do("ALTER TABLE `aqbasket` ADD FOREIGN KEY (`contractnumber`) REFERENCES `aqcontract` (`contractnumber`)");
2859 print "Upgrade to $DBversion done (edit aqbasket table done)\n";
2860 SetVersion ($DBversion);
2863 $DBversion = '3.01.00.075';
2864 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2865 $dbh->do("ALTER TABLE `aqorders` ADD COLUMN `uncertainprice` tinyint(1)");
2867 print "Upgrade to $DBversion done (adding uncertainprices)\n";
2868 SetVersion ($DBversion);
2871 $DBversion = '3.01.00.076';
2872 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2873 $dbh->do('SET FOREIGN_KEY_CHECKS=0 ');
2874 $dbh->do("CREATE TABLE IF NOT EXISTS `aqbasketgroups` (
2875 `id` int(11) NOT NULL auto_increment,
2876 `name` varchar(50) default NULL,
2877 `closed` tinyint(1) default NULL,
2878 `booksellerid` int(11) NOT NULL,
2880 KEY `booksellerid` (`booksellerid`),
2881 CONSTRAINT `aqbasketgroups_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
2882 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
2883 $dbh->do("ALTER TABLE aqbasket ADD COLUMN `basketgroupid` int(11)");
2884 $dbh->do("ALTER TABLE aqbasket ADD FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE ON DELETE SET NULL");
2885 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('pdfformat','pdfformat::layout2pages','Controls what script is used for printing (basketgroups)','','free')");
2886 $dbh->do('SET FOREIGN_KEY_CHECKS=1 ');
2887 print "Upgrade to $DBversion done (adding basketgroups)\n";
2888 SetVersion ($DBversion);
2890 $DBversion = '3.01.00.077';
2891 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2893 $dbh->do("SET FOREIGN_KEY_CHECKS=0 ");
2894 # create a mapping table holding the info we need to match orders to budgets
2895 $dbh->do('DROP TABLE IF EXISTS fundmapping');
2897 q|CREATE TABLE fundmapping AS
2898 SELECT aqorderbreakdown.ordernumber, branchcode, bookfundid, budgetdate, entrydate
2899 FROM aqorderbreakdown JOIN aqorders ON aqorderbreakdown.ordernumber = aqorders.ordernumber|);
2900 # match the new type of the corresponding field
2901 $dbh->do('ALTER TABLE fundmapping modify column bookfundid varchar(30)');
2902 # System did not ensure budgetdate was valid historically
2903 $dbh->do(q|UPDATE fundmapping SET budgetdate = entrydate WHERE budgetdate = '0000-00-00' OR budgetdate IS NULL|);
2904 # We save the map in fundmapping in case you need later processing
2905 $dbh->do(q|ALTER TABLE fundmapping add column aqbudgetid integer|);
2906 # these can speed processing up
2907 $dbh->do(q|CREATE INDEX fundmaporder ON fundmapping (ordernumber)|);
2908 $dbh->do(q|CREATE INDEX fundmapid ON fundmapping (bookfundid)|);
2910 $dbh->do("DROP TABLE IF EXISTS `aqbudgetperiods` ");
2913 CREATE TABLE `aqbudgetperiods` (
2914 `budget_period_id` int(11) NOT NULL auto_increment,
2915 `budget_period_startdate` date NOT NULL,
2916 `budget_period_enddate` date NOT NULL,
2917 `budget_period_active` tinyint(1) default '0',
2918 `budget_period_description` mediumtext,
2919 `budget_period_locked` tinyint(1) default NULL,
2920 `sort1_authcat` varchar(10) default NULL,
2921 `sort2_authcat` varchar(10) default NULL,
2922 PRIMARY KEY (`budget_period_id`)
2923 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |);
2925 $dbh->do(<<ADDPERIODS);
2926 INSERT INTO aqbudgetperiods (budget_period_startdate,budget_period_enddate,budget_period_active,budget_period_description,budget_period_locked)
2927 SELECT DISTINCT startdate, enddate, NOW() BETWEEN startdate and enddate, concat(startdate," ",enddate),NOT NOW() BETWEEN startdate AND enddate from aqbudget
2929 # SORRY , NO AQBUDGET/AQBOOKFUND -> AQBUDGETS IMPORT JUST YET,
2930 # BUT A NEW CLEAN AQBUDGETS TABLE CREATE FOR NOW..
2931 # DROP TABLE IF EXISTS `aqbudget`;
2932 #CREATE TABLE `aqbudget` (
2933 # `bookfundid` varchar(10) NOT NULL default ',
2934 # `startdate` date NOT NULL default 0,
2935 # `enddate` date default NULL,
2936 # `budgetamount` decimal(13,2) default NULL,
2937 # `aqbudgetid` tinyint(4) NOT NULL auto_increment,
2938 # `branchcode` varchar(10) default NULL,
2939 DropAllForeignKeys('aqbudget');
2940 #$dbh->do("drop table aqbudget;");
2943 my $maxbudgetid = $dbh->selectcol_arrayref(<<IDsBUDGET);
2944 SELECT MAX(aqbudgetid) from aqbudget
2947 $$maxbudgetid[0] = 0 if !$$maxbudgetid[0];
2949 $dbh->do(<<BUDGETAUTOINCREMENT);
2950 ALTER TABLE aqbudget AUTO_INCREMENT=$$maxbudgetid[0]
2953 $dbh->do(<<BUDGETNAME);
2954 ALTER TABLE aqbudget RENAME `aqbudgets`
2957 $dbh->do(<<BUDGETS);
2958 ALTER TABLE `aqbudgets`
2959 CHANGE COLUMN aqbudgetid `budget_id` int(11) NOT NULL AUTO_INCREMENT,
2960 CHANGE COLUMN branchcode `budget_branchcode` varchar(10) default NULL,
2961 CHANGE COLUMN budgetamount `budget_amount` decimal(28,6) NOT NULL default '0.00',
2962 CHANGE COLUMN bookfundid `budget_code` varchar(30) default NULL,
2963 ADD COLUMN `budget_parent_id` int(11) default NULL,
2964 ADD COLUMN `budget_name` varchar(80) default NULL,
2965 ADD COLUMN `budget_encumb` decimal(28,6) default '0.00',
2966 ADD COLUMN `budget_expend` decimal(28,6) default '0.00',
2967 ADD COLUMN `budget_notes` mediumtext,
2968 ADD COLUMN `budget_description` mediumtext,
2969 ADD COLUMN `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2970 ADD COLUMN `budget_amount_sublevel` decimal(28,6) AFTER `budget_amount`,
2971 ADD COLUMN `budget_period_id` int(11) default NULL,
2972 ADD COLUMN `sort1_authcat` varchar(80) default NULL,
2973 ADD COLUMN `sort2_authcat` varchar(80) default NULL,
2974 ADD COLUMN `budget_owner_id` int(11) default NULL,
2975 ADD COLUMN `budget_permission` int(1) default '0';
2978 $dbh->do(<<BUDGETCONSTRAINTS);
2979 ALTER TABLE `aqbudgets`
2980 ADD CONSTRAINT `aqbudgets_ifbk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON DELETE CASCADE ON UPDATE CASCADE
2982 # $dbh->do(<<BUDGETPKDROP);
2983 #ALTER TABLE `aqbudgets`
2986 # $dbh->do(<<BUDGETPKADD);
2987 #ALTER TABLE `aqbudgets`
2988 # ADD PRIMARY KEY budget_id
2992 my $query_period= $dbh->prepare(qq|SELECT budget_period_id from aqbudgetperiods where budget_period_startdate=? and budget_period_enddate=?|);
2993 my $query_bookfund= $dbh->prepare(qq|SELECT * from aqbookfund where bookfundid=?|);
2994 my $selectbudgets=$dbh->prepare(qq|SELECT * from aqbudgets|);
2995 my $updatebudgets=$dbh->prepare(qq|UPDATE aqbudgets SET budget_period_id= ? , budget_name=?, budget_branchcode=? where budget_id=?|);
2996 $selectbudgets->execute;
2997 while (my $databudget=$selectbudgets->fetchrow_hashref){
2998 $query_period->execute ($$databudget{startdate},$$databudget{enddate});
2999 my ($budgetperiodid)=$query_period->fetchrow;
3000 $query_bookfund->execute ($$databudget{budget_code});
3001 my $databf=$query_bookfund->fetchrow_hashref;
3002 my $branchcode=$$databudget{budget_branchcode}||$$databf{branchcode};
3003 $updatebudgets->execute($budgetperiodid,$$databf{bookfundname},$branchcode,$$databudget{budget_id});
3005 $dbh->do(<<BUDGETDROPDATES);
3006 ALTER TABLE `aqbudgets`
3012 $dbh->do("DROP TABLE IF EXISTS `aqbudgets_planning` ");
3013 $dbh->do("CREATE TABLE `aqbudgets_planning` (
3014 `plan_id` int(11) NOT NULL auto_increment,
3015 `budget_id` int(11) NOT NULL,
3016 `budget_period_id` int(11) NOT NULL,
3017 `estimated_amount` decimal(28,6) default NULL,
3018 `authcat` varchar(30) NOT NULL,
3019 `authvalue` varchar(30) NOT NULL,
3020 `display` tinyint(1) DEFAULT 1,
3021 PRIMARY KEY (`plan_id`),
3022 CONSTRAINT `aqbudgets_planning_ifbk_1` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
3023 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
3025 $dbh->do("ALTER TABLE `aqorders`
3026 ADD COLUMN `budget_id` tinyint(4) NOT NULL,
3027 ADD COLUMN `budgetgroup_id` int(11) NOT NULL,
3028 ADD COLUMN `sort1_authcat` varchar(10) default NULL,
3029 ADD COLUMN `sort2_authcat` varchar(10) default NULL" );
3030 # We need to map the orders to the budgets
3031 # For Historic reasons this is more complex than it should be on occasions
3032 my $budg_arr = $dbh->selectall_arrayref(