commit for holidays and news management.
[koha.git] / updater / updatedatabase
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Database Updater
6 # This script checks for required updates to the database.
7
8 # Part of the Koha Library Software www.koha.org
9 # Licensed under the GPL.
10
11 # Bugs/ToDo:
12 # - Would also be a good idea to offer to do a backup at this time...
13
14 # NOTE:  If you do something more than once in here, make it table driven.
15 use strict;
16
17 # CPAN modules
18 use DBI;
19 use Getopt::Long;
20 # Koha modules
21 use C4::Context;
22
23 use MARC::Record;
24 use MARC::File::XML;
25
26 # FIXME - The user might be installing a new database, so can't rely
27 # on /etc/koha.conf anyway.
28
29 my $debug = 0;
30
31 my (
32     $sth, $sti,
33     $query,
34     %existingtables,    # tables already in database
35     %types,
36     $table,
37     $column,
38     $type, $null, $key, $default, $extra,
39     $prefitem,          # preference item in systempreferences table
40 );
41
42 my $silent;
43 GetOptions(
44         's' =>\$silent
45         );
46 my $dbh = C4::Context->dbh;
47 print "connected to your DB. Checking & modifying it\n" unless $silent;
48 $|=1; # flushes output
49
50 #-------------------
51 # Defines
52
53 # Tables to add if they don't exist
54 my %requiretables = (
55     categorytable       => "(categorycode char(5) NOT NULL default '',
56                              description text default '',
57                              itemtypecodes text default '',
58                              PRIMARY KEY (categorycode)
59                             )",
60     subcategorytable       => "(subcategorycode char(5) NOT NULL default '',
61                              description text default '',
62                              itemtypecodes text default '',
63                              PRIMARY KEY (subcategorycode)
64                             )",
65     mediatypetable       => "(mediatypecode char(5) NOT NULL default '',
66                              description text default '',
67                              itemtypecodes text default '',
68                              PRIMARY KEY (mediatypecode)
69                             )",
70     action_logs         => "(
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` )
78                             )",
79         letter          => "(
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 '',
84                                         content text,
85                                         PRIMARY KEY  (module,code)
86                                 )",
87         alert           =>"(
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)
95                                 )",
96         opac_news => "(
97                                 `idnew` int(10) unsigned NOT NULL auto_increment,
98                                 `title` varchar(250) NOT NULL default '',
99                                 `new` text NOT NULL,
100                                 `lang` varchar(4) NOT NULL default '',
101                                 `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
102                                 PRIMARY KEY  (`idnew`)
103                                 )",
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,
112                                 PRIMARY KEY  (`id`)
113                                 )",
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,
123                                 PRIMARY KEY  (`id`)
124                                 )",
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`)
137                                         )",
138 );
139
140 my %requirefields = (
141         subscription => { 'letter' => 'char(20) NULL', 'distributedto' => 'text NULL'},
142         itemtypes => { 'imageurl' => 'char(200) NULL'},
143 #    tablename        => { 'field' => 'fieldtype' },
144 );
145
146 my %dropable_table = (
147         sessionqueries  => 'sessionqueries',
148         marcrecorddone  => 'marcrecorddone',
149         users                   => 'users',
150         itemsprices             => 'itemsprices',
151         biblioanalysis  => 'biblioanalysis',
152         borexp                  => 'borexp',
153 # tablename => 'tablename',
154 );
155
156 my %uselessfields = (
157 # tablename => "field1,field2",
158         );
159 # the other hash contains other actions that can't be done elsewhere. they are done
160 # either BEFORE of AFTER everything else, depending on "when" entry (default => AFTER)
161
162 # The tabledata hash contains data that should be in the tables.
163 # The uniquefieldrequired hash entry is used to determine which (if any) fields
164 # must not exist in the table for this row to be inserted.  If the
165 # uniquefieldrequired entry is already in the table, the existing data is not
166 # modified, unless the forceupdate hash entry is also set.  Fields in the
167 # anonymous "forceupdate" hash will be forced to be updated to the default
168 # values given in the %tabledata hash.
169
170 my %tabledata = (
171 # tablename => [
172 #       {       uniquefielrequired => 'fieldname', # the primary key in the table
173 #               fieldname => fieldvalue,
174 #               fieldname2 => fieldvalue2,
175 #       },
176 # ],
177     systempreferences => [
178                 {
179             uniquefieldrequired => 'variable',
180             variable            => 'Activate_Log',
181             value               => 'On',
182             forceupdate         => { 'explanation' => 1,
183                                      'type' => 1},
184             explanation         => 'Turn Log Actions on DB On an Off',
185             type                => 'YesNo',
186         },
187         {
188             uniquefieldrequired => 'variable',
189             variable            => 'IndependantBranches',
190             value               => 0,
191             forceupdate         => { 'explanation' => 1,
192                                      'type' => 1},
193             explanation         => 'Turn Branch independancy management On an Off',
194             type                => 'YesNo',
195         },
196                 {
197             uniquefieldrequired => 'variable',
198             variable            => 'ReturnBeforeExpiry',
199             value               => 'Off',
200             forceupdate         => { 'explanation' => 1,
201                                      'type' => 1},
202             explanation         => 'If Yes, Returndate on issuing can\'t be after borrower card expiry',
203             type                => 'YesNo',
204         },
205         {
206             uniquefieldrequired => 'variable',
207             variable            => 'opacstylesheet',
208             value               => '',
209             forceupdate         => { 'explanation' => 1,
210                                      'type' => 1},
211             explanation         => 'Enter a complete URL to use an alternate stylesheet in OPAC',
212             type                => 'free',
213         },
214         {
215             uniquefieldrequired => 'variable',
216             variable            => 'opacsmallimage',
217             value               => '',
218             forceupdate         => { 'explanation' => 1,
219                                      'type' => 1},
220             explanation         => 'Enter a complete URL to an image, will be on top/left instead of the Koha logo',
221             type                => 'free',
222         },
223         {
224             uniquefieldrequired => 'variable',
225             variable            => 'opaclargeimage',
226             value               => '',
227             forceupdate         => { 'explanation' => 1,
228                                      'type' => 1},
229             explanation         => 'Enter a complete URL to an image, will be on the main page, instead of the Koha logo',
230             type                => 'free',
231         },
232         {
233             uniquefieldrequired => 'variable',
234             variable            => 'delimiter',
235             value               => ';',
236             forceupdate         => { 'explanation' => 1,
237                                      'type' => 1},
238             explanation         => 'separator for reports exported to spreadsheet',
239             type                => 'free',
240         },
241         {
242             uniquefieldrequired => 'variable',
243             variable            => 'MIME',
244             value               => 'OPENOFFICE.ORG',
245             forceupdate         => { 'explanation' => 1,
246                                      'type' => 1,
247                                      'options' => 1},
248             explanation         => 'Define the default application for report exportations into files',
249                 type            => 'Choice',
250                 options         => 'EXCEL|OPENOFFICE.ORG'
251         },
252         {
253             uniquefieldrequired => 'variable',
254             variable            => 'Delimiter',
255             value               => ';',
256                 forceupdate             => { 'explanation' => 1,
257                                      'type' => 1,
258                                      'options' => 1},
259             explanation         => 'Define the default separator character for report exportations into files',
260                 type            => 'Choice',
261                 options         => ';|tabulation|,|/|\|#'
262         },
263         {
264             uniquefieldrequired => 'variable',
265             variable            => 'SubscriptionHistory',
266             value               => ';',
267                 forceupdate             => { 'explanation' => 1,
268                                      'type' => 1,
269                                      'options' => 1},
270             explanation         => 'Define the information level for serials history in OPAC',
271                 type            => 'Choice',
272                 options         => 'simplified|full'
273         },
274         {
275             uniquefieldrequired => 'variable',
276             variable            => 'hidelostitems',
277             value               => 'No',
278             forceupdate         => { 'explanation' => 1,
279                                      'type' => 1},
280             explanation         => 'show or hide "lost" items in OPAC.',
281             type                => 'YesNo',
282         },
283                  {
284             uniquefieldrequired => 'variable',
285             variable            => 'IndependantBranches',
286             value               => '0',
287             forceupdate         => { 'explanation' => 1,
288                                      'type' => 1},
289             explanation         => 'Turn Branch independancy management On an Off',
290             type                => 'YesNo',
291         },
292                 {
293             uniquefieldrequired => 'variable',
294             variable            => 'ReturnBeforeExpiry',
295             value               => '0',
296             forceupdate         => { 'explanation' => 1,
297                                      'type' => 1},
298             explanation         => 'If Yes, Returndate on issuing can\'t be after borrower card expiry',
299             type                => 'YesNo',
300         },
301         {
302             uniquefieldrequired => 'variable',
303             variable            => 'Disable_Dictionary',
304             value               => '0',
305             forceupdate         => { 'explanation' => 1,
306                                      'type' => 1},
307             explanation         => 'Disables Dictionary buttons if set to yes',
308             type                => 'YesNo',
309         },
310         {
311             uniquefieldrequired => 'variable',
312             variable            => 'hide_marc',
313             value               => '0',
314             forceupdate         => { 'explanation' => 1,
315                                      'type' => 1},
316             explanation         => 'hide marc specific datas like subfield code & indicators to library',
317             type                => 'YesNo',
318         },
319         {
320             uniquefieldrequired => 'variable',
321             variable            => 'NotifyBorrowerDeparture',
322             value               => '0',
323             forceupdate         => { 'explanation' => 1,
324                                      'type' => 1},
325             explanation         => 'Delay before expiry where a notice is sent when issuing',
326             type                => 'Integer',
327         },
328         {
329             uniquefieldrequired => 'variable',
330             variable            => 'OpacPasswordChange',
331             value               => '1',
332             forceupdate         => { 'explanation' => 1,
333                                      'type' => 1},
334             explanation         => 'Enable/Disable password change in OPAC (disable it when using LDAP auth)',
335             type                => 'YesNo',
336         },
337         {
338             uniquefieldrequired => 'variable',
339             variable            => 'useDaysMode',
340             value               => 'Calendar',
341             forceupdate         => { 'explanation' => 1,
342                                      'type' => 1},
343             explanation                 => 'How to calculate return dates : Calendar means holidays will be controled, Days means the return date don\'t depend on holidays',
344                 type            => 'Choice',
345                 options         => 'Calendar|Days'
346         },
347     ],
348
349 );
350
351 my %fielddefinitions = (
352 # fieldname => [
353 #       {                 field => 'fieldname',
354 #             type    => 'fieldtype',
355 #             null    => '',
356 #             key     => '',
357 #             default => ''
358 #         },
359 #     ],
360         serial => [
361         {
362             field   => 'notes',
363             type    => 'TEXT',
364             null    => 'NULL',
365             key     => '',
366             default => '',
367             extra   => ''
368         },
369     ],
370         aqbasket =>  [
371                 {
372                         field   => 'booksellerid',
373                         type    => 'int(11)',
374                         null    => 'NOT NULL',
375                         key             => '',
376                         default => '1',
377                         extra   => '',
378                 },
379         ],
380         aqbooksellers =>  [
381                 {
382                         field   => 'listprice',
383                         type    => 'varchar(10)',
384                         null    => 'NULL',
385                         key             => '',
386                         default => '',
387                         extra   => '',
388                 },
389                 {
390                         field   => 'invoiceprice',
391                         type    => 'varchar(10)',
392                         null    => 'NULL',
393                         key             => '',
394                         default => '',
395                         extra   => '',
396                 },
397         ],
398         issues =>  [
399                 {
400                         field   => 'borrowernumber',
401                         type    => 'int(11)',
402                         null    => 'NULL', # can be null when a borrower is deleted and the foreign key rule executed
403                         key             => '',
404                         default => '',
405                         extra   => '',
406                 },
407                 {
408                         field   => 'itemnumber',
409                         type    => 'int(11)',
410                         null    => 'NULL', # can be null when a borrower is deleted and the foreign key rule executed
411                         key             => '',
412                         default => '',
413                         extra   => '',
414                 },
415         ],
416 );
417
418 my %indexes = (
419 #       table => [
420 #               {       indexname => 'index detail'
421 #               }
422 #       ],
423         shelfcontents => [
424                 {       indexname => 'shelfnumber',
425                         content => 'shelfnumber',
426                 },
427                 {       indexname => 'itemnumber',
428                         content => 'itemnumber',
429                 }
430         ],
431         bibliosubject => [
432                 {       indexname => 'biblionumber',
433                         content => 'biblionumber',
434                 }
435         ],
436         items => [
437                 {       indexname => 'homebranch',
438                         content => 'homebranch',
439                 },
440                 {       indexname => 'holdingbranch',
441                         content => 'holdingbranch',
442                 }
443         ],
444         aqbooksellers => [
445                 {       indexname => 'PRIMARY',
446                         content => 'id',
447                         type => 'PRIMARY',
448                 }
449         ],
450         aqbasket => [
451                 {       indexname => 'booksellerid',
452                         content => 'booksellerid',
453                 },
454         ],
455         aqorders => [
456                 {       indexname => 'basketno',
457                         content => 'basketno',
458                 },
459         ],
460         aqorderbreakdown => [
461                 {       indexname => 'ordernumber',
462                         content => 'ordernumber',
463                 },
464                 {       indexname => 'bookfundid',
465                         content => 'bookfundid',
466                 },
467         ],
468         currency => [
469                 {       indexname => 'PRIMARY',
470                         content => 'currency',
471                         type => 'PRIMARY',
472                 }
473         ],
474 );
475
476 my %foreign_keys = (
477 #       table => [
478 #               {       key => 'the key in table' (must be indexed)
479 #                       foreigntable => 'the foreigntable name', # (the parent)
480 #                       foreignkey => 'the foreign key column(s)' # (in the parent)
481 #                       onUpdate => 'CASCADE|SET NULL|NO ACTION| RESTRICT',
482 #                       onDelete => 'CASCADE|SET NULL|NO ACTION| RESTRICT',
483 #               }
484 #       ],
485         shelfcontents => [
486                 {       key => 'shelfnumber',
487                         foreigntable => 'bookshelf',
488                         foreignkey => 'shelfnumber',
489                         onUpdate => 'CASCADE',
490                         onDelete => 'CASCADE',
491                 },
492                 {       key => 'itemnumber',
493                         foreigntable => 'items',
494                         foreignkey => 'itemnumber',
495                         onUpdate => 'CASCADE',
496                         onDelete => 'CASCADE',
497                 },
498         ],
499         # onDelete is RESTRICT on reference tables (branches, itemtype) as we don't want items to be 
500         # easily deleted, but branches/itemtype not too easy to empty...
501         biblioitems => [
502                 {       key => 'biblionumber',
503                         foreigntable => 'biblio',
504                         foreignkey => 'biblionumber',
505                         onUpdate => 'CASCADE',
506                         onDelete => 'CASCADE',
507                 },
508                 {       key => 'itemtype',
509                         foreigntable => 'itemtypes',
510                         foreignkey => 'itemtype',
511                         onUpdate => 'CASCADE',
512                         onDelete => 'RESTRICT',
513                 },
514         ],
515         items => [
516                 {       key => 'biblioitemnumber',
517                         foreigntable => 'biblioitems',
518                         foreignkey => 'biblioitemnumber',
519                         onUpdate => 'CASCADE',
520                         onDelete => 'CASCADE',
521                 },
522                 {       key => 'homebranch',
523                         foreigntable => 'branches',
524                         foreignkey => 'branchcode',
525                         onUpdate => 'CASCADE',
526                         onDelete => 'RESTRICT',
527                 },
528                 {       key => 'holdingbranch',
529                         foreigntable => 'branches',
530                         foreignkey => 'branchcode',
531                         onUpdate => 'CASCADE',
532                         onDelete => 'RESTRICT',
533                 },
534         ],
535         additionalauthors => [
536                 {       key => 'biblionumber',
537                         foreigntable => 'biblio',
538                         foreignkey => 'biblionumber',
539                         onUpdate => 'CASCADE',
540                         onDelete => 'CASCADE',
541                 },
542         ],
543         bibliosubject => [
544                 {       key => 'biblionumber',
545                         foreigntable => 'biblio',
546                         foreignkey => 'biblionumber',
547                         onUpdate => 'CASCADE',
548                         onDelete => 'CASCADE',
549                 },
550         ],
551         aqbasket => [
552                 {       key => 'booksellerid',
553                         foreigntable => 'aqbooksellers',
554                         foreignkey => 'id',
555                         onUpdate => 'CASCADE',
556                         onDelete => 'RESTRICT',
557                 },
558         ],
559         aqorders => [
560                 {       key => 'basketno',
561                         foreigntable => 'aqbasket',
562                         foreignkey => 'basketno',
563                         onUpdate => 'CASCADE',
564                         onDelete => 'CASCADE',
565                 },
566                 {       key => 'biblionumber',
567                         foreigntable => 'biblio',
568                         foreignkey => 'biblionumber',
569                         onUpdate => 'SET NULL',
570                         onDelete => 'SET NULL',
571                 },
572         ],
573         aqbooksellers => [
574                 {       key => 'listprice',
575                         foreigntable => 'currency',
576                         foreignkey => 'currency',
577                         onUpdate => 'CASCADE',
578                         onDelete => 'CASCADE',
579                 },
580                 {       key => 'invoiceprice',
581                         foreigntable => 'currency',
582                         foreignkey => 'currency',
583                         onUpdate => 'CASCADE',
584                         onDelete => 'CASCADE',
585                 },
586         ],
587         aqorderbreakdown => [
588                 {       key => 'ordernumber',
589                         foreigntable => 'aqorders',
590                         foreignkey => 'ordernumber',
591                         onUpdate => 'CASCADE',
592                         onDelete => 'CASCADE',
593                 },
594                 {       key => 'bookfundid',
595                         foreigntable => 'aqbookfund',
596                         foreignkey => 'bookfundid',
597                         onUpdate => 'CASCADE',
598                         onDelete => 'CASCADE',
599                 },
600         ],
601         branchtransfers => [
602                 {       key => 'frombranch',
603                         foreigntable => 'branches',
604                         foreignkey => 'branchcode',
605                         onUpdate => 'CASCADE',
606                         onDelete => 'CASCADE',
607                 },
608                 {       key => 'tobranch',
609                         foreigntable => 'branches',
610                         foreignkey => 'branchcode',
611                         onUpdate => 'CASCADE',
612                         onDelete => 'CASCADE',
613                 },
614                 {       key => 'itemnumber',
615                         foreigntable => 'items',
616                         foreignkey => 'itemnumber',
617                         onUpdate => 'CASCADE',
618                         onDelete => 'CASCADE',
619                 },
620         ],
621         issuingrules => [
622                 {       key => 'categorycode',
623                         foreigntable => 'categories',
624                         foreignkey => 'categorycode',
625                         onUpdate => 'CASCADE',
626                         onDelete => 'CASCADE',
627                 },
628                 {       key => 'itemtype',
629                         foreigntable => 'itemtypes',
630                         foreignkey => 'itemtype',
631                         onUpdate => 'CASCADE',
632                         onDelete => 'CASCADE',
633                 },
634         ],
635         issues => [     # constraint is SET NULL : when a borrower or an item is deleted, we keep the issuing record
636         # for stat purposes
637                 {       key => 'borrowernumber',
638                         foreigntable => 'borrowers',
639                         foreignkey => 'borrowernumber',
640                         onUpdate => 'SET NULL',
641                         onDelete => 'SET NULL',
642                 },
643                 {       key => 'itemnumber',
644                         foreigntable => 'items',
645                         foreignkey => 'itemnumber',
646                         onUpdate => 'SET NULL',
647                         onDelete => 'SET NULL',
648                 },
649         ],
650         reserves => [
651                 {       key => 'borrowernumber',
652                         foreigntable => 'borrowers',
653                         foreignkey => 'borrowernumber',
654                         onUpdate => 'CASCADE',
655                         onDelete => 'CASCADE',
656                 },
657                 {       key => 'biblionumber',
658                         foreigntable => 'biblio',
659                         foreignkey => 'biblionumber',
660                         onUpdate => 'CASCADE',
661                         onDelete => 'CASCADE',
662                 },
663                 {       key => 'itemnumber',
664                         foreigntable => 'items',
665                         foreignkey => 'itemnumber',
666                         onUpdate => 'CASCADE',
667                         onDelete => 'CASCADE',
668                 },
669                 {       key => 'branchcode',
670                         foreigntable => 'branches',
671                         foreignkey => 'branchcode',
672                         onUpdate => 'CASCADE',
673                         onDelete => 'CASCADE',
674                 },
675         ],
676         borrowers => [ # foreign keys are RESTRICT as we don't want to delete borrowers when a branch is deleted
677         # but prevent deleting a branch as soon as it has 1 borrower !
678                 {       key => 'categorycode',
679                         foreigntable => 'categories',
680                         foreignkey => 'categorycode',
681                         onUpdate => 'RESTRICT',
682                         onDelete => 'RESTRICT',
683                 },
684                 {       key => 'branchcode',
685                         foreigntable => 'branches',
686                         foreignkey => 'branchcode',
687                         onUpdate => 'RESTRICT',
688                         onDelete => 'RESTRICT',
689                 },
690         ],
691         accountlines => [
692                 {       key => 'borrowernumber',
693                         foreigntable => 'borrowers',
694                         foreignkey => 'borrowernumber',
695                         onUpdate => 'CASCADE',
696                         onDelete => 'CASCADE',
697                 },
698                 {       key => 'itemnumber',
699                         foreigntable => 'items',
700                         foreignkey => 'itemnumber',
701                         onUpdate => 'SET NULL',
702                         onDelete => 'SET NULL',
703                 },
704         ],
705         auth_tag_structure => [
706                 {       key => 'authtypecode',
707                         foreigntable => 'auth_types',
708                         foreignkey => 'authtypecode',
709                         onUpdate => 'CASCADE',
710                         onDelete => 'CASCADE',
711                 },
712         ],
713         # FIXME : don't constraint auth_*_table and auth_word, as they may be replaced by zebra
714 );
715
716 #-------------------
717 # Initialize
718
719 # Start checking
720
721 # Get version of MySQL database engine.
722 my $mysqlversion = `mysqld --version`;
723 $mysqlversion =~ /Ver (\S*) /;
724 $mysqlversion = $1;
725 if ( $mysqlversion ge '3.23' ) {
726     print "Could convert to MyISAM database tables...\n" unless $silent;
727 }
728
729 #---------------------------------
730 # Tables
731
732 # Collect all tables into a list
733 $sth = $dbh->prepare("show tables");
734 $sth->execute;
735 while ( my ($table) = $sth->fetchrow ) {
736     $existingtables{$table} = 1;
737 }
738
739
740 # Now add any missing tables
741 foreach $table ( keys %requiretables ) {
742     unless ( $existingtables{$table} ) {
743         print "Adding $table table...\n" unless $silent;
744         my $sth = $dbh->prepare("create table $table $requiretables{$table}");
745         $sth->execute;
746         if ( $sth->err ) {
747             print "Error : $sth->errstr \n";
748             $sth->finish;
749         }    # if error
750     }    # unless exists
751 }    # foreach
752
753 # now drop useless tables
754 foreach $table ( keys %dropable_table ) {
755         if ( $existingtables{$table} ) {
756                 print "Dropping unused table $table\n" if $debug and not $silent;
757                 $dbh->do("drop table $table");
758                 if ( $dbh->err ) {
759                         print "Error : $dbh->errstr \n";
760                 }
761         }
762 }
763
764 #---------------------------------
765 # Columns
766
767 foreach $table ( keys %requirefields ) {
768     print "Check table $table\n" if $debug and not $silent;
769     $sth = $dbh->prepare("show columns from $table");
770     $sth->execute();
771     undef %types;
772     while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
773     {
774         $types{$column} = $type;
775     }    # while
776     foreach $column ( keys %{ $requirefields{$table} } ) {
777         print "  Check column $column  [$types{$column}]\n" if $debug and not $silent;
778         if ( !$types{$column} ) {
779
780             # column doesn't exist
781             print "Adding $column field to $table table...\n" unless $silent;
782             $query = "alter table $table
783                         add column $column " . $requirefields{$table}->{$column};
784             print "Execute: $query\n" if $debug;
785             my $sti = $dbh->prepare($query);
786             $sti->execute;
787             if ( $sti->err ) {
788                 print "**Error : $sti->errstr \n";
789                 $sti->finish;
790             }    # if error
791         }    # if column
792     }    # foreach column
793 }    # foreach table
794
795 foreach $table ( keys %fielddefinitions ) {
796         print "Check table $table\n" if $debug;
797         $sth = $dbh->prepare("show columns from $table");
798         $sth->execute();
799         my $definitions;
800         while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
801         {
802                 $definitions->{$column}->{type}    = $type;
803                 $definitions->{$column}->{null}    = $null;
804                 $definitions->{$column}->{null}    = 'NULL' if $null eq 'YES';
805                 $definitions->{$column}->{key}     = $key;
806                 $definitions->{$column}->{default} = $default;
807                 $definitions->{$column}->{extra}   = $extra;
808         }    # while
809         my $fieldrow = $fielddefinitions{$table};
810         foreach my $row (@$fieldrow) {
811                 my $field   = $row->{field};
812                 my $type    = $row->{type};
813                 my $null    = $row->{null};
814 #               $null    = 'YES' if $row->{null} eq 'NULL';
815                 my $key     = $row->{key};
816                 my $default = $row->{default};
817                 my $null    = $row->{null};
818 #               $default="''" unless $default;
819                 my $extra   = $row->{extra};
820                 my $def     = $definitions->{$field};
821
822                 unless ( $type eq $def->{type}
823                         && $null eq $def->{null}
824                         && $key eq $def->{key}
825                         && $extra eq $def->{extra} )
826                 {
827                         if ( $null eq '' ) {
828                                 $null = 'NOT NULL';
829                         }
830                         if ( $key eq 'PRI' ) {
831                                 $key = 'PRIMARY KEY';
832                         }
833                         unless ( $extra eq 'auto_increment' ) {
834                                 $extra = '';
835                         }
836
837                         # if it's a new column use "add", if it's an old one, use "change".
838                         my $action;
839                         if ($definitions->{$field}->{type}) {
840                                 $action="change $field"
841                         } else {
842                                 $action="add";
843                         }
844 # if it's a primary key, drop the previous pk, before altering the table
845                         my $sth;
846                         if ($key ne 'PRIMARY KEY') {
847                                 $sth =$dbh->prepare("alter table $table $action $field $type $null $key $extra default ?");
848                         } else {
849                                 $sth =$dbh->prepare("alter table $table drop primary key, $action $field $type $null $key $extra default ?");
850                         }
851                         $sth->execute($default);
852                         print "  Alter $field in $table\n" unless $silent;
853                 }
854         }
855 }
856
857
858 # Populate tables with required data
859
860
861 # synch table and deletedtable.
862 foreach my $table (('borrowers','items','biblio','biblioitems')) {
863         my %deletedborrowers;
864         print "synch'ing $table\n";
865         $sth = $dbh->prepare("show columns from deleted$table");
866         $sth->execute;
867         while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ) {
868                 $deletedborrowers{$column}=1;
869         }
870         $sth = $dbh->prepare("show columns from $table");
871         $sth->execute;
872         my $previous;
873         while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ) {
874                 unless ($deletedborrowers{$column}) {
875                         my $newcol="alter table deleted$table add $column $type";
876                         if ($null eq 'YES') {
877                                 $newcol .= " NULL ";
878                         } else {
879                                 $newcol .= " NOT NULL ";
880                         }
881                         $newcol .= "default $default" if $default;
882                         $newcol .= " after $previous" if $previous;
883                         $previous=$column;
884                         print "creating column $column\n";
885                         $dbh->do($newcol);
886                 }
887         }
888 }
889
890 foreach my $table ( keys %tabledata ) {
891     print "Checking for data required in table $table...\n" unless $silent;
892     my $tablerows = $tabledata{$table};
893     foreach my $row (@$tablerows) {
894         my $uniquefieldrequired = $row->{uniquefieldrequired};
895         my $uniquevalue         = $row->{$uniquefieldrequired};
896         my $forceupdate         = $row->{forceupdate};
897         my $sth                 =
898           $dbh->prepare(
899 "select $uniquefieldrequired from $table where $uniquefieldrequired=?"
900         );
901         $sth->execute($uniquevalue);
902                 if ($sth->rows) {
903                         foreach my $field (keys %$forceupdate) {
904                                 if ($forceupdate->{$field}) {
905                                         my $sth=$dbh->prepare("update systempreferences set $field=? where $uniquefieldrequired=?");
906                                         $sth->execute($row->{$field}, $uniquevalue);
907                                 }
908                 }
909                 } else {
910                         print "Adding row to $table: " unless $silent;
911                         my @values;
912                         my $fieldlist;
913                         my $placeholders;
914                         foreach my $field ( keys %$row ) {
915                                 next if $field eq 'uniquefieldrequired';
916                                 next if $field eq 'forceupdate';
917                                 my $value = $row->{$field};
918                                 push @values, $value;
919                                 print "  $field => $value" unless $silent;
920                                 $fieldlist .= "$field,";
921                                 $placeholders .= "?,";
922                         }
923                         print "\n" unless $silent;
924                         $fieldlist    =~ s/,$//;
925                         $placeholders =~ s/,$//;
926                         my $sth =
927                         $dbh->prepare(
928                                 "insert into $table ($fieldlist) values ($placeholders)");
929                         $sth->execute(@values);
930                 }
931         }
932 }
933
934 #
935 # check indexes and create them when needed
936 #
937 print "Checking for index required...\n" unless $silent;
938 foreach my $table ( keys %indexes ) {
939         #
940         # read all indexes from $table
941         #
942         $sth = $dbh->prepare("show index from $table");
943         $sth->execute;
944         my %existingindexes;
945         while ( my ( $table, $non_unique, $key_name, $Seq_in_index, $Column_name, $Collation, $cardinality, $sub_part, $Packed, $comment ) = $sth->fetchrow ) {
946                 $existingindexes{$key_name} = 1;
947         }
948         # read indexes to check
949         my $tablerows = $indexes{$table};
950         foreach my $row (@$tablerows) {
951                 my $key_name=$row->{indexname};
952                 if ($existingindexes{$key_name} eq 1) {
953 #                       print "$key_name existing";
954                 } else {
955                         print "\tCreating index $key_name in $table\n";
956                         my $sql;
957                         if ($row->{indexname} eq 'PRIMARY') {
958                                 $sql = "alter table $table ADD PRIMARY KEY ($row->{content})";
959                         } else {
960                                 $sql = "alter table $table ADD INDEX $key_name ($row->{content}) $row->{type}";
961                         }
962                         $dbh->do($sql);
963             print "Error $sql : $dbh->err \n" if $dbh->err;
964                 }
965         }
966 }
967
968 #
969 # check foreign keys and create them when needed
970 #
971 print "Checking for foreign keys required...\n" unless $silent;
972 foreach my $table ( keys %foreign_keys ) {
973         #
974         # read all indexes from $table
975         #
976         $sth = $dbh->prepare("show table status like '$table'");
977         $sth->execute;
978         my $stat = $sth->fetchrow_hashref;
979         # read indexes to check
980         my $tablerows = $foreign_keys{$table};
981         foreach my $row (@$tablerows) {
982                 my $foreign_table=$row->{foreigntable};
983                 if ($stat->{'Comment'} =~/$foreign_table/) {
984 #                       print "$foreign_table existing\n";
985                 } else {
986                         print "\tCreating foreign key $foreign_table in $table\n";
987                         # first, drop any orphan value in child table
988                         if ($row->{onDelete} ne "RESTRICT") {
989                                 my $sql = "delete from $table where $row->{key} not in (select $row->{foreignkey} from $row->{foreigntable})";
990                                 $dbh->do($sql);
991                                 print "SQL ERROR: $sql : $dbh->err \n" if $dbh->err;
992                         }
993                         my $sql="alter table $table ADD FOREIGN KEY $row->{key} ($row->{key}) REFERENCES $row->{foreigntable} ($row->{foreignkey})";
994                         $sql .= " on update ".$row->{onUpdate} if $row->{onUpdate};
995                         $sql .= " on delete ".$row->{onDelete} if $row->{onDelete};
996                         $dbh->do($sql);
997                         if ($dbh->err) {
998                                 print "====================
999 An error occured during :
1000 \t$sql
1001 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).
1002 You can find those values with select
1003 \t$table.* from $table where $row->{key} not in (select $row->{foreignkey} from $row->{foreigntable})
1004 ====================\n
1005 ";
1006                         }
1007                 }
1008         }
1009 }
1010
1011 #
1012 # SPECIFIC STUFF
1013 #
1014 #
1015 # create frameworkcode row in biblio table & fill it with marc_biblio.frameworkcode.
1016 #
1017
1018 # 1st, get how many biblio we will have to do...
1019 $sth = $dbh->prepare('select count(*) from marc_biblio');
1020 $sth->execute;
1021 my ($totaltodo) = $sth->fetchrow;
1022
1023 $sth = $dbh->prepare("show columns from biblio");
1024 $sth->execute();
1025 my $definitions;
1026 my $bibliofwexist=0;
1027 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ){
1028         $bibliofwexist=1 if $column eq 'frameworkcode';
1029 }
1030 unless ($bibliofwexist) {
1031         print "moving biblioframework to biblio table\n";
1032         $dbh->do('ALTER TABLE `biblio` ADD `frameworkcode` VARCHAR( 4 ) NOT NULL AFTER `biblionumber`');
1033         $sth = $dbh->prepare('select biblionumber,frameworkcode from marc_biblio');
1034         $sth->execute;
1035         my $sth_update = $dbh->prepare('update biblio set frameworkcode=? where biblionumber=?');
1036         my $totaldone=0;
1037         while (my ($biblionumber,$frameworkcode) = $sth->fetchrow) {
1038                 $sth_update->execute($frameworkcode,$biblionumber);
1039                 $totaldone++;
1040                 print "\r$totaldone / $totaltodo" unless ($totaldone % 100);
1041         }
1042         print "\rdone\n";
1043 }
1044
1045 #
1046 # moving MARC data from marc_subfield_table to biblioitems.marc
1047 #
1048 $sth = $dbh->prepare("show columns from biblioitems");
1049 $sth->execute();
1050 my $definitions;
1051 my $marcdone=0;
1052 while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ){
1053         $marcdone=1 if ($type eq 'blob' && $column eq 'marc') ;
1054 }
1055 unless ($marcdone) {
1056         print "moving MARC record to biblioitems table\n";
1057         # changing marc field type
1058         $dbh->do('ALTER TABLE `biblioitems` CHANGE `marc` `marc` BLOB NULL DEFAULT NULL ');
1059         # adding marc xml, just for convenience
1060         $dbh->do('ALTER TABLE `biblioitems` ADD `marcxml` TEXT NOT NULL');
1061         # moving data from marc_subfield_value to biblio
1062         $sth = $dbh->prepare('select bibid,biblionumber from marc_biblio');
1063         $sth->execute;
1064         my $sth_update = $dbh->prepare('update biblioitems set marc=?, marcxml=? where biblionumber=?');
1065         my $totaldone=0;
1066         while (my ($bibid,$biblionumber) = $sth->fetchrow) {
1067                 my $record = MARCgetbiblio($dbh,$bibid);
1068                 $sth_update->execute($record->as_usmarc(),$record->as_xml(),$biblionumber);
1069                 $totaldone++;
1070                 print "\r$totaldone / $totaltodo" unless ($totaldone % 100);
1071         }
1072         print "\rdone\n";
1073 }
1074
1075 # MOVE all tables TO UTF-8 and innoDB
1076 $sth = $dbh->prepare("show table status");
1077 $sth->execute;
1078 while ( my $table = $sth->fetchrow_hashref ) {
1079         if ($table->{Engine} ne 'InnoDB') {
1080 #               $dbh->do("ALTER TABLE $table->{Name} TYPE = innodb");
1081                 print "moving $table->{Name} to InnoDB\n";
1082         }
1083         unless ($table->{Collation} =~ /^utf8/) {
1084                 #$dbh->do("ALTER TABLE $table->{Name} DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
1085 #               $dbh->do("ALTER TABLE $table->{Name} CONVERT TO CHARACTER SET utf8");
1086                 # 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 !
1087                 print "moving $table->{Name} to utf8\n";
1088         } else {
1089         }
1090 }
1091
1092 # at last, remove useless fields
1093 foreach $table ( keys %uselessfields ) {
1094         my @fields = split /,/,$uselessfields{$table};
1095         my $fields;
1096         my $exists;
1097         foreach my $fieldtodrop (@fields) {
1098                 $fieldtodrop =~ s/\t//g;
1099                 $fieldtodrop =~ s/\n//g;
1100                 $exists =0;
1101                 $sth = $dbh->prepare("show columns from $table");
1102                 $sth->execute;
1103                 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
1104                 {
1105                         $exists =1 if ($column eq $fieldtodrop);
1106                 }
1107                 if ($exists) {
1108                         print "deleting $fieldtodrop field in $table...\n" unless $silent;
1109                         my $sth = $dbh->prepare("alter table $table drop $fieldtodrop");
1110                         $sth->execute;
1111                 }
1112         }
1113 }    # foreach
1114
1115
1116 $sth->finish;
1117
1118 #
1119 # those 2 subs are a copy of Biblio.pm, version 2.2.4
1120 # they are useful only once, for moving from 2.2 to 3.0
1121 # the MARCgetbiblio & MARCgetitem subs in Biblio.pm
1122 # are still here, but uses other tables
1123 # (the ones that are filled by updatedatabase !)
1124 #
1125 sub MARCgetbiblio {
1126
1127     # Returns MARC::Record of the biblio passed in parameter.
1128     my ( $dbh, $bibid ) = @_;
1129     my $record = MARC::Record->new();
1130 #       warn "". $bidid;
1131
1132     my $sth =
1133       $dbh->prepare(
1134 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
1135                                  from marc_subfield_table
1136                                  where bibid=? order by tag,tagorder,subfieldorder
1137                          "
1138     );
1139     my $sth2 =
1140       $dbh->prepare(
1141         "select subfieldvalue from marc_blob_subfield where blobidlink=?");
1142     $sth->execute($bibid);
1143     my $prevtagorder = 1;
1144     my $prevtag      = 'XXX';
1145     my $previndicator;
1146     my $field;        # for >=10 tags
1147     my $prevvalue;    # for <10 tags
1148     while ( my $row = $sth->fetchrow_hashref ) {
1149
1150         if ( $row->{'valuebloblink'} ) {    #---- search blob if there is one
1151             $sth2->execute( $row->{'valuebloblink'} );
1152             my $row2 = $sth2->fetchrow_hashref;
1153             $sth2->finish;
1154             $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
1155         }
1156         if ( $row->{tagorder} ne $prevtagorder || $row->{tag} ne $prevtag ) {
1157             $previndicator .= "  ";
1158             if ( $prevtag < 10 ) {
1159                                 if ($prevtag ne '000') {
1160                         $record->add_fields( ( sprintf "%03s", $prevtag ), $prevvalue ) unless $prevtag eq "XXX";    # ignore the 1st loop
1161                                 } else {
1162                                         $record->leader(sprintf("%24s",$prevvalue));
1163                                 }
1164             }
1165             else {
1166                 $record->add_fields($field) unless $prevtag eq "XXX";
1167             }
1168             undef $field;
1169             $prevtagorder  = $row->{tagorder};
1170             $prevtag       = $row->{tag};
1171             $previndicator = $row->{tag_indicator};
1172             if ( $row->{tag} < 10 ) {
1173                 $prevvalue = $row->{subfieldvalue};
1174             }
1175             else {
1176                 $field = MARC::Field->new(
1177                     ( sprintf "%03s", $prevtag ),
1178                     substr( $row->{tag_indicator} . '  ', 0, 1 ),
1179                     substr( $row->{tag_indicator} . '  ', 1, 1 ),
1180                     $row->{'subfieldcode'},
1181                     $row->{'subfieldvalue'}
1182                 );
1183             }
1184         }
1185         else {
1186             if ( $row->{tag} < 10 ) {
1187                 $record->add_fields( ( sprintf "%03s", $row->{tag} ),
1188                     $row->{'subfieldvalue'} );
1189             }
1190             else {
1191                 $field->add_subfields( $row->{'subfieldcode'},
1192                     $row->{'subfieldvalue'} );
1193             }
1194             $prevtag       = $row->{tag};
1195             $previndicator = $row->{tag_indicator};
1196         }
1197     }
1198
1199     # the last has not been included inside the loop... do it now !
1200     if ( $prevtag ne "XXX" )
1201     { # check that we have found something. Otherwise, prevtag is still XXX and we
1202          # must return an empty record, not make MARC::Record fail because we try to
1203          # create a record with XXX as field :-(
1204         if ( $prevtag < 10 ) {
1205             $record->add_fields( $prevtag, $prevvalue );
1206         }
1207         else {
1208
1209             #           my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
1210             $record->add_fields($field);
1211         }
1212     }
1213     return $record;
1214 }
1215
1216 sub MARCgetitem {
1217
1218     # Returns MARC::Record of the biblio passed in parameter.
1219     my ( $dbh, $bibid, $itemnumber ) = @_;
1220     my $record = MARC::Record->new();
1221
1222     # search MARC tagorder
1223     my $sth2 =
1224       $dbh->prepare(
1225 "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=?"
1226     );
1227     $sth2->execute( $bibid, $itemnumber );
1228     my ($tagorder) = $sth2->fetchrow_array();
1229
1230     #---- TODO : the leader is missing
1231     my $sth =
1232       $dbh->prepare(
1233 "select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
1234                                  from marc_subfield_table
1235                                  where bibid=? and tagorder=? order by subfieldcode,subfieldorder
1236                          "
1237     );
1238     $sth2 =
1239       $dbh->prepare(
1240         "select subfieldvalue from marc_blob_subfield where blobidlink=?");
1241     $sth->execute( $bibid, $tagorder );
1242     while ( my $row = $sth->fetchrow_hashref ) {
1243         if ( $row->{'valuebloblink'} ) {    #---- search blob if there is one
1244             $sth2->execute( $row->{'valuebloblink'} );
1245             my $row2 = $sth2->fetchrow_hashref;
1246             $sth2->finish;
1247             $row->{'subfieldvalue'} = $row2->{'subfieldvalue'};
1248         }
1249         if ( $record->field( $row->{'tag'} ) ) {
1250             my $field;
1251
1252 #--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
1253             #--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
1254             if ( length( $row->{'tag'} ) < 3 ) {
1255                 $row->{'tag'} = "0" . $row->{'tag'};
1256             }
1257             $field = $record->field( $row->{'tag'} );
1258             if ($field) {
1259                 my $x =
1260                   $field->add_subfields( $row->{'subfieldcode'},
1261                     $row->{'subfieldvalue'} );
1262                 $record->delete_field($field);
1263                 $record->add_fields($field);
1264             }
1265         }
1266         else {
1267             if ( length( $row->{'tag'} ) < 3 ) {
1268                 $row->{'tag'} = "0" . $row->{'tag'};
1269             }
1270             my $temp =
1271               MARC::Field->new( $row->{'tag'}, " ", " ",
1272                 $row->{'subfieldcode'} => $row->{'subfieldvalue'} );
1273             $record->add_fields($temp);
1274         }
1275
1276     }
1277     return $record;
1278 }
1279
1280
1281 exit;
1282
1283 # $Log$
1284 # Revision 1.131  2006/03/03 17:02:22  tipaul
1285 # commit for holidays and news management.
1286 # (some forgotten files)
1287 #
1288 # Revision 1.130  2006/03/03 16:35:21  tipaul
1289 # commit for holidays and news management.
1290 #
1291 # Contrib from Tümer Garip (from Turkey) :
1292 # * holiday :
1293 # 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 :
1294 # - single day : only this day is closed
1295 # - repet weekly (like "sunday") : the day is holiday every week
1296 # - repet yearly (like "July, 4") : this day is closed every year.
1297 #
1298 # You can also put exception :
1299 # - sunday is holiday, but "2006 March, 5th" the library will be open
1300 #
1301 # 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.
1302 #
1303 # Revision 1.129  2006/02/27 18:19:33  hdl
1304 # New table used in overduerules.pl tools page.
1305 #
1306 # Revision 1.128  2006/01/25 15:16:06  tipaul
1307 # updating DB :
1308 # * removing useless tables
1309 # * adding useful indexes
1310 # * altering some columns definitions
1311 # * The goal being to have updater working fine for foreign keys.
1312 #
1313 # 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
1314 #
1315 # Revision 1.127  2006/01/24 17:57:17  tipaul
1316 # DB improvements : adding foreign keys on some tables. partial stuff done.
1317 #
1318 # Revision 1.126  2006/01/06 16:39:42  tipaul
1319 # synch'ing head and rel_2_2 (from 2.2.5, including npl templates)
1320 # Seems not to break too many things, but i'm probably wrong here.
1321 # at least, new features/bugfixes from 2.2.5 are here (tested on some features on my head local copy)
1322 #
1323 # - removing useless directories (koha-html and koha-plucene)
1324 #
1325 # Revision 1.125  2006/01/04 15:54:55  tipaul
1326 # utf8 is a : go for beta test in HEAD.
1327 # some explanations :
1328 # - 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.
1329 # - *-top.inc will show the pages in utf8
1330 # - 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.
1331 # - using marcxml field and no more the iso2709 raw marc biblioitems.marc field.
1332 #
1333 # Revision 1.124  2005/10/27 12:09:05  tipaul
1334 # new features for serial module :
1335 # - 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")
1336 # - 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).
1337 #
1338 # Revision 1.123  2005/10/26 09:13:37  tipaul
1339 # big commit, still breaking things...
1340 #
1341 # * synch with rel_2_2. Probably the last non manual synch, as rel_2_2 should not be modified deeply.
1342 # * code cleaning (cleaning warnings from perl -w) continued
1343 #
1344 # Revision 1.122  2005/09/02 14:18:38  tipaul
1345 # new feature : image for itemtypes.
1346 #
1347 # * run updater/updatedatabase to create imageurl field in itemtypes.
1348 # * 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)
1349 # * go to OPAC, and search something. In the result list, you now have the picture instead of the text itemtype.
1350 #
1351 # Revision 1.121  2005/08/24 08:49:03  hdl
1352 # Adding a note field in serial table.
1353 # This will allow librarian to mention a note on a peculiar waiting serial number.
1354 #
1355 # Revision 1.120  2005/08/09 14:10:32  tipaul
1356 # 1st commit to go to zebra.
1357 # don't update your cvs if you want to have a working head...
1358 #
1359 # this commit contains :
1360 # * 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...
1361 # * 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.
1362 # * other files : get rid of bibid and use biblionumber instead.
1363 #
1364 # What is broken :
1365 # * does not do anything on zebra yet.
1366 # * if you rename marc_subfield_table, you can't search anymore.
1367 # * you can view a biblio & bibliodetails, go to MARC editor, but NOT save any modif.
1368 # * 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 ;-) )
1369 #
1370 # 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
1371 # 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.
1372 #
1373 # Revision 1.119  2005/08/04 16:07:58  tipaul
1374 # Synch really broke this script...
1375 #
1376 # Revision 1.118  2005/08/04 16:02:55  tipaul
1377 # oops... error in synch between 2.2 and head
1378 #
1379 # Revision 1.117  2005/08/04 14:24:39  tipaul
1380 # synch'ing 2.2 and head
1381 #
1382 # Revision 1.116  2005/08/04 08:55:54  tipaul
1383 # Letters / alert system, continuing...
1384 #
1385 # * adding a package Letters.pm, that manages Letters & alerts.
1386 # * 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)
1387 # * 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)
1388 # * 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.
1389 #
1390 # Note that the system should be generic enough to manage any type of alert.
1391 # 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 ;-) )
1392 #
1393 # Revision 1.115  2005/08/02 16:15:34  tipaul
1394 # adding 2 fields to letter system :
1395 # * module (acquisition, catalogue...) : it will be usefull to show the librarian only letters he may be interested by.
1396 # * title, that will be used as mail subject.
1397 #
1398 # Revision 1.114  2005/07/28 15:10:13  tipaul
1399 # 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.
1400 # the letter table contains 3 fields :
1401 # * code => the code of the letter
1402 # * name => the complete name of the letter
1403 # * content => the complete text. It's a TEXT field type, so has no limits.
1404 #
1405 # My next goal now is to work on point 2-I "serial issue alert"
1406 # 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.
1407 # (see mail on koha-devel, 2005/04/07)
1408 #
1409 # The "serial issue alert" will be the 1st to use this letter system that probably needs some tweaking ;-)
1410 #
1411 # Once it will be stabilised default letters (in any languages) could be added during installer to help the library begin with this new feature.
1412 #
1413 # Revision 1.113  2005/07/28 08:38:41  tipaul
1414 # 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 :
1415 # * ReturnBeforeExpiry = yes => return date can't be after expiry date
1416 # * ReturnBeforeExpiry = no  => return date can be after expiry date
1417 #
1418 # Revision 1.112  2005/07/26 08:19:47  hdl
1419 # Adding IndependantBranches System preference variable in order to manage Branch independancy.
1420 #
1421 # Revision 1.111  2005/07/25 15:35:38  tipaul
1422 # we have decided that moving to Koha 3.0 requires being already in Koha 2.2.x
1423 # So, the updatedatabase script can highly be cleaned (90% removed).
1424 # Let's play with the new Koha DB structure now ;-)
1425 #