6 # This script checks for required updates to the database.
8 # Part of the Koha Library Software www.koha.org
9 # Licensed under the GPL.
12 # - Would also be a good idea to offer to do a backup at this time...
14 # NOTE: If you do something more than once in here, make it table driven.
24 # FIXME - The user might be installing a new database, so can't rely
25 # on /etc/koha.conf anyway.
32 %existingtables, # tables already in database
36 $type, $null, $key, $default, $extra,
37 $prefitem, # preference item in systempreferences table
40 my $dbh = C4::Context->dbh;
41 print "connected to your DB. Checking & modifying it\n";
46 # Tables to add if they don't exist
48 shelfcontents => "( shelfnumber int not null,
49 itemnumber int not null,
51 bookshelf => "( shelfnumber int auto_increment primary key,
52 shelfname char(255))",
53 z3950queue => "( id int auto_increment primary key,
62 identifier char(30))",
63 z3950results => "( id int auto_increment primary key,
73 branchrelations => "( branchcode varchar(4),
74 categorycode varchar(4))",
75 websites => "( websitenumber int(11) NOT NULL auto_increment,
76 biblionumber int(11) NOT NULL default '0',
80 PRIMARY KEY (websitenumber) )",
81 marcrecorddone => "( isbn char(40),
84 controlnumber char(40))",
85 uploadedmarc => "( id int(11) NOT NULL auto_increment PRIMARY KEY,
87 hidden smallint(6) default NULL,
88 name varchar(255) default NULL)",
89 ethnicity => "( code varchar(10) NOT NULL default '',
90 name varchar(255) default NULL,
91 PRIMARY KEY (code) )",
92 sessions => "( sessionID varchar(255) NOT NULL default '',
93 userid varchar(255) default NULL,
94 ip varchar(16) default NULL,
96 PRIMARY KEY (sessionID) )",
97 sessionqueries => "( sessionID varchar(255) NOT NULL default '',
98 userid char(100) NOT NULL default '',
99 ip char(18) NOT NULL default '',
100 url text NOT NULL default '' )",
101 bibliothesaurus => "( id bigint(20) NOT NULL auto_increment,
102 freelib char(255) NOT NULL default '',
103 stdlib char(255) NOT NULL default '',
104 category char(10) NOT NULL default '',
105 level tinyint(4) NOT NULL default '1',
106 hierarchy char(80) NOT NULL default '',
107 father char(80) NOT NULL default '',
109 KEY freelib (freelib),
111 KEY category (category),
112 KEY hierarchy (hierarchy)
115 bibid bigint(20) unsigned NOT NULL auto_increment,
116 biblionumber int(11) NOT NULL default '0',
117 datecreated date NOT NULL default '0000-00-00',
118 datemodified date default NULL,
119 origincode char(20) default NULL,
121 KEY origincode (origincode),
122 KEY biblionumber (biblionumber)
124 marc_blob_subfield => "(
125 blobidlink bigint(20) NOT NULL auto_increment,
126 subfieldvalue longtext NOT NULL,
127 PRIMARY KEY (blobidlink)
129 marc_subfield_structure => "(
130 tagfield char(3) NOT NULL default '',
131 tagsubfield char(1) NOT NULL default '',
132 liblibrarian char(255) NOT NULL default '',
133 libopac char(255) NOT NULL default '',
134 repeatable tinyint(4) NOT NULL default '0',
135 mandatory tinyint(4) NOT NULL default '0',
136 kohafield char(40) default NULL,
137 tab tinyint(1) default NULL,
138 authorised_value char(10) default NULL,
139 thesaurus_category char(10) default NULL,
140 value_builder char(80) default NULL,
141 PRIMARY KEY (tagfield,tagsubfield),
142 KEY kohafield (kohafield),
145 marc_subfield_table => "(
146 subfieldid bigint(20) unsigned NOT NULL auto_increment,
147 bibid bigint(20) unsigned NOT NULL default '0',
148 tag char(3) NOT NULL default '',
149 tagorder tinyint(4) NOT NULL default '1',
150 tag_indicator char(2) NOT NULL default '',
151 subfieldcode char(1) NOT NULL default '',
152 subfieldorder tinyint(4) NOT NULL default '1',
153 subfieldvalue varchar(255) default NULL,
154 valuebloblink bigint(20) default NULL,
155 PRIMARY KEY (subfieldid),
158 KEY tag_indicator (tag_indicator),
159 KEY subfieldorder (subfieldorder),
160 KEY subfieldcode (subfieldcode),
161 KEY subfieldvalue (subfieldvalue),
162 KEY tagorder (tagorder)
164 marc_tag_structure => "(
165 tagfield char(3) NOT NULL default '',
166 liblibrarian char(255) NOT NULL default '',
167 libopac char(255) NOT NULL default '',
168 repeatable tinyint(4) NOT NULL default '0',
169 mandatory tinyint(4) NOT NULL default '0',
170 authorised_value char(10) default NULL,
171 PRIMARY KEY (tagfield)
174 bibid bigint(20) NOT NULL default '0',
175 tag char(3) NOT NULL default '',
176 tagorder tinyint(4) NOT NULL default '1',
177 subfieldid char(1) NOT NULL default '',
178 subfieldorder tinyint(4) NOT NULL default '1',
179 word varchar(255) NOT NULL default '',
180 sndx_word varchar(255) NOT NULL default '',
183 KEY tagorder (tagorder),
184 KEY subfieldid (subfieldid),
185 KEY subfieldorder (subfieldorder),
187 KEY sndx_word (sndx_word)
189 marc_breeding => "( id bigint(20) NOT NULL auto_increment,
190 file varchar(80) NOT NULL default '',
191 isbn varchar(10) NOT NULL default '',
192 title varchar(128) default NULL,
193 author varchar(80) default NULL,
195 encoding varchar(40) default NULL,
200 authorised_values => "(id int(11) NOT NULL auto_increment,
201 category char(10) NOT NULL default '',
202 authorised_value char(80) NOT NULL default '',
207 userflags => "( bit int(11) NOT NULL default '0',
208 flag char(30), flagdesc char(255),
213 my %requirefields = (
214 biblio => { 'abstract' => 'text' },
215 deletedbiblio => { 'abstract' => 'text', 'marc' => 'blob' },
216 deleteditems => { 'marc' => 'blob', 'paidfor' => 'text' },
218 'lccn' => 'char(25)',
219 'url' => 'varchar(255)',
222 deletedbiblioitems => {
223 'lccn' => 'char(25)',
224 'url' => 'varchar(255)',
227 branchtransfers => { 'datearrived' => 'datetime' },
228 statistics => { 'borrowernumber' => 'int(11)' },
230 'invoicedisc' => 'float(6,4)',
231 'nocalc' => 'int(11)'
234 'userid' => 'char(30)',
235 'password' => 'char(30)',
236 'flags' => 'int(11)',
237 'textmessaging' => 'varchar(30)',
238 'zipcode' => 'varchar(25)',
239 'homezipcode' => 'varchar(25)',
241 aqorders => { 'budgetdate' => 'date' },
242 aqbudget => {'aqbudgetid' => 'tinyint(4) auto_increment primary key'},
243 items => {'paidfor' => 'text'},
245 #added so that reference items are not available for reserves...
246 itemtypes => { 'notforloan' => 'smallint(6)' },
247 systempreferences => { 'explanation' => 'char(80)',
248 'type' => 'char(20)',
249 'options' => 'text' },
250 z3950servers => { 'syntax' => 'char(80)' },
251 marc_tag_structure =>{
252 'itemtype' => 'char(4) not NULL default \'\''},
253 marc_subfield_structure =>{'seealso' => 'char(255)',
254 'itemtype' => 'char(4) not NULL default \'\''},
255 bookshelf => {'owner' => 'char(80)',
256 'category' => 'char(1)',
260 my %dropable_table = (
261 classification => 'classification',
262 multipart => 'multipart',
263 multivolume => 'multivolume',
264 newitems => 'newitems',
265 procedures => 'procedures',
266 publisher => 'publisher',
267 searchstats => 'searchstats',
268 serialissues => 'serialissues',
271 # the other hash contains other actions that can't be done elsewhere. they are done
272 # either BEFORE of AFTER everything else, depending on "when" entry (default => AFTER)
274 # The tabledata hash contains data that should be in the tables.
275 # The uniquefieldrequired hash entry is used to determine which (if any) fields
276 # must not exist in the table for this row to be inserted. If the
277 # uniquefieldrequired entry is already in the table, the existing data is not
278 # modified, unless the forceupdate hash entry is also set. Fields in the
279 # anonymous "forceupdate" hash will be forced to be updated to the default
280 # values given in the %tabledata hash.
285 uniquefieldrequired => 'bit',
287 flag => 'superlibrarian',
288 flagdesc => 'Access to all librarian functions',
292 uniquefieldrequired => 'bit',
295 flagdesc => 'Circulate books',
299 uniquefieldrequired => 'bit',
302 flagdesc => 'View Catalogue (Librarian Interface)',
306 uniquefieldrequired => 'bit',
308 flag => 'parameters',
309 flagdesc => 'Set Koha system paramters',
313 uniquefieldrequired => 'bit',
316 flagdesc => 'Add or modify borrowers',
320 uniquefieldrequired => 'bit',
322 flag => 'permissions',
323 flagdesc => 'Set user permissions',
327 uniquefieldrequired => 'bit',
329 flag => 'reserveforothers',
330 flagdesc => 'Reserve books for patrons',
334 uniquefieldrequired => 'bit',
337 flagdesc => 'Borrow books',
341 uniquefieldrequired => 'bit',
343 flag => 'reserveforself',
344 flagdesc => 'Reserve books for self',
348 uniquefieldrequired => 'bit',
350 flag => 'editcatalogue',
351 flagdesc => 'Edit Catalogue (Modify bibliographic/holdings data)',
355 uniquefieldrequired => 'bit',
357 flag => 'updatecharges',
358 flagdesc => 'Update borrower charges',
362 systempreferences => [
364 uniquefieldrequired => 'variable',
365 forceupdate => { 'explanation' => 1,
367 variable => 'LibraryName',
368 value => '<i><b>Koha<br/>Free Software ILS<br/><br/></b>Koha : a gift, a contribution<br/> in Maori</i>',
369 explanation => 'Library name as shown on main opac page',
374 uniquefieldrequired => 'variable',
375 forceupdate => { 'explanation' => 1,
377 variable => 'autoMemberNum',
379 explanation => 'Member number is auto-calculated',
384 uniquefieldrequired => 'variable',
385 forceupdate => { 'explanation' => 1,
388 variable => 'acquisitions',
391 'Normal, budget-based acquisitions, or Simple bibliographic-data acquisitions',
393 options => 'simple|normal'
396 uniquefieldrequired => 'variable',
397 forceupdate => { 'explanation' => 1,
400 variable => 'dateformat',
403 'date format (us mm/dd/yyyy, metric dd/mm/yyy, ISO yyyy/mm/dd)',
405 options => 'metric|us|iso'
408 uniquefieldrequired => 'variable',
409 variable => 'template',
410 forceupdate => { 'explanation' => 1,
413 explanation => 'Preference order for intranet interface templates',
417 uniquefieldrequired => 'variable',
418 variable => 'autoBarcode',
419 forceupdate => { 'explanation' => 1,
422 explanation => 'Barcode is auto-calculated',
426 uniquefieldrequired => 'variable',
427 variable => 'insecure',
428 forceupdate => { 'explanation' => 1,
432 'If YES, no auth at all is needed. Be careful if you set this to yes!',
436 uniquefieldrequired => 'variable',
437 variable => 'authoritysep',
438 forceupdate => { 'explanation' => 1,
443 'the separator used in authority/thesaurus. Usually --',
448 uniquefieldrequired => 'variable',
449 variable => 'opaclanguages',
450 forceupdate => { 'explanation' => 1,
453 explanation => 'Set the preferred order for translations. The top language will be tried first.',
457 uniquefieldrequired => 'variable',
458 variable => 'opacthemes',
459 forceupdate => { 'explanation' => 1,
462 explanation => 'Set the preferred order for themes. The top theme will be tried first.',
466 uniquefieldrequired => 'variable',
467 variable => 'timeout',
468 forceupdate => { 'explanation' => 1,
471 explanation => 'Inactivity timeout for cookies authentication (in seconds)',
475 uniquefieldrequired => 'variable',
477 forceupdate => { 'explanation' => 1,
480 explanation => 'Turn on MARC support',
484 uniquefieldrequired => 'variable',
485 variable => 'marcflavour',
486 forceupdate => { 'explanation' => 1,
491 'your MARC flavor (MARC21 or UNIMARC) used for character encoding',
493 options => 'MARC21|UNIMARC'
496 uniquefieldrequired => 'variable',
497 variable => 'checkdigit',
499 forceupdate => { 'explanation' => 1,
502 explanation => 'Validity checks on membership number: none or "Katipo" style checks',
504 options => 'none|katipo'
507 uniquefieldrequired => 'variable',
508 variable => 'maxoutstanding',
509 forceupdate => { 'explanation' => 1,
513 'maximum amount withstanding to be able make reserves ',
517 uniquefieldrequired => 'variable',
518 variable => 'maxreserves',
519 forceupdate => { 'explanation' => 1,
523 'maximum number of reserves a member can make',
528 uniquefieldrequired => 'variable',
529 variable => 'noissuescharge',
530 forceupdate => { 'explanation' => 1,
534 'maximum amount withstanding to be able to check out an item',
539 uniquefieldrequired => 'variable',
540 variable => 'KohaAdminEmailAddress',
541 forceupdate => { 'explanation' => 1,
543 value => 'your.mail@here',
544 explanation => 'the email address where borrowers modifs are sent',
548 uniquefieldrequired => 'variable',
550 forceupdate => { 'explanation' => 1,
553 explanation => 'the gist rate. NOT in %, but in numeric form (0.12 for 12%)',
557 uniquefieldrequired => 'variable',
558 variable => 'ldapserver',
559 forceupdate => { 'explanation' => 1,
562 explanation => 'your ldap server',
566 uniquefieldrequired => 'variable',
567 variable => 'ldapinfos',
568 forceupdate => { 'explanation' => 1,
571 explanation => 'ldap info. The ldap will be used in dn : uid=xxx, <ldapinfos>',
575 uniquefieldrequired => 'variable',
576 variable => 'printcirculationslips',
577 forceupdate => { 'explanation' => 1,
580 explanation => 'if set to 1, print circulation slips. If set to 0, don\'t',
587 my %fielddefinitions = (
590 field => 'printername',
599 field => 'bookfundid',
608 field => 'aqbudgetid',
609 type => 'tinyint(4)',
613 extra => 'auto_increment'
623 extra => 'auto_increment'
628 field => 'z3950random',
629 type => 'varchar(40)',
637 type => 'varchar(40)',
651 # Get version of MySQL database engine.
652 my $mysqlversion = `mysqld --version`;
653 $mysqlversion =~ /Ver (\S*) /;
655 if ( $mysqlversion ge '3.23' ) {
656 print "Could convert to MyISAM database tables...\n";
659 #---------------------------------
662 # Collect all tables into a list
663 $sth = $dbh->prepare("show tables");
665 while ( my ($table) = $sth->fetchrow ) {
666 $existingtables{$table} = 1;
670 # Now add any missing tables
671 foreach $table ( keys %requiretables ) {
672 unless ( $existingtables{$table} ) {
673 print "Adding $table table...\n";
674 my $sth = $dbh->prepare("create table $table $requiretables{$table}");
677 print "Error : $sth->errstr \n";
683 # now drop useless tables
684 foreach $table ( keys %dropable_table ) {
685 if ( $existingtables{$table} ) {
686 print "Dropping unused table $table\n" if $debug;
687 $dbh->do("drop table $table");
689 print "Error : $dbh->errstr \n";
693 unless ( $existingtables{'z3950servers'} ) {
694 #MJR: added syntax entries to close bug 624
695 print "Adding z3950servers table...\n";
696 my $sti = $dbh->prepare( "create table z3950servers (
709 $sti = $dbh->prepare( "insert into z3950servers
710 values ('z3950.loc.gov',
714 'Library of Congress',
719 unless ( $existingtables{'issuingrules'} ) {
720 $dbh->do("alter table categoryitem rename issuingrules");
721 print "renaming categoryitem\n";
725 #---------------------------------
728 foreach $table ( keys %requirefields ) {
729 print "Check table $table\n" if $debug;
730 $sth = $dbh->prepare("show columns from $table");
733 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
735 $types{$column} = $type;
737 foreach $column ( keys %{ $requirefields{$table} } ) {
738 print " Check column $column [$types{$column}]\n" if $debug;
739 if ( !$types{$column} ) {
741 # column doesn't exist
742 print "Adding $column field to $table table...\n";
743 $query = "alter table $table
744 add column $column " . $requirefields{$table}->{$column};
745 print "Execute: $query\n" if $debug;
746 my $sti = $dbh->prepare($query);
749 print "**Error : $sti->errstr \n";
756 foreach $table ( keys %fielddefinitions ) {
757 print "Check table $table\n" if $debug;
758 $sth = $dbh->prepare("show columns from $table");
761 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
763 $definitions->{$column}->{type} = $type;
764 $definitions->{$column}->{null} = $null;
765 $definitions->{$column}->{key} = $key;
766 $definitions->{$column}->{default} = $default;
767 $definitions->{$column}->{extra} = $extra;
769 my $fieldrow = $fielddefinitions{$table};
770 foreach my $row (@$fieldrow) {
771 my $field = $row->{field};
772 my $type = $row->{type};
773 my $null = $row->{null};
774 my $key = $row->{key};
775 my $default = $row->{default};
776 $default="''" unless $default;
777 my $extra = $row->{extra};
778 my $def = $definitions->{$field};
779 unless ( $type eq $def->{type}
780 && $null eq $def->{null}
781 && $key eq $def->{key}
782 && $default eq $def->{default}
783 && $extra eq $def->{extra} )
789 if ( $key eq 'PRI' ) {
790 $key = 'PRIMARY KEY';
792 unless ( $extra eq 'auto_increment' ) {
795 # if it's a new column use "add", if it's an old one, use "change".
797 if ($definitions->{$field}->{type}) {
798 $action="change $field"
802 # if it's a primary key, drop the previous pk, before altering the table
804 if ($key ne 'PRIMARY KEY') {
805 $sth =$dbh->prepare("alter table $table $action $field $type $null $key $extra default ?");
807 $sth =$dbh->prepare("alter table $table drop primary key, $action $field $type $null $key $extra default ?");
809 $sth->execute($default);
810 print " Alter $field in $table\n";
815 # Get list of columns from borrowers table
818 $sth = $dbh->prepare("show columns from borrowers");
820 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
822 $itemtypes{$column} = $type;
823 $nullenabled{$column} = $null;
826 unless ( $itemtypes{'cardnumber'} eq 'varchar(20)' ) {
827 $itemtypes{'cardnumber'} =~ /varchar\((\d+)\)/;
829 if ( $oldlength < 16 ) {
830 print "Setting maximum cardnumber length to 16 (was $oldlength) and marking unique.\n";
833 "alter table borrowers change cardnumber cardnumber varchar(16)");
838 "alter table borrowers drop index cardnumber");
843 "alter table borrowers add unique(cardnumber)");
849 # Get list of columns from items table
850 $sth = $dbh->prepare("show columns from items");
852 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
854 $itemtypes{$column} = $type;
855 $nullenabled{$column} = $null;
858 unless ( $itemtypes{'barcode'} eq 'varchar(20)' ) {
859 $itemtypes{'barcode'} =~ /varchar\((\d+)\)/;
861 if ( $oldlength < 20 ) {
862 print "Setting maximum barcode length to 20 (was $oldlength).\n";
865 "alter table items change barcode barcode varchar(20)");
870 # dropping unique barcode index & setting barcode to null allowed.
872 $sth = $dbh->prepare("show index from items");
874 while ( my ( $table, $non_unique, $key_name, $Seq_in_index, $Column_name, $Collation, $cardinality, $sub_part, $Packed, $comment ) = $sth->fetchrow )
876 if ($key_name eq 'barcode' && $non_unique eq 0) {
877 print "dropping BARCODE index to enable empty barcodes\n";
878 $dbh->do("ALTER TABLE `items` DROP INDEX `barcode`");
881 $dbh->do("ALTER TABLE `items` CHANGE `barcode` `barcode` VARCHAR( 20 )") unless ($nullenabled{barcode} eq 'YES');
884 # creating fulltext index in bibliothesaurus if needed
886 $sth = $dbh->prepare("show index from bibliothesaurus");
889 while ( my ( $table, $non_unique, $key_name, $Seq_in_index, $Column_name, $Collation, $cardinality, $sub_part, $Packed, $comment ) = $sth->fetchrow )
891 if ($key_name eq 'category_2') {
895 print "Creating fulltext index on bibliothesaurus\n" unless $exists;
896 $dbh->do('create fulltext index category_2 on bibliothesaurus (category,freelib)') unless $exists;
899 # creating index in z3950results if needed
901 $sth = $dbh->prepare("show index from z3950results");
904 while ( my ( $table, $non_unique, $key_name, $Seq_in_index, $Column_name, $Collation, $cardinality, $sub_part, $Packed, $comment ) = $sth->fetchrow )
906 if ($key_name eq 'query_server') {
910 print "Creating index on z3950results\n" unless $exists;
911 $dbh->do('create unique index query_server on z3950results (queryid,server)') unless $exists;
913 # changing z3950daemon field to NULL in marc_breeding
914 $dbh->do("ALTER TABLE `marc_breeding` CHANGE `z3950random` `z3950random` VARCHAR( 40 )");
916 # making borrowernumber an auto_increment field
917 $dbh->do("ALTER TABLE `borrowers` CHANGE `borrowernumber` `borrowernumber` INTEGER auto_increment");
919 # extending the timestamp in branchtransfers...
922 $sth = $dbh->prepare("show columns from branchtransfers");
924 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
926 $branchtransfers{$column} = $type;
929 unless ( $branchtransfers{'datesent'} eq 'datetime' ) {
930 print "Setting type of datesent in branchtransfers to datetime.\n";
933 "alter table branchtransfers change datesent datesent datetime");
937 unless ( $branchtransfers{'datearrived'} eq 'datetime' ) {
938 print "Setting type of datearrived in branchtransfers to datetime.\n";
941 "alter table branchtransfers change datearrived datearrived datetime");
945 # changing the branchcategories table around...
946 my %branchcategories;
948 $sth = $dbh->prepare("show columns from branchcategories");
950 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
952 $branchcategories{$column} = $type;
955 unless ( $branchcategories{'categorycode'} eq 'varchar(4)' ) {
957 "Setting type of categorycode in branchcategories to varchar(4),\n and making the primary key.\n";
960 "alter table branchcategories change categorycode categorycode varchar(4) not null"
965 "alter table branchcategories add primary key (categorycode)");
969 unless ( $branchcategories{'categoryname'} eq 'text' ) {
970 print "Changing branchcode in branchcategories to categoryname text.\n";
973 "alter table branchcategories change branchcode categoryname text");
977 unless ( $branchcategories{'codedescription'} eq 'text' ) {
979 "Replacing branchholding in branchcategories with codedescription text.\n";
982 "alter table branchcategories change branchholding codedescription text"
987 # changing the items table around...
990 $sth = $dbh->prepare("show columns from items");
992 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
994 $items{$column} = $type;
997 if ($items{'bulk'} eq "varchar(30)") {
998 print " Setting callnumber in items table\n";
1000 $dbh->prepare("ALTER TABLE `items` CHANGE `bulk` `itemcallnumber` VARCHAR( 30 ) DEFAULT NULL");
1002 $sti = $dbh->prepare("update marc_subfield_structure set kohafield=\"items.itemcallnumber\" where kohafield=\"items.bulk\"");
1007 # creating index in issuingrules if needed
1009 $sth = $dbh->prepare("show index from issuingrules");
1012 while ( my ( $table, $non_unique, $key_name, $Seq_in_index, $Column_name, $Collation, $cardinality, $sub_part, $Packed, $comment ) = $sth->fetchrow )
1014 if ($key_name eq 'PRIMARY') {
1018 print "Creating index on z3950results\n" unless $exists;
1019 $dbh->do('ALTER TABLE issuingrules ADD PRIMARY KEY ( branchcode, categorycode, itemtype )') unless $exists;
1021 $dbh->do('ALTER TABLE marc_tag_structure drop primary key');
1022 $dbh->do('ALTER TABLE marc_tag_structure ADD PRIMARY KEY ( itemtype, tagfield )');
1024 $dbh->do('ALTER TABLE marc_subfield_structure drop primary key');
1025 $dbh->do('ALTER TABLE marc_subfield_structure ADD PRIMARY KEY ( itemtype, tagfield, tagsubfield )');
1027 # Populate tables with required data
1029 foreach my $table ( keys %tabledata ) {
1030 print "Checking for data required in table $table...\n";
1031 my $tablerows = $tabledata{$table};
1032 foreach my $row (@$tablerows) {
1033 my $uniquefieldrequired = $row->{uniquefieldrequired};
1034 my $uniquevalue = $row->{$uniquefieldrequired};
1035 my $forceupdate = $row->{forceupdate};
1038 "select $uniquefieldrequired from $table where $uniquefieldrequired=?"
1040 $sth->execute($uniquevalue);
1042 foreach my $field (keys %$forceupdate) {
1043 if ($forceupdate->{$field}) {
1044 my $sth=$dbh->prepare("update systempreferences set $field=? where $uniquefieldrequired=?");
1045 $sth->execute($row->{$field}, $uniquevalue);
1049 print "Adding row to $table: ";
1053 foreach my $field ( keys %$row ) {
1054 next if $field eq 'uniquefieldrequired';
1055 next if $field eq 'forceupdate';
1056 my $value = $row->{$field};
1057 push @values, $value;
1058 print " $field => $value";
1059 $fieldlist .= "$field,";
1060 $placeholders .= "?,";
1063 $fieldlist =~ s/,$//;
1064 $placeholders =~ s/,$//;
1067 "insert into $table ($fieldlist) values ($placeholders)");
1068 $sth->execute(@values);
1078 # Revision 1.79 2004/05/18 09:50:07 tipaul
1079 # *** empty log message ***
1081 # Revision 1.78 2004/05/10 09:29:33 tipaul
1082 # css is now the default theme for OPAC.
1083 # It will be the theme used for improvements and new things in OPAC.
1085 # Revision 1.77 2004/05/06 14:56:51 tipaul
1086 # adding table issuingrules (previously called categoryitem
1088 # Revision 1.76 2004/05/03 09:32:25 tipaul
1089 # adding printcirculationsplit parameter (already existed, but was not in systempref by defaul)
1091 # Revision 1.75 2004/04/14 19:49:00 tipaul
1092 # seealso field set to 255 chars
1094 # Revision 1.74 2004/03/11 16:10:16 tipaul
1095 # *** empty log message ***
1097 # Revision 1.73 2004/03/06 20:26:13 tipaul
1098 # adding seealso feature in MARC searches