Changeset 27111

22.03.2013 15:31:54 (7 years ago)

Bugfix. When GS3 specifies that the metadata of a subsection is to be edited in its call to, the meta ended up being accumulated in the top level section instead of changing the relevant meta of the subsection. With this commit, the same metadata action now overrides (edits) or accumulates (adds to) the correct section or subsection of doc.xml. There's now also error statements printed to stderr if an invalid subsection was specified, and the metadata was not added. This is only caught at the end, after all the parsing is done and all the subsections encountered. I may yet commit the code to produce an gsdl_cgi error message when an invalid subsection was provided, but not sure if this is necessary or desirable at this point, as it's not a serious error (and unlikely to occur when GS3 and not a human user is passing the section values to

1 modified


  • main/trunk/greenstone2/perllib/cgiactions/

    r27007 r27111  
    757757            if(defined $parser->{'parameters'}->{'metapos'} && $parser->{'parameters'}->{'poscount'} == $parser->{'parameters'}->{'metapos'}) 
    758758            { 
    759                 ##print STDERR "**** got match!!\n"; 
     759                ##print STDERR "#### got match!!\n"; 
    760760                # Get the value and override the current value 
    761761                my $metavalue = $parser->{'parameters'}->{'metavalue'}; 
     780# This method exists purely for catching invalid section numbers that the client 
     781# requested to edit. Once the parser has reached the end (the final </Archive> tag), 
     782# we've seen all the Sections in the doc.xml, and none of their section nums matched 
     783# if the metamode has not been set to 'done' by then. 
     784sub dxml_archive 
     786    my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_; 
     787    my $metamode = $parser->{'parameters'}->{'metamode'}; 
     789    my $curr_secnum = $parser->{'parameters'}->{'curr_section_num'}; 
     790    my $opt_doc_secnum = $parser->{'parameters'}->{'secnum'}; 
     792#    print STDERR "@@@ $tagname Processing a closing </Archive> tag [$curr_secnum|$opt_doc_secnum]\n"; 
     794    if ($metamode ne "done" && $curr_secnum ne $opt_doc_secnum) { 
     795    print STDERR "@@@ $tagname Finished processing FINAL Section [$curr_secnum|$opt_doc_secnum]\n"; 
     797    my $metaname = $parser->{'parameters'}->{'metaname'}; 
     798    my $metavalue = $parser->{'parameters'}->{'metavalue'}; 
     800    print STDERR "@@@ Unknown requested section number $opt_doc_secnum\n"; 
     801    print STDERR "\tas final section number in document was $curr_secnum\n"; 
     802    print STDERR "\tMetadata value '$metavalue' for meta '$metaname'\n"; 
     803    print STDERR "\tin section $opt_doc_secnum discarded.\n"; 
     804    } 
     806    # RAW is [$tagname => $attrHash] not $tagname => $attrHash!! 
     807    return [$tagname => $attrHash]; 
    781810sub dxml_description 
    784813    my $metamode = $parser->{'parameters'}->{'metamode'}; 
     815    my $curr_secnum = $parser->{'parameters'}->{'curr_section_num'}; 
     816    my $opt_doc_secnum = $parser->{'parameters'}->{'secnum'}; 
    786818    print STDERR "**** Processing a closing </Description> tag \n"; 
     819#   print STDERR "@@@ $tagname Processing a closing </Description> tag [$curr_secnum|$opt_doc_secnum]\n"; 
    788821    # Accumulate the metadata 
    790     if (($metamode eq "accumulate") || ($metamode eq "override")) { 
     823    # We'll be accumulating metadata at this point if we haven't found and therefore 
     824    # haven't processed the metadata yet.  
     825    # For subsections, this means that if we're at a matching subsection, but haven't  
     826    # found the correct metaname to override in that subsection, we accumulate it as new 
     827    # meta in the subsection by adding it to the current description. 
     828    # If there's no subsection info for the metadata, it will accumulate at the top level 
     829    # section description if we hadn't found a matching metaname to override at this point. 
     831    # Both curr_secnum and opt_doc_secnum can be "". In the former case, it means we're now 
     832    # at the toplevel section. In the latter case, it means we want to process meta in the 
     833    # toplevel section. So the eq check between the values below will work in all cases. 
     835    # The only time this won't work is if an opt_doc_secnum beyond the section numbers of 
     836    # this document has been provided. In that case, the metadata for that opt_doc_secnum 
     837    # won't get attached/accumulated to any part of the doc, not even its top-level section. 
     839    if ($curr_secnum eq $opt_doc_secnum  
     840        && ($metamode eq "accumulate" || $metamode eq "override")) { 
    791841        if ($metamode eq "override") { 
    792842        print "No metadata value to override.  Switching 'metamode' to accumulate\n"; 
    944994    ( _default => 'raw', 
    945995      'Metadata'    => \&dxml_metadata, 
    946       'Description' => \&dxml_description); 
     996      'Description' => \&dxml_description, 
     997      'Archive'     => \&dxml_archive); # just for catching errors at end 
    948999    # Sets the parameters