/
updatedatabase.pl
executable file
·4907 lines (4341 loc) · 265 KB
/
updatedatabase.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
# Database Updater
# This script checks for required updates to the database.
# Part of the Koha Library Software www.koha.org
# Licensed under the GPL.
# Bugs/ToDo:
# - Would also be a good idea to offer to do a backup at this time...
# NOTE: If you do something more than once in here, make it table driven.
# NOTE: Please keep the version in kohaversion.pl up-to-date!
use strict;
use warnings;
# CPAN modules
use DBI;
use Getopt::Long;
# Koha modules
use Koha;
use C4::Context;
use C4::Installer;
use MARC::Record;
use MARC::File::XML ( BinaryEncoding => 'utf8' );
# FIXME - The user might be installing a new database, so can't rely
# on /etc/koha.conf anyway.
my $debug = 0;
my (
$sth, $sti,
$query,
%existingtables, # tables already in database
%types,
$table,
$column,
$type, $null, $key, $default, $extra,
$prefitem, # preference item in systempreferences table
);
my $silent;
GetOptions(
's' =>\$silent
);
my $dbh = C4::Context->dbh;
$dbh->{RaiseError} = 0;
$|=1; # flushes output
=item
Deal with virtualshelves
=cut
my $DBversion = "3.00.00.001";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
# update virtualshelves table to
#
$dbh->do("ALTER TABLE `bookshelf` RENAME `virtualshelves`");
$dbh->do("ALTER TABLE `shelfcontents` RENAME `virtualshelfcontents`");
$dbh->do("ALTER TABLE `virtualshelfcontents` ADD `biblionumber` INT( 11 ) NOT NULL default '0' AFTER shelfnumber");
$dbh->do("UPDATE `virtualshelfcontents` SET biblionumber=(SELECT biblionumber FROM items WHERE items.itemnumber=virtualshelfcontents.itemnumber)");
# drop all foreign keys : otherwise, we can't drop itemnumber field.
DropAllForeignKeys('virtualshelfcontents');
$dbh->do("ALTER TABLE `virtualshelfcontents` ADD KEY biblionumber (biblionumber)");
# create the new foreign keys (on biblionumber)
$dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `virtualshelfcontents_ibfk_1` FOREIGN KEY (`shelfnumber`) REFERENCES `virtualshelves` (`shelfnumber`) ON DELETE CASCADE ON UPDATE CASCADE");
# re-create the foreign key on virtualshelf
$dbh->do("ALTER TABLE `virtualshelfcontents` ADD CONSTRAINT `shelfcontents_ibfk_2` FOREIGN KEY (`biblionumber`) REFERENCES `biblio` (`biblionumber`) ON DELETE CASCADE ON UPDATE CASCADE");
$dbh->do("ALTER TABLE `virtualshelfcontents` DROP `itemnumber`");
print "Upgrade to $DBversion done (virtualshelves)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.002";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("DROP TABLE sessions");
$dbh->do("CREATE TABLE `sessions` (
`id` varchar(32) NOT NULL,
`a_session` text NOT NULL,
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
print "Upgrade to $DBversion done (sessions uses CGI::session, new table structure for sessions)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.003";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
if (C4::Context->preference("opaclanguages") eq "fr") {
$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')");
} else {
$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')");
}
print "Upgrade to $DBversion done (adding ReservesNeedReturns systempref, in circulation)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.004";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$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')");
print "Upgrade to $DBversion done (adding DebugLevel systempref, in 'Admin' tab)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.005";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("CREATE TABLE `tags` (
`entry` varchar(255) NOT NULL default '',
`weight` bigint(20) NOT NULL default 0,
PRIMARY KEY (`entry`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$dbh->do("CREATE TABLE `nozebra` (
`server` varchar(20) NOT NULL,
`indexname` varchar(40) NOT NULL,
`value` varchar(250) NOT NULL,
`biblionumbers` longtext NOT NULL,
KEY `indexname` (`server`,`indexname`),
KEY `value` (`server`,`value`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
print "Upgrade to $DBversion done (adding tags and nozebra tables )\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.006";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("UPDATE issues SET issuedate=timestamp WHERE issuedate='0000-00-00'");
print "Upgrade to $DBversion done (filled issues.issuedate with timestamp)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.007";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$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')");
print "Upgrade to $DBversion done (set SessionStorage variable)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.008";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE `biblio` ADD `datecreated` DATE NOT NULL AFTER `timestamp` ;");
$dbh->do("UPDATE biblio SET datecreated=timestamp");
print "Upgrade to $DBversion done (biblio creation date)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.009";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
# Create backups of call number columns
# in case default migration needs to be customized
#
# UPGRADE NOTE: temp_upg_biblioitems_call_num should be dropped
# after call numbers have been transformed to the new structure
#
# Not bothering to do the same with deletedbiblioitems -- assume
# default is good enough.
$dbh->do("CREATE TABLE `temp_upg_biblioitems_call_num` AS
SELECT `biblioitemnumber`, `biblionumber`,
`classification`, `dewey`, `subclass`,
`lcsort`, `ccode`
FROM `biblioitems`");
# biblioitems changes
$dbh->do("ALTER TABLE `biblioitems` CHANGE COLUMN `volumeddesc` `volumedesc` TEXT,
ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
ADD `totalissues` INT(10) AFTER `cn_sort`");
# default mapping of call number columns:
# cn_class = concatentation of classification + dewey,
# trimmed to fit -- assumes that most users do not
# populate both classification and dewey in a single record
# cn_item = subclass
# cn_source = left null
# cn_sort = lcsort
#
# After upgrade, cn_sort will have to be set based on whatever
# default call number scheme user sets as a preference. Misc
# script will be added at some point to do that.
#
$dbh->do("UPDATE `biblioitems`
SET cn_class = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
cn_item = subclass,
`cn_sort` = `lcsort`
");
# Now drop the old call number columns
$dbh->do("ALTER TABLE `biblioitems` DROP COLUMN `classification`,
DROP COLUMN `dewey`,
DROP COLUMN `subclass`,
DROP COLUMN `lcsort`,
DROP COLUMN `ccode`");
# deletedbiblio changes
$dbh->do("ALTER TABLE `deletedbiblio` ALTER COLUMN `frameworkcode` SET DEFAULT '',
DROP COLUMN `marc`,
ADD `datecreated` DATE NOT NULL AFTER `timestamp`");
$dbh->do("UPDATE deletedbiblio SET datecreated = timestamp");
# deletedbiblioitems changes
$dbh->do("ALTER TABLE `deletedbiblioitems`
MODIFY `publicationyear` TEXT,
CHANGE `volumeddesc` `volumedesc` TEXT,
MODIFY `collectiontitle` MEDIUMTEXT DEFAULT NULL AFTER `volumedesc`,
MODIFY `collectionissn` TEXT DEFAULT NULL AFTER `collectiontitle`,
MODIFY `collectionvolume` MEDIUMTEXT DEFAULT NULL AFTER `collectionissn`,
MODIFY `editionstatement` TEXT DEFAULT NULL AFTER `collectionvolume`,
MODIFY `editionresponsibility` TEXT DEFAULT NULL AFTER `editionstatement`,
MODIFY `place` VARCHAR(255) DEFAULT NULL AFTER `size`,
MODIFY `marc` LONGBLOB,
ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `url`,
ADD `cn_class` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
ADD `cn_item` VARCHAR(10) DEFAULT NULL AFTER `cn_class`,
ADD `cn_suffix` VARCHAR(10) DEFAULT NULL AFTER `cn_item`,
ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_suffix`,
ADD `totalissues` INT(10) AFTER `cn_sort`,
ADD `marcxml` LONGTEXT NOT NULL AFTER `totalissues`,
ADD KEY `isbn` (`isbn`),
ADD KEY `publishercode` (`publishercode`)
");
$dbh->do("UPDATE `deletedbiblioitems`
SET `cn_class` = SUBSTR(TRIM(CONCAT_WS(' ', `classification`, `dewey`)), 1, 30),
`cn_item` = `subclass`,
`cn_sort` = `lcsort`
");
$dbh->do("ALTER TABLE `deletedbiblioitems`
DROP COLUMN `classification`,
DROP COLUMN `dewey`,
DROP COLUMN `subclass`,
DROP COLUMN `lcsort`,
DROP COLUMN `ccode`
");
# deleteditems changes
$dbh->do("ALTER TABLE `deleteditems`
MODIFY `barcode` VARCHAR(20) DEFAULT NULL,
MODIFY `price` DECIMAL(8,2) DEFAULT NULL,
MODIFY `replacementprice` DECIMAL(8,2) DEFAULT NULL,
DROP `bulk`,
MODIFY `itemcallnumber` VARCHAR(30) DEFAULT NULL AFTER `wthdrawn`,
MODIFY `holdingbranch` VARCHAR(10) DEFAULT NULL,
DROP `interim`,
MODIFY `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP AFTER `paidfor`,
DROP `cutterextra`,
ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`,
MODIFY `marc` LONGBLOB AFTER `uri`,
DROP KEY `barcode`,
DROP KEY `itembarcodeidx`,
DROP KEY `itembinoidx`,
DROP KEY `itembibnoidx`,
ADD UNIQUE KEY `delitembarcodeidx` (`barcode`),
ADD KEY `delitembinoidx` (`biblioitemnumber`),
ADD KEY `delitembibnoidx` (`biblionumber`),
ADD KEY `delhomebranch` (`homebranch`),
ADD KEY `delholdingbranch` (`holdingbranch`)");
$dbh->do("UPDATE deleteditems SET `ccode` = `itype`");
$dbh->do("ALTER TABLE deleteditems DROP `itype`");
$dbh->do("UPDATE `deleteditems` SET `cn_sort` = `itemcallnumber`");
# items changes
$dbh->do("ALTER TABLE `items` ADD `cn_source` VARCHAR(10) DEFAULT NULL AFTER `onloan`,
ADD `cn_sort` VARCHAR(30) DEFAULT NULL AFTER `cn_source`,
ADD `ccode` VARCHAR(10) DEFAULT NULL AFTER `cn_sort`,
ADD `materials` VARCHAR(10) DEFAULT NULL AFTER `ccode`,
ADD `uri` VARCHAR(255) DEFAULT NULL AFTER `materials`
");
$dbh->do("ALTER TABLE `items`
DROP KEY `itembarcodeidx`,
ADD UNIQUE KEY `itembarcodeidx` (`barcode`)");
# map items.itype to items.ccode and
# set cn_sort to itemcallnumber -- as with biblioitems.cn_sort,
# will have to be subsequently updated per user's default
# classification scheme
$dbh->do("UPDATE `items` SET `cn_sort` = `itemcallnumber`,
`ccode` = `itype`");
$dbh->do("ALTER TABLE `items` DROP `cutterextra`,
DROP `itype`");
print "Upgrade to $DBversion done (major changes to biblio, biblioitems, items, and deleted* versions of same\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.010";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("CREATE INDEX `userid` ON borrowers (`userid`) ");
print "Upgrade to $DBversion done (userid index added)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.011";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE `branchcategories` CHANGE `categorycode` `categorycode` varchar(10) ");
$dbh->do("ALTER TABLE `branchcategories` CHANGE `categoryname` `categoryname` varchar(32) ");
$dbh->do("ALTER TABLE `branchcategories` ADD COLUMN `categorytype` varchar(16) ");
$dbh->do("UPDATE `branchcategories` SET `categorytype` = 'properties'");
$dbh->do("ALTER TABLE `branchrelations` CHANGE `categorycode` `categorycode` varchar(10) ");
print "Upgrade to $DBversion done (added branchcategory type)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.012";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("CREATE TABLE `class_sort_rules` (
`class_sort_rule` varchar(10) NOT NULL default '',
`description` mediumtext,
`sort_routine` varchar(30) NOT NULL default '',
PRIMARY KEY (`class_sort_rule`),
UNIQUE KEY `class_sort_rule_idx` (`class_sort_rule`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE `class_sources` (
`cn_source` varchar(10) NOT NULL default '',
`description` mediumtext,
`used` tinyint(4) NOT NULL default 0,
`class_sort_rule` varchar(10) NOT NULL default '',
PRIMARY KEY (`cn_source`),
UNIQUE KEY `cn_source_idx` (`cn_source`),
KEY `used_idx` (`used`),
CONSTRAINT `class_source_ibfk_1` FOREIGN KEY (`class_sort_rule`)
REFERENCES `class_sort_rules` (`class_sort_rule`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type)
VALUES('DefaultClassificationSource','ddc',
'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.', NULL,'free')");
$dbh->do("INSERT INTO `class_sort_rules` (`class_sort_rule`, `description`, `sort_routine`) VALUES
('dewey', 'Default filing rules for DDC', 'Dewey'),
('lcc', 'Default filing rules for LCC', 'LCC'),
('generic', 'Generic call number filing rules', 'Generic')");
$dbh->do("INSERT INTO `class_sources` (`cn_source`, `description`, `used`, `class_sort_rule`) VALUES
('ddc', 'Dewey Decimal Classification', 1, 'dewey'),
('lcc', 'Library of Congress Classification', 1, 'lcc'),
('udc', 'Universal Decimal Classification', 0, 'generic'),
('sudocs', 'SuDoc Classification (U.S. GPO)', 0, 'generic'),
('z', 'Other/Generic Classification Scheme', 0, 'generic')");
print "Upgrade to $DBversion done (classification sources added)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.013";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("CREATE TABLE `import_batches` (
`import_batch_id` int(11) NOT NULL auto_increment,
`template_id` int(11) default NULL,
`branchcode` varchar(10) default NULL,
`num_biblios` int(11) NOT NULL default 0,
`num_items` int(11) NOT NULL default 0,
`upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
`overlay_action` enum('replace', 'create_new', 'use_template') NOT NULL default 'create_new',
`import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging',
`batch_type` enum('batch', 'z3950') NOT NULL default 'batch',
`file_name` varchar(100),
`comments` mediumtext,
PRIMARY KEY (`import_batch_id`),
KEY `branchcode` (`branchcode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE `import_records` (
`import_record_id` int(11) NOT NULL auto_increment,
`import_batch_id` int(11) NOT NULL,
`branchcode` varchar(10) default NULL,
`record_sequence` int(11) NOT NULL default 0,
`upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
`import_date` DATE default NULL,
`marc` longblob NOT NULL,
`marcxml` longtext NOT NULL,
`marcxml_old` longtext NOT NULL,
`record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio',
`overlay_status` enum('no_match', 'auto_match', 'manual_match', 'match_applied') NOT NULL default 'no_match',
`status` enum('error', 'staged', 'imported', 'reverted', 'items_reverted') NOT NULL default 'staged',
`import_error` mediumtext,
`encoding` varchar(40) NOT NULL default '',
`z3950random` varchar(40) default NULL,
PRIMARY KEY (`import_record_id`),
CONSTRAINT `import_records_ifbk_1` FOREIGN KEY (`import_batch_id`)
REFERENCES `import_batches` (`import_batch_id`) ON DELETE CASCADE ON UPDATE CASCADE,
KEY `branchcode` (`branchcode`),
KEY `batch_sequence` (`import_batch_id`, `record_sequence`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE `import_record_matches` (
`import_record_id` int(11) NOT NULL,
`candidate_match_id` int(11) NOT NULL,
`score` int(11) NOT NULL default 0,
CONSTRAINT `import_record_matches_ibfk_1` FOREIGN KEY (`import_record_id`)
REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
KEY `record_score` (`import_record_id`, `score`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE `import_biblios` (
`import_record_id` int(11) NOT NULL,
`matched_biblionumber` int(11) default NULL,
`control_number` varchar(25) default NULL,
`original_source` varchar(25) default NULL,
`title` varchar(128) default NULL,
`author` varchar(80) default NULL,
`isbn` varchar(14) default NULL,
`issn` varchar(9) default NULL,
`has_items` tinyint(1) NOT NULL default 0,
CONSTRAINT `import_biblios_ibfk_1` FOREIGN KEY (`import_record_id`)
REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
KEY `matched_biblionumber` (`matched_biblionumber`),
KEY `title` (`title`),
KEY `isbn` (`isbn`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE `import_items` (
`import_items_id` int(11) NOT NULL auto_increment,
`import_record_id` int(11) NOT NULL,
`itemnumber` int(11) default NULL,
`branchcode` varchar(10) default NULL,
`status` enum('error', 'staged', 'imported', 'reverted') NOT NULL default 'staged',
`marcxml` longtext NOT NULL,
`import_error` mediumtext,
PRIMARY KEY (`import_items_id`),
CONSTRAINT `import_items_ibfk_1` FOREIGN KEY (`import_record_id`)
REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
KEY `itemnumber` (`itemnumber`),
KEY `branchcode` (`branchcode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("INSERT INTO `import_batches`
(`overlay_action`, `import_status`, `batch_type`, `file_name`)
SELECT distinct 'create_new', 'staged', 'z3950', `file`
FROM `marc_breeding`");
$dbh->do("INSERT INTO `import_records`
(`import_batch_id`, `import_record_id`, `record_sequence`, `marc`, `record_type`, `status`,
`encoding`, `z3950random`, `marcxml`, `marcxml_old`)
SELECT `import_batch_id`, `id`, 1, `marc`, 'biblio', 'staged', `encoding`, `z3950random`, '', ''
FROM `marc_breeding`
JOIN `import_batches` ON (`file_name` = `file`)");
$dbh->do("INSERT INTO `import_biblios`
(`import_record_id`, `title`, `author`, `isbn`)
SELECT `import_record_id`, `title`, `author`, `isbn`
FROM `marc_breeding`
JOIN `import_records` ON (`import_record_id` = `id`)");
$dbh->do("UPDATE `import_batches`
SET `num_biblios` = (
SELECT COUNT(*)
FROM `import_records`
WHERE `import_batch_id` = `import_batches`.`import_batch_id`
)");
$dbh->do("DROP TABLE `marc_breeding`");
print "Upgrade to $DBversion done (import_batches et al. added)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.014";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE subscription ADD lastbranch VARCHAR(4)");
print "Upgrade to $DBversion done (userid index added)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.015";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("CREATE TABLE `saved_sql` (
`id` int(11) NOT NULL auto_increment,
`borrowernumber` int(11) default NULL,
`date_created` datetime default NULL,
`last_modified` datetime default NULL,
`savedsql` text,
`last_run` datetime default NULL,
`report_name` varchar(255) default NULL,
`type` varchar(255) default NULL,
`notes` text,
PRIMARY KEY (`id`),
KEY boridx (`borrowernumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$dbh->do("CREATE TABLE `saved_reports` (
`id` int(11) NOT NULL auto_increment,
`report_id` int(11) default NULL,
`report` longtext,
`date_run` datetime default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
print "Upgrade to $DBversion done (saved_sql and saved_reports added)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.016";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do(" CREATE TABLE reports_dictionary (
id int(11) NOT NULL auto_increment,
name varchar(255) default NULL,
description text,
date_created datetime default NULL,
date_modified datetime default NULL,
saved_sql text,
area int(11) default NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ");
print "Upgrade to $DBversion done (reports_dictionary) added)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.017";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE action_logs DROP PRIMARY KEY");
$dbh->do("ALTER TABLE action_logs ADD KEY timestamp (timestamp,user)");
$dbh->do("ALTER TABLE action_logs ADD action_id INT(11) NOT NULL FIRST");
$dbh->do("UPDATE action_logs SET action_id = if (\@a, \@a:=\@a+1, \@a:=1)");
$dbh->do("ALTER TABLE action_logs MODIFY action_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY");
print "Upgrade to $DBversion done (added column to action_logs)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.019";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE `zebraqueue`
ADD `done` INT NOT NULL DEFAULT '0',
ADD `time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ;
");
print "Upgrade to $DBversion done (adding timestamp and done columns to zebraque table to improve problem tracking) added)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.019";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE biblio MODIFY biblionumber INT(11) NOT NULL AUTO_INCREMENT");
$dbh->do("ALTER TABLE biblioitems MODIFY biblioitemnumber INT(11) NOT NULL AUTO_INCREMENT");
$dbh->do("ALTER TABLE items MODIFY itemnumber INT(11) NOT NULL AUTO_INCREMENT");
print "Upgrade to $DBversion done (made bib/item PKs auto_increment)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.020";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE deleteditems
DROP KEY `delitembarcodeidx`,
ADD KEY `delitembarcodeidx` (`barcode`)");
print "Upgrade to $DBversion done (dropped uniqueness of key on deleteditems.barcode)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.021";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE items CHANGE homebranch homebranch VARCHAR(10)");
$dbh->do("ALTER TABLE deleteditems CHANGE homebranch homebranch VARCHAR(10)");
$dbh->do("ALTER TABLE statistics CHANGE branch branch VARCHAR(10)");
$dbh->do("ALTER TABLE subscription CHANGE lastbranch lastbranch VARCHAR(10)");
print "Upgrade to $DBversion done (extended missed branchcode columns to 10 chars)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.022";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE items
ADD `damaged` tinyint(1) default NULL AFTER notforloan");
$dbh->do("ALTER TABLE deleteditems
ADD `damaged` tinyint(1) default NULL AFTER notforloan");
print "Upgrade to $DBversion done (adding damaged column to items table)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.023";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
VALUES ('yuipath','http://yui.yahooapis.com/2.3.1/build','Insert the path to YUI libraries','','free')");
print "Upgrade to $DBversion done (adding new system preference for controlling YUI path)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.024";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE biblioitems CHANGE itemtype itemtype VARCHAR(10)");
print "Upgrade to $DBversion done (changing itemtype to (10))\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.025";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE items ADD COLUMN itype VARCHAR(10)");
$dbh->do("ALTER TABLE deleteditems ADD COLUMN itype VARCHAR(10) AFTER uri");
if(C4::Context->preference('item-level_itypes')){
$dbh->do('update items,biblioitems set items.itype=biblioitems.itemtype where items.biblionumber=biblioitems.biblionumber and itype is null');
}
print "Upgrade to $DBversion done (reintroduce items.itype - fill from itemtype)\n ";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.026";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
VALUES ('HomeOrHoldingBranch','homebranch','homebranch|holdingbranch','With independent branches turned on this decides whether to check the items holdingbranch or homebranch at circulatilon','choice')");
print "Upgrade to $DBversion done (adding new system preference for choosing whether homebranch or holdingbranch is checked in circulation)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.027";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("CREATE TABLE `marc_matchers` (
`matcher_id` int(11) NOT NULL auto_increment,
`code` varchar(10) NOT NULL default '',
`description` varchar(255) NOT NULL default '',
`record_type` varchar(10) NOT NULL default 'biblio',
`threshold` int(11) NOT NULL default 0,
PRIMARY KEY (`matcher_id`),
KEY `code` (`code`),
KEY `record_type` (`record_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE `matchpoints` (
`matcher_id` int(11) NOT NULL,
`matchpoint_id` int(11) NOT NULL auto_increment,
`search_index` varchar(30) NOT NULL default '',
`score` int(11) NOT NULL default 0,
PRIMARY KEY (`matchpoint_id`),
CONSTRAINT `matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE `matchpoint_components` (
`matchpoint_id` int(11) NOT NULL,
`matchpoint_component_id` int(11) NOT NULL auto_increment,
sequence int(11) NOT NULL default 0,
tag varchar(3) NOT NULL default '',
subfields varchar(40) NOT NULL default '',
offset int(4) NOT NULL default 0,
length int(4) NOT NULL default 0,
PRIMARY KEY (`matchpoint_component_id`),
KEY `by_sequence` (`matchpoint_id`, `sequence`),
CONSTRAINT `matchpoint_components_ifbk_1` FOREIGN KEY (`matchpoint_id`)
REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE `matchpoint_component_norms` (
`matchpoint_component_id` int(11) NOT NULL,
`sequence` int(11) NOT NULL default 0,
`norm_routine` varchar(50) NOT NULL default '',
KEY `matchpoint_component_norms` (`matchpoint_component_id`, `sequence`),
CONSTRAINT `matchpoint_component_norms_ifbk_1` FOREIGN KEY (`matchpoint_component_id`)
REFERENCES `matchpoint_components` (`matchpoint_component_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE `matcher_matchpoints` (
`matcher_id` int(11) NOT NULL,
`matchpoint_id` int(11) NOT NULL,
CONSTRAINT `matcher_matchpoints_ifbk_1` FOREIGN KEY (`matcher_id`)
REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `matcher_matchpoints_ifbk_2` FOREIGN KEY (`matchpoint_id`)
REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE `matchchecks` (
`matcher_id` int(11) NOT NULL,
`matchcheck_id` int(11) NOT NULL auto_increment,
`source_matchpoint_id` int(11) NOT NULL,
`target_matchpoint_id` int(11) NOT NULL,
PRIMARY KEY (`matchcheck_id`),
CONSTRAINT `matcher_matchchecks_ifbk_1` FOREIGN KEY (`matcher_id`)
REFERENCES `marc_matchers` (`matcher_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `matcher_matchchecks_ifbk_2` FOREIGN KEY (`source_matchpoint_id`)
REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `matcher_matchchecks_ifbk_3` FOREIGN KEY (`target_matchpoint_id`)
REFERENCES `matchpoints` (`matchpoint_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
print "Upgrade to $DBversion done (added C4::Matcher serialization tables)\n ";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.028";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
VALUES ('canreservefromotherbranches','1','','With Independent branches on, can a user from one library reserve an item from another library','YesNo')");
print "Upgrade to $DBversion done (adding new system preference for changing reserve/holds behaviour with independent branches)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.029";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE `import_batches` ADD `matcher_id` int(11) NULL AFTER `import_batch_id`");
print "Upgrade to $DBversion done (adding matcher_id to import_batches)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.030";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("
CREATE TABLE services_throttle (
service_type varchar(10) NOT NULL default '',
service_count varchar(45) default NULL,
PRIMARY KEY (service_type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
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')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
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')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
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')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
VALUES ('XISBNDailyLimit',499,'','The xISBN Web service is free for non-commercial use when usage does not exceed 500 requests per day','free')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
VALUES ('PINESISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use PINES OISBN web service in the Editions tab on the detail pages.','YesNo')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,options,explanation,type)
VALUES ('ThingISBN',0,'','Use with FRBRizeEditions. If ON, Koha will use the ThingISBN web service in the Editions tab on the detail pages.','YesNo')");
print "Upgrade to $DBversion done (adding services throttle table and sysprefs for xISBN)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.031";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryStemming',1,'If ON, enables query stemming',NULL,'YesNo')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryFuzzy',1,'If ON, enables fuzzy option for searches',NULL,'YesNo')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('QueryWeightFields',1,'If ON, enables field weighting',NULL,'YesNo')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('WebBasedSelfCheck',0,'If ON, enables the web-based self-check system',NULL,'YesNo')");
$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')");
$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')");
$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')");
$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')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('defaultSortOrder',NULL,'Specify the default sort order','asc|dsc|az|za','Choice')");
$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')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACdefaultSortOrder',NULL,'Specify the default sort order','asc|dsc|za|az','Choice')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('staffClientBaseURL','','Specify the base URL of the staff client',NULL,'free')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('minPasswordLength',3,'Specify the minimum length of a patron/staff password',NULL,'free')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('noItemTypeImages',0,'If ON, disables item-type images',NULL,'YesNo')");
$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')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('holdCancelLength','','Specify how many days before a hold is canceled',NULL,'free')");
$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')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('finesMode','test','Choose the fines mode, test or production','test|production','Choice')");
$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')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('itemBarcodeInputFilter','','If set, allows specification of a item barcode input filter','cuecat','Choice')");
$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')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('URLLinkText','','Text to display as the link anchor in the OPAC',NULL,'free')");
$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')");
$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')");
$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')");
$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')");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACUserCSS',0,'Add CSS to be included in the OPAC',NULL,'free')");
print "Upgrade to $DBversion done (adding additional system preference)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.032";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("UPDATE `marc_subfield_structure` SET `kohafield` = 'items.wthdrawn' WHERE `kohafield` = 'items.withdrawn'");
print "Upgrade to $DBversion done (fixed MARC framework references to items.withdrawn)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.033";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("INSERT INTO `userflags` VALUES(17,'staffaccess','Modify login / permissions for staff users',0)");
print "Upgrade to $DBversion done (Adding permissions flag for staff member access modification. )\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.034";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE `virtualshelves` ADD COLUMN `sortfield` VARCHAR(16) ");
print "Upgrade to $DBversion done (Adding sortfield for Virtual Shelves. )\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.035";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("UPDATE marc_subfield_structure
SET authorised_value = 'cn_source'
WHERE kohafield IN ('items.cn_source', 'biblioitems.cn_source')
AND (authorised_value is NULL OR authorised_value = '')");
print "Upgrade to $DBversion done (MARC frameworks: make classification source a drop-down)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.036";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$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');");
print "Upgrade to $DBversion done (OPACItemsResultsDisplay systempreference added)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.037";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactfirstname` varchar(255)");
$dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactsurname` varchar(255)");
$dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress1` varchar(255)");
$dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress2` varchar(255)");
$dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactaddress3` varchar(255)");
$dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactzipcode` varchar(50)");
$dbh->do("ALTER TABLE `borrowers` ADD COLUMN `altcontactphone` varchar(50)");
print "Upgrade to $DBversion done (Adding Alternative Contact Person information to borrowers table)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.038";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$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'");
$dbh->do("DELETE FROM `systempreferences` WHERE variable='hideBiblioNumber'");
print "Upgrade to $DBversion done ('alter finesMode systempreference, remove superfluous syspref.')\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.039";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$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')");
$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')");
$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')");
# $dbh->do("DELETE FROM `systempreferences` WHERE variable='HomeOrHoldingBranch'"); # Bug #2752
print "Upgrade to $DBversion done ('add circ sysprefs CircControl, finesCalendar, and uppercasesurnames, and delete HomeOrHoldingBranch.')\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.040";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$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')");
$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')");
print "Upgrade to $DBversion done ('add circ sysprefs todaysIssuesDefaultSortOrder and previousIssuesDefaultSortOrder.')\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.041";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
# Strictly speaking it is not necessary to explicitly change
# NULL values to 0, because the ALTER TABLE statement will do that.
# However, setting them first avoids a warning.
$dbh->do("UPDATE items SET notforloan = 0 WHERE notforloan IS NULL");
$dbh->do("UPDATE items SET damaged = 0 WHERE damaged IS NULL");
$dbh->do("UPDATE items SET itemlost = 0 WHERE itemlost IS NULL");
$dbh->do("UPDATE items SET wthdrawn = 0 WHERE wthdrawn IS NULL");
$dbh->do("ALTER TABLE items
MODIFY notforloan tinyint(1) NOT NULL default 0,
MODIFY damaged tinyint(1) NOT NULL default 0,
MODIFY itemlost tinyint(1) NOT NULL default 0,
MODIFY wthdrawn tinyint(1) NOT NULL default 0");
$dbh->do("UPDATE deleteditems SET notforloan = 0 WHERE notforloan IS NULL");
$dbh->do("UPDATE deleteditems SET damaged = 0 WHERE damaged IS NULL");
$dbh->do("UPDATE deleteditems SET itemlost = 0 WHERE itemlost IS NULL");
$dbh->do("UPDATE deleteditems SET wthdrawn = 0 WHERE wthdrawn IS NULL");
$dbh->do("ALTER TABLE deleteditems
MODIFY notforloan tinyint(1) NOT NULL default 0,
MODIFY damaged tinyint(1) NOT NULL default 0,
MODIFY itemlost tinyint(1) NOT NULL default 0,
MODIFY wthdrawn tinyint(1) NOT NULL default 0");
print "Upgrade to $DBversion done (disallow NULL in several item status columns)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.042";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE aqbooksellers CHANGE name name mediumtext NOT NULL");
print "Upgrade to $DBversion done (disallow NULL in aqbooksellers.name; part of fix for bug 1251)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.043";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$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");
print "Upgrade to $DBversion done (currency table: add symbol and timestamp columns)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.044";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE deletedborrowers
ADD `altcontactfirstname` varchar(255) default NULL,
ADD `altcontactsurname` varchar(255) default NULL,
ADD `altcontactaddress1` varchar(255) default NULL,
ADD `altcontactaddress2` varchar(255) default NULL,
ADD `altcontactaddress3` varchar(255) default NULL,
ADD `altcontactzipcode` varchar(50) default NULL,
ADD `altcontactphone` varchar(50) default NULL
");
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
('OPACBaseURL',NULL,'Specify the Base URL of the OPAC, e.g., opac.mylibrary.com, the http:// will be added automatically by Koha.',NULL,'Free'),
('language','en','Set the default language in the staff client.',NULL,'Languages'),
('QueryAutoTruncate',1,'If ON, query truncation is enabled by default',NULL,'YesNo'),
('QueryRemoveStopwords',0,'If ON, stopwords listed in the Administration area will be removed from queries',NULL,'YesNo')
");
print "Upgrade to $DBversion done (syncing deletedborrowers table with borrowers table)\n";
SetVersion ($DBversion);
}
#-- http://www.w3.org/International/articles/language-tags/
#-- RFC4646
$DBversion = "3.00.00.045";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("
CREATE TABLE language_subtag_registry (
subtag varchar(25),
type varchar(25), -- language-script-region-variant-extension-privateuse
description varchar(25), -- only one of the possible descriptions for ease of reference, see language_descriptions for the complete list
added date,
KEY `subtag` (`subtag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
#-- TODO: add suppress_scripts
#-- this maps three letter codes defined in iso639.2 back to their
#-- two letter equivilents in rfc4646 (LOC maintains iso639+)
$dbh->do("CREATE TABLE language_rfc4646_to_iso639 (
rfc4646_subtag varchar(25),
iso639_2_code varchar(25),
KEY `rfc4646_subtag` (`rfc4646_subtag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("CREATE TABLE language_descriptions (
subtag varchar(25),
type varchar(25),
lang varchar(25),
description varchar(255),
KEY `lang` (`lang`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
#-- bi-directional support, keyed by script subcode
$dbh->do("CREATE TABLE language_script_bidi (
rfc4646_subtag varchar(25), -- script subtag, Arab, Hebr, etc.
bidi varchar(3), -- rtl ltr
KEY `rfc4646_subtag` (`rfc4646_subtag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
#-- BIDI Stuff, Arabic and Hebrew
$dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
VALUES( 'Arab', 'rtl')");
$dbh->do("INSERT INTO language_script_bidi(rfc4646_subtag,bidi)
VALUES( 'Hebr', 'rtl')");
#-- TODO: need to map language subtags to script subtags for detection
#-- of bidi when script is not specified (like ar, he)
$dbh->do("CREATE TABLE language_script_mapping (
language_subtag varchar(25),
script_subtag varchar(25),
KEY `language_subtag` (`language_subtag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8");
#-- Default mappings between script and language subcodes
$dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
VALUES( 'ar', 'Arab')");
$dbh->do("INSERT INTO language_script_mapping(language_subtag,script_subtag)
VALUES( 'he', 'Hebr')");
print "Upgrade to $DBversion done (adding language subtag registry and basic BiDi support NOTE: You should import the subtag registry SQL)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.046";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE `subscription` CHANGE `numberlength` `numberlength` int(11) default '0' ,
CHANGE `weeklength` `weeklength` int(11) default '0'");
$dbh->do("CREATE TABLE `serialitems` (`serialid` int(11) NOT NULL, `itemnumber` int(11) NOT NULL, UNIQUE KEY `serialididx` (`serialid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8");
$dbh->do("INSERT INTO `serialitems` SELECT `serialid`,`itemnumber` from serial where NOT ISNULL(itemnumber) && itemnumber <> '' && itemnumber NOT LIKE '%,%'");
print "Upgrade to $DBversion done (Add serialitems table to link serial issues to items. )\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.047";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$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');");
print "Upgrade to $DBversion done ( Added OpacRenewalAllowed syspref )\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.048";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE `items` ADD `more_subfields_xml` longtext default NULL AFTER `itype`");
print "Upgrade to $DBversion done (added items.more_subfields_xml)\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.049";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("ALTER TABLE `z3950servers` ADD `encoding` text default NULL AFTER type ");
print "Upgrade to $DBversion done ( Added encoding field to z3950servers table )\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.050";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHighlightedWords','0','If Set, query matched terms are highlighted in OPAC',NULL,'YesNo');");
print "Upgrade to $DBversion done ( Added OpacHighlightedWords syspref )\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.051";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
$dbh->do("UPDATE systempreferences SET explanation = 'Define the current theme for the OPAC interface.' WHERE variable = 'opacthemes';");
print "Upgrade to $DBversion done ( Corrected opacthemes explanation. )\n";
SetVersion ($DBversion);
}
$DBversion = "3.00.00.052";
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {