synch'ing 2.2 and head
[koha.git] / z3950 / processz3950queue
index 8ab2ada..543aaa7 100755 (executable)
@@ -104,11 +104,11 @@ if ($< == 0) {
     $>=$uid;
     $<=$uid;
 }
-my $db_driver = $context->{"config"}{"db_scheme"} || "mysql";
-my $db_name   = $context->{"config"}{"database"};
-my $db_host   = $context->{"config"}{"hostname"};
-my $db_user   = $context->{"config"}{"user"};
-my $db_passwd = $context->{"config"}{"pass"};
+my $db_driver = C4::Context->config("db_scheme") || "mysql";
+my $db_name   = C4::Context->config("database");
+my $db_host   = C4::Context->config("hostname");
+my $db_user   = C4::Context->config("user");
+my $db_passwd = C4::Context->config("pass");
 my $dbh = DBI->connect("DBI:$db_driver:$db_name:$db_host",$db_user, $db_passwd);
 
 # we begin the script, so "unactive" every pending request : they will never give anything, the script died :-(
@@ -132,7 +132,6 @@ my $pid=$$;
 my $lastrun=0;
 while (1) {
        if ((time-$lastrun)>5) {
-               print "starting loop\n";
                $checkqueue = 1; # FIXME during testing, this line forces the loop. REMOVE it to use SIG{HUP} when "daemonized" !
 # clean DB
                my $now = time();
@@ -183,13 +182,14 @@ while (1) {
                                                        $forkcounter++;
                                                } else {
 # and connect to z3950 server
-# new connection required ($dbi) because we might have forked (thanks Harry Jackson)
-                                                       my $db_driver = $context->{"config"}{"db_scheme"} || "mysql";
-                                                       my $db_name   = $context->{"config"}{"database"};
-                                                       my $db_host   = $context->{"config"}{"hostname"};
-                                                       my $db_user   = $context->{"config"}{"user"};
-                                                       my $db_passwd = $context->{"config"}{"pass"};
+#FIXME: why do we need $dbi ? can't we use $dbh ?
+                                                       my $db_driver = C4::Context->config("db_scheme") || "mysql";
+                                                       my $db_name   = C4::Context->config("database");
+                                                       my $db_host   = C4::Context->config("hostname");
+                                                       my $db_user   = C4::Context->config("user");
+                                                       my $db_passwd = C4::Context->config("pass");
                                                        my $dbi = DBI->connect("DBI:$db_driver:$db_name:$db_host",$db_user, $db_passwd);
+                                                       $dbh->{"InactiveDestroy"} = "true";
                                                        my ($name, $server, $database, $user, $password,$syntax) = split(/\//, $serverinfo, 6);
                                                        $globalname=$name;
                                                        $globalsyntax = $syntax;
@@ -257,7 +257,7 @@ while (1) {
 #######
                                                                print "$$/$id : connected to $globalname\n";
                                                                eval {$conn->option(elementSetName => 'F')};
-                                                               eval { $conn->option(preferredRecordSyntax => Net::Z3950::RecordSyntax::USMARC);} if ($globalsyntax eq "USMARC");
+                                                               eval { $conn->option(preferredRecordSyntax => Net::Z3950::RecordSyntax::USMARC);} if ($globalsyntax eq "MARC21");
                                                                eval { $conn->option(preferredRecordSyntax => Net::Z3950::RecordSyntax::UNIMARC);} if ($globalsyntax eq "UNIMARC");
                                                                if ($@) {
                                                                        print "$$/$id : $globalname ERROR: $@ for $resultsid\n";
@@ -282,14 +282,11 @@ while (1) {
                                                                                my $rec=$rs->record($i);
                                                                                my $marcdata;
                                                                                # use render() or rawdata() depending on the type of the returned record
-                                                                               my $marcrecord;
                                                                                if (ref($rec) eq "Net::Z3950::Record::USMARC") {
                                                                                        $marcdata = $rec->rawdata();
-                                                                                       $marcrecord = MARC::File::USMARC::decode($rec->rawdata())
                                                                                }
                                                                                if (ref($rec) eq "Net::Z3950::Record::UNIMARC") {
-                                                                                       $marcdata = $rec->render();
-                                                                                       $marcrecord = MARC::File::USMARC::decode($rec->render())
+                                                                                       $marcdata = $rec->rawdata();
                                                                                }
                                                                                $globalencoding = ref($rec);
                                                                                $result.=$marcdata;