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 use MARC::File::XML ( BinaryEncoding => 'utf8' );
26 # FIXME - The user might be installing a new database, so can't rely
27 # on /etc/koha.conf anyway.
34 %existingtables, # tables already in database
38 $type, $null, $key, $default, $extra,
39 $prefitem, # preference item in systempreferences table
46 my $dbh = C4::Context->dbh;
47 print "connected to your DB. Checking & modifying it\n" unless $silent;
48 $|=1; # flushes output
53 # Tables to add if they don't exist
55 categorytable => "(categorycode char(5) NOT NULL default '',
56 description text default '',
57 itemtypecodes text default '',
58 PRIMARY KEY (categorycode)
60 subcategorytable => "(subcategorycode char(5) NOT NULL default '',
61 description text default '',
62 itemtypecodes text default '',
63 PRIMARY KEY (subcategorycode)
65 mediatypetable => "(mediatypecode char(5) NOT NULL default '',
66 description text default '',
67 itemtypecodes text default '',
68 PRIMARY KEY (mediatypecode)
71 `timestamp` TIMESTAMP NOT NULL ,
72 `user` INT( 11 ) NOT NULL ,
73 `module` TEXT default '',
74 `action` TEXT default '' ,
75 `object` INT(11) default '' ,
76 `info` TEXT default '' ,
77 PRIMARY KEY ( `timestamp` , `user` )
80 module varchar(20) NOT NULL default '',
81 code varchar(20) NOT NULL default '',
82 name varchar(100) NOT NULL default '',
83 title varchar(200) NOT NULL default '',
85 PRIMARY KEY (module,code)
88 alertid int(11) NOT NULL auto_increment,
89 borrowernumber int(11) NOT NULL default '0',
90 type varchar(10) NOT NULL default '',
91 externalid varchar(20) NOT NULL default '',
92 PRIMARY KEY (alertid),
93 KEY borrowernumber (borrowernumber),
94 KEY type (type,externalid)
97 `idnew` int(10) unsigned NOT NULL auto_increment,
98 `title` varchar(250) NOT NULL default '',
100 `lang` varchar(4) NOT NULL default '',
101 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
102 PRIMARY KEY (`idnew`)
104 repeatable_holidays => "(
105 `id` int(11) NOT NULL auto_increment,
106 `branchcode` varchar(4) NOT NULL default '',
107 `weekday` smallint(6) default NULL,
108 `day` smallint(6) default NULL,
109 `month` smallint(6) default NULL,
110 `title` varchar(50) NOT NULL default '',
111 `description` text NOT NULL,
114 special_holidays => "(
115 `id` int(11) NOT NULL auto_increment,
116 `branchcode` varchar(4) NOT NULL default '',
117 `day` smallint(6) NOT NULL default '0',
118 `month` smallint(6) NOT NULL default '0',
119 `year` smallint(6) NOT NULL default '0',
120 `isexception` smallint(1) NOT NULL default '1',
121 `title` varchar(50) NOT NULL default '',
122 `description` text NOT NULL,
125 overduerules =>"(`branchcode` varchar(255) NOT NULL default '',
126 `categorycode` char(2) NOT NULL default '',
127 `delay1` int(4) default '0',
128 `letter1` varchar(20) default NULL,
129 `debarred1` char(1) default '0',
130 `delay2` int(4) default '0',
131 `debarred2` char(1) default '0',
132 `letter2` varchar(20) default NULL,
133 `delay3` int(4) default '0',
134 `letter3` varchar(20) default NULL,
135 `debarred3` int(1) default '0',
136 PRIMARY KEY (`branchcode`,`categorycode`)
138 cities => "(`cityid` int auto_increment,
139 `city_name` char(100) NOT NULL,
140 `city_zipcode` char(20),
141 PRIMARY KEY (`cityid`)
143 roadtype => "(`roadtypeid` int auto_increment,
144 `road_type` char(100) NOT NULL,
145 PRIMARY KEY (`roadtypeid`)
149 labelid int(11) NOT NULL auto_increment,
150 itemnumber varchar(100) NOT NULL default '',
151 timestamp timestamp(14) NOT NULL,
152 PRIMARY KEY (labelid)
156 id int(4) NOT NULL auto_increment,
157 barcodetype char(100) default '',
158 title tinyint(1) default '0',
159 isbn tinyint(1) default '0',
160 itemtype tinyint(1) default '0',
161 barcode tinyint(1) default '0',
162 dewey tinyint(1) default '0',
163 class tinyint(1) default '0',
164 author tinyint(1) default '0',
165 papertype char(100) default '',
166 startrow int(2) default NULL,
170 reviewid integer NOT NULL auto_increment,
171 borrowernumber integer,
172 biblionumber integer,
175 datereviewed datetime,
176 PRIMARY KEY (reviewid)
178 borrowers_to_borrowers => "(
185 my %requirefields = (
186 subscription => { 'letter' => 'char(20) NULL', 'distributedto' => 'text NULL'},
187 itemtypes => { 'imageurl' => 'char(200) NULL'},
188 aqbookfund => { 'branchcode' => 'varchar(4) NULL'},
189 aqbudget => { 'branchcode' => 'varchar(4) NULL'},
190 auth_header => { 'marc' => 'BLOB NOT NULL', 'linkid' => 'BIGINT(20) NULL'},
191 auth_subfield_structure =>{ 'hidden' => 'TINYINT(3) NOT NULL UNSIGNED ZEROFILL', 'kohafield' => 'VARCHAR(45) NOT NULL', 'linkid' => 'TINYINT(1) NOT NULL UNSIGNED', 'isurl' => 'TINYINT(1) UNSIGNED'},
192 statistics => { 'associatedborrower' => 'integer'},
193 # tablename => { 'field' => 'fieldtype' },
196 my %dropable_table = (
197 sessionqueries => 'sessionqueries',
198 marcrecorddone => 'marcrecorddone',
200 itemsprices => 'itemsprices',
201 biblioanalysis => 'biblioanalysis',
203 # tablename => 'tablename',
206 my %uselessfields = (
207 # tablename => "field1,field2",
208 borrowers => "suburb,altstreetaddress,altsuburb,altcity,studentnumber,school,area,preferredcont,altcp",
209 deletedborrowers=> "suburb,altstreetaddress,altsuburb,altcity,studentnumber,school,area,preferredcont,altcp",
211 # the other hash contains other actions that can't be done elsewhere. they are done
212 # either BEFORE of AFTER everything else, depending on "when" entry (default => AFTER)
214 # The tabledata hash contains data that should be in the tables.
215 # The uniquefieldrequired hash entry is used to determine which (if any) fields
216 # must not exist in the table for this row to be inserted. If the
217 # uniquefieldrequired entry is already in the table, the existing data is not
218 # modified, unless the forceupdate hash entry is also set. Fields in the
219 # anonymous "forceupdate" hash will be forced to be updated to the default
220 # values given in the %tabledata hash.
224 # { uniquefielrequired => 'fieldname', # the primary key in the table
225 # fieldname => fieldvalue,
226 # fieldname2 => fieldvalue2,
229 systempreferences => [
231 uniquefieldrequired => 'variable',
232 variable => 'Activate_Log',
234 forceupdate => { 'explanation' => 1,
236 explanation => 'Turn Log Actions on DB On an Off',
240 uniquefieldrequired => 'variable',
241 variable => 'IndependantBranches',
243 forceupdate => { 'explanation' => 1,
245 explanation => 'Turn Branch independancy management On an Off',
249 uniquefieldrequired => 'variable',
250 variable => 'ReturnBeforeExpiry',
252 forceupdate => { 'explanation' => 1,
254 explanation => 'If Yes, Returndate on issuing can\'t be after borrower card expiry',
258 uniquefieldrequired => 'variable',
259 variable => 'opacstylesheet',
261 forceupdate => { 'explanation' => 1,
263 explanation => 'Enter a complete URL to use an alternate stylesheet in OPAC',
267 uniquefieldrequired => 'variable',
268 variable => 'opacsmallimage',
270 forceupdate => { 'explanation' => 1,
272 explanation => 'Enter a complete URL to an image, will be on top/left instead of the Koha logo',
276 uniquefieldrequired => 'variable',
277 variable => 'opaclargeimage',
279 forceupdate => { 'explanation' => 1,
281 explanation => 'Enter a complete URL to an image, will be on the main page, instead of the Koha logo',
285 uniquefieldrequired => 'variable',
286 variable => 'delimiter',
288 forceupdate => { 'explanation' => 1,
290 explanation => 'separator for reports exported to spreadsheet',
294 uniquefieldrequired => 'variable',
296 value => 'OPENOFFICE.ORG',
297 forceupdate => { 'explanation' => 1,
300 explanation => 'Define the default application for report exportations into files',
302 options => 'EXCEL|OPENOFFICE.ORG'
305 uniquefieldrequired => 'variable',
306 variable => 'Delimiter',
308 forceupdate => { 'explanation' => 1,
311 explanation => 'Define the default separator character for report exportations into files',
313 options => ';|tabulation|,|/|\|#'
316 uniquefieldrequired => 'variable',
317 variable => 'SubscriptionHistory',
319 forceupdate => { 'explanation' => 1,
322 explanation => 'Define the information level for serials history in OPAC',
324 options => 'simplified|full'
327 uniquefieldrequired => 'variable',
328 variable => 'hidelostitems',
330 forceupdate => { 'explanation' => 1,
332 explanation => 'show or hide "lost" items in OPAC.',
336 uniquefieldrequired => 'variable',
337 variable => 'IndependantBranches',
339 forceupdate => { 'explanation' => 1,
341 explanation => 'Turn Branch independancy management On an Off',
345 uniquefieldrequired => 'variable',
346 variable => 'ReturnBeforeExpiry',
348 forceupdate => { 'explanation' => 1,
350 explanation => 'If Yes, Returndate on issuing can\'t be after borrower card expiry',
354 uniquefieldrequired => 'variable',
355 variable => 'Disable_Dictionary',
357 forceupdate => { 'explanation' => 1,
359 explanation => 'Disables Dictionary buttons if set to yes',
363 uniquefieldrequired => 'variable',
364 variable => 'hide_marc',
366 forceupdate => { 'explanation' => 1,
368 explanation => 'hide marc specific datas like subfield code & indicators to library',
372 uniquefieldrequired => 'variable',
373 variable => 'NotifyBorrowerDeparture',
375 forceupdate => { 'explanation' => 1,
377 explanation => 'Delay before expiry where a notice is sent when issuing',
381 uniquefieldrequired => 'variable',
382 variable => 'OpacPasswordChange',
384 forceupdate => { 'explanation' => 1,
386 explanation => 'Enable/Disable password change in OPAC (disable it when using LDAP auth)',
390 uniquefieldrequired => 'variable',
391 variable => 'useDaysMode',
393 forceupdate => { 'explanation' => 1,
395 explanation => 'How to calculate return dates : Calendar means holidays will be controled, Days means the return date don\'t depend on holidays',
397 options => 'Calendar|Days'
400 uniquefieldrequired => 'variable',
401 variable => 'borrowerMandatoryField',
402 value => 'zipcode|surname',
403 forceupdate => { 'explanation' => 1,
405 explanation => 'List all mandatory fields for borrowers',
409 uniquefieldrequired => 'variable',
410 variable => 'borrowerRelationship',
411 value => 'father|mother,grand-mother',
412 forceupdate => { 'explanation' => 1,
414 explanation => 'The relationships between a guarantor & a guarantee (separated by | or ,)',
418 uniquefieldrequired => 'variable',
419 variable => 'ReservesMaxPickUpDelay',
421 forceupdate => { 'explanation' => 1,
423 explanation => 'Maximum delay to pick up a reserved document',
427 uniquefieldrequired => 'variable',
428 variable => 'TransfersMaxDaysWarning',
430 forceupdate => { 'explanation' => 1,
432 explanation => 'Max delay before considering the transfer has potentialy a problem',
436 uniquefieldrequired => 'variable',
437 variable => 'memberofinstitution',
439 forceupdate => { 'explanation' => 1,
441 explanation => 'Are your patrons members of institutions',
445 uniquefieldrequired => 'variable',
446 variable => 'ReadingHistory',
448 forceupdate => { 'explanation' => 1,
450 explanation => 'Allow reading record info retrievable from issues and oldissues tables',
454 uniquefieldrequired => 'variable',
455 variable => 'IssuingInProcess',
457 forceupdate => { 'explanation' => 1,
459 explanation => 'Allow no debt alert if the patron is issuing item that accumulate debt',
463 uniquefieldrequired => 'variable',
464 variable => 'AutomaticItemReturn',
466 forceupdate => { 'explanation' => 1,
468 explanation => 'This Variable allow or not to return automaticly to his homebranch',
472 uniquefieldrequired => 'variable',
473 variable => 'reviewson',
475 forceupdate => { 'explanation' => 1,
477 explanation => 'Allows patrons to submit reviews from the opac',
484 my %fielddefinitions = (
486 # { field => 'fieldname',
487 # type => 'fieldtype',
505 field => 'booksellerid',
515 field => 'listprice',
516 type => 'varchar(10)',
523 field => 'invoiceprice',
524 type => 'varchar(10)',
533 field => 'borrowernumber',
535 null => 'NULL', # can be null when a borrower is deleted and the foreign key rule executed
541 field => 'itemnumber',
543 null => 'NULL', # can be null when a borrower is deleted and the foreign key rule executed
550 { field => 'firstname',
554 { field => 'B_email',
557 after => 'B_zipcode',
560 field => 'streetnumber', # street number (hidden if streettable table is empty)
566 field => 'streettype', # street table, list builded from a system table
569 after => 'streetnumber',
572 field => 'B_streetnumber', # street number (hidden if streettable table is empty)
578 field => 'B_streettype', # street table, list builded from a system table
581 after => 'B_streetnumber',
590 field => 'address2', # complement address
602 field => 'contactfirstname', # contact's firstname
605 after => 'contactname',
608 field => 'contacttitle', # contact's title
611 after => 'contactfirstname',
615 deletedborrowers => [
616 { field => 'firstname',
620 { field => 'B_email',
623 after => 'B_zipcode',
626 field => 'streetnumber', # street number (hidden if streettable table is empty)
632 field => 'streettype', # street table, list builded from a system table
635 after => 'streetnumber',
638 field => 'B_streetnumber', # street number (hidden if streettable table is empty)
644 field => 'B_streettype', # street table, list builded from a system table
647 after => 'B_streetnumber',
656 field => 'address2', # complement address
668 field => 'contactfirstname', # contact's firstname
671 after => 'contactname',
674 field => 'contacttitle', # contact's title
677 after => 'contactfirstname',
684 type => 'varchar(15)',
691 field => 'branchprinter',
692 type => 'varchar(100)',
701 field => 'category_type',
711 field => 'waitingdate',
723 # { indexname => 'index detail'
727 { indexname => 'shelfnumber',
728 content => 'shelfnumber',
730 { indexname => 'itemnumber',
731 content => 'itemnumber',
735 { indexname => 'biblionumber',
736 content => 'biblionumber',
740 { indexname => 'homebranch',
741 content => 'homebranch',
743 { indexname => 'holdingbranch',
744 content => 'holdingbranch',
748 { indexname => 'PRIMARY',
754 { indexname => 'booksellerid',
755 content => 'booksellerid',
759 { indexname => 'basketno',
760 content => 'basketno',
763 aqorderbreakdown => [
764 { indexname => 'ordernumber',
765 content => 'ordernumber',
767 { indexname => 'bookfundid',
768 content => 'bookfundid',
772 { indexname => 'PRIMARY',
773 content => 'currency',
781 # { key => 'the key in table' (must be indexed)
782 # foreigntable => 'the foreigntable name', # (the parent)
783 # foreignkey => 'the foreign key column(s)' # (in the parent)
784 # onUpdate => 'CASCADE|SET NULL|NO ACTION| RESTRICT',
785 # onDelete => 'CASCADE|SET NULL|NO ACTION| RESTRICT',
789 { key => 'shelfnumber',
790 foreigntable => 'bookshelf',
791 foreignkey => 'shelfnumber',
792 onUpdate => 'CASCADE',
793 onDelete => 'CASCADE',
795 { key => 'itemnumber',
796 foreigntable => 'items',
797 foreignkey => 'itemnumber',
798 onUpdate => 'CASCADE',
799 onDelete => 'CASCADE',
802 # onDelete is RESTRICT on reference tables (branches, itemtype) as we don't want items to be
803 # easily deleted, but branches/itemtype not too easy to empty...
805 { key => 'biblionumber',
806 foreigntable => 'biblio',
807 foreignkey => 'biblionumber',
808 onUpdate => 'CASCADE',
809 onDelete => 'CASCADE',
812 foreigntable => 'itemtypes',
813 foreignkey => 'itemtype',
814 onUpdate => 'CASCADE',
815 onDelete => 'RESTRICT',
819 { key => 'biblioitemnumber',
820 foreigntable => 'biblioitems',
821 foreignkey => 'biblioitemnumber',
822 onUpdate => 'CASCADE',
823 onDelete => 'CASCADE',
825 { key => 'homebranch',
826 foreigntable => 'branches',
827 foreignkey => 'branchcode',
828 onUpdate => 'CASCADE',
829 onDelete => 'RESTRICT',
831 { key => 'holdingbranch',
832 foreigntable => 'branches',
833 foreignkey => 'branchcode',
834 onUpdate => 'CASCADE',
835 onDelete => 'RESTRICT',
838 additionalauthors => [
839 { key => 'biblionumber',
840 foreigntable => 'biblio',
841 foreignkey => 'biblionumber',
842 onUpdate => 'CASCADE',
843 onDelete => 'CASCADE',
847 { key => 'biblionumber',
848 foreigntable => 'biblio',
849 foreignkey => 'biblionumber',
850 onUpdate => 'CASCADE',
851 onDelete => 'CASCADE',
855 { key => 'booksellerid',
856 foreigntable => 'aqbooksellers',
858 onUpdate => 'CASCADE',
859 onDelete => 'RESTRICT',
864 foreigntable => 'aqbasket',
865 foreignkey => 'basketno',
866 onUpdate => 'CASCADE',
867 onDelete => 'CASCADE',
869 { key => 'biblionumber',
870 foreigntable => 'biblio',
871 foreignkey => 'biblionumber',
872 onUpdate => 'SET NULL',
873 onDelete => 'SET NULL',
877 { key => 'listprice',
878 foreigntable => 'currency',
879 foreignkey => 'currency',
880 onUpdate => 'CASCADE',
881 onDelete => 'CASCADE',
883 { key => 'invoiceprice',
884 foreigntable => 'currency',
885 foreignkey => 'currency',
886 onUpdate => 'CASCADE',
887 onDelete => 'CASCADE',
890 aqorderbreakdown => [
891 { key => 'ordernumber',
892 foreigntable => 'aqorders',
893 foreignkey => 'ordernumber',
894 onUpdate => 'CASCADE',
895 onDelete => 'CASCADE',
897 { key => 'bookfundid',
898 foreigntable => 'aqbookfund',
899 foreignkey => 'bookfundid',
900 onUpdate => 'CASCADE',
901 onDelete => 'CASCADE',
905 { key => 'frombranch',
906 foreigntable => 'branches',
907 foreignkey => 'branchcode',
908 onUpdate => 'CASCADE',
909 onDelete => 'CASCADE',
912 foreigntable => 'branches',
913 foreignkey => 'branchcode',
914 onUpdate => 'CASCADE',
915 onDelete => 'CASCADE',
917 { key => 'itemnumber',
918 foreigntable => 'items',
919 foreignkey => 'itemnumber',
920 onUpdate => 'CASCADE',
921 onDelete => 'CASCADE',
925 { key => 'categorycode',
926 foreigntable => 'categories',
927 foreignkey => 'categorycode',
928 onUpdate => 'CASCADE',
929 onDelete => 'CASCADE',
932 foreigntable => 'itemtypes',
933 foreignkey => 'itemtype',
934 onUpdate => 'CASCADE',
935 onDelete => 'CASCADE',
938 issues => [ # constraint is SET NULL : when a borrower or an item is deleted, we keep the issuing record
940 { key => 'borrowernumber',
941 foreigntable => 'borrowers',
942 foreignkey => 'borrowernumber',
943 onUpdate => 'SET NULL',
944 onDelete => 'SET NULL',
946 { key => 'itemnumber',
947 foreigntable => 'items',
948 foreignkey => 'itemnumber',
949 onUpdate => 'SET NULL',
950 onDelete => 'SET NULL',
954 { key => 'borrowernumber',
955 foreigntable => 'borrowers',
956 foreignkey => 'borrowernumber',
957 onUpdate => 'CASCADE',
958 onDelete => 'CASCADE',
960 { key => 'biblionumber',
961 foreigntable => 'biblio',
962 foreignkey => 'biblionumber',
963 onUpdate => 'CASCADE',
964 onDelete => 'CASCADE',
966 { key => 'itemnumber',
967 foreigntable => 'items',
968 foreignkey => 'itemnumber',
969 onUpdate => 'CASCADE',
970 onDelete => 'CASCADE',
972 { key => 'branchcode',
973 foreigntable => 'branches',
974 foreignkey => 'branchcode',
975 onUpdate => 'CASCADE',
976 onDelete => 'CASCADE',
979 borrowers => [ # foreign keys are RESTRICT as we don't want to delete borrowers when a branch is deleted
980 # but prevent deleting a branch as soon as it has 1 borrower !
981 { key => 'categorycode',
982 foreigntable => 'categories',
983 foreignkey => 'categorycode',
984 onUpdate => 'RESTRICT',
985 onDelete => 'RESTRICT',
987 { key => 'branchcode',
988 foreigntable => 'branches',
989 foreignkey => 'branchcode',
990 onUpdate => 'RESTRICT',
991 onDelete => 'RESTRICT',
994 deletedborrowers => [ # foreign keys are RESTRICT as we don't want to delete borrowers when a branch is deleted
995 # but prevent deleting a branch as soon as it has 1 borrower !
996 { key => 'categorycode',
997 foreigntable => 'categories',
998 foreignkey => 'categorycode',
999 onUpdate => 'RESTRICT',
1000 onDelete => 'RESTRICT',
1002 { key => 'branchcode',
1003 foreigntable => 'branches',
1004 foreignkey => 'branchcode',
1005 onUpdate => 'RESTRICT',
1006 onDelete => 'RESTRICT',
1010 { key => 'borrowernumber',
1011 foreigntable => 'borrowers',
1012 foreignkey => 'borrowernumber',
1013 onUpdate => 'CASCADE',
1014 onDelete => 'CASCADE',
1016 { key => 'itemnumber',
1017 foreigntable => 'items',
1018 foreignkey => 'itemnumber',
1019 onUpdate => 'SET NULL',
1020 onDelete => 'SET NULL',
1023 auth_tag_structure => [
1024 { key => 'authtypecode',
1025 foreigntable => 'auth_types',
1026 foreignkey => 'authtypecode',
1027 onUpdate => 'CASCADE',
1028 onDelete => 'CASCADE',
1031 # FIXME : don't constraint auth_*_table and auth_word, as they may be replaced by zebra
1036 my %column_change = (
1040 from => 'emailaddress',
1045 from => 'streetaddress',
1047 after => 'initials',
1050 from => 'faxnumber',
1055 from => 'textmessaging',
1061 to => 'contactnote',
1062 after => 'opacnote',
1065 from => 'physstreet',
1070 from => 'streetcity',
1072 after => 'B_address',
1085 from => 'homezipcode',
1092 after => 'B_zipcode',
1097 after => 'dateenrolled',
1100 from => 'guarantor',
1101 to => 'guarantorid',
1102 after => 'contactname',
1105 from => 'textmessaging',
1111 to => 'contactnotes',
1112 after => 'opacnotes',
1115 from => 'altrelationship',
1116 to => 'relationship',
1117 after => 'borrowernotes',
1121 deletedborrowers => [
1123 from => 'emailaddress',
1128 from => 'streetaddress',
1130 after => 'initials',
1133 from => 'faxnumber',
1138 from => 'textmessaging',
1144 to => 'contactnote',
1145 after => 'opacnote',
1148 from => 'physstreet',
1153 from => 'streetcity',
1155 after => 'B_address',
1168 from => 'homezipcode',
1175 after => 'B_zipcode',
1180 after => 'dateenrolled',
1183 from => 'guarantor',
1184 to => 'guarantorid',
1185 after => 'contactname',
1188 from => 'textmessaging',
1194 to => 'contactnotes',
1195 after => 'opacnotes',
1198 from => 'altrelationship',
1199 to => 'relationship',
1200 after => 'borrowernotes',
1206 foreach my $table (keys %column_change) {
1207 $sth = $dbh->prepare("show columns from $table");
1210 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1212 $types{$column}->{type} ="$type";
1213 $types{$column}->{null} = "$null";
1214 $types{$column}->{key} = "$key";
1215 $types{$column}->{default} = "$default";
1216 $types{$column}->{extra} = "$extra";
1218 my $tablerows = $column_change{$table};
1219 foreach my $row ( @$tablerows ) {
1220 if ($types{$row->{from}}->{type}) {
1221 print "altering $table $row->{from} to $row->{to}\n";
1222 # ALTER TABLE `borrowers` CHANGE `faxnumber` `fax` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
1223 # alter table `borrowers` change `faxnumber` `fax` type text null after phone
1225 "alter table `$table` change `$row->{from}` `$row->{to}` $types{$row->{from}}->{type} ".
1226 ($types{$row->{from}}->{null} eq 'YES'?" NULL":" NOT NULL").
1227 ($types{$row->{from}}->{default}?" default ".$types{$row->{from}}->{default}:"").
1228 "$types{$row->{from}}->{extra} after $row->{after} ";
1235 #-------------------
1240 # Get version of MySQL database engine.
1241 my $mysqlversion = `mysqld --version`;
1242 $mysqlversion =~ /Ver (\S*) /;
1244 if ( $mysqlversion ge '3.23' ) {
1245 print "Could convert to MyISAM database tables...\n" unless $silent;
1248 #---------------------------------
1251 # Collect all tables into a list
1252 $sth = $dbh->prepare("show tables");
1254 while ( my ($table) = $sth->fetchrow ) {
1255 $existingtables{$table} = 1;
1259 # Now add any missing tables
1260 foreach $table ( keys %requiretables ) {
1261 unless ( $existingtables{$table} ) {
1262 print "Adding $table table...\n" unless $silent;
1263 my $sth = $dbh->prepare("create table $table $requiretables{$table}");
1266 print "Error : $sth->errstr \n";
1272 # now drop useless tables
1273 foreach $table ( keys %dropable_table ) {
1274 if ( $existingtables{$table} ) {
1275 print "Dropping unused table $table\n" if $debug and not $silent;
1276 $dbh->do("drop table $table");
1278 print "Error : $dbh->errstr \n";
1283 #---------------------------------
1286 foreach $table ( keys %requirefields ) {
1287 print "Check table $table\n" if $debug and not $silent;
1288 $sth = $dbh->prepare("show columns from $table");
1291 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1293 $types{$column} = $type;
1295 foreach $column ( keys %{ $requirefields{$table} } ) {
1296 print " Check column $column [$types{$column}]\n" if $debug and not $silent;
1297 if ( !$types{$column} ) {
1299 # column doesn't exist
1300 print "Adding $column field to $table table...\n" unless $silent;
1301 $query = "alter table $table
1302 add column $column " . $requirefields{$table}->{$column};
1303 print "Execute: $query\n" if $debug;
1304 my $sti = $dbh->prepare($query);
1307 print "**Error : $sti->errstr \n";
1314 foreach $table ( keys %fielddefinitions ) {
1315 print "Check table $table\n" if $debug;
1316 $sth = $dbh->prepare("show columns from $table");
1319 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1321 $definitions->{$column}->{type} = $type;
1322 $definitions->{$column}->{null} = $null;
1323 $definitions->{$column}->{null} = 'NULL' if $null eq 'YES';
1324 $definitions->{$column}->{key} = $key;
1325 $definitions->{$column}->{default} = $default;
1326 $definitions->{$column}->{extra} = $extra;
1328 my $fieldrow = $fielddefinitions{$table};
1329 foreach my $row (@$fieldrow) {
1330 my $field = $row->{field};
1331 my $type = $row->{type};
1332 my $null = $row->{null};
1333 # $null = 'YES' if $row->{null} eq 'NULL';
1334 my $key = $row->{key};
1335 my $default = $row->{default};
1336 my $null = $row->{null};
1337 # $default="''" unless $default;
1338 my $extra = $row->{extra};
1339 my $def = $definitions->{$field};
1340 my $after = ($row->{after}?" after ".$row->{after}:"");
1342 unless ( $type eq $def->{type}
1343 && $null eq $def->{null}
1344 && $key eq $def->{key}
1345 && $extra eq $def->{extra} )
1347 if ( $null eq '' ) {
1350 if ( $key eq 'PRI' ) {
1351 $key = 'PRIMARY KEY';
1353 unless ( $extra eq 'auto_increment' ) {
1357 # if it's a new column use "add", if it's an old one, use "change".
1359 if ($definitions->{$field}->{type}) {
1360 $action="change $field"
1364 # if it's a primary key, drop the previous pk, before altering the table
1366 if ($key ne 'PRIMARY KEY') {
1367 $sth =$dbh->prepare("alter table $table $action $field $type $null $key $extra default ? $after");
1369 $sth =$dbh->prepare("alter table $table drop primary key, $action $field $type $null $key $extra default ? $after");
1371 $sth->execute($default);
1372 print " alter or create $field in $table\n" unless $silent;
1377 # Populate tables with required data
1380 # synch table and deletedtable.
1381 foreach my $table (('borrowers','items','biblio','biblioitems')) {
1382 my %deletedborrowers;
1383 print "synch'ing $table\n";
1384 $sth = $dbh->prepare("show columns from deleted$table");
1386 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ) {
1387 $deletedborrowers{$column}=1;
1389 $sth = $dbh->prepare("show columns from $table");
1392 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ) {
1393 unless ($deletedborrowers{$column}) {
1394 my $newcol="alter table deleted$table add $column $type";
1395 if ($null eq 'YES') {
1396 $newcol .= " NULL ";
1398 $newcol .= " NOT NULL ";
1400 $newcol .= "default $default" if $default;
1401 $newcol .= " after $previous" if $previous;
1403 print "creating column $column\n";
1409 foreach my $table ( keys %tabledata ) {
1410 print "Checking for data required in table $table...\n" unless $silent;
1411 my $tablerows = $tabledata{$table};
1412 foreach my $row (@$tablerows) {
1413 my $uniquefieldrequired = $row->{uniquefieldrequired};
1414 my $uniquevalue = $row->{$uniquefieldrequired};
1415 my $forceupdate = $row->{forceupdate};
1418 "select $uniquefieldrequired from $table where $uniquefieldrequired=?"
1420 $sth->execute($uniquevalue);
1422 foreach my $field (keys %$forceupdate) {
1423 if ($forceupdate->{$field}) {
1424 my $sth=$dbh->prepare("update systempreferences set $field=? where $uniquefieldrequired=?");
1425 $sth->execute($row->{$field}, $uniquevalue);
1429 print "Adding row to $table: " unless $silent;
1433 foreach my $field ( keys %$row ) {
1434 next if $field eq 'uniquefieldrequired';
1435 next if $field eq 'forceupdate';
1436 my $value = $row->{$field};
1437 push @values, $value;
1438 print " $field => $value" unless $silent;
1439 $fieldlist .= "$field,";
1440 $placeholders .= "?,";
1442 print "\n" unless $silent;
1443 $fieldlist =~ s/,$//;
1444 $placeholders =~ s/,$//;
1447 "insert into $table ($fieldlist) values ($placeholders)");
1448 $sth->execute(@values);
1454 # check indexes and create them when needed
1456 print "Checking for index required...\n" unless $silent;
1457 foreach my $table ( keys %indexes ) {
1459 # read all indexes from $table
1461 $sth = $dbh->prepare("show index from $table");
1463 my %existingindexes;
1464 while ( my ( $table, $non_unique, $key_name, $Seq_in_index, $Column_name, $Collation, $cardinality, $sub_part, $Packed, $comment ) = $sth->fetchrow ) {
1465 $existingindexes{$key_name} = 1;
1467 # read indexes to check
1468 my $tablerows = $indexes{$table};
1469 foreach my $row (@$tablerows) {
1470 my $key_name=$row->{indexname};
1471 if ($existingindexes{$key_name} eq 1) {
1472 # print "$key_name existing";
1474 print "\tCreating index $key_name in $table\n";
1476 if ($row->{indexname} eq 'PRIMARY') {
1477 $sql = "alter table $table ADD PRIMARY KEY ($row->{content})";
1479 $sql = "alter table $table ADD INDEX $key_name ($row->{content}) $row->{type}";
1482 print "Error $sql : $dbh->err \n" if $dbh->err;
1488 # check foreign keys and create them when needed
1490 print "Checking for foreign keys required...\n" unless $silent;
1491 foreach my $table ( keys %foreign_keys ) {
1493 # read all indexes from $table
1495 $sth = $dbh->prepare("show table status like '$table'");
1497 my $stat = $sth->fetchrow_hashref;
1498 # read indexes to check
1499 my $tablerows = $foreign_keys{$table};
1500 foreach my $row (@$tablerows) {
1501 my $foreign_table=$row->{foreigntable};
1502 if ($stat->{'Comment'} =~/$foreign_table/) {
1503 # print "$foreign_table existing\n";
1505 print "\tCreating foreign key $foreign_table in $table\n";
1506 # first, drop any orphan value in child table
1507 if ($row->{onDelete} ne "RESTRICT") {
1508 my $sql = "delete from $table where $row->{key} not in (select $row->{foreignkey} from $row->{foreigntable})";
1510 print "SQL ERROR: $sql : $dbh->err \n" if $dbh->err;
1512 my $sql="alter table $table ADD FOREIGN KEY $row->{key} ($row->{key}) REFERENCES $row->{foreigntable} ($row->{foreignkey})";
1513 $sql .= " on update ".$row->{onUpdate} if $row->{onUpdate};
1514 $sql .= " on delete ".$row->{onDelete} if $row->{onDelete};
1517 print "====================
1518 An error occured during :
1520 It probably means there is something wrong in your DB : a row ($table.$row->{key}) refers to a value in $row->{foreigntable}.$row->{foreignkey} that does not exist. solve the problem and run updater again (or just the previous SQL statement).
1521 You can find those values with select
1522 \t$table.* from $table where $row->{key} not in (select $row->{foreignkey} from $row->{foreigntable})
1523 ====================\n
1534 # create frameworkcode row in biblio table & fill it with marc_biblio.frameworkcode.
1537 # 1st, get how many biblio we will have to do...
1538 $sth = $dbh->prepare('select count(*) from marc_biblio');
1540 my ($totaltodo) = $sth->fetchrow;
1542 $sth = $dbh->prepare("show columns from biblio");
1545 my $bibliofwexist=0;
1546 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ){
1547 $bibliofwexist=1 if $column eq 'frameworkcode';
1549 unless ($bibliofwexist) {
1550 print "moving biblioframework to biblio table\n";
1551 $dbh->do('ALTER TABLE `biblio` ADD `frameworkcode` VARCHAR( 4 ) NOT NULL AFTER `biblionumber`');
1552 $sth = $dbh->prepare('select biblionumber,frameworkcode from marc_biblio');
1554 my $sth_update = $dbh->prepare('update biblio set frameworkcode=? where biblionumber=?');
1556 while (my ($biblionumber,$frameworkcode) = $sth->fetchrow) {
1557 $sth_update->execute($frameworkcode,$biblionumber);
1559 print "\r$totaldone / $totaltodo" unless ($totaldone % 100);
1565 # moving MARC data from marc_subfield_table to biblioitems.marc
1567 $sth = $dbh->prepare("show columns from biblioitems");
1571 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ){
1572 $marcdone=1 if ($type eq 'blob' && $column eq 'marc') ;
1574 unless ($marcdone) {
1575 print "moving MARC record to biblioitems table\n";
1576 # changing marc field type
1577 $dbh->do('ALTER TABLE `biblioitems` CHANGE `marc` `marc` BLOB NULL DEFAULT NULL ');
1578 # adding marc xml, just for convenience
1579 $dbh->do('ALTER TABLE `biblioitems` ADD `marcxml` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ');
1580 # moving data from marc_subfield_value to biblio
1581 $sth = $dbh->prepare('select bibid,biblionumber from marc_biblio');
1583 my $sth_update = $dbh->prepare('update biblioitems set marc=?, marcxml=? where biblionumber=?');
1585 while (my ($bibid,$biblionumber) = $sth->fetchrow) {
1586 my $record = MARCgetbiblio($dbh,$bibid);
1587 #Force UTF-8 in record leader
1588 $record->encoding('UTF-8');
1589 print $record->as_formatted if ($biblionumber==3902);
1590 $sth_update->execute($record->as_usmarc(),$record->as_xml_record(),$biblionumber);
1592 print "\r$totaldone / $totaltodo" unless ($totaldone % 100);
1598 # at last, remove useless fields
1599 foreach $table ( keys %uselessfields ) {
1600 my @fields = split /,/,$uselessfields{$table};
1603 foreach my $fieldtodrop (@fields) {
1604 $fieldtodrop =~ s/\t//g;
1605 $fieldtodrop =~ s/\n//g;
1607 $sth = $dbh->prepare("show columns from $table");
1609 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1611 $exists =1 if ($column eq $fieldtodrop);
1614 print "deleting $fieldtodrop field in $table...\n" unless $silent;
1615 my $sth = $dbh->prepare("alter table $table drop $fieldtodrop");
1622 # MOVE all tables TO UTF-8 and innoDB
1623 $sth = $dbh->prepare("show table status");
1625 while ( my $table = $sth->fetchrow_hashref ) {
1626 # if ($table->{Engine} ne 'InnoDB') {
1627 # $dbh->do("ALTER TABLE $table->{Name} TYPE = innodb");
1628 # print "moving $table->{Name} to InnoDB\n";
1630 unless ($table->{Collation} =~ /^utf8/) {
1631 $dbh->do("ALTER TABLE $table->{Name} CONVERT TO CHARACTER SET utf8");
1632 $dbh->do("ALTER TABLE $table->{Name} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
1633 # FIXME : maybe a ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 would be better, def char set seems to work fine. If any problem encountered, let's try with convert !
1634 print "moving $table->{Name} to utf8\n";
1642 # those 2 subs are a copy of Biblio.pm, version 2.2.4
1643 # they are useful only once, for moving from 2.2 to 3.0
1644 # the MARCgetbiblio & MARCgetitem subs in Biblio.pm
1645 # are still here, but uses other tables
1646 # (the ones that are filled by updatedatabase !)
1651 # Returns MARC::Record of the biblio passed in parameter.
1652 my ( $dbh, $bibid ) = @_;
1653 my $record = MARC::Record->new();
1658 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
1659 from marc_subfield_table
1660 where bibid=? order by tag,tagorder,subfieldorder
1665 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
1666 $sth->execute($bibid);
1667 my $prevtagorder = 1;
1668 my $prevtag = 'XXX';
1670 my $field; # for >=10 tags
1671 my $prevvalue; # for <10 tags
1672 while ( my $row = $sth->fetchrow_hashref ) {
1674 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
1675 $sth2->execute( $row->{'valuebloblink'} );
1676 my $row2 = $sth2->fetchrow_hashref;
1678 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
1680 if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
1681 $previndicator .= " ";
1682 if ( $prevtag < 10 ) {
1683 if ($prevtag ne '000') {
1684 $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue ) unless $prevtag eq "XXX"; # ignore the 1st loop
1686 $record->leader(sprintf("%24s",$prevvalue));
1690 $record->add_fields($field) unless $prevtag eq "XXX";
1693 $prevtagorder = $row->{tagorder};
1694 $prevtag = $row->{tag};
1695 $previndicator = $row->{tag_indicator};
1696 if ( $row->{tag} < 10 ) {
1697 $prevvalue = $row->{subfieldvalue};
1700 $field = MARC::Field->new(
1701 ( sprintf "%03s", $prevtag ),
1702 substr( $row->{tag_indicator} . ' ', 0, 1 ),
1703 substr( $row->{tag_indicator} . ' ', 1, 1 ),
1704 $row->{'subfieldcode'},
1705 $row->{'subfieldvalue'}
1710 if ( $row->{tag} < 10 ) {
1711 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
1712 $row->{'subfieldvalue'} );
1715 $field->add_subfields( $row->{'subfieldcode'},
1716 $row->{'subfieldvalue'} );
1718 $prevtag = $row->{tag};
1719 $previndicator = $row->{tag_indicator};
1723 # the last has not been included inside the loop... do it now !
1724 if ( $prevtag ne "XXX" )
1725 { # check that we have found something. Otherwise, prevtag is still XXX and we
1726 # must return an empty record, not make MARC::Record fail because we try to
1727 # create a record with XXX as field :-(
1728 if ( $prevtag < 10 ) {
1729 $record->add_fields( $prevtag, $prevvalue );
1733 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
1734 $record->add_fields($field);
1742 # Returns MARC::Record of the biblio passed in parameter.
1743 my ( $dbh, $bibid, $itemnumber ) = @_;
1744 my $record = MARC::Record->new();
1746 # search MARC tagorder
1749 "select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?"
1751 $sth2->execute( $bibid, $itemnumber );
1752 my ($tagorder) = $sth2->fetchrow_array();
1754 #---- TODO : the leader is missing
1757 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
1758 from marc_subfield_table
1759 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
1764 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
1765 $sth->execute( $bibid, $tagorder );
1766 while ( my $row = $sth->fetchrow_hashref ) {
1767 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
1768 $sth2->execute( $row->{'valuebloblink'} );
1769 my $row2 = $sth2->fetchrow_hashref;
1771 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
1773 if ( $record->field( $row->{'tag'} ) ) {
1776 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
1777 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
1778 if ( length( $row->{'tag'} ) < 3 ) {
1779 $row->{'tag'} = "0" . $row->{'tag'};
1781 $field = $record->field( $row->{'tag'} );
1784 $field->add_subfields( $row->{'subfieldcode'},
1785 $row->{'subfieldvalue'} );
1786 $record->delete_field($field);
1787 $record->add_fields($field);
1791 if ( length( $row->{'tag'} ) < 3 ) {
1792 $row->{'tag'} = "0" . $row->{'tag'};
1795 MARC::Field->new( $row->{'tag'}, " ", " ",
1796 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
1797 $record->add_fields($temp);
1808 # Revision 1.151 2006/06/22 10:33:14 btoumi
1809 # sorry i forget deletedborrowers table
1810 # modify firstname field from deletedborrowers table
1812 # Revision 1.149 2006/06/20 22:35:47 rangi
1813 # Code to allow the associated borrowers to work
1815 # Revision 1.148 2006/06/17 22:12:01 rangi
1816 # Adding id field to reviews table
1818 # Revision 1.147 2006/06/17 03:36:41 rangi
1819 # Table definition for the reviews table
1821 # Revision 1.146 2006/06/17 03:29:41 rangi
1822 # Variable to allow librarians to switch reviews on or off
1824 # Revision 1.145 2006/06/16 09:45:02 btoumi
1825 # updatedatabase.pl: add change of borrowers table to deletedborrowers table
1826 # deletemem.pl: delete use of warn function
1828 # Revision 1.144 2006/06/08 15:36:31 alaurin
1829 # Add a new system preference 'AutomaticItemReturn' :
1831 # if this prefence is switched on: the document returned in another library than homebranch, the system automaticly transfer the document to his homebranch (with notification for librarian in returns.tmpl) .
1833 # switch off : the document stay in the holdingbranch ...
1836 # - comment C4::acquisition (not using in request.pl).
1837 # - correcting date in request.pl
1838 # -add the new call of function getbranches in request.pl
1840 # Revision 1.143 2006/06/07 02:02:47 bob_lyon
1841 # merging katipo changes...
1843 # adding new preference IssuingInProcess
1845 # Revision 1.142 2006/06/06 23:42:46 bob_lyon
1846 # Merging Katipo changes...
1848 # Adding new system pref where one can still retrieve a correct reading
1849 # record history if one has moved older data from issues to oldissues table
1850 # to speed up issues speed
1852 # Revision 1.141 2006/06/01 03:18:11 rangi
1853 # Adding a new column to the statistics table
1855 # Revision 1.140 2006/05/22 22:40:45 rangi
1856 # Adding new systempreference allowing for the library to add borrowers to institutions (rest homes, parishes, schools, classes etc).
1858 # Revision 1.139 2006/05/19 19:31:29 tgarip1957
1859 # Added new fields to auth_header and auth_subfield_table to allow ZEBRA use of authorities and new MARC framework like structure.
1860 # Authority tables are modified to be compatible with new MARC frameworks. This change is part of Authority Linking & Zebra authorities. Requires change in Mysql database. It will break head unless all changes regarding this is implemented. This warning will take place on all commits regarding this
1862 # Revision 1.138 2006/05/19 16:51:44 alaurin
1863 # update database for :
1864 # - new feature ip and printer management
1865 # adding two fields in branches table (branchip,branchprinter)
1867 # - waiting date : adding one field in reserves table(waiting date) to calculate the Maximum delay to pick up a reserved document when it's available
1869 # new system preference :
1870 # - ReservesMaxPickUpDelay : Maximum delay to pick up a reserved document
1871 # TransfersMaxDaysWarning : Max delay before considering the transfer as potentialy a problem
1873 # Revision 1.137 2006/04/18 09:36:36 plg
1874 # bug fixed: typo fixed in labels and labels_conf tables creation query.
1876 # Revision 1.136 2006/04/17 21:55:33 sushi
1877 # Added 'labels' and 'labels_conf' tables, for spine lable tool.
1879 # Revision 1.135 2006/04/15 02:37:03 tgarip1957
1880 # Marc record should be set to UTF-8 in leader.Force it.
1881 # XML should be with<record> wrappers
1883 # Revision 1.134 2006/04/14 09:37:29 tipaul
1884 # improvements from SAN Ouest Provence :
1885 # * introducing a category_type into categories. It can be A (adult), C (children), P (Professionnal), I (institution/organisation).
1886 # * each category_type has it's own forms to create members.
1887 # * the borrowers table has been heavily modified (many fields changed), to get something more logic & readable
1888 # * reintroducing guarantor/guanrantee system that is now independant from hardcoded C/A for categories
1889 # * updating templates to fit template rules
1891 # (see mail feb, 17 on koha-devel "new features for borrowers" for more details)
1893 # Revision 1.133 2006/04/13 08:36:42 plg
1894 # new: function C4::Date::get_date_format_string_for_DHTMLcalendar based on
1895 # the system preference prefered date format.
1897 # improvement: book fund list and budget list screen redesigned. Filters on
1898 # each field. Columns are not sortable yet. Using DHTML Calendar to fill date
1899 # fields instead of manual filling. Pagination system. From the book fund
1900 # list, you can reach the budget list, filtered on a book fund, or not. A
1901 # budget can be added only from book fund list screen.
1903 # bug fixed: branchcode was missing in table aqbudget.
1905 # bug fixed: when setting a branchcode to a book fund, all associated budgets
1906 # move to this branchcode.
1908 # modification: when adding/modifying budget/fund, MySQL specific "REPLACE..."
1909 # statements replaced by standard SQL compliant statement.
1911 # bug fixed: when adding/modifying a budget, if the book fund is associated to
1912 # a branch, the branch selection is disabled and set to the book fund branch.
1914 # Revision 1.132 2006/04/06 12:37:05 hdl
1915 # Bugfixing : aqbookfund needed a field.
1917 # Revision 1.131 2006/03/03 17:02:22 tipaul
1918 # commit for holidays and news management.
1919 # (some forgotten files)
1921 # Revision 1.130 2006/03/03 16:35:21 tipaul
1922 # commit for holidays and news management.
1924 # Contrib from Tümer Garip (from Turkey) :
1926 # in /tools/ the holiday.pl script let you define holidays (days where the library is closed), branch by branch. You can define 3 types of holidays :
1927 # - single day : only this day is closed
1928 # - repet weekly (like "sunday") : the day is holiday every week
1929 # - repet yearly (like "July, 4") : this day is closed every year.
1931 # You can also put exception :
1932 # - sunday is holiday, but "2006 March, 5th" the library will be open
1934 # The holidays are used for return date calculation : the return date is set to the next date where the library is open. A systempreference (useDaysMode) set ON (Calendar) or OFF (Normal) the calendar calculation.
1936 # Revision 1.129 2006/02/27 18:19:33 hdl
1937 # New table used in overduerules.pl tools page.
1939 # Revision 1.128 2006/01/25 15:16:06 tipaul
1941 # * removing useless tables
1942 # * adding useful indexes
1943 # * altering some columns definitions
1944 # * The goal being to have updater working fine for foreign keys.
1946 # For me it's done, let me know if it works for you. You can see an updated schema of the DB (with constraints) on the wiki
1948 # Revision 1.127 2006/01/24 17:57:17 tipaul
1949 # DB improvements : adding foreign keys on some tables. partial stuff done.
1951 # Revision 1.126 2006/01/06 16:39:42 tipaul
1952 # synch'ing head and rel_2_2 (from 2.2.5, including npl templates)
1953 # Seems not to break too many things, but i'm probably wrong here.
1954 # at least, new features/bugfixes from 2.2.5 are here (tested on some features on my head local copy)
1956 # - removing useless directories (koha-html and koha-plucene)
1958 # Revision 1.125 2006/01/04 15:54:55 tipaul
1959 # utf8 is a : go for beta test in HEAD.
1960 # some explanations :
1961 # - updater/updatedatabase => will transform all tables in innoDB (not related to utf8, just to warn you) AND collate them in utf8 / utf8_general_ci. The SQL command is : ALTER TABLE tablename DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci.
1962 # - *-top.inc will show the pages in utf8
1963 # - THE HARD THING : for me, mysql-client and mysql-server were set up to communicate in iso8859-1, whatever the mysql collation ! Thus, pages were improperly shown, as datas were transmitted in iso8859-1 format ! After a full day of investigation, someone on usenet pointed "set NAMES 'utf8'" to explain that I wanted utf8. I could put this in my.cnf, but if I do that, ALL databases will "speak" in utf8, that's not what we want. Thus, I added a line in Context.pm : everytime a DB handle is opened, the communication is set to utf8.
1964 # - using marcxml field and no more the iso2709 raw marc biblioitems.marc field.
1966 # Revision 1.124 2005/10/27 12:09:05 tipaul
1967 # new features for serial module :
1968 # - the last 5 issues are now shown, and their status can be changed (but not reverted to "waited", as there can be only one "waited")
1969 # - the library can create a "distribution list". this paper contains a list of borrowers (selected from the borrower list, or manually entered), and print it for a given issue. once printed, the sheet can be put on the issue and distributed to every reader on the list (one by one).
1971 # Revision 1.123 2005/10/26 09:13:37 tipaul
1972 # big commit, still breaking things...
1974 # * synch with rel_2_2. Probably the last non manual synch, as rel_2_2 should not be modified deeply.
1975 # * code cleaning (cleaning warnings from perl -w) continued
1977 # Revision 1.122 2005/09/02 14:18:38 tipaul
1978 # new feature : image for itemtypes.
1980 # * run updater/updatedatabase to create imageurl field in itemtypes.
1981 # * go to Koha >> parameters >> itemtypes >> modify (or add) an itemtype. You will see around 20 nice images to choose between (thanks to owen). If you prefer your own image, you also can type a complete url (http://www.myserver.lib/path/to/my/image.gif)
1982 # * go to OPAC, and search something. In the result list, you now have the picture instead of the text itemtype.
1984 # Revision 1.121 2005/08/24 08:49:03 hdl
1985 # Adding a note field in serial table.
1986 # This will allow librarian to mention a note on a peculiar waiting serial number.
1988 # Revision 1.120 2005/08/09 14:10:32 tipaul
1989 # 1st commit to go to zebra.
1990 # don't update your cvs if you want to have a working head...
1992 # this commit contains :
1993 # * updater/updatedatabase : get rid with marc_* tables, but DON'T remove them. As a lot of things uses them, it would not be a good idea for instance to drop them. If you really want to play, you can rename them to test head without them but being still able to reintroduce them...
1994 # * Biblio.pm : modify MARCgetbiblio to find the raw marc record in biblioitems.marc field, not from marc_subfield_table, modify MARCfindframeworkcode to find frameworkcode in biblio.frameworkcode, modify some other subs to use biblio.biblionumber & get rid of bibid.
1995 # * other files : get rid of bibid and use biblionumber instead.
1998 # * does not do anything on zebra yet.
1999 # * if you rename marc_subfield_table, you can't search anymore.
2000 # * you can view a biblio & bibliodetails, go to MARC editor, but NOT save any modif.
2001 # * don't try to add a biblio, it would add data poorly... (don't try to delete either, it may work, but that would be a surprise ;-) )
2003 # IMPORTANT NOTE : you need MARC::XML package (http://search.cpan.org/~esummers/MARC-XML-0.7/lib/MARC/File/XML.pm), that requires a recent version of MARC::Record
2004 # Updatedatabase stores the iso2709 data in biblioitems.marc field & an xml version in biblioitems.marcxml Not sure we will keep it when releasing the stable version, but I think it's a good idea to have something readable in sql, at least for development stage.
2006 # Revision 1.119 2005/08/04 16:07:58 tipaul
2007 # Synch really broke this script...
2009 # Revision 1.118 2005/08/04 16:02:55 tipaul
2010 # oops... error in synch between 2.2 and head
2012 # Revision 1.117 2005/08/04 14:24:39 tipaul
2013 # synch'ing 2.2 and head
2015 # Revision 1.116 2005/08/04 08:55:54 tipaul
2016 # Letters / alert system, continuing...
2018 # * adding a package Letters.pm, that manages Letters & alerts.
2019 # * adding feature : it's now possible to define a "letter" for any subscription created. If a letter is defined, users in OPAC can put an alert on the subscription. When an issue is marked "arrived", all users in the alert will recieve a mail (as defined in the "letter"). This last part (= send the mail) is not yet developped. (Should be done this week)
2020 # * adding feature : it's now possible to "put to an alert" in OPAC, for any serial subscription. The alert is stored in a new table, called alert. An alert can be put only if the librarian has activated them in subscription (and they activate it just by choosing a "letter" to sent to borrowers on new issues)
2021 # * adding feature : librarian can see in borrower detail which alerts they have put, and a user can see in opac-detail which alert they have put too.
2023 # Note that the system should be generic enough to manage any type of alert.
2024 # I plan to extend it soon to virtual shelves : a borrower will be able to put an alert on a virtual shelf, to be warned when something is changed in the virtual shelf (mail being sent once a day by cron, or manually by the shelf owner. Anyway, a mail won't be sent on every change, users would be spammed by Koha ;-) )
2026 # Revision 1.115 2005/08/02 16:15:34 tipaul
2027 # adding 2 fields to letter system :
2028 # * module (acquisition, catalogue...) : it will be usefull to show the librarian only letters he may be interested by.
2029 # * title, that will be used as mail subject.
2031 # Revision 1.114 2005/07/28 15:10:13 tipaul
2032 # Introducing new "Letters" system : Letters will be used everytime you want to sent something to someone (through mail or paper). For example, sending a mail for overdues use letter that you can put as parameters. Sending a mail to a borrower when a suggestion is validated uses a letter too.
2033 # the letter table contains 3 fields :
2034 # * code => the code of the letter
2035 # * name => the complete name of the letter
2036 # * content => the complete text. It's a TEXT field type, so has no limits.
2038 # My next goal now is to work on point 2-I "serial issue alert"
2039 # With this feature, in serials, a user can subscribe the "issue alert". For every issue arrived/missing, a mail is sent to all subscribers of this list. The mail warns the user that the issue is arrive or missing. Will be in head.
2040 # (see mail on koha-devel, 2005/04/07)
2042 # The "serial issue alert" will be the 1st to use this letter system that probably needs some tweaking ;-)
2044 # Once it will be stabilised default letters (in any languages) could be added during installer to help the library begin with this new feature.
2046 # Revision 1.113 2005/07/28 08:38:41 tipaul
2047 # For instance, the return date does not rely on the borrower expiration date. A systempref will be added in Koha, to modify return date calculation schema :
2048 # * ReturnBeforeExpiry = yes => return date can't be after expiry date
2049 # * ReturnBeforeExpiry = no => return date can be after expiry date
2051 # Revision 1.112 2005/07/26 08:19:47 hdl
2052 # Adding IndependantBranches System preference variable in order to manage Branch independancy.
2054 # Revision 1.111 2005/07/25 15:35:38 tipaul
2055 # we have decided that moving to Koha 3.0 requires being already in Koha 2.2.x
2056 # So, the updatedatabase script can highly be cleaned (90% removed).
2057 # Let's play with the new Koha DB structure now ;-)