use C4::AuthoritiesMarc::MARC21;
use C4::AuthoritiesMarc::UNIMARC;
use C4::Charset;
+use C4::Debug;
use vars qw($VERSION @ISA @EXPORT);
my $n=0;
my @authtypecode;
my @auths=split / /,$authtypecode ;
+ my @queries;
foreach my $auth (@auths){
- $query .=" \@attr 1=authtype \@attr 5=100 ".$auth; ##No truncation on authtype
+ push @queries, " \@attr 1=authtype \@attr 5=100 ".$auth; ##No truncation on authtype
push @authtypecode ,$auth;
$n++;
}
my $dosearch;
my $and=" \@and " ;
- my $q2;
for(my $i = 0 ; $i <= $#{$value} ; $i++)
{
if (@$value[$i]){
##If mainentry search $a tag
if (@$tags[$i] eq "mainmainentry") {
- $attr =" \@attr 1=Heading-Main ";
+
+ $attr =" \@attr 1=Heading-Main ";
+# $attr =" \@attr 1=Heading ";
+
}elsif (@$tags[$i] eq "mainentry") {
$attr =" \@attr 1=Heading ";
}else{
$attr .=" \@attr 5=1 \@attr 4=6 ";## Word list, right truncated, anywhere
}
$attr =$attr."\"".@$value[$i]."\"";
- $q2 .=$attr;
+ push @queries, "$attr";
$dosearch=1;
}#if value
}
##Add how many queries generated
- if ($query=~/\S+/){
- $query= $and.$query.$q2
- } else {
- $query=$q2;
- }
+ my $query;
+ foreach my $query_part (@queries){
+ $query=($query?$and.$query_part.$query:$query_part);
+ }
## Adding order
#$query=' @or @attr 7=2 @attr 1=Heading 0 @or @attr 7=1 @attr 1=Heading 1'.$query if ($sortby eq "HeadingDsc");
my $orderstring= ($sortby eq "HeadingAsc"?
'@attr 7=2 @attr 1=Heading 0'
:''
);
- $query=($query?"\@or $orderstring $query":"\@or \@attr 1=_ALLRECORDS \@attr 2=103 '' $orderstring ");
+ $query=($dosearch?"\@or $orderstring $query":"\@or ".($query?"$and $query":"")." \@attr 1=_ALLRECORDS \@attr 2=103 '' $orderstring ");
+ $debug && warn $query;
$offset=0 unless $offset;
my $counter = $offset;
# pass the MARC::Record to this function, and it will create the records in the authority table
my ($record,$authid,$authtypecode) = @_;
my $dbh=C4::Context->dbh;
- my $leader=' a ';##Fixme correct leader as this one just adds utf8 to MARC21
+ my $leader=' nz a22 o 4500';#Leader for incomplete MARC21 record
# if authid empty => true add, find a new authid number
my $format= 'UNIMARCAUTH' if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC');
$format= 'MARC21' if (uc(C4::Context->preference('marcflavour')) ne 'UNIMARC');
+
+ if ($format eq "MARC21") {
+ if (!$record->leader) {
+ $record->leader($leader);
+ }
+ if (!$record->field('003')) {
+ $record->insert_fields_ordered(
+ MARC::Field->new('003',C4::Context->preference('MARCOrgCode'))
+ );
+ }
+ my $time=POSIX::strftime("%Y%m%d%H%M%S",localtime);
+ if (!$record->field('005')) {
+ $record->insert_fields_ordered(
+ MARC::Field->new('005',$time.".0")
+ );
+ }
+ my $date=POSIX::strftime("%y%m%d",localtime);
+ if (!$record->field('008')) {
+ $record->insert_fields_ordered(
+ MARC::Field->new('008',$date."|||a|||||| | ||| d")
+ );
+ }
+ if (!$record->field('040')) {
+ $record->insert_fields_ordered(
+ MARC::Field->new('040','','',
+ 'a' => C4::Context->preference('MARCOrgCode'),
+ 'c' => C4::Context->preference('MARCOrgCode')
+ )
+ );
+ }
+ }
+
if (($format eq "UNIMARCAUTH") && (!$record->subfield('100','a'))){
$record->leader(" nx j22 ");
my $date=POSIX::strftime("%Y%m%d",localtime);
sub GetAuthorityXML {
# Returns MARC::XML of the authority passed in parameter.
my ( $authid ) = @_;
- my $format= 'UNIMARCAUTH' if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC');
- $format= 'MARC21' if (uc(C4::Context->preference('marcflavour')) ne 'UNIMARC');
- if ($format eq "MARC21") {
- # for MARC21, call GetAuthority instead of
- # getting the XML directly since we may
- # need to fix up the location of the authority
- # code -- note that this is reasonably safe
- # because GetAuthorityXML is used only by the
- # indexing processes like zebraqueue_start.pl
- my $record = GetAuthority($authid);
- return $record->as_xml_record($format);
- } else {
- my $dbh=C4::Context->dbh;
- my $sth = $dbh->prepare("select marcxml from auth_header where authid=? " );
- $sth->execute($authid);
- my ($marcxml)=$sth->fetchrow;
- return $marcxml;
+ if (uc(C4::Context->preference('marcflavour')) eq 'UNIMARC') {
+ my $dbh=C4::Context->dbh;
+ my $sth = $dbh->prepare("select marcxml from auth_header where authid=? " );
+ $sth->execute($authid);
+ my ($marcxml)=$sth->fetchrow;
+ return $marcxml;
+ }
+ else {
+ # for MARC21, call GetAuthority instead of
+ # getting the XML directly since we may
+ # need to fix up the location of the authority
+ # code -- note that this is reasonably safe
+ # because GetAuthorityXML is used only by the
+ # indexing processes like zebraqueue_start.pl
+ my $record = GetAuthority($authid);
+ return $record->as_xml_record('MARC21');
}
}
# warn "record :".$record->as_formatted." auth_tag_to_report :$auth_tag_to_report";
# build a request for SearchAuthorities
my $query='at='.$authtypecode.' ';
- map {$query.= " and he=\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/)} $record->field($auth_tag_to_report)->subfields() if $record->field($auth_tag_to_report);
+ my $filtervalues=qr([\001-\040\!\'\"\`\#\$\%\&\*\+,\-\./:;<=>\?\@\(\)\{\[\]\}_\|\~]);
+ if ($record->field($auth_tag_to_report)) {
+ foreach ($record->field($auth_tag_to_report)->subfields()) {
+ $_->[1]=~s/$filtervalues/ /g; $query.= " and he,wrdl=\"".$_->[1]."\"" if ($_->[0]=~/[A-z]/);
+ }
+ }
my ($error, $results, $total_hits)=SimpleSearch( $query, 0, 1, [ "authorityserver" ] );
# there is at least 1 result => return the 1st one
if (@$results>0) {
$notes.= '<span class="note">'.$field->subfield('a')."</span>\n";
}
foreach my $field ($record->field('4..')) {
- my $thesaurus = "thes. : ".$thesaurus{"$field->subfield('2')"}." : " if ($field->subfield('2'));
- $see.= '<span class="UF">'.$thesaurus.$field->subfield('a')."</span> -- \n";
+ if ($field->subfield('2')) {
+ my $thesaurus = "thes. : ".$thesaurus{"$field->subfield('2')"}." : ";
+ $see.= '<span class="UF">'.$thesaurus.$field->subfield('a')."</span> -- \n";
+ }
}
# see :
foreach my $field ($record->field('5..')) {
my $record = shift @_;
my $class = shift @_;
my $authid_constructed = shift @_;
- my $authid=$record->subfield('250','3');
+ my $authid=$record->subfield('2..','3');
my %cell;
my $parents=""; my $children="";
my (@loopparents,@loopchildren);
$cell{"class"}=$class;
$cell{"loopauthid"}=$authid;
$cell{"current_value"} =1 if $authid eq $authid_constructed;
- $cell{"value"}=$record->subfield('250',"a");
+ $cell{"value"}=$record->subfield('2..',"a");
return \%cell;
}
my $dbh=C4::Context->dbh;
my $authtypecodefrom = GetAuthTypeCode($mergefrom);
my $authtypecodeto = GetAuthTypeCode($mergeto);
- warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto ";
+# warn "mergefrom : $authtypecodefrom $mergefrom mergeto : $authtypecodeto $mergeto ";
# return if authority does not exist
- my @X = $MARCfrom->fields();
- return "error MARCFROM not a marcrecord ".Data::Dumper::Dumper($MARCfrom) if $#X == -1;
- my @X = $MARCto->fields();
- return "error MARCTO not a marcrecord".Data::Dumper::Dumper($MARCto) if $#X == -1;
+ return "error MARCFROM not a marcrecord ".Data::Dumper::Dumper($MARCfrom) if scalar($MARCfrom->fields()) == 0;
+ return "error MARCTO not a marcrecord".Data::Dumper::Dumper($MARCto) if scalar($MARCto->fields()) == 0;
# search the tag to report
my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?");
$sth->execute($authtypecodefrom);
$rq->execute;
while (my $biblionumbers=$rq->fetchrow){
my @biblionumbers=split /;/,$biblionumbers;
- map {
- my $biblionumber=$1 if ($_=~/(\d+),.*/);
- my $marc=GetMarcBiblio($biblionumber);
- push @reccache,$marc;
- } @biblionumbers;
+ foreach (@biblionumbers) {
+ if ($_=~/(\d+),.*/) {
+ my $marc=GetMarcBiblio($1);
+ push @reccache,$marc;
+ }
+ }
}
} else {
#zebra connection
my $query;
$query= "an=".$mergefrom;
my $oResult = $oConnection->search(new ZOOM::Query::CCL2RPN( $query, $oConnection ));
- my $count=$oResult->size() if ($oResult);
+ my $count = 0;
+ if ($oResult) {
+ $count=$oResult->size();
+ }
my $z=0;
while ( $z<$count ) {
my $rec;
$rec=$oResult->record($z);
my $marcdata = $rec->raw();
push @reccache, $marcdata;
- $z++;
+ $z++;
}
$oConnection->destroy();
}
my $update;
$marcrecord= MARC::Record->new_from_xml($marcrecord,"utf8",C4::Context->preference("marcflavour")) unless(C4::Context->preference('NoZebra'));
foreach my $tagfield (@tags_using_authtype){
- warn "tagfield : $tagfield ";
+# warn "tagfield : $tagfield ";
foreach my $field ($marcrecord->field($tagfield)){
my $auth_number=$field->subfield("9");
my $tag=$field->tag();