4 # This script checks for required updates to the database.
6 # Parts copyright Catalyst IT 2011
8 # Part of the Koha Library Software www.koha-community.org
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 # - Would also be a good idea to offer to do a backup at this time...
26 # NOTE: If you do something more than once in here, make it table driven.
28 # NOTE: Please keep the version in kohaversion.pl up-to-date!
44 use MARC::File::XML ( BinaryEncoding => 'utf8' );
46 # FIXME - The user might be installing a new database, so can't rely
47 # on /etc/koha.conf anyway.
54 %existingtables, # tables already in database
58 $type, $null, $key, $default, $extra,
59 $prefitem, # preference item in systempreferences table
62 my $schema = Koha::Database->new()->schema();
68 my $dbh = C4::Context->dbh;
69 $|=1; # flushes output
71 local $dbh->{RaiseError} = 0;
73 # Record the version we are coming from
75 my $original_version = C4::Context->preference("Version");
77 # Deal with virtualshelves
78 my $DBversion = "3.00.00.001";
79 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
80 # update virtualshelves table to
82 $dbh->do("ALTER TABLE `bookshelf` RENAME `virtualshelves`");
83 $dbh->do("ALTER TABLE `shelfcontents` RENAME `virtualshelfcontents`");
84 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD `biblionumber` INT( 11 ) NOT NULL default '0' AFTER shelfnumber");
85 $dbh->do("UPDATE `virtualshelfcontents` SET biblionumber=(SELECT biblionumber FROM items WHERE items.itemnumber=virtualshelfcontents.itemnumber)");
86 # drop all foreign keys : otherwise, we can't drop itemnumber field.
87 DropAllForeignKeys('virtualshelfcontents');
88 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD KEY biblionumber (biblionumber)");
89 # create the new foreign keys (on biblionumber)
90 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `virtualshelfcontents_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE");
91 # re-create the foreign key on virtualshelf
92 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `shelfcontents_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE");
93 $dbh->do("ALTER TABLE `virtualshelfcontents` DROP `itemnumber`");
94 print "Upgrade to $DBversion done (virtualshelves)\n";
95 SetVersion ($DBversion);
99 $DBversion = "3.00.00.002";
100 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
101 $dbh->do("DROP TABLE sessions");
102 $dbh->do("CREATE TABLE `sessions` (
103 `id` varchar(32) NOT NULL,
104 `a_session` text NOT NULL,
105 UNIQUE KEY `id` (`id`)
106 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
107 print "Upgrade to $DBversion done (sessions uses CGI::session, new table structure for sessions)\n";
108 SetVersion ($DBversion);
112 $DBversion = "3.00.00.003";
113 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
114 if (C4::Context->preference("opaclanguages") eq "fr") {
115 $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')");
117 $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')");
119 print "Upgrade to $DBversion done (adding ReservesNeedReturns systempref, in circulation)\n";
120 SetVersion ($DBversion);
124 $DBversion = "3.00.00.004";
125 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
126 $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')");
127 print "Upgrade to $DBversion done (adding DebugLevel systempref, in 'Admin' tab)\n";
128 SetVersion ($DBversion);
131 $DBversion = "3.00.00.005";
132 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
133 $dbh->do("CREATE TABLE `tags` (
134 `entry` varchar(255) NOT NULL default '',
135 `weight` bigint(20) NOT NULL default 0,
136 PRIMARY KEY (`entry`)
137 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
139 $dbh->do("CREATE TABLE `nozebra` (
140 `server` varchar(20) NOT NULL,
141 `indexname` varchar(40) NOT NULL,
142 `value` varchar(250) NOT NULL,
143 `biblionumbers` longtext NOT NULL,
144 KEY `indexname` (`server`,`indexname`),
145 KEY `value` (`server`,`value`))
146 ENGINE=InnoDB DEFAULT CHARSET=utf8;
148 print "Upgrade to $DBversion done (adding tags and nozebra tables )\n";
149 SetVersion ($DBversion);
152 $DBversion = "3.00.00.006";
153 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
154 $dbh->do("UPDATE issues SET issuedate=timestamp WHERE issuedate='0000-00-00'");
155 print "Upgrade to $DBversion done (filled issues.issuedate with timestamp)\n";
156 SetVersion ($DBversion);
159 $DBversion = "3.00.00.007";
160 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
161 $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')");
162 print "Upgrade to $DBversion done (set SessionStorage variable)\n";
163 SetVersion ($DBversion);
166 $DBversion = "3.00.00.008";
167 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
168 $dbh->do("ALTER TABLE `biblio` ADD `datecreated` DATE NOT NULL AFTER `timestamp` ;");
169 $dbh->do("UPDATE biblio SET datecreated=timestamp");
170 print "Upgrade to $DBversion done (biblio creation date)\n";
171 SetVersion ($DBversion);
174 $DBversion = "3.00.00.009";
175 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
177 # Create backups of call number columns
178 # in case default migration needs to be customized
180 # UPGRADE NOTE: temp_upg_biblioitems_call_num should be dropped
181 # after call numbers have been transformed to the new structure
183 # Not bothering to do the same with deletedbiblioitems -- assume
184 # default is good enough.
185 $dbh->do("CREATE TABLE `temp_upg_biblioitems_call_num` AS
186 SELECT `biblioitemnumber`, `biblionumber`,
187 `classification`, `dewey`, `subclass`,
189 FROM `biblioitems`");
191 # biblioitems changes
192 $dbh->do("ALTER TABLE `biblioitems` CHANGE COLUMN `volumeddesc` `volumedesc` TEXT,
193 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
194 ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
195 ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
196 ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
197 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
198 ADD `totalissues` INT(10) AFTER `cn_sort`");
200 # default mapping of call number columns:
201 # cn_class = concatentation of classification + dewey,
202 # trimmed to fit -- assumes that most users do not
203 # populate both classification and dewey in a single record
205 # cn_source = left null
208 # After upgrade, cn_sort will have to be set based on whatever
209 # default call number scheme user sets as a preference. Misc
210 # script will be added at some point to do that.
212 $dbh->do("UPDATE `biblioitems`
213 SET cn_class = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
218 # Now drop the old call number columns
219 $dbh->do("ALTER TABLE `biblioitems` DROP COLUMN `classification`,
221 DROP COLUMN `subclass`,
222 DROP COLUMN `lcsort`,
223 DROP COLUMN `ccode`");
225 # deletedbiblio changes
226 $dbh->do("ALTER TABLE `deletedbiblio` ALTER COLUMN `frameworkcode` SET DEFAULT '',
228 ADD `datecreated` DATE NOT NULL AFTER `timestamp`");
229 $dbh->do("UPDATE deletedbiblio SET datecreated = timestamp");
231 # deletedbiblioitems changes
232 $dbh->do("ALTER TABLE `deletedbiblioitems`
233 MODIFY `publicationyear` TEXT,
234 CHANGE `volumeddesc` `volumedesc` TEXT,
235 MODIFY `collectiontitle` MEDIUMTEXT DEFAULT NULL AFTER `volumedesc`,
236 MODIFY `collectionissn` TEXT DEFAULT NULL AFTER `collectiontitle`,
237 MODIFY `collectionvolume` MEDIUMTEXT DEFAULT NULL AFTER `collectionissn`,
238 MODIFY `editionstatement` TEXT DEFAULT NULL AFTER `collectionvolume`,
239 MODIFY `editionresponsibility` TEXT DEFAULT NULL AFTER `editionstatement`,
240 MODIFY `place` VARCHAR(255) DEFAULT NULL AFTER `size`,
241 MODIFY `marc` LONGBLOB,
242 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `url`,
243 ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
244 ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
245 ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
246 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
247 ADD `totalissues` INT(10) AFTER `cn_sort`,
248 ADD `marcxml` LONGTEXT NOT NULL AFTER `totalissues`,
249 ADD KEY `isbn` (`isbn`),
250 ADD KEY `publishercode` (`publishercode`)
253 $dbh->do("UPDATE `deletedbiblioitems`
254 SET `cn_class` = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
255 `cn_item` = `subclass`,
258 $dbh->do("ALTER TABLE `deletedbiblioitems`
259 DROP COLUMN `classification`,
261 DROP COLUMN `subclass`,
262 DROP COLUMN `lcsort`,
266 # deleteditems changes
267 $dbh->do("ALTER TABLE `deleteditems`
268 MODIFY `barcode` VARCHAR(20) DEFAULT NULL,
269 MODIFY `price` DECIMAL(8,2) DEFAULT NULL,
270 MODIFY `replacementprice` DECIMAL(8,2) DEFAULT NULL,
272 MODIFY `itemcallnumber` VARCHAR(30) DEFAULT NULL AFTER `wthdrawn`,
273 MODIFY `holdingbranch` VARCHAR(10) DEFAULT NULL,
275 MODIFY `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP AFTER `paidfor`,
277 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
278 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
279 ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
280 ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
281 ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`,
282 MODIFY `marc` LONGBLOB AFTER `uri`,
284 DROP KEY `itembarcodeidx`,
285 DROP KEY `itembinoidx`,
286 DROP KEY `itembibnoidx`,
287 ADD UNIQUE KEY `delitembarcodeidx` (`barcode`),
288 ADD KEY `delitembinoidx` (`biblioitemnumber`),
289 ADD KEY `delitembibnoidx` (`biblionumber`),
290 ADD KEY `delhomebranch` (`homebranch`),
291 ADD KEY `delholdingbranch` (`holdingbranch`)");
292 $dbh->do("UPDATE deleteditems SET `ccode` = `itype`");
293 $dbh->do("ALTER TABLE deleteditems DROP `itype`");
294 $dbh->do("UPDATE `deleteditems` SET `cn_sort` = `itemcallnumber`");
297 $dbh->do("ALTER TABLE `items` ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
298 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
299 ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
300 ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
301 ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`
303 $dbh->do("ALTER TABLE `items`
304 DROP KEY `itembarcodeidx`,
305 ADD UNIQUE KEY `itembarcodeidx` (`barcode`)");
307 # map items.itype to items.ccode and
308 # set cn_sort to itemcallnumber -- as with biblioitems.cn_sort,
309 # will have to be subsequently updated per user's default
310 # classification scheme
311 $dbh->do("UPDATE `items` SET `cn_sort` = `itemcallnumber`,
314 $dbh->do("ALTER TABLE `items` DROP `cutterextra`,
317 print "Upgrade to $DBversion done (major changes to biblio, biblioitems, items, and deleted* versions of same\n";
318 SetVersion ($DBversion);
321 $DBversion = "3.00.00.010";
322 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
323 $dbh->do("CREATE INDEX `userid` ON borrowers (`userid`) ");
324 print "Upgrade to $DBversion done (userid index added)\n";
325 SetVersion ($DBversion);
328 $DBversion = "3.00.00.011";
329 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
330 $dbh->do("ALTER TABLE `branchcategories` CHANGE `categorycode` `categorycode` varchar(10) ");
331 $dbh->do("ALTER TABLE `branchcategories` CHANGE `categoryname` `categoryname` varchar(32) ");
332 $dbh->do("ALTER TABLE `branchcategories` ADD COLUMN `categorytype` varchar(16) ");
333 $dbh->do("UPDATE `branchcategories` SET `categorytype` = 'properties'");
334 $dbh->do("ALTER TABLE `branchrelations` CHANGE `categorycode` `categorycode` varchar(10) ");
335 print "Upgrade to $DBversion done (added branchcategory type)\n";
336 SetVersion ($DBversion);
339 $DBversion = "3.00.00.012";
340 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
341 $dbh->do("CREATE TABLE `class_sort_rules` (
342 `class_sort_rule` varchar(10) NOT NULL default '',
343 `description` mediumtext,
344 `sort_routine` varchar(30) NOT NULL default '',
345 PRIMARY KEY (`class_sort_rule`),
346 UNIQUE KEY `class_sort_rule_idx` (`class_sort_rule`)
347 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
348 $dbh->do("CREATE TABLE `class_sources` (
349 `cn_source` varchar(10) NOT NULL default '',
350 `description` mediumtext,
351 `used` tinyint(4) NOT NULL default 0,
352 `class_sort_rule` varchar(10) NOT NULL default '',
353 PRIMARY KEY (`cn_source`),
354 UNIQUE KEY `cn_source_idx` (`cn_source`),
355 KEY `used_idx` (`used`),
356 CONSTRAINT `class_source_ibfk_1` FOREIGN KEY (`class_sort_rule`)
357 REFERENCES `class_sort_rules` (`class_sort_rule`)
358 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
359 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type)
360 VALUES('DefaultClassificationSource','ddc',
361 'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.', NULL,'free')");
362 $dbh->do("INSERT INTO `class_sort_rules` (`class_sort_rule`, `description`, `sort_routine`) VALUES
363 ('dewey', 'Default filing rules for DDC', 'Dewey'),
364 ('lcc', 'Default filing rules for LCC', 'LCC'),
365 ('generic', 'Generic call number filing rules', 'Generic')");
366 $dbh->do("INSERT INTO `class_sources` (`cn_source`, `description`, `used`, `class_sort_rule`) VALUES
367 ('ddc', 'Dewey Decimal Classification', 1, 'dewey'),
368 ('lcc', 'Library of Congress Classification', 1, 'lcc'),
369 ('udc', 'Universal Decimal Classification', 0, 'generic'),
370 ('sudocs', 'SuDoc Classification (U.S. GPO)', 0, 'generic'),
371 ('z', 'Other/Generic Classification Scheme', 0, 'generic')");
372 print "Upgrade to $DBversion done (classification sources added)\n";
373 SetVersion ($DBversion);
376 $DBversion = "3.00.00.013";
377 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
378 $dbh->do("CREATE TABLE `import_batches` (
379 `import_batch_id` int(11) NOT NULL auto_increment,
380 `template_id` int(11) default NULL,
381 `branchcode` varchar(10) default NULL,
382 `num_biblios` int(11) NOT NULL default 0,
383 `num_items` int(11) NOT NULL default 0,
384 `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
385 `overlay_action` enum('replace', 'create_new', 'use_template') NOT NULL default 'create_new',
386 `import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging',
387 `batch_type` enum('batch', 'z3950') NOT NULL default 'batch',
388 `file_name` varchar(100),
389 `comments` mediumtext,
390 PRIMARY KEY (`import_batch_id`),
391 KEY `branchcode` (`branchcode`)
392 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
393 $dbh->do("CREATE TABLE `import_records` (
394 `import_record_id` int(11) NOT NULL auto_increment,
395 `import_batch_id` int(11) NOT NULL,
396 `branchcode` varchar(10) default NULL,
397 `record_sequence` int(11) NOT NULL default 0,
398 `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
399 `import_date` DATE default NULL,
400 `marc` longblob NOT NULL,
401 `marcxml` longtext NOT NULL,
402 `marcxml_old` longtext NOT NULL,
403 `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio',
404 `overlay_status` enum('no_match', 'auto_match', 'manual_match', 'match_applied') NOT NULL default 'no_match',
405 `status` enum('error', 'staged', 'imported', 'reverted', 'items_reverted') NOT NULL default 'staged',
406 `import_error` mediumtext,
407 `encoding` varchar(40) NOT NULL default '',
408 `z3950random` varchar(40) default NULL,
409 PRIMARY KEY (`import_record_id`),
410 CONSTRAINT `import_records_ifbk_1` FOREIGN KEY (`import_batch_id`)
411 REFERENCES `import_batches` (`import_batch_id`) ON DELETE CASCADE ON UPDATE CASCADE,
412 KEY `branchcode` (`branchcode`),
413 KEY `batch_sequence` (`import_batch_id`, `record_sequence`)
414 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
415 $dbh->do("CREATE TABLE `import_record_matches` (
416 `import_record_id` int(11) NOT NULL,
417 `candidate_match_id` int(11) NOT NULL,
418 `score` int(11) NOT NULL default 0,
419 CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`)
420 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
421 KEY `record_score` (`import_record_id`, `score`)
422 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
423 $dbh->do("CREATE TABLE `import_biblios` (
424 `import_record_id` int(11) NOT NULL,
425 `matched_biblionumber` int(11) default NULL,
426 `control_number` varchar(25) default NULL,
427 `original_source` varchar(25) default NULL,
428 `title` varchar(128) default NULL,
429 `author` varchar(80) default NULL,
430 `isbn` varchar(14) default NULL,
431 `issn` varchar(9) default NULL,
432 `has_items` tinyint(1) NOT NULL default 0,
433 CONSTRAINT `import_biblios_ibfk_1` FOREIGN KEY (`import_record_id`)
434 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
435 KEY `matched_biblionumber` (`matched_biblionumber`),
436 KEY `title` (`title`),
438 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
439 $dbh->do("CREATE TABLE `import_items` (
440 `import_items_id` int(11) NOT NULL auto_increment,
441 `import_record_id` int(11) NOT NULL,
442 `itemnumber` int(11) default NULL,
443 `branchcode` varchar(10) default NULL,
444 `status` enum('error', 'staged', 'imported', 'reverted') NOT NULL default 'staged',
445 `marcxml` longtext NOT NULL,
446 `import_error` mediumtext,
447 PRIMARY KEY (`import_items_id`),
448 CONSTRAINT `import_items_ibfk_1` FOREIGN KEY (`import_record_id`)
449 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
450 KEY `itemnumber` (`itemnumber`),
451 KEY `branchcode` (`branchcode`)
452 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
454 $dbh->do("INSERT INTO `import_batches`
455 (`overlay_action`, `import_status`, `batch_type`, `file_name`)
456 SELECT distinct 'create_new', 'staged', 'z3950', `file`
457 FROM `marc_breeding`");
459 $dbh->do("INSERT INTO `import_records`
460 (`import_batch_id`, `import_record_id`, `record_sequence`, `marc`, `record_type`, `status`,
461 `encoding`, `z3950random`, `marcxml`, `marcxml_old`)
462 SELECT `import_batch_id`, `id`, 1, `marc`, 'biblio', 'staged', `encoding`, `z3950random`, '', ''
464 JOIN `import_batches` ON (`file_name` = `file`)");
466 $dbh->do("INSERT INTO `import_biblios`
467 (`import_record_id`, `title`, `author`, `isbn`)
468 SELECT `import_record_id`, `title`, `author`, `isbn`
470 JOIN `import_records` ON (`import_record_id` = `id`)");
472 $dbh->do("UPDATE `import_batches`
473 SET `num_biblios` = (
475 FROM `import_records`
476 WHERE `import_batch_id` = `import_batches`.`import_batch_id`
479 $dbh->do("DROP TABLE `marc_breeding`");
481 print "Upgrade to $DBversion done (import_batches et al. added)\n";
482 SetVersion ($DBversion);
485 $DBversion = "3.00.00.014";
486 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
487 $dbh->do("ALTER TABLE subscription ADD lastbranch VARCHAR(4)");
488 print "Upgrade to $DBversion done (userid index added)\n";
489 SetVersion ($DBversion);
492 $DBversion = "3.00.00.015";
493 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
494 $dbh->do("CREATE TABLE `saved_sql` (
495 `id` int(11) NOT NULL auto_increment,
496 `borrowernumber` int(11) default NULL,
497 `date_created` datetime default NULL,
498 `last_modified` datetime default NULL,
500 `last_run` datetime default NULL,
501 `report_name` varchar(255) default NULL,
502 `type` varchar(255) default NULL,
505 KEY boridx (`borrowernumber`)
506 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
507 $dbh->do("CREATE TABLE `saved_reports` (
508 `id` int(11) NOT NULL auto_increment,
509 `report_id` int(11) default NULL,
511 `date_run` datetime default NULL,
513 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
514 print "Upgrade to $DBversion done (saved_sql and saved_reports added)\n";
515 SetVersion ($DBversion);
518 $DBversion = "3.00.00.016";
519 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
520 $dbh->do(" CREATE TABLE reports_dictionary (
521 id int(11) NOT NULL auto_increment,
522 name varchar(255) default NULL,
524 date_created datetime default NULL,
525 date_modified datetime default NULL,
527 area int(11) default NULL,
529 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
530 print "Upgrade to $DBversion done (reports_dictionary) added)\n";
531 SetVersion ($DBversion);
534 $DBversion = "3.00.00.017";
535 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
536 $dbh->do("ALTER TABLE action_logs DROP PRIMARY KEY");
537 $dbh->do("ALTER TABLE action_logs ADD KEY timestamp (timestamp,user)");
538 $dbh->do("ALTER TABLE action_logs ADD action_id INT(11) NOT NULL FIRST");
539 $dbh->do("UPDATE action_logs SET action_id = if (\@a, \@a:=\@a+1, \@a:=1)");
540 $dbh->do("ALTER TABLE action_logs MODIFY action_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY");
541 print "Upgrade to $DBversion done (added column to action_logs)\n";
542 SetVersion ($DBversion);
545 $DBversion = "3.00.00.018";
546 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
547 $dbh->do("ALTER TABLE `zebraqueue`
548 ADD `done` INT NOT NULL DEFAULT '0',
549 ADD `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ;
551 print "Upgrade to $DBversion done (adding timestamp and done columns to zebraque table to improve problem tracking) added)\n";
552 SetVersion ($DBversion);
555 $DBversion = "3.00.00.019";
556 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
557 $dbh->do("ALTER TABLE biblio MODIFY biblionumber INT(11) NOT NULL AUTO_INCREMENT");
558 $dbh->do("ALTER TABLE biblioitems MODIFY biblioitemnumber INT(11) NOT NULL AUTO_INCREMENT");
559 $dbh->do("ALTER TABLE items MODIFY itemnumber INT(11) NOT NULL AUTO_INCREMENT");
560 print "Upgrade to $DBversion done (made bib/item PKs auto_increment)\n";
561 SetVersion ($DBversion);
564 $DBversion = "3.00.00.020";
565 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
566 $dbh->do("ALTER TABLE deleteditems
567 DROP KEY `delitembarcodeidx`,
568 ADD KEY `delitembarcodeidx` (`barcode`)");
569 print "Upgrade to $DBversion done (dropped uniqueness of key on deleteditems.barcode)\n";
570 SetVersion ($DBversion);
573 $DBversion = "3.00.00.021";
574 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
575 $dbh->do("ALTER TABLE items CHANGE homebranch homebranch VARCHAR(10)");
576 $dbh->do("ALTER TABLE deleteditems CHANGE homebranch homebranch VARCHAR(10)");
577 $dbh->do("ALTER TABLE statistics CHANGE branch branch VARCHAR(10)");
578 $dbh->do("ALTER TABLE subscription CHANGE lastbranch lastbranch VARCHAR(10)");
579 print "Upgrade to $DBversion done (extended missed branchcode columns to 10 chars)\n";
580 SetVersion ($DBversion);
583 $DBversion = "3.00.00.022";
584 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
585 $dbh->do("ALTER TABLE items
586 ADD `damaged` tinyint(1) default NULL AFTER notforloan");
587 $dbh->do("ALTER TABLE deleteditems
588 ADD `damaged` tinyint(1) default NULL AFTER notforloan");
589 print "Upgrade to $DBversion done (adding damaged column to items table)\n";
590 SetVersion ($DBversion);
593 $DBversion = "3.00.00.023";
594 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
595 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
596 VALUES ('yuipath','http://yui.yahooapis.com/2.3.1/build','Insert the path to YUI libraries','','free')");
597 print "Upgrade to $DBversion done (adding new system preference for controlling YUI path)\n";
598 SetVersion ($DBversion);
600 $DBversion = "3.00.00.024";
601 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
602 $dbh->do("ALTER TABLE biblioitems CHANGE itemtype itemtype VARCHAR(10)");
603 print "Upgrade to $DBversion done (changing itemtype to (10))\n";
604 SetVersion ($DBversion);
607 $DBversion = "3.00.00.025";
608 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
609 $dbh->do("ALTER TABLE items ADD COLUMN itype VARCHAR(10)");
610 $dbh->do("ALTER TABLE deleteditems ADD COLUMN itype VARCHAR(10) AFTER uri");
611 if(C4::Context->preference('item-level_itypes')){
612 $dbh->do('update items,biblioitems set items.itype=biblioitems.itemtype where items.biblionumber=biblioitems.biblionumber and itype is null');
614 print "Upgrade to $DBversion done (reintroduce items.itype - fill from itemtype)\n ";
615 SetVersion ($DBversion);
618 $DBversion = "3.00.00.026";
619 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
620 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
621 VALUES ('HomeOrHoldingBranch','homebranch','homebranch|holdingbranch','With independent branches turned on this decides whether to check the items holdingbranch or homebranch at circulatilon','choice')");
622 print "Upgrade to $DBversion done (adding new system preference for choosing whether homebranch or holdingbranch is checked in circulation)\n";
623 SetVersion ($DBversion);
626 $DBversion = "3.00.00.027";
627 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
628 $dbh->do("CREATE TABLE `marc_matchers` (
629 `matcher_id` int(11) NOT NULL auto_increment,
630 `code` varchar(10) NOT NULL default '',
631 `description` varchar(255) NOT NULL default '',
632 `record_type` varchar(10) NOT NULL default 'biblio',
633 `threshold` int(11) NOT NULL default 0,
634 PRIMARY KEY (`matcher_id`),
636 KEY `record_type` (`record_type`)
637 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
638 $dbh->do("CREATE TABLE `matchpoints` (
639 `matcher_id` int(11) NOT NULL,
640 `matchpoint_id` int(11) NOT NULL auto_increment,
641 `search_index` varchar(30) NOT NULL default '',
642 `score` int(11) NOT NULL default 0,
643 PRIMARY KEY (`matchpoint_id`),
644 CONSTRAINT `matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
645 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE
646 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
647 $dbh->do("CREATE TABLE `matchpoint_components` (
648 `matchpoint_id` int(11) NOT NULL,
649 `matchpoint_component_id` int(11) NOT NULL auto_increment,
650 sequence int(11) NOT NULL default 0,
651 tag varchar(3) NOT NULL default '',
652 subfields varchar(40) NOT NULL default '',
653 offset int(4) NOT NULL default 0,
654 length int(4) NOT NULL default 0,
655 PRIMARY KEY (`matchpoint_component_id`),
656 KEY `by_sequence` (`matchpoint_id`, `sequence`),
657 CONSTRAINT `matchpoint_components_ifbk_1` FOREIGN KEY (`matchpoint_id`)
658 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
659 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
660 $dbh->do("CREATE TABLE `matchpoint_component_norms` (
661 `matchpoint_component_id` int(11) NOT NULL,
662 `sequence` int(11) NOT NULL default 0,
663 `norm_routine` varchar(50) NOT NULL default '',
664 KEY `matchpoint_component_norms` (`matchpoint_component_id`, `sequence`),
665 CONSTRAINT `matchpoint_component_norms_ifbk_1` FOREIGN KEY (`matchpoint_component_id`)
666 REFERENCES `matchpoint_components` (`matchpoint_component_id`) ON DELETE CASCADE ON UPDATE CASCADE
667 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
668 $dbh->do("CREATE TABLE `matcher_matchpoints` (
669 `matcher_id` int(11) NOT NULL,
670 `matchpoint_id` int(11) NOT NULL,
671 CONSTRAINT `matcher_matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
672 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
673 CONSTRAINT `matcher_matchpoints_ifbk_2` FOREIGN KEY (`matchpoint_id`)
674 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
675 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
676 $dbh->do("CREATE TABLE `matchchecks` (
677 `matcher_id` int(11) NOT NULL,
678 `matchcheck_id` int(11) NOT NULL auto_increment,
679 `source_matchpoint_id` int(11) NOT NULL,
680 `target_matchpoint_id` int(11) NOT NULL,
681 PRIMARY KEY (`matchcheck_id`),
682 CONSTRAINT `matcher_matchchecks_ifbk_1` FOREIGN KEY (`matcher_id`)
683 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
684 CONSTRAINT `matcher_matchchecks_ifbk_2` FOREIGN KEY (`source_matchpoint_id`)
685 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE,
686 CONSTRAINT `matcher_matchchecks_ifbk_3` FOREIGN KEY (`target_matchpoint_id`)
687 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
688 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
689 print "Upgrade to $DBversion done (added C4::Matcher serialization tables)\n ";
690 SetVersion ($DBversion);
693 $DBversion = "3.00.00.028";
694 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
695 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
696 VALUES ('canreservefromotherbranches','1','','With Independent branches on, can a user from one library reserve an item from another library','YesNo')");
697 print "Upgrade to $DBversion done (adding new system preference for changing reserve/holds behaviour with independent branches)\n";
698 SetVersion ($DBversion);
702 $DBversion = "3.00.00.029";
703 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
704 $dbh->do("ALTER TABLE `import_batches` ADD `matcher_id` int(11) NULL AFTER `import_batch_id`");
705 print "Upgrade to $DBversion done (adding matcher_id to import_batches)\n";
706 SetVersion ($DBversion);
709 $DBversion = "3.00.00.030";
710 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
712 CREATE TABLE services_throttle (
713 service_type varchar(10) NOT NULL default '',
714 service_count varchar(45) default NULL,
715 PRIMARY KEY (service_type)
716 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
718 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
719 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')");
720 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
721 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')");
722 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
723 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')");
724 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
725 VALUES ('XISBNDailyLimit',499,'','The xISBN Web service is free for non-commercial use when usage does not exceed 500 requests per day','free')");
726 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
727 VALUES ('PINESISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use PINES OISBN web service in the Editions tab on the detail pages.','YesNo')");
728 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
729 VALUES ('ThingISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use the ThingISBN web service in the Editions tab on the detail pages.','YesNo')");
730 print "Upgrade to $DBversion done (adding services throttle table and sysprefs for xISBN)\n";
731 SetVersion ($DBversion);
734 $DBversion = "3.00.00.031";
735 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
737 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryStemming',1,'If ON, enables query stemming',NULL,'YesNo')");
738 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryFuzzy',1,'If ON, enables fuzzy option for searches',NULL,'YesNo')");
739 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryWeightFields',1,'If ON, enables field weighting',NULL,'YesNo')");
740 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('WebBasedSelfCheck',0,'If ON, enables the web-based self-check system',NULL,'YesNo')");
741 $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')");
742 $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')");
743 $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')");
744 $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')");
745 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('defaultSortOrder',NULL,'Specify the default sort order','asc|dsc|az|za','Choice')");
746 $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')");
747 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACdefaultSortOrder',NULL,'Specify the default sort order','asc|dsc|za|az','Choice')");
748 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('staffClientBaseURL','','Specify the base URL of the staff client',NULL,'free')");
749 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('minPasswordLength',3,'Specify the minimum length of a patron/staff password',NULL,'free')");
750 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('noItemTypeImages',0,'If ON, disables item-type images',NULL,'YesNo')");
751 $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')");
752 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('holdCancelLength','','Specify how many days before a hold is canceled',NULL,'free')");
753 $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')");
754 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('finesMode','test','Choose the fines mode, test or production','test|production','Choice')");
755 $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')");
756 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeInputFilter','','If set, allows specification of a item barcode input filter','cuecat','Choice')");
757 $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')");
758 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('URLLinkText','','Text to display as the link anchor in the OPAC',NULL,'free')");
759 $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')");
760 $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')");
761 $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')");
762 $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')");
763 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACUserCSS',0,'Add CSS to be included in the OPAC',NULL,'free')");
765 print "Upgrade to $DBversion done (adding additional system preference)\n";
766 SetVersion ($DBversion);
769 $DBversion = "3.00.00.032";
770 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
771 $dbh->do("UPDATE `marc_subfield_structure` SET `kohafield` = 'items.wthdrawn' WHERE `kohafield` = 'items.withdrawn'");
772 print "Upgrade to $DBversion done (fixed MARC framework references to items.withdrawn)\n";
773 SetVersion ($DBversion);
776 $DBversion = "3.00.00.033";
777 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
778 $dbh->do("INSERT INTO `userflags` VALUES(17,'staffaccess','Modify login / permissions for staff users',0)");
779 print "Upgrade to $DBversion done (Adding permissions flag for staff member access modification. )\n";
780 SetVersion ($DBversion);
783 $DBversion = "3.00.00.034";
784 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
785 $dbh->do("ALTER TABLE `virtualshelves` ADD COLUMN `sortfield` VARCHAR(16) ");
786 print "Upgrade to $DBversion done (Adding sortfield for Virtual Shelves. )\n";
787 SetVersion ($DBversion);
790 $DBversion = "3.00.00.035";
791 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
792 $dbh->do("UPDATE marc_subfield_structure
793 SET authorised_value = 'cn_source'
794 WHERE kohafield IN ('items.cn_source', 'biblioitems.cn_source')
795 AND (authorised_value is NULL OR authorised_value = '')");
796 print "Upgrade to $DBversion done (MARC frameworks: make classification source a drop-down)\n";
797 SetVersion ($DBversion);
800 $DBversion = "3.00.00.036";
801 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
802 $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');");
803 print "Upgrade to $DBversion done (OPACItemsResultsDisplay systempreference added)\n";
804 SetVersion ($DBversion);
807 $DBversion = "3.00.00.037";
808 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
809 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactfirstname` varchar(255)");
810 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactsurname` varchar(255)");
811 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress1` varchar(255)");
812 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress2` varchar(255)");
813 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress3` varchar(255)");
814 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactzipcode` varchar(50)");
815 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactphone` varchar(50)");
816 print "Upgrade to $DBversion done (Adding Alternative Contact Person information to borrowers table)\n";
817 SetVersion ($DBversion);
820 $DBversion = "3.00.00.038";
821 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
822 $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'");
823 $dbh->do("DELETE FROM `systempreferences` WHERE variable='hideBiblioNumber'");
824 print "Upgrade to $DBversion done ('alter finesMode systempreference, remove superfluous syspref.')\n";
825 SetVersion ($DBversion);
828 $DBversion = "3.00.00.039";
829 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
830 $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')");
831 $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')");
832 $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')");
833 # $dbh->do("DELETE FROM `systempreferences` WHERE variable='HomeOrHoldingBranch'"); # Bug #2752
834 print "Upgrade to $DBversion done ('add circ sysprefs CircControl, finesCalendar, and uppercasesurnames, and delete HomeOrHoldingBranch.')\n";
835 SetVersion ($DBversion);
838 $DBversion = "3.00.00.040";
839 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
840 $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')");
841 $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')");
842 print "Upgrade to $DBversion done ('add circ sysprefs todaysIssuesDefaultSortOrder and previousIssuesDefaultSortOrder.')\n";
843 SetVersion ($DBversion);
847 $DBversion = "3.00.00.041";
848 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
849 # Strictly speaking it is not necessary to explicitly change
850 # NULL values to 0, because the ALTER TABLE statement will do that.
851 # However, setting them first avoids a warning.
852 $dbh->do("UPDATE items SET notforloan = 0 WHERE notforloan IS NULL");
853 $dbh->do("UPDATE items SET damaged = 0 WHERE damaged IS NULL");
854 $dbh->do("UPDATE items SET itemlost = 0 WHERE itemlost IS NULL");
855 $dbh->do("UPDATE items SET wthdrawn = 0 WHERE wthdrawn IS NULL");
856 $dbh->do("ALTER TABLE items
857 MODIFY notforloan tinyint(1) NOT NULL default 0,
858 MODIFY damaged tinyint(1) NOT NULL default 0,
859 MODIFY itemlost tinyint(1) NOT NULL default 0,
860 MODIFY wthdrawn tinyint(1) NOT NULL default 0");
861 $dbh->do("UPDATE deleteditems SET notforloan = 0 WHERE notforloan IS NULL");
862 $dbh->do("UPDATE deleteditems SET damaged = 0 WHERE damaged IS NULL");
863 $dbh->do("UPDATE deleteditems SET itemlost = 0 WHERE itemlost IS NULL");
864 $dbh->do("UPDATE deleteditems SET wthdrawn = 0 WHERE wthdrawn IS NULL");
865 $dbh->do("ALTER TABLE deleteditems
866 MODIFY notforloan tinyint(1) NOT NULL default 0,
867 MODIFY damaged tinyint(1) NOT NULL default 0,
868 MODIFY itemlost tinyint(1) NOT NULL default 0,
869 MODIFY wthdrawn tinyint(1) NOT NULL default 0");
870 print "Upgrade to $DBversion done (disallow NULL in several item status columns)\n";
871 SetVersion ($DBversion);
874 $DBversion = "3.00.00.04";
875 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
876 $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
877 print "Upgrade to $DBversion done (disallow NULL in aqbooksellers.name; part of fix for bug 1251)\n";
878 SetVersion ($DBversion);
881 $DBversion = "3.00.00.043";
882 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
883 $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");
884 print "Upgrade to $DBversion done (currency table: add symbol and timestamp columns)\n";
885 SetVersion ($DBversion);
888 $DBversion = "3.00.00.044";
889 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
890 $dbh->do("ALTER TABLE deletedborrowers
891 ADD `altcontactfirstname` varchar(255) default NULL,
892 ADD `altcontactsurname` varchar(255) default NULL,
893 ADD `altcontactaddress1` varchar(255) default NULL,
894 ADD `altcontactaddress2` varchar(255) default NULL,
895 ADD `altcontactaddress3` varchar(255) default NULL,
896 ADD `altcontactzipcode` varchar(50) default NULL,
897 ADD `altcontactphone` varchar(50) default NULL
899 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
900 ('OPACBaseURL',NULL,'Specify the Base URL of the OPAC, e.g., opac.mylibrary.com, the http:// will be added automatically by Koha.',NULL,'Free'),
901 ('language','en','Set the default language in the staff client.',NULL,'Languages'),
902 ('QueryAutoTruncate',1,'If ON, query truncation is enabled by default',NULL,'YesNo'),
903 ('QueryRemoveStopwords',0,'If ON, stopwords listed in the Administration area will be removed from queries',NULL,'YesNo')
905 print "Upgrade to $DBversion done (syncing deletedborrowers table with borrowers table)\n";
906 SetVersion ($DBversion);
909 #-- http://www.w3.org/International/articles/language-tags/
912 $DBversion = "3.00.00.045";
913 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
915 CREATE TABLE language_subtag_registry (
917 type varchar(25), -- language-script-region-variant-extension-privateuse
918 description varchar(25), -- only one of the possible descriptions for ease of reference, see language_descriptions for the complete list
920 KEY `subtag` (`subtag`)
921 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
923 #-- TODO: add suppress_scripts
924 #-- this maps three letter codes defined in iso639.2 back to their
925 #-- two letter equivilents in rfc4646 (LOC maintains iso639+)
926 $dbh->do("CREATE TABLE language_rfc4646_to_iso639 (
927 rfc4646_subtag varchar(25),
928 iso639_2_code varchar(25),
929 KEY `rfc4646_subtag` (`rfc4646_subtag`)
930 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
932 $dbh->do("CREATE TABLE language_descriptions (
936 description varchar(255),
938 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
940 #-- bi-directional support, keyed by script subcode
941 $dbh->do("CREATE TABLE language_script_bidi (
942 rfc4646_subtag varchar(25), -- script subtag, Arab, Hebr, etc.
943 bidi varchar(3), -- rtl ltr
944 KEY `rfc4646_subtag` (`rfc4646_subtag`)
945 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
947 #-- BIDI Stuff, Arabic and Hebrew
948 $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
949 VALUES( 'Arab', 'rtl')");
950 $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
951 VALUES( 'Hebr', 'rtl')");
953 #-- TODO: need to map language subtags to script subtags for detection
954 #-- of bidi when script is not specified (like ar, he)
955 $dbh->do("CREATE TABLE language_script_mapping (
956 language_subtag varchar(25),
957 script_subtag varchar(25),
958 KEY `language_subtag` (`language_subtag`)
959 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
961 #-- Default mappings between script and language subcodes
962 $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
963 VALUES( 'ar', 'Arab')");
964 $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
965 VALUES( 'he', 'Hebr')");
967 print "Upgrade to $DBversion done (adding language subtag registry and basic BiDi support NOTE: You should import the subtag registry SQL)\n";
968 SetVersion ($DBversion);
971 $DBversion = "3.00.00.046";
972 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
973 $dbh->do("ALTER TABLE `subscription` CHANGE `numberlength` `numberlength` int(11) default '0' ,
974 CHANGE `weeklength` `weeklength` int(11) default '0'");
975 $dbh->do("CREATE TABLE `serialitems` (`serialid` int(11) NOT NULL, `itemnumber` int(11) NOT NULL, UNIQUE KEY `serialididx` (`serialid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
976 $dbh->do("INSERT INTO `serialitems` SELECT `serialid`,`itemnumber` from serial where NOT ISNULL(itemnumber) && itemnumber <> '' && itemnumber NOT LIKE '%,%'");
977 print "Upgrade to $DBversion done (Add serialitems table to link serial issues to items. )\n";
978 SetVersion ($DBversion);
981 $DBversion = "3.00.00.047";
982 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
983 $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');");
984 print "Upgrade to $DBversion done ( Added OpacRenewalAllowed syspref )\n";
985 SetVersion ($DBversion);
988 $DBversion = "3.00.00.048";
989 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
990 $dbh->do("ALTER TABLE `items` ADD `more_subfields_xml` longtext default NULL AFTER `itype`");
991 print "Upgrade to $DBversion done (added items.more_subfields_xml)\n";
992 SetVersion ($DBversion);
995 $DBversion = "3.00.00.049";
996 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
997 $dbh->do("ALTER TABLE `z3950servers` ADD `encoding` text default NULL AFTER type ");
998 print "Upgrade to $DBversion done ( Added encoding field to z3950servers table )\n";
999 SetVersion ($DBversion);
1002 $DBversion = "3.00.00.050";
1003 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1004 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHighlightedWords','0','If Set, query matched terms are highlighted in OPAC',NULL,'YesNo');");
1005 print "Upgrade to $DBversion done ( Added OpacHighlightedWords syspref )\n";
1006 SetVersion ($DBversion);
1009 $DBversion = "3.00.00.051";
1010 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1011 $dbh->do("UPDATE systempreferences SET explanation = 'Define the current theme for the OPAC interface.' WHERE variable = 'opacthemes';");
1012 print "Upgrade to $DBversion done ( Corrected opacthemes explanation. )\n";
1013 SetVersion ($DBversion);
1016 $DBversion = "3.00.00.052";
1017 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1018 $dbh->do("ALTER TABLE `deleteditems` ADD `more_subfields_xml` LONGTEXT DEFAULT NULL AFTER `itype`");
1019 print "Upgrade to $DBversion done ( Adding missing column to deleteditems table. )\n";
1020 SetVersion ($DBversion);
1023 $DBversion = "3.00.00.053";
1024 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1025 $dbh->do("CREATE TABLE `printers_profile` (
1026 `prof_id` int(4) NOT NULL auto_increment,
1027 `printername` varchar(40) NOT NULL,
1028 `tmpl_id` int(4) NOT NULL,
1029 `paper_bin` varchar(20) NOT NULL,
1030 `offset_horz` float default NULL,
1031 `offset_vert` float default NULL,
1032 `creep_horz` float default NULL,
1033 `creep_vert` float default NULL,
1034 `unit` char(20) NOT NULL default 'POINT',
1035 PRIMARY KEY (`prof_id`),
1036 UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
1037 CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
1038 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1039 $dbh->do("CREATE TABLE `labels_profile` (
1040 `tmpl_id` int(4) NOT NULL,
1041 `prof_id` int(4) NOT NULL,
1042 UNIQUE KEY `tmpl_id` (`tmpl_id`),
1043 UNIQUE KEY `prof_id` (`prof_id`)
1044 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1045 print "Upgrade to $DBversion done ( Printer Profile tables added )\n";
1046 SetVersion ($DBversion);
1049 $DBversion = "3.00.00.054";
1050 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1051 $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';");
1052 print "Upgrade to $DBversion done ( Added another barcode autogeneration sequence to barcode.pl. )\n";
1053 SetVersion ($DBversion);
1056 $DBversion = "3.00.00.055";
1057 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1058 $dbh->do("ALTER TABLE `zebraqueue` ADD KEY `zebraqueue_lookup` (`server`, `biblio_auth_number`, `operation`, `done`)");
1059 print "Upgrade to $DBversion done ( Added index on zebraqueue. )\n";
1060 SetVersion ($DBversion);
1062 $DBversion = "3.00.00.056";
1063 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1064 if (C4::Context->preference("marcflavour") eq 'UNIMARC') {
1065 $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) ");
1067 $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) ");
1069 $dbh->do("ALTER TABLE `items` ADD `enumchron` VARCHAR(80) DEFAULT NULL;");
1070 print "Upgrade to $DBversion done ( Added item.enumchron column, and framework map to 952h )\n";
1071 SetVersion ($DBversion);
1074 $DBversion = "3.00.00.057";
1075 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1076 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH','0','if ON, OAI-PMH server is enabled',NULL,'YesNo');");
1077 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:archiveID','KOHA-OAI-TEST','OAI-PMH archive identification',NULL,'Free');");
1078 $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');");
1079 $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');");
1080 $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');");
1081 SetVersion ($DBversion);
1084 $DBversion = "3.00.00.058";
1085 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1086 $dbh->do("ALTER TABLE `opac_news`
1087 CHANGE `lang` `lang` VARCHAR( 25 )
1089 COLLATE utf8_general_ci
1090 NOT NULL default ''");
1091 print "Upgrade to $DBversion done ( lang field in opac_news made longer )\n";
1092 SetVersion ($DBversion);
1095 $DBversion = "3.00.00.059";
1096 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1098 $dbh->do("CREATE TABLE IF NOT EXISTS `labels_templates` (
1099 `tmpl_id` int(4) NOT NULL auto_increment,
1100 `tmpl_code` char(100) default '',
1101 `tmpl_desc` char(100) default '',
1102 `page_width` float default '0',
1103 `page_height` float default '0',
1104 `label_width` float default '0',
1105 `label_height` float default '0',
1106 `topmargin` float default '0',
1107 `leftmargin` float default '0',
1108 `cols` int(2) default '0',
1109 `rows` int(2) default '0',
1110 `colgap` float default '0',
1111 `rowgap` float default '0',
1112 `active` int(1) default NULL,
1113 `units` char(20) default 'PX',
1114 `fontsize` int(4) NOT NULL default '3',
1115 PRIMARY KEY (`tmpl_id`)
1116 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1117 $dbh->do("CREATE TABLE IF NOT EXISTS `printers_profile` (
1118 `prof_id` int(4) NOT NULL auto_increment,
1119 `printername` varchar(40) NOT NULL,
1120 `tmpl_id` int(4) NOT NULL,
1121 `paper_bin` varchar(20) NOT NULL,
1122 `offset_horz` float default NULL,
1123 `offset_vert` float default NULL,
1124 `creep_horz` float default NULL,
1125 `creep_vert` float default NULL,
1126 `unit` char(20) NOT NULL default 'POINT',
1127 PRIMARY KEY (`prof_id`),
1128 UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
1129 CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
1130 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1131 print "Upgrade to $DBversion done ( Added labels_templates table if it did not exist. )\n";
1132 SetVersion ($DBversion);
1135 $DBversion = "3.00.00.060";
1136 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1137 $dbh->do("CREATE TABLE IF NOT EXISTS `patronimage` (
1138 `cardnumber` varchar(16) NOT NULL,
1139 `mimetype` varchar(15) NOT NULL,
1140 `imagefile` mediumblob NOT NULL,
1141 PRIMARY KEY (`cardnumber`),
1142 CONSTRAINT `patronimage_fk1` FOREIGN KEY (`cardnumber`) REFERENCES `borrowers` (`cardnumber`) ON DELETE CASCADE ON UPDATE CASCADE
1143 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1144 print "Upgrade to $DBversion done ( Added patronimage table. )\n";
1145 SetVersion ($DBversion);
1148 $DBversion = "3.00.00.061";
1149 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1150 $dbh->do("ALTER TABLE labels_templates ADD COLUMN font char(10) NOT NULL DEFAULT 'TR';");
1151 print "Upgrade to $DBversion done ( Added font column to labels_templates )\n";
1152 SetVersion ($DBversion);
1155 $DBversion = "3.00.00.062";
1156 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1157 $dbh->do("CREATE TABLE `old_issues` (
1158 `borrowernumber` int(11) default NULL,
1159 `itemnumber` int(11) default NULL,
1160 `date_due` date default NULL,
1161 `branchcode` varchar(10) default NULL,
1162 `issuingbranch` varchar(18) default NULL,
1163 `returndate` date default NULL,
1164 `lastreneweddate` date default NULL,
1165 `return` varchar(4) default NULL,
1166 `renewals` tinyint(4) default NULL,
1167 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1168 `issuedate` date default NULL,
1169 KEY `old_issuesborridx` (`borrowernumber`),
1170 KEY `old_issuesitemidx` (`itemnumber`),
1171 KEY `old_bordate` (`borrowernumber`,`timestamp`),
1172 CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1173 ON DELETE SET NULL ON UPDATE SET NULL,
1174 CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1175 ON DELETE SET NULL ON UPDATE SET NULL
1176 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1177 $dbh->do("CREATE TABLE `old_reserves` (
1178 `borrowernumber` int(11) default NULL,
1179 `reservedate` date default NULL,
1180 `biblionumber` int(11) default NULL,
1181 `constrainttype` varchar(1) default NULL,
1182 `branchcode` varchar(10) default NULL,
1183 `notificationdate` date default NULL,
1184 `reminderdate` date default NULL,
1185 `cancellationdate` date default NULL,
1186 `reservenotes` mediumtext,
1187 `priority` smallint(6) default NULL,
1188 `found` varchar(1) default NULL,
1189 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1190 `itemnumber` int(11) default NULL,
1191 `waitingdate` date default NULL,
1192 KEY `old_reserves_borrowernumber` (`borrowernumber`),
1193 KEY `old_reserves_biblionumber` (`biblionumber`),
1194 KEY `old_reserves_itemnumber` (`itemnumber`),
1195 KEY `old_reserves_branchcode` (`branchcode`),
1196 CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1197 ON DELETE SET NULL ON UPDATE SET NULL,
1198 CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
1199 ON DELETE SET NULL ON UPDATE SET NULL,
1200 CONSTRAINT `old_reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1201 ON DELETE SET NULL ON UPDATE SET NULL
1202 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1204 # move closed transactions to old_* tables
1205 $dbh->do("INSERT INTO old_issues SELECT * FROM issues WHERE returndate IS NOT NULL");
1206 $dbh->do("DELETE FROM issues WHERE returndate IS NOT NULL");
1207 $dbh->do("INSERT INTO old_reserves SELECT * FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
1208 $dbh->do("DELETE FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
1210 print "Upgrade to $DBversion done ( Added old_issues and old_reserves tables )\n";
1211 SetVersion ($DBversion);
1214 $DBversion = "3.00.00.063";
1215 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1216 $dbh->do("ALTER TABLE deleteditems
1217 CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT DEFAULT NULL,
1218 ADD COLUMN enumchron VARCHAR(80) DEFAULT NULL AFTER more_subfields_xml,
1219 ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
1220 $dbh->do("ALTER TABLE items
1221 CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT,
1222 ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
1223 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";
1224 SetVersion ($DBversion);
1227 $DBversion = "3.00.00.064";
1228 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1229 $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');");
1230 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSAccessKeyID','','See: http://aws.amazon.com','','free');");
1231 $dbh->do("DELETE FROM `systempreferences` WHERE variable='AmazonDevKey';");
1232 $dbh->do("DELETE FROM `systempreferences` WHERE variable='XISBNAmazonSimilarItems';");
1233 $dbh->do("DELETE FROM `systempreferences` WHERE variable='OPACXISBNAmazonSimilarItems';");
1234 print "Upgrade to $DBversion done (IMPORTANT: Upgrading to Amazon.com Associates Web Service 4.0 ) \n";
1235 SetVersion ($DBversion);
1238 $DBversion = "3.00.00.065";
1239 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1240 $dbh->do("CREATE TABLE `patroncards` (
1241 `cardid` int(11) NOT NULL auto_increment,
1242 `batch_id` varchar(10) NOT NULL default '1',
1243 `borrowernumber` int(11) NOT NULL,
1244 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1245 PRIMARY KEY (`cardid`),
1246 KEY `patroncards_ibfk_1` (`borrowernumber`),
1247 CONSTRAINT `patroncards_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1248 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1249 print "Upgrade to $DBversion done (Adding patroncards table for patroncards generation feature. ) \n";
1250 SetVersion ($DBversion);
1253 $DBversion = "3.00.00.066";
1254 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1255 $dbh->do("ALTER TABLE `virtualshelfcontents` MODIFY `dateadded` timestamp NOT NULL
1256 DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;
1258 print "Upgrade to $DBversion done (fix for bug 1873: virtualshelfcontents dateadded column empty. ) \n";
1259 SetVersion ($DBversion);
1262 $DBversion = "3.00.00.067";
1263 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1264 $dbh->do("UPDATE systempreferences SET explanation = 'Enable patron images for the Staff Client', type = 'YesNo' WHERE variable = 'patronimages'");
1265 print "Upgrade to $DBversion done (Updating patronimages syspref to reflect current kohastructure.sql. ) \n";
1266 SetVersion ($DBversion);
1269 $DBversion = "3.00.00.068";
1270 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1271 $dbh->do("CREATE TABLE `permissions` (
1272 `module_bit` int(11) NOT NULL DEFAULT 0,
1273 `code` varchar(30) DEFAULT NULL,
1274 `description` varchar(255) DEFAULT NULL,
1275 PRIMARY KEY (`module_bit`, `code`),
1276 CONSTRAINT `permissions_ibfk_1` FOREIGN KEY (`module_bit`) REFERENCES `userflags` (`bit`)
1277 ON DELETE CASCADE ON UPDATE CASCADE
1278 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1279 $dbh->do("CREATE TABLE `user_permissions` (
1280 `borrowernumber` int(11) NOT NULL DEFAULT 0,
1281 `module_bit` int(11) NOT NULL DEFAULT 0,
1282 `code` varchar(30) DEFAULT NULL,
1283 CONSTRAINT `user_permissions_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1284 ON DELETE CASCADE ON UPDATE CASCADE,
1285 CONSTRAINT `user_permissions_ibfk_2` FOREIGN KEY (`module_bit`, `code`)
1286 REFERENCES `permissions` (`module_bit`, `code`)
1287 ON DELETE CASCADE ON UPDATE CASCADE
1288 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1290 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES
1291 (13, 'edit_news', 'Write news for the OPAC and staff interfaces'),
1292 (13, 'label_creator', 'Create printable labels and barcodes from catalog and patron data'),
1293 (13, 'edit_calendar', 'Define days when the library is closed'),
1294 (13, 'moderate_comments', 'Moderate patron comments'),
1295 (13, 'edit_notices', 'Define notices'),
1296 (13, 'edit_notice_status_triggers', 'Set notice/status triggers for overdue items'),
1297 (13, 'view_system_logs', 'Browse the system logs'),
1298 (13, 'inventory', 'Perform inventory (stocktaking) of your catalogue'),
1299 (13, 'stage_marc_import', 'Stage MARC records into the reservoir'),
1300 (13, 'manage_staged_marc', 'Managed staged MARC records, including completing and reversing imports'),
1301 (13, 'export_catalog', 'Export bibliographic and holdings data'),
1302 (13, 'import_patrons', 'Import patron data'),
1303 (13, 'delete_anonymize_patrons', 'Delete old borrowers and anonymize circulation history (deletes borrower reading history)'),
1304 (13, 'batch_upload_patron_images', 'Upload patron images in batch or one at a time'),
1305 (13, 'schedule_tasks', 'Schedule tasks to run')");
1307 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('GranularPermissions','0','Use detailed staff user permissions',NULL,'YesNo')");
1309 print "Upgrade to $DBversion done (adding permissions and user_permissions tables and GranularPermissions syspref) \n";
1310 SetVersion ($DBversion);
1312 $DBversion = "3.00.00.069";
1313 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1314 $dbh->do("ALTER TABLE labels_conf CHANGE COLUMN class classification int(1) DEFAULT NULL;");
1315 print "Upgrade to $DBversion done ( Correcting columname in labels_conf )\n";
1316 SetVersion ($DBversion);
1319 $DBversion = "3.00.00.070";
1320 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1321 $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='yuipath'");
1323 my ($value) = $sth->fetchrow;
1324 $value =~ s/2.3.1/2.5.1/;
1325 $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='yuipath';");
1326 print "Update yuipath syspref to 2.5.1 if necessary\n";
1327 SetVersion ($DBversion);
1330 $DBversion = "3.00.00.071";
1331 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1332 $dbh->do(" ALTER TABLE `subscription` ADD `serialsadditems` TINYINT( 1 ) NOT NULL DEFAULT '0';");
1333 # fill the new field with the previous systempreference value, then drop the syspref
1334 my $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='serialsadditems'");
1336 my ($serialsadditems) = $sth->fetchrow();
1337 $dbh->do("UPDATE subscription SET serialsadditems=$serialsadditems");
1338 $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
1339 print "Upgrade to $DBversion done ( moving serialsadditems from syspref to subscription )\n";
1340 SetVersion ($DBversion);
1343 $DBversion = "3.00.00.072";
1344 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1345 $dbh->do("ALTER TABLE labels_conf ADD COLUMN formatstring mediumtext DEFAULT NULL AFTER printingtype");
1346 print "Upgrade to $DBversion done ( Adding format string to labels generator. )\n";
1347 SetVersion ($DBversion);
1350 $DBversion = "3.00.00.073";
1351 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1352 $dbh->do("DROP TABLE IF EXISTS `tags_all`;");
1354 CREATE TABLE `tags_all` (
1355 `tag_id` int(11) NOT NULL auto_increment,
1356 `borrowernumber` int(11) NOT NULL,
1357 `biblionumber` int(11) NOT NULL,
1358 `term` varchar(255) NOT NULL,
1359 `language` int(4) default NULL,
1360 `date_created` datetime NOT NULL,
1361 PRIMARY KEY (`tag_id`),
1362 KEY `tags_borrowers_fk_1` (`borrowernumber`),
1363 KEY `tags_biblionumber_fk_1` (`biblionumber`),
1364 CONSTRAINT `tags_borrowers_fk_1` FOREIGN KEY (`borrowernumber`)
1365 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1366 CONSTRAINT `tags_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
1367 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1368 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1370 $dbh->do("DROP TABLE IF EXISTS `tags_approval`;");
1372 CREATE TABLE `tags_approval` (
1373 `term` varchar(255) NOT NULL,
1374 `approved` int(1) NOT NULL default '0',
1375 `date_approved` datetime default NULL,
1376 `approved_by` int(11) default NULL,
1377 `weight_total` int(9) NOT NULL default '1',
1378 PRIMARY KEY (`term`),
1379 KEY `tags_approval_borrowers_fk_1` (`approved_by`),
1380 CONSTRAINT `tags_approval_borrowers_fk_1` FOREIGN KEY (`approved_by`)
1381 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1382 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1384 $dbh->do("DROP TABLE IF EXISTS `tags_index`;");
1386 CREATE TABLE `tags_index` (
1387 `term` varchar(255) NOT NULL,
1388 `biblionumber` int(11) NOT NULL,
1389 `weight` int(9) NOT NULL default '1',
1390 PRIMARY KEY (`term`,`biblionumber`),
1391 KEY `tags_index_biblionumber_fk_1` (`biblionumber`),
1392 CONSTRAINT `tags_index_term_fk_1` FOREIGN KEY (`term`)
1393 REFERENCES `tags_approval` (`term`) ON DELETE CASCADE ON UPDATE CASCADE,
1394 CONSTRAINT `tags_index_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
1395 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1396 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1399 INSERT INTO `systempreferences` VALUES
1400 ('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=',''),
1401 ('BakerTaylorEnabled','0','','Enable or disable all Baker & Taylor features.','YesNo'),
1402 ('BakerTaylorPassword','','','Baker & Taylor Password for Content Cafe (external content)','Textarea'),
1403 ('BakerTaylorUsername','','','Baker & Taylor Username for Content Cafe (external content)','Textarea'),
1404 ('TagsEnabled','1','','Enables or disables all tagging features. This is the main switch for tags.','YesNo'),
1405 ('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.',''),
1406 ('TagsInputOnDetail','1','','Allow users to input tags from the detail page.', 'YesNo'),
1407 ('TagsInputOnList', '0','','Allow users to input tags from the search results list.', 'YesNo'),
1408 ('TagsModeration', NULL,'','Require tags from patrons to be approved before becoming visible.','YesNo'),
1409 ('TagsShowOnDetail','10','','Number of tags to display on detail page. 0 is off.', 'Integer'),
1410 ('TagsShowOnList', '6','','Number of tags to display on search results list. 0 is off.','Integer')
1412 print "Upgrade to $DBversion done (Baker/Taylor,Tags: sysprefs and tables (tags_all, tags_index, tags_approval)) \n";
1413 SetVersion ($DBversion);
1416 $DBversion = "3.00.00.074";
1417 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1418 $dbh->do( q(update itemtypes set imageurl = concat( 'npl/', imageurl )
1419 where imageurl not like 'http%'
1420 and imageurl is not NULL
1421 and imageurl != '') );
1422 print "Upgrade to $DBversion done (updating imagetype.imageurls to reflect new icon locations.)\n";
1423 SetVersion ($DBversion);
1426 $DBversion = "3.00.00.075";
1427 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1428 $dbh->do( q(alter table authorised_values add imageurl varchar(200) default NULL) );
1429 print "Upgrade to $DBversion done (adding imageurl field to authorised_values table)\n";
1430 SetVersion ($DBversion);
1433 $DBversion = "3.00.00.076";
1434 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1435 $dbh->do("ALTER TABLE import_batches
1436 ADD COLUMN nomatch_action enum('create_new', 'ignore') NOT NULL default 'create_new' AFTER overlay_action");
1437 $dbh->do("ALTER TABLE import_batches
1438 ADD COLUMN item_action enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore')
1439 NOT NULL default 'always_add' AFTER nomatch_action");
1440 $dbh->do("ALTER TABLE import_batches
1441 MODIFY overlay_action enum('replace', 'create_new', 'use_template', 'ignore')
1442 NOT NULL default 'create_new'");
1443 $dbh->do("ALTER TABLE import_records
1444 MODIFY status enum('error', 'staged', 'imported', 'reverted', 'items_reverted',
1445 'ignored') NOT NULL default 'staged'");
1446 $dbh->do("ALTER TABLE import_items
1447 MODIFY status enum('error', 'staged', 'imported', 'reverted', 'ignored') NOT NULL default 'staged'");
1449 print "Upgrade to $DBversion done (changes to import_batches and import_records)\n";
1450 SetVersion ($DBversion);
1453 $DBversion = "3.00.00.077";
1454 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1455 # drop these tables only if they exist and none of them are empty
1456 # these tables are not defined in the packaged 2.2.9, but since it is believed
1457 # that at least one library may be using them in a post-2.2.9 but pre-3.0 Koha,
1458 # some care is taken.
1459 my ($print_error) = $dbh->{PrintError};
1460 $dbh->{PrintError} = 0;
1461 my ($raise_error) = $dbh->{RaiseError};
1462 $dbh->{RaiseError} = 1;
1466 eval { $count = $dbh->do("SELECT 1 FROM categorytable"); };
1470 eval { $count = $dbh->do("SELECT 1 FROM mediatypetable"); };
1474 eval { $count = $dbh->do("SELECT 1 FROM subcategorytable"); };
1480 $dbh->do("DROP TABLE IF EXISTS `categorytable`");
1481 $dbh->do("DROP TABLE IF EXISTS `mediatypetable`");
1482 $dbh->do("DROP TABLE IF EXISTS `subcategorytable`");
1485 $dbh->{PrintError} = $print_error;
1486 $dbh->{RaiseError} = $raise_error;
1487 print "Upgrade to $DBversion done (drop categorytable, subcategorytable, and mediatypetable)\n";
1488 SetVersion ($DBversion);
1491 $DBversion = "3.00.00.078";
1492 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1493 my ($print_error) = $dbh->{PrintError};
1494 $dbh->{PrintError} = 0;
1496 unless ($dbh->do("SELECT 1 FROM browser")) {
1497 $dbh->{PrintError} = $print_error;
1498 $dbh->do("CREATE TABLE `browser` (
1499 `level` int(11) NOT NULL,
1500 `classification` varchar(20) NOT NULL,
1501 `description` varchar(255) NOT NULL,
1502 `number` bigint(20) NOT NULL,
1503 `endnode` tinyint(4) NOT NULL
1504 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1506 $dbh->{PrintError} = $print_error;
1507 print "Upgrade to $DBversion done (add browser table if not already present)\n";
1508 SetVersion ($DBversion);
1511 $DBversion = "3.00.00.079";
1512 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1513 my ($print_error) = $dbh->{PrintError};
1514 $dbh->{PrintError} = 0;
1516 $dbh->do("INSERT INTO `systempreferences` (variable, value,options,type, explanation)VALUES
1517 ('AddPatronLists','categorycode','categorycode|category_type','Choice','Allow user to choose what list to pick up from when adding patrons')");
1518 print "Upgrade to $DBversion done (add browser table if not already present)\n";
1519 SetVersion ($DBversion);
1522 $DBversion = "3.00.00.080";
1523 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1524 $dbh->do("ALTER TABLE subscription CHANGE monthlength monthlength int(11) default '0'");
1525 $dbh->do("ALTER TABLE deleteditems MODIFY marc LONGBLOB AFTER copynumber");
1526 $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
1527 print "Upgrade to $DBversion done (catch up on DB schema changes since alpha and beta)\n";
1528 SetVersion ($DBversion);
1531 $DBversion = "3.00.00.081";
1532 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1533 $dbh->do("CREATE TABLE `borrower_attribute_types` (
1534 `code` varchar(10) NOT NULL,
1535 `description` varchar(255) NOT NULL,
1536 `repeatable` tinyint(1) NOT NULL default 0,
1537 `unique_id` tinyint(1) NOT NULL default 0,
1538 `opac_display` tinyint(1) NOT NULL default 0,
1539 `password_allowed` tinyint(1) NOT NULL default 0,
1540 `staff_searchable` tinyint(1) NOT NULL default 0,
1541 `authorised_value_category` varchar(10) default NULL,
1542 PRIMARY KEY (`code`)
1543 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1544 $dbh->do("CREATE TABLE `borrower_attributes` (
1545 `borrowernumber` int(11) NOT NULL,
1546 `code` varchar(10) NOT NULL,
1547 `attribute` varchar(30) default NULL,
1548 `password` varchar(30) default NULL,
1549 KEY `borrowernumber` (`borrowernumber`),
1550 KEY `code_attribute` (`code`, `attribute`),
1551 CONSTRAINT `borrower_attributes_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1552 ON DELETE CASCADE ON UPDATE CASCADE,
1553 CONSTRAINT `borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`)
1554 ON DELETE CASCADE ON UPDATE CASCADE
1555 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1556 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ExtendedPatronAttributes','0','Use extended patron IDs and attributes',NULL,'YesNo')");
1557 print "Upgrade to $DBversion done (added borrower_attributes and borrower_attribute_types)\n";
1558 SetVersion ($DBversion);
1561 $DBversion = "3.00.00.082";
1562 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1563 $dbh->do( q(alter table accountlines add column lastincrement decimal(28,6) default NULL) );
1564 print "Upgrade to $DBversion done (adding lastincrement column to accountlines table)\n";
1565 SetVersion ($DBversion);
1568 $DBversion = "3.00.00.083";
1569 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1570 $dbh->do( qq(UPDATE systempreferences SET value='local' where variable='yuipath' and value like "%/intranet-tmpl/prog/%"));
1571 print "Upgrade to $DBversion done (Changing yuipath behaviour in managing a local value)\n";
1572 SetVersion ($DBversion);
1574 $DBversion = "3.00.00.084";
1575 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1576 $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')");
1577 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GoogleJackets','0','if ON, displays jacket covers from Google Books API',NULL,'YesNo')");
1578 print "Upgrade to $DBversion done (add new sysprefs)\n";
1579 SetVersion ($DBversion);
1582 $DBversion = "3.00.00.085";
1583 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1584 if (C4::Context->preference("marcflavour") eq 'MARC21') {
1585 $dbh->do("UPDATE marc_subfield_structure SET tab = 0 WHERE tab = 9 AND tagfield = '037'");
1586 $dbh->do("UPDATE marc_subfield_structure SET tab = 1 WHERE tab = 6 AND tagfield in ('100', '110', '111', '130')");
1587 $dbh->do("UPDATE marc_subfield_structure SET tab = 2 WHERE tab = 6 AND tagfield in ('240', '243')");
1588 $dbh->do("UPDATE marc_subfield_structure SET tab = 4 WHERE tab = 6 AND tagfield in ('400', '410', '411', '440')");
1589 $dbh->do("UPDATE marc_subfield_structure SET tab = 5 WHERE tab = 9 AND tagfield = '584'");
1590 $dbh->do("UPDATE marc_subfield_structure SET tab = 7 WHERE tab = -6 AND tagfield = '760'");
1592 print "Upgrade to $DBversion done (move editing tab of various MARC21 subfields)\n";
1593 SetVersion ($DBversion);
1596 $DBversion = "3.00.00.086";
1597 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1599 "CREATE TABLE `tmp_holdsqueue` (
1600 `biblionumber` int(11) default NULL,
1601 `itemnumber` int(11) default NULL,
1602 `barcode` varchar(20) default NULL,
1603 `surname` mediumtext NOT NULL,
1606 `borrowernumber` int(11) NOT NULL,
1607 `cardnumber` varchar(16) default NULL,
1608 `reservedate` date default NULL,
1610 `itemcallnumber` varchar(30) default NULL,
1611 `holdingbranch` varchar(10) default NULL,
1612 `pickbranch` varchar(10) default NULL,
1614 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1616 $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')");
1617 $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')");
1619 print "Upgrade to $DBversion done (Table structure for table `tmp_holdsqueue`)\n";
1620 SetVersion ($DBversion);
1623 $DBversion = "3.00.00.087";
1624 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1625 $dbh->do("INSERT INTO `systempreferences` VALUES ('AutoEmailOpacUser','0','','Sends notification emails containing new account details to patrons - when account is created.','YesNo')" );
1626 $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')");
1627 print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
1628 SetVersion ($DBversion);
1631 $DBversion = "3.00.00.088";
1632 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1633 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('OPACShelfBrowser','1','','Enable/disable Shelf Browser on item details page','YesNo')");
1634 $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')");
1635 $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')");
1636 $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')");
1637 print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
1638 SetVersion ($DBversion);
1641 $DBversion = "3.00.00.089";
1642 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1643 $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')");
1644 print "Upgrade to $DBversion done (added new AdvancedSearchTypes syspref)\n";
1645 SetVersion ($DBversion);
1648 $DBversion = "3.00.00.090";
1649 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1651 CREATE TABLE `branch_borrower_circ_rules` (
1652 `branchcode` VARCHAR(10) NOT NULL,
1653 `categorycode` VARCHAR(10) NOT NULL,
1654 `maxissueqty` int(4) default NULL,
1655 PRIMARY KEY (`categorycode`, `branchcode`),
1656 CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
1657 ON DELETE CASCADE ON UPDATE CASCADE,
1658 CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
1659 ON DELETE CASCADE ON UPDATE CASCADE
1660 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1663 CREATE TABLE `default_borrower_circ_rules` (
1664 `categorycode` VARCHAR(10) NOT NULL,
1665 `maxissueqty` int(4) default NULL,
1666 PRIMARY KEY (`categorycode`),
1667 CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
1668 ON DELETE CASCADE ON UPDATE CASCADE
1669 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1672 CREATE TABLE `default_branch_circ_rules` (
1673 `branchcode` VARCHAR(10) NOT NULL,
1674 `maxissueqty` int(4) default NULL,
1675 PRIMARY KEY (`branchcode`),
1676 CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
1677 ON DELETE CASCADE ON UPDATE CASCADE
1678 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1681 CREATE TABLE `default_circ_rules` (
1682 `singleton` enum('singleton') NOT NULL default 'singleton',
1683 `maxissueqty` int(4) default NULL,
1684 PRIMARY KEY (`singleton`)
1685 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1687 print "Upgrade to $DBversion done (added several circ rules tables)\n";
1688 SetVersion ($DBversion);
1692 $DBversion = "3.00.00.091";
1693 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1694 $dbh->do(<<'END_SQL');
1695 ALTER TABLE borrowers
1696 ADD `smsalertnumber` varchar(50) default NULL
1699 $dbh->do(<<'END_SQL');
1700 CREATE TABLE `message_attributes` (
1701 `message_attribute_id` int(11) NOT NULL auto_increment,
1702 `message_name` varchar(20) NOT NULL default '',
1703 `takes_days` tinyint(1) NOT NULL default '0',
1704 PRIMARY KEY (`message_attribute_id`),
1705 UNIQUE KEY `message_name` (`message_name`)
1706 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1709 $dbh->do(<<'END_SQL');
1710 CREATE TABLE `message_transport_types` (
1711 `message_transport_type` varchar(20) NOT NULL,
1712 PRIMARY KEY (`message_transport_type`)
1713 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1716 $dbh->do(<<'END_SQL');
1717 CREATE TABLE `message_transports` (
1718 `message_attribute_id` int(11) NOT NULL,
1719 `message_transport_type` varchar(20) NOT NULL,
1720 `is_digest` tinyint(1) NOT NULL default '0',
1721 `letter_module` varchar(20) NOT NULL default '',
1722 `letter_code` varchar(20) NOT NULL default '',
1723 PRIMARY KEY (`message_attribute_id`,`message_transport_type`,`is_digest`),
1724 KEY `message_transport_type` (`message_transport_type`),
1725 KEY `letter_module` (`letter_module`,`letter_code`),
1726 CONSTRAINT `message_transports_ibfk_1` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1727 CONSTRAINT `message_transports_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE,
1728 CONSTRAINT `message_transports_ibfk_3` FOREIGN KEY (`letter_module`, `letter_code`) REFERENCES `letter` (`module`, `code`) ON DELETE CASCADE ON UPDATE CASCADE
1729 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1732 $dbh->do(<<'END_SQL');
1733 CREATE TABLE `borrower_message_preferences` (
1734 `borrower_message_preference_id` int(11) NOT NULL auto_increment,
1735 `borrowernumber` int(11) NOT NULL default '0',
1736 `message_attribute_id` int(11) default '0',
1737 `days_in_advance` int(11) default '0',
1738 `wants_digets` tinyint(1) NOT NULL default '0',
1739 PRIMARY KEY (`borrower_message_preference_id`),
1740 KEY `borrowernumber` (`borrowernumber`),
1741 KEY `message_attribute_id` (`message_attribute_id`),
1742 CONSTRAINT `borrower_message_preferences_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1743 CONSTRAINT `borrower_message_preferences_ibfk_2` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE
1744 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1747 $dbh->do(<<'END_SQL');
1748 CREATE TABLE `borrower_message_transport_preferences` (
1749 `borrower_message_preference_id` int(11) NOT NULL default '0',
1750 `message_transport_type` varchar(20) NOT NULL default '0',
1751 PRIMARY KEY (`borrower_message_preference_id`,`message_transport_type`),
1752 KEY `message_transport_type` (`message_transport_type`),
1753 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,
1754 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
1755 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1758 $dbh->do(<<'END_SQL');
1759 CREATE TABLE `message_queue` (
1760 `message_id` int(11) NOT NULL auto_increment,
1761 `borrowernumber` int(11) NOT NULL,
1764 `message_transport_type` varchar(20) NOT NULL,
1765 `status` enum('sent','pending','failed','deleted') NOT NULL default 'pending',
1766 `time_queued` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1767 KEY `message_id` (`message_id`),
1768 KEY `borrowernumber` (`borrowernumber`),
1769 KEY `message_transport_type` (`message_transport_type`),
1770 CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1771 CONSTRAINT `messageq_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE RESTRICT ON UPDATE CASCADE
1772 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1775 $dbh->do(<<'END_SQL');
1776 INSERT INTO `systempreferences`
1777 (variable,value,explanation,options,type)
1779 ('EnhancedMessagingPreferences',0,'If ON, allows patrons to select to receive additional messages about items due or nearly due.','','YesNo')
1782 $dbh->do( <<'END_SQL');
1783 INSERT INTO `letter`
1784 (module, code, name, title, content)
1786 ('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>>'),
1787 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You have <<count>> items due'),
1788 ('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>>'),
1789 ('circulation','PREDUEDGST','Advance Notice of Item Due (Digest)','Advance Notice of Item Due','You have <<count>> items due soon'),
1790 ('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.');
1794 'installer/data/mysql/en/mandatory/message_transport_types.sql',
1795 'installer/data/mysql/en/optional/sample_notices_message_attributes.sql',
1796 'installer/data/mysql/en/optional/sample_notices_message_transports.sql',
1799 my $installer = C4::Installer->new();
1800 foreach my $script ( @sql_scripts ) {
1801 my $full_path = $installer->get_file_path_from_name($script);
1802 my $error = $installer->load_sql($full_path);
1803 warn $error if $error;
1806 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";
1807 SetVersion ($DBversion);
1810 $DBversion = "3.00.00.092";
1811 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1812 $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')");
1813 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Allow hold requests to be placed on damaged items', 'YesNo')");
1814 print "Upgrade to $DBversion done (added new AllowOnShelfHolds syspref)\n";
1815 SetVersion ($DBversion);
1818 $DBversion = "3.00.00.093";
1819 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1820 $dbh->do("ALTER TABLE `items` MODIFY COLUMN `copynumber` VARCHAR(32) DEFAULT NULL");
1821 $dbh->do("ALTER TABLE `deleteditems` MODIFY COLUMN `copynumber` VARCHAR(32) DEFAULT NULL");
1822 print "Upgrade to $DBversion done (Change data type of items.copynumber to allow free text)\n";
1823 SetVersion ($DBversion);
1826 $DBversion = "3.00.00.094";
1827 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1828 $dbh->do("ALTER TABLE `marc_subfield_structure` MODIFY `tagsubfield` VARCHAR(1) NOT NULL DEFAULT '' COLLATE utf8_bin");
1829 print "Upgrade to $DBversion done (Change Collation of marc_subfield_structure to allow mixed case in subfield labels.)\n";
1830 SetVersion ($DBversion);
1833 $DBversion = "3.00.00.095";
1834 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1835 if (C4::Context->preference("marcflavour") eq 'MARC21') {
1836 $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'MEETI_NAME' WHERE authtypecode = 'Meeting Name'");
1837 $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'CORPO_NAME' WHERE authtypecode = 'CORP0_NAME'");
1839 print "Upgrade to $DBversion done (fix invalid authority types in MARC21 frameworks [bug 2254])\n";
1840 SetVersion ($DBversion);
1843 $DBversion = "3.00.00.096";
1844 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1845 $sth = $dbh->prepare("SHOW COLUMNS FROM borrower_message_preferences LIKE 'wants_digets'");
1847 if (my $row = $sth->fetchrow_hashref) {
1848 $dbh->do("ALTER TABLE borrower_message_preferences CHANGE wants_digets wants_digest tinyint(1) NOT NULL default 0");
1850 print "Upgrade to $DBversion done (fix name borrower_message_preferences.wants_digest)\n";
1851 SetVersion ($DBversion);
1854 $DBversion = '3.00.00.097';
1855 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1857 $dbh->do('ALTER TABLE message_queue ADD to_address mediumtext default NULL');
1858 $dbh->do('ALTER TABLE message_queue ADD from_address mediumtext default NULL');
1859 $dbh->do('ALTER TABLE message_queue ADD content_type text');
1860 $dbh->do('ALTER TABLE message_queue CHANGE borrowernumber borrowernumber int(11) default NULL');
1862 print "Upgrade to $DBversion done (updating 4 fields in message_queue table)\n";
1863 SetVersion($DBversion);
1866 $DBversion = '3.00.00.098';
1867 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1869 $dbh->do(q(DELETE FROM message_transport_types WHERE message_transport_type = 'rss'));
1870 $dbh->do(q(DELETE FROM message_transports WHERE message_transport_type = 'rss'));
1872 print "Upgrade to $DBversion done (removing unused RSS message_transport_type)\n";
1873 SetVersion($DBversion);
1876 $DBversion = '3.00.00.099';
1877 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1878 $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')");
1879 print "Upgrade to $DBversion done (Adding OpacSuppression syspref)\n";
1880 SetVersion($DBversion);
1883 $DBversion = '3.00.00.100';
1884 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1885 $dbh->do('ALTER TABLE virtualshelves ADD COLUMN lastmodified timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP');
1886 print "Upgrade to $DBversion done (Adding lastmodified column to virtualshelves)\n";
1887 SetVersion($DBversion);
1890 $DBversion = '3.00.00.101';
1891 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1892 $dbh->do('ALTER TABLE `overduerules` CHANGE `categorycode` `categorycode` VARCHAR(10) NOT NULL');
1893 $dbh->do('ALTER TABLE `deletedborrowers` CHANGE `categorycode` `categorycode` VARCHAR(10) NOT NULL');
1894 print "Upgrade to $DBversion done (Updating columnd definitions for patron category codes in notice/statsu triggers and deletedborrowers tables.)\n";
1895 SetVersion($DBversion);
1898 $DBversion = '3.00.00.102';
1899 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1900 $dbh->do('ALTER TABLE serialitems MODIFY `serialid` int(11) NOT NULL AFTER itemnumber' );
1901 $dbh->do('ALTER TABLE serialitems DROP KEY serialididx' );
1902 $dbh->do('ALTER TABLE serialitems ADD CONSTRAINT UNIQUE KEY serialitemsidx (itemnumber)' );
1903 # before setting constraint, delete any unvalid data
1904 $dbh->do('DELETE from serialitems WHERE serialid not in (SELECT serial.serialid FROM serial)');
1905 $dbh->do('ALTER TABLE serialitems ADD CONSTRAINT serialitems_sfk_1 FOREIGN KEY (serialid) REFERENCES serial (serialid) ON DELETE CASCADE ON UPDATE CASCADE' );
1906 print "Upgrade to $DBversion done (Updating serialitems table to allow for multiple items per serial fixing kohabug 2380)\n";
1907 SetVersion($DBversion);
1910 $DBversion = "3.00.00.103";
1911 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1912 $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
1913 print "Upgrade to $DBversion done ( Verifying the removal of serialsadditems from syspref fixing kohabug 2219)\n";
1914 SetVersion ($DBversion);
1917 $DBversion = "3.00.00.104";
1918 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1919 $dbh->do("DELETE FROM systempreferences WHERE variable='noOPACHolds'");
1920 print "Upgrade to $DBversion done (remove superseded 'noOPACHolds' system preference per bug 2413)\n";
1921 SetVersion ($DBversion);
1924 $DBversion = '3.00.00.105';
1925 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
1927 # it is possible that this syspref is already defined since the feature was added some time ago.
1928 unless ( $dbh->do(q(SELECT variable FROM systempreferences WHERE variable = 'SMSSendDriver')) ) {
1929 $dbh->do(<<'END_SQL');
1930 INSERT INTO `systempreferences`
1931 (variable,value,explanation,options,type)
1933 ('SMSSendDriver','','Sets which SMS::Send driver is used to send SMS messages.','','free')
1936 print "Upgrade to $DBversion done (added SMSSendDriver system preference)\n";
1937 SetVersion($DBversion);
1940 $DBversion = "3.00.00.106";
1941 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1942 $dbh->do("DELETE FROM systempreferences WHERE variable='noOPACHolds'");
1944 # db revision 105 didn't apply correctly, so we're rolling this into 106
1945 $dbh->do("INSERT INTO `systempreferences`
1946 (variable,value,explanation,options,type)
1948 ('SMSSendDriver','','Sets which SMS::Send driver is used to send SMS messages.','','free')");
1950 print "Upgrade to $DBversion done (remove default '0000-00-00' in subscriptionhistory.enddate field)\n";
1951 $dbh->do("ALTER TABLE `subscriptionhistory` CHANGE `enddate` `enddate` DATE NULL DEFAULT NULL ");
1952 $dbh->do("UPDATE subscriptionhistory SET enddate=NULL WHERE enddate='0000-00-00'");
1953 SetVersion ($DBversion);
1956 $DBversion = '3.00.00.107';
1957 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1958 $dbh->do(<<'END_SQL');
1959 UPDATE systempreferences
1960 SET explanation = CONCAT( explanation, '. WARNING: this feature is very resource consuming on collections with large numbers of items.' )
1961 WHERE variable = 'OPACShelfBrowser'
1962 AND explanation NOT LIKE '%WARNING%'
1964 $dbh->do(<<'END_SQL');
1965 UPDATE systempreferences
1966 SET explanation = CONCAT( explanation, '. WARNING: this feature is very resource consuming.' )
1967 WHERE variable = 'CataloguingLog'
1968 AND explanation NOT LIKE '%WARNING%'
1970 $dbh->do(<<'END_SQL');
1971 UPDATE systempreferences
1972 SET explanation = CONCAT( explanation, '. WARNING: using NoZebra on even modest sized collections is very slow.' )
1973 WHERE variable = 'NoZebra'
1974 AND explanation NOT LIKE '%WARNING%'
1976 print "Upgrade to $DBversion done (warning added to OPACShelfBrowser system preference)\n";
1977 SetVersion ($DBversion);
1980 $DBversion = '3.01.00.000';
1981 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1982 print "Upgrade to $DBversion done (start of 3.1)\n";
1983 SetVersion ($DBversion);
1986 $DBversion = '3.01.00.001';
1987 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1989 CREATE TABLE hold_fill_targets (
1990 `borrowernumber` int(11) NOT NULL,
1991 `biblionumber` int(11) NOT NULL,
1992 `itemnumber` int(11) NOT NULL,
1993 `source_branchcode` varchar(10) default NULL,
1994 `item_level_request` tinyint(4) NOT NULL default 0,
1995 PRIMARY KEY `itemnumber` (`itemnumber`),
1996 KEY `bib_branch` (`biblionumber`, `source_branchcode`),
1997 CONSTRAINT `hold_fill_targets_ibfk_1` FOREIGN KEY (`borrowernumber`)
1998 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1999 CONSTRAINT `hold_fill_targets_ibfk_2` FOREIGN KEY (`biblionumber`)
2000 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2001 CONSTRAINT `hold_fill_targets_ibfk_3` FOREIGN KEY (`itemnumber`)
2002 REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2003 CONSTRAINT `hold_fill_targets_ibfk_4` FOREIGN KEY (`source_branchcode`)
2004 REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2005 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2008 ALTER TABLE tmp_holdsqueue
2009 ADD item_level_request tinyint(4) NOT NULL default 0
2012 print "Upgrade to $DBversion done (add hold_fill_targets table and a column to tmp_holdsqueue)\n";
2013 SetVersion($DBversion);
2016 $DBversion = '3.01.00.002';
2017 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2018 # use statistics where available
2020 ALTER TABLE statistics ADD KEY tmp_stats (type, itemnumber, borrowernumber)
2025 SELECT max(datetime)
2027 WHERE type = 'issue'
2028 AND itemnumber = iss.itemnumber
2029 AND borrowernumber = iss.borrowernumber
2031 WHERE issuedate IS NULL;
2033 $dbh->do("ALTER TABLE statistics DROP KEY tmp_stats");
2035 # default to last renewal date
2038 SET issuedate = lastreneweddate
2039 WHERE issuedate IS NULL
2040 and lastreneweddate IS NOT NULL
2043 my $num_bad_issuedates = $dbh->selectrow_array("SELECT COUNT(*) FROM issues WHERE issuedate IS NULL");
2044 if ($num_bad_issuedates > 0) {
2045 print STDERR "After the upgrade to $DBversion, there are still $num_bad_issuedates loan(s) with a NULL (blank) loan date. ",
2046 "Please check the issues table in your database.";
2048 print "Upgrade to $DBversion done (bug 2582: set null issues.issuedate to lastreneweddate)\n";
2049 SetVersion($DBversion);
2052 $DBversion = "3.01.00.003";
2053 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2054 $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')");
2055 print "Upgrade to $DBversion done (add new syspref)\n";
2056 SetVersion ($DBversion);
2059 $DBversion = '3.01.00.004';
2060 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2061 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACDisplayRequestPriority','0','Show patrons the priority level on holds in the OPAC','','YesNo')");
2062 print "Upgrade to $DBversion done (added OPACDisplayRequestPriority system preference)\n";
2063 SetVersion ($DBversion);
2066 $DBversion = '3.01.00.005';
2067 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2069 INSERT INTO `letter` (module, code, name, title, content)
2070 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>>')
2072 $dbh->do("INSERT INTO `message_attributes` (message_attribute_id, message_name, takes_days) values(4, 'Hold Filled', 0)");
2073 $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'sms', 0, 'reserves', 'HOLD')");
2074 $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'email', 0, 'reserves', 'HOLD')");
2075 print "Upgrade to $DBversion done (Add letter for holds notifications)\n";
2076 SetVersion ($DBversion);
2079 $DBversion = '3.01.00.006';
2080 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2081 $dbh->do("ALTER TABLE `biblioitems` ADD KEY issn (issn)");
2082 print "Upgrade to $DBversion done (add index on biblioitems.issn)\n";
2083 SetVersion ($DBversion);
2086 $DBversion = "3.01.00.007";
2087 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2088 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetmainUserblock'");
2089 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetuserjs'");
2090 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacheader'");
2091 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacMainUserBlock'");
2092 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacNav'");
2093 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacuserjs'");
2094 $dbh->do("UPDATE `systempreferences` SET options='30|10', type='Textarea' WHERE variable='OAI-PMH:Set'");
2095 $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetstylesheet'");
2096 $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetcolorstylesheet'");
2097 $dbh->do("UPDATE `systempreferences` SET options='10' WHERE variable='globalDueDate'");
2098 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='numSearchResults'");
2099 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='OPACnumSearchResults'");
2100 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='ReservesMaxPickupDelay'");
2101 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='TransfersMaxDaysWarning'");
2102 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='StaticHoldsQueueWeight'");
2103 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='holdCancelLength'");
2104 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='XISBNDailyLimit'");
2105 $dbh->do("UPDATE `systempreferences` SET type='Float' WHERE variable='gist'");
2106 $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorUsername'");
2107 $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorPassword'");
2108 $dbh->do("UPDATE `systempreferences` SET type='Textarea', options='70|10' WHERE variable='ISBD'");
2109 $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'");
2110 print "Upgrade to $DBversion done (fix display of many sysprefs)\n";
2111 SetVersion ($DBversion);
2114 $DBversion = '3.01.00.008';
2115 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2117 $dbh->do("CREATE TABLE branch_transfer_limits (
2118 limitId int(8) NOT NULL auto_increment,
2119 toBranch varchar(4) NOT NULL,
2120 fromBranch varchar(4) NOT NULL,
2121 itemtype varchar(4) NOT NULL,
2122 PRIMARY KEY (limitId)
2123 ) ENGINE=InnoDB DEFAULT CHARSET=utf8"
2126 $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')");
2128 print "Upgrade to $DBversion done (added branch_transfer_limits table and UseBranchTransferLimits system preference)\n";
2129 SetVersion ($DBversion);
2132 $DBversion = "3.01.00.009";
2133 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2134 $dbh->do("ALTER TABLE permissions MODIFY `code` varchar(64) DEFAULT NULL");
2135 $dbh->do("ALTER TABLE user_permissions MODIFY `code` varchar(64) DEFAULT NULL");
2136 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'circulate_remaining_permissions', 'Remaining circulation permissions')");
2137 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'override_renewals', 'Override blocked renewals')");
2138 print "Upgrade to $DBversion done (added subpermissions for circulate permission)\n";
2141 $DBversion = '3.01.00.010';
2142 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2143 $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `attribute` VARCHAR(64) DEFAULT NULL");
2144 $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `password` VARCHAR(64) DEFAULT NULL");
2145 print "Upgrade to $DBversion done (bug 2687: increase length of borrower attribute fields)\n";
2146 SetVersion ($DBversion);
2149 $DBversion = '3.01.00.011';
2150 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2152 # Yes, the old value was ^M terminated.
2153 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);";
2155 my $intranetuserjs = C4::Context->preference('intranetuserjs');
2156 if ($intranetuserjs and $intranetuserjs eq $bad_value) {
2157 my $sql = <<'END_SQL';
2158 UPDATE systempreferences
2160 WHERE variable = 'intranetuserjs'
2164 print "Upgrade to $DBversion done (removed bogus intranetuserjs syspref)\n";
2165 SetVersion($DBversion);
2168 $DBversion = "3.01.00.012";
2169 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2170 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowHoldPolicyOverride', '0', 'Allow staff to override hold policies when placing holds',NULL,'YesNo')");
2172 CREATE TABLE `branch_item_rules` (
2173 `branchcode` varchar(10) NOT NULL,
2174 `itemtype` varchar(10) NOT NULL,
2175 `holdallowed` tinyint(1) default NULL,
2176 PRIMARY KEY (`itemtype`,`branchcode`),
2177 KEY `branch_item_rules_ibfk_2` (`branchcode`),
2178 CONSTRAINT `branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE,
2179 CONSTRAINT `branch_item_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2180 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2183 CREATE TABLE `default_branch_item_rules` (
2184 `itemtype` varchar(10) NOT NULL,
2185 `holdallowed` tinyint(1) default NULL,
2186 PRIMARY KEY (`itemtype`),
2187 CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE
2188 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2191 ALTER TABLE default_branch_circ_rules
2192 ADD COLUMN holdallowed tinyint(1) NULL
2195 ALTER TABLE default_circ_rules
2196 ADD COLUMN holdallowed tinyint(1) NULL
2198 print "Upgrade to $DBversion done (Add tables and system preferences for holds policies)\n";
2199 SetVersion ($DBversion);
2202 $DBversion = '3.01.00.013';
2203 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2205 CREATE TABLE item_circulation_alert_preferences (
2206 id int(11) AUTO_INCREMENT,
2207 branchcode varchar(10) NOT NULL,
2208 categorycode varchar(10) NOT NULL,
2209 item_type varchar(10) NOT NULL,
2210 notification varchar(16) NOT NULL,
2212 KEY (branchcode, categorycode, item_type, notification)
2213 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2216 $dbh->do(q{ ALTER TABLE `message_queue` ADD metadata text DEFAULT NULL AFTER content; });
2217 $dbh->do(q{ ALTER TABLE `message_queue` ADD letter_code varchar(64) DEFAULT NULL AFTER metadata; });
2220 INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES
2221 ('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.');
2224 INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES
2225 ('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>>.');
2228 $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (5, 'Item Check-in', 0);});
2229 $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (6, 'Item Checkout', 0);});
2231 $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');});
2232 $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');});
2233 $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');});
2234 $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');});
2236 print "Upgrade to $DBversion done (data for Email Checkout Slips project)\n";
2237 SetVersion ($DBversion);
2240 $DBversion = "3.01.00.014";
2241 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2242 $dbh->do("ALTER TABLE `branch_transfer_limits` CHANGE `itemtype` `itemtype` VARCHAR( 4 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL");
2243 $dbh->do("ALTER TABLE `branch_transfer_limits` ADD `ccode` VARCHAR( 10 ) NULL ;");
2244 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2246 'BranchTransferLimitsType', 'ccode', 'itemtype|ccode', 'When using branch transfer limits, choose whether to limit by itemtype or collection code.', 'Choice'
2249 print "Upgrade to $DBversion done ( Updated table for Branch Transfer Limits)\n";
2250 SetVersion ($DBversion);
2253 $DBversion = '3.01.00.015';
2254 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2255 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsClientCode', '0', 'Client Code for using Syndetics Solutions content','','free')");
2257 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEnabled', '0', 'Turn on Syndetics Enhanced Content','','YesNo')");
2259 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsCoverImages', '0', 'Display Cover Images from Syndetics','','YesNo')");
2261 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsTOC', '0', 'Display Table of Content information from Syndetics','','YesNo')");
2263 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSummary', '0', 'Display Summary Information from Syndetics','','YesNo')");
2265 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEditions', '0', 'Display Editions from Syndetics','','YesNo')");
2267 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsExcerpt', '0', 'Display Excerpts and first chapters on OPAC from Syndetics','','YesNo')");
2269 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsReviews', '0', 'Display Reviews on OPAC from Syndetics','','YesNo')");
2271 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAuthorNotes', '0', 'Display Notes about the Author on OPAC from Syndetics','','YesNo')");
2273 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAwards', '0', 'Display Awards on OPAC from Syndetics','','YesNo')");
2275 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSeries', '0', 'Display Series information on OPAC from Syndetics','','YesNo')");
2277 $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')");
2279 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonCoverImages', '0', 'Display cover images on OPAC from Amazon Web Services','','YesNo')");
2281 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonCoverImages', '0', 'Display Cover Images in Staff Client from Amazon Web Services','','YesNo')");
2283 $dbh->do("UPDATE systempreferences SET variable='AmazonEnabled' WHERE variable = 'AmazonContent'");
2285 $dbh->do("UPDATE systempreferences SET variable='OPACAmazonEnabled' WHERE variable = 'OPACAmazonContent'");
2287 print "Upgrade to $DBversion done (added Syndetics Enhanced Content system preferences)\n";
2288 SetVersion ($DBversion);
2291 $DBversion = "3.01.00.016";
2292 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2293 $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')");
2294 print "Upgrade to $DBversion done (Added Babeltheque syspref)\n";
2295 SetVersion ($DBversion);
2298 $DBversion = "3.01.00.017";
2299 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2300 $dbh->do("ALTER TABLE `subscription` ADD `staffdisplaycount` VARCHAR(10) NULL;");
2301 $dbh->do("ALTER TABLE `subscription` ADD `opacdisplaycount` VARCHAR(10) NULL;");
2302 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2304 'StaffSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the Staff client', 'Integer'
2306 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2308 'OPACSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the OPAC', 'Integer'
2311 print "Upgrade to $DBversion done ( Updated table for Serials Display)\n";
2312 SetVersion ($DBversion);
2315 $DBversion = "3.01.00.018";
2316 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2317 $dbh->do("ALTER TABLE deletedborrowers ADD `smsalertnumber` varchar(50) default NULL");
2318 print "Upgrade to $DBversion done (added deletedborrowers.smsalertnumber, missed in 3.00.00.091)\n";
2319 SetVersion ($DBversion);
2322 $DBversion = "3.01.00.019";
2323 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2324 $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')");
2325 print "Upgrade to $DBversion done (adding OPACShowCheckoutName systempref)\n";
2326 SetVersion ($DBversion);
2329 $DBversion = "3.01.00.020";
2330 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2331 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesID','','See:http://librarything.com/forlibraries/','','free')");
2332 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesEnabled','0','Enable or Disable Library Thing for Libraries Features','','YesNo')");
2333 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesTabbedView','0','Put LibraryThingForLibraries Content in Tabs.','','YesNo')");
2334 print "Upgrade to $DBversion done (adding LibraryThing for Libraries sysprefs)\n";
2335 SetVersion ($DBversion);
2338 $DBversion = "3.01.00.021";
2339 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2340 my $enable_reviews = C4::Context->preference('OPACAmazonEnabled') ? '1' : '0';
2341 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonReviews', '$enable_reviews', 'Display Amazon readers reviews on OPAC','','YesNo')");
2342 print "Upgrade to $DBversion done (adding OPACAmazonReviews syspref)\n";
2343 SetVersion ($DBversion);
2346 $DBversion = '3.01.00.022';
2347 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2348 $dbh->do("ALTER TABLE `labels_conf` MODIFY COLUMN `formatstring` mediumtext DEFAULT NULL");
2349 print "Upgrade to $DBversion done (bug 2945: increase size of labels_conf.formatstring)\n";
2350 SetVersion ($DBversion);
2353 $DBversion = '3.01.00.023';
2354 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2355 $dbh->do("ALTER TABLE biblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2356 $dbh->do("ALTER TABLE deletedbiblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2357 $dbh->do("ALTER TABLE import_biblios MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2358 $dbh->do("ALTER TABLE suggestions MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2359 print "Upgrade to $DBversion done (bug 2765: increase width of isbn column in several tables)\n";
2360 SetVersion ($DBversion);
2363 $DBversion = "3.01.00.024";
2364 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2365 $dbh->do("ALTER TABLE labels MODIFY COLUMN batch_id int(10) NOT NULL default 1;");
2366 print "Upgrade to $DBversion done (change labels.batch_id from varchar to int)\n";
2367 SetVersion ($DBversion);
2370 $DBversion = '3.01.00.025';
2371 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2372 $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')");
2374 print "Upgrade to $DBversion done (added ceilingDueDate system preference)\n";
2375 SetVersion ($DBversion);
2378 $DBversion = '3.01.00.026';
2379 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2380 $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')");
2382 print "Upgrade to $DBversion done (added numReturnedItemsToShow system preference)\n";
2383 SetVersion ($DBversion);
2386 $DBversion = '3.01.00.027';
2387 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2388 $dbh->do("ALTER TABLE zebraqueue CHANGE `biblio_auth_number` `biblio_auth_number` bigint(20) unsigned NOT NULL default 0");
2389 print "Upgrade to $DBversion done (Increased size of zebraqueue biblio_auth_number to address bug 3148.)\n";
2390 SetVersion ($DBversion);
2393 $DBversion = '3.01.00.028';
2394 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2395 my $enable_reviews = C4::Context->preference('AmazonEnabled') ? '1' : '0';
2396 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonReviews', '$enable_reviews', 'Display Amazon reviews on staff interface','','YesNo')");
2397 print "Upgrade to $DBversion done (added AmazonReviews)\n";
2398 SetVersion ($DBversion);
2401 $DBversion = '3.01.00.029';
2402 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2403 $dbh->do(q( UPDATE language_rfc4646_to_iso639
2404 SET iso639_2_code = 'spa'
2405 WHERE rfc4646_subtag = 'es'
2406 AND iso639_2_code = 'rus' )
2408 print "Upgrade to $DBversion done (fixed bug 2599: using Spanish search limit retrieves Russian results)\n";
2409 SetVersion ($DBversion);
2412 $DBversion = "3.01.00.030";
2413 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2414 $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')");
2415 print "Upgrade to $DBversion done (added AllowNotForLoanOverride system preference)\n";
2416 SetVersion ($DBversion);
2419 $DBversion = "3.01.00.031";
2420 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2421 $dbh->do("ALTER TABLE branch_transfer_limits
2422 MODIFY toBranch varchar(10) NOT NULL,
2423 MODIFY fromBranch varchar(10) NOT NULL,
2424 MODIFY itemtype varchar(10) NULL");
2425 print "Upgrade to $DBversion done (fix column widths in branch_transfer_limits)\n";
2426 SetVersion ($DBversion);
2429 $DBversion = "3.01.00.032";
2430 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2431 $dbh->do(<<ENDOFRENEWAL);
2432 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');
2434 print "Upgrade to $DBversion done (Change the field)\n";
2435 SetVersion ($DBversion);
2438 $DBversion = "3.01.00.033";
2439 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2441 ALTER TABLE borrower_message_preferences
2442 MODIFY borrowernumber int(11) default NULL,
2443 ADD categorycode varchar(10) default NULL AFTER borrowernumber,
2444 ADD KEY `categorycode` (`categorycode`),
2445 ADD CONSTRAINT `borrower_message_preferences_ibfk_3`
2446 FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
2447 ON DELETE CASCADE ON UPDATE CASCADE
2449 print "Upgrade to $DBversion done (DB changes to allow patron category defaults for messaging preferences)\n";
2450 SetVersion ($DBversion);
2453 $DBversion = "3.01.00.034";
2454 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2455 $dbh->do("ALTER TABLE `subscription` ADD COLUMN `graceperiod` INT(11) NOT NULL default '0';");
2456 print "Upgrade to $DBversion done (Adding graceperiod column to subscription table)\n";
2457 SetVersion ($DBversion);
2460 $DBversion = '3.01.00.035';
2461 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2462 $dbh->do(q{ ALTER TABLE `subscription` ADD location varchar(80) NULL DEFAULT '' AFTER callnumber; });
2463 print "Upgrade to $DBversion done (Adding location to subscription table)\n";
2464 SetVersion ($DBversion);
2467 $DBversion = '3.01.00.036';
2468 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2469 $dbh->do("UPDATE systempreferences SET explanation = 'Choose the default detail view in the staff interface; choose between normal, labeled_marc, marc or isbd'
2470 WHERE variable = 'IntranetBiblioDefaultView'
2471 AND explanation = 'IntranetBiblioDefaultView'");
2472 $dbh->do("UPDATE systempreferences SET type = 'Choice', options = 'normal|marc|isbd|labeled_marc'
2473 WHERE variable = 'IntranetBiblioDefaultView'");
2474 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewISBD','1','Allow display of ISBD view of bibiographic records','','YesNo')");
2475 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Allow display of labeled MARC view of bibiographic records','','YesNo')");
2476 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Allow display of MARC view of bibiographic records','','YesNo')");
2477 print "Upgrade to $DBversion done (new viewISBD, viewLabeledMARC, viewMARC sysprefs and tweak IntranetBiblioDefaultView)\n";
2478 SetVersion ($DBversion);
2481 $DBversion = '3.01.00.037';
2482 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2483 $dbh->do('ALTER TABLE authorised_values ADD KEY `lib` (`lib`)');
2484 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Do not run overdue report until filter selected','','YesNo')");
2485 SetVersion ($DBversion);
2486 print "Upgrade to $DBversion done (added FilterBeforeOverdueReport syspref and new index on authorised_values)\n";
2489 $DBversion = "3.01.00.038";
2490 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2491 # update branches table
2493 $dbh->do("ALTER TABLE branches ADD `branchzip` varchar(25) default NULL AFTER `branchaddress3`");
2494 $dbh->do("ALTER TABLE branches ADD `branchcity` mediumtext AFTER `branchzip`");
2495 $dbh->do("ALTER TABLE branches ADD `branchcountry` text AFTER `branchcity`");
2496 $dbh->do("ALTER TABLE branches ADD `branchurl` mediumtext AFTER `branchemail`");
2497 $dbh->do("ALTER TABLE branches ADD `branchnotes` mediumtext AFTER `branchprinter`");
2498 print "Upgrade to $DBversion done (add ZIP, city, country, URL, and notes column to branches)\n";
2499 SetVersion ($DBversion);
2502 $DBversion = '3.01.00.039';
2503 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2504 $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')");
2505 $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')");
2506 SetVersion ($DBversion);
2507 print "Upgrade to $DBversion done (added SpineLabelFormat and SpineLabelAutoPrint sysprefs)\n";
2510 $DBversion = '3.01.00.040';
2511 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2512 $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')");
2513 $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')");
2514 SetVersion ($DBversion);
2515 print "Upgrade to $DBversion done (AllowHoldDateInFuture and OPACAllowHoldDateInFuture sysprefs)\n";
2518 $DBversion = '3.01.00.041';
2519 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2520 $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')");
2521 SetVersion ($DBversion);
2522 print "Upgrade to $DBversion done (added AWSPrivateKey syspref - note that if you use enhanced content from Amazon, this should be set right away.)\n";
2525 $DBversion = '3.01.00.042';
2526 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2527 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACFineNoRenewals','99999','Fine Limit above which user canmot renew books via OPAC','','Integer')");
2528 SetVersion ($DBversion);
2529 print "Upgrade to $DBversion done (added OPACFineNoRenewals syspref)\n";
2532 $DBversion = '3.01.00.043';
2533 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2534 $dbh->do('ALTER TABLE items ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location');
2535 $dbh->do('UPDATE items SET permanent_location = location');
2536 $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 )', '')");
2537 $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')");
2538 $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')");
2539 SetVersion ($DBversion);
2540 print "Upgrade to $DBversion done (amended Item added NewItemsDefaultLocation, InProcessingToShelvingCart, ReturnToShelvingCart sysprefs)\n";
2543 $DBversion = '3.01.00.044';
2544 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2545 $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')");
2546 SetVersion ($DBversion);
2547 print "Upgrade to $DBversion done (added DisplayClearScreenButton system preference)\n";
2550 $DBversion = '3.01.00.045';
2551 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2552 $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')");
2553 SetVersion ($DBversion);
2554 print "Upgrade to $DBversion done (added a preference to hide the patrons name in the staff catalog)\n";
2557 $DBversion = "3.01.00.046";
2558 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2559 # update borrowers table
2561 $dbh->do("ALTER TABLE borrowers ADD `country` text AFTER zipcode");
2562 $dbh->do("ALTER TABLE borrowers ADD `B_country` text AFTER B_zipcode");
2563 $dbh->do("ALTER TABLE deletedborrowers ADD `country` text AFTER zipcode");
2564 $dbh->do("ALTER TABLE deletedborrowers ADD `B_country` text AFTER B_zipcode");
2565 print "Upgrade to $DBversion done (add country and B_country to borrowers)\n";
2566 SetVersion ($DBversion);
2569 $DBversion = '3.01.00.047';
2570 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2571 $dbh->do("ALTER TABLE items MODIFY itemcallnumber varchar(255);");
2572 $dbh->do("ALTER TABLE deleteditems MODIFY itemcallnumber varchar(255);");
2573 $dbh->do("ALTER TABLE tmp_holdsqueue MODIFY itemcallnumber varchar(255);");
2574 SetVersion ($DBversion);
2575 print " Upgrade to $DBversion done (bug 2761: change max length of itemcallnumber to 255 from 30)\n";
2578 $DBversion = '3.01.00.048';
2579 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2580 $dbh->do("UPDATE userflags SET flagdesc='View Catalog (Librarian Interface)' WHERE bit=2;");
2581 $dbh->do("UPDATE userflags SET flagdesc='Edit Catalog (Modify bibliographic/holdings data)' WHERE bit=9;");
2582 $dbh->do("UPDATE userflags SET flagdesc='Allow to edit authorities' WHERE bit=14;");
2583 $dbh->do("UPDATE userflags SET flagdesc='Allow to access to the reports module' WHERE bit=16;");
2584 $dbh->do("UPDATE userflags SET flagdesc='Allow to manage serials subscriptions' WHERE bit=15;");
2585 SetVersion ($DBversion);
2586 print " Upgrade to $DBversion done (bug 2611: fix spelling/capitalization in permission flag descriptions)\n";
2589 $DBversion = '3.01.00.049';
2590 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2591 $dbh->do("UPDATE permissions SET description = 'Perform inventory (stocktaking) of your catalog' WHERE code = 'inventory';");
2592 SetVersion ($DBversion);
2593 print "Upgrade to $DBversion done (bug 2611: changed catalogue to catalog per the standard)\n";
2596 $DBversion = '3.01.00.050';
2597 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2598 $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');");
2599 SetVersion ($DBversion);
2600 print "Upgrade to $DBversion done (bug 1934: Add OPACSearchForTitleIn syspref)\n";
2603 $DBversion = '3.01.00.051';
2604 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2605 $dbh->do("UPDATE systempreferences SET explanation='Fine limit above which user cannot renew books via OPAC' WHERE variable='OPACFineNoRenewals';");
2606 $dbh->do("UPDATE systempreferences SET explanation='If set to ON, a clear screen button will appear on the circulation page.' WHERE variable='DisplayClearScreenButton';");
2607 SetVersion ($DBversion);
2608 print "Upgrade to $DBversion done (fixed typos in new sysprefs)\n";
2611 $DBversion = '3.01.00.052';
2612 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2613 $dbh->do('ALTER TABLE deleteditems ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location');
2614 SetVersion ($DBversion);
2615 print "Upgrade to $DBversion done (bug 3481: add permanent_location column to deleteditems)\n";
2618 $DBversion = '3.01.00.053';
2619 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2620 my $upgrade_script = C4::Context->config("intranetdir") . "/installer/data/mysql/labels_upgrade.pl";
2621 system("perl $upgrade_script");
2622 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";
2623 SetVersion ($DBversion);
2626 $DBversion = '3.01.00.054';
2627 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2628 $dbh->do("ALTER TABLE borrowers ADD `B_address2` text AFTER B_address");
2629 $dbh->do("ALTER TABLE borrowers ADD `altcontactcountry` text AFTER altcontactzipcode");
2630 $dbh->do("ALTER TABLE deletedborrowers ADD `B_address2` text AFTER B_address");
2631 $dbh->do("ALTER TABLE deletedborrowers ADD `altcontactcountry` text AFTER altcontactzipcode");
2632 SetVersion ($DBversion);
2633 print "Upgrade to $DBversion done (bug 1600, bug 3454: add altcontactcountry and B_address2 to borrowers and deletedborrowers)\n";
2636 $DBversion = '3.01.00.055';
2637 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2638 $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'|);
2639 SetVersion ($DBversion);
2640 print "Upgrade to $DBversion done (changed OPACSearchForTitleIn per requests in bug 1934)\n";
2643 $DBversion = '3.01.00.056';
2644 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2645 $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');");
2646 SetVersion ($DBversion);
2647 print "Upgrade to $DBversion done (Bug 1172 : Add OPACPatronDetails syspref)\n";
2650 $DBversion = '3.01.00.057';
2651 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2652 $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');");
2653 SetVersion ($DBversion);
2654 print "Upgrade to $DBversion done (Bug 2576 : Add OPACFinesTab syspref)\n";
2657 $DBversion = '3.01.00.058';
2658 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2659 $dbh->do("ALTER TABLE `language_subtag_registry` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2660 $dbh->do("ALTER TABLE `language_rfc4646_to_iso639` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2661 $dbh->do("ALTER TABLE `language_descriptions` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2662 SetVersion ($DBversion);
2663 print "Upgrade to $DBversion done (Added primary keys to language tables)\n";
2666 $DBversion = '3.01.00.059';
2667 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2668 $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')");
2669 SetVersion ($DBversion);
2670 print "Upgrade to $DBversion done (added DisplayOPACiconsXSLT sysprefs)\n";
2673 $DBversion = '3.01.00.060';
2674 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2675 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo');");
2676 $dbh->do('DROP TABLE IF EXISTS messages');
2677 $dbh->do("CREATE TABLE messages ( `message_id` int(11) NOT NULL auto_increment,
2678 `borrowernumber` int(11) NOT NULL,
2679 `branchcode` varchar(4) default NULL,
2680 `message_type` varchar(1) NOT NULL,
2681 `message` text NOT NULL,
2682 `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
2683 PRIMARY KEY (`message_id`)
2684 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
2686 print "Upgrade to $DBversion done ( Added AllowAllMessageDeletion syspref and messages table )\n";
2687 SetVersion ($DBversion);
2690 $DBversion = '3.01.00.061';
2691 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2692 $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')");
2693 print "Upgrade to $DBversion done ( Added ShowPatronImageInWebBasedSelfCheck system preference )\n";
2694 SetVersion ($DBversion);
2697 $DBversion = "3.01.00.062";
2698 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2699 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'manage_csv_profiles', 'Manage CSV export profiles')");
2701 CREATE TABLE `export_format` (
2702 `export_format_id` int(11) NOT NULL auto_increment,
2703 `profile` varchar(255) NOT NULL,
2704 `description` mediumtext NOT NULL,
2705 `marcfields` mediumtext NOT NULL,
2706 PRIMARY KEY (`export_format_id`)
2707 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used for CSV export';
2709 print "Upgrade to $DBversion done (added csv export profiles)\n";
2712 $DBversion = "3.01.00.063";
2713 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2715 CREATE TABLE `fieldmapping` (
2716 `id` int(11) NOT NULL auto_increment,
2717 `field` varchar(255) NOT NULL,
2718 `frameworkcode` char(4) NOT NULL default '',
2719 `fieldcode` char(3) NOT NULL,
2720 `subfieldcode` char(1) NOT NULL,
2722 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2724 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";
2727 $DBversion = '3.01.00.065';
2728 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2729 $dbh->do('ALTER TABLE issuingrules ADD COLUMN `renewalsallowed` smallint(6) NOT NULL default "0" AFTER `issuelength`;');
2730 $sth = $dbh->prepare("SELECT itemtype, renewalsallowed FROM itemtypes");
2733 my $sthupd = $dbh->prepare("UPDATE issuingrules SET renewalsallowed = ? WHERE itemtype = ?");
2735 while(my $row = $sth->fetchrow_hashref){
2736 $sthupd->execute($row->{renewalsallowed}, $row->{itemtype});
2739 $dbh->do('ALTER TABLE itemtypes DROP COLUMN `renewalsallowed`;');
2741 SetVersion ($DBversion);
2742 print "Upgrade to $DBversion done (Moving allowed renewals from itemtypes to issuingrule)\n";
2745 $DBversion = '3.01.00.066';
2746 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2747 $dbh->do('ALTER TABLE issuingrules ADD COLUMN `reservesallowed` smallint(6) NOT NULL default "0" AFTER `renewalsallowed`;');
2749 my $maxreserves = C4::Context->preference('maxreserves');
2750 $sth = $dbh->prepare('UPDATE issuingrules SET reservesallowed = ?;');
2751 $sth->execute($maxreserves);
2753 $dbh->do('DELETE FROM systempreferences WHERE variable = "maxreserves";');
2755 $dbh->do("INSERT INTO systempreferences (variable,value, options, explanation, type) VALUES('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice')");
2757 SetVersion ($DBversion);
2758 print "Upgrade to $DBversion done (Moving max allowed reserves from system preference to issuingrule)\n";
2761 $DBversion = "3.01.00.067";
2762 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2763 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchmod', 'Perform batch modification of items')");
2764 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchdel', 'Perform batch deletion of items')");
2765 print "Upgrade to $DBversion done (added permissions for batch modification and deletion)\n";
2766 SetVersion ($DBversion);
2769 $DBversion = "3.01.00.068";
2770 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2771 $dbh->do("ALTER TABLE issuingrules ADD COLUMN `finedays` int(11) default NULL AFTER `fine` ");
2772 print "Upgrade to $DBversion done (Adding finedays in issuingrules table)\n";
2773 SetVersion ($DBversion);
2777 $DBversion = "3.01.00.069";
2778 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2779 $dbh->do("INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('EnableOpacSearchHistory', '1', '', 'Enable or disable opac search history', 'YesNo')");
2781 my $create = <<SEARCHHIST;
2782 CREATE TABLE IF NOT EXISTS `search_history` (
2783 `userid` int(11) NOT NULL,
2784 `sessionid` varchar(32) NOT NULL,
2785 `query_desc` varchar(255) NOT NULL,
2786 `query_cgi` varchar(255) NOT NULL,
2787 `total` int(11) NOT NULL,
2788 `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
2789 KEY `userid` (`userid`),
2790 KEY `sessionid` (`sessionid`)
2791 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Opac search history results';
2795 print "Upgrade to $DBversion done (added OPAC search history preference and table)\n";
2798 $DBversion = "3.01.00.070";
2799 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2800 $dbh->do("ALTER TABLE authorised_values ADD COLUMN `lib_opac` VARCHAR(80) default NULL AFTER `lib`");
2801 print "Upgrade to $DBversion done (Added a lib_opac field in authorised_values table)\n";
2804 $DBversion = "3.01.00.071";
2805 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2806 $dbh->do("ALTER TABLE `subscription` ADD `enddate` date default NULL");
2807 $dbh->do("ALTER TABLE subscriptionhistory CHANGE enddate histenddate DATE default NULL");
2808 print "Upgrade to $DBversion done ( Adding enddate to subscription)\n";
2811 # Acquisitions update
2813 $DBversion = "3.01.00.072";
2814 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2815 $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')");
2816 # create a new syspref for the 'Mr anonymous' patron
2817 $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,'')");
2818 # fill AnonymousPatron with AnonymousSuggestion value (copy)
2819 my $sth=$dbh->prepare("SELECT value FROM systempreferences WHERE variable='AnonSuggestions'");
2821 my ($value) = $sth->fetchrow() || 0;
2822 $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='AnonymousPatron'");
2823 # set AnonymousSuggestion do YesNo
2824 # 1st, set the value (1/True if it had a borrowernumber)
2825 $dbh->do("UPDATE systempreferences SET value=1 WHERE variable='AnonSuggestions' AND value>0");
2826 # 2nd, change the type to Choice
2827 $dbh->do("UPDATE systempreferences SET type='YesNo' WHERE variable='AnonSuggestions'");
2828 # borrower reading record privacy : 0 : forever, 1 : laws, 2 : don't keep at all
2829 $dbh->do("ALTER TABLE `borrowers` ADD `privacy` INTEGER NOT NULL DEFAULT 1;");
2830 print "Upgrade to $DBversion done (add new syspref and column in borrowers)\n";
2831 SetVersion ($DBversion);
2834 $DBversion = '3.01.00.073';
2835 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2836 $dbh->do('SET FOREIGN_KEY_CHECKS=0 ');
2837 $dbh->do(<<'END_SQL');
2838 CREATE TABLE IF NOT EXISTS `aqcontract` (
2839 `contractnumber` int(11) NOT NULL auto_increment,
2840 `contractstartdate` date default NULL,
2841 `contractenddate` date default NULL,
2842 `contractname` varchar(50) default NULL,
2843 `contractdescription` mediumtext,
2844 `booksellerid` int(11) not NULL,
2845 PRIMARY KEY (`contractnumber`),
2846 CONSTRAINT `booksellerid_fk1` FOREIGN KEY (`booksellerid`)
2847 REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
2848 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
2850 $dbh->do('SET FOREIGN_KEY_CHECKS=1 ');
2851 print "Upgrade to $DBversion done (adding aqcontract table)\n";
2852 SetVersion ($DBversion);
2855 $DBversion = '3.01.00.074';
2856 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2857 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `basketname` varchar(50) default NULL AFTER `basketno`");
2858 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `note` mediumtext AFTER `basketname`");
2859 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `booksellernote` mediumtext AFTER `note`");
2860 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `contractnumber` int(11) AFTER `booksellernote`");
2861 $dbh->do("ALTER TABLE `aqbasket` ADD FOREIGN KEY (`contractnumber`) REFERENCES `aqcontract` (`contractnumber`)");
2862 print "Upgrade to $DBversion done (edit aqbasket table done)\n";
2863 SetVersion ($DBversion);
2866 $DBversion = '3.01.00.075';
2867 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2868 $dbh->do("ALTER TABLE `aqorders` ADD COLUMN `uncertainprice` tinyint(1)");
2870 print "Upgrade to $DBversion done (adding uncertainprices)\n";
2871 SetVersion ($DBversion);
2874 $DBversion = '3.01.00.076';
2875 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2876 $dbh->do('SET FOREIGN_KEY_CHECKS=0 ');
2877 $dbh->do("CREATE TABLE IF NOT EXISTS `aqbasketgroups` (
2878 `id` int(11) NOT NULL auto_increment,
2879 `name` varchar(50) default NULL,
2880 `closed` tinyint(1) default NULL,
2881 `booksellerid` int(11) NOT NULL,
2883 KEY `booksellerid` (`booksellerid`),
2884 CONSTRAINT `aqbasketgroups_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
2885 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
2886 $dbh->do("ALTER TABLE aqbasket ADD COLUMN `basketgroupid` int(11)");
2887 $dbh->do("ALTER TABLE aqbasket ADD FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE ON DELETE SET NULL");
2888 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('pdfformat','pdfformat::layout2pages','Controls what script is used for printing (basketgroups)','','free')");
2889 $dbh->do('SET FOREIGN_KEY_CHECKS=1 ');
2890 print "Upgrade to $DBversion done (adding basketgroups)\n";
2891 SetVersion ($DBversion);
2893 $DBversion = '3.01.00.077';
2894 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2896 $dbh->do("SET FOREIGN_KEY_CHECKS=0 ");
2897 # create a mapping table holding the info we need to match orders to budgets
2898 $dbh->do('DROP TABLE IF EXISTS fundmapping');
2900 q|CREATE TABLE fundmapping AS
2901 SELECT aqorderbreakdown.ordernumber, branchcode, bookfundid, budgetdate, entrydate
2902 FROM aqorderbreakdown JOIN aqorders ON aqorderbreakdown.ordernumber = aqorders.ordernumber|);
2903 # match the new type of the corresponding field
2904 $dbh->do('ALTER TABLE fundmapping modify column bookfundid varchar(30)');
2905 # System did not ensure budgetdate was valid historically
2906 $dbh->do(q|UPDATE fundmapping SET budgetdate = entrydate WHERE budgetdate = '0000-00-00' OR budgetdate IS NULL|);
2907 # We save the map in fundmapping in case you need later processing
2908 $dbh->do(q|ALTER TABLE fundmapping add column aqbudgetid integer|);
2909 # these can speed processing up
2910 $dbh->do(q|CREATE INDEX fundmaporder ON fundmapping (ordernumber)|);
2911 $dbh->do(q|CREATE INDEX fundmapid ON fundmapping (bookfundid)|);
2913 $dbh->do("DROP TABLE IF EXISTS `aqbudgetperiods` ");
2916 CREATE TABLE `aqbudgetperiods` (
2917 `budget_period_id` int(11) NOT NULL auto_increment,
2918 `budget_period_startdate` date NOT NULL,
2919 `budget_period_enddate` date NOT NULL,
2920 `budget_period_active` tinyint(1) default '0',
2921 `budget_period_description` mediumtext,
2922 `budget_period_locked` tinyint(1) default NULL,
2923 `sort1_authcat` varchar(10) default NULL,
2924 `sort2_authcat` varchar(10) default NULL,
2925 PRIMARY KEY (`budget_period_id`)
2926 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |);
2928 $dbh->do(<<ADDPERIODS);
2929 INSERT INTO aqbudgetperiods (budget_period_startdate,budget_period_enddate,budget_period_active,budget_period_description,budget_period_locked)
2930 SELECT DISTINCT startdate, enddate, NOW() BETWEEN startdate and enddate, concat(startdate," ",enddate),NOT NOW() BETWEEN startdate AND enddate from aqbudget
2932 # SORRY , NO AQBUDGET/AQBOOKFUND -> AQBUDGETS IMPORT JUST YET,
2933 # BUT A NEW CLEAN AQBUDGETS TABLE CREATE FOR NOW..
2934 # DROP TABLE IF EXISTS `aqbudget`;
2935 #CREATE TABLE `aqbudget` (
2936 # `bookfundid` varchar(10) NOT NULL default ',
2937 # `startdate` date NOT NULL default 0,
2938 # `enddate` date default NULL,
2939 # `budgetamount` decimal(13,2) default NULL,
2940 # `aqbudgetid` tinyint(4) NOT NULL auto_increment,
2941 # `branchcode` varchar(10) default NULL,
2942 DropAllForeignKeys('aqbudget');
2943 #$dbh->do("drop table aqbudget;");
2946 my $maxbudgetid = $dbh->selectcol_arrayref(<<IDsBUDGET);
2947 SELECT MAX(aqbudgetid) from aqbudget
2950 $$maxbudgetid[0] = 0 if !$$maxbudgetid[0];
2952 $dbh->do(<<BUDGETAUTOINCREMENT);
2953 ALTER TABLE aqbudget AUTO_INCREMENT=$$maxbudgetid[0]
2956 $dbh->do(<<BUDGETNAME);
2957 ALTER TABLE aqbudget RENAME `aqbudgets`
2960 $dbh->do(<<BUDGETS);
2961 ALTER TABLE `aqbudgets`
2962 CHANGE COLUMN aqbudgetid `budget_id` int(11) NOT NULL AUTO_INCREMENT,
2963 CHANGE COLUMN branchcode `budget_branchcode` varchar(10) default NULL,
2964 CHANGE COLUMN budgetamount `budget_amount` decimal(28,6) NOT NULL default '0.00',
2965 CHANGE COLUMN bookfundid `budget_code` varchar(30) default NULL,
2966 ADD COLUMN `budget_parent_id` int(11) default NULL,
2967 ADD COLUMN `budget_name` varchar(80) default NULL,
2968 ADD COLUMN `budget_encumb` decimal(28,6) default '0.00',
2969 ADD COLUMN `budget_expend` decimal(28,6) default '0.00',
2970 ADD COLUMN `budget_notes` mediumtext,
2971 ADD COLUMN `budget_description` mediumtext,
2972 ADD COLUMN `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2973 ADD COLUMN `budget_amount_sublevel` decimal(28,6) AFTER `budget_amount`,
2974 ADD COLUMN `budget_period_id` int(11) default NULL,
2975 ADD COLUMN `sort1_authcat` varchar(80) default NULL,
2976 ADD COLUMN `sort2_authcat` varchar(80) default NULL,
2977 ADD COLUMN `budget_owner_id` int(11) default NULL,
2978 ADD COLUMN `budget_permission` int(1) default '0';
2981 $dbh->do(<<BUDGETCONSTRAINTS);
2982 ALTER TABLE `aqbudgets`
2983 ADD CONSTRAINT `aqbudgets_ifbk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON DELETE CASCADE ON UPDATE CASCADE
2985 # $dbh->do(<<BUDGETPKDROP);
2986 #ALTER TABLE `aqbudgets`
2989 # $dbh->do(<<BUDGETPKADD);
2990 #ALTER TABLE `aqbudgets`
2991 # ADD PRIMARY KEY budget_id
2995 my $query_period= $dbh->prepare(qq|SELECT budget_period_id from aqbudgetperiods where budget_period_startdate=? and budget_period_enddate=?|);
2996 my $query_bookfund= $dbh->prepare(qq|SELECT * from aqbookfund where bookfundid=?|);
2997 my $selectbudgets=$dbh->prepare(qq|SELECT * from aqbudgets|);
2998 my $updatebudgets=$dbh->prepare(qq|UPDATE aqbudgets SET budget_period_id= ? , budget_name=?, budget_branchcode=? where budget_id=?|);
2999 $selectbudgets->execute;
3000 while (my $databudget=$selectbudgets->fetchrow_hashref){
3001 $query_period->execute ($$databudget{startdate},$$databudget{enddate});
3002 my ($budgetperiodid)=$query_period->fetchrow;
3003 $query_bookfund->execute ($$databudget{budget_code});
3004 my $databf=$query_bookfund->fetchrow_hashref;
3005 my $branchcode=$$databudget{budget_branchcode}||$$databf{branchcode};
3006 $updatebudgets->execute($budgetperiodid,$$databf{bookfundname},$branchcode,$$databudget{budget_id});
3008 $dbh->do(<<BUDGETDROPDATES);
3009 ALTER TABLE `aqbudgets`
3015 $dbh->do("DROP TABLE IF EXISTS `aqbudgets_planning` ");
3016 $dbh->do("CREATE TABLE `aqbudgets_planning` (
3017 `plan_id` int(11) NOT NULL auto_increment,
3018 `budget_id` int(11) NOT NULL,
3019 `budget_period_id` int(11) NOT NULL,
3020 `estimated_amount` decimal(28,6) default NULL,
3021 `authcat` varchar(30) NOT NULL,
3022 `authvalue` varchar(30) NOT NULL,
3023 `display` tinyint(1) DEFAULT 1,
3024 PRIMARY KEY (`plan_id`),
3025 CONSTRAINT `aqbudgets_planning_ifbk_1` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
3026 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
3028 $dbh->do("ALTER TABLE `aqorders`
3029 ADD COLUMN `budget_id` tinyint(4) NOT NULL,
3030 ADD COLUMN `budgetgroup_id` int(11) NOT NULL,
3031 ADD COLUMN `sort1_authcat` varchar(10) default NULL,
3032 ADD COLUMN `sort2_authcat` varchar(10) default NULL" );
3033 # We need to map the orders to the budgets
3034 # For Historic reasons this is more complex than it should be on occasions