|
@ -16,12 +16,44 @@ use DBI; |
|
|
|
|
|
|
|
|
# Koha modules |
|
|
# Koha modules |
|
|
use C4::Database; |
|
|
use C4::Database; |
|
|
#use C4::Catalogue; |
|
|
|
|
|
use C4::Acquisitions; |
|
|
|
|
|
use C4::Output; |
|
|
|
|
|
|
|
|
|
|
|
my %tables; |
|
|
my %existingtables; # tables already in database |
|
|
my %types; |
|
|
my %types; |
|
|
|
|
|
my $table; |
|
|
|
|
|
|
|
|
|
|
|
#------------------- |
|
|
|
|
|
# Defines |
|
|
|
|
|
|
|
|
|
|
|
# Tables to add if they don't exist |
|
|
|
|
|
my %requiretables=( |
|
|
|
|
|
shelfcontents=>"( shelfnumber int not null, |
|
|
|
|
|
itemnumber int not null, |
|
|
|
|
|
flags int)", |
|
|
|
|
|
bookshelf=>"( shelfnumber int auto_increment primary key, |
|
|
|
|
|
shelfname char(255))", |
|
|
|
|
|
z3950queue=>"( id int auto_increment primary key, |
|
|
|
|
|
term text, |
|
|
|
|
|
type char(10), |
|
|
|
|
|
startdate int, |
|
|
|
|
|
enddate int, |
|
|
|
|
|
done smallint, |
|
|
|
|
|
results longblob, |
|
|
|
|
|
numrecords int, |
|
|
|
|
|
servers text, |
|
|
|
|
|
identifier char(30))", |
|
|
|
|
|
z3950results=>"( id int auto_increment primary key, |
|
|
|
|
|
queryid int, |
|
|
|
|
|
server char(255), |
|
|
|
|
|
startdate int, |
|
|
|
|
|
enddate int, |
|
|
|
|
|
results longblob, |
|
|
|
|
|
numrecords int, |
|
|
|
|
|
numdownloaded int, |
|
|
|
|
|
highestseen int, |
|
|
|
|
|
active smallint)", |
|
|
|
|
|
branchrelations=>"( branchcode varchar(4), |
|
|
|
|
|
categorycode varchar(4))", |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
#------------------- |
|
|
#------------------- |
|
|
# Initialize |
|
|
# Initialize |
|
@ -44,62 +76,25 @@ if ($mysqlversion ge '3.23') { |
|
|
my $sth=$dbh->prepare("show tables"); |
|
|
my $sth=$dbh->prepare("show tables"); |
|
|
$sth->execute; |
|
|
$sth->execute; |
|
|
while (my ($table) = $sth->fetchrow) { |
|
|
while (my ($table) = $sth->fetchrow) { |
|
|
$tables{$table}=1; |
|
|
$existingtables{$table}=1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
# Now add any missing tables |
|
|
# Now add any missing tables |
|
|
|
|
|
foreach $table ( keys %requiretables ) { |
|
|
# Add tables for virtual bookshelf management |
|
|
unless ($existingtables{$table} ) { |
|
|
unless ($tables{'shelfcontents'}) { |
|
|
print "Adding $table table...\n"; |
|
|
print "Adding shelfcontents table...\n"; |
|
|
my $sth=$dbh->prepare( |
|
|
my $sti=$dbh->prepare("create table shelfcontents ( |
|
|
"create table $table $requiretables{$table}" ); |
|
|
shelfnumber int not null, |
|
|
$sth->execute; |
|
|
itemnumber int not null, |
|
|
if ($sth->err) { |
|
|
flags int)"); |
|
|
print "Error : $sth->errstr \n"; |
|
|
$sti->execute; |
|
|
$sth->finish; |
|
|
} |
|
|
} # if error |
|
|
unless ($tables{'bookshelf'}) { |
|
|
} # unless exists |
|
|
print "Adding bookshelf table...\n"; |
|
|
} # foreach |
|
|
my $sti=$dbh->prepare("create table bookshelf ( |
|
|
exit; |
|
|
shelfnumber int auto_increment primary key, |
|
|
|
|
|
shelfname char(255))"); |
|
|
unless ($existingtables{'z3950servers'}) { |
|
|
$sti->execute; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
# Add tables required by Z-3950 scripts |
|
|
|
|
|
|
|
|
|
|
|
unless ($tables{'z3950queue'}) { |
|
|
|
|
|
print "Adding z3950queue table...\n"; |
|
|
|
|
|
my $sti=$dbh->prepare("create table z3950queue ( |
|
|
|
|
|
id int auto_increment primary key, |
|
|
|
|
|
term text, |
|
|
|
|
|
type char(10), |
|
|
|
|
|
startdate int, |
|
|
|
|
|
enddate int, |
|
|
|
|
|
done smallint, |
|
|
|
|
|
results longblob, |
|
|
|
|
|
numrecords int, |
|
|
|
|
|
servers text, |
|
|
|
|
|
identifier char(30))"); |
|
|
|
|
|
$sti->execute; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unless ($tables{'z3950results'}) { |
|
|
|
|
|
print "Adding z3950results table...\n"; |
|
|
|
|
|
my $sti=$dbh->prepare("create table z3950results ( |
|
|
|
|
|
id int auto_increment primary key, |
|
|
|
|
|
queryid int, |
|
|
|
|
|
server char(255), |
|
|
|
|
|
startdate int, |
|
|
|
|
|
enddate int, |
|
|
|
|
|
results longblob, |
|
|
|
|
|
numrecords int, |
|
|
|
|
|
numdownloaded int, |
|
|
|
|
|
highestseen int, |
|
|
|
|
|
active smallint)"); |
|
|
|
|
|
$sti->execute; |
|
|
|
|
|
} |
|
|
|
|
|
unless ($tables{'z3950servers'}) { |
|
|
|
|
|
print "Adding z3950servers table...\n"; |
|
|
print "Adding z3950servers table...\n"; |
|
|
my $sti=$dbh->prepare("create table z3950servers ( |
|
|
my $sti=$dbh->prepare("create table z3950servers ( |
|
|
host char(255), |
|
|
host char(255), |
|
@ -122,15 +117,6 @@ unless ($tables{'z3950servers'}) { |
|
|
$sti->execute; |
|
|
$sti->execute; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
# Create new branchrelations table if it doesnt already exist.... |
|
|
|
|
|
unless ($tables{'branchrelations'} ) { |
|
|
|
|
|
print "creating branchrelations table\n"; |
|
|
|
|
|
my $sth=$dbh->prepare("create table branchrelations ( |
|
|
|
|
|
branchcode varchar(4), |
|
|
|
|
|
categorycode varchar(4))"); |
|
|
|
|
|
$sth->execute; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#--------------------------------- |
|
|
#--------------------------------- |
|
|
# Columns |
|
|
# Columns |
|
|
|
|
|
|
|
|