Changeset 27167

Show
Ignore:
Timestamp:
10.04.2013 17:37:04 (7 years ago)
Author:
ak19
Message:

Another bugfix: when doing a set_archives_meta with metamode=override, it was overwriting only the first metavalue of a metaname but preserving the rest. That behaviour is only supposed to happen if metamode=override combined with metapos=0. But when metamode=override and no metapos is defined, need to remove all metavalues for the given metaname, and then set the archives metadata for that metaname to the newly provided metavalue.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm

    r27162 r27167  
    717717    my $prevmetavalue = $self->{'prevmetavalue'}; 
    718718     
    719     my $metapos    = $self->{'metapos'}; 
    720     $metapos = 0 if (!defined $metapos); 
     719    my $metapos    = $self->{'metapos'}; # Don't append "|| undef", since if metapos=0 it will then be set to undef 
     720 
     721    # Don't set metapos=0 if it's undefined, as doing so will interfere when overriding all values for a metaname 
     722    # (all values for a metaname should get overridden if metamode=override combined with no user-defined metapos) 
    721723 
    722724    my $metamode   = $self->{'metamode'}; 
     
    725727    # delete any existing values) 
    726728    $metamode = "accumulate"; 
    727     }  
     729    } 
    728730     
    729731    my $status = $self->set_archives_metadata_entry($gsdl_cgi,$archive_dir, $collect_dir,$collect, $infodbtype,$docid, 
     
    13121314    my $archives_dir = &util::filename_cat($collect_dir,$collect,"archives");     
    13131315    my $doc_xml_filename = &util::filename_cat($archives_dir,$doc_xml_file); 
     1316 
     1317    # If we're overriding everything, then $metamode=override combined with $metapos=undefined 
     1318    # in which case, we need to remove all metavalues for the metaname at the given (sub)section 
     1319    # Thereafter, we will finally be setting the overriding metavalue for this metaname 
     1320    if(!defined $metapos && $metamode eq "override") { 
     1321    $self->remove_from_doc_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_xml_file), $metaname, $metapos, undef, $docid_secnum, $metamode); 
     1322    } 
    13141323     
    13151324    # Edit the doc.xml file with the specified metadata name, value and position. 
     
    14661475        $metapos = 0; 
    14671476    } 
     1477 
     1478    my $metamode = $self->{'metamode'} || undef;     
    14681479     
    14691480    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir); 
     
    14731484    my $doc_filename = $doc_rec->{'doc-file'}->[0];  
    14741485 
    1475     my $status = $self->remove_from_doc_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_filename), $metaname, $metapos, $metavalue, $docid_secnum); 
     1486    my $status = $self->remove_from_doc_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_filename), $metaname, $metapos, $metavalue, $docid_secnum, $metamode); 
    14761487#   my $status = $self->remove_from_doc_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_filename), $metaname, $metapos, undef, $docid_secnum); 
    14771488     
     
    15231534{ 
    15241535    my $self = shift @_; 
    1525     my ($gsdl_cgi, $doc_xml_filename, $metaname, $metapos, $metavalue, $secid) = @_; 
     1536    my ($gsdl_cgi, $doc_xml_filename, $metaname, $metapos, $metavalue, $secid, $metamode) = @_; 
    15261537     
    15271538    my @start_rules = ('Section' => \&dxml_start_section); 
     
    15681579        else { 
    15691580            binmode($MOUT,":utf8"); 
    1570             $parser->filter($xml_in, $MOUT, {metaname => $metaname, metapos => $metapos, metavalue => $metavalue, secid => $secid}); 
     1581            $parser->filter($xml_in, $MOUT, {metaname => $metaname, metapos => $metapos, metavalue => $metavalue, secid => $secid, metamode => $metamode}); 
    15711582            close($MOUT);        
    15721583        } 
     
    15941605        { 
    15951606            $parser->{'parameters'}->{'poscount'}++; 
     1607        } 
     1608 
     1609        # if overriding but no metapos, then clear all the meta for this metaname 
     1610        if ((defined $parser->{'parameters'}->{'metamode'}) && ($parser->{'parameters'}->{'metamode'} eq "override") && (!defined $parser->{'parameters'}->{'metapos'})) {           
     1611            return []; 
    15961612        } 
    15971613    }