Introducing new "Letters" system : Letters will be used everytime you want to sent...
[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 # FIXME - The user might be installing a new database, so can't rely
24 # on /etc/koha.conf anyway.
25
26 my $debug = 0;
27
28 my (
29     $sth, $sti,
30     $query,
31     %existingtables,    # tables already in database
32     %types,
33     $table,
34     $column,
35     $type, $null, $key, $default, $extra,
36     $prefitem,          # preference item in systempreferences table
37 );
38
39 my $silent;
40 GetOptions(
41         's' =>\$silent
42         );
43 my $dbh = C4::Context->dbh;
44 print "connected to your DB. Checking & modifying it\n" unless $silent;
45
46 #-------------------
47 # Defines
48
49 # Tables to add if they don't exist
50 my %requiretables = (
51     categorytable       => "(categorycode char(5) NOT NULL default '',
52                              description text default '',
53                              itemtypecodes text default '',
54                              PRIMARY KEY (categorycode)
55                             )",
56     subcategorytable       => "(subcategorycode char(5) NOT NULL default '',
57                              description text default '',
58                              itemtypecodes text default '',
59                              PRIMARY KEY (subcategorycode)
60                             )",
61     mediatypetable       => "(mediatypecode char(5) NOT NULL default '',
62                              description text default '',
63                              itemtypecodes text default '',
64                              PRIMARY KEY (mediatypecode)
65                             )",
66     action_logs         => "(
67                                     `timestamp` TIMESTAMP NOT NULL ,
68                                     `user` INT( 11 ) NOT NULL ,
69                                     `module` TEXT default '',
70                                     `action` TEXT default '' ,
71                                     `object` INT(11) default '' ,
72                                     `info` TEXT default '' ,
73                                     PRIMARY KEY ( `timestamp` , `user` )
74                             )",
75         letter          => "(
76                                         code varchar(20) NOT NULL,
77                                         name varchar(100) NOT NULL,
78                                         content TEXT,
79                                         PRIMARY KEY (code)
80                                 )",
81 );
82
83 my %requirefields = (
84 #    tablename        => { 'field' => 'fieldtype' },
85 );
86
87 my %dropable_table = (
88 # tablename => 'tablename',
89 );
90
91 my %uselessfields = (
92 # tablename => "field1,field2",
93         );
94 # the other hash contains other actions that can't be done elsewhere. they are done
95 # either BEFORE of AFTER everything else, depending on "when" entry (default => AFTER)
96
97 # The tabledata hash contains data that should be in the tables.
98 # The uniquefieldrequired hash entry is used to determine which (if any) fields
99 # must not exist in the table for this row to be inserted.  If the
100 # uniquefieldrequired entry is already in the table, the existing data is not
101 # modified, unless the forceupdate hash entry is also set.  Fields in the
102 # anonymous "forceupdate" hash will be forced to be updated to the default
103 # values given in the %tabledata hash.
104
105 my %tabledata = (
106 # tablename => [
107 #       {       uniquefielrequired => 'fieldname', # the primary key in the table
108 #               fieldname => fieldvalue,
109 #               fieldname2 => fieldvalue2,
110 #       },
111 # ],
112     systempreferences => [
113                 {
114             uniquefieldrequired => 'variable',
115             variable            => 'Activate_Log',
116             value               => 'On',
117             forceupdate         => { 'explanation' => 1,
118                                      'type' => 1},
119             explanation         => 'Turn Log Actions on DB On an Off',
120             type                => 'YesNo',
121         },
122                 {
123             uniquefieldrequired => 'variable',
124             variable            => 'ReturnBeforeExpiry',
125             value               => 'Off',
126             forceupdate         => { 'explanation' => 1,
127                                      'type' => 1},
128             explanation         => 'If Yes, Returndate on issuing can\'t be after borrower card expiry',
129             type                => 'YesNo',
130         },
131     ],
132
133 );
134
135 my %fielddefinitions = (
136 # fieldname => [
137 #       {                 field => 'fieldname',
138 #             type    => 'fieldtype',
139 #             null    => '',
140 #             key     => '',
141 #             default => ''
142 #         },
143 #     ],
144 );
145
146 #-------------------
147 # Initialize
148
149 # Start checking
150
151 # Get version of MySQL database engine.
152 my $mysqlversion = `mysqld --version`;
153 $mysqlversion =~ /Ver (\S*) /;
154 $mysqlversion = $1;
155 if ( $mysqlversion ge '3.23' ) {
156     print "Could convert to MyISAM database tables...\n" unless $silent;
157 }
158
159 #---------------------------------
160 # Tables
161
162 # Collect all tables into a list
163 $sth = $dbh->prepare("show tables");
164 $sth->execute;
165 while ( my ($table) = $sth->fetchrow ) {
166     $existingtables{$table} = 1;
167 }
168
169
170 # Now add any missing tables
171 foreach $table ( keys %requiretables ) {
172     unless ( $existingtables{$table} ) {
173         print "Adding $table table...\n" unless $silent;
174         my $sth = $dbh->prepare("create table $table $requiretables{$table}");
175         $sth->execute;
176         if ( $sth->err ) {
177             print "Error : $sth->errstr \n";
178             $sth->finish;
179         }    # if error
180     }    # unless exists
181 }    # foreach
182
183 # now drop useless tables
184 foreach $table ( keys %dropable_table ) {
185         if ( $existingtables{$table} ) {
186                 print "Dropping unused table $table\n" if $debug and not $silent;
187                 $dbh->do("drop table $table");
188                 if ( $dbh->err ) {
189                         print "Error : $dbh->errstr \n";
190                 }
191         }
192 }
193
194 #---------------------------------
195 # Columns
196
197 foreach $table ( keys %requirefields ) {
198     print "Check table $table\n" if $debug and not $silent;
199     $sth = $dbh->prepare("show columns from $table");
200     $sth->execute();
201     undef %types;
202     while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
203     {
204         $types{$column} = $type;
205     }    # while
206     foreach $column ( keys %{ $requirefields{$table} } ) {
207         print "  Check column $column  [$types{$column}]\n" if $debug and not $silent;
208         if ( !$types{$column} ) {
209
210             # column doesn't exist
211             print "Adding $column field to $table table...\n" unless $silent;
212             $query = "alter table $table
213                         add column $column " . $requirefields{$table}->{$column};
214             print "Execute: $query\n" if $debug;
215             my $sti = $dbh->prepare($query);
216             $sti->execute;
217             if ( $sti->err ) {
218                 print "**Error : $sti->errstr \n";
219                 $sti->finish;
220             }    # if error
221         }    # if column
222     }    # foreach column
223 }    # foreach table
224
225 foreach $table ( keys %fielddefinitions ) {
226         print "Check table $table\n" if $debug;
227         $sth = $dbh->prepare("show columns from $table");
228         $sth->execute();
229         my $definitions;
230         while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
231         {
232                 $definitions->{$column}->{type}    = $type;
233                 $definitions->{$column}->{null}    = $null;
234                 $definitions->{$column}->{key}     = $key;
235                 $definitions->{$column}->{default} = $default;
236                 $definitions->{$column}->{extra}   = $extra;
237         }    # while
238         my $fieldrow = $fielddefinitions{$table};
239         foreach my $row (@$fieldrow) {
240                 my $field   = $row->{field};
241                 my $type    = $row->{type};
242                 my $null    = $row->{null};
243                 my $key     = $row->{key};
244                 my $default = $row->{default};
245                 $default="''" unless $default;
246                 my $extra   = $row->{extra};
247                 my $def     = $definitions->{$field};
248                 unless ( $type eq $def->{type}
249                         && $null eq $def->{null}
250                         && $key eq $def->{key}
251                         && $default eq $def->{default}
252                         && $extra eq $def->{extra} )
253                 {
254
255                         if ( $null eq '' ) {
256                                 $null = 'NOT NULL';
257                         }
258                         if ( $key eq 'PRI' ) {
259                                 $key = 'PRIMARY KEY';
260                         }
261                         unless ( $extra eq 'auto_increment' ) {
262                                 $extra = '';
263                         }
264                         # if it's a new column use "add", if it's an old one, use "change".
265                         my $action;
266                         if ($definitions->{$field}->{type}) {
267                                 $action="change $field"
268                         } else {
269                                 $action="add";
270                         }
271 # if it's a primary key, drop the previous pk, before altering the table
272                         my $sth;
273                         if ($key ne 'PRIMARY KEY') {
274                                 $sth =$dbh->prepare("alter table $table $action $field $type $null $key $extra default ?");
275                         } else {
276                                 $sth =$dbh->prepare("alter table $table drop primary key, $action $field $type $null $key $extra default ?");
277                         }
278                         $sth->execute($default);
279                         print "  Alter $field in $table\n" unless $silent;
280                 }
281         }
282 }
283
284
285 # Populate tables with required data
286 foreach my $table ( keys %tabledata ) {
287     print "Checking for data required in table $table...\n" unless $silent;
288     my $tablerows = $tabledata{$table};
289     foreach my $row (@$tablerows) {
290         my $uniquefieldrequired = $row->{uniquefieldrequired};
291         my $uniquevalue         = $row->{$uniquefieldrequired};
292         my $forceupdate         = $row->{forceupdate};
293         my $sth                 =
294           $dbh->prepare(
295 "select $uniquefieldrequired from $table where $uniquefieldrequired=?"
296         );
297         $sth->execute($uniquevalue);
298         if ($sth->rows) {
299             foreach my $field (keys %$forceupdate) {
300                 if ($forceupdate->{$field}) {
301                     my $sth=$dbh->prepare("update systempreferences set $field=? where $uniquefieldrequired=?");
302                     $sth->execute($row->{$field}, $uniquevalue);
303                 }
304             }
305         } else {
306             print "Adding row to $table: " unless $silent;
307             my @values;
308             my $fieldlist;
309             my $placeholders;
310             foreach my $field ( keys %$row ) {
311                 next if $field eq 'uniquefieldrequired';
312                 next if $field eq 'forceupdate';
313                 my $value = $row->{$field};
314                 push @values, $value;
315                 print "  $field => $value" unless $silent;
316                 $fieldlist .= "$field,";
317                 $placeholders .= "?,";
318             }
319             print "\n" unless $silent;
320             $fieldlist    =~ s/,$//;
321             $placeholders =~ s/,$//;
322             my $sth =
323               $dbh->prepare(
324                 "insert into $table ($fieldlist) values ($placeholders)");
325             $sth->execute(@values);
326         }
327     }
328 }
329
330 # at last, remove useless fields
331 foreach $table ( keys %uselessfields ) {
332         my @fields = split /,/,$uselessfields{$table};
333         my $fields;
334         my $exists;
335         foreach my $fieldtodrop (@fields) {
336                 $fieldtodrop =~ s/\t//g;
337                 $fieldtodrop =~ s/\n//g;
338                 $exists =0;
339                 $sth = $dbh->prepare("show columns from $table");
340                 $sth->execute;
341                 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
342                 {
343                         $exists =1 if ($column eq $fieldtodrop);
344                 }
345                 if ($exists) {
346                         print "deleting $fieldtodrop field in $table...\n" unless $silent;
347                         my $sth = $dbh->prepare("alter table $table drop $fieldtodrop");
348                         $sth->execute;
349                 }
350         }
351 }    # foreach
352
353
354 $sth->finish;
355
356 exit;
357
358 # $Log$
359 # Revision 1.114  2005/07/28 15:10:13  tipaul
360 # 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.
361 # the letter table contains 3 fields :
362 # * code => the code of the letter
363 # * name => the complete name of the letter
364 # * content => the complete text. It's a TEXT field type, so has no limits.
365 #
366 # My next goal now is to work on point 2-I "serial issue alert"
367 # 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.
368 # (see mail on koha-devel, 2005/04/07)
369 #
370 # The "serial issue alert" will be the 1st to use this letter system that probably needs some tweaking ;-)
371 #
372 # Once it will be stabilised default letters (in any languages) could be added during installer to help the library begin with this new feature.
373 #
374 # Revision 1.113  2005/07/28 08:38:41  tipaul
375 # 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 :
376 # * ReturnBeforeExpiry = yes => return date can't be after expiry date
377 # * ReturnBeforeExpiry = no  => return date can be after expiry date
378 #
379 # Revision 1.112  2005/07/26 08:19:47  hdl
380 # Adding IndependantBranches System preference variable in order to manage Branch independancy.
381 #
382 # Revision 1.111  2005/07/25 15:35:38  tipaul
383 # we have decided that moving to Koha 3.0 requires being already in Koha 2.2.x
384 # So, the updatedatabase script can highly be cleaned (90% removed).
385 # Let's play with the new Koha DB structure now ;-)
386 #
387 #!/usr/bin/perl
388
389 # $Id$
390
391 # Database Updater
392 # This script checks for required updates to the database.
393
394 # Part of the Koha Library Software www.koha.org
395 # Licensed under the GPL.
396
397 # Bugs/ToDo:
398 # - Would also be a good idea to offer to do a backup at this time...
399
400 # NOTE:  If you do something more than once in here, make it table driven.
401 use strict;
402
403 # CPAN modules
404 use DBI;
405 use Getopt::Long;
406 # Koha modules
407 use C4::Context;
408
409 # FIXME - The user might be installing a new database, so can't rely
410 # on /etc/koha.conf anyway.
411
412 my $debug = 0;
413
414 my (
415     $sth, $sti,
416     $query,
417     %existingtables,    # tables already in database
418     %types,
419     $table,
420     $column,
421     $type, $null, $key, $default, $extra,
422     $prefitem,          # preference item in systempreferences table
423 );
424
425 my $silent;
426 GetOptions(
427         's' =>\$silent
428         );
429 my $dbh = C4::Context->dbh;
430 print "connected to your DB. Checking & modifying it\n" unless $silent;
431
432 #-------------------
433 # Defines
434
435 # Tables to add if they don't exist
436 my %requiretables = (
437     categorytable       => "(categorycode char(5) NOT NULL default '',
438                              description text default '',
439                              itemtypecodes text default '',
440                              PRIMARY KEY (categorycode)
441                             )",
442     subcategorytable       => "(subcategorycode char(5) NOT NULL default '',
443                              description text default '',
444                              itemtypecodes text default '',
445                              PRIMARY KEY (subcategorycode)
446                             )",
447     mediatypetable       => "(mediatypecode char(5) NOT NULL default '',
448                              description text default '',
449                              itemtypecodes text default '',
450                              PRIMARY KEY (mediatypecode)
451                             )",
452     action_logs         => "(
453                                     `timestamp` TIMESTAMP NOT NULL ,
454                                     `user` INT( 11 ) NOT NULL ,
455                                     `module` TEXT default '',
456                                     `action` TEXT default '' ,
457                                     `object` INT(11) default '' ,
458                                     `info` TEXT default '' ,
459                                     PRIMARY KEY ( `timestamp` , `user` )
460                             )",
461 );
462
463 my %requirefields = (
464 #    tablename        => { 'field' => 'fieldtype' },
465 );
466
467 my %dropable_table = (
468 # tablename => 'tablename',
469 );
470
471 my %uselessfields = (
472 # tablename => "field1,field2",
473         );
474 # the other hash contains other actions that can't be done elsewhere. they are done
475 # either BEFORE of AFTER everything else, depending on "when" entry (default => AFTER)
476
477 # The tabledata hash contains data that should be in the tables.
478 # The uniquefieldrequired hash entry is used to determine which (if any) fields
479 # must not exist in the table for this row to be inserted.  If the
480 # uniquefieldrequired entry is already in the table, the existing data is not
481 # modified, unless the forceupdate hash entry is also set.  Fields in the
482 # anonymous "forceupdate" hash will be forced to be updated to the default
483 # values given in the %tabledata hash.
484
485 my %tabledata = (
486 # tablename => [
487 #       {       uniquefielrequired => 'fieldname', # the primary key in the table
488 #               fieldname => fieldvalue,
489 #               fieldname2 => fieldvalue2,
490 #       },
491 # ],
492     systempreferences => [
493                 {
494             uniquefieldrequired => 'variable',
495             variable            => 'Activate_Log',
496             value               => 'On',
497             forceupdate         => { 'explanation' => 1,
498                                      'type' => 1},
499             explanation         => 'Turn Log Actions on DB On an Off',
500             type                => 'YesNo',
501         },
502         {
503             uniquefieldrequired => 'variable',
504             variable            => 'IndependantBranches',
505             value               => 0,
506             forceupdate         => { 'explanation' => 1,
507                                      'type' => 1},
508             explanation         => 'Turn Branch independancy management On an Off',
509             type                => 'YesNo',
510         },
511
512     ],
513
514 );
515
516 my %fielddefinitions = (
517 # fieldname => [
518 #       {                 field => 'fieldname',
519 #             type    => 'fieldtype',
520 #             null    => '',
521 #             key     => '',
522 #             default => ''
523 #         },
524 #     ],
525 );
526
527 #-------------------
528 # Initialize
529
530 # Start checking
531
532 # Get version of MySQL database engine.
533 my $mysqlversion = `mysqld --version`;
534 $mysqlversion =~ /Ver (\S*) /;
535 $mysqlversion = $1;
536 if ( $mysqlversion ge '3.23' ) {
537     print "Could convert to MyISAM database tables...\n" unless $silent;
538 }
539
540 #---------------------------------
541 # Tables
542
543 # Collect all tables into a list
544 $sth = $dbh->prepare("show tables");
545 $sth->execute;
546 while ( my ($table) = $sth->fetchrow ) {
547     $existingtables{$table} = 1;
548 }
549
550
551 # Now add any missing tables
552 foreach $table ( keys %requiretables ) {
553     unless ( $existingtables{$table} ) {
554         print "Adding $table table...\n" unless $silent;
555         my $sth = $dbh->prepare("create table $table $requiretables{$table}");
556         $sth->execute;
557         if ( $sth->err ) {
558             print "Error : $sth->errstr \n";
559             $sth->finish;
560         }    # if error
561     }    # unless exists
562 }    # foreach
563
564 # now drop useless tables
565 foreach $table ( keys %dropable_table ) {
566         if ( $existingtables{$table} ) {
567                 print "Dropping unused table $table\n" if $debug and not $silent;
568                 $dbh->do("drop table $table");
569                 if ( $dbh->err ) {
570                         print "Error : $dbh->errstr \n";
571                 }
572         }
573 }
574
575 #---------------------------------
576 # Columns
577
578 foreach $table ( keys %requirefields ) {
579     print "Check table $table\n" if $debug and not $silent;
580     $sth = $dbh->prepare("show columns from $table");
581     $sth->execute();
582     undef %types;
583     while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
584     {
585         $types{$column} = $type;
586     }    # while
587     foreach $column ( keys %{ $requirefields{$table} } ) {
588         print "  Check column $column  [$types{$column}]\n" if $debug and not $silent;
589         if ( !$types{$column} ) {
590
591             # column doesn't exist
592             print "Adding $column field to $table table...\n" unless $silent;
593             $query = "alter table $table
594                         add column $column " . $requirefields{$table}->{$column};
595             print "Execute: $query\n" if $debug;
596             my $sti = $dbh->prepare($query);
597             $sti->execute;
598             if ( $sti->err ) {
599                 print "**Error : $sti->errstr \n";
600                 $sti->finish;
601             }    # if error
602         }    # if column
603     }    # foreach column
604 }    # foreach table
605
606 foreach $table ( keys %fielddefinitions ) {
607         print "Check table $table\n" if $debug;
608         $sth = $dbh->prepare("show columns from $table");
609         $sth->execute();
610         my $definitions;
611         while ( ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
612         {
613                 $definitions->{$column}->{type}    = $type;
614                 $definitions->{$column}->{null}    = $null;
615                 $definitions->{$column}->{key}     = $key;
616                 $definitions->{$column}->{default} = $default;
617                 $definitions->{$column}->{extra}   = $extra;
618         }    # while
619         my $fieldrow = $fielddefinitions{$table};
620         foreach my $row (@$fieldrow) {
621                 my $field   = $row->{field};
622                 my $type    = $row->{type};
623                 my $null    = $row->{null};
624                 my $key     = $row->{key};
625                 my $default = $row->{default};
626                 $default="''" unless $default;
627                 my $extra   = $row->{extra};
628                 my $def     = $definitions->{$field};
629                 unless ( $type eq $def->{type}
630                         && $null eq $def->{null}
631                         && $key eq $def->{key}
632                         && $default eq $def->{default}
633                         && $extra eq $def->{extra} )
634                 {
635
636                         if ( $null eq '' ) {
637                                 $null = 'NOT NULL';
638                         }
639                         if ( $key eq 'PRI' ) {
640                                 $key = 'PRIMARY KEY';
641                         }
642                         unless ( $extra eq 'auto_increment' ) {
643                                 $extra = '';
644                         }
645                         # if it's a new column use "add", if it's an old one, use "change".
646                         my $action;
647                         if ($definitions->{$field}->{type}) {
648                                 $action="change $field"
649                         } else {
650                                 $action="add";
651                         }
652 # if it's a primary key, drop the previous pk, before altering the table
653                         my $sth;
654                         if ($key ne 'PRIMARY KEY') {
655                                 $sth =$dbh->prepare("alter table $table $action $field $type $null $key $extra default ?");
656                         } else {
657                                 $sth =$dbh->prepare("alter table $table drop primary key, $action $field $type $null $key $extra default ?");
658                         }
659                         $sth->execute($default);
660                         print "  Alter $field in $table\n" unless $silent;
661                 }
662         }
663 }
664
665
666 # Populate tables with required data
667 foreach my $table ( keys %tabledata ) {
668     print "Checking for data required in table $table...\n" unless $silent;
669     my $tablerows = $tabledata{$table};
670     foreach my $row (@$tablerows) {
671         my $uniquefieldrequired = $row->{uniquefieldrequired};
672         my $uniquevalue         = $row->{$uniquefieldrequired};
673         my $forceupdate         = $row->{forceupdate};
674         my $sth                 =
675           $dbh->prepare(
676 "select $uniquefieldrequired from $table where $uniquefieldrequired=?"
677         );
678         $sth->execute($uniquevalue);
679         if ($sth->rows) {
680             foreach my $field (keys %$forceupdate) {
681                 if ($forceupdate->{$field}) {
682                     my $sth=$dbh->prepare("update systempreferences set $field=? where $uniquefieldrequired=?");
683                     $sth->execute($row->{$field}, $uniquevalue);
684                 }
685             }
686         } else {
687             print "Adding row to $table: " unless $silent;
688             my @values;
689             my $fieldlist;
690             my $placeholders;
691             foreach my $field ( keys %$row ) {
692                 next if $field eq 'uniquefieldrequired';
693                 next if $field eq 'forceupdate';
694                 my $value = $row->{$field};
695                 push @values, $value;
696                 print "  $field => $value" unless $silent;
697                 $fieldlist .= "$field,";
698                 $placeholders .= "?,";
699             }
700             print "\n" unless $silent;
701             $fieldlist    =~ s/,$//;
702             $placeholders =~ s/,$//;
703             my $sth =
704               $dbh->prepare(
705                 "insert into $table ($fieldlist) values ($placeholders)");
706             $sth->execute(@values);
707         }
708     }
709 }
710
711 # at last, remove useless fields
712 foreach $table ( keys %uselessfields ) {
713         my @fields = split /,/,$uselessfields{$table};
714         my $fields;
715         my $exists;
716         foreach my $fieldtodrop (@fields) {
717                 $fieldtodrop =~ s/\t//g;
718                 $fieldtodrop =~ s/\n//g;
719                 $exists =0;
720                 $sth = $dbh->prepare("show columns from $table");
721                 $sth->execute;
722                 while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow )
723                 {
724                         $exists =1 if ($column eq $fieldtodrop);
725                 }
726                 if ($exists) {
727                         print "deleting $fieldtodrop field in $table...\n" unless $silent;
728                         my $sth = $dbh->prepare("alter table $table drop $fieldtodrop");
729                         $sth->execute;
730                 }
731         }
732 }    # foreach
733
734
735 $sth->finish;
736
737 exit;
738
739 # $Log$
740 # Revision 1.114  2005/07/28 15:10:13  tipaul
741 # 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.
742 # the letter table contains 3 fields :
743 # * code => the code of the letter
744 # * name => the complete name of the letter
745 # * content => the complete text. It's a TEXT field type, so has no limits.
746 #
747 # My next goal now is to work on point 2-I "serial issue alert"
748 # 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.
749 # (see mail on koha-devel, 2005/04/07)
750 #
751 # The "serial issue alert" will be the 1st to use this letter system that probably needs some tweaking ;-)
752 #
753 # Once it will be stabilised default letters (in any languages) could be added during installer to help the library begin with this new feature.
754 #
755 # Revision 1.113  2005/07/28 08:38:41  tipaul
756 # 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 :
757 # * ReturnBeforeExpiry = yes => return date can't be after expiry date
758 # * ReturnBeforeExpiry = no  => return date can be after expiry date
759 #
760 # Revision 1.112  2005/07/26 08:19:47  hdl
761 # Adding IndependantBranches System preference variable in order to manage Branch independancy.
762 #
763 # Revision 1.111  2005/07/25 15:35:38  tipaul
764 # we have decided that moving to Koha 3.0 requires being already in Koha 2.2.x
765 # So, the updatedatabase script can highly be cleaned (90% removed).
766 # Let's play with the new Koha DB structure now ;-)
767 #