9fb81afb85
Database.pm and Output.pm are almost not modified (var test...) Biblio.pm is almost completly rewritten. WHAT DOES IT ??? ==> END of Hitchcock suspens 1st, it does... nothing... Every old API should be there. So if MARC-stuff is not done, the behaviour is EXACTLY the same (if there is no added bug, of course). So, if you use normal acquisition, you won't find anything new neither on screen or old-DB tables ... All old-API functions have been cloned. for example, the "newbiblio" sub, now has become : * a "newbiblio" sub, with the same parameters. It just call a sub named OLDnewbiblio * a "OLDnewbiblio" sub, which is a copy/paste of the previous newbiblio sub. Then, when you want to add the MARC-DB stuff, you can modify the newbiblio sub without modifying the OLDnewbiblio one. If we correct a bug in 1.2 in newbiblio, we can do the same in main branch by correcting OLDnewbiblio. * The MARC stuff is usually done through a sub named MARCxxx where xxx is the same as OLDxxx. For example, newbiblio calls MARCnewbiblio. the MARCxxx subs use a MARC::Record as parameter. The last thing to solve was to manage biblios through real MARC import : they must populate the old-db, but must populate the MARC-DB too, without loosing information (if we go from MARC::Record to old-data then back to MARC::Record, we loose A LOT OF ROWS). To do this, there are subs beginning by "ALLxxx" : they manage datas with MARC::Record datas. they call OLDxxx sub too (to populate old-DB), but MARCxxx subs too, with a complete MARC::Record ;-) In Biblio.pm, there are some subs that permits to build a old-style record from a MARC::Record, and the opposite. There is also a sub finding a MARC-bibid from a old-biblionumber and the opposite too. Note we have decided with steve that a old-biblio <=> a MARC-Biblio.
61 lines
1.4 KiB
Perl
Executable file
61 lines
1.4 KiB
Perl
Executable file
package C4::Database; #asummes C4/Database
|
|
|
|
#requires DBI.pm to be installed
|
|
|
|
use strict;
|
|
require Exporter;
|
|
use DBI;
|
|
use vars qw($VERSION @ISA @EXPORT);
|
|
|
|
$VERSION = 0.01;
|
|
|
|
@ISA = qw(Exporter);
|
|
@EXPORT = qw(
|
|
&C4Connect &requireDBI
|
|
);
|
|
|
|
|
|
sub C4Connect {
|
|
my $dbname="c4";
|
|
my ($database,$hostname,$user,$pass,%configfile);
|
|
open (KC, "/etc/koha.conf");
|
|
while (<KC>) {
|
|
chomp;
|
|
(next) if (/^\s*#/);
|
|
if (/(.*)\s*=\s*(.*)/) {
|
|
my $variable=$1;
|
|
my $value=$2;
|
|
# Clean up white space at beginning and end
|
|
$variable=~s/^\s*//g;
|
|
$variable=~s/\s*$//g;
|
|
$value=~s/^\s*//g;
|
|
$value=~s/\s*$//g;
|
|
$configfile{$variable}=$value;
|
|
}
|
|
}
|
|
$database=$configfile{'database'};
|
|
$hostname=$configfile{'hostname'};
|
|
$user=$configfile{'user'};
|
|
$pass=$configfile{'pass'};
|
|
|
|
my $dbh=DBI->connect("DBI:mysql:$database:$hostname",$user,$pass);
|
|
return $dbh;
|
|
} # sub C4Connect
|
|
|
|
#------------------
|
|
# Helper subroutine to make sure database handle was passed properly
|
|
sub requireDBI {
|
|
my (
|
|
$dbh,
|
|
$subrname, # name of calling subroutine
|
|
)=@_;
|
|
|
|
unless ( ref($dbh) =~ /DBI::db/ ) {
|
|
print "<pre>\nERROR: Subroutine $subrname called without proper DBI handle.\n" .
|
|
"Please contact system administrator.\n</pre>\n";
|
|
die "ERROR: Subroutine $subrname called without proper DBI handle.\n";
|
|
}
|
|
} # sub requireDBI
|
|
|
|
|
|
END { }
|