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.
25 use MARC::File::XML ( BinaryEncoding => 'utf8' );
27 # FIXME - The user might be installing a new database, so can't rely
28 # on /etc/koha.conf anyway.
35 %existingtables, # tables already in database
39 $type, $null, $key, $default, $extra,
40 $prefitem, # preference item in systempreferences table
44 GetOptions( 's' => \$silent );
45 my $dbh = C4::Context->dbh;
46 print "connected to your DB. Checking & modifying it\n" unless $silent;
47 $|=1; # flushes output
52 # Tables to add if they don't exist
54 categorytable => "(categorycode char(5) NOT NULL default '',
55 description text default '',
56 itemtypecodes text default '',
57 PRIMARY KEY (categorycode)
59 subcategorytable => "(subcategorycode char(5) NOT NULL default '',
60 description text default '',
61 itemtypecodes text default '',
62 PRIMARY KEY (subcategorycode)
64 mediatypetable => "(mediatypecode char(5) NOT NULL default '',
65 description text default '',
66 itemtypecodes text default '',
67 PRIMARY KEY (mediatypecode)
70 `timestamp` TIMESTAMP NOT NULL ,
71 `user` INT( 11 ) NOT NULL ,
72 `module` TEXT default '',
73 `action` TEXT default '' ,
74 `object` INT(11) default '' ,
75 `info` TEXT default '' ,
76 PRIMARY KEY ( `timestamp` , `user` )
79 module varchar(20) NOT NULL default '',
80 code varchar(20) NOT NULL default '',
81 name varchar(100) NOT NULL default '',
82 title varchar(200) NOT NULL default '',
84 PRIMARY KEY (module,code)
87 alertid int(11) NOT NULL auto_increment,
88 borrowernumber int(11) NOT NULL default '0',
89 type varchar(10) NOT NULL default '',
90 externalid varchar(20) NOT NULL default '',
91 PRIMARY KEY (alertid),
92 KEY borrowernumber (borrowernumber),
93 KEY type (type,externalid)
96 `idnew` int(10) unsigned NOT NULL auto_increment,
97 `title` varchar(250) NOT NULL default '',
99 `lang` varchar(4) NOT NULL default '',
100 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
101 PRIMARY KEY (`idnew`)
103 repeatable_holidays => "(
104 `id` int(11) NOT NULL auto_increment,
105 `branchcode` varchar(4) NOT NULL default '',
106 `weekday` smallint(6) default NULL,
107 `day` smallint(6) default NULL,
108 `month` smallint(6) default NULL,
109 `title` varchar(50) NOT NULL default '',
110 `description` text NOT NULL,
113 special_holidays => "(
114 `id` int(11) NOT NULL auto_increment,
115 `branchcode` varchar(4) NOT NULL default '',
116 `day` smallint(6) NOT NULL default '0',
117 `month` smallint(6) NOT NULL default '0',
118 `year` smallint(6) NOT NULL default '0',
119 `isexception` smallint(1) NOT NULL default '1',
120 `title` varchar(50) NOT NULL default '',
121 `description` text NOT NULL,
124 overduerules =>"(`branchcode` varchar(255) NOT NULL default '',
125 `categorycode` char(2) NOT NULL default '',
126 `delay1` int(4) default '0',
127 `letter1` varchar(20) default NULL,
128 `debarred1` char(1) default '0',
129 `delay2` int(4) default '0',
130 `debarred2` char(1) default '0',
131 `letter2` varchar(20) default NULL,
132 `delay3` int(4) default '0',
133 `letter3` varchar(20) default NULL,
134 `debarred3` int(1) default '0',
135 PRIMARY KEY (`branchcode`,`categorycode`)
137 cities => "(`cityid` int auto_increment,
138 `city_name` char(100) NOT NULL,
139 `city_zipcode` char(20),
140 PRIMARY KEY (`cityid`)
142 roadtype => "(`roadtypeid` int auto_increment,
143 `road_type` char(100) NOT NULL,
144 PRIMARY KEY (`roadtypeid`)
148 labelid int(11) NOT NULL auto_increment,
149 itemnumber varchar(100) NOT NULL default '',
150 timestamp timestamp(14) NOT NULL,
151 PRIMARY KEY (labelid)
155 id int(4) NOT NULL auto_increment,
156 barcodetype char(100) default '',
157 title tinyint(1) default '0',
158 isbn tinyint(1) default '0',
159 itemtype tinyint(1) default '0',
160 barcode tinyint(1) default '0',
161 dewey tinyint(1) default '0',
162 class tinyint(1) default '0',
163 author tinyint(1) default '0',
164 papertype char(100) default '',
165 startrow int(2) default NULL,
169 reviewid integer NOT NULL auto_increment,
170 borrowernumber integer,
171 biblionumber integer,
174 datereviewed datetime,
175 PRIMARY KEY (reviewid)
177 borrowers_to_borrowers => "(
184 my %requirefields = (
185 subscription => { 'letter' => 'char(20) NULL', 'distributedto' => 'text NULL'},
186 itemtypes => { 'imageurl' => 'char(200) NULL'},
187 aqbookfund => { 'branchcode' => 'varchar(4) NULL'},
188 aqbudget => { 'branchcode' => 'varchar(4) NULL'},
189 auth_header => { 'marc' => 'BLOB NOT NULL', 'linkid' => 'BIGINT(20) NULL'},
190 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'},
191 statistics => { 'associatedborrower' => 'integer'},
192 # tablename => { 'field' => 'fieldtype' },
195 my %dropable_table = (
196 sessionqueries => 'sessionqueries',
197 marcrecorddone => 'marcrecorddone',
199 itemsprices => 'itemsprices',
200 biblioanalysis => 'biblioanalysis',
202 # tablename => 'tablename',
205 my %uselessfields = (
206 # tablename => "field1,field2",
207 borrowers => "suburb,altstreetaddress,altsuburb,altcity,studentnumber,school,area,preferredcont,altcp",
208 deletedborrowers=> "suburb,altstreetaddress,altsuburb,altcity,studentnumber,school,area,preferredcont,altcp",
210 # the other hash contains other actions that can't be done elsewhere. they are done
211 # either BEFORE of AFTER everything else, depending on "when" entry (default => AFTER)
213 # The tabledata hash contains data that should be in the tables.
214 # The uniquefieldrequired hash entry is used to determine which (if any) fields
215 # must not exist in the table for this row to be inserted. If the
216 # uniquefieldrequired entry is already in the table, the existing data is not
217 # modified, unless the forceupdate hash entry is also set. Fields in the
218 # anonymous "forceupdate" hash will be forced to be updated to the default
219 # values given in the %tabledata hash.
223 # { uniquefielrequired => 'fieldname', # the primary key in the table
224 # fieldname => fieldvalue,
225 # fieldname2 => fieldvalue2,
228 systempreferences => [
230 uniquefieldrequired => 'variable',
231 variable => 'Activate_Log',
233 forceupdate => { 'explanation' => 1,
235 explanation => 'Turn Log Actions on DB On an Off',
239 uniquefieldrequired => 'variable',
240 variable => 'IndependantBranches',
242 forceupdate => { 'explanation' => 1,
244 explanation => 'Turn Branch independancy management On an Off',
248 uniquefieldrequired => 'variable',
249 variable => 'ReturnBeforeExpiry',
251 forceupdate => { 'explanation' => 1,
253 explanation => 'If Yes, Returndate on issuing can\'t be after borrower card expiry',
258 uniquefieldrequired => 'variable',
259 variable => 'opacstylesheet',
266 'Enter a complete URL to use an alternate layout stylesheet in OPAC',
270 uniquefieldrequired => 'variable',
271 variable => 'opaccolorstylesheet',
278 'Enter the name of the color stylesheet to use in the OPAC',
282 uniquefieldrequired => 'variable',
283 variable => 'opaclayoutstylesheet',
290 'Enter the name of the layout stylesheet to use in the OPAC',
295 uniquefieldrequired => 'variable',
296 variable => 'opacreadinghistory',
303 'Turn on/off display of Patron Reading History in OPAC',
307 uniquefieldrequired => 'variable',
308 variable => 'opaclanguagesdisplay',
315 'Turn on/off display of Change Language feature on OPAC',
319 uniquefieldrequired => 'variable',
320 variable => 'patronimages',
327 'Turn on/off display of patron images in Intranet and specify a file extension for images',
331 uniquefieldrequired => 'variable',
332 variable => 'intranetstylesheet',
339 'Enter a complete URL to use an alternate layout stylesheet in Intranet',
343 uniquefieldrequired => 'variable',
344 variable => 'intranetcolorstylesheet',
351 'Enter the name of the color stylesheet to use in Intranet',
355 uniquefieldrequired => 'variable',
356 variable => 'opacsmallimage',
363 'Enter a complete URL to an image, will be on top/left instead of the Koha logo',
367 uniquefieldrequired => 'variable',
368 variable => 'opaclargeimage',
375 'Enter a complete URL to an image, will be on the main page, instead of the Koha logo',
379 uniquefieldrequired => 'variable',
380 variable => 'delimiter',
386 explanation => 'separator for reports exported to spreadsheet',
390 uniquefieldrequired => 'variable',
392 value => 'OPENOFFICE.ORG',
399 'Define the default application for report exportations into files',
401 options => 'EXCEL|OPENOFFICE.ORG'
404 uniquefieldrequired => 'variable',
405 variable => 'Delimiter',
413 'Define the default separator character for report exportations into files',
415 options => ';|tabulation|,|/|\|#'
418 uniquefieldrequired => 'variable',
419 variable => 'SubscriptionHistory',
427 'Define the information level for serials history in OPAC',
429 options => 'simplified|full'
432 uniquefieldrequired => 'variable',
433 variable => 'hidelostitems',
439 explanation => 'show or hide "lost" items in OPAC.',
443 uniquefieldrequired => 'variable',
444 variable => 'IndependantBranches',
450 explanation => 'Turn Branch independency management On and Off',
454 uniquefieldrequired => 'variable',
455 variable => 'ReturnBeforeExpiry',
462 'If Yes, Returndate on issuing can\'t be after borrower card expiry',
466 uniquefieldrequired => 'variable',
467 variable => 'Disable_Dictionary',
473 explanation => 'Disables Dictionary buttons if set to yes',
477 uniquefieldrequired => 'variable',
478 variable => 'hide_marc',
485 'hide marc specific datas like subfield code & indicators to library',
489 uniquefieldrequired => 'variable',
490 variable => 'NotifyBorrowerDeparture',
497 'Delay before expiry where a notice is sent when issuing',
501 uniquefieldrequired => 'variable',
502 variable => 'OpacPasswordChange',
509 'Enable/Disable password change in OPAC (disable it when using LDAP auth)',
513 uniquefieldrequired => 'variable',
514 variable => 'OpacNav',
521 'Use HTML tabs to add navigational links to the left-hand navigational bar in OPAC',
526 uniquefieldrequired => 'variable',
527 variable => 'IntranetNav',
534 'Use HTML tabs to add navigational links to the left-hand navigational bar in Intranet',
540 uniquefieldrequired => 'variable',
541 variable => 'AnonSuggestions',
549 'Set to anonymous borrowernumber to enable Anonymous suggestions',
553 uniquefieldrequired => 'variable',
554 variable => 'MARCOrgCode',
562 'Your MARC Organization Code - http://www.loc.gov/marc/organizations/orgshome.html',
566 uniquefieldrequired => 'variable',
567 variable => 'AmazonContent',
575 'Turn On Amazon Content - You MUST set AmazonDevKey and AmazonAssocTag if enabled',
579 uniquefieldrequired => 'variable',
580 variable => 'AmazonDevKey',
588 'see: aws-portal.amazon.com/gp/aws/developer/registration/index.html',
592 uniquefieldrequired => 'variable',
593 variable => 'AmazonAssocTag',
601 'see: associates.amazon.com/gp/flex/associates/apply-login.html',
605 uniquefieldrequired => 'variable',
611 variable => 'TemplateEncoding',
612 value => 'iso-8859-1',
613 explanation => 'Specify the encoding to use in Templates',
615 options => 'iso-8859-1|utf-8'
619 uniquefieldrequired => 'variable',
620 variable => 'opaccredits',
628 'Put any HTML Credits at the bottom of the OPAC page',
634 uniquefieldrequired => 'variable',
635 variable => 'opacheader',
637 forceupdate => { 'explanation' => 1,
639 explanation => 'Enter HTML to be included as a custom header in the OPAC',
645 uniquefieldrequired => 'variable',
646 variable => 'IntranetBiblioDefaultView',
648 forceupdate => { 'explanation' => 1,
650 explanation => 'Define the default view of a biblio in the intranet. Can be either normal, marc, or ISBD',
652 options => 'normal|marc|isbd'
656 uniquefieldrequired => 'variable',
657 variable => 'opacbookbag',
659 forceupdate => { 'explanation' => 1,
661 explanation => 'Enable or disable display of biblio basket (book bag)',
666 uniquefieldrequired => 'variable',
667 variable => 'opacuserlogin',
669 forceupdate => { 'explanation' => 1,
671 explanation => 'Enable or disable display of user login features',
676 uniquefieldrequired => 'variable',
677 variable => 'serialsadditems',
685 'If set, a new item will be automatically added when receiving an issue',
689 uniquefieldrequired => 'variable',
690 variable => 'advancedMARCeditor',
698 "If set, the MARC editor won't show you tag/subfields description",
702 uniquefieldrequired => 'variable',
703 variable => 'z3950NormalizeAuthor',
711 "If set, Personnal Authorities will replace authors in biblio.author",
715 uniquefieldrequired => 'variable',
716 variable => 'z3950AuthorAuthFields',
717 value => '701,702,700',
724 "contains the MARC biblio tags of person authorities to fill biblio.author with when importing biblio",
728 uniquefieldrequired => 'variable',
729 variable => 'useDaysMode',
731 forceupdate => { 'explanation' => 1,
733 explanation => 'How to calculate return dates : Calendar means holidays will be controled, Days means the return date don\'t depend on holidays',
735 options => 'Calendar|Days'
738 uniquefieldrequired => 'variable',
739 variable => 'borrowerMandatoryField',
740 value => 'zipcode|surname',
741 forceupdate => { 'explanation' => 1,
743 explanation => 'List all mandatory fields for borrowers',
747 uniquefieldrequired => 'variable',
748 variable => 'borrowerRelationship',
749 value => 'father|mother,grand-mother',
750 forceupdate => { 'explanation' => 1,
752 explanation => 'The relationships between a guarantor & a guarantee (separated by | or ,)',
756 uniquefieldrequired => 'variable',
757 variable => 'ReservesMaxPickUpDelay',
759 forceupdate => { 'explanation' => 1,
761 explanation => 'Maximum delay to pick up a reserved document',
765 uniquefieldrequired => 'variable',
766 variable => 'TransfersMaxDaysWarning',
768 forceupdate => { 'explanation' => 1,
770 explanation => 'Max delay before considering the transfer has potentialy a problem',
774 uniquefieldrequired => 'variable',
775 variable => 'memberofinstitution',
777 forceupdate => { 'explanation' => 1,
779 explanation => 'Are your patrons members of institutions',
783 uniquefieldrequired => 'variable',
784 variable => 'ReadingHistory',
786 forceupdate => { 'explanation' => 1,
788 explanation => 'Allow reading record info retrievable from issues and oldissues tables',
792 uniquefieldrequired => 'variable',
793 variable => 'IssuingInProcess',
795 forceupdate => { 'explanation' => 1,
797 explanation => 'Allow no debt alert if the patron is issuing item that accumulate debt',
801 uniquefieldrequired => 'variable',
802 variable => 'AutomaticItemReturn',
804 forceupdate => { 'explanation' => 1,
806 explanation => 'This Variable allow or not to return automaticly to his homebranch',
810 uniquefieldrequired => 'variable',
811 variable => 'reviewson',
813 forceupdate => { 'explanation' => 1,
815 explanation => 'Allows patrons to submit reviews from the opac',
822 my %fielddefinitions = (
824 # { field => 'fieldname',
825 # type => 'fieldtype',
843 field => 'booksellerid',
853 field => 'listprice',
854 type => 'varchar(10)',
861 field => 'invoiceprice',
862 type => 'varchar(10)',
871 field => 'borrowernumber',
873 null => 'NULL', # can be null when a borrower is deleted and the foreign key rule executed
879 field => 'itemnumber',
881 null => 'NULL', # can be null when a borrower is deleted and the foreign key rule executed
888 { field => 'firstname',
892 { field => 'initials',
896 { field => 'B_email',
899 after => 'B_zipcode',
902 field => 'streetnumber', # street number (hidden if streettable table is empty)
908 field => 'streettype', # street table, list builded from a system table
911 after => 'streetnumber',
918 field => 'B_streetnumber', # street number (hidden if streettable table is empty)
924 field => 'B_streettype', # street table, list builded from a system table
927 after => 'B_streetnumber',
936 field => 'address2', # complement address
948 field => 'contactfirstname', # contact's firstname
951 after => 'contactname',
954 field => 'contacttitle', # contact's title
957 after => 'contactfirstname',
961 deletedborrowers => [
962 { field => 'firstname',
966 { field => 'initials',
970 { field => 'B_email',
973 after => 'B_zipcode',
976 field => 'streetnumber', # street number (hidden if streettable table is empty)
982 field => 'streettype', # street table, list builded from a system table
985 after => 'streetnumber',
992 field => 'B_streetnumber', # street number (hidden if streettable table is empty)
998 field => 'B_streettype', # street table, list builded from a system table
1001 after => 'B_streetnumber',
1004 field => 'phonepro',
1010 field => 'address2', # complement address
1016 field => 'emailpro',
1022 field => 'contactfirstname', # contact's firstname
1025 after => 'contactname',
1028 field => 'contacttitle', # contact's title
1031 after => 'contactfirstname',
1037 field => 'branchip',
1038 type => 'varchar(15)',
1045 field => 'branchprinter',
1046 type => 'varchar(100)',
1055 field => 'category_type',
1065 field => 'waitingdate',
1077 # { indexname => 'index detail'
1081 { indexname => 'shelfnumber',
1082 content => 'shelfnumber',
1084 { indexname => 'itemnumber',
1085 content => 'itemnumber',
1089 { indexname => 'biblionumber',
1090 content => 'biblionumber',
1094 { indexname => 'homebranch',
1095 content => 'homebranch',
1097 { indexname => 'holdingbranch',
1098 content => 'holdingbranch',
1102 { indexname => 'PRIMARY',
1108 { indexname => 'booksellerid',
1109 content => 'booksellerid',
1113 { indexname => 'basketno',
1114 content => 'basketno',
1117 aqorderbreakdown => [
1118 { indexname => 'ordernumber',
1119 content => 'ordernumber',
1121 { indexname => 'bookfundid',
1122 content => 'bookfundid',
1126 { indexname => 'PRIMARY',
1127 content => 'currency',
1133 my %foreign_keys = (
1135 # { key => 'the key in table' (must be indexed)
1136 # foreigntable => 'the foreigntable name', # (the parent)
1137 # foreignkey => 'the foreign key column(s)' # (in the parent)
1138 # onUpdate => 'CASCADE|SET NULL|NO ACTION| RESTRICT',
1139 # onDelete => 'CASCADE|SET NULL|NO ACTION| RESTRICT',
1143 { key => 'shelfnumber',
1144 foreigntable => 'bookshelf',
1145 foreignkey => 'shelfnumber',
1146 onUpdate => 'CASCADE',
1147 onDelete => 'CASCADE',
1149 { key => 'itemnumber',
1150 foreigntable => 'items',
1151 foreignkey => 'itemnumber',
1152 onUpdate => 'CASCADE',
1153 onDelete => 'CASCADE',
1156 # onDelete is RESTRICT on reference tables (branches, itemtype) as we don't want items to be
1157 # easily deleted, but branches/itemtype not too easy to empty...
1159 { key => 'biblionumber',
1160 foreigntable => 'biblio',
1161 foreignkey => 'biblionumber',
1162 onUpdate => 'CASCADE',
1163 onDelete => 'CASCADE',
1165 { key => 'itemtype',
1166 foreigntable => 'itemtypes',
1167 foreignkey => 'itemtype',
1168 onUpdate => 'CASCADE',
1169 onDelete => 'RESTRICT',
1173 { key => 'biblioitemnumber',
1174 foreigntable => 'biblioitems',
1175 foreignkey => 'biblioitemnumber',
1176 onUpdate => 'CASCADE',
1177 onDelete => 'CASCADE',
1179 { key => 'homebranch',
1180 foreigntable => 'branches',
1181 foreignkey => 'branchcode',
1182 onUpdate => 'CASCADE',
1183 onDelete => 'RESTRICT',
1185 { key => 'holdingbranch',
1186 foreigntable => 'branches',
1187 foreignkey => 'branchcode',
1188 onUpdate => 'CASCADE',
1189 onDelete => 'RESTRICT',
1192 additionalauthors => [
1193 { key => 'biblionumber',
1194 foreigntable => 'biblio',
1195 foreignkey => 'biblionumber',
1196 onUpdate => 'CASCADE',
1197 onDelete => 'CASCADE',
1201 { key => 'biblionumber',
1202 foreigntable => 'biblio',
1203 foreignkey => 'biblionumber',
1204 onUpdate => 'CASCADE',
1205 onDelete => 'CASCADE',
1209 { key => 'booksellerid',
1210 foreigntable => 'aqbooksellers',
1212 onUpdate => 'CASCADE',
1213 onDelete => 'RESTRICT',
1217 { key => 'basketno',
1218 foreigntable => 'aqbasket',
1219 foreignkey => 'basketno',
1220 onUpdate => 'CASCADE',
1221 onDelete => 'CASCADE',
1223 { key => 'biblionumber',
1224 foreigntable => 'biblio',
1225 foreignkey => 'biblionumber',
1226 onUpdate => 'SET NULL',
1227 onDelete => 'SET NULL',
1231 { key => 'listprice',
1232 foreigntable => 'currency',
1233 foreignkey => 'currency',
1234 onUpdate => 'CASCADE',
1235 onDelete => 'CASCADE',
1237 { key => 'invoiceprice',
1238 foreigntable => 'currency',
1239 foreignkey => 'currency',
1240 onUpdate => 'CASCADE',
1241 onDelete => 'CASCADE',
1244 aqorderbreakdown => [
1245 { key => 'ordernumber',
1246 foreigntable => 'aqorders',
1247 foreignkey => 'ordernumber',
1248 onUpdate => 'CASCADE',
1249 onDelete => 'CASCADE',
1251 { key => 'bookfundid',
1252 foreigntable => 'aqbookfund',
1253 foreignkey => 'bookfundid',
1254 onUpdate => 'CASCADE',
1255 onDelete => 'CASCADE',
1258 branchtransfers => [
1259 { key => 'frombranch',
1260 foreigntable => 'branches',
1261 foreignkey => 'branchcode',
1262 onUpdate => 'CASCADE',
1263 onDelete => 'CASCADE',
1265 { key => 'tobranch',
1266 foreigntable => 'branches',
1267 foreignkey => 'branchcode',
1268 onUpdate => 'CASCADE',
1269 onDelete => 'CASCADE',
1271 { key => 'itemnumber',
1272 foreigntable => 'items',
1273 foreignkey => 'itemnumber',
1274 onUpdate => 'CASCADE',
1275 onDelete => 'CASCADE',
1279 { key => 'categorycode',
1280 foreigntable => 'categories',
1281 foreignkey => 'categorycode',
1282 onUpdate => 'CASCADE',
1283 onDelete => 'CASCADE',
1285 { key => 'itemtype',
1286 foreigntable => 'itemtypes',
1287 foreignkey => 'itemtype',
1288 onUpdate => 'CASCADE',
1289 onDelete => 'CASCADE',
1292 issues => [ # constraint is SET NULL : when a borrower or an item is deleted, we keep the issuing record
1294 { key => 'borrowernumber',
1295 foreigntable => 'borrowers',
1296 foreignkey => 'borrowernumber',
1297 onUpdate => 'SET NULL',
1298 onDelete => 'SET NULL',
1300 { key => 'itemnumber',
1301 foreigntable => 'items',
1302 foreignkey => 'itemnumber',
1303 onUpdate => 'SET NULL',
1304 onDelete => 'SET NULL',
1308 { key => 'borrowernumber',
1309 foreigntable => 'borrowers',
1310 foreignkey => 'borrowernumber',
1311 onUpdate => 'CASCADE',
1312 onDelete => 'CASCADE',
1314 { key => 'biblionumber',
1315 foreigntable => 'biblio',
1316 foreignkey => 'biblionumber',
1317 onUpdate => 'CASCADE',
1318 onDelete => 'CASCADE',
1320 { key => 'itemnumber',
1321 foreigntable => 'items',
1322 foreignkey => 'itemnumber',
1323 onUpdate => 'CASCADE',
1324 onDelete => 'CASCADE',
1326 { key => 'branchcode',
1327 foreigntable => 'branches',
1328 foreignkey => 'branchcode',
1329 onUpdate => 'CASCADE',
1330 onDelete => 'CASCADE',
1333 borrowers => [ # foreign keys are RESTRICT as we don't want to delete borrowers when a branch is deleted
1334 # but prevent deleting a branch as soon as it has 1 borrower !
1335 { key => 'categorycode',
1336 foreigntable => 'categories',
1337 foreignkey => 'categorycode',
1338 onUpdate => 'RESTRICT',
1339 onDelete => 'RESTRICT',
1341 { key => 'branchcode',
1342 foreigntable => 'branches',
1343 foreignkey => 'branchcode',
1344 onUpdate => 'RESTRICT',
1345 onDelete => 'RESTRICT',
1348 deletedborrowers => [ # foreign keys are RESTRICT as we don't want to delete borrowers when a branch is deleted
1349 # but prevent deleting a branch as soon as it has 1 borrower !
1350 { key => 'categorycode',
1351 foreigntable => 'categories',
1352 foreignkey => 'categorycode',
1353 onUpdate => 'RESTRICT',
1354 onDelete => 'RESTRICT',
1356 { key => 'branchcode',
1357 foreigntable => 'branches',
1358 foreignkey => 'branchcode',
1359 onUpdate => 'RESTRICT',
1360 onDelete => 'RESTRICT',
1364 { key => 'borrowernumber',
1365 foreigntable => 'borrowers',
1366 foreignkey => 'borrowernumber',
1367 onUpdate => 'CASCADE',
1368 onDelete => 'CASCADE',
1370 { key => 'itemnumber',
1371 foreigntable => 'items',
1372 foreignkey => 'itemnumber',
1373 onUpdate => 'SET NULL',
1374 onDelete => 'SET NULL',
1377 auth_tag_structure => [
1378 { key => 'authtypecode',
1379 foreigntable => 'auth_types',
1380 foreignkey => 'authtypecode',
1381 onUpdate => 'CASCADE',
1382 onDelete => 'CASCADE',
1385 # FIXME : don't constraint auth_*_table and auth_word, as they may be replaced by zebra
1390 my %column_change = (
1394 from => 'emailaddress',
1399 from => 'streetaddress',
1401 after => 'initials',
1404 from => 'faxnumber',
1409 from => 'textmessaging',
1415 to => 'contactnote',
1416 after => 'opacnote',
1419 from => 'physstreet',
1424 from => 'streetcity',
1426 after => 'B_address',
1439 from => 'homezipcode',
1446 after => 'B_zipcode',
1451 after => 'dateenrolled',
1454 from => 'guarantor',
1455 to => 'guarantorid',
1456 after => 'contactname',
1459 from => 'textmessaging',
1465 to => 'contactnotes',
1466 after => 'opacnotes',
1469 from => 'altrelationship',
1470 to => 'relationship',
1471 after => 'borrowernotes',
1475 deletedborrowers => [
1477 from => 'emailaddress',
1482 from => 'streetaddress',
1484 after => 'initials',
1487 from => 'faxnumber',
1492 from => 'textmessaging',
1498 to => 'contactnote',
1499 after => 'opacnote',
1502 from => 'physstreet',
1507 from => 'streetcity',
1509 after => 'B_address',
1522 from => 'homezipcode',
1529 after => 'B_zipcode',
1534 after => 'dateenrolled',
1537 from => 'guarantor',
1538 to => 'guarantorid',
1539 after => 'contactname',
1542 from => 'textmessaging',
1548 to => 'contactnotes',
1549 after => 'opacnotes',
1552 from => 'altrelationship',
1553 to => 'relationship',
1554 after => 'borrowernotes',
1560 foreach my $table (keys %column_change) {
1561 $sth = $dbh->prepare("show columns from $table");
1564 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1566 $types{$column}->{type} ="$type";
1567 $types{$column}->{null} = "$null";
1568 $types{$column}->{key} = "$key";
1569 $types{$column}->{default} = "$default";
1570 $types{$column}->{extra} = "$extra";
1572 my $tablerows = $column_change{$table};
1573 foreach my $row ( @$tablerows ) {
1574 if ($types{$row->{from}}->{type}) {
1575 print "altering $table $row->{from} to $row->{to}\n";
1576 # ALTER TABLE `borrowers` CHANGE `faxnumber` `fax` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
1577 # alter table `borrowers` change `faxnumber` `fax` type text null after phone
1579 "alter table `$table` change `$row->{from}` `$row->{to}` $types{$row->{from}}->{type} ".
1580 ($types{$row->{from}}->{null} eq 'YES'?" NULL":" NOT NULL").
1581 ($types{$row->{from}}->{default}?" default ".$types{$row->{from}}->{default}:"").
1582 "$types{$row->{from}}->{extra} after $row->{after} ";
1589 #-------------------
1594 # Get version of MySQL database engine.
1595 my $mysqlversion = `mysqld --version`;
1596 $mysqlversion =~ /Ver (\S*) /;
1598 if ( $mysqlversion ge '3.23' ) {
1599 print "Could convert to MyISAM database tables...\n" unless $silent;
1602 #---------------------------------
1605 # Collect all tables into a list
1606 $sth = $dbh->prepare("show tables");
1608 while ( my ($table) = $sth->fetchrow ) {
1609 $existingtables{$table} = 1;
1612 # Now add any missing tables
1613 foreach $table ( keys %requiretables ) {
1614 unless ( $existingtables{$table} ) {
1615 print "Adding $table table...\n" unless $silent;
1616 my $sth = $dbh->prepare("create table $table $requiretables{$table}");
1619 print "Error : $sth->errstr \n";
1625 # now drop useless tables
1626 foreach $table ( keys %dropable_table ) {
1627 if ( $existingtables{$table} ) {
1628 print "Dropping unused table $table\n" if $debug and not $silent;
1629 $dbh->do("drop table $table");
1631 print "Error : $dbh->errstr \n";
1636 #---------------------------------
1639 foreach $table ( keys %requirefields ) {
1640 print "Check table $table\n" if $debug and not $silent;
1641 $sth = $dbh->prepare("show columns from $table");
1644 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1646 $types{$column} = $type;
1648 foreach $column ( keys %{ $requirefields{$table} } ) {
1649 print " Check column $column [$types{$column}]\n"
1650 if $debug and not $silent;
1651 if ( !$types{$column} ) {
1653 # column doesn't exist
1654 print "Adding $column field to $table table...\n" unless $silent;
1655 $query = "alter table $table
1656 add column $column " . $requirefields{$table}->{$column};
1657 print "Execute: $query\n" if $debug;
1658 my $sti = $dbh->prepare($query);
1661 print "**Error : $sti->errstr \n";
1668 foreach $table ( keys %fielddefinitions ) {
1669 print "Check table $table\n" if $debug;
1670 $sth = $dbh->prepare("show columns from $table");
1673 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1675 $definitions->{$column}->{type} = $type;
1676 $definitions->{$column}->{null} = $null;
1677 $definitions->{$column}->{null} = 'NULL' if $null eq 'YES';
1678 $definitions->{$column}->{key} = $key;
1679 $definitions->{$column}->{default} = $default;
1680 $definitions->{$column}->{extra} = $extra;
1682 my $fieldrow = $fielddefinitions{$table};
1683 foreach my $row (@$fieldrow) {
1684 my $field = $row->{field};
1685 my $type = $row->{type};
1686 my $null = $row->{null};
1687 # $null = 'YES' if $row->{null} eq 'NULL';
1688 my $key = $row->{key};
1689 my $default = $row->{default};
1690 my $null = $row->{null};
1691 # $default="''" unless $default;
1692 my $extra = $row->{extra};
1693 my $def = $definitions->{$field};
1694 my $after = ($row->{after}?" after ".$row->{after}:"");
1696 unless ( $type eq $def->{type}
1697 && $null eq $def->{null}
1698 && $key eq $def->{key}
1699 && $extra eq $def->{extra} )
1701 if ( $null eq '' ) {
1704 if ( $key eq 'PRI' ) {
1705 $key = 'PRIMARY KEY';
1707 unless ( $extra eq 'auto_increment' ) {
1711 # if it's a new column use "add", if it's an old one, use "change".
1713 if ($definitions->{$field}->{type}) {
1714 $action="change $field"
1718 # if it's a primary key, drop the previous pk, before altering the table
1720 if ($key ne 'PRIMARY KEY') {
1721 $sth =$dbh->prepare("alter table $table $action $field $type $null $key $extra default ? $after");
1723 $sth =$dbh->prepare("alter table $table drop primary key, $action $field $type $null $key $extra default ? $after");
1725 $sth->execute($default);
1726 print " alter or create $field in $table\n" unless $silent;
1731 # Populate tables with required data
1733 # synch table and deletedtable.
1734 foreach my $table ( ( 'borrowers', 'items', 'biblio', 'biblioitems' ) ) {
1735 my %deletedborrowers;
1736 print "synch'ing $table\n";
1737 $sth = $dbh->prepare("show columns from deleted$table");
1739 while ( my ( $column, $type, $null, $key, $default, $extra ) =
1742 $deletedborrowers{$column} = 1;
1744 $sth = $dbh->prepare("show columns from $table");
1747 while ( my ( $column, $type, $null, $key, $default, $extra ) =
1750 unless ( $deletedborrowers{$column} ) {
1751 my $newcol = "alter table deleted$table add $column $type";
1752 if ( $null eq 'YES' ) {
1753 $newcol .= " NULL ";
1756 $newcol .= " NOT NULL ";
1758 $newcol .= "default $default" if $default;
1759 $newcol .= " after $previous" if $previous;
1760 $previous = $column;
1761 print "creating column $column\n";
1767 foreach my $table ( keys %tabledata ) {
1768 print "Checking for data required in table $table...\n" unless $silent;
1769 my $tablerows = $tabledata{$table};
1770 foreach my $row (@$tablerows) {
1771 my $uniquefieldrequired = $row->{uniquefieldrequired};
1772 my $uniquevalue = $row->{$uniquefieldrequired};
1773 my $forceupdate = $row->{forceupdate};
1776 "select $uniquefieldrequired from $table where $uniquefieldrequired=?"
1778 $sth->execute($uniquevalue);
1780 foreach my $field (keys %$forceupdate) {
1781 if ($forceupdate->{$field}) {
1782 my $sth=$dbh->prepare("update systempreferences set $field=? where $uniquefieldrequired=?");
1783 $sth->execute($row->{$field}, $uniquevalue);
1787 print "Adding row to $table: " unless $silent;
1791 foreach my $field ( keys %$row ) {
1792 next if $field eq 'uniquefieldrequired';
1793 next if $field eq 'forceupdate';
1794 my $value = $row->{$field};
1795 push @values, $value;
1796 print " $field => $value" unless $silent;
1797 $fieldlist .= "$field,";
1798 $placeholders .= "?,";
1800 print "\n" unless $silent;
1801 $fieldlist =~ s/,$//;
1802 $placeholders =~ s/,$//;
1805 "insert into $table ($fieldlist) values ($placeholders)");
1806 $sth->execute(@values);
1812 # check indexes and create them when needed
1814 print "Checking for index required...\n" unless $silent;
1815 foreach my $table ( keys %indexes ) {
1817 # read all indexes from $table
1819 $sth = $dbh->prepare("show index from $table");
1821 my %existingindexes;
1822 while ( my ( $table, $non_unique, $key_name, $Seq_in_index, $Column_name, $Collation, $cardinality, $sub_part, $Packed, $comment ) = $sth->fetchrow ) {
1823 $existingindexes{$key_name} = 1;
1825 # read indexes to check
1826 my $tablerows = $indexes{$table};
1827 foreach my $row (@$tablerows) {
1828 my $key_name=$row->{indexname};
1829 if ($existingindexes{$key_name} eq 1) {
1830 # print "$key_name existing";
1832 print "\tCreating index $key_name in $table\n";
1834 if ($row->{indexname} eq 'PRIMARY') {
1835 $sql = "alter table $table ADD PRIMARY KEY ($row->{content})";
1837 $sql = "alter table $table ADD INDEX $key_name ($row->{content}) $row->{type}";
1840 print "Error $sql : $dbh->err \n" if $dbh->err;
1846 # check foreign keys and create them when needed
1848 print "Checking for foreign keys required...\n" unless $silent;
1849 foreach my $table ( keys %foreign_keys ) {
1851 # read all indexes from $table
1853 $sth = $dbh->prepare("show table status like '$table'");
1855 my $stat = $sth->fetchrow_hashref;
1856 # read indexes to check
1857 my $tablerows = $foreign_keys{$table};
1858 foreach my $row (@$tablerows) {
1859 my $foreign_table=$row->{foreigntable};
1860 if ($stat->{'Comment'} =~/$foreign_table/) {
1861 # print "$foreign_table existing\n";
1863 print "\tCreating foreign key $foreign_table in $table\n";
1864 # first, drop any orphan value in child table
1865 if ($row->{onDelete} ne "RESTRICT") {
1866 my $sql = "delete from $table where $row->{key} not in (select $row->{foreignkey} from $row->{foreigntable})";
1868 print "SQL ERROR: $sql : $dbh->err \n" if $dbh->err;
1870 my $sql="alter table $table ADD FOREIGN KEY $row->{key} ($row->{key}) REFERENCES $row->{foreigntable} ($row->{foreignkey})";
1871 $sql .= " on update ".$row->{onUpdate} if $row->{onUpdate};
1872 $sql .= " on delete ".$row->{onDelete} if $row->{onDelete};
1875 print "====================
1876 An error occured during :
1878 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).
1879 You can find those values with select
1880 \t$table.* from $table where $row->{key} not in (select $row->{foreignkey} from $row->{foreigntable})
1881 ====================\n
1892 # create frameworkcode row in biblio table & fill it with marc_biblio.frameworkcode.
1895 # 1st, get how many biblio we will have to do...
1896 $sth = $dbh->prepare('select count(*) from marc_biblio');
1898 my ($totaltodo) = $sth->fetchrow;
1900 $sth = $dbh->prepare("show columns from biblio");
1903 my $bibliofwexist=0;
1904 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ){
1905 $bibliofwexist=1 if $column eq 'frameworkcode';
1907 unless ($bibliofwexist) {
1908 print "moving biblioframework to biblio table\n";
1909 $dbh->do('ALTER TABLE `biblio` ADD `frameworkcode` VARCHAR( 4 ) NOT NULL AFTER `biblionumber`');
1910 $sth = $dbh->prepare('select biblionumber,frameworkcode from marc_biblio');
1912 my $sth_update = $dbh->prepare('update biblio set frameworkcode=? where biblionumber=?');
1914 while (my ($biblionumber,$frameworkcode) = $sth->fetchrow) {
1915 $sth_update->execute($frameworkcode,$biblionumber);
1917 print "\r$totaldone / $totaltodo" unless ($totaldone % 100);
1923 # moving MARC data from marc_subfield_table to biblioitems.marc
1925 $sth = $dbh->prepare("show columns from biblioitems");
1929 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ){
1930 $marcdone=1 if ($type eq 'blob' && $column eq 'marc') ;
1932 unless ($marcdone) {
1933 print "moving MARC record to biblioitems table\n";
1934 # changing marc field type
1935 $dbh->do('ALTER TABLE `biblioitems` CHANGE `marc` `marc` BLOB NULL DEFAULT NULL ');
1936 # adding marc xml, just for convenience
1937 $dbh->do('ALTER TABLE `biblioitems` ADD `marcxml` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ');
1938 # moving data from marc_subfield_value to biblio
1939 $sth = $dbh->prepare('select bibid,biblionumber from marc_biblio');
1941 my $sth_update = $dbh->prepare('update biblioitems set marc=?, marcxml=? where biblionumber=?');
1943 while (my ($bibid,$biblionumber) = $sth->fetchrow) {
1944 my $record = MARCgetbiblio($dbh,$bibid);
1945 #Force UTF-8 in record leader
1946 $record->encoding('UTF-8');
1947 print $record->as_formatted if ($biblionumber==3902);
1948 $sth_update->execute($record->as_usmarc(),$record->as_xml_record(),$biblionumber);
1950 print "\r$totaldone / $totaltodo" unless ($totaldone % 100);
1956 # at last, remove useless fields
1957 foreach $table ( keys %uselessfields ) {
1958 my @fields = split /,/, $uselessfields{$table};
1961 foreach my $fieldtodrop (@fields) {
1962 $fieldtodrop =~ s/\t//g;
1963 $fieldtodrop =~ s/\n//g;
1965 $sth = $dbh->prepare("show columns from $table");
1967 while ( my ( $column, $type, $null, $key, $default, $extra ) =
1970 $exists = 1 if ( $column eq $fieldtodrop );
1973 print "deleting $fieldtodrop field in $table...\n" unless $silent;
1974 my $sth = $dbh->prepare("alter table $table drop $fieldtodrop");
1981 # MOVE all tables TO UTF-8 and innoDB
1982 $sth = $dbh->prepare("show table status");
1984 while ( my $table = $sth->fetchrow_hashref ) {
1985 # if ($table->{Engine} ne 'InnoDB') {
1986 # $dbh->do("ALTER TABLE $table->{Name} TYPE = innodb");
1987 # print "moving $table->{Name} to InnoDB\n";
1989 unless ($table->{Collation} =~ /^utf8/) {
1990 $dbh->do("ALTER TABLE $table->{Name} CONVERT TO CHARACTER SET utf8");
1991 $dbh->do("ALTER TABLE $table->{Name} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
1992 # 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 !
1993 print "moving $table->{Name} to utf8\n";
2001 # those 2 subs are a copy of Biblio.pm, version 2.2.4
2002 # they are useful only once, for moving from 2.2 to 3.0
2003 # the MARCgetbiblio & MARCgetitem subs in Biblio.pm
2004 # are still here, but uses other tables
2005 # (the ones that are filled by updatedatabase !)
2010 # Returns MARC::Record of the biblio passed in parameter.
2011 my ( $dbh, $bibid ) = @_;
2012 my $record = MARC::Record->new();
2017 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
2018 from marc_subfield_table
2019 where bibid=? order by tag,tagorder,subfieldorder
2024 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
2025 $sth->execute($bibid);
2026 my $prevtagorder = 1;
2027 my $prevtag = 'XXX';
2029 my $field; # for >=10 tags
2030 my $prevvalue; # for <10 tags
2031 while ( my $row = $sth->fetchrow_hashref ) {
2033 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
2034 $sth2->execute( $row->{'valuebloblink'} );
2035 my $row2 = $sth2->fetchrow_hashref;
2037 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
2039 if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
2040 $previndicator .= " ";
2041 if ( $prevtag < 10 ) {
2042 if ($prevtag ne '000') {
2043 $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue ) unless $prevtag eq "XXX"; # ignore the 1st loop
2045 $record->leader(sprintf("%24s",$prevvalue));
2049 $record->add_fields($field) unless $prevtag eq "XXX";
2052 $prevtagorder = $row->{tagorder};
2053 $prevtag = $row->{tag};
2054 $previndicator = $row->{tag_indicator};
2055 if ( $row->{tag} < 10 ) {
2056 $prevvalue = $row->{subfieldvalue};
2059 $field = MARC::Field->new(
2060 ( sprintf "%03s", $prevtag ),
2061 substr( $row->{tag_indicator} . ' ', 0, 1 ),
2062 substr( $row->{tag_indicator} . ' ', 1, 1 ),
2063 $row->{'subfieldcode'},
2064 $row->{'subfieldvalue'}
2069 if ( $row->{tag} < 10 ) {
2070 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
2071 $row->{'subfieldvalue'} );
2074 $field->add_subfields( $row->{'subfieldcode'},
2075 $row->{'subfieldvalue'} );
2077 $prevtag = $row->{tag};
2078 $previndicator = $row->{tag_indicator};
2082 # the last has not been included inside the loop... do it now !
2083 if ( $prevtag ne "XXX" )
2084 { # check that we have found something. Otherwise, prevtag is still XXX and we
2085 # must return an empty record, not make MARC::Record fail because we try to
2086 # create a record with XXX as field :-(
2087 if ( $prevtag < 10 ) {
2088 $record->add_fields( $prevtag, $prevvalue );
2092 # my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
2093 $record->add_fields($field);
2101 # Returns MARC::Record of the biblio passed in parameter.
2102 my ( $dbh, $bibid, $itemnumber ) = @_;
2103 my $record = MARC::Record->new();
2105 # search MARC tagorder
2108 "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=?"
2110 $sth2->execute( $bibid, $itemnumber );
2111 my ($tagorder) = $sth2->fetchrow_array();
2113 #---- TODO : the leader is missing
2116 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
2117 from marc_subfield_table
2118 where bibid=? and tagorder=? order by subfieldcode,subfieldorder
2123 "select subfieldvalue from marc_blob_subfield where blobidlink=?");
2124 $sth->execute( $bibid, $tagorder );
2125 while ( my $row = $sth->fetchrow_hashref ) {
2126 if ( $row->{'valuebloblink'} ) { #---- search blob if there is one
2127 $sth2->execute( $row->{'valuebloblink'} );
2128 my $row2 = $sth2->fetchrow_hashref;
2130 $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
2132 if ( $record->field( $row->{'tag'} ) ) {
2135 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
2136 #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
2137 if ( length( $row->{'tag'} ) < 3 ) {
2138 $row->{'tag'} = "0" . $row->{'tag'};
2140 $field = $record->field( $row->{'tag'} );
2143 $field->add_subfields( $row->{'subfieldcode'},
2144 $row->{'subfieldvalue'} );
2145 $record->delete_field($field);
2146 $record->add_fields($field);
2150 if ( length( $row->{'tag'} ) < 3 ) {
2151 $row->{'tag'} = "0" . $row->{'tag'};
2154 MARC::Field->new( $row->{'tag'}, " ", " ",
2155 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
2156 $record->add_fields($temp);
2167 # Revision 1.154 2006/07/17 12:28:45 toins
2170 # Revision 1.153 2006/07/04 14:36:52 toins
2171 # Head & rel_2_2 merged
2173 # Revision 1.152 2006/06/27 09:26:37 btoumi
2174 # modify (initials,phone ) fields property in borrowers and deletedborrowers table
2176 # Revision 1.151 2006/06/22 10:33:14 btoumi
2177 # sorry i forget deletedborrowers table
2178 # modify firstname field from deletedborrowers table
2180 # Revision 1.149 2006/06/20 22:35:47 rangi
2181 # Code to allow the associated borrowers to work
2183 # Revision 1.148 2006/06/17 22:12:01 rangi
2184 # Adding id field to reviews table
2186 # Revision 1.147 2006/06/17 03:36:41 rangi
2187 # Table definition for the reviews table
2189 # Revision 1.146 2006/06/17 03:29:41 rangi
2190 # Variable to allow librarians to switch reviews on or off
2192 # Revision 1.145 2006/06/16 09:45:02 btoumi
2193 # updatedatabase.pl: add change of borrowers table to deletedborrowers table
2194 # deletemem.pl: delete use of warn function
2196 # Revision 1.144 2006/06/08 15:36:31 alaurin
2197 # Add a new system preference 'AutomaticItemReturn' :
2199 # 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) .
2201 # switch off : the document stay in the holdingbranch ...
2204 # - comment C4::acquisition (not using in request.pl).
2205 # - correcting date in request.pl
2206 # -add the new call of function getbranches in request.pl
2208 # Revision 1.143 2006/06/07 02:02:47 bob_lyon
2209 # merging katipo changes...
2211 # adding new preference IssuingInProcess
2213 # Revision 1.142 2006/06/06 23:42:46 bob_lyon
2214 # Merging Katipo changes...
2216 # Adding new system pref where one can still retrieve a correct reading
2217 # record history if one has moved older data from issues to oldissues table
2218 # to speed up issues speed
2220 # Revision 1.141 2006/06/01 03:18:11 rangi
2221 # Adding a new column to the statistics table
2223 # Revision 1.140 2006/05/22 22:40:45 rangi
2224 # Adding new systempreference allowing for the library to add borrowers to institutions (rest homes, parishes, schools, classes etc).
2226 # Revision 1.139 2006/05/19 19:31:29 tgarip1957
2227 # Added new fields to auth_header and auth_subfield_table to allow ZEBRA use of authorities and new MARC framework like structure.
2228 # 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
2230 # Revision 1.138 2006/05/19 16:51:44 alaurin
2231 # update database for :
2232 # - new feature ip and printer management
2233 # adding two fields in branches table (branchip,branchprinter)
2235 # - 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
2237 # new system preference :
2238 # - ReservesMaxPickUpDelay : Maximum delay to pick up a reserved document
2239 # TransfersMaxDaysWarning : Max delay before considering the transfer as potentialy a problem
2241 # Revision 1.137 2006/04/18 09:36:36 plg
2242 # bug fixed: typo fixed in labels and labels_conf tables creation query.
2244 # Revision 1.136 2006/04/17 21:55:33 sushi
2245 # Added 'labels' and 'labels_conf' tables, for spine lable tool.
2247 # Revision 1.135 2006/04/15 02:37:03 tgarip1957
2248 # Marc record should be set to UTF-8 in leader.Force it.
2249 # XML should be with<record> wrappers
2251 # Revision 1.134 2006/04/14 09:37:29 tipaul
2252 # improvements from SAN Ouest Provence :
2253 # * introducing a category_type into categories. It can be A (adult), C (children), P (Professionnal), I (institution/organisation).
2254 # * each category_type has it's own forms to create members.
2255 # * the borrowers table has been heavily modified (many fields changed), to get something more logic & readable
2256 # * reintroducing guarantor/guanrantee system that is now independant from hardcoded C/A for categories
2257 # * updating templates to fit template rules
2259 # (see mail feb, 17 on koha-devel "new features for borrowers" for more details)
2261 # Revision 1.133 2006/04/13 08:36:42 plg
2262 # new: function C4::Date::get_date_format_string_for_DHTMLcalendar based on
2263 # the system preference prefered date format.
2265 # improvement: book fund list and budget list screen redesigned. Filters on
2266 # each field. Columns are not sortable yet. Using DHTML Calendar to fill date
2267 # fields instead of manual filling. Pagination system. From the book fund
2268 # list, you can reach the budget list, filtered on a book fund, or not. A
2269 # budget can be added only from book fund list screen.
2271 # bug fixed: branchcode was missing in table aqbudget.
2273 # bug fixed: when setting a branchcode to a book fund, all associated budgets
2274 # move to this branchcode.
2276 # modification: when adding/modifying budget/fund, MySQL specific "REPLACE..."
2277 # statements replaced by standard SQL compliant statement.
2279 # bug fixed: when adding/modifying a budget, if the book fund is associated to
2280 # a branch, the branch selection is disabled and set to the book fund branch.
2282 # Revision 1.132 2006/04/06 12:37:05 hdl
2283 # Bugfixing : aqbookfund needed a field.
2285 # Revision 1.131 2006/03/03 17:02:22 tipaul
2286 # commit for holidays and news management.
2287 # (some forgotten files)
2289 # Revision 1.130 2006/03/03 16:35:21 tipaul
2290 # commit for holidays and news management.
2292 # Contrib from Tümer Garip (from Turkey) :
2294 # 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 :
2295 # - single day : only this day is closed
2296 # - repet weekly (like "sunday") : the day is holiday every week
2297 # - repet yearly (like "July, 4") : this day is closed every year.
2299 # You can also put exception :
2300 # - sunday is holiday, but "2006 March, 5th" the library will be open
2302 # 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.
2304 # Revision 1.129 2006/02/27 18:19:33 hdl
2305 # New table used in overduerules.pl tools page.
2307 # Revision 1.128 2006/01/25 15:16:06 tipaul
2309 # * removing useless tables
2310 # * adding useful indexes
2311 # * altering some columns definitions
2312 # * The goal being to have updater working fine for foreign keys.
2314 # 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
2316 # Revision 1.127 2006/01/24 17:57:17 tipaul
2317 # DB improvements : adding foreign keys on some tables. partial stuff done.
2319 # Revision 1.126 2006/01/06 16:39:42 tipaul
2320 # synch'ing head and rel_2_2 (from 2.2.5, including npl templates)
2321 # Seems not to break too many things, but i'm probably wrong here.
2322 # at least, new features/bugfixes from 2.2.5 are here (tested on some features on my head local copy)
2324 # - removing useless directories (koha-html and koha-plucene)
2326 # Revision 1.125 2006/01/04 15:54:55 tipaul
2327 # utf8 is a : go for beta test in HEAD.
2328 # some explanations :
2329 # - 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.
2330 # - *-top.inc will show the pages in utf8
2331 # - 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.
2332 # - using marcxml field and no more the iso2709 raw marc biblioitems.marc field.
2334 # Revision 1.124 2005/10/27 12:09:05 tipaul
2335 # new features for serial module :
2336 # - 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")
2337 # - 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).
2339 # Revision 1.123 2005/10/26 09:13:37 tipaul
2340 # big commit, still breaking things...
2342 # * synch with rel_2_2. Probably the last non manual synch, as rel_2_2 should not be modified deeply.
2343 # * code cleaning (cleaning warnings from perl -w) continued
2345 # Revision 1.122 2005/09/02 14:18:38 tipaul
2346 # new feature : image for itemtypes.
2348 # * run updater/updatedatabase to create imageurl field in itemtypes.
2349 # * 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)
2350 # * go to OPAC, and search something. In the result list, you now have the picture instead of the text itemtype.
2352 # Revision 1.121 2005/08/24 08:49:03 hdl
2353 # Adding a note field in serial table.
2354 # This will allow librarian to mention a note on a peculiar waiting serial number.
2356 # Revision 1.120 2005/08/09 14:10:32 tipaul
2357 # 1st commit to go to zebra.
2358 # don't update your cvs if you want to have a working head...
2360 # this commit contains :
2361 # * 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...
2362 # * 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.
2363 # * other files : get rid of bibid and use biblionumber instead.
2366 # * does not do anything on zebra yet.
2367 # * if you rename marc_subfield_table, you can't search anymore.
2368 # * you can view a biblio & bibliodetails, go to MARC editor, but NOT save any modif.
2369 # * 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 ;-) )
2371 # 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
2372 # 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.
2374 # Revision 1.119 2005/08/04 16:07:58 tipaul
2375 # Synch really broke this script...
2377 # Revision 1.118 2005/08/04 16:02:55 tipaul
2378 # oops... error in synch between 2.2 and head
2380 # Revision 1.117 2005/08/04 14:24:39 tipaul
2381 # synch'ing 2.2 and head
2383 # Revision 1.116 2005/08/04 08:55:54 tipaul
2384 # Letters / alert system, continuing...
2386 # * adding a package Letters.pm, that manages Letters & alerts.
2387 # * 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)
2388 # * 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)
2389 # * 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.
2391 # Note that the system should be generic enough to manage any type of alert.
2392 # 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 ;-) )
2394 # Revision 1.115 2005/08/02 16:15:34 tipaul
2395 # adding 2 fields to letter system :
2396 # * module (acquisition, catalogue...) : it will be usefull to show the librarian only letters he may be interested by.
2397 # * title, that will be used as mail subject.
2399 # Revision 1.114 2005/07/28 15:10:13 tipaul
2400 # 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.
2401 # the letter table contains 3 fields :
2402 # * code => the code of the letter
2403 # * name => the complete name of the letter
2404 # * content => the complete text. It's a TEXT field type, so has no limits.
2406 # My next goal now is to work on point 2-I "serial issue alert"
2407 # 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.
2408 # (see mail on koha-devel, 2005/04/07)
2410 # The "serial issue alert" will be the 1st to use this letter system that probably needs some tweaking ;-)
2412 # Once it will be stabilised default letters (in any languages) could be added during installer to help the library begin with this new feature.
2414 # Revision 1.113 2005/07/28 08:38:41 tipaul
2415 # 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 :
2416 # * ReturnBeforeExpiry = yes => return date can't be after expiry date
2417 # * ReturnBeforeExpiry = no => return date can be after expiry date
2419 # Revision 1.112 2005/07/26 08:19:47 hdl
2420 # Adding IndependantBranches System preference variable in order to manage Branch independancy.
2422 # Revision 1.111 2005/07/25 15:35:38 tipaul
2423 # we have decided that moving to Koha 3.0 requires being already in Koha 2.2.x
2424 # So, the updatedatabase script can highly be cleaned (90% removed).
2425 # Let's play with the new Koha DB structure now ;-)