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!
46 use MARC::File::XML ( BinaryEncoding => 'utf8' );
48 use File::Path qw[remove_tree]; # perl core module
51 # FIXME - The user might be installing a new database, so can't rely
52 # on /etc/koha.conf anyway.
59 %existingtables, # tables already in database
63 $type, $null, $key, $default, $extra,
64 $prefitem, # preference item in systempreferences table
67 my $schema = Koha::Database->new()->schema();
73 my $dbh = C4::Context->dbh;
74 $|=1; # flushes output
76 local $dbh->{RaiseError} = 0;
78 # Record the version we are coming from
80 my $original_version = C4::Context->preference("Version");
82 # Deal with virtualshelves
83 my $DBversion = "3.00.00.001";
84 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
85 # update virtualshelves table to
87 $dbh->do("ALTER TABLE `bookshelf` RENAME `virtualshelves`");
88 $dbh->do("ALTER TABLE `shelfcontents` RENAME `virtualshelfcontents`");
89 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD `biblionumber` INT( 11 ) NOT NULL default '0' AFTER shelfnumber");
90 $dbh->do("UPDATE `virtualshelfcontents` SET biblionumber=(SELECT biblionumber FROM items WHERE items.itemnumber=virtualshelfcontents.itemnumber)");
91 # drop all foreign keys : otherwise, we can't drop itemnumber field.
92 DropAllForeignKeys('virtualshelfcontents');
93 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD KEY biblionumber (biblionumber)");
94 # create the new foreign keys (on biblionumber)
95 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `virtualshelfcontents_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE");
96 # re-create the foreign key on virtualshelf
97 $dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `shelfcontents_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE");
98 $dbh->do("ALTER TABLE `virtualshelfcontents` DROP `itemnumber`");
99 print "Upgrade to $DBversion done (virtualshelves)\n";
100 SetVersion ($DBversion);
104 $DBversion = "3.00.00.002";
105 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
106 $dbh->do("DROP TABLE sessions");
107 $dbh->do("CREATE TABLE `sessions` (
108 `id` varchar(32) NOT NULL,
109 `a_session` text NOT NULL,
110 UNIQUE KEY `id` (`id`)
111 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
112 print "Upgrade to $DBversion done (sessions uses CGI::session, new table structure for sessions)\n";
113 SetVersion ($DBversion);
117 $DBversion = "3.00.00.003";
118 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
119 if (C4::Context->preference("opaclanguages") eq "fr") {
120 $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')");
122 $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')");
124 print "Upgrade to $DBversion done (adding ReservesNeedReturns systempref, in circulation)\n";
125 SetVersion ($DBversion);
129 $DBversion = "3.00.00.004";
130 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
131 $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')");
132 print "Upgrade to $DBversion done (adding DebugLevel systempref, in 'Admin' tab)\n";
133 SetVersion ($DBversion);
136 $DBversion = "3.00.00.005";
137 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
138 $dbh->do("CREATE TABLE `tags` (
139 `entry` varchar(255) NOT NULL default '',
140 `weight` bigint(20) NOT NULL default 0,
141 PRIMARY KEY (`entry`)
142 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
144 $dbh->do("CREATE TABLE `nozebra` (
145 `server` varchar(20) NOT NULL,
146 `indexname` varchar(40) NOT NULL,
147 `value` varchar(250) NOT NULL,
148 `biblionumbers` longtext NOT NULL,
149 KEY `indexname` (`server`,`indexname`),
150 KEY `value` (`server`,`value`))
151 ENGINE=InnoDB DEFAULT CHARSET=utf8;
153 print "Upgrade to $DBversion done (adding tags and nozebra tables )\n";
154 SetVersion ($DBversion);
157 $DBversion = "3.00.00.006";
158 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
159 $dbh->do("UPDATE issues SET issuedate=timestamp WHERE issuedate='0000-00-00'");
160 print "Upgrade to $DBversion done (filled issues.issuedate with timestamp)\n";
161 SetVersion ($DBversion);
164 $DBversion = "3.00.00.007";
165 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
166 $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')");
167 print "Upgrade to $DBversion done (set SessionStorage variable)\n";
168 SetVersion ($DBversion);
171 $DBversion = "3.00.00.008";
172 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
173 $dbh->do("ALTER TABLE `biblio` ADD `datecreated` DATE NOT NULL AFTER `timestamp` ;");
174 $dbh->do("UPDATE biblio SET datecreated=timestamp");
175 print "Upgrade to $DBversion done (biblio creation date)\n";
176 SetVersion ($DBversion);
179 $DBversion = "3.00.00.009";
180 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
182 # Create backups of call number columns
183 # in case default migration needs to be customized
185 # UPGRADE NOTE: temp_upg_biblioitems_call_num should be dropped
186 # after call numbers have been transformed to the new structure
188 # Not bothering to do the same with deletedbiblioitems -- assume
189 # default is good enough.
190 $dbh->do("CREATE TABLE `temp_upg_biblioitems_call_num` AS
191 SELECT `biblioitemnumber`, `biblionumber`,
192 `classification`, `dewey`, `subclass`,
194 FROM `biblioitems`");
196 # biblioitems changes
197 $dbh->do("ALTER TABLE `biblioitems` CHANGE COLUMN `volumeddesc` `volumedesc` TEXT,
198 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
199 ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
200 ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
201 ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
202 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
203 ADD `totalissues` INT(10) AFTER `cn_sort`");
205 # default mapping of call number columns:
206 # cn_class = concatentation of classification + dewey,
207 # trimmed to fit -- assumes that most users do not
208 # populate both classification and dewey in a single record
210 # cn_source = left null
213 # After upgrade, cn_sort will have to be set based on whatever
214 # default call number scheme user sets as a preference. Misc
215 # script will be added at some point to do that.
217 $dbh->do("UPDATE `biblioitems`
218 SET cn_class = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
223 # Now drop the old call number columns
224 $dbh->do("ALTER TABLE `biblioitems` DROP COLUMN `classification`,
226 DROP COLUMN `subclass`,
227 DROP COLUMN `lcsort`,
228 DROP COLUMN `ccode`");
230 # deletedbiblio changes
231 $dbh->do("ALTER TABLE `deletedbiblio` ALTER COLUMN `frameworkcode` SET DEFAULT '',
233 ADD `datecreated` DATE NOT NULL AFTER `timestamp`");
234 $dbh->do("UPDATE deletedbiblio SET datecreated = timestamp");
236 # deletedbiblioitems changes
237 $dbh->do("ALTER TABLE `deletedbiblioitems`
238 MODIFY `publicationyear` TEXT,
239 CHANGE `volumeddesc` `volumedesc` TEXT,
240 MODIFY `collectiontitle` MEDIUMTEXT DEFAULT NULL AFTER `volumedesc`,
241 MODIFY `collectionissn` TEXT DEFAULT NULL AFTER `collectiontitle`,
242 MODIFY `collectionvolume` MEDIUMTEXT DEFAULT NULL AFTER `collectionissn`,
243 MODIFY `editionstatement` TEXT DEFAULT NULL AFTER `collectionvolume`,
244 MODIFY `editionresponsibility` TEXT DEFAULT NULL AFTER `editionstatement`,
245 MODIFY `place` VARCHAR(255) DEFAULT NULL AFTER `size`,
246 MODIFY `marc` LONGBLOB,
247 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `url`,
248 ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
249 ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
250 ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
251 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
252 ADD `totalissues` INT(10) AFTER `cn_sort`,
253 ADD `marcxml` LONGTEXT NOT NULL AFTER `totalissues`,
254 ADD KEY `isbn` (`isbn`),
255 ADD KEY `publishercode` (`publishercode`)
258 $dbh->do("UPDATE `deletedbiblioitems`
259 SET `cn_class` = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
260 `cn_item` = `subclass`,
263 $dbh->do("ALTER TABLE `deletedbiblioitems`
264 DROP COLUMN `classification`,
266 DROP COLUMN `subclass`,
267 DROP COLUMN `lcsort`,
271 # deleteditems changes
272 $dbh->do("ALTER TABLE `deleteditems`
273 MODIFY `barcode` VARCHAR(20) DEFAULT NULL,
274 MODIFY `price` DECIMAL(8,2) DEFAULT NULL,
275 MODIFY `replacementprice` DECIMAL(8,2) DEFAULT NULL,
277 MODIFY `itemcallnumber` VARCHAR(30) DEFAULT NULL AFTER `wthdrawn`,
278 MODIFY `holdingbranch` VARCHAR(10) DEFAULT NULL,
280 MODIFY `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP AFTER `paidfor`,
282 ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
283 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
284 ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
285 ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
286 ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`,
287 MODIFY `marc` LONGBLOB AFTER `uri`,
289 DROP KEY `itembarcodeidx`,
290 DROP KEY `itembinoidx`,
291 DROP KEY `itembibnoidx`,
292 ADD UNIQUE KEY `delitembarcodeidx` (`barcode`),
293 ADD KEY `delitembinoidx` (`biblioitemnumber`),
294 ADD KEY `delitembibnoidx` (`biblionumber`),
295 ADD KEY `delhomebranch` (`homebranch`),
296 ADD KEY `delholdingbranch` (`holdingbranch`)");
297 $dbh->do("UPDATE deleteditems SET `ccode` = `itype`");
298 $dbh->do("ALTER TABLE deleteditems DROP `itype`");
299 $dbh->do("UPDATE `deleteditems` SET `cn_sort` = `itemcallnumber`");
302 $dbh->do("ALTER TABLE `items` ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
303 ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
304 ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
305 ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
306 ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`
308 $dbh->do("ALTER TABLE `items`
309 DROP KEY `itembarcodeidx`,
310 ADD UNIQUE KEY `itembarcodeidx` (`barcode`)");
312 # map items.itype to items.ccode and
313 # set cn_sort to itemcallnumber -- as with biblioitems.cn_sort,
314 # will have to be subsequently updated per user's default
315 # classification scheme
316 $dbh->do("UPDATE `items` SET `cn_sort` = `itemcallnumber`,
319 $dbh->do("ALTER TABLE `items` DROP `cutterextra`,
322 print "Upgrade to $DBversion done (major changes to biblio, biblioitems, items, and deleted* versions of same\n";
323 SetVersion ($DBversion);
326 $DBversion = "3.00.00.010";
327 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
328 $dbh->do("CREATE INDEX `userid` ON borrowers (`userid`) ");
329 print "Upgrade to $DBversion done (userid index added)\n";
330 SetVersion ($DBversion);
333 $DBversion = "3.00.00.011";
334 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
335 $dbh->do("ALTER TABLE `branchcategories` CHANGE `categorycode` `categorycode` varchar(10) ");
336 $dbh->do("ALTER TABLE `branchcategories` CHANGE `categoryname` `categoryname` varchar(32) ");
337 $dbh->do("ALTER TABLE `branchcategories` ADD COLUMN `categorytype` varchar(16) ");
338 $dbh->do("UPDATE `branchcategories` SET `categorytype` = 'properties'");
339 $dbh->do("ALTER TABLE `branchrelations` CHANGE `categorycode` `categorycode` varchar(10) ");
340 print "Upgrade to $DBversion done (added branchcategory type)\n";
341 SetVersion ($DBversion);
344 $DBversion = "3.00.00.012";
345 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
346 $dbh->do("CREATE TABLE `class_sort_rules` (
347 `class_sort_rule` varchar(10) NOT NULL default '',
348 `description` mediumtext,
349 `sort_routine` varchar(30) NOT NULL default '',
350 PRIMARY KEY (`class_sort_rule`),
351 UNIQUE KEY `class_sort_rule_idx` (`class_sort_rule`)
352 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
353 $dbh->do("CREATE TABLE `class_sources` (
354 `cn_source` varchar(10) NOT NULL default '',
355 `description` mediumtext,
356 `used` tinyint(4) NOT NULL default 0,
357 `class_sort_rule` varchar(10) NOT NULL default '',
358 PRIMARY KEY (`cn_source`),
359 UNIQUE KEY `cn_source_idx` (`cn_source`),
360 KEY `used_idx` (`used`),
361 CONSTRAINT `class_source_ibfk_1` FOREIGN KEY (`class_sort_rule`)
362 REFERENCES `class_sort_rules` (`class_sort_rule`)
363 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
364 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type)
365 VALUES('DefaultClassificationSource','ddc',
366 'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.', NULL,'free')");
367 $dbh->do("INSERT INTO `class_sort_rules` (`class_sort_rule`, `description`, `sort_routine`) VALUES
368 ('dewey', 'Default filing rules for DDC', 'Dewey'),
369 ('lcc', 'Default filing rules for LCC', 'LCC'),
370 ('generic', 'Generic call number filing rules', 'Generic')");
371 $dbh->do("INSERT INTO `class_sources` (`cn_source`, `description`, `used`, `class_sort_rule`) VALUES
372 ('ddc', 'Dewey Decimal Classification', 1, 'dewey'),
373 ('lcc', 'Library of Congress Classification', 1, 'lcc'),
374 ('udc', 'Universal Decimal Classification', 0, 'generic'),
375 ('sudocs', 'SuDoc Classification (U.S. GPO)', 0, 'generic'),
376 ('z', 'Other/Generic Classification Scheme', 0, 'generic')");
377 print "Upgrade to $DBversion done (classification sources added)\n";
378 SetVersion ($DBversion);
381 $DBversion = "3.00.00.013";
382 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
383 $dbh->do("CREATE TABLE `import_batches` (
384 `import_batch_id` int(11) NOT NULL auto_increment,
385 `template_id` int(11) default NULL,
386 `branchcode` varchar(10) default NULL,
387 `num_biblios` int(11) NOT NULL default 0,
388 `num_items` int(11) NOT NULL default 0,
389 `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
390 `overlay_action` enum('replace', 'create_new', 'use_template') NOT NULL default 'create_new',
391 `import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging',
392 `batch_type` enum('batch', 'z3950') NOT NULL default 'batch',
393 `file_name` varchar(100),
394 `comments` mediumtext,
395 PRIMARY KEY (`import_batch_id`),
396 KEY `branchcode` (`branchcode`)
397 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
398 $dbh->do("CREATE TABLE `import_records` (
399 `import_record_id` int(11) NOT NULL auto_increment,
400 `import_batch_id` int(11) NOT NULL,
401 `branchcode` varchar(10) default NULL,
402 `record_sequence` int(11) NOT NULL default 0,
403 `upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
404 `import_date` DATE default NULL,
405 `marc` longblob NOT NULL,
406 `marcxml` longtext NOT NULL,
407 `marcxml_old` longtext NOT NULL,
408 `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio',
409 `overlay_status` enum('no_match', 'auto_match', 'manual_match', 'match_applied') NOT NULL default 'no_match',
410 `status` enum('error', 'staged', 'imported', 'reverted', 'items_reverted') NOT NULL default 'staged',
411 `import_error` mediumtext,
412 `encoding` varchar(40) NOT NULL default '',
413 `z3950random` varchar(40) default NULL,
414 PRIMARY KEY (`import_record_id`),
415 CONSTRAINT `import_records_ifbk_1` FOREIGN KEY (`import_batch_id`)
416 REFERENCES `import_batches` (`import_batch_id`) ON DELETE CASCADE ON UPDATE CASCADE,
417 KEY `branchcode` (`branchcode`),
418 KEY `batch_sequence` (`import_batch_id`, `record_sequence`)
419 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
420 $dbh->do("CREATE TABLE `import_record_matches` (
421 `import_record_id` int(11) NOT NULL,
422 `candidate_match_id` int(11) NOT NULL,
423 `score` int(11) NOT NULL default 0,
424 CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`)
425 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
426 KEY `record_score` (`import_record_id`, `score`)
427 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
428 $dbh->do("CREATE TABLE `import_biblios` (
429 `import_record_id` int(11) NOT NULL,
430 `matched_biblionumber` int(11) default NULL,
431 `control_number` varchar(25) default NULL,
432 `original_source` varchar(25) default NULL,
433 `title` varchar(128) default NULL,
434 `author` varchar(80) default NULL,
435 `isbn` varchar(14) default NULL,
436 `issn` varchar(9) default NULL,
437 `has_items` tinyint(1) NOT NULL default 0,
438 CONSTRAINT `import_biblios_ibfk_1` FOREIGN KEY (`import_record_id`)
439 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
440 KEY `matched_biblionumber` (`matched_biblionumber`),
441 KEY `title` (`title`),
443 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
444 $dbh->do("CREATE TABLE `import_items` (
445 `import_items_id` int(11) NOT NULL auto_increment,
446 `import_record_id` int(11) NOT NULL,
447 `itemnumber` int(11) default NULL,
448 `branchcode` varchar(10) default NULL,
449 `status` enum('error', 'staged', 'imported', 'reverted') NOT NULL default 'staged',
450 `marcxml` longtext NOT NULL,
451 `import_error` mediumtext,
452 PRIMARY KEY (`import_items_id`),
453 CONSTRAINT `import_items_ibfk_1` FOREIGN KEY (`import_record_id`)
454 REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
455 KEY `itemnumber` (`itemnumber`),
456 KEY `branchcode` (`branchcode`)
457 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
459 $dbh->do("INSERT INTO `import_batches`
460 (`overlay_action`, `import_status`, `batch_type`, `file_name`)
461 SELECT distinct 'create_new', 'staged', 'z3950', `file`
462 FROM `marc_breeding`");
464 $dbh->do("INSERT INTO `import_records`
465 (`import_batch_id`, `import_record_id`, `record_sequence`, `marc`, `record_type`, `status`,
466 `encoding`, `z3950random`, `marcxml`, `marcxml_old`)
467 SELECT `import_batch_id`, `id`, 1, `marc`, 'biblio', 'staged', `encoding`, `z3950random`, '', ''
469 JOIN `import_batches` ON (`file_name` = `file`)");
471 $dbh->do("INSERT INTO `import_biblios`
472 (`import_record_id`, `title`, `author`, `isbn`)
473 SELECT `import_record_id`, `title`, `author`, `isbn`
475 JOIN `import_records` ON (`import_record_id` = `id`)");
477 $dbh->do("UPDATE `import_batches`
478 SET `num_biblios` = (
480 FROM `import_records`
481 WHERE `import_batch_id` = `import_batches`.`import_batch_id`
484 $dbh->do("DROP TABLE `marc_breeding`");
486 print "Upgrade to $DBversion done (import_batches et al. added)\n";
487 SetVersion ($DBversion);
490 $DBversion = "3.00.00.014";
491 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
492 $dbh->do("ALTER TABLE subscription ADD lastbranch VARCHAR(4)");
493 print "Upgrade to $DBversion done (userid index added)\n";
494 SetVersion ($DBversion);
497 $DBversion = "3.00.00.015";
498 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
499 $dbh->do("CREATE TABLE `saved_sql` (
500 `id` int(11) NOT NULL auto_increment,
501 `borrowernumber` int(11) default NULL,
502 `date_created` datetime default NULL,
503 `last_modified` datetime default NULL,
505 `last_run` datetime default NULL,
506 `report_name` varchar(255) default NULL,
507 `type` varchar(255) default NULL,
510 KEY boridx (`borrowernumber`)
511 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
512 $dbh->do("CREATE TABLE `saved_reports` (
513 `id` int(11) NOT NULL auto_increment,
514 `report_id` int(11) default NULL,
516 `date_run` datetime default NULL,
518 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
519 print "Upgrade to $DBversion done (saved_sql and saved_reports added)\n";
520 SetVersion ($DBversion);
523 $DBversion = "3.00.00.016";
524 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
525 $dbh->do(" CREATE TABLE reports_dictionary (
526 id int(11) NOT NULL auto_increment,
527 name varchar(255) default NULL,
529 date_created datetime default NULL,
530 date_modified datetime default NULL,
532 area int(11) default NULL,
534 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
535 print "Upgrade to $DBversion done (reports_dictionary) added)\n";
536 SetVersion ($DBversion);
539 $DBversion = "3.00.00.017";
540 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
541 $dbh->do("ALTER TABLE action_logs DROP PRIMARY KEY");
542 $dbh->do("ALTER TABLE action_logs ADD KEY timestamp (timestamp,user)");
543 $dbh->do("ALTER TABLE action_logs ADD action_id INT(11) NOT NULL FIRST");
544 $dbh->do("UPDATE action_logs SET action_id = if (\@a, \@a:=\@a+1, \@a:=1)");
545 $dbh->do("ALTER TABLE action_logs MODIFY action_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY");
546 print "Upgrade to $DBversion done (added column to action_logs)\n";
547 SetVersion ($DBversion);
550 $DBversion = "3.00.00.018";
551 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
552 $dbh->do("ALTER TABLE `zebraqueue`
553 ADD `done` INT NOT NULL DEFAULT '0',
554 ADD `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ;
556 print "Upgrade to $DBversion done (adding timestamp and done columns to zebraque table to improve problem tracking) added)\n";
557 SetVersion ($DBversion);
560 $DBversion = "3.00.00.019";
561 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
562 $dbh->do("ALTER TABLE biblio MODIFY biblionumber INT(11) NOT NULL AUTO_INCREMENT");
563 $dbh->do("ALTER TABLE biblioitems MODIFY biblioitemnumber INT(11) NOT NULL AUTO_INCREMENT");
564 $dbh->do("ALTER TABLE items MODIFY itemnumber INT(11) NOT NULL AUTO_INCREMENT");
565 print "Upgrade to $DBversion done (made bib/item PKs auto_increment)\n";
566 SetVersion ($DBversion);
569 $DBversion = "3.00.00.020";
570 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
571 $dbh->do("ALTER TABLE deleteditems
572 DROP KEY `delitembarcodeidx`,
573 ADD KEY `delitembarcodeidx` (`barcode`)");
574 print "Upgrade to $DBversion done (dropped uniqueness of key on deleteditems.barcode)\n";
575 SetVersion ($DBversion);
578 $DBversion = "3.00.00.021";
579 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
580 $dbh->do("ALTER TABLE items CHANGE homebranch homebranch VARCHAR(10)");
581 $dbh->do("ALTER TABLE deleteditems CHANGE homebranch homebranch VARCHAR(10)");
582 $dbh->do("ALTER TABLE statistics CHANGE branch branch VARCHAR(10)");
583 $dbh->do("ALTER TABLE subscription CHANGE lastbranch lastbranch VARCHAR(10)");
584 print "Upgrade to $DBversion done (extended missed branchcode columns to 10 chars)\n";
585 SetVersion ($DBversion);
588 $DBversion = "3.00.00.022";
589 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
590 $dbh->do("ALTER TABLE items
591 ADD `damaged` tinyint(1) default NULL AFTER notforloan");
592 $dbh->do("ALTER TABLE deleteditems
593 ADD `damaged` tinyint(1) default NULL AFTER notforloan");
594 print "Upgrade to $DBversion done (adding damaged column to items table)\n";
595 SetVersion ($DBversion);
598 $DBversion = "3.00.00.023";
599 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
600 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
601 VALUES ('yuipath','http://yui.yahooapis.com/2.3.1/build','Insert the path to YUI libraries','','free')");
602 print "Upgrade to $DBversion done (adding new system preference for controlling YUI path)\n";
603 SetVersion ($DBversion);
605 $DBversion = "3.00.00.024";
606 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
607 $dbh->do("ALTER TABLE biblioitems CHANGE itemtype itemtype VARCHAR(10)");
608 print "Upgrade to $DBversion done (changing itemtype to (10))\n";
609 SetVersion ($DBversion);
612 $DBversion = "3.00.00.025";
613 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
614 $dbh->do("ALTER TABLE items ADD COLUMN itype VARCHAR(10)");
615 $dbh->do("ALTER TABLE deleteditems ADD COLUMN itype VARCHAR(10) AFTER uri");
616 if(C4::Context->preference('item-level_itypes')){
617 $dbh->do('update items,biblioitems set items.itype=biblioitems.itemtype where items.biblionumber=biblioitems.biblionumber and itype is null');
619 print "Upgrade to $DBversion done (reintroduce items.itype - fill from itemtype)\n ";
620 SetVersion ($DBversion);
623 $DBversion = "3.00.00.026";
624 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
625 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
626 VALUES ('HomeOrHoldingBranch','homebranch','homebranch|holdingbranch','With independent branches turned on this decides whether to check the items holdingbranch or homebranch at circulatilon','choice')");
627 print "Upgrade to $DBversion done (adding new system preference for choosing whether homebranch or holdingbranch is checked in circulation)\n";
628 SetVersion ($DBversion);
631 $DBversion = "3.00.00.027";
632 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
633 $dbh->do("CREATE TABLE `marc_matchers` (
634 `matcher_id` int(11) NOT NULL auto_increment,
635 `code` varchar(10) NOT NULL default '',
636 `description` varchar(255) NOT NULL default '',
637 `record_type` varchar(10) NOT NULL default 'biblio',
638 `threshold` int(11) NOT NULL default 0,
639 PRIMARY KEY (`matcher_id`),
641 KEY `record_type` (`record_type`)
642 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
643 $dbh->do("CREATE TABLE `matchpoints` (
644 `matcher_id` int(11) NOT NULL,
645 `matchpoint_id` int(11) NOT NULL auto_increment,
646 `search_index` varchar(30) NOT NULL default '',
647 `score` int(11) NOT NULL default 0,
648 PRIMARY KEY (`matchpoint_id`),
649 CONSTRAINT `matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
650 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE
651 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
652 $dbh->do("CREATE TABLE `matchpoint_components` (
653 `matchpoint_id` int(11) NOT NULL,
654 `matchpoint_component_id` int(11) NOT NULL auto_increment,
655 sequence int(11) NOT NULL default 0,
656 tag varchar(3) NOT NULL default '',
657 subfields varchar(40) NOT NULL default '',
658 offset int(4) NOT NULL default 0,
659 length int(4) NOT NULL default 0,
660 PRIMARY KEY (`matchpoint_component_id`),
661 KEY `by_sequence` (`matchpoint_id`, `sequence`),
662 CONSTRAINT `matchpoint_components_ifbk_1` FOREIGN KEY (`matchpoint_id`)
663 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
664 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
665 $dbh->do("CREATE TABLE `matchpoint_component_norms` (
666 `matchpoint_component_id` int(11) NOT NULL,
667 `sequence` int(11) NOT NULL default 0,
668 `norm_routine` varchar(50) NOT NULL default '',
669 KEY `matchpoint_component_norms` (`matchpoint_component_id`, `sequence`),
670 CONSTRAINT `matchpoint_component_norms_ifbk_1` FOREIGN KEY (`matchpoint_component_id`)
671 REFERENCES `matchpoint_components` (`matchpoint_component_id`) ON DELETE CASCADE ON UPDATE CASCADE
672 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
673 $dbh->do("CREATE TABLE `matcher_matchpoints` (
674 `matcher_id` int(11) NOT NULL,
675 `matchpoint_id` int(11) NOT NULL,
676 CONSTRAINT `matcher_matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
677 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
678 CONSTRAINT `matcher_matchpoints_ifbk_2` FOREIGN KEY (`matchpoint_id`)
679 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
680 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
681 $dbh->do("CREATE TABLE `matchchecks` (
682 `matcher_id` int(11) NOT NULL,
683 `matchcheck_id` int(11) NOT NULL auto_increment,
684 `source_matchpoint_id` int(11) NOT NULL,
685 `target_matchpoint_id` int(11) NOT NULL,
686 PRIMARY KEY (`matchcheck_id`),
687 CONSTRAINT `matcher_matchchecks_ifbk_1` FOREIGN KEY (`matcher_id`)
688 REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
689 CONSTRAINT `matcher_matchchecks_ifbk_2` FOREIGN KEY (`source_matchpoint_id`)
690 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE,
691 CONSTRAINT `matcher_matchchecks_ifbk_3` FOREIGN KEY (`target_matchpoint_id`)
692 REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
693 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
694 print "Upgrade to $DBversion done (added C4::Matcher serialization tables)\n ";
695 SetVersion ($DBversion);
698 $DBversion = "3.00.00.028";
699 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
700 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
701 VALUES ('canreservefromotherbranches','1','','With Independent branches on, can a user from one library reserve an item from another library','YesNo')");
702 print "Upgrade to $DBversion done (adding new system preference for changing reserve/holds behaviour with independent branches)\n";
703 SetVersion ($DBversion);
707 $DBversion = "3.00.00.029";
708 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
709 $dbh->do("ALTER TABLE `import_batches` ADD `matcher_id` int(11) NULL AFTER `import_batch_id`");
710 print "Upgrade to $DBversion done (adding matcher_id to import_batches)\n";
711 SetVersion ($DBversion);
714 $DBversion = "3.00.00.030";
715 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
717 CREATE TABLE services_throttle (
718 service_type varchar(10) NOT NULL default '',
719 service_count varchar(45) default NULL,
720 PRIMARY KEY (service_type)
721 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
723 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
724 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')");
725 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
726 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')");
727 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
728 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')");
729 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
730 VALUES ('XISBNDailyLimit',499,'','The xISBN Web service is free for non-commercial use when usage does not exceed 500 requests per day','free')");
731 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
732 VALUES ('PINESISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use PINES OISBN web service in the Editions tab on the detail pages.','YesNo')");
733 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
734 VALUES ('ThingISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use the ThingISBN web service in the Editions tab on the detail pages.','YesNo')");
735 print "Upgrade to $DBversion done (adding services throttle table and sysprefs for xISBN)\n";
736 SetVersion ($DBversion);
739 $DBversion = "3.00.00.031";
740 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
742 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryStemming',1,'If ON, enables query stemming',NULL,'YesNo')");
743 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryFuzzy',1,'If ON, enables fuzzy option for searches',NULL,'YesNo')");
744 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryWeightFields',1,'If ON, enables field weighting',NULL,'YesNo')");
745 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('WebBasedSelfCheck',0,'If ON, enables the web-based self-check system',NULL,'YesNo')");
746 $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')");
747 $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')");
748 $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')");
749 $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')");
750 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('defaultSortOrder',NULL,'Specify the default sort order','asc|dsc|az|za','Choice')");
751 $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')");
752 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACdefaultSortOrder',NULL,'Specify the default sort order','asc|dsc|za|az','Choice')");
753 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('staffClientBaseURL','','Specify the base URL of the staff client',NULL,'free')");
754 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('minPasswordLength',3,'Specify the minimum length of a patron/staff password',NULL,'free')");
755 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('noItemTypeImages',0,'If ON, disables item-type images',NULL,'YesNo')");
756 $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')");
757 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('holdCancelLength','','Specify how many days before a hold is canceled',NULL,'free')");
758 $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')");
759 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('finesMode','test','Choose the fines mode, test or production','test|production','Choice')");
760 $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')");
761 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeInputFilter','','If set, allows specification of a item barcode input filter','cuecat','Choice')");
762 $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')");
763 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('URLLinkText','','Text to display as the link anchor in the OPAC',NULL,'free')");
764 $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')");
765 $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')");
766 $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')");
767 $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')");
768 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACUserCSS',0,'Add CSS to be included in the OPAC',NULL,'free')");
770 print "Upgrade to $DBversion done (adding additional system preference)\n";
771 SetVersion ($DBversion);
774 $DBversion = "3.00.00.032";
775 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
776 $dbh->do("UPDATE `marc_subfield_structure` SET `kohafield` = 'items.wthdrawn' WHERE `kohafield` = 'items.withdrawn'");
777 print "Upgrade to $DBversion done (fixed MARC framework references to items.withdrawn)\n";
778 SetVersion ($DBversion);
781 $DBversion = "3.00.00.033";
782 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
783 $dbh->do("INSERT INTO `userflags` VALUES(17,'staffaccess','Modify login / permissions for staff users',0)");
784 print "Upgrade to $DBversion done (Adding permissions flag for staff member access modification. )\n";
785 SetVersion ($DBversion);
788 $DBversion = "3.00.00.034";
789 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
790 $dbh->do("ALTER TABLE `virtualshelves` ADD COLUMN `sortfield` VARCHAR(16) ");
791 print "Upgrade to $DBversion done (Adding sortfield for Virtual Shelves. )\n";
792 SetVersion ($DBversion);
795 $DBversion = "3.00.00.035";
796 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
797 $dbh->do("UPDATE marc_subfield_structure
798 SET authorised_value = 'cn_source'
799 WHERE kohafield IN ('items.cn_source', 'biblioitems.cn_source')
800 AND (authorised_value is NULL OR authorised_value = '')");
801 print "Upgrade to $DBversion done (MARC frameworks: make classification source a drop-down)\n";
802 SetVersion ($DBversion);
805 $DBversion = "3.00.00.036";
806 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
807 $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');");
808 print "Upgrade to $DBversion done (OPACItemsResultsDisplay systempreference added)\n";
809 SetVersion ($DBversion);
812 $DBversion = "3.00.00.037";
813 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
814 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactfirstname` varchar(255)");
815 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactsurname` varchar(255)");
816 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress1` varchar(255)");
817 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress2` varchar(255)");
818 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress3` varchar(255)");
819 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactzipcode` varchar(50)");
820 $dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactphone` varchar(50)");
821 print "Upgrade to $DBversion done (Adding Alternative Contact Person information to borrowers table)\n";
822 SetVersion ($DBversion);
825 $DBversion = "3.00.00.038";
826 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
827 $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'");
828 $dbh->do("DELETE FROM `systempreferences` WHERE variable='hideBiblioNumber'");
829 print "Upgrade to $DBversion done ('alter finesMode systempreference, remove superfluous syspref.')\n";
830 SetVersion ($DBversion);
833 $DBversion = "3.00.00.039";
834 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
835 $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')");
836 $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')");
837 $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')");
838 # $dbh->do("DELETE FROM `systempreferences` WHERE variable='HomeOrHoldingBranch'"); # Bug #2752
839 print "Upgrade to $DBversion done ('add circ sysprefs CircControl, finesCalendar, and uppercasesurnames, and delete HomeOrHoldingBranch.')\n";
840 SetVersion ($DBversion);
843 $DBversion = "3.00.00.040";
844 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
845 $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')");
846 $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')");
847 print "Upgrade to $DBversion done ('add circ sysprefs todaysIssuesDefaultSortOrder and previousIssuesDefaultSortOrder.')\n";
848 SetVersion ($DBversion);
852 $DBversion = "3.00.00.041";
853 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
854 # Strictly speaking it is not necessary to explicitly change
855 # NULL values to 0, because the ALTER TABLE statement will do that.
856 # However, setting them first avoids a warning.
857 $dbh->do("UPDATE items SET notforloan = 0 WHERE notforloan IS NULL");
858 $dbh->do("UPDATE items SET damaged = 0 WHERE damaged IS NULL");
859 $dbh->do("UPDATE items SET itemlost = 0 WHERE itemlost IS NULL");
860 $dbh->do("UPDATE items SET wthdrawn = 0 WHERE wthdrawn IS NULL");
861 $dbh->do("ALTER TABLE items
862 MODIFY notforloan tinyint(1) NOT NULL default 0,
863 MODIFY damaged tinyint(1) NOT NULL default 0,
864 MODIFY itemlost tinyint(1) NOT NULL default 0,
865 MODIFY wthdrawn tinyint(1) NOT NULL default 0");
866 $dbh->do("UPDATE deleteditems SET notforloan = 0 WHERE notforloan IS NULL");
867 $dbh->do("UPDATE deleteditems SET damaged = 0 WHERE damaged IS NULL");
868 $dbh->do("UPDATE deleteditems SET itemlost = 0 WHERE itemlost IS NULL");
869 $dbh->do("UPDATE deleteditems SET wthdrawn = 0 WHERE wthdrawn IS NULL");
870 $dbh->do("ALTER TABLE deleteditems
871 MODIFY notforloan tinyint(1) NOT NULL default 0,
872 MODIFY damaged tinyint(1) NOT NULL default 0,
873 MODIFY itemlost tinyint(1) NOT NULL default 0,
874 MODIFY wthdrawn tinyint(1) NOT NULL default 0");
875 print "Upgrade to $DBversion done (disallow NULL in several item status columns)\n";
876 SetVersion ($DBversion);
879 $DBversion = "3.00.00.04";
880 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
881 $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
882 print "Upgrade to $DBversion done (disallow NULL in aqbooksellers.name; part of fix for bug 1251)\n";
883 SetVersion ($DBversion);
886 $DBversion = "3.00.00.043";
887 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
888 $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");
889 print "Upgrade to $DBversion done (currency table: add symbol and timestamp columns)\n";
890 SetVersion ($DBversion);
893 $DBversion = "3.00.00.044";
894 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
895 $dbh->do("ALTER TABLE deletedborrowers
896 ADD `altcontactfirstname` varchar(255) default NULL,
897 ADD `altcontactsurname` varchar(255) default NULL,
898 ADD `altcontactaddress1` varchar(255) default NULL,
899 ADD `altcontactaddress2` varchar(255) default NULL,
900 ADD `altcontactaddress3` varchar(255) default NULL,
901 ADD `altcontactzipcode` varchar(50) default NULL,
902 ADD `altcontactphone` varchar(50) default NULL
904 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
905 ('OPACBaseURL',NULL,'Specify the Base URL of the OPAC, e.g., opac.mylibrary.com, the http:// will be added automatically by Koha.',NULL,'Free'),
906 ('language','en','Set the default language in the staff client.',NULL,'Languages'),
907 ('QueryAutoTruncate',1,'If ON, query truncation is enabled by default',NULL,'YesNo'),
908 ('QueryRemoveStopwords',0,'If ON, stopwords listed in the Administration area will be removed from queries',NULL,'YesNo')
910 print "Upgrade to $DBversion done (syncing deletedborrowers table with borrowers table)\n";
911 SetVersion ($DBversion);
914 #-- http://www.w3.org/International/articles/language-tags/
917 $DBversion = "3.00.00.045";
918 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
920 CREATE TABLE language_subtag_registry (
922 type varchar(25), -- language-script-region-variant-extension-privateuse
923 description varchar(25), -- only one of the possible descriptions for ease of reference, see language_descriptions for the complete list
925 KEY `subtag` (`subtag`)
926 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
928 #-- TODO: add suppress_scripts
929 #-- this maps three letter codes defined in iso639.2 back to their
930 #-- two letter equivilents in rfc4646 (LOC maintains iso639+)
931 $dbh->do("CREATE TABLE language_rfc4646_to_iso639 (
932 rfc4646_subtag varchar(25),
933 iso639_2_code varchar(25),
934 KEY `rfc4646_subtag` (`rfc4646_subtag`)
935 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
937 $dbh->do("CREATE TABLE language_descriptions (
941 description varchar(255),
943 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
945 #-- bi-directional support, keyed by script subcode
946 $dbh->do("CREATE TABLE language_script_bidi (
947 rfc4646_subtag varchar(25), -- script subtag, Arab, Hebr, etc.
948 bidi varchar(3), -- rtl ltr
949 KEY `rfc4646_subtag` (`rfc4646_subtag`)
950 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
952 #-- BIDI Stuff, Arabic and Hebrew
953 $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
954 VALUES( 'Arab', 'rtl')");
955 $dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
956 VALUES( 'Hebr', 'rtl')");
958 #-- TODO: need to map language subtags to script subtags for detection
959 #-- of bidi when script is not specified (like ar, he)
960 $dbh->do("CREATE TABLE language_script_mapping (
961 language_subtag varchar(25),
962 script_subtag varchar(25),
963 KEY `language_subtag` (`language_subtag`)
964 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
966 #-- Default mappings between script and language subcodes
967 $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
968 VALUES( 'ar', 'Arab')");
969 $dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
970 VALUES( 'he', 'Hebr')");
972 print "Upgrade to $DBversion done (adding language subtag registry and basic BiDi support NOTE: You should import the subtag registry SQL)\n";
973 SetVersion ($DBversion);
976 $DBversion = "3.00.00.046";
977 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
978 $dbh->do("ALTER TABLE `subscription` CHANGE `numberlength` `numberlength` int(11) default '0' ,
979 CHANGE `weeklength` `weeklength` int(11) default '0'");
980 $dbh->do("CREATE TABLE `serialitems` (`serialid` int(11) NOT NULL, `itemnumber` int(11) NOT NULL, UNIQUE KEY `serialididx` (`serialid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
981 $dbh->do("INSERT INTO `serialitems` SELECT `serialid`,`itemnumber` from serial where NOT ISNULL(itemnumber) && itemnumber <> '' && itemnumber NOT LIKE '%,%'");
982 print "Upgrade to $DBversion done (Add serialitems table to link serial issues to items. )\n";
983 SetVersion ($DBversion);
986 $DBversion = "3.00.00.047";
987 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
988 $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');");
989 print "Upgrade to $DBversion done ( Added OpacRenewalAllowed syspref )\n";
990 SetVersion ($DBversion);
993 $DBversion = "3.00.00.048";
994 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
995 $dbh->do("ALTER TABLE `items` ADD `more_subfields_xml` longtext default NULL AFTER `itype`");
996 print "Upgrade to $DBversion done (added items.more_subfields_xml)\n";
997 SetVersion ($DBversion);
1000 $DBversion = "3.00.00.049";
1001 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1002 $dbh->do("ALTER TABLE `z3950servers` ADD `encoding` text default NULL AFTER type ");
1003 print "Upgrade to $DBversion done ( Added encoding field to z3950servers table )\n";
1004 SetVersion ($DBversion);
1007 $DBversion = "3.00.00.050";
1008 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1009 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHighlightedWords','0','If Set, query matched terms are highlighted in OPAC',NULL,'YesNo');");
1010 print "Upgrade to $DBversion done ( Added OpacHighlightedWords syspref )\n";
1011 SetVersion ($DBversion);
1014 $DBversion = "3.00.00.051";
1015 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1016 $dbh->do("UPDATE systempreferences SET explanation = 'Define the current theme for the OPAC interface.' WHERE variable = 'opacthemes';");
1017 print "Upgrade to $DBversion done ( Corrected opacthemes explanation. )\n";
1018 SetVersion ($DBversion);
1021 $DBversion = "3.00.00.052";
1022 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1023 $dbh->do("ALTER TABLE `deleteditems` ADD `more_subfields_xml` LONGTEXT DEFAULT NULL AFTER `itype`");
1024 print "Upgrade to $DBversion done ( Adding missing column to deleteditems table. )\n";
1025 SetVersion ($DBversion);
1028 $DBversion = "3.00.00.053";
1029 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1030 $dbh->do("CREATE TABLE `printers_profile` (
1031 `prof_id` int(4) NOT NULL auto_increment,
1032 `printername` varchar(40) NOT NULL,
1033 `tmpl_id` int(4) NOT NULL,
1034 `paper_bin` varchar(20) NOT NULL,
1035 `offset_horz` float default NULL,
1036 `offset_vert` float default NULL,
1037 `creep_horz` float default NULL,
1038 `creep_vert` float default NULL,
1039 `unit` char(20) NOT NULL default 'POINT',
1040 PRIMARY KEY (`prof_id`),
1041 UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
1042 CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
1043 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1044 $dbh->do("CREATE TABLE `labels_profile` (
1045 `tmpl_id` int(4) NOT NULL,
1046 `prof_id` int(4) NOT NULL,
1047 UNIQUE KEY `tmpl_id` (`tmpl_id`),
1048 UNIQUE KEY `prof_id` (`prof_id`)
1049 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1050 print "Upgrade to $DBversion done ( Printer Profile tables added )\n";
1051 SetVersion ($DBversion);
1054 $DBversion = "3.00.00.054";
1055 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1056 $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';");
1057 print "Upgrade to $DBversion done ( Added another barcode autogeneration sequence to barcode.pl. )\n";
1058 SetVersion ($DBversion);
1061 $DBversion = "3.00.00.055";
1062 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1063 $dbh->do("ALTER TABLE `zebraqueue` ADD KEY `zebraqueue_lookup` (`server`, `biblio_auth_number`, `operation`, `done`)");
1064 print "Upgrade to $DBversion done ( Added index on zebraqueue. )\n";
1065 SetVersion ($DBversion);
1067 $DBversion = "3.00.00.056";
1068 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1069 if (C4::Context->preference("marcflavour") eq 'UNIMARC') {
1070 $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) ");
1072 $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) ");
1074 $dbh->do("ALTER TABLE `items` ADD `enumchron` VARCHAR(80) DEFAULT NULL;");
1075 print "Upgrade to $DBversion done ( Added item.enumchron column, and framework map to 952h )\n";
1076 SetVersion ($DBversion);
1079 $DBversion = "3.00.00.057";
1080 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1081 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH','0','if ON, OAI-PMH server is enabled',NULL,'YesNo');");
1082 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OAI-PMH:archiveID','KOHA-OAI-TEST','OAI-PMH archive identification',NULL,'Free');");
1083 $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');");
1084 $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');");
1085 $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');");
1086 SetVersion ($DBversion);
1089 $DBversion = "3.00.00.058";
1090 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1091 $dbh->do("ALTER TABLE `opac_news`
1092 CHANGE `lang` `lang` VARCHAR( 25 )
1094 COLLATE utf8_general_ci
1095 NOT NULL default ''");
1096 print "Upgrade to $DBversion done ( lang field in opac_news made longer )\n";
1097 SetVersion ($DBversion);
1100 $DBversion = "3.00.00.059";
1101 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1103 $dbh->do("CREATE TABLE IF NOT EXISTS `labels_templates` (
1104 `tmpl_id` int(4) NOT NULL auto_increment,
1105 `tmpl_code` char(100) default '',
1106 `tmpl_desc` char(100) default '',
1107 `page_width` float default '0',
1108 `page_height` float default '0',
1109 `label_width` float default '0',
1110 `label_height` float default '0',
1111 `topmargin` float default '0',
1112 `leftmargin` float default '0',
1113 `cols` int(2) default '0',
1114 `rows` int(2) default '0',
1115 `colgap` float default '0',
1116 `rowgap` float default '0',
1117 `active` int(1) default NULL,
1118 `units` char(20) default 'PX',
1119 `fontsize` int(4) NOT NULL default '3',
1120 PRIMARY KEY (`tmpl_id`)
1121 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1122 $dbh->do("CREATE TABLE IF NOT EXISTS `printers_profile` (
1123 `prof_id` int(4) NOT NULL auto_increment,
1124 `printername` varchar(40) NOT NULL,
1125 `tmpl_id` int(4) NOT NULL,
1126 `paper_bin` varchar(20) NOT NULL,
1127 `offset_horz` float default NULL,
1128 `offset_vert` float default NULL,
1129 `creep_horz` float default NULL,
1130 `creep_vert` float default NULL,
1131 `unit` char(20) NOT NULL default 'POINT',
1132 PRIMARY KEY (`prof_id`),
1133 UNIQUE KEY `printername` (`printername`,`tmpl_id`,`paper_bin`),
1134 CONSTRAINT `printers_profile_pnfk_1` FOREIGN KEY (`tmpl_id`) REFERENCES `labels_templates` (`tmpl_id`) ON DELETE CASCADE ON UPDATE CASCADE
1135 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
1136 print "Upgrade to $DBversion done ( Added labels_templates table if it did not exist. )\n";
1137 SetVersion ($DBversion);
1140 $DBversion = "3.00.00.060";
1141 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1142 $dbh->do("CREATE TABLE IF NOT EXISTS `patronimage` (
1143 `cardnumber` varchar(16) NOT NULL,
1144 `mimetype` varchar(15) NOT NULL,
1145 `imagefile` mediumblob NOT NULL,
1146 PRIMARY KEY (`cardnumber`),
1147 CONSTRAINT `patronimage_fk1` FOREIGN KEY (`cardnumber`) REFERENCES `borrowers` (`cardnumber`) ON DELETE CASCADE ON UPDATE CASCADE
1148 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1149 print "Upgrade to $DBversion done ( Added patronimage table. )\n";
1150 SetVersion ($DBversion);
1153 $DBversion = "3.00.00.061";
1154 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1155 $dbh->do("ALTER TABLE labels_templates ADD COLUMN font char(10) NOT NULL DEFAULT 'TR';");
1156 print "Upgrade to $DBversion done ( Added font column to labels_templates )\n";
1157 SetVersion ($DBversion);
1160 $DBversion = "3.00.00.062";
1161 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1162 $dbh->do("CREATE TABLE `old_issues` (
1163 `borrowernumber` int(11) default NULL,
1164 `itemnumber` int(11) default NULL,
1165 `date_due` date default NULL,
1166 `branchcode` varchar(10) default NULL,
1167 `issuingbranch` varchar(18) default NULL,
1168 `returndate` date default NULL,
1169 `lastreneweddate` date default NULL,
1170 `return` varchar(4) default NULL,
1171 `renewals` tinyint(4) default NULL,
1172 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1173 `issuedate` date default NULL,
1174 KEY `old_issuesborridx` (`borrowernumber`),
1175 KEY `old_issuesitemidx` (`itemnumber`),
1176 KEY `old_bordate` (`borrowernumber`,`timestamp`),
1177 CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1178 ON DELETE SET NULL ON UPDATE SET NULL,
1179 CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1180 ON DELETE SET NULL ON UPDATE SET NULL
1181 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1182 $dbh->do("CREATE TABLE `old_reserves` (
1183 `borrowernumber` int(11) default NULL,
1184 `reservedate` date default NULL,
1185 `biblionumber` int(11) default NULL,
1186 `constrainttype` varchar(1) default NULL,
1187 `branchcode` varchar(10) default NULL,
1188 `notificationdate` date default NULL,
1189 `reminderdate` date default NULL,
1190 `cancellationdate` date default NULL,
1191 `reservenotes` mediumtext,
1192 `priority` smallint(6) default NULL,
1193 `found` varchar(1) default NULL,
1194 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1195 `itemnumber` int(11) default NULL,
1196 `waitingdate` date default NULL,
1197 KEY `old_reserves_borrowernumber` (`borrowernumber`),
1198 KEY `old_reserves_biblionumber` (`biblionumber`),
1199 KEY `old_reserves_itemnumber` (`itemnumber`),
1200 KEY `old_reserves_branchcode` (`branchcode`),
1201 CONSTRAINT `old_reserves_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1202 ON DELETE SET NULL ON UPDATE SET NULL,
1203 CONSTRAINT `old_reserves_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`)
1204 ON DELETE SET NULL ON UPDATE SET NULL,
1205 CONSTRAINT `old_reserves_ibfk_3` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`)
1206 ON DELETE SET NULL ON UPDATE SET NULL
1207 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1209 # move closed transactions to old_* tables
1210 $dbh->do("INSERT INTO old_issues SELECT * FROM issues WHERE returndate IS NOT NULL");
1211 $dbh->do("DELETE FROM issues WHERE returndate IS NOT NULL");
1212 $dbh->do("INSERT INTO old_reserves SELECT * FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
1213 $dbh->do("DELETE FROM reserves WHERE cancellationdate IS NOT NULL OR found = 'F'");
1215 print "Upgrade to $DBversion done ( Added old_issues and old_reserves tables )\n";
1216 SetVersion ($DBversion);
1219 $DBversion = "3.00.00.063";
1220 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1221 $dbh->do("ALTER TABLE deleteditems
1222 CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT DEFAULT NULL,
1223 ADD COLUMN enumchron VARCHAR(80) DEFAULT NULL AFTER more_subfields_xml,
1224 ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
1225 $dbh->do("ALTER TABLE items
1226 CHANGE COLUMN booksellerid booksellerid MEDIUMTEXT,
1227 ADD COLUMN copynumber SMALLINT(6) DEFAULT NULL AFTER enumchron;");
1228 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";
1229 SetVersion ($DBversion);
1232 $DBversion = "3.00.00.064";
1233 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1234 $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');");
1235 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AWSAccessKeyID','','See: http://aws.amazon.com','','free');");
1236 $dbh->do("DELETE FROM `systempreferences` WHERE variable='AmazonDevKey';");
1237 $dbh->do("DELETE FROM `systempreferences` WHERE variable='XISBNAmazonSimilarItems';");
1238 $dbh->do("DELETE FROM `systempreferences` WHERE variable='OPACXISBNAmazonSimilarItems';");
1239 print "Upgrade to $DBversion done (IMPORTANT: Upgrading to Amazon.com Associates Web Service 4.0 ) \n";
1240 SetVersion ($DBversion);
1243 $DBversion = "3.00.00.065";
1244 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1245 $dbh->do("CREATE TABLE `patroncards` (
1246 `cardid` int(11) NOT NULL auto_increment,
1247 `batch_id` varchar(10) NOT NULL default '1',
1248 `borrowernumber` int(11) NOT NULL,
1249 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1250 PRIMARY KEY (`cardid`),
1251 KEY `patroncards_ibfk_1` (`borrowernumber`),
1252 CONSTRAINT `patroncards_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1253 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
1254 print "Upgrade to $DBversion done (Adding patroncards table for patroncards generation feature. ) \n";
1255 SetVersion ($DBversion);
1258 $DBversion = "3.00.00.066";
1259 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1260 $dbh->do("ALTER TABLE `virtualshelfcontents` MODIFY `dateadded` timestamp NOT NULL
1261 DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;
1263 print "Upgrade to $DBversion done (fix for bug 1873: virtualshelfcontents dateadded column empty. ) \n";
1264 SetVersion ($DBversion);
1267 $DBversion = "3.00.00.067";
1268 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1269 $dbh->do("UPDATE systempreferences SET explanation = 'Enable patron images for the Staff Client', type = 'YesNo' WHERE variable = 'patronimages'");
1270 print "Upgrade to $DBversion done (Updating patronimages syspref to reflect current kohastructure.sql. ) \n";
1271 SetVersion ($DBversion);
1274 $DBversion = "3.00.00.068";
1275 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1276 $dbh->do("CREATE TABLE `permissions` (
1277 `module_bit` int(11) NOT NULL DEFAULT 0,
1278 `code` varchar(30) DEFAULT NULL,
1279 `description` varchar(255) DEFAULT NULL,
1280 PRIMARY KEY (`module_bit`, `code`),
1281 CONSTRAINT `permissions_ibfk_1` FOREIGN KEY (`module_bit`) REFERENCES `userflags` (`bit`)
1282 ON DELETE CASCADE ON UPDATE CASCADE
1283 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1284 $dbh->do("CREATE TABLE `user_permissions` (
1285 `borrowernumber` int(11) NOT NULL DEFAULT 0,
1286 `module_bit` int(11) NOT NULL DEFAULT 0,
1287 `code` varchar(30) DEFAULT NULL,
1288 CONSTRAINT `user_permissions_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1289 ON DELETE CASCADE ON UPDATE CASCADE,
1290 CONSTRAINT `user_permissions_ibfk_2` FOREIGN KEY (`module_bit`, `code`)
1291 REFERENCES `permissions` (`module_bit`, `code`)
1292 ON DELETE CASCADE ON UPDATE CASCADE
1293 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1295 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES
1296 (13, 'edit_news', 'Write news for the OPAC and staff interfaces'),
1297 (13, 'label_creator', 'Create printable labels and barcodes from catalog and patron data'),
1298 (13, 'edit_calendar', 'Define days when the library is closed'),
1299 (13, 'moderate_comments', 'Moderate patron comments'),
1300 (13, 'edit_notices', 'Define notices'),
1301 (13, 'edit_notice_status_triggers', 'Set notice/status triggers for overdue items'),
1302 (13, 'view_system_logs', 'Browse the system logs'),
1303 (13, 'inventory', 'Perform inventory (stocktaking) of your catalogue'),
1304 (13, 'stage_marc_import', 'Stage MARC records into the reservoir'),
1305 (13, 'manage_staged_marc', 'Managed staged MARC records, including completing and reversing imports'),
1306 (13, 'export_catalog', 'Export bibliographic and holdings data'),
1307 (13, 'import_patrons', 'Import patron data'),
1308 (13, 'delete_anonymize_patrons', 'Delete old borrowers and anonymize circulation history (deletes borrower reading history)'),
1309 (13, 'batch_upload_patron_images', 'Upload patron images in batch or one at a time'),
1310 (13, 'schedule_tasks', 'Schedule tasks to run')");
1312 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('GranularPermissions','0','Use detailed staff user permissions',NULL,'YesNo')");
1314 print "Upgrade to $DBversion done (adding permissions and user_permissions tables and GranularPermissions syspref) \n";
1315 SetVersion ($DBversion);
1317 $DBversion = "3.00.00.069";
1318 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1319 $dbh->do("ALTER TABLE labels_conf CHANGE COLUMN class classification int(1) DEFAULT NULL;");
1320 print "Upgrade to $DBversion done ( Correcting columname in labels_conf )\n";
1321 SetVersion ($DBversion);
1324 $DBversion = "3.00.00.070";
1325 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1326 $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='yuipath'");
1328 my ($value) = $sth->fetchrow;
1329 $value =~ s/2.3.1/2.5.1/;
1330 $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='yuipath';");
1331 print "Update yuipath syspref to 2.5.1 if necessary\n";
1332 SetVersion ($DBversion);
1335 $DBversion = "3.00.00.071";
1336 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1337 $dbh->do(" ALTER TABLE `subscription` ADD `serialsadditems` TINYINT( 1 ) NOT NULL DEFAULT '0';");
1338 # fill the new field with the previous systempreference value, then drop the syspref
1339 my $sth = $dbh->prepare("SELECT value FROM systempreferences WHERE variable='serialsadditems'");
1341 my ($serialsadditems) = $sth->fetchrow();
1342 $dbh->do("UPDATE subscription SET serialsadditems=$serialsadditems");
1343 $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
1344 print "Upgrade to $DBversion done ( moving serialsadditems from syspref to subscription )\n";
1345 SetVersion ($DBversion);
1348 $DBversion = "3.00.00.072";
1349 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1350 $dbh->do("ALTER TABLE labels_conf ADD COLUMN formatstring mediumtext DEFAULT NULL AFTER printingtype");
1351 print "Upgrade to $DBversion done ( Adding format string to labels generator. )\n";
1352 SetVersion ($DBversion);
1355 $DBversion = "3.00.00.073";
1356 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1357 $dbh->do("DROP TABLE IF EXISTS `tags_all`;");
1359 CREATE TABLE `tags_all` (
1360 `tag_id` int(11) NOT NULL auto_increment,
1361 `borrowernumber` int(11) NOT NULL,
1362 `biblionumber` int(11) NOT NULL,
1363 `term` varchar(255) NOT NULL,
1364 `language` int(4) default NULL,
1365 `date_created` datetime NOT NULL,
1366 PRIMARY KEY (`tag_id`),
1367 KEY `tags_borrowers_fk_1` (`borrowernumber`),
1368 KEY `tags_biblionumber_fk_1` (`biblionumber`),
1369 CONSTRAINT `tags_borrowers_fk_1` FOREIGN KEY (`borrowernumber`)
1370 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1371 CONSTRAINT `tags_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
1372 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1373 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1375 $dbh->do("DROP TABLE IF EXISTS `tags_approval`;");
1377 CREATE TABLE `tags_approval` (
1378 `term` varchar(255) NOT NULL,
1379 `approved` int(1) NOT NULL default '0',
1380 `date_approved` datetime default NULL,
1381 `approved_by` int(11) default NULL,
1382 `weight_total` int(9) NOT NULL default '1',
1383 PRIMARY KEY (`term`),
1384 KEY `tags_approval_borrowers_fk_1` (`approved_by`),
1385 CONSTRAINT `tags_approval_borrowers_fk_1` FOREIGN KEY (`approved_by`)
1386 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
1387 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1389 $dbh->do("DROP TABLE IF EXISTS `tags_index`;");
1391 CREATE TABLE `tags_index` (
1392 `term` varchar(255) NOT NULL,
1393 `biblionumber` int(11) NOT NULL,
1394 `weight` int(9) NOT NULL default '1',
1395 PRIMARY KEY (`term`,`biblionumber`),
1396 KEY `tags_index_biblionumber_fk_1` (`biblionumber`),
1397 CONSTRAINT `tags_index_term_fk_1` FOREIGN KEY (`term`)
1398 REFERENCES `tags_approval` (`term`) ON DELETE CASCADE ON UPDATE CASCADE,
1399 CONSTRAINT `tags_index_biblionumber_fk_1` FOREIGN KEY (`biblionumber`)
1400 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE
1401 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1404 INSERT INTO `systempreferences` VALUES
1405 ('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=',''),
1406 ('BakerTaylorEnabled','0','','Enable or disable all Baker & Taylor features.','YesNo'),
1407 ('BakerTaylorPassword','','','Baker & Taylor Password for Content Cafe (external content)','Textarea'),
1408 ('BakerTaylorUsername','','','Baker & Taylor Username for Content Cafe (external content)','Textarea'),
1409 ('TagsEnabled','1','','Enables or disables all tagging features. This is the main switch for tags.','YesNo'),
1410 ('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.',''),
1411 ('TagsInputOnDetail','1','','Allow users to input tags from the detail page.', 'YesNo'),
1412 ('TagsInputOnList', '0','','Allow users to input tags from the search results list.', 'YesNo'),
1413 ('TagsModeration', NULL,'','Require tags from patrons to be approved before becoming visible.','YesNo'),
1414 ('TagsShowOnDetail','10','','Number of tags to display on detail page. 0 is off.', 'Integer'),
1415 ('TagsShowOnList', '6','','Number of tags to display on search results list. 0 is off.','Integer')
1417 print "Upgrade to $DBversion done (Baker/Taylor,Tags: sysprefs and tables (tags_all, tags_index, tags_approval)) \n";
1418 SetVersion ($DBversion);
1421 $DBversion = "3.00.00.074";
1422 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1423 $dbh->do( q(update itemtypes set imageurl = concat( 'npl/', imageurl )
1424 where imageurl not like 'http%'
1425 and imageurl is not NULL
1426 and imageurl != '') );
1427 print "Upgrade to $DBversion done (updating imagetype.imageurls to reflect new icon locations.)\n";
1428 SetVersion ($DBversion);
1431 $DBversion = "3.00.00.075";
1432 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1433 $dbh->do( q(alter table authorised_values add imageurl varchar(200) default NULL) );
1434 print "Upgrade to $DBversion done (adding imageurl field to authorised_values table)\n";
1435 SetVersion ($DBversion);
1438 $DBversion = "3.00.00.076";
1439 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1440 $dbh->do("ALTER TABLE import_batches
1441 ADD COLUMN nomatch_action enum('create_new', 'ignore') NOT NULL default 'create_new' AFTER overlay_action");
1442 $dbh->do("ALTER TABLE import_batches
1443 ADD COLUMN item_action enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore')
1444 NOT NULL default 'always_add' AFTER nomatch_action");
1445 $dbh->do("ALTER TABLE import_batches
1446 MODIFY overlay_action enum('replace', 'create_new', 'use_template', 'ignore')
1447 NOT NULL default 'create_new'");
1448 $dbh->do("ALTER TABLE import_records
1449 MODIFY status enum('error', 'staged', 'imported', 'reverted', 'items_reverted',
1450 'ignored') NOT NULL default 'staged'");
1451 $dbh->do("ALTER TABLE import_items
1452 MODIFY status enum('error', 'staged', 'imported', 'reverted', 'ignored') NOT NULL default 'staged'");
1454 print "Upgrade to $DBversion done (changes to import_batches and import_records)\n";
1455 SetVersion ($DBversion);
1458 $DBversion = "3.00.00.077";
1459 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1460 # drop these tables only if they exist and none of them are empty
1461 # these tables are not defined in the packaged 2.2.9, but since it is believed
1462 # that at least one library may be using them in a post-2.2.9 but pre-3.0 Koha,
1463 # some care is taken.
1464 my ($print_error) = $dbh->{PrintError};
1465 $dbh->{PrintError} = 0;
1466 my ($raise_error) = $dbh->{RaiseError};
1467 $dbh->{RaiseError} = 1;
1471 eval { $count = $dbh->do("SELECT 1 FROM categorytable"); };
1475 eval { $count = $dbh->do("SELECT 1 FROM mediatypetable"); };
1479 eval { $count = $dbh->do("SELECT 1 FROM subcategorytable"); };
1485 $dbh->do("DROP TABLE IF EXISTS `categorytable`");
1486 $dbh->do("DROP TABLE IF EXISTS `mediatypetable`");
1487 $dbh->do("DROP TABLE IF EXISTS `subcategorytable`");
1490 $dbh->{PrintError} = $print_error;
1491 $dbh->{RaiseError} = $raise_error;
1492 print "Upgrade to $DBversion done (drop categorytable, subcategorytable, and mediatypetable)\n";
1493 SetVersion ($DBversion);
1496 $DBversion = "3.00.00.078";
1497 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1498 my ($print_error) = $dbh->{PrintError};
1499 $dbh->{PrintError} = 0;
1501 unless ($dbh->do("SELECT 1 FROM browser")) {
1502 $dbh->{PrintError} = $print_error;
1503 $dbh->do("CREATE TABLE `browser` (
1504 `level` int(11) NOT NULL,
1505 `classification` varchar(20) NOT NULL,
1506 `description` varchar(255) NOT NULL,
1507 `number` bigint(20) NOT NULL,
1508 `endnode` tinyint(4) NOT NULL
1509 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1511 $dbh->{PrintError} = $print_error;
1512 print "Upgrade to $DBversion done (add browser table if not already present)\n";
1513 SetVersion ($DBversion);
1516 $DBversion = "3.00.00.079";
1517 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1518 my ($print_error) = $dbh->{PrintError};
1519 $dbh->{PrintError} = 0;
1521 $dbh->do("INSERT INTO `systempreferences` (variable, value,options,type, explanation)VALUES
1522 ('AddPatronLists','categorycode','categorycode|category_type','Choice','Allow user to choose what list to pick up from when adding patrons')");
1523 print "Upgrade to $DBversion done (add browser table if not already present)\n";
1524 SetVersion ($DBversion);
1527 $DBversion = "3.00.00.080";
1528 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1529 $dbh->do("ALTER TABLE subscription CHANGE monthlength monthlength int(11) default '0'");
1530 $dbh->do("ALTER TABLE deleteditems MODIFY marc LONGBLOB AFTER copynumber");
1531 $dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
1532 print "Upgrade to $DBversion done (catch up on DB schema changes since alpha and beta)\n";
1533 SetVersion ($DBversion);
1536 $DBversion = "3.00.00.081";
1537 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1538 $dbh->do("CREATE TABLE `borrower_attribute_types` (
1539 `code` varchar(10) NOT NULL,
1540 `description` varchar(255) NOT NULL,
1541 `repeatable` tinyint(1) NOT NULL default 0,
1542 `unique_id` tinyint(1) NOT NULL default 0,
1543 `opac_display` tinyint(1) NOT NULL default 0,
1544 `password_allowed` tinyint(1) NOT NULL default 0,
1545 `staff_searchable` tinyint(1) NOT NULL default 0,
1546 `authorised_value_category` varchar(10) default NULL,
1547 PRIMARY KEY (`code`)
1548 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1549 $dbh->do("CREATE TABLE `borrower_attributes` (
1550 `borrowernumber` int(11) NOT NULL,
1551 `code` varchar(10) NOT NULL,
1552 `attribute` varchar(30) default NULL,
1553 `password` varchar(30) default NULL,
1554 KEY `borrowernumber` (`borrowernumber`),
1555 KEY `code_attribute` (`code`, `attribute`),
1556 CONSTRAINT `borrower_attributes_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`)
1557 ON DELETE CASCADE ON UPDATE CASCADE,
1558 CONSTRAINT `borrower_attributes_ibfk_2` FOREIGN KEY (`code`) REFERENCES `borrower_attribute_types` (`code`)
1559 ON DELETE CASCADE ON UPDATE CASCADE
1560 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1561 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ExtendedPatronAttributes','0','Use extended patron IDs and attributes',NULL,'YesNo')");
1562 print "Upgrade to $DBversion done (added borrower_attributes and borrower_attribute_types)\n";
1563 SetVersion ($DBversion);
1566 $DBversion = "3.00.00.082";
1567 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1568 $dbh->do( q(alter table accountlines add column lastincrement decimal(28,6) default NULL) );
1569 print "Upgrade to $DBversion done (adding lastincrement column to accountlines table)\n";
1570 SetVersion ($DBversion);
1573 $DBversion = "3.00.00.083";
1574 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1575 $dbh->do( qq(UPDATE systempreferences SET value='local' where variable='yuipath' and value like "%/intranet-tmpl/prog/%"));
1576 print "Upgrade to $DBversion done (Changing yuipath behaviour in managing a local value)\n";
1577 SetVersion ($DBversion);
1579 $DBversion = "3.00.00.084";
1580 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1581 $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')");
1582 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('GoogleJackets','0','if ON, displays jacket covers from Google Books API',NULL,'YesNo')");
1583 print "Upgrade to $DBversion done (add new sysprefs)\n";
1584 SetVersion ($DBversion);
1587 $DBversion = "3.00.00.085";
1588 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1589 if (C4::Context->preference("marcflavour") eq 'MARC21') {
1590 $dbh->do("UPDATE marc_subfield_structure SET tab = 0 WHERE tab = 9 AND tagfield = '037'");
1591 $dbh->do("UPDATE marc_subfield_structure SET tab = 1 WHERE tab = 6 AND tagfield in ('100', '110', '111', '130')");
1592 $dbh->do("UPDATE marc_subfield_structure SET tab = 2 WHERE tab = 6 AND tagfield in ('240', '243')");
1593 $dbh->do("UPDATE marc_subfield_structure SET tab = 4 WHERE tab = 6 AND tagfield in ('400', '410', '411', '440')");
1594 $dbh->do("UPDATE marc_subfield_structure SET tab = 5 WHERE tab = 9 AND tagfield = '584'");
1595 $dbh->do("UPDATE marc_subfield_structure SET tab = 7 WHERE tab = -6 AND tagfield = '760'");
1597 print "Upgrade to $DBversion done (move editing tab of various MARC21 subfields)\n";
1598 SetVersion ($DBversion);
1601 $DBversion = "3.00.00.086";
1602 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1604 "CREATE TABLE `tmp_holdsqueue` (
1605 `biblionumber` int(11) default NULL,
1606 `itemnumber` int(11) default NULL,
1607 `barcode` varchar(20) default NULL,
1608 `surname` mediumtext NOT NULL,
1611 `borrowernumber` int(11) NOT NULL,
1612 `cardnumber` varchar(16) default NULL,
1613 `reservedate` date default NULL,
1615 `itemcallnumber` varchar(30) default NULL,
1616 `holdingbranch` varchar(10) default NULL,
1617 `pickbranch` varchar(10) default NULL,
1619 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
1621 $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')");
1622 $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')");
1624 print "Upgrade to $DBversion done (Table structure for table `tmp_holdsqueue`)\n";
1625 SetVersion ($DBversion);
1628 $DBversion = "3.00.00.087";
1629 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1630 $dbh->do("INSERT INTO `systempreferences` VALUES ('AutoEmailOpacUser','0','','Sends notification emails containing new account details to patrons - when account is created.','YesNo')" );
1631 $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')");
1632 print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
1633 SetVersion ($DBversion);
1636 $DBversion = "3.00.00.088";
1637 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1638 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ('OPACShelfBrowser','1','','Enable/disable Shelf Browser on item details page','YesNo')");
1639 $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')");
1640 $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')");
1641 $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')");
1642 print "Upgrade to $DBversion done (added 2 new 'AutoEmailOpacUser' sysprefs)\n";
1643 SetVersion ($DBversion);
1646 $DBversion = "3.00.00.089";
1647 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1648 $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')");
1649 print "Upgrade to $DBversion done (added new AdvancedSearchTypes syspref)\n";
1650 SetVersion ($DBversion);
1653 $DBversion = "3.00.00.090";
1654 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1656 CREATE TABLE `branch_borrower_circ_rules` (
1657 `branchcode` VARCHAR(10) NOT NULL,
1658 `categorycode` VARCHAR(10) NOT NULL,
1659 `maxissueqty` int(4) default NULL,
1660 PRIMARY KEY (`categorycode`, `branchcode`),
1661 CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
1662 ON DELETE CASCADE ON UPDATE CASCADE,
1663 CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
1664 ON DELETE CASCADE ON UPDATE CASCADE
1665 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1668 CREATE TABLE `default_borrower_circ_rules` (
1669 `categorycode` VARCHAR(10) NOT NULL,
1670 `maxissueqty` int(4) default NULL,
1671 PRIMARY KEY (`categorycode`),
1672 CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
1673 ON DELETE CASCADE ON UPDATE CASCADE
1674 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1677 CREATE TABLE `default_branch_circ_rules` (
1678 `branchcode` VARCHAR(10) NOT NULL,
1679 `maxissueqty` int(4) default NULL,
1680 PRIMARY KEY (`branchcode`),
1681 CONSTRAINT `default_branch_circ_rules_ibfk_1` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`)
1682 ON DELETE CASCADE ON UPDATE CASCADE
1683 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1686 CREATE TABLE `default_circ_rules` (
1687 `singleton` enum('singleton') NOT NULL default 'singleton',
1688 `maxissueqty` int(4) default NULL,
1689 PRIMARY KEY (`singleton`)
1690 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1692 print "Upgrade to $DBversion done (added several circ rules tables)\n";
1693 SetVersion ($DBversion);
1697 $DBversion = "3.00.00.091";
1698 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1699 $dbh->do(<<'END_SQL');
1700 ALTER TABLE borrowers
1701 ADD `smsalertnumber` varchar(50) default NULL
1704 $dbh->do(<<'END_SQL');
1705 CREATE TABLE `message_attributes` (
1706 `message_attribute_id` int(11) NOT NULL auto_increment,
1707 `message_name` varchar(20) NOT NULL default '',
1708 `takes_days` tinyint(1) NOT NULL default '0',
1709 PRIMARY KEY (`message_attribute_id`),
1710 UNIQUE KEY `message_name` (`message_name`)
1711 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1714 $dbh->do(<<'END_SQL');
1715 CREATE TABLE `message_transport_types` (
1716 `message_transport_type` varchar(20) NOT NULL,
1717 PRIMARY KEY (`message_transport_type`)
1718 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1721 $dbh->do(<<'END_SQL');
1722 CREATE TABLE `message_transports` (
1723 `message_attribute_id` int(11) NOT NULL,
1724 `message_transport_type` varchar(20) NOT NULL,
1725 `is_digest` tinyint(1) NOT NULL default '0',
1726 `letter_module` varchar(20) NOT NULL default '',
1727 `letter_code` varchar(20) NOT NULL default '',
1728 PRIMARY KEY (`message_attribute_id`,`message_transport_type`,`is_digest`),
1729 KEY `message_transport_type` (`message_transport_type`),
1730 KEY `letter_module` (`letter_module`,`letter_code`),
1731 CONSTRAINT `message_transports_ibfk_1` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE,
1732 CONSTRAINT `message_transports_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE CASCADE ON UPDATE CASCADE,
1733 CONSTRAINT `message_transports_ibfk_3` FOREIGN KEY (`letter_module`, `letter_code`) REFERENCES `letter` (`module`, `code`) ON DELETE CASCADE ON UPDATE CASCADE
1734 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1737 $dbh->do(<<'END_SQL');
1738 CREATE TABLE `borrower_message_preferences` (
1739 `borrower_message_preference_id` int(11) NOT NULL auto_increment,
1740 `borrowernumber` int(11) NOT NULL default '0',
1741 `message_attribute_id` int(11) default '0',
1742 `days_in_advance` int(11) default '0',
1743 `wants_digets` tinyint(1) NOT NULL default '0',
1744 PRIMARY KEY (`borrower_message_preference_id`),
1745 KEY `borrowernumber` (`borrowernumber`),
1746 KEY `message_attribute_id` (`message_attribute_id`),
1747 CONSTRAINT `borrower_message_preferences_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1748 CONSTRAINT `borrower_message_preferences_ibfk_2` FOREIGN KEY (`message_attribute_id`) REFERENCES `message_attributes` (`message_attribute_id`) ON DELETE CASCADE ON UPDATE CASCADE
1749 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1752 $dbh->do(<<'END_SQL');
1753 CREATE TABLE `borrower_message_transport_preferences` (
1754 `borrower_message_preference_id` int(11) NOT NULL default '0',
1755 `message_transport_type` varchar(20) NOT NULL default '0',
1756 PRIMARY KEY (`borrower_message_preference_id`,`message_transport_type`),
1757 KEY `message_transport_type` (`message_transport_type`),
1758 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,
1759 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
1760 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1763 $dbh->do(<<'END_SQL');
1764 CREATE TABLE `message_queue` (
1765 `message_id` int(11) NOT NULL auto_increment,
1766 `borrowernumber` int(11) NOT NULL,
1769 `message_transport_type` varchar(20) NOT NULL,
1770 `status` enum('sent','pending','failed','deleted') NOT NULL default 'pending',
1771 `time_queued` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
1772 KEY `message_id` (`message_id`),
1773 KEY `borrowernumber` (`borrowernumber`),
1774 KEY `message_transport_type` (`message_transport_type`),
1775 CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
1776 CONSTRAINT `messageq_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON DELETE RESTRICT ON UPDATE CASCADE
1777 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
1780 $dbh->do(<<'END_SQL');
1781 INSERT INTO `systempreferences`
1782 (variable,value,explanation,options,type)
1784 ('EnhancedMessagingPreferences',0,'If ON, allows patrons to select to receive additional messages about items due or nearly due.','','YesNo')
1787 $dbh->do( <<'END_SQL');
1788 INSERT INTO `letter`
1789 (module, code, name, title, content)
1791 ('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>>'),
1792 ('circulation','DUEDGST','Item Due Reminder (Digest)','Item Due Reminder','You have <<count>> items due'),
1793 ('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>>'),
1794 ('circulation','PREDUEDGST','Advance Notice of Item Due (Digest)','Advance Notice of Item Due','You have <<count>> items due soon'),
1795 ('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.');
1799 'installer/data/mysql/en/mandatory/message_transport_types.sql',
1800 'installer/data/mysql/en/optional/sample_notices_message_attributes.sql',
1801 'installer/data/mysql/en/optional/sample_notices_message_transports.sql',
1804 my $installer = C4::Installer->new();
1805 foreach my $script ( @sql_scripts ) {
1806 my $full_path = $installer->get_file_path_from_name($script);
1807 my $error = $installer->load_sql($full_path);
1808 warn $error if $error;
1811 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";
1812 SetVersion ($DBversion);
1815 $DBversion = "3.00.00.092";
1816 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1817 $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')");
1818 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES('AllowHoldsOnDamagedItems', '1', '', 'Allow hold requests to be placed on damaged items', 'YesNo')");
1819 print "Upgrade to $DBversion done (added new AllowOnShelfHolds syspref)\n";
1820 SetVersion ($DBversion);
1823 $DBversion = "3.00.00.093";
1824 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1825 $dbh->do("ALTER TABLE `items` MODIFY COLUMN `copynumber` VARCHAR(32) DEFAULT NULL");
1826 $dbh->do("ALTER TABLE `deleteditems` MODIFY COLUMN `copynumber` VARCHAR(32) DEFAULT NULL");
1827 print "Upgrade to $DBversion done (Change data type of items.copynumber to allow free text)\n";
1828 SetVersion ($DBversion);
1831 $DBversion = "3.00.00.094";
1832 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1833 $dbh->do("ALTER TABLE `marc_subfield_structure` MODIFY `tagsubfield` VARCHAR(1) NOT NULL DEFAULT '' COLLATE utf8_bin");
1834 print "Upgrade to $DBversion done (Change Collation of marc_subfield_structure to allow mixed case in subfield labels.)\n";
1835 SetVersion ($DBversion);
1838 $DBversion = "3.00.00.095";
1839 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1840 if (C4::Context->preference("marcflavour") eq 'MARC21') {
1841 $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'MEETI_NAME' WHERE authtypecode = 'Meeting Name'");
1842 $dbh->do("UPDATE marc_subfield_structure SET authtypecode = 'CORPO_NAME' WHERE authtypecode = 'CORP0_NAME'");
1844 print "Upgrade to $DBversion done (fix invalid authority types in MARC21 frameworks [bug 2254])\n";
1845 SetVersion ($DBversion);
1848 $DBversion = "3.00.00.096";
1849 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1850 $sth = $dbh->prepare("SHOW COLUMNS FROM borrower_message_preferences LIKE 'wants_digets'");
1852 if (my $row = $sth->fetchrow_hashref) {
1853 $dbh->do("ALTER TABLE borrower_message_preferences CHANGE wants_digets wants_digest tinyint(1) NOT NULL default 0");
1855 print "Upgrade to $DBversion done (fix name borrower_message_preferences.wants_digest)\n";
1856 SetVersion ($DBversion);
1859 $DBversion = '3.00.00.097';
1860 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1862 $dbh->do('ALTER TABLE message_queue ADD to_address mediumtext default NULL');
1863 $dbh->do('ALTER TABLE message_queue ADD from_address mediumtext default NULL');
1864 $dbh->do('ALTER TABLE message_queue ADD content_type text');
1865 $dbh->do('ALTER TABLE message_queue CHANGE borrowernumber borrowernumber int(11) default NULL');
1867 print "Upgrade to $DBversion done (updating 4 fields in message_queue table)\n";
1868 SetVersion($DBversion);
1871 $DBversion = '3.00.00.098';
1872 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1874 $dbh->do(q(DELETE FROM message_transport_types WHERE message_transport_type = 'rss'));
1875 $dbh->do(q(DELETE FROM message_transports WHERE message_transport_type = 'rss'));
1877 print "Upgrade to $DBversion done (removing unused RSS message_transport_type)\n";
1878 SetVersion($DBversion);
1881 $DBversion = '3.00.00.099';
1882 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1883 $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')");
1884 print "Upgrade to $DBversion done (Adding OpacSuppression syspref)\n";
1885 SetVersion($DBversion);
1888 $DBversion = '3.00.00.100';
1889 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1890 $dbh->do('ALTER TABLE virtualshelves ADD COLUMN lastmodified timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP');
1891 print "Upgrade to $DBversion done (Adding lastmodified column to virtualshelves)\n";
1892 SetVersion($DBversion);
1895 $DBversion = '3.00.00.101';
1896 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1897 $dbh->do('ALTER TABLE `overduerules` CHANGE `categorycode` `categorycode` VARCHAR(10) NOT NULL');
1898 $dbh->do('ALTER TABLE `deletedborrowers` CHANGE `categorycode` `categorycode` VARCHAR(10) NOT NULL');
1899 print "Upgrade to $DBversion done (Updating columnd definitions for patron category codes in notice/statsu triggers and deletedborrowers tables.)\n";
1900 SetVersion($DBversion);
1903 $DBversion = '3.00.00.102';
1904 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1905 $dbh->do('ALTER TABLE serialitems MODIFY `serialid` int(11) NOT NULL AFTER itemnumber' );
1906 $dbh->do('ALTER TABLE serialitems DROP KEY serialididx' );
1907 $dbh->do('ALTER TABLE serialitems ADD CONSTRAINT UNIQUE KEY serialitemsidx (itemnumber)' );
1908 # before setting constraint, delete any unvalid data
1909 $dbh->do('DELETE from serialitems WHERE serialid not in (SELECT serial.serialid FROM serial)');
1910 $dbh->do('ALTER TABLE serialitems ADD CONSTRAINT serialitems_sfk_1 FOREIGN KEY (serialid) REFERENCES serial (serialid) ON DELETE CASCADE ON UPDATE CASCADE' );
1911 print "Upgrade to $DBversion done (Updating serialitems table to allow for multiple items per serial fixing kohabug 2380)\n";
1912 SetVersion($DBversion);
1915 $DBversion = "3.00.00.103";
1916 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1917 $dbh->do("DELETE FROM systempreferences WHERE variable='serialsadditems'");
1918 print "Upgrade to $DBversion done ( Verifying the removal of serialsadditems from syspref fixing kohabug 2219)\n";
1919 SetVersion ($DBversion);
1922 $DBversion = "3.00.00.104";
1923 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1924 $dbh->do("DELETE FROM systempreferences WHERE variable='noOPACHolds'");
1925 print "Upgrade to $DBversion done (remove superseded 'noOPACHolds' system preference per bug 2413)\n";
1926 SetVersion ($DBversion);
1929 $DBversion = '3.00.00.105';
1930 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
1932 # it is possible that this syspref is already defined since the feature was added some time ago.
1933 unless ( $dbh->do(q(SELECT variable FROM systempreferences WHERE variable = 'SMSSendDriver')) ) {
1934 $dbh->do(<<'END_SQL');
1935 INSERT INTO `systempreferences`
1936 (variable,value,explanation,options,type)
1938 ('SMSSendDriver','','Sets which SMS::Send driver is used to send SMS messages.','','free')
1941 print "Upgrade to $DBversion done (added SMSSendDriver system preference)\n";
1942 SetVersion($DBversion);
1945 $DBversion = "3.00.00.106";
1946 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1947 $dbh->do("DELETE FROM systempreferences WHERE variable='noOPACHolds'");
1949 # db revision 105 didn't apply correctly, so we're rolling this into 106
1950 $dbh->do("INSERT INTO `systempreferences`
1951 (variable,value,explanation,options,type)
1953 ('SMSSendDriver','','Sets which SMS::Send driver is used to send SMS messages.','','free')");
1955 print "Upgrade to $DBversion done (remove default '0000-00-00' in subscriptionhistory.enddate field)\n";
1956 $dbh->do("ALTER TABLE `subscriptionhistory` CHANGE `enddate` `enddate` DATE NULL DEFAULT NULL ");
1957 $dbh->do("UPDATE subscriptionhistory SET enddate=NULL WHERE enddate='0000-00-00'");
1958 SetVersion ($DBversion);
1961 $DBversion = '3.00.00.107';
1962 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1963 $dbh->do(<<'END_SQL');
1964 UPDATE systempreferences
1965 SET explanation = CONCAT( explanation, '. WARNING: this feature is very resource consuming on collections with large numbers of items.' )
1966 WHERE variable = 'OPACShelfBrowser'
1967 AND explanation NOT LIKE '%WARNING%'
1969 $dbh->do(<<'END_SQL');
1970 UPDATE systempreferences
1971 SET explanation = CONCAT( explanation, '. WARNING: this feature is very resource consuming.' )
1972 WHERE variable = 'CataloguingLog'
1973 AND explanation NOT LIKE '%WARNING%'
1975 $dbh->do(<<'END_SQL');
1976 UPDATE systempreferences
1977 SET explanation = CONCAT( explanation, '. WARNING: using NoZebra on even modest sized collections is very slow.' )
1978 WHERE variable = 'NoZebra'
1979 AND explanation NOT LIKE '%WARNING%'
1981 print "Upgrade to $DBversion done (warning added to OPACShelfBrowser system preference)\n";
1982 SetVersion ($DBversion);
1985 $DBversion = '3.01.00.000';
1986 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
1987 print "Upgrade to $DBversion done (start of 3.1)\n";
1988 SetVersion ($DBversion);
1991 $DBversion = '3.01.00.001';
1992 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
1994 CREATE TABLE hold_fill_targets (
1995 `borrowernumber` int(11) NOT NULL,
1996 `biblionumber` int(11) NOT NULL,
1997 `itemnumber` int(11) NOT NULL,
1998 `source_branchcode` varchar(10) default NULL,
1999 `item_level_request` tinyint(4) NOT NULL default 0,
2000 PRIMARY KEY `itemnumber` (`itemnumber`),
2001 KEY `bib_branch` (`biblionumber`, `source_branchcode`),
2002 CONSTRAINT `hold_fill_targets_ibfk_1` FOREIGN KEY (`borrowernumber`)
2003 REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2004 CONSTRAINT `hold_fill_targets_ibfk_2` FOREIGN KEY (`biblionumber`)
2005 REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2006 CONSTRAINT `hold_fill_targets_ibfk_3` FOREIGN KEY (`itemnumber`)
2007 REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE,
2008 CONSTRAINT `hold_fill_targets_ibfk_4` FOREIGN KEY (`source_branchcode`)
2009 REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2010 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2013 ALTER TABLE tmp_holdsqueue
2014 ADD item_level_request tinyint(4) NOT NULL default 0
2017 print "Upgrade to $DBversion done (add hold_fill_targets table and a column to tmp_holdsqueue)\n";
2018 SetVersion($DBversion);
2021 $DBversion = '3.01.00.002';
2022 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2023 # use statistics where available
2025 ALTER TABLE statistics ADD KEY tmp_stats (type, itemnumber, borrowernumber)
2030 SELECT max(datetime)
2032 WHERE type = 'issue'
2033 AND itemnumber = iss.itemnumber
2034 AND borrowernumber = iss.borrowernumber
2036 WHERE issuedate IS NULL;
2038 $dbh->do("ALTER TABLE statistics DROP KEY tmp_stats");
2040 # default to last renewal date
2043 SET issuedate = lastreneweddate
2044 WHERE issuedate IS NULL
2045 and lastreneweddate IS NOT NULL
2048 my $num_bad_issuedates = $dbh->selectrow_array("SELECT COUNT(*) FROM issues WHERE issuedate IS NULL");
2049 if ($num_bad_issuedates > 0) {
2050 print STDERR "After the upgrade to $DBversion, there are still $num_bad_issuedates loan(s) with a NULL (blank) loan date. ",
2051 "Please check the issues table in your database.";
2053 print "Upgrade to $DBversion done (bug 2582: set null issues.issuedate to lastreneweddate)\n";
2054 SetVersion($DBversion);
2057 $DBversion = "3.01.00.003";
2058 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2059 $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')");
2060 print "Upgrade to $DBversion done (add new syspref)\n";
2061 SetVersion ($DBversion);
2064 $DBversion = '3.01.00.004';
2065 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2066 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACDisplayRequestPriority','0','Show patrons the priority level on holds in the OPAC','','YesNo')");
2067 print "Upgrade to $DBversion done (added OPACDisplayRequestPriority system preference)\n";
2068 SetVersion ($DBversion);
2071 $DBversion = '3.01.00.005';
2072 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2074 INSERT INTO `letter` (module, code, name, title, content)
2075 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>>')
2077 $dbh->do("INSERT INTO `message_attributes` (message_attribute_id, message_name, takes_days) values(4, 'Hold Filled', 0)");
2078 $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'sms', 0, 'reserves', 'HOLD')");
2079 $dbh->do("INSERT INTO `message_transports` (message_attribute_id, message_transport_type, is_digest, letter_module, letter_code) values(4, 'email', 0, 'reserves', 'HOLD')");
2080 print "Upgrade to $DBversion done (Add letter for holds notifications)\n";
2081 SetVersion ($DBversion);
2084 $DBversion = '3.01.00.006';
2085 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2086 $dbh->do("ALTER TABLE `biblioitems` ADD KEY issn (issn)");
2087 print "Upgrade to $DBversion done (add index on biblioitems.issn)\n";
2088 SetVersion ($DBversion);
2091 $DBversion = "3.01.00.007";
2092 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2093 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetmainUserblock'");
2094 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='intranetuserjs'");
2095 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacheader'");
2096 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacMainUserBlock'");
2097 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='OpacNav'");
2098 $dbh->do("UPDATE `systempreferences` SET options='70|10' WHERE variable='opacuserjs'");
2099 $dbh->do("UPDATE `systempreferences` SET options='30|10', type='Textarea' WHERE variable='OAI-PMH:Set'");
2100 $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetstylesheet'");
2101 $dbh->do("UPDATE `systempreferences` SET options='50' WHERE variable='intranetcolorstylesheet'");
2102 $dbh->do("UPDATE `systempreferences` SET options='10' WHERE variable='globalDueDate'");
2103 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='numSearchResults'");
2104 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='OPACnumSearchResults'");
2105 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='ReservesMaxPickupDelay'");
2106 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='TransfersMaxDaysWarning'");
2107 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='StaticHoldsQueueWeight'");
2108 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='holdCancelLength'");
2109 $dbh->do("UPDATE `systempreferences` SET type='Integer' WHERE variable='XISBNDailyLimit'");
2110 $dbh->do("UPDATE `systempreferences` SET type='Float' WHERE variable='gist'");
2111 $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorUsername'");
2112 $dbh->do("UPDATE `systempreferences` SET type='Free' WHERE variable='BakerTaylorPassword'");
2113 $dbh->do("UPDATE `systempreferences` SET type='Textarea', options='70|10' WHERE variable='ISBD'");
2114 $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'");
2115 print "Upgrade to $DBversion done (fix display of many sysprefs)\n";
2116 SetVersion ($DBversion);
2119 $DBversion = '3.01.00.008';
2120 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2122 $dbh->do("CREATE TABLE branch_transfer_limits (
2123 limitId int(8) NOT NULL auto_increment,
2124 toBranch varchar(4) NOT NULL,
2125 fromBranch varchar(4) NOT NULL,
2126 itemtype varchar(4) NOT NULL,
2127 PRIMARY KEY (limitId)
2128 ) ENGINE=InnoDB DEFAULT CHARSET=utf8"
2131 $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')");
2133 print "Upgrade to $DBversion done (added branch_transfer_limits table and UseBranchTransferLimits system preference)\n";
2134 SetVersion ($DBversion);
2137 $DBversion = "3.01.00.009";
2138 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2139 $dbh->do("ALTER TABLE permissions MODIFY `code` varchar(64) DEFAULT NULL");
2140 $dbh->do("ALTER TABLE user_permissions MODIFY `code` varchar(64) DEFAULT NULL");
2141 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'circulate_remaining_permissions', 'Remaining circulation permissions')");
2142 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 1, 'override_renewals', 'Override blocked renewals')");
2143 print "Upgrade to $DBversion done (added subpermissions for circulate permission)\n";
2146 $DBversion = '3.01.00.010';
2147 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2148 $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `attribute` VARCHAR(64) DEFAULT NULL");
2149 $dbh->do("ALTER TABLE `borrower_attributes` MODIFY COLUMN `password` VARCHAR(64) DEFAULT NULL");
2150 print "Upgrade to $DBversion done (bug 2687: increase length of borrower attribute fields)\n";
2151 SetVersion ($DBversion);
2154 $DBversion = '3.01.00.011';
2155 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2157 # Yes, the old value was ^M terminated.
2158 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);";
2160 my $intranetuserjs = C4::Context->preference('intranetuserjs');
2161 if ($intranetuserjs and $intranetuserjs eq $bad_value) {
2162 my $sql = <<'END_SQL';
2163 UPDATE systempreferences
2165 WHERE variable = 'intranetuserjs'
2169 print "Upgrade to $DBversion done (removed bogus intranetuserjs syspref)\n";
2170 SetVersion($DBversion);
2173 $DBversion = "3.01.00.012";
2174 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2175 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowHoldPolicyOverride', '0', 'Allow staff to override hold policies when placing holds',NULL,'YesNo')");
2177 CREATE TABLE `branch_item_rules` (
2178 `branchcode` varchar(10) NOT NULL,
2179 `itemtype` varchar(10) NOT NULL,
2180 `holdallowed` tinyint(1) default NULL,
2181 PRIMARY KEY (`itemtype`,`branchcode`),
2182 KEY `branch_item_rules_ibfk_2` (`branchcode`),
2183 CONSTRAINT `branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE,
2184 CONSTRAINT `branch_item_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE
2185 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2188 CREATE TABLE `default_branch_item_rules` (
2189 `itemtype` varchar(10) NOT NULL,
2190 `holdallowed` tinyint(1) default NULL,
2191 PRIMARY KEY (`itemtype`),
2192 CONSTRAINT `default_branch_item_rules_ibfk_1` FOREIGN KEY (`itemtype`) REFERENCES `itemtypes` (`itemtype`) ON DELETE CASCADE ON UPDATE CASCADE
2193 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2196 ALTER TABLE default_branch_circ_rules
2197 ADD COLUMN holdallowed tinyint(1) NULL
2200 ALTER TABLE default_circ_rules
2201 ADD COLUMN holdallowed tinyint(1) NULL
2203 print "Upgrade to $DBversion done (Add tables and system preferences for holds policies)\n";
2204 SetVersion ($DBversion);
2207 $DBversion = '3.01.00.013';
2208 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2210 CREATE TABLE item_circulation_alert_preferences (
2211 id int(11) AUTO_INCREMENT,
2212 branchcode varchar(10) NOT NULL,
2213 categorycode varchar(10) NOT NULL,
2214 item_type varchar(10) NOT NULL,
2215 notification varchar(16) NOT NULL,
2217 KEY (branchcode, categorycode, item_type, notification)
2218 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2221 $dbh->do(q{ ALTER TABLE `message_queue` ADD metadata text DEFAULT NULL AFTER content; });
2222 $dbh->do(q{ ALTER TABLE `message_queue` ADD letter_code varchar(64) DEFAULT NULL AFTER metadata; });
2225 INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES
2226 ('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.');
2229 INSERT INTO `letter` (`module`, `code`, `name`, `title`, `content`) VALUES
2230 ('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>>.');
2233 $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (5, 'Item Check-in', 0);});
2234 $dbh->do(q{INSERT INTO message_attributes (message_attribute_id, message_name, takes_days) VALUES (6, 'Item Checkout', 0);});
2236 $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');});
2237 $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');});
2238 $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');});
2239 $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');});
2241 print "Upgrade to $DBversion done (data for Email Checkout Slips project)\n";
2242 SetVersion ($DBversion);
2245 $DBversion = "3.01.00.014";
2246 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2247 $dbh->do("ALTER TABLE `branch_transfer_limits` CHANGE `itemtype` `itemtype` VARCHAR( 4 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL");
2248 $dbh->do("ALTER TABLE `branch_transfer_limits` ADD `ccode` VARCHAR( 10 ) NULL ;");
2249 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2251 'BranchTransferLimitsType', 'ccode', 'itemtype|ccode', 'When using branch transfer limits, choose whether to limit by itemtype or collection code.', 'Choice'
2254 print "Upgrade to $DBversion done ( Updated table for Branch Transfer Limits)\n";
2255 SetVersion ($DBversion);
2258 $DBversion = '3.01.00.015';
2259 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2260 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsClientCode', '0', 'Client Code for using Syndetics Solutions content','','free')");
2262 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEnabled', '0', 'Turn on Syndetics Enhanced Content','','YesNo')");
2264 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsCoverImages', '0', 'Display Cover Images from Syndetics','','YesNo')");
2266 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsTOC', '0', 'Display Table of Content information from Syndetics','','YesNo')");
2268 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSummary', '0', 'Display Summary Information from Syndetics','','YesNo')");
2270 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsEditions', '0', 'Display Editions from Syndetics','','YesNo')");
2272 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsExcerpt', '0', 'Display Excerpts and first chapters on OPAC from Syndetics','','YesNo')");
2274 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsReviews', '0', 'Display Reviews on OPAC from Syndetics','','YesNo')");
2276 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAuthorNotes', '0', 'Display Notes about the Author on OPAC from Syndetics','','YesNo')");
2278 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsAwards', '0', 'Display Awards on OPAC from Syndetics','','YesNo')");
2280 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('SyndeticsSeries', '0', 'Display Series information on OPAC from Syndetics','','YesNo')");
2282 $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')");
2284 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonCoverImages', '0', 'Display cover images on OPAC from Amazon Web Services','','YesNo')");
2286 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonCoverImages', '0', 'Display Cover Images in Staff Client from Amazon Web Services','','YesNo')");
2288 $dbh->do("UPDATE systempreferences SET variable='AmazonEnabled' WHERE variable = 'AmazonContent'");
2290 $dbh->do("UPDATE systempreferences SET variable='OPACAmazonEnabled' WHERE variable = 'OPACAmazonContent'");
2292 print "Upgrade to $DBversion done (added Syndetics Enhanced Content system preferences)\n";
2293 SetVersion ($DBversion);
2296 $DBversion = "3.01.00.016";
2297 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2298 $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')");
2299 print "Upgrade to $DBversion done (Added Babeltheque syspref)\n";
2300 SetVersion ($DBversion);
2303 $DBversion = "3.01.00.017";
2304 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2305 $dbh->do("ALTER TABLE `subscription` ADD `staffdisplaycount` VARCHAR(10) NULL;");
2306 $dbh->do("ALTER TABLE `subscription` ADD `opacdisplaycount` VARCHAR(10) NULL;");
2307 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2309 'StaffSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the Staff client', 'Integer'
2311 $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
2313 'OPACSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the OPAC', 'Integer'
2316 print "Upgrade to $DBversion done ( Updated table for Serials Display)\n";
2317 SetVersion ($DBversion);
2320 $DBversion = "3.01.00.018";
2321 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2322 $dbh->do("ALTER TABLE deletedborrowers ADD `smsalertnumber` varchar(50) default NULL");
2323 print "Upgrade to $DBversion done (added deletedborrowers.smsalertnumber, missed in 3.00.00.091)\n";
2324 SetVersion ($DBversion);
2327 $DBversion = "3.01.00.019";
2328 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2329 $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')");
2330 print "Upgrade to $DBversion done (adding OPACShowCheckoutName systempref)\n";
2331 SetVersion ($DBversion);
2334 $DBversion = "3.01.00.020";
2335 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2336 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesID','','See:http://librarything.com/forlibraries/','','free')");
2337 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesEnabled','0','Enable or Disable Library Thing for Libraries Features','','YesNo')");
2338 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesTabbedView','0','Put LibraryThingForLibraries Content in Tabs.','','YesNo')");
2339 print "Upgrade to $DBversion done (adding LibraryThing for Libraries sysprefs)\n";
2340 SetVersion ($DBversion);
2343 $DBversion = "3.01.00.021";
2344 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2345 my $enable_reviews = C4::Context->preference('OPACAmazonEnabled') ? '1' : '0';
2346 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonReviews', '$enable_reviews', 'Display Amazon readers reviews on OPAC','','YesNo')");
2347 print "Upgrade to $DBversion done (adding OPACAmazonReviews syspref)\n";
2348 SetVersion ($DBversion);
2351 $DBversion = '3.01.00.022';
2352 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2353 $dbh->do("ALTER TABLE `labels_conf` MODIFY COLUMN `formatstring` mediumtext DEFAULT NULL");
2354 print "Upgrade to $DBversion done (bug 2945: increase size of labels_conf.formatstring)\n";
2355 SetVersion ($DBversion);
2358 $DBversion = '3.01.00.023';
2359 if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
2360 $dbh->do("ALTER TABLE biblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2361 $dbh->do("ALTER TABLE deletedbiblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2362 $dbh->do("ALTER TABLE import_biblios MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2363 $dbh->do("ALTER TABLE suggestions MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
2364 print "Upgrade to $DBversion done (bug 2765: increase width of isbn column in several tables)\n";
2365 SetVersion ($DBversion);
2368 $DBversion = "3.01.00.024";
2369 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2370 $dbh->do("ALTER TABLE labels MODIFY COLUMN batch_id int(10) NOT NULL default 1;");
2371 print "Upgrade to $DBversion done (change labels.batch_id from varchar to int)\n";
2372 SetVersion ($DBversion);
2375 $DBversion = '3.01.00.025';
2376 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2377 $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')");
2379 print "Upgrade to $DBversion done (added ceilingDueDate system preference)\n";
2380 SetVersion ($DBversion);
2383 $DBversion = '3.01.00.026';
2384 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2385 $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')");
2387 print "Upgrade to $DBversion done (added numReturnedItemsToShow system preference)\n";
2388 SetVersion ($DBversion);
2391 $DBversion = '3.01.00.027';
2392 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2393 $dbh->do("ALTER TABLE zebraqueue CHANGE `biblio_auth_number` `biblio_auth_number` bigint(20) unsigned NOT NULL default 0");
2394 print "Upgrade to $DBversion done (Increased size of zebraqueue biblio_auth_number to address bug 3148.)\n";
2395 SetVersion ($DBversion);
2398 $DBversion = '3.01.00.028';
2399 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2400 my $enable_reviews = C4::Context->preference('AmazonEnabled') ? '1' : '0';
2401 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonReviews', '$enable_reviews', 'Display Amazon reviews on staff interface','','YesNo')");
2402 print "Upgrade to $DBversion done (added AmazonReviews)\n";
2403 SetVersion ($DBversion);
2406 $DBversion = '3.01.00.029';
2407 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2408 $dbh->do(q( UPDATE language_rfc4646_to_iso639
2409 SET iso639_2_code = 'spa'
2410 WHERE rfc4646_subtag = 'es'
2411 AND iso639_2_code = 'rus' )
2413 print "Upgrade to $DBversion done (fixed bug 2599: using Spanish search limit retrieves Russian results)\n";
2414 SetVersion ($DBversion);
2417 $DBversion = "3.01.00.030";
2418 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2419 $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')");
2420 print "Upgrade to $DBversion done (added AllowNotForLoanOverride system preference)\n";
2421 SetVersion ($DBversion);
2424 $DBversion = "3.01.00.031";
2425 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2426 $dbh->do("ALTER TABLE branch_transfer_limits
2427 MODIFY toBranch varchar(10) NOT NULL,
2428 MODIFY fromBranch varchar(10) NOT NULL,
2429 MODIFY itemtype varchar(10) NULL");
2430 print "Upgrade to $DBversion done (fix column widths in branch_transfer_limits)\n";
2431 SetVersion ($DBversion);
2434 $DBversion = "3.01.00.032";
2435 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2436 $dbh->do(<<ENDOFRENEWAL);
2437 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');
2439 print "Upgrade to $DBversion done (Change the field)\n";
2440 SetVersion ($DBversion);
2443 $DBversion = "3.01.00.033";
2444 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2446 ALTER TABLE borrower_message_preferences
2447 MODIFY borrowernumber int(11) default NULL,
2448 ADD categorycode varchar(10) default NULL AFTER borrowernumber,
2449 ADD KEY `categorycode` (`categorycode`),
2450 ADD CONSTRAINT `borrower_message_preferences_ibfk_3`
2451 FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`)
2452 ON DELETE CASCADE ON UPDATE CASCADE
2454 print "Upgrade to $DBversion done (DB changes to allow patron category defaults for messaging preferences)\n";
2455 SetVersion ($DBversion);
2458 $DBversion = "3.01.00.034";
2459 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2460 $dbh->do("ALTER TABLE `subscription` ADD COLUMN `graceperiod` INT(11) NOT NULL default '0';");
2461 print "Upgrade to $DBversion done (Adding graceperiod column to subscription table)\n";
2462 SetVersion ($DBversion);
2465 $DBversion = '3.01.00.035';
2466 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2467 $dbh->do(q{ ALTER TABLE `subscription` ADD location varchar(80) NULL DEFAULT '' AFTER callnumber; });
2468 print "Upgrade to $DBversion done (Adding location to subscription table)\n";
2469 SetVersion ($DBversion);
2472 $DBversion = '3.01.00.036';
2473 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2474 $dbh->do("UPDATE systempreferences SET explanation = 'Choose the default detail view in the staff interface; choose between normal, labeled_marc, marc or isbd'
2475 WHERE variable = 'IntranetBiblioDefaultView'
2476 AND explanation = 'IntranetBiblioDefaultView'");
2477 $dbh->do("UPDATE systempreferences SET type = 'Choice', options = 'normal|marc|isbd|labeled_marc'
2478 WHERE variable = 'IntranetBiblioDefaultView'");
2479 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewISBD','1','Allow display of ISBD view of bibiographic records','','YesNo')");
2480 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Allow display of labeled MARC view of bibiographic records','','YesNo')");
2481 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Allow display of MARC view of bibiographic records','','YesNo')");
2482 print "Upgrade to $DBversion done (new viewISBD, viewLabeledMARC, viewMARC sysprefs and tweak IntranetBiblioDefaultView)\n";
2483 SetVersion ($DBversion);
2486 $DBversion = '3.01.00.037';
2487 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2488 $dbh->do('ALTER TABLE authorised_values ADD KEY `lib` (`lib`)');
2489 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Do not run overdue report until filter selected','','YesNo')");
2490 SetVersion ($DBversion);
2491 print "Upgrade to $DBversion done (added FilterBeforeOverdueReport syspref and new index on authorised_values)\n";
2494 $DBversion = "3.01.00.038";
2495 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2496 # update branches table
2498 $dbh->do("ALTER TABLE branches ADD `branchzip` varchar(25) default NULL AFTER `branchaddress3`");
2499 $dbh->do("ALTER TABLE branches ADD `branchcity` mediumtext AFTER `branchzip`");
2500 $dbh->do("ALTER TABLE branches ADD `branchcountry` text AFTER `branchcity`");
2501 $dbh->do("ALTER TABLE branches ADD `branchurl` mediumtext AFTER `branchemail`");
2502 $dbh->do("ALTER TABLE branches ADD `branchnotes` mediumtext AFTER `branchprinter`");
2503 print "Upgrade to $DBversion done (add ZIP, city, country, URL, and notes column to branches)\n";
2504 SetVersion ($DBversion);
2507 $DBversion = '3.01.00.039';
2508 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2509 $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')");
2510 $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')");
2511 SetVersion ($DBversion);
2512 print "Upgrade to $DBversion done (added SpineLabelFormat and SpineLabelAutoPrint sysprefs)\n";
2515 $DBversion = '3.01.00.040';
2516 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2517 $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')");
2518 $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')");
2519 SetVersion ($DBversion);
2520 print "Upgrade to $DBversion done (AllowHoldDateInFuture and OPACAllowHoldDateInFuture sysprefs)\n";
2523 $DBversion = '3.01.00.041';
2524 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2525 $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')");
2526 SetVersion ($DBversion);
2527 print "Upgrade to $DBversion done (added AWSPrivateKey syspref - note that if you use enhanced content from Amazon, this should be set right away.)\n";
2530 $DBversion = '3.01.00.042';
2531 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2532 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACFineNoRenewals','99999','Fine Limit above which user canmot renew books via OPAC','','Integer')");
2533 SetVersion ($DBversion);
2534 print "Upgrade to $DBversion done (added OPACFineNoRenewals syspref)\n";
2537 $DBversion = '3.01.00.043';
2538 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2539 $dbh->do('ALTER TABLE items ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location');
2540 $dbh->do('UPDATE items SET permanent_location = location');
2541 $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 )', '')");
2542 $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')");
2543 $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')");
2544 SetVersion ($DBversion);
2545 print "Upgrade to $DBversion done (amended Item added NewItemsDefaultLocation, InProcessingToShelvingCart, ReturnToShelvingCart sysprefs)\n";
2548 $DBversion = '3.01.00.044';
2549 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2550 $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')");
2551 SetVersion ($DBversion);
2552 print "Upgrade to $DBversion done (added DisplayClearScreenButton system preference)\n";
2555 $DBversion = '3.01.00.045';
2556 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2557 $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')");
2558 SetVersion ($DBversion);
2559 print "Upgrade to $DBversion done (added a preference to hide the patrons name in the staff catalog)\n";
2562 $DBversion = "3.01.00.046";
2563 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2564 # update borrowers table
2566 $dbh->do("ALTER TABLE borrowers ADD `country` text AFTER zipcode");
2567 $dbh->do("ALTER TABLE borrowers ADD `B_country` text AFTER B_zipcode");
2568 $dbh->do("ALTER TABLE deletedborrowers ADD `country` text AFTER zipcode");
2569 $dbh->do("ALTER TABLE deletedborrowers ADD `B_country` text AFTER B_zipcode");
2570 print "Upgrade to $DBversion done (add country and B_country to borrowers)\n";
2571 SetVersion ($DBversion);
2574 $DBversion = '3.01.00.047';
2575 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2576 $dbh->do("ALTER TABLE items MODIFY itemcallnumber varchar(255);");
2577 $dbh->do("ALTER TABLE deleteditems MODIFY itemcallnumber varchar(255);");
2578 $dbh->do("ALTER TABLE tmp_holdsqueue MODIFY itemcallnumber varchar(255);");
2579 SetVersion ($DBversion);
2580 print " Upgrade to $DBversion done (bug 2761: change max length of itemcallnumber to 255 from 30)\n";
2583 $DBversion = '3.01.00.048';
2584 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2585 $dbh->do("UPDATE userflags SET flagdesc='View Catalog (Librarian Interface)' WHERE bit=2;");
2586 $dbh->do("UPDATE userflags SET flagdesc='Edit Catalog (Modify bibliographic/holdings data)' WHERE bit=9;");
2587 $dbh->do("UPDATE userflags SET flagdesc='Allow to edit authorities' WHERE bit=14;");
2588 $dbh->do("UPDATE userflags SET flagdesc='Allow to access to the reports module' WHERE bit=16;");
2589 $dbh->do("UPDATE userflags SET flagdesc='Allow to manage serials subscriptions' WHERE bit=15;");
2590 SetVersion ($DBversion);
2591 print " Upgrade to $DBversion done (bug 2611: fix spelling/capitalization in permission flag descriptions)\n";
2594 $DBversion = '3.01.00.049';
2595 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2596 $dbh->do("UPDATE permissions SET description = 'Perform inventory (stocktaking) of your catalog' WHERE code = 'inventory';");
2597 SetVersion ($DBversion);
2598 print "Upgrade to $DBversion done (bug 2611: changed catalogue to catalog per the standard)\n";
2601 $DBversion = '3.01.00.050';
2602 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2603 $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');");
2604 SetVersion ($DBversion);
2605 print "Upgrade to $DBversion done (bug 1934: Add OPACSearchForTitleIn syspref)\n";
2608 $DBversion = '3.01.00.051';
2609 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2610 $dbh->do("UPDATE systempreferences SET explanation='Fine limit above which user cannot renew books via OPAC' WHERE variable='OPACFineNoRenewals';");
2611 $dbh->do("UPDATE systempreferences SET explanation='If set to ON, a clear screen button will appear on the circulation page.' WHERE variable='DisplayClearScreenButton';");
2612 SetVersion ($DBversion);
2613 print "Upgrade to $DBversion done (fixed typos in new sysprefs)\n";
2616 $DBversion = '3.01.00.052';
2617 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2618 $dbh->do('ALTER TABLE deleteditems ADD COLUMN permanent_location VARCHAR(80) DEFAULT NULL AFTER location');
2619 SetVersion ($DBversion);
2620 print "Upgrade to $DBversion done (bug 3481: add permanent_location column to deleteditems)\n";
2623 $DBversion = '3.01.00.053';
2624 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2625 my $upgrade_script = C4::Context->config("intranetdir") . "/installer/data/mysql/labels_upgrade.pl";
2626 system("perl $upgrade_script");
2627 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";
2628 SetVersion ($DBversion);
2631 $DBversion = '3.01.00.054';
2632 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2633 $dbh->do("ALTER TABLE borrowers ADD `B_address2` text AFTER B_address");
2634 $dbh->do("ALTER TABLE borrowers ADD `altcontactcountry` text AFTER altcontactzipcode");
2635 $dbh->do("ALTER TABLE deletedborrowers ADD `B_address2` text AFTER B_address");
2636 $dbh->do("ALTER TABLE deletedborrowers ADD `altcontactcountry` text AFTER altcontactzipcode");
2637 SetVersion ($DBversion);
2638 print "Upgrade to $DBversion done (bug 1600, bug 3454: add altcontactcountry and B_address2 to borrowers and deletedborrowers)\n";
2641 $DBversion = '3.01.00.055';
2642 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2643 $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'|);
2644 SetVersion ($DBversion);
2645 print "Upgrade to $DBversion done (changed OPACSearchForTitleIn per requests in bug 1934)\n";
2648 $DBversion = '3.01.00.056';
2649 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2650 $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');");
2651 SetVersion ($DBversion);
2652 print "Upgrade to $DBversion done (Bug 1172 : Add OPACPatronDetails syspref)\n";
2655 $DBversion = '3.01.00.057';
2656 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2657 $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');");
2658 SetVersion ($DBversion);
2659 print "Upgrade to $DBversion done (Bug 2576 : Add OPACFinesTab syspref)\n";
2662 $DBversion = '3.01.00.058';
2663 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2664 $dbh->do("ALTER TABLE `language_subtag_registry` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2665 $dbh->do("ALTER TABLE `language_rfc4646_to_iso639` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2666 $dbh->do("ALTER TABLE `language_descriptions` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY;");
2667 SetVersion ($DBversion);
2668 print "Upgrade to $DBversion done (Added primary keys to language tables)\n";
2671 $DBversion = '3.01.00.059';
2672 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2673 $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')");
2674 SetVersion ($DBversion);
2675 print "Upgrade to $DBversion done (added DisplayOPACiconsXSLT sysprefs)\n";
2678 $DBversion = '3.01.00.060';
2679 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2680 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowAllMessageDeletion','0','Allow any Library to delete any message','','YesNo');");
2681 $dbh->do('DROP TABLE IF EXISTS messages');
2682 $dbh->do("CREATE TABLE messages ( `message_id` int(11) NOT NULL auto_increment,
2683 `borrowernumber` int(11) NOT NULL,
2684 `branchcode` varchar(4) default NULL,
2685 `message_type` varchar(1) NOT NULL,
2686 `message` text NOT NULL,
2687 `message_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
2688 PRIMARY KEY (`message_id`)
2689 ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
2691 print "Upgrade to $DBversion done ( Added AllowAllMessageDeletion syspref and messages table )\n";
2692 SetVersion ($DBversion);
2695 $DBversion = '3.01.00.061';
2696 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2697 $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')");
2698 print "Upgrade to $DBversion done ( Added ShowPatronImageInWebBasedSelfCheck system preference )\n";
2699 SetVersion ($DBversion);
2702 $DBversion = "3.01.00.062";
2703 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2704 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'manage_csv_profiles', 'Manage CSV export profiles')");
2706 CREATE TABLE `export_format` (
2707 `export_format_id` int(11) NOT NULL auto_increment,
2708 `profile` varchar(255) NOT NULL,
2709 `description` mediumtext NOT NULL,
2710 `marcfields` mediumtext NOT NULL,
2711 PRIMARY KEY (`export_format_id`)
2712 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Used for CSV export';
2714 print "Upgrade to $DBversion done (added csv export profiles)\n";
2717 $DBversion = "3.01.00.063";
2718 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2720 CREATE TABLE `fieldmapping` (
2721 `id` int(11) NOT NULL auto_increment,
2722 `field` varchar(255) NOT NULL,
2723 `frameworkcode` char(4) NOT NULL default '',
2724 `fieldcode` char(3) NOT NULL,
2725 `subfieldcode` char(1) NOT NULL,
2727 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2729 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";
2732 $DBversion = '3.01.00.065';
2733 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2734 $dbh->do('ALTER TABLE issuingrules ADD COLUMN `renewalsallowed` smallint(6) NOT NULL default "0" AFTER `issuelength`;');
2735 $sth = $dbh->prepare("SELECT itemtype, renewalsallowed FROM itemtypes");
2738 my $sthupd = $dbh->prepare("UPDATE issuingrules SET renewalsallowed = ? WHERE itemtype = ?");
2740 while(my $row = $sth->fetchrow_hashref){
2741 $sthupd->execute($row->{renewalsallowed}, $row->{itemtype});
2744 $dbh->do('ALTER TABLE itemtypes DROP COLUMN `renewalsallowed`;');
2746 SetVersion ($DBversion);
2747 print "Upgrade to $DBversion done (Moving allowed renewals from itemtypes to issuingrule)\n";
2750 $DBversion = '3.01.00.066';
2751 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2752 $dbh->do('ALTER TABLE issuingrules ADD COLUMN `reservesallowed` smallint(6) NOT NULL default "0" AFTER `renewalsallowed`;');
2754 my $maxreserves = C4::Context->preference('maxreserves');
2755 $sth = $dbh->prepare('UPDATE issuingrules SET reservesallowed = ?;');
2756 $sth->execute($maxreserves);
2758 $dbh->do('DELETE FROM systempreferences WHERE variable = "maxreserves";');
2760 $dbh->do("INSERT INTO systempreferences (variable,value, options, explanation, type) VALUES('ReservesControlBranch','PatronLibrary','ItemHomeLibrary|PatronLibrary','Branch checked for members reservations rights','Choice')");
2762 SetVersion ($DBversion);
2763 print "Upgrade to $DBversion done (Moving max allowed reserves from system preference to issuingrule)\n";
2766 $DBversion = "3.01.00.067";
2767 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2768 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchmod', 'Perform batch modification of items')");
2769 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES ( 13, 'batchdel', 'Perform batch deletion of items')");
2770 print "Upgrade to $DBversion done (added permissions for batch modification and deletion)\n";
2771 SetVersion ($DBversion);
2774 $DBversion = "3.01.00.068";
2775 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2776 $dbh->do("ALTER TABLE issuingrules ADD COLUMN `finedays` int(11) default NULL AFTER `fine` ");
2777 print "Upgrade to $DBversion done (Adding finedays in issuingrules table)\n";
2778 SetVersion ($DBversion);
2782 $DBversion = "3.01.00.069";
2783 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2784 $dbh->do("INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('EnableOpacSearchHistory', '1', '', 'Enable or disable opac search history', 'YesNo')");
2786 my $create = <<SEARCHHIST;
2787 CREATE TABLE IF NOT EXISTS `search_history` (
2788 `userid` int(11) NOT NULL,
2789 `sessionid` varchar(32) NOT NULL,
2790 `query_desc` varchar(255) NOT NULL,
2791 `query_cgi` varchar(255) NOT NULL,
2792 `total` int(11) NOT NULL,
2793 `time` timestamp NOT NULL default CURRENT_TIMESTAMP,
2794 KEY `userid` (`userid`),
2795 KEY `sessionid` (`sessionid`)
2796 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Opac search history results';
2800 print "Upgrade to $DBversion done (added OPAC search history preference and table)\n";
2803 $DBversion = "3.01.00.070";
2804 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2805 $dbh->do("ALTER TABLE authorised_values ADD COLUMN `lib_opac` VARCHAR(80) default NULL AFTER `lib`");
2806 print "Upgrade to $DBversion done (Added a lib_opac field in authorised_values table)\n";
2809 $DBversion = "3.01.00.071";
2810 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2811 $dbh->do("ALTER TABLE `subscription` ADD `enddate` date default NULL");
2812 $dbh->do("ALTER TABLE subscriptionhistory CHANGE enddate histenddate DATE default NULL");
2813 print "Upgrade to $DBversion done ( Adding enddate to subscription)\n";
2816 # Acquisitions update
2818 $DBversion = "3.01.00.072";
2819 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2820 $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')");
2821 # create a new syspref for the 'Mr anonymous' patron
2822 $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,'')");
2823 # fill AnonymousPatron with AnonymousSuggestion value (copy)
2824 my $sth=$dbh->prepare("SELECT value FROM systempreferences WHERE variable='AnonSuggestions'");
2826 my ($value) = $sth->fetchrow() || 0;
2827 $dbh->do("UPDATE systempreferences SET value='$value' WHERE variable='AnonymousPatron'");
2828 # set AnonymousSuggestion do YesNo
2829 # 1st, set the value (1/True if it had a borrowernumber)
2830 $dbh->do("UPDATE systempreferences SET value=1 WHERE variable='AnonSuggestions' AND value>0");
2831 # 2nd, change the type to Choice
2832 $dbh->do("UPDATE systempreferences SET type='YesNo' WHERE variable='AnonSuggestions'");
2833 # borrower reading record privacy : 0 : forever, 1 : laws, 2 : don't keep at all
2834 $dbh->do("ALTER TABLE `borrowers` ADD `privacy` INTEGER NOT NULL DEFAULT 1;");
2835 print "Upgrade to $DBversion done (add new syspref and column in borrowers)\n";
2836 SetVersion ($DBversion);
2839 $DBversion = '3.01.00.073';
2840 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2841 $dbh->do('SET FOREIGN_KEY_CHECKS=0 ');
2842 $dbh->do(<<'END_SQL');
2843 CREATE TABLE IF NOT EXISTS `aqcontract` (
2844 `contractnumber` int(11) NOT NULL auto_increment,
2845 `contractstartdate` date default NULL,
2846 `contractenddate` date default NULL,
2847 `contractname` varchar(50) default NULL,
2848 `contractdescription` mediumtext,
2849 `booksellerid` int(11) not NULL,
2850 PRIMARY KEY (`contractnumber`),
2851 CONSTRAINT `booksellerid_fk1` FOREIGN KEY (`booksellerid`)
2852 REFERENCES `aqbooksellers` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
2853 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
2855 $dbh->do('SET FOREIGN_KEY_CHECKS=1 ');
2856 print "Upgrade to $DBversion done (adding aqcontract table)\n";
2857 SetVersion ($DBversion);
2860 $DBversion = '3.01.00.074';
2861 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2862 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `basketname` varchar(50) default NULL AFTER `basketno`");
2863 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `note` mediumtext AFTER `basketname`");
2864 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `booksellernote` mediumtext AFTER `note`");
2865 $dbh->do("ALTER TABLE `aqbasket` ADD COLUMN `contractnumber` int(11) AFTER `booksellernote`");
2866 $dbh->do("ALTER TABLE `aqbasket` ADD FOREIGN KEY (`contractnumber`) REFERENCES `aqcontract` (`contractnumber`)");
2867 print "Upgrade to $DBversion done (edit aqbasket table done)\n";
2868 SetVersion ($DBversion);
2871 $DBversion = '3.01.00.075';
2872 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2873 $dbh->do("ALTER TABLE `aqorders` ADD COLUMN `uncertainprice` tinyint(1)");
2875 print "Upgrade to $DBversion done (adding uncertainprices)\n";
2876 SetVersion ($DBversion);
2879 $DBversion = '3.01.00.076';
2880 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2881 $dbh->do('SET FOREIGN_KEY_CHECKS=0 ');
2882 $dbh->do("CREATE TABLE IF NOT EXISTS `aqbasketgroups` (
2883 `id` int(11) NOT NULL auto_increment,
2884 `name` varchar(50) default NULL,
2885 `closed` tinyint(1) default NULL,
2886 `booksellerid` int(11) NOT NULL,
2888 KEY `booksellerid` (`booksellerid`),
2889 CONSTRAINT `aqbasketgroups_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
2890 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
2891 $dbh->do("ALTER TABLE aqbasket ADD COLUMN `basketgroupid` int(11)");
2892 $dbh->do("ALTER TABLE aqbasket ADD FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE ON DELETE SET NULL");
2893 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('pdfformat','pdfformat::layout2pages','Controls what script is used for printing (basketgroups)','','free')");
2894 $dbh->do('SET FOREIGN_KEY_CHECKS=1 ');
2895 print "Upgrade to $DBversion done (adding basketgroups)\n";
2896 SetVersion ($DBversion);
2898 $DBversion = '3.01.00.077';
2899 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
2901 $dbh->do("SET FOREIGN_KEY_CHECKS=0 ");
2902 # create a mapping table holding the info we need to match orders to budgets
2903 $dbh->do('DROP TABLE IF EXISTS fundmapping');
2905 q|CREATE TABLE fundmapping AS
2906 SELECT aqorderbreakdown.ordernumber, branchcode, bookfundid, budgetdate, entrydate
2907 FROM aqorderbreakdown JOIN aqorders ON aqorderbreakdown.ordernumber = aqorders.ordernumber|);
2908 # match the new type of the corresponding field
2909 $dbh->do('ALTER TABLE fundmapping modify column bookfundid varchar(30)');
2910 # System did not ensure budgetdate was valid historically
2911 $dbh->do(q|UPDATE fundmapping SET budgetdate = entrydate WHERE budgetdate = '0000-00-00' OR budgetdate IS NULL|);
2912 # We save the map in fundmapping in case you need later processing
2913 $dbh->do(q|ALTER TABLE fundmapping add column aqbudgetid integer|);
2914 # these can speed processing up
2915 $dbh->do(q|CREATE INDEX fundmaporder ON fundmapping (ordernumber)|);
2916 $dbh->do(q|CREATE INDEX fundmapid ON fundmapping (bookfundid)|);
2918 $dbh->do("DROP TABLE IF EXISTS `aqbudgetperiods` ");
2921 CREATE TABLE `aqbudgetperiods` (
2922 `budget_period_id` int(11) NOT NULL auto_increment,
2923 `budget_period_startdate` date NOT NULL,
2924 `budget_period_enddate` date NOT NULL,
2925 `budget_period_active` tinyint(1) default '0',
2926 `budget_period_description` mediumtext,
2927 `budget_period_locked` tinyint(1) default NULL,
2928 `sort1_authcat` varchar(10) default NULL,
2929 `sort2_authcat` varchar(10) default NULL,
2930 PRIMARY KEY (`budget_period_id`)
2931 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |);
2933 $dbh->do(<<ADDPERIODS);
2934 INSERT INTO aqbudgetperiods (budget_period_startdate,budget_period_enddate,budget_period_active,budget_period_description,budget_period_locked)
2935 SELECT DISTINCT startdate, enddate, NOW() BETWEEN startdate and enddate, concat(startdate," ",enddate),NOT NOW() BETWEEN startdate AND enddate from aqbudget
2937 # SORRY , NO AQBUDGET/AQBOOKFUND -> AQBUDGETS IMPORT JUST YET,
2938 # BUT A NEW CLEAN AQBUDGETS TABLE CREATE FOR NOW..
2939 # DROP TABLE IF EXISTS `aqbudget`;
2940 #CREATE TABLE `aqbudget` (
2941 # `bookfundid` varchar(10) NOT NULL default ',
2942 # `startdate` date NOT NULL default 0,
2943 # `enddate` date default NULL,
2944 # `budgetamount` decimal(13,2) default NULL,
2945 # `aqbudgetid` tinyint(4) NOT NULL auto_increment,
2946 # `branchcode` varchar(10) default NULL,
2947 DropAllForeignKeys('aqbudget');
2948 #$dbh->do("drop table aqbudget;");
2951 my $maxbudgetid = $dbh->selectcol_arrayref(<<IDsBUDGET);
2952 SELECT MAX(aqbudgetid) from aqbudget
2955 $$maxbudgetid[0] = 0 if !$$maxbudgetid[0];
2957 $dbh->do(<<BUDGETAUTOINCREMENT);
2958 ALTER TABLE aqbudget AUTO_INCREMENT=$$maxbudgetid[0]
2961 $dbh->do(<<BUDGETNAME);
2962 ALTER TABLE aqbudget RENAME `aqbudgets`
2965 $dbh->do(<<BUDGETS);
2966 ALTER TABLE `aqbudgets`
2967 CHANGE COLUMN aqbudgetid `budget_id` int(11) NOT NULL AUTO_INCREMENT,
2968 CHANGE COLUMN branchcode `budget_branchcode` varchar(10) default NULL,
2969 CHANGE COLUMN budgetamount `budget_amount` decimal(28,6) NOT NULL default '0.00',
2970 CHANGE COLUMN bookfundid `budget_code` varchar(30) default NULL,
2971 ADD COLUMN `budget_parent_id` int(11) default NULL,
2972 ADD COLUMN `budget_name` varchar(80) default NULL,
2973 ADD COLUMN `budget_encumb` decimal(28,6) default '0.00',
2974 ADD COLUMN `budget_expend` decimal(28,6) default '0.00',
2975 ADD COLUMN `budget_notes` mediumtext,
2976 ADD COLUMN `budget_description` mediumtext,
2977 ADD COLUMN `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
2978 ADD COLUMN `budget_amount_sublevel` decimal(28,6) AFTER `budget_amount`,
2979 ADD COLUMN `budget_period_id` int(11) default NULL,
2980 ADD COLUMN `sort1_authcat` varchar(80) default NULL,
2981 ADD COLUMN `sort2_authcat` varchar(80) default NULL,
2982 ADD COLUMN `budget_owner_id` int(11) default NULL,
2983 ADD COLUMN `budget_permission` int(1) default '0';
2986 $dbh->do(<<BUDGETCONSTRAINTS);
2987 ALTER TABLE `aqbudgets`
2988 ADD CONSTRAINT `aqbudgets_ifbk_1` FOREIGN KEY (`budget_period_id`) REFERENCES `aqbudgetperiods` (`budget_period_id`) ON DELETE CASCADE ON UPDATE CASCADE
2990 # $dbh->do(<<BUDGETPKDROP);
2991 #ALTER TABLE `aqbudgets`
2994 # $dbh->do(<<BUDGETPKADD);
2995 #ALTER TABLE `aqbudgets`
2996 # ADD PRIMARY KEY budget_id
3000 my $query_period= $dbh->prepare(qq|SELECT budget_period_id from aqbudgetperiods where budget_period_startdate=? and budget_period_enddate=?|);
3001 my $query_bookfund= $dbh->prepare(qq|SELECT * from aqbookfund where bookfundid=?|);
3002 my $selectbudgets=$dbh->prepare(qq|SELECT * from aqbudgets|);
3003 my $updatebudgets=$dbh->prepare(qq|UPDATE aqbudgets SET budget_period_id= ? , budget_name=?, budget_branchcode=? where budget_id=?|);
3004 $selectbudgets->execute;
3005 while (my $databudget=$selectbudgets->fetchrow_hashref){
3006 $query_period->execute ($$databudget{startdate},$$databudget{enddate});
3007 my ($budgetperiodid)=$query_period->fetchrow;
3008 $query_bookfund->execute ($$databudget{budget_code});
3009 my $databf=$query_bookfund->fetchrow_hashref;
3010 my $branchcode=$$databudget{budget_branchcode}||$$databf{branchcode};
3011 $updatebudgets->execute($budgetperiodid,$$databf{bookfundname},$branchcode,$$databudget{budget_id});
3013 $dbh->do(<<BUDGETDROPDATES);
3014 ALTER TABLE `aqbudgets`
3020 $dbh->do("DROP TABLE IF EXISTS `aqbudgets_planning` ");
3021 $dbh->do("CREATE TABLE `aqbudgets_planning` (
3022 `plan_id` int(11) NOT NULL auto_increment,
3023 `budget_id` int(11) NOT NULL,
3024 `budget_period_id` int(11) NOT NULL,
3025 `estimated_amount` decimal(28,6) default NULL,
3026 `authcat` varchar(30) NOT NULL,
3027 `authvalue` varchar(30) NOT NULL,
3028 `display` tinyint(1) DEFAULT 1,
3029 PRIMARY KEY (`plan_id`),
3030 CONSTRAINT `aqbudgets_planning_ifbk_1` FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON DELETE CASCADE ON UPDATE CASCADE
3031 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
3033 $dbh->do("ALTER TABLE `aqorders`
3034 ADD COLUMN `budget_id` tinyint(4) NOT NULL,
3035 ADD COLUMN `budgetgroup_id` int(11) NOT NULL,
3036 ADD COLUMN `sort1_authcat` varchar(10) default NULL,
3037 ADD COLUMN `sort2_authcat` varchar(10) default NULL" );
3038 # We need to map the orders to the budgets
3039 # For Historic reasons this is more complex than it should be on occasions
3040 my $budg_arr = $dbh->selectall_arrayref(
3041 q|SELECT aqbudgets.budget_id, aqbudgets.budget_code, aqbudgetperiods.budget_period_startdate,
3042 aqbudgetperiods.budget_period_enddate
3043 FROM aqbudgets JOIN aqbudgetperiods ON aqbudgets.budget_period_id = aqbudgetperiods.budget_period_id
3044 ORDER BY budget_code, budget_period_startdate|, { Slice => {} });
3045 # We arbitarily order on start date, this means if you have overlapping periods the order will be
3046 # linked to the latest matching budget YMMV
3047 my $b_sth = $dbh->prepare(
3048 'UPDATE fundmapping set aqbudgetid = ? where bookfundid =? AND budgetdate >= ? AND budgetdate <= ?');
3049 for my $b ( @{$budg_arr}) {
3050 $b_sth->execute($b->{budget_id}, $b->{budget_code}, $b->{budget_period_startdate}, $b->{budget_period_enddate});
3052 # move the budgetids to aqorders
3053 $dbh->do(q|UPDATE aqorders, fundmapping SET aqorders.budget_id = fundmapping.aqbudgetid
3054 WHERE aqorders.ordernumber = fundmapping.ordernumber AND fundmapping.aqbudgetid IS NOT NULL|);
3055 # NB fundmapping is left as an accontants trail also if you have budgetids that werent set
3056 # you can decide what to do with them
3059 q|UPDATE aqorders, aqbudgets SET aqorders.budgetgroup_id = aqbudgets.budget_period_id
3060 WHERE aqorders.budget_id = aqbudgets.budget_id|);
3061 # cannot do until aqorderbreakdown removed
3062 # $dbh->do("DROP TABLE aqbookfund ");
3063 # $dbh->do("ALTER TABLE aqorders ADD FOREIGN KEY (`budget_id`) REFERENCES `aqbudgets` (`budget_id`) ON UPDATE CASCADE " ); ????
3064 $dbh->do("SET FOREIGN_KEY_CHECKS=1 ");
3066 print "Upgrade to $DBversion done (Adding new aqbudgetperiods, aqbudgets and aqbudget_planning tables )\n";
3067 SetVersion ($DBversion);
3072 $DBversion = '3.01.00.078';
3073 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
3074 $dbh->do("ALTER TABLE aqbudgetperiods ADD COLUMN budget_period_total decimal(28,6)");
3075 print "Upgrade to $DBversion done (adds 'budget_period_total' column to aqbudgetperiods table)\n";
3076 SetVersion($DBversion);
3080 $DBversion = '3.01.00.079';
3081 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
3082 $dbh->do("ALTER TABLE currency ADD COLUMN active tinyint(1)");
3084 print "Upgrade to $DBversion done (adds 'active' column to currencies table)\n";
3085 SetVersion($DBversion);
3088 $DBversion = '3.01.00.080';
3089 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
3090 $dbh->do(<<BUDG_PERM );
3091 INSERT INTO permissions (module_bit, code, description) VALUES
3092 (11, 'vendors_manage', 'Manage vendors'),
3093 (11, 'contracts_manage', 'Manage contracts'),
3094 (11, 'period_manage', 'Manage periods'),
3095 (11, 'budget_manage', 'Manage budgets'),
3096 (11, 'budget_modify', "Modify budget (can't create lines but can modify existing ones)"),
3097 (11, 'planning_manage', 'Manage budget plannings'),
3098 (11, 'order_manage', 'Manage orders & basket'),
3099 (11, 'group_manage', 'Manage orders & basketgroups'),
3100 (11, 'order_receive', 'Manage orders & basket'),
3101 (11, 'budget_add_del', "Add and delete budgets (but can't modify budgets)");
3104 print "Upgrade to $DBversion done (adds permissions for the acquisitions module)\n";
3105 SetVersion($DBversion);
3109 $DBversion = '3.01.00.081';
3110 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
3111 $dbh->do("ALTER TABLE aqbooksellers ADD COLUMN `gstrate` decimal(6,4) default NULL");
3112 if (my $gist=C4::Context->preference("gist")){
3113 my $sql=$dbh->prepare("UPDATE aqbooksellers set `gstrate`=? ");
3114 $sql->execute($gist) ;
3116 print "Upgrade to $DBversion done (added per-supplier gstrate setting)\n";
3117 SetVersion($DBversion);
3120 $DBversion = "3.01.00.082";
3121 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3122 if (C4::Context->preference("opaclanguages") eq "fr") {
3123 $dbh->do(qq#INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AcqCreateItem','ordering',"Définit quand l'exemplaire est créé : à la commande, à la livraison, au catalogage",'ordering|receiving|cataloguing','Choice')#);
3125 $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AcqCreateItem','ordering','Define when the item is created : when ordering, when receiving, or in cataloguing module','ordering|receiving|cataloguing','Choice')");
3127 print "Upgrade to $DBversion done (adding ReservesNeedReturns systempref, in circulation)\n";
3128 SetVersion ($DBversion);
3131 $DBversion = "3.01.00.083";
3132 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3134 CREATE TABLE `aqorders_items` (
3135 `ordernumber` int(11) NOT NULL,
3136 `itemnumber` int(11) NOT NULL,
3137 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
3138 PRIMARY KEY (`itemnumber`),
3139 KEY `ordernumber` (`ordernumber`)
3140 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
3143 $dbh->do(qq| DROP TABLE aqorderbreakdown |);
3144 $dbh->do('DROP TABLE aqbookfund');
3145 print "Upgrade to $DBversion done (New aqorders_items table for acqui)\n";
3146 SetVersion ($DBversion);
3149 $DBversion = "3.01.00.084";
3150 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3151 $dbh->do( qq# INSERT INTO `systempreferences` VALUES ('CurrencyFormat','US','US|FR','Determines the display format of currencies. eg: ''36000'' is displayed as ''360 000,00'' in ''FR'' or 360,000.00'' in ''US''.','Choice') #);
3153 print "Upgrade to $DBversion done (CurrencyFormat syspref added)\n";
3154 SetVersion ($DBversion);
3157 $DBversion = "3.01.00.085";
3158 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3159 $dbh->do("ALTER table aqorders drop column title");
3160 $dbh->do("ALTER TABLE `aqorders` CHANGE `budget_id` `budget_id` INT( 11 ) NOT NULL");
3161 print "Upgrade to $DBversion done update budget_id size that should not be a tinyint\n";
3162 SetVersion ($DBversion);
3165 $DBversion = "3.01.00.086";
3166 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3167 $dbh->do(<<SUGGESTIONS);
3168 ALTER table suggestions
3169 ADD budgetid INT(11),
3170 ADD branchcode VARCHAR(10) default NULL,
3171 ADD acceptedby INT(11) default NULL,
3172 ADD accepteddate date default NULL,
3173 ADD suggesteddate date default NULL,
3174 ADD manageddate date default NULL,
3175 ADD rejectedby INT(11) default NULL,
3176 ADD rejecteddate date default NULL,
3177 ADD collectiontitle text default NULL,
3178 ADD itemtype VARCHAR(30) default NULL
3181 print "Upgrade to $DBversion done (Suggestions)\n";
3182 SetVersion ($DBversion);
3185 $DBversion = "3.01.00.087";
3186 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3187 $dbh->do("ALTER table aqbudgets drop column budget_amount_sublevel;");
3188 print "Upgrade to $DBversion done (Drop column budget_amount_sublevel from aqbudgets)\n";
3189 SetVersion ($DBversion);
3192 $DBversion = "3.01.00.088";
3193 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3194 $dbh->do( qq# INSERT INTO `systempreferences` VALUES ('intranetbookbag','1','','If ON, enables display of Cart feature in the intranet','YesNo') #);
3196 print "Upgrade to $DBversion done (intranetbookbag syspref added)\n";
3197 SetVersion ($DBversion);
3200 $DBversion = "3.01.00.090";
3201 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3203 INSERT INTO `permissions` (`module_bit`, `code`, `description`) VALUES
3204 (16, 'execute_reports', 'Execute SQL reports'),
3205 (16, 'create_reports', 'Create SQL Reports')
3208 print "Upgrade to $DBversion done (granular permissions for guided reports added)\n";
3209 SetVersion ($DBversion);
3212 $DBversion = "3.01.00.091";
3213 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3215 UPDATE `systempreferences` SET `options` = 'holdings|serialcollection|subscriptions'
3216 WHERE `systempreferences`.`variable` = 'opacSerialDefaultTab' LIMIT 1
3219 print "Upgrade to $DBversion done (opac-detail default tag updated)\n";
3220 SetVersion ($DBversion);
3223 $DBversion = "3.01.00.092";
3224 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3225 if (C4::Context->preference("opaclanguages") =~ /fr/) {
3227 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('RoutingListAddReserves','1','Si activé, des reservations sont automatiquement créées pour chaque lecteur de la liste de circulation d''un numéro de périodique','','YesNo');
3231 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('RoutingListAddReserves','1','If ON the patrons on routing lists are automatically added to holds on the issue.','','YesNo');
3234 print "Upgrade to $DBversion done (Added RoutingListAddReserves syspref)\n";
3235 SetVersion ($DBversion);
3238 $DBversion = "3.01.00.093";
3239 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3241 ALTER TABLE biblioitems ADD INDEX issn_idx (issn);
3243 print "Upgrade to $DBversion done (added index to ISSN)\n";
3244 SetVersion ($DBversion);
3247 $DBversion = "3.01.00.094";
3248 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3250 ALTER TABLE aqbasketgroups ADD deliveryplace VARCHAR(10) default NULL, ADD deliverycomment VARCHAR(255) default NULL;
3253 print "Upgrade to $DBversion done (adding deliveryplace deliverycomment to basketgroups)\n";
3254 SetVersion ($DBversion);
3257 $DBversion = "3.01.00.095";
3258 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3260 ALTER TABLE items ADD stocknumber VARCHAR(32) DEFAULT NULL COMMENT "stores the inventory number";
3263 ALTER TABLE items ADD UNIQUE INDEX itemsstocknumberidx (stocknumber);
3266 ALTER TABLE deleteditems ADD stocknumber VARCHAR(32) DEFAULT NULL COMMENT "stores the inventory number of deleted items";
3269 ALTER TABLE deleteditems ADD UNIQUE INDEX deleteditemsstocknumberidx (stocknumber);
3271 if (C4::Context->preference('marcflavour') eq 'UNIMARC'){
3273 INSERT IGNORE INTO marc_subfield_structure (frameworkcode,tagfield, tagsubfield, tab, repeatable, mandatory,kohafield)
3274 SELECT DISTINCT (frameworkcode),995,"j",10,0,0,"items.stocknumber" from biblio_framework ;
3276 #Previously, copynumber was used as stocknumber
3278 UPDATE items set stocknumber=copynumber;
3281 UPDATE items set copynumber=NULL;
3284 print "Upgrade to $DBversion done (stocknumber field added)\n";
3285 SetVersion ($DBversion);
3288 $DBversion = "3.01.00.096";
3289 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3290 $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OrderPdfTemplate','','Uploads a PDF template to use for printing baskets','NULL','Upload')");
3291 $dbh->do("UPDATE systempreferences SET variable='OrderPdfFormat' WHERE variable='pdfformat'");
3292 print "Upgrade to $DBversion done (PDF orders system preferences added and updated)\n";
3293 SetVersion ($DBversion);
3296 $DBversion = "3.01.00.097";
3297 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3299 ALTER TABLE aqbasketgroups ADD billingplace VARCHAR(10) NOT NULL AFTER deliverycomment;
3302 print "Upgrade to $DBversion done (Adding billingplace to aqbasketgroups)\n";
3303 SetVersion ($DBversion);
3306 $DBversion = "3.01.00.098";
3307 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3309 ALTER TABLE auth_subfield_structure MODIFY frameworkcode VARCHAR(10) NULL;
3312 print "Upgrade to $DBversion done (changing frameworkcode length in auth_subfield_structure)\n";
3313 SetVersion ($DBversion);
3316 $DBversion = "3.01.00.099";
3317 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3319 INSERT INTO `permissions` (`module_bit`, `code`, `description`) VALUES
3320 (9, 'edit_catalogue', 'Edit catalogue'),
3321 (9, 'fast_cataloging', 'Fast cataloging')
3324 print "Upgrade to $DBversion done (granular permissions for cataloging added)\n";
3325 SetVersion ($DBversion);
3328 $DBversion = "3.01.00.100";
3329 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3330 $dbh->do("INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('casAuthentication', '0', '', 'Enable or disable CAS authentication', 'YesNo'), ('casLogout', '1', '', 'Does a logout from Koha should also log out of CAS ?', 'YesNo'), ('casServerUrl', 'https://localhost:8443/cas', '', 'URL of the cas server', 'Free')");
3331 print "Upgrade to $DBversion done (added CAS authentication system preferences)\n";
3332 SetVersion ($DBversion);
3335 $DBversion = "3.01.00.101";
3336 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3338 "INSERT INTO systempreferences
3339 (variable, value, options, explanation, type)
3341 'OverdueNoticeBcc', '', '',
3342 'Email address to Bcc outgoing notices sent by email',
3345 print "Upgrade to $DBversion done (added OverdueNoticeBcc system preferences)\n";
3346 SetVersion ($DBversion);
3348 $DBversion = "3.01.00.102";
3349 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3351 "UPDATE permissions set description = 'Edit catalog (Modify bibliographic/holdings data)' where module_bit = 9 and code = 'edit_catalogue'"
3353 print "Upgrade to $DBversion done (fixed spelling error in edit_catalogue permission)\n";
3354 SetVersion ($DBversion);
3357 $DBversion = "3.01.00.103";
3358 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3359 $dbh->do("INSERT INTO permissions (module_bit, code, description) VALUES (13, 'moderate_tags', 'Moderate patron tags')");
3360 print "Upgrade to $DBversion done (adding patron permissions for tags tool)\n";
3361 SetVersion ($DBversion);
3364 $DBversion = "3.01.00.104";
3365 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3367 my ($maninv_count, $borrnotes_count);
3368 eval { $maninv_count = $dbh->do("SELECT 1 FROM authorised_values WHERE category='MANUAL_INV'"); };
3369 if ($maninv_count == 0) {
3370 $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('MANUAL_INV','Copier Fees','.25')");
3372 eval { $borrnotes_count = $dbh->do("SELECT 1 FROM authorised_values WHERE category='BOR_NOTES'"); };
3373 if ($borrnotes_count == 0) {
3374 $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('BOR_NOTES','ADDR','Address Notes')");
3377 $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('LOC','CART','Book Cart')");
3378 $dbh->do("INSERT INTO authorised_values (category,authorised_value,lib) VALUES ('LOC','PROC','Processing Center')");
3380 print "Upgrade to $DBversion done ( add defaults to authorized values for MANUAL_INV and BOR_NOTES and add new default LOC authorized values for shelf to cart processing )\n";
3381 SetVersion ($DBversion);
3385 $DBversion = "3.01.00.105";
3386 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3388 CREATE TABLE `collections` (
3389 `colId` int(11) NOT NULL auto_increment,
3390 `colTitle` varchar(100) NOT NULL default '',
3391 `colDesc` text NOT NULL,
3392 `colBranchcode` varchar(4) default NULL COMMENT 'branchcode for branch where item should be held.',
3393 PRIMARY KEY (`colId`)
3394 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3398 CREATE TABLE `collections_tracking` (
3399 `ctId` int(11) NOT NULL auto_increment,
3400 `colId` int(11) NOT NULL default '0' COMMENT 'collections.colId',
3401 `itemnumber` int(11) NOT NULL default '0' COMMENT 'items.itemnumber',
3402 PRIMARY KEY (`ctId`)
3403 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3406 INSERT INTO permissions (module_bit, code, description)
3407 VALUES ( 13, 'rotating_collections', 'Manage Rotating collections')" );
3408 print "Upgrade to $DBversion done (added collection and collection_tracking tables for rotating collections functionality)\n";
3409 SetVersion ($DBversion);
3411 $DBversion = "3.01.00.106";
3412 if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
3413 $dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type) VALUES ( 'OpacAddMastheadLibraryPulldown', '0', '', 'Adds a pulldown menu to select the library to search on the opac masthead.', 'YesNo' )");
3414 print "Upgrade to $DBversion done (added OpacAddMastheadLibraryPulldown system preferences)\n";
3415 SetVersion ($DBversion);