koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] CVS: koha/updater updatedatabase,1.25,1.26


From: Steve Tonnesen
Subject: [Koha-cvs] CVS: koha/updater updatedatabase,1.25,1.26
Date: Tue, 12 Nov 2002 09:42:46 -0800

Update of /cvsroot/koha/koha/updater
In directory usw-pr-cvs1:/tmp/cvs-serv11634

Modified Files:
        updatedatabase 
Log Message:
Merged some features over from rel-1-2, including primary key checking.


Index: updatedatabase
===================================================================
RCS file: /cvsroot/koha/koha/updater/updatedatabase,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** updatedatabase      12 Nov 2002 16:44:38 -0000      1.25
--- updatedatabase      12 Nov 2002 17:42:40 -0000      1.26
***************
*** 233,246 ****
                    );
  
- # Default system preferences
- my %defaultprefs=(
-               'autoMemberNum'=> ['1','1 or else. If 1, Barcode is 
auto-calculated'],
-               'acquisitions'=> ['simple','normal or simple : will use 
acquisition system found in directory acqui.simple or acquisition'],
-               'template' => ['default','template default name'],
-               'autoBarcode' => ['0','1 or else. If 1, Barcode is 
auto-calculated'],
-               'insecure' => ['no','if YES, no auth at all is needed. Be 
careful if you set this to yes !'],
-               'authoritysep' => ['--','the separator used in 
authority/thesaurus. Usually --']
-                 );
  
  
  # Start checking
--- 233,286 ----
                    );
  
  
+ # The tabledata hash contains data that should be in the tables.
+ # The uniquefieldrequired hash entry is used to determine which (if any) 
fields
+ # must not exist in the table for this row to be inserted.  If the
+ # uniquefieldrequired entry is already in the table, the existing data is not
+ # modified.
+ 
+ my %tabledata=(
+     userflags => [ 
+       { uniquefieldrequired => 'bit', bit => 0, flag => 'superlibrarian', 
flagdesc => 'Access to all librarian functions', defaulton => 0 },
+       { uniquefieldrequired => 'bit', bit => 1, flag => 'circulate', flagdesc 
=> 'Circulate books', defaulton => 0 },
+       { uniquefieldrequired => 'bit', bit => 2, flag => 'catalogue', flagdesc 
=> 'View Catalogue (Librarian Interface)', defaulton => 0 },
+       { uniquefieldrequired => 'bit', bit => 3, flag => 'parameters', 
flagdesc => 'Set Koha system paramters', defaulton => 0 },
+       { uniquefieldrequired => 'bit', bit => 4, flag => 'borrowers', flagdesc 
=> 'Add or modify borrowers', defaulton => 0 },
+       { uniquefieldrequired => 'bit', bit => 5, flag => 'permissions', 
flagdesc => 'Set user permissions', defaulton => 0 },
+       { uniquefieldrequired => 'bit', bit => 6, flag => 'reserveforothers', 
flagdesc => 'Reserve books for patrons', defaulton => 0 },
+       { uniquefieldrequired => 'bit', bit => 7, flag => 'borrow', flagdesc => 
'Borrow books', defaulton => 1 },
+       { uniquefieldrequired => 'bit', bit => 8, flag => 'reserveforself', 
flagdesc => 'Reserve books for self', defaulton => 0 },
+       { uniquefieldrequired => 'bit', bit => 9, flag => 'editcatalogue', 
flagdesc => 'Edit Catalogue (Modify bibliographic/holdings data)', defaulton => 
0 },
+       { uniquefieldrequired => 'bit', bit => 10, flag => 'updatecharges', 
flagdesc => 'Update borrower charges', defaulton => 0 },
+     ],
+     systempreferences => [
+       { uniquefieldrequired => 'variable', variable => 'autoMemberNum', value 
=> '1', explanation => '1 or else. If 1, Barcode is auto-calculated' },
+       { uniquefieldrequired => 'variable', variable => 'acquisitions', value 
=> 'simple', explanation => 'normal or simple : will use acquisition system 
found in directory acqui.simple or acquisition' },
+       { uniquefieldrequired => 'variable', variable => 'dateformat', value => 
'metric', explanation => 'metric or us' },
+       { uniquefieldrequired => 'variable', variable => 'template', value => 
'metric', explanation => 'template default name' },
+       { uniquefieldrequired => 'variable', variable => 'autoBarcode', value 
=> 'metric', explanation => '1 or else. If 1, Barcode is auto-calculated' },
+       { uniquefieldrequired => 'variable', variable => 'insecure', value => 
'metric', explanation => 'if YES, no auth at all is needed. Be careful if you 
set this to yes !' },
+       { uniquefieldrequired => 'variable', variable => 'authoritysep', value 
=> '--', explanation => 'the separator used in authority/thesaurus. Usually --' 
},
+     ],
+ 
+ );
+ 
+ 
+ my %fielddefinitions=(
+ printers => [
+       { field => 'printername', type => 'char(40)', null => '', key => 'PRI', 
default => '' },
+       ],
+ aqbookfund => [
+       { field => 'bookfundid', type => 'char(5)', null => '', key => 'PRI', 
default => '' },
+       ],
+ z3950servers => [
+       { field => 'id', type => 'int', null => '', key => 'PRI', default => 
'', extra => 'auto_increment' },
+       ],
+ );
+ 
+ 
+ 
+ #-------------------
+ # Initialize
  
  # Start checking
***************
*** 342,345 ****
--- 382,423 ----
  } # foreach table
  
+ foreach $table ( keys %fielddefinitions ) {
+     print "Check table $table\n" if $debug;
+     $sth=$dbh->prepare("show columns from $table");
+     $sth->execute();
+     my $definitions;
+     while ( ($column, $type, $null, $key, $default, $extra) = $sth->fetchrow) 
{
+       $definitions->{$column}->{type}=$type;
+       $definitions->{$column}->{null}=$null;
+       $definitions->{$column}->{key}=$key;
+       $definitions->{$column}->{default}=$default;
+       $definitions->{$column}->{extra}=$extra;
+     } # while 
+     my $fieldrow=$fielddefinitions{$table};
+     foreach my $row ( @$fieldrow )  {
+       my $field = $row->{field};
+       my $type = $row->{type};
+       my $null = $row->{null};
+       my $key = $row->{key};
+       my $default = $row->{default};
+       my $extra = $row->{extra};
+       my $def=$definitions->{$field};
+       unless ($type eq $def->{type} && $null eq $def->{null} && $key eq 
$def->{key} && $default eq $def->{default} && $extra eq $def->{extra}) {
+           if ($null eq '') {
+               $null='NOT NULL';
+           }
+           if ($key eq 'PRI') {
+               $key ='PRIMARY KEY';
+           }
+           unless ($extra eq 'auto_increment') {
+               $extra='';
+           }
+           my $sth=$dbh->prepare("alter table $table change $field $field 
$type $null $key $extra default ?");
+           $sth->execute($default);
+           print "  Alter $field in $table\n";
+       }
+     }
+ }
+ 
  # Get list of columns from items table
  my %itemtypes;
***************
*** 412,429 ****
  
  
! # Populate systempreferences if it is empty
! 
! foreach $prefitem ( keys %defaultprefs ) {
!       $sth=$dbh->prepare("select value
!                                                               from 
systempreferences
!                                                               where 
variable=?");
!       $sth->execute($prefitem);
        unless ($sth->rows) {
!               print "Adding system preference item $prefitem with value " 
.$defaultprefs{$prefitem}[0] ."\n";
!               $sti=$dbh->prepare("insert into systempreferences (variable, 
value,explanation) values (?,?,?)");
!               
$sti->execute($prefitem,$defaultprefs{$prefitem}[0],$defaultprefs{$prefitem}[1]);
!       } # unless
! } # foreach
! 
  
  $sth->finish;
--- 490,524 ----
  
  
! # Populate tables with required data
!  
! foreach my $table (keys %tabledata) {
!     print "Checking for data required in table $table...\n";
!     my $tablerows=$tabledata{$table};
!     foreach my $row (@$tablerows) {
!       my $uniquefieldrequired=$row->{uniquefieldrequired};
!       my $uniquevalue=$row->{$uniquefieldrequired};
!       my $sth=$dbh->prepare("select $uniquefieldrequired from $table where 
$uniquefieldrequired=?");
!       $sth->execute($uniquevalue);
        unless ($sth->rows) {
!           print "Adding row to $table: ";
!           my @values;
!           my $fieldlist;
!           my $placeholders;
!           foreach my $field (keys %$row) {
!               (next) if ($field eq 'uniquefieldrequired');
!               my $value=$row->{$field};
!               push @values, $value;
!               print "  $field => $value";
!               $fieldlist.="$field,";
!               $placeholders.="?,";
!           }
!           print "\n";
!           $fieldlist=~s/,$//;
!           $placeholders=~s/,$//;
!           my $sth=$dbh->prepare("insert into $table ($fieldlist) values 
($placeholders)");
!           $sth->execute(@values);
!       }
!     }
! }
  
  $sth->finish;
***************
*** 432,435 ****
--- 527,533 ----
  
  # $Log$
+ # Revision 1.26  2002/11/12 17:42:40  tonnesen
+ # Merged some features over from rel-1-2, including primary key checking.
+ #
  # Revision 1.25  2002/11/12 16:44:38  tipaul
  # road to 1.3.2 :




reply via email to

[Prev in Thread] Current Thread [Next in Thread]