X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=misc%2Fmarc_into_authority.pl;h=1befaf109daf51f7e0950d6b727f33e67f86f5f1;hb=a4c086ac41c0265a4085fa2e7414226f2549340c;hp=e900d02daab9371b8e6c0088e0e9a61d8fc03acc;hpb=dad8b825d34ed9e654516b3086e8c7be7102d759;p=koha.git diff --git a/misc/marc_into_authority.pl b/misc/marc_into_authority.pl index e900d02daa..1befaf109d 100644 --- a/misc/marc_into_authority.pl +++ b/misc/marc_into_authority.pl @@ -9,6 +9,7 @@ use C4::Context; use MARC::Record; use MARC::File::USMARC; use MARC::File::XML; +use C4::AuthoritiesMarc; use Time::HiRes qw(gettimeofday); my $timeneeded; my $starttime = gettimeofday; @@ -23,7 +24,7 @@ $columns{$cols}=1; } ##Update the database if missing fields; - $dbh->do("LOCK TABLES auth_header WRITE auth_subfield_table READ"); + $dbh->do("LOCK TABLES auth_header WRITE, auth_subfield_structure WRITE , auth_subfield_table READ"); unless ($columns{'linkid'}){ my $sth=$dbh->prepare("ALTER TABLE auth_header ADD COLUMN `linkid` BIGINT(20) UNSIGNED NOT NULL DEFAULT 0 "); $sth->execute(); @@ -32,7 +33,31 @@ unless ($columns{'marc'}){ my $sth=$dbh->prepare("ALTER TABLE auth_header ADD COLUMN `marc` BLOB NOT NULL DEFAULT 0 "); $sth->execute(); } - +###Chechk auth_subfield_structure as well. User may have forgotten to update database +my $sthcols=$dbh->prepare("show columns from auth_subfield_structure"); +$sthcols->execute(); +my %columns; +while (( my $cols)=$sthcols->fetchrow){ +$columns{$cols}=1; +} +##Update the database if missing fields; +unless ($columns{'link'}){ +my $sth=$dbh->prepare("ALTER TABLE auth_subfield_structure ADD COLUMN `link` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 "); +$sth->execute(); +} +unless ($columns{'isurl'}){ +my $sth=$dbh->prepare("ALTER TABLE auth_subfield_structure ADD COLUMN `isurl` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0 "); +$sth->execute(); +} +unless ($columns{'hidden'}){ +my $sth=$dbh->prepare("ALTER TABLE auth_subfield_structure ADD COLUMN `hidden` TINYINT(3) UNSIGNED NOT NULL ZEROFILL DEFAULT 000 "); +$sth->execute(); +} +unless ($columns{'kohafield'}){ +my $sth=$dbh->prepare("ALTER TABLE auth_subfield_structure ADD COLUMN `kohafield` VARCHAR(45) NOT NULL "); +$sth->execute(); +} +$dbh->do("UNLOCK TABLES "); my $sth=$dbh->prepare("select authid,authtypecode from auth_header "); $sth->execute(); @@ -41,16 +66,21 @@ my $sth2 = $dbh->prepare("UPDATE auth_header set marc=? where authid=?" ); while (my ($authid,$authtypecode)=$sth->fetchrow ){ - my $record = AUTHgetauthority($dbh,$authid); + my $record = AUTHgetauthorityold($dbh,$authid); +##Add authid and authtypecode to record. Old records did not have these fields +my ($authidfield,$authidsubfield)=AUTHfind_marc_from_kohafield($dbh,"auth_header.authid",$authtypecode); +my ($authidfield,$authtypesubfield)=AUTHfind_marc_from_kohafield($dbh,"auth_header.authtypecode",$authtypecode); +##Both authid and authtypecode is expected to be in the same field. Modify if other requirements arise + $record->add_fields($authidfield,'','',$authidsubfield=>$authid,$authtypesubfield=>$authtypecode); $sth2->execute($record->as_usmarc,$authid); $timeneeded = gettimeofday - $starttime unless ($i % 1000); print "$i in $timeneeded s\n" unless ($i % 1000); print "." unless ($i % 500); $i++; } -$dbh->do("UNLOCK TABLES "); -sub AUTHgetauthority { + +sub AUTHgetauthorityold { # Returns MARC::Record of the biblio passed in parameter. my ($dbh,$authid)=@_; my $record = MARC::Record->new();