[Koha-cvs] CVS: koha/updater thesaurus_create.pl,1.3,1.4

Paul POULAIN tipaul at users.sourceforge.net
Sat Oct 26 19:59:37 CEST 2002


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

Modified Files:
	thesaurus_create.pl 
Log Message:
road to 1.3.2
Thesaurus / authorities support. db schema update

Index: thesaurus_create.pl
===================================================================
RCS file: /cvsroot/koha/koha/updater/thesaurus_create.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** thesaurus_create.pl	5 Oct 2002 10:17:04 -0000	1.3
--- thesaurus_create.pl	26 Oct 2002 17:59:35 -0000	1.4
***************
*** 26,31 ****
  use C4::Catalogue;
  use DBI;
- use C4::Acquisitions;
- use C4::Output;
  
  my $dbh = C4::Context->dbh;
--- 26,29 ----
***************
*** 49,80 ****
  }
  
! print "creating thesaurus...\n";
! dosql($dbh,"CREATE TABLE bibliothesaurus (code BIGINT not null AUTO_INCREMENT, freelib CHAR (255) not null , stdlib CHAR (255) not null , type CHAR (80) not null , PRIMARY KEY (code), INDEX (freelib),index(stdlib),index(type))");
! 	my $sti=$dbh->prepare("select count(*) as tot from bibliosubject");
! 	$sti->execute;
! 	my $total = $sti->fetchrow_hashref;
! 	# FIXME - There's already a $sti in this scope.
! 	my $sti=$dbh->prepare("select subject from bibliosubject");
! 	$sti->execute;
! 	my $i;
! 	while (my $line =$sti->fetchrow_hashref) {
! 		$i++;
! 		if ($i % 1000==0) {
! 			print "$i / $total->{'tot'}\n";
! 		}
! #		print "$i $line->{'subject'}\n";
! 		my $sti2=$dbh->prepare("select count(*) as t from bibliothesaurus where freelib=".$dbh->quote($line->{'subject'}));
! 		$sti2->execute;
! 		if ($sti2->err) {
! 			print "error : ".$sti2->errstr."\n";
! 			die;
! 		}
! 		my $line2=$sti2->fetchrow_hashref;
! 		if ($line2->{'t'} ==0) {
! 			dosql($dbh,"insert into bibliothesaurus (freelib,stdlib) values (".$dbh->quote($line->{'subject'}).",".$dbh->quote($line->{'subject'}).")");
! #		} else {
! #			print "pas ecriture pour : $line->{'subject'}\n";
  		}
! 
  	}
! 
--- 47,100 ----
  }
  
! #print "creating thesaurus...\n";
! #dosql($dbh,"CREATE TABLE bibliothesaurus (code BIGINT not null AUTO_INCREMENT, freelib CHAR (255) not null , stdlib CHAR (255) not null , type CHAR (80) not null , PRIMARY KEY (code), INDEX (freelib),index(stdlib),index(type))");
! $dbh->do("delete from bibliothesaurus");
! my $sti=$dbh->prepare("select count(*) from bibliosubject");
! $sti->execute;
! my ($total) = $sti->fetchrow_array;
! $sti=$dbh->prepare("select subject from bibliosubject");
! $sti->execute;
! my $i;
! my $search_sth = $dbh->prepare("select id,level,hierarchy from bibliothesaurus where stdlib=?");
! my $insert_sth = $dbh->prepare("insert into bibliothesaurus (freelib,stdlib,category,level,hierarchy) values (?,?,?,?,?)");
! while (my $line =$sti->fetchrow_hashref) {
! 	$i++;
! 	if ($i % 1000==0) {
! 		print "$i / $total\n";
! 	}
! 	my @hierarchy = split / - /,$line->{'subject'};
! 	my $rebuild = "";
! 	my $top_hierarchy = "";
! 	#---- if not a main authority field, search where to link
! 	for (my $hier=0; $hier<$#hierarchy+1 ; $hier++) {
! 		$rebuild .=$hierarchy[$hier];
! 		$search_sth->execute($rebuild);
! 		my ($id,$level,$hierarchy) = $search_sth->fetchrow_array;
! #		warn "/($line->{'subject'}) : $rebuild/";
! # if father not found, create father and son
! 		if (!$id) {
! 			$insert_sth->execute($rebuild,$rebuild,"",$hier,"$top_hierarchy");
! 			# search again, to find $id and buiild $top_hierarchy
! 			$search_sth->execute($rebuild);
! 			my ($id,$level,$hierarchy) = $search_sth->fetchrow_array;
! 			$top_hierarchy .="|" if ($top_hierarchy);
! 			$top_hierarchy .= "$id";
! # else create only son
! 		} else {
! 			$top_hierarchy .="|" if ($top_hierarchy);
! 			$top_hierarchy .= "$id";
! #			$insert_sth->execute($rebuild,$rebuild,"",$hier,"$top_hierarchy");
  		}
! 		$rebuild .=" - ";
  	}
! #	my $sti2=$dbh->prepare("select count(*) as t from bibliothesaurus where freelib=".$dbh->quote($line->{'subject'}));
! #	$sti2->execute;
! #	if ($sti2->err) {
! #		print "error : ".$sti2->errstr."\n";
! #		die;
! #	}
! #	my $line2=$sti2->fetchrow_hashref;
! #	if ($line2->{'t'} ==0) {
! #		dosql($dbh,"insert into bibliothesaurus (freelib,stdlib,category) values (".$dbh->quote($line->{'subject'}).",".$dbh->quote($line->{'subject'}).")");
! #	}
! }





More information about the Koha-cvs mailing list