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 => 'B_email',
553 after => 'B_zipcode',
556 field => 'streetnumber', # street number (hidden if streettable table is empty)
562 field => 'streettype', # street table, list builded from a system table
565 after => 'streetnumber',
568 field => 'B_streetnumber', # street number (hidden if streettable table is empty)
574 field => 'B_streettype', # street table, list builded from a system table
577 after => 'B_streetnumber',
586 field => 'address2', # complement address
598 field => 'contactfirstname', # contact's firstname
601 after => 'contactname',
604 field => 'contacttitle', # contact's title
607 after => 'contactfirstname',
611 deletedborrowers => [
612 { field => 'B_email',
615 after => 'B_zipcode',
618 field => 'streetnumber', # street number (hidden if streettable table is empty)
624 field => 'streettype', # street table, list builded from a system table
627 after => 'streetnumber',
630 field => 'B_streetnumber', # street number (hidden if streettable table is empty)
636 field => 'B_streettype', # street table, list builded from a system table
639 after => 'B_streetnumber',
648 field => 'address2', # complement address
660 field => 'contactfirstname', # contact's firstname
663 after => 'contactname',
666 field => 'contacttitle', # contact's title
669 after => 'contactfirstname',
676 type => 'varchar(15)',
683 field => 'branchprinter',
684 type => 'varchar(100)',
693 field => 'category_type',
703 field => 'waitingdate',
715 # { indexname => 'index detail'
719 { indexname => 'shelfnumber',
720 content => 'shelfnumber',
722 { indexname => 'itemnumber',
723 content => 'itemnumber',
727 { indexname => 'biblionumber',
728 content => 'biblionumber',
732 { indexname => 'homebranch',
733 content => 'homebranch',
735 { indexname => 'holdingbranch',
736 content => 'holdingbranch',
740 { indexname => 'PRIMARY',
746 { indexname => 'booksellerid',
747 content => 'booksellerid',
751 { indexname => 'basketno',
752 content => 'basketno',
755 aqorderbreakdown => [
756 { indexname => 'ordernumber',
757 content => 'ordernumber',
759 { indexname => 'bookfundid',
760 content => 'bookfundid',
764 { indexname => 'PRIMARY',
765 content => 'currency',
773 # { key => 'the key in table' (must be indexed)
774 # foreigntable => 'the foreigntable name', # (the parent)
775 # foreignkey => 'the foreign key column(s)' # (in the parent)
776 # onUpdate => 'CASCADE|SET NULL|NO ACTION| RESTRICT',
777 # onDelete => 'CASCADE|SET NULL|NO ACTION| RESTRICT',
781 { key => 'shelfnumber',
782 foreigntable => 'bookshelf',
783 foreignkey => 'shelfnumber',
784 onUpdate => 'CASCADE',
785 onDelete => 'CASCADE',
787 { key => 'itemnumber',
788 foreigntable => 'items',
789 foreignkey => 'itemnumber',
790 onUpdate => 'CASCADE',
791 onDelete => 'CASCADE',
794 # onDelete is RESTRICT on reference tables (branches, itemtype) as we don't want items to be
795 # easily deleted, but branches/itemtype not too easy to empty...
797 { key => 'biblionumber',
798 foreigntable => 'biblio',
799 foreignkey => 'biblionumber',
800 onUpdate => 'CASCADE',
801 onDelete => 'CASCADE',
804 foreigntable => 'itemtypes',
805 foreignkey => 'itemtype',
806 onUpdate => 'CASCADE',
807 onDelete => 'RESTRICT',
811 { key => 'biblioitemnumber',
812 foreigntable => 'biblioitems',
813 foreignkey => 'biblioitemnumber',
814 onUpdate => 'CASCADE',
815 onDelete => 'CASCADE',
817 { key => 'homebranch',
818 foreigntable => 'branches',
819 foreignkey => 'branchcode',
820 onUpdate => 'CASCADE',
821 onDelete => 'RESTRICT',
823 { key => 'holdingbranch',
824 foreigntable => 'branches',
825 foreignkey => 'branchcode',
826 onUpdate => 'CASCADE',
827 onDelete => 'RESTRICT',
830 additionalauthors => [
831 { key => 'biblionumber',
832 foreigntable => 'biblio',
833 foreignkey => 'biblionumber',
834 onUpdate => 'CASCADE',
835 onDelete => 'CASCADE',
839 { key => 'biblionumber',
840 foreigntable => 'biblio',
841 foreignkey => 'biblionumber',
842 onUpdate => 'CASCADE',
843 onDelete => 'CASCADE',
847 { key => 'booksellerid',
848 foreigntable => 'aqbooksellers',
850 onUpdate => 'CASCADE',
851 onDelete => 'RESTRICT',
856 foreigntable => 'aqbasket',
857 foreignkey => 'basketno',
858 onUpdate => 'CASCADE',
859 onDelete => 'CASCADE',
861 { key => 'biblionumber',
862 foreigntable => 'biblio',
863 foreignkey => 'biblionumber',
864 onUpdate => 'SET NULL',
865 onDelete => 'SET NULL',
869 { key => 'listprice',
870 foreigntable => 'currency',
871 foreignkey => 'currency',
872 onUpdate => 'CASCADE',
873 onDelete => 'CASCADE',
875 { key => 'invoiceprice',
876 foreigntable => 'currency',
877 foreignkey => 'currency',
878 onUpdate => 'CASCADE',
879 onDelete => 'CASCADE',
882 aqorderbreakdown => [
883 { key => 'ordernumber',
884 foreigntable => 'aqorders',
885 foreignkey => 'ordernumber',
886 onUpdate => 'CASCADE',
887 onDelete => 'CASCADE',
889 { key => 'bookfundid',
890 foreigntable => 'aqbookfund',
891 foreignkey => 'bookfundid',
892 onUpdate => 'CASCADE',
893 onDelete => 'CASCADE',
897 { key => 'frombranch',
898 foreigntable => 'branches',
899 foreignkey => 'branchcode',
900 onUpdate => 'CASCADE',
901 onDelete => 'CASCADE',
904 foreigntable => 'branches',
905 foreignkey => 'branchcode',
906 onUpdate => 'CASCADE',
907 onDelete => 'CASCADE',
909 { key => 'itemnumber',
910 foreigntable => 'items',
911 foreignkey => 'itemnumber',
912 onUpdate => 'CASCADE',
913 onDelete => 'CASCADE',
917 { key => 'categorycode',
918 foreigntable => 'categories',
919 foreignkey => 'categorycode',
920 onUpdate => 'CASCADE',
921 onDelete => 'CASCADE',
924 foreigntable => 'itemtypes',
925 foreignkey => 'itemtype',
926 onUpdate => 'CASCADE',
927 onDelete => 'CASCADE',
930 issues => [ # constraint is SET NULL : when a borrower or an item is deleted, we keep the issuing record
932 { key => 'borrowernumber',
933 foreigntable => 'borrowers',
934 foreignkey => 'borrowernumber',
935 onUpdate => 'SET NULL',
936 onDelete => 'SET NULL',
938 { key => 'itemnumber',
939 foreigntable => 'items',
940 foreignkey => 'itemnumber',
941 onUpdate => 'SET NULL',
942 onDelete => 'SET NULL',
946 { key => 'borrowernumber',
947 foreigntable => 'borrowers',
948 foreignkey => 'borrowernumber',
949 onUpdate => 'CASCADE',
950 onDelete => 'CASCADE',
952 { key => 'biblionumber',
953 foreigntable => 'biblio',
954 foreignkey => 'biblionumber',
955 onUpdate => 'CASCADE',
956 onDelete => 'CASCADE',
958 { key => 'itemnumber',
959 foreigntable => 'items',
960 foreignkey => 'itemnumber',
961 onUpdate => 'CASCADE',
962 onDelete => 'CASCADE',
964 { key => 'branchcode',
965 foreigntable => 'branches',
966 foreignkey => 'branchcode',
967 onUpdate => 'CASCADE',
968 onDelete => 'CASCADE',
971 borrowers => [ # foreign keys are RESTRICT as we don't want to delete borrowers when a branch is deleted
972 # but prevent deleting a branch as soon as it has 1 borrower !
973 { key => 'categorycode',
974 foreigntable => 'categories',
975 foreignkey => 'categorycode',
976 onUpdate => 'RESTRICT',
977 onDelete => 'RESTRICT',
979 { key => 'branchcode',
980 foreigntable => 'branches',
981 foreignkey => 'branchcode',
982 onUpdate => 'RESTRICT',
983 onDelete => 'RESTRICT',
986 deletedborrowers => [ # foreign keys are RESTRICT as we don't want to delete borrowers when a branch is deleted
987 # but prevent deleting a branch as soon as it has 1 borrower !
988 { key => 'categorycode',
989 foreigntable => 'categories',
990 foreignkey => 'categorycode',
991 onUpdate => 'RESTRICT',
992 onDelete => 'RESTRICT',
994 { key => 'branchcode',
995 foreigntable => 'branches',
996 foreignkey => 'branchcode',
997 onUpdate => 'RESTRICT',
998 onDelete => 'RESTRICT',
1002 { key => 'borrowernumber',
1003 foreigntable => 'borrowers',
1004 foreignkey => 'borrowernumber',
1005 onUpdate => 'CASCADE',
1006 onDelete => 'CASCADE',
1008 { key => 'itemnumber',
1009 foreigntable => 'items',
1010 foreignkey => 'itemnumber',
1011 onUpdate => 'SET NULL',
1012 onDelete => 'SET NULL',
1015 auth_tag_structure => [
1016 { key => 'authtypecode',
1017 foreigntable => 'auth_types',
1018 foreignkey => 'authtypecode',
1019 onUpdate => 'CASCADE',
1020 onDelete => 'CASCADE',
1023 # FIXME : don't constraint auth_*_table and auth_word, as they may be replaced by zebra
1028 my %column_change = (
1032 from => 'emailaddress',
1037 from => 'streetaddress',
1039 after => 'initials',
1042 from => 'faxnumber',
1047 from => 'textmessaging',
1053 to => 'contactnote',
1054 after => 'opacnote',
1057 from => 'physstreet',
1062 from => 'streetcity',
1064 after => 'B_address',
1077 from => 'homezipcode',
1084 after => 'B_zipcode',
1089 after => 'dateenrolled',
1092 from => 'guarantor',
1093 to => 'guarantorid',
1094 after => 'contactname',
1097 from => 'textmessaging',
1103 to => 'contactnotes',
1104 after => 'opacnotes',
1107 from => 'altrelationship',
1108 to => 'relationship',
1109 after => 'borrowernotes',
1113 deletedborrowers => [
1115 from => 'emailaddress',
1120 from => 'streetaddress',
1122 after => 'initials',
1125 from => 'faxnumber',
1130 from => 'textmessaging',
1136 to => 'contactnote',
1137 after => 'opacnote',
1140 from => 'physstreet',
1145 from => 'streetcity',
1147 after => 'B_address',
1160 from => 'homezipcode',
1167 after => 'B_zipcode',
1172 after => 'dateenrolled',
1175 from => 'guarantor',
1176 to => 'guarantorid',
1177 after => 'contactname',
1180 from => 'textmessaging',
1186 to => 'contactnotes',
1187 after => 'opacnotes',
1190 from => 'altrelationship',
1191 to => 'relationship',
1192 after => 'borrowernotes',
1198 foreach my $table (keys %column_change) {
1199 $sth = $dbh->prepare("show columns from $table");
1202 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1204 $types{$column}->{type} ="$type";
1205 $types{$column}->{null} = "$null";
1206 $types{$column}->{key} = "$key";
1207 $types{$column}->{default} = "$default";
1208 $types{$column}->{extra} = "$extra";
1210 my $tablerows = $column_change{$table};
1211 foreach my $row ( @$tablerows ) {
1212 if ($types{$row->{from}}->{type}) {
1213 print "altering $table $row->{from} to $row->{to}\n";
1214 # ALTER TABLE `borrowers` CHANGE `faxnumber` `fax` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
1215 # alter table `borrowers` change `faxnumber` `fax` type text null after phone
1217 "alter table `$table` change `$row->{from}` `$row->{to}` $types{$row->{from}}->{type} ".
1218 ($types{$row->{from}}->{null} eq 'YES'?" NULL":" NOT NULL").
1219 ($types{$row->{from}}->{default}?" default ".$types{$row->{from}}->{default}:"").
1220 "$types{$row->{from}}->{extra} after $row->{after} ";
1227 #-------------------
1232 # Get version of MySQL database engine.
1233 my $mysqlversion = `mysqld --version`;
1234 $mysqlversion =~ /Ver (\S*) /;
1236 if ( $mysqlversion ge '3.23' ) {
1237 print "Could convert to MyISAM database tables...\n" unless $silent;
1240 #---------------------------------
1243 # Collect all tables into a list
1244 $sth = $dbh->prepare("show tables");
1246 while ( my ($table) = $sth->fetchrow ) {
1247 $existingtables{$table} = 1;
1251 # Now add any missing tables
1252 foreach $table ( keys %requiretables ) {
1253 unless ( $existingtables{$table} ) {
1254 print "Adding $table table...\n" unless $silent;
1255 my $sth = $dbh->prepare("create table $table $requiretables{$table}");
1258 print "Error : $sth->errstr \n";
1264 # now drop useless tables
1265 foreach $table ( keys %dropable_table ) {
1266 if ( $existingtables{$table} ) {
1267 print "Dropping unused table $table\n" if $debug and not $silent;
1268 $dbh->do("drop table $table");
1270 print "Error : $dbh->errstr \n";
1275 #---------------------------------
1278 foreach $table ( keys %requirefields ) {
1279 print "Check table $table\n" if $debug and not $silent;
1280 $sth = $dbh->prepare("show columns from $table");
1283 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1285 $types{$column} = $type;
1287 foreach $column ( keys %{ $requirefields{$table} } ) {
1288 print " Check column $column [$types{$column}]\n" if $debug and not $silent;
1289 if ( !$types{$column} ) {
1291 # column doesn't exist
1292 print "Adding $column field to $table table...\n" unless $silent;
1293 $query = "alter table $table
1294 add column $column " . $requirefields{$table}->{$column};
1295 print "Execute: $query\n" if $debug;
1296 my $sti = $dbh->prepare($query);
1299 print "**Error : $sti->errstr \n";
1306 foreach $table ( keys %fielddefinitions ) {
1307 print "Check table $table\n" if $debug;
1308 $sth = $dbh->prepare("show columns from $table");
1311 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1313 $definitions->{$column}->{type} = $type;
1314 $definitions->{$column}->{null} = $null;
1315 $definitions->{$column}->{null} = 'NULL' if $null eq 'YES';
1316 $definitions->{$column}->{key} = $key;
1317 $definitions->{$column}->{default} = $default;
1318 $definitions->{$column}->{extra} = $extra;
1320 my $fieldrow = $fielddefinitions{$table};
1321 foreach my $row (@$fieldrow) {
1322 my $field = $row->{field};
1323 my $type = $row->{type};
1324 my $null = $row->{null};
1325 # $null = 'YES' if $row->{null} eq 'NULL';
1326 my $key = $row->{key};
1327 my $default = $row->{default};
1328 my $null = $row->{null};
1329 # $default="''" unless $default;
1330 my $extra = $row->{extra};
1331 my $def = $definitions->{$field};
1332 my $after = ($row->{after}?" after ".$row->{after}:"");
1334 unless ( $type eq $def->{type}
1335 && $null eq $def->{null}
1336 && $key eq $def->{key}
1337 && $extra eq $def->{extra} )
1339 if ( $null eq '' ) {
1342 if ( $key eq 'PRI' ) {
1343 $key = 'PRIMARY KEY';
1345 unless ( $extra eq 'auto_increment' ) {
1349 # if it's a new column use "add", if it's an old one, use "change".
1351 if ($definitions->{$field}->{type}) {
1352 $action="change $field"
1356 # if it's a primary key, drop the previous pk, before altering the table
1358 if ($key ne 'PRIMARY KEY') {
1359 $sth =$dbh->prepare("alter table $table $action $field $type $null $key $extra default ? $after");
1361 $sth =$dbh->prepare("alter table $table drop primary key, $action $field $type $null $key $extra default ? $after");
1363 $sth->execute($default);
1364 print " alter or create $field in $table\n" unless $silent;
1369 # Populate tables with required data
1372 # synch table and deletedtable.
1373 foreach my $table (('borrowers','items','biblio','biblioitems')) {
1374 my %deletedborrowers;
1375 print "synch'ing $table\n";
1376 $sth = $dbh->prepare("show columns from deleted$table");
1378 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ) {
1379 $deletedborrowers{$column}=1;
1381 $sth = $dbh->prepare("show columns from $table");
1384 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ) {
1385 unless ($deletedborrowers{$column}) {
1386 my $newcol="alter table deleted$table add $column $type";
1387 if ($null eq 'YES') {
1388 $newcol .= " NULL ";
1390 $newcol .= " NOT NULL ";
1392 $newcol .= "default $default" if $default;
1393 $newcol .= " after $previous" if $previous;
1395 print "creating column $column\n";
1401 foreach my $table ( keys %tabledata ) {
1402 print "Checking for data required in table $table...\n" unless $silent;
1403 my $tablerows = $tabledata{$table};
1404 foreach my $row (@$tablerows) {
1405 my $uniquefieldrequired = $row->{uniquefieldrequired};
1406 my $uniquevalue = $row->{$uniquefieldrequired};
1407 my $forceupdate = $row->{forceupdate};
1410 "select $uniquefieldrequired from $table where $uniquefieldrequired=?"
1412 $sth->execute($uniquevalue);
1414 foreach my $field (keys %$forceupdate) {
1415 if ($forceupdate->{$field}) {
1416 my $sth=$dbh->prepare("update systempreferences set $field=? where $uniquefieldrequired=?");
1417 $sth->execute($row->{$field}, $uniquevalue);
1421 print "Adding row to $table: " unless $silent;
1425 foreach my $field ( keys %$row ) {
1426 next if $field eq 'uniquefieldrequired';
1427 next if $field eq 'forceupdate';
1428 my $value = $row->{$field};
1429 push @values, $value;
1430 print " $field => $value" unless $silent;
1431 $fieldlist .= "$field,";
1432 $placeholders .= "?,";
1434 print "\n" unless $silent;
1435 $fieldlist =~ s/,$//;
1436 $placeholders =~ s/,$//;
1439 "insert into $table ($fieldlist) values ($placeholders)");
1440 $sth->execute(@values);
1446 # check indexes and create them when needed
1448 print "Checking for index required...\n" unless $silent;
1449 foreach my $table ( keys %indexes ) {
1451 # read all indexes from $table
1453 $sth = $dbh->prepare("show index from $table");
1455 my %existingindexes;
1456 while ( my ( $table, $non_unique, $key_name, $Seq_in_index, $Column_name, $Collation, $cardinality, $sub_part, $Packed, $comment ) = $sth->fetchrow ) {
1457 $existingindexes{$key_name} = 1;
1459 # read indexes to check
1460 my $tablerows = $indexes{$table};
1461 foreach my $row (@$tablerows) {
1462 my $key_name=$row->{indexname};
1463 if ($existingindexes{$key_name} eq 1) {
1464 # print "$key_name existing";
1466 print "\tCreating index $key_name in $table\n";
1468 if ($row->{indexname} eq 'PRIMARY') {
1469 $sql = "alter table $table ADD PRIMARY KEY ($row->{content})";
1471 $sql = "alter table $table ADD INDEX $key_name ($row->{content}) $row->{type}";
1474 print "Error $sql : $dbh->err \n" if $dbh->err;
1480 # check foreign keys and create them when needed
1482 print "Checking for foreign keys required...\n" unless $silent;
1483 foreach my $table ( keys %foreign_keys ) {
1485 # read all indexes from $table
1487 $sth = $dbh->prepare("show table status like '$table'");
1489 my $stat = $sth->fetchrow_hashref;
1490 # read indexes to check
1491 my $tablerows = $foreign_keys{$table};
1492 foreach my $row (@$tablerows) {
1493 my $foreign_table=$row->{foreigntable};
1494 if ($stat->{'Comment'} =~/$foreign_table/) {
1495 # print "$foreign_table existing\n";
1497 print "\tCreating foreign key $foreign_table in $table\n";
1498 # first, drop any orphan value in child table
1499 if ($row->{onDelete} ne "RESTRICT") {
1500 my $sql = "delete from $table where $row->{key} not in (select $row->{foreignkey} from $row->{foreigntable})";
1502 print "SQL ERROR: $sql : $dbh->err \n" if $dbh->err;
1504 my $sql="alter table $table ADD FOREIGN KEY $row->{key} ($row->{key}) REFERENCES $row->{foreigntable} ($row->{foreignkey})";
1505 $sql .= " on update ".$row->{onUpdate} if $row->{onUpdate};
1506 $sql .= " on delete ".$row->{onDelete} if $row->{onDelete};
1509 print "====================
1510 An error occured during :
1512 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).
1513 You can find those values with select
1514 \t$table.* from $table where $row->{key} not in (select $row->{foreignkey} from $row->{foreigntable})
1515 ====================\n
1526 # create frameworkcode row in biblio table & fill it with marc_biblio.frameworkcode.
1529 # 1st, get how many biblio we will have to do...
1530 $sth = $dbh->prepare('select count(*) from marc_biblio');
1532 my ($totaltodo) = $sth->fetchrow;
1534 $sth = $dbh->prepare("show columns from biblio");
1537 my $bibliofwexist=0;
1538 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ){
1539 $bibliofwexist=1 if $column eq 'frameworkcode';
1541 unless ($bibliofwexist) {
1542 print "moving biblioframework to biblio table\n";
1543 $dbh->do('ALTER TABLE `biblio` ADD `frameworkcode` VARCHAR( 4 ) NOT NULL AFTER `biblionumber`');
1544 $sth = $dbh->prepare('select biblionumber,frameworkcode from marc_biblio');
1546 my $sth_update = $dbh->prepare('update biblio set frameworkcode=? where biblionumber=?');
1548 while (my ($biblionumber,$frameworkcode) = $sth->fetchrow) {
1549 $sth_update->execute($frameworkcode,$biblionumber);
1551 print "\r$totaldone / $totaltodo" unless ($totaldone % 100);
1557 # moving MARC data from marc_subfield_table to biblioitems.marc
1559 $sth = $dbh->prepare("show columns from biblioitems");
1563 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ){
1564 $marcdone=1 if ($type eq 'blob' && $column eq 'marc') ;
1566 unless ($marcdone) {
1567 print "moving MARC record to biblioitems table\n";
1568 # changing marc field type
1569 $dbh->do('ALTER TABLE `biblioitems` CHANGE `marc` `marc` BLOB NULL DEFAULT NULL ');
1570 # adding marc xml, just for convenience
1571 $dbh->do('ALTER TABLE `biblioitems` ADD `marcxml` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ');
1572 # moving data from marc_subfield_value to biblio
1573 $sth = $dbh->prepare('select bibid,biblionumber from marc_biblio');
1575 my $sth_update = $dbh->prepare('update biblioitems set marc=?, marcxml=? where biblionumber=?');
1577 while (my ($bibid,$biblionumber) = $sth->fetchrow) {
1578 my $record = MARCgetbiblio($dbh,$bibid);
1579 #Force UTF-8 in record leader
1580 $record->encoding('UTF-8');
1581 print $record->as_formatted if ($biblionumber==3902);
1582 $sth_update->execute($record->as_usmarc(),$record->as_xml_record(),$biblionumber);
1584 print "\r$totaldone / $totaltodo" unless ($totaldone % 100);
1590 # at last, remove useless fields
1591 foreach $table ( keys %uselessfields ) {
1592 my @fields = split /,/,$uselessfields{$table};
1595 foreach my $fieldtodrop (@fields) {
1596 $fieldtodrop =~ s/\t//g;
1597 $fieldtodrop =~ s/\n//g;
1599 $sth = $dbh->prepare("show columns from $table");
1601 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1603 $exists =1 if ($column eq $fieldtodrop);
1606 print "deleting $fieldtodrop field in $table...\n" unless $silent;
1607 my $sth = $dbh->prepare("alter table $table drop $fieldtodrop");
1614 # MOVE all tables TO UTF-8 and innoDB
1615 $sth = $dbh->prepare("show table status");
1617 while ( my $table = $sth->fetchrow_hashref ) {
1618 # if ($table->{Engine} ne 'InnoDB') {
1619 # $dbh->do("ALTER TABLE $table->{Name} TYPE = innodb");
1620 # print "moving $table->{Name} to InnoDB\n";
1622 unless ($table->{Collation} =~ /^utf8/) {
1623 $dbh->do("ALTER TABLE $table->{Name} CONVERT TO CHARACTER SET utf8");
1624 $dbh->do("ALTER TABLE $table->{Name} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
1625 # 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 !
1626 print "moving $table->{Name} to utf8\n";
1634 # those 2 subs are a copy of Biblio.pm, version 2.2.4
1635 # they are useful only once, for moving from 2.2 to 3.0
1636 # the MARCgetbiblio & MARCgetitem subs in Biblio.pm
1637 # are still here, but uses other tables
1638 # (the ones that are filled by updatedatabase !)
1643 # Returns MARC::Record of the biblio passed in parameter.
1644 my ( $dbh, $bibid ) = @_;
1645 my $record = MARC::Record->new();
1650 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
1651 from marc_subfield_table
1652 where bibid=? order by tag,tagorder,subfieldorder
1657 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
1658 $sth->execute($bibid);
1659 my $prevtagorder = 1;
1660 my $prevtag = 'XXX';
1662 my $field; # for >=10 tags
1663 my $prevvalue; # for <10 tags
1664 while ( my $row = $sth->fetchrow_hashref ) {
1666 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
1667 $sth2->execute( $row->{'valuebloblink'} );
1668 my $row2 = $sth2->fetchrow_hashref;
1670 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
1672 if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
1673 $previndicator .= " ";
1674 if ( $prevtag < 10 ) {
1675 if ($prevtag ne '000') {
1676 $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue ) unless $prevtag eq "XXX"; # ignore the 1st loop
1678 $record->leader(sprintf("%24s",$prevvalue));
1682 $record->add_fields($field) unless $prevtag eq "XXX";
1685 $prevtagorder = $row->{tagorder};
1686 $prevtag = $row->{tag};
1687 $previndicator = $row->{tag_indicator};
1688 if ( $row->{tag} < 10 ) {
1689 $prevvalue = $row->{subfieldvalue};
1692 $field = MARC::Field->new(
1693 ( sprintf "%03s", $prevtag ),
1694 substr( $row->{tag_indicator} . ' ', 0, 1 ),
1695 substr( $row->{tag_indicator} . ' ', 1, 1 ),
1696 $row->{'subfieldcode'},
1697 $row->{'subfieldvalue'}
1702 if ( $row->{tag} < 10 ) {
1703 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
1704 $row->{'subfieldvalue'} );
1707 $field->add_subfields( $row->{'subfieldcode'},
1708 $row->{'subfieldvalue'} );
1710 $prevtag = $row->{tag};
1711 $previndicator = $row->{tag_indicator};
1715 # the last has not been included inside the loop... do it now !
1716 if ( $prevtag ne "XXX" )
1717 { # check that we have found something. Otherwise, prevtag is still XXX and we
1718 # must return an empty record, not make MARC::Record fail because we try to
1719 # create a record with XXX as field :-(
1720 if ( $prevtag < 10 ) {
1721 $record->add_fields( $prevtag, $prevvalue );
1725 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
1726 $record->add_fields($field);
1734 # Returns MARC::Record of the biblio passed in parameter.
1735 my ( $dbh, $bibid, $itemnumber ) = @_;
1736 my $record = MARC::Record->new();
1738 # search MARC tagorder
1741 "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=?"
1743 $sth2->execute( $bibid, $itemnumber );
1744 my ($tagorder) = $sth2->fetchrow_array();
1746 #---- TODO : the leader is missing
1749 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
1750 from marc_subfield_table
1751 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
1756 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
1757 $sth->execute( $bibid, $tagorder );
1758 while ( my $row = $sth->fetchrow_hashref ) {
1759 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
1760 $sth2->execute( $row->{'valuebloblink'} );
1761 my $row2 = $sth2->fetchrow_hashref;
1763 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
1765 if ( $record->field( $row->{'tag'} ) ) {
1768 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
1769 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
1770 if ( length( $row->{'tag'} ) < 3 ) {
1771 $row->{'tag'} = "0" . $row->{'tag'};
1773 $field = $record->field( $row->{'tag'} );
1776 $field->add_subfields( $row->{'subfieldcode'},
1777 $row->{'subfieldvalue'} );
1778 $record->delete_field($field);
1779 $record->add_fields($field);
1783 if ( length( $row->{'tag'} ) < 3 ) {
1784 $row->{'tag'} = "0" . $row->{'tag'};
1787 MARC::Field->new( $row->{'tag'}, " ", " ",
1788 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
1789 $record->add_fields($temp);
1800 # Revision 1.149 2006/06/20 22:35:47 rangi
1801 # Code to allow the associated borrowers to work
1803 # Revision 1.148 2006/06/17 22:12:01 rangi
1804 # Adding id field to reviews table
1806 # Revision 1.147 2006/06/17 03:36:41 rangi
1807 # Table definition for the reviews table
1809 # Revision 1.146 2006/06/17 03:29:41 rangi
1810 # Variable to allow librarians to switch reviews on or off
1812 # Revision 1.145 2006/06/16 09:45:02 btoumi
1813 # updatedatabase.pl: add change of borrowers table to deletedborrowers table
1814 # deletemem.pl: delete use of warn function
1816 # Revision 1.144 2006/06/08 15:36:31 alaurin
1817 # Add a new system preference 'AutomaticItemReturn' :
1819 # 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) .
1821 # switch off : the document stay in the holdingbranch ...
1824 # - comment C4::acquisition (not using in request.pl).
1825 # - correcting date in request.pl
1826 # -add the new call of function getbranches in request.pl
1828 # Revision 1.143 2006/06/07 02:02:47 bob_lyon
1829 # merging katipo changes...
1831 # adding new preference IssuingInProcess
1833 # Revision 1.142 2006/06/06 23:42:46 bob_lyon
1834 # Merging Katipo changes...
1836 # Adding new system pref where one can still retrieve a correct reading
1837 # record history if one has moved older data from issues to oldissues table
1838 # to speed up issues speed
1840 # Revision 1.141 2006/06/01 03:18:11 rangi
1841 # Adding a new column to the statistics table
1843 # Revision 1.140 2006/05/22 22:40:45 rangi
1844 # Adding new systempreference allowing for the library to add borrowers to institutions (rest homes, parishes, schools, classes etc).
1846 # Revision 1.139 2006/05/19 19:31:29 tgarip1957
1847 # Added new fields to auth_header and auth_subfield_table to allow ZEBRA use of authorities and new MARC framework like structure.
1848 # 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
1850 # Revision 1.138 2006/05/19 16:51:44 alaurin
1851 # update database for :
1852 # - new feature ip and printer management
1853 # adding two fields in branches table (branchip,branchprinter)
1855 # - 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
1857 # new system preference :
1858 # - ReservesMaxPickUpDelay : Maximum delay to pick up a reserved document
1859 # TransfersMaxDaysWarning : Max delay before considering the transfer as potentialy a problem
1861 # Revision 1.137 2006/04/18 09:36:36 plg
1862 # bug fixed: typo fixed in labels and labels_conf tables creation query.
1864 # Revision 1.136 2006/04/17 21:55:33 sushi
1865 # Added 'labels' and 'labels_conf' tables, for spine lable tool.
1867 # Revision 1.135 2006/04/15 02:37:03 tgarip1957
1868 # Marc record should be set to UTF-8 in leader.Force it.
1869 # XML should be with<record> wrappers
1871 # Revision 1.134 2006/04/14 09:37:29 tipaul
1872 # improvements from SAN Ouest Provence :
1873 # * introducing a category_type into categories. It can be A (adult), C (children), P (Professionnal), I (institution/organisation).
1874 # * each category_type has it's own forms to create members.
1875 # * the borrowers table has been heavily modified (many fields changed), to get something more logic & readable
1876 # * reintroducing guarantor/guanrantee system that is now independant from hardcoded C/A for categories
1877 # * updating templates to fit template rules
1879 # (see mail feb, 17 on koha-devel "new features for borrowers" for more details)
1881 # Revision 1.133 2006/04/13 08:36:42 plg
1882 # new: function C4::Date::get_date_format_string_for_DHTMLcalendar based on
1883 # the system preference prefered date format.
1885 # improvement: book fund list and budget list screen redesigned. Filters on
1886 # each field. Columns are not sortable yet. Using DHTML Calendar to fill date
1887 # fields instead of manual filling. Pagination system. From the book fund
1888 # list, you can reach the budget list, filtered on a book fund, or not. A
1889 # budget can be added only from book fund list screen.
1891 # bug fixed: branchcode was missing in table aqbudget.
1893 # bug fixed: when setting a branchcode to a book fund, all associated budgets
1894 # move to this branchcode.
1896 # modification: when adding/modifying budget/fund, MySQL specific "REPLACE..."
1897 # statements replaced by standard SQL compliant statement.
1899 # bug fixed: when adding/modifying a budget, if the book fund is associated to
1900 # a branch, the branch selection is disabled and set to the book fund branch.
1902 # Revision 1.132 2006/04/06 12:37:05 hdl
1903 # Bugfixing : aqbookfund needed a field.
1905 # Revision 1.131 2006/03/03 17:02:22 tipaul
1906 # commit for holidays and news management.
1907 # (some forgotten files)
1909 # Revision 1.130 2006/03/03 16:35:21 tipaul
1910 # commit for holidays and news management.
1912 # Contrib from Tümer Garip (from Turkey) :
1914 # 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 :
1915 # - single day : only this day is closed
1916 # - repet weekly (like "sunday") : the day is holiday every week
1917 # - repet yearly (like "July, 4") : this day is closed every year.
1919 # You can also put exception :
1920 # - sunday is holiday, but "2006 March, 5th" the library will be open
1922 # 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.
1924 # Revision 1.129 2006/02/27 18:19:33 hdl
1925 # New table used in overduerules.pl tools page.
1927 # Revision 1.128 2006/01/25 15:16:06 tipaul
1929 # * removing useless tables
1930 # * adding useful indexes
1931 # * altering some columns definitions
1932 # * The goal being to have updater working fine for foreign keys.
1934 # 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
1936 # Revision 1.127 2006/01/24 17:57:17 tipaul
1937 # DB improvements : adding foreign keys on some tables. partial stuff done.
1939 # Revision 1.126 2006/01/06 16:39:42 tipaul
1940 # synch'ing head and rel_2_2 (from 2.2.5, including npl templates)
1941 # Seems not to break too many things, but i'm probably wrong here.
1942 # at least, new features/bugfixes from 2.2.5 are here (tested on some features on my head local copy)
1944 # - removing useless directories (koha-html and koha-plucene)
1946 # Revision 1.125 2006/01/04 15:54:55 tipaul
1947 # utf8 is a : go for beta test in HEAD.
1948 # some explanations :
1949 # - 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.
1950 # - *-top.inc will show the pages in utf8
1951 # - 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.
1952 # - using marcxml field and no more the iso2709 raw marc biblioitems.marc field.
1954 # Revision 1.124 2005/10/27 12:09:05 tipaul
1955 # new features for serial module :
1956 # - 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")
1957 # - 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).
1959 # Revision 1.123 2005/10/26 09:13:37 tipaul
1960 # big commit, still breaking things...
1962 # * synch with rel_2_2. Probably the last non manual synch, as rel_2_2 should not be modified deeply.
1963 # * code cleaning (cleaning warnings from perl -w) continued
1965 # Revision 1.122 2005/09/02 14:18:38 tipaul
1966 # new feature : image for itemtypes.
1968 # * run updater/updatedatabase to create imageurl field in itemtypes.
1969 # * 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)
1970 # * go to OPAC, and search something. In the result list, you now have the picture instead of the text itemtype.
1972 # Revision 1.121 2005/08/24 08:49:03 hdl
1973 # Adding a note field in serial table.
1974 # This will allow librarian to mention a note on a peculiar waiting serial number.
1976 # Revision 1.120 2005/08/09 14:10:32 tipaul
1977 # 1st commit to go to zebra.
1978 # don't update your cvs if you want to have a working head...
1980 # this commit contains :
1981 # * 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...
1982 # * 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.
1983 # * other files : get rid of bibid and use biblionumber instead.
1986 # * does not do anything on zebra yet.
1987 # * if you rename marc_subfield_table, you can't search anymore.
1988 # * you can view a biblio & bibliodetails, go to MARC editor, but NOT save any modif.
1989 # * 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 ;-) )
1991 # 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
1992 # 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.
1994 # Revision 1.119 2005/08/04 16:07:58 tipaul
1995 # Synch really broke this script...
1997 # Revision 1.118 2005/08/04 16:02:55 tipaul
1998 # oops... error in synch between 2.2 and head
2000 # Revision 1.117 2005/08/04 14:24:39 tipaul
2001 # synch'ing 2.2 and head
2003 # Revision 1.116 2005/08/04 08:55:54 tipaul
2004 # Letters / alert system, continuing...
2006 # * adding a package Letters.pm, that manages Letters & alerts.
2007 # * 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)
2008 # * 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)
2009 # * 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.
2011 # Note that the system should be generic enough to manage any type of alert.
2012 # 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 ;-) )
2014 # Revision 1.115 2005/08/02 16:15:34 tipaul
2015 # adding 2 fields to letter system :
2016 # * module (acquisition, catalogue...) : it will be usefull to show the librarian only letters he may be interested by.
2017 # * title, that will be used as mail subject.
2019 # Revision 1.114 2005/07/28 15:10:13 tipaul
2020 # 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.
2021 # the letter table contains 3 fields :
2022 # * code => the code of the letter
2023 # * name => the complete name of the letter
2024 # * content => the complete text. It's a TEXT field type, so has no limits.
2026 # My next goal now is to work on point 2-I "serial issue alert"
2027 # 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.
2028 # (see mail on koha-devel, 2005/04/07)
2030 # The "serial issue alert" will be the 1st to use this letter system that probably needs some tweaking ;-)
2032 # Once it will be stabilised default letters (in any languages) could be added during installer to help the library begin with this new feature.
2034 # Revision 1.113 2005/07/28 08:38:41 tipaul
2035 # 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 :
2036 # * ReturnBeforeExpiry = yes => return date can't be after expiry date
2037 # * ReturnBeforeExpiry = no => return date can be after expiry date
2039 # Revision 1.112 2005/07/26 08:19:47 hdl
2040 # Adding IndependantBranches System preference variable in order to manage Branch independancy.
2042 # Revision 1.111 2005/07/25 15:35:38 tipaul
2043 # we have decided that moving to Koha 3.0 requires being already in Koha 2.2.x
2044 # So, the updatedatabase script can highly be cleaned (90% removed).
2045 # Let's play with the new Koha DB structure now ;-)