Index: main/trunk/greenstone2/perllib/cgiactions/modmetadataaction.pm
===================================================================
--- main/trunk/greenstone2/perllib/cgiactions/modmetadataaction.pm	(revision 32077)
+++ main/trunk/greenstone2/perllib/cgiactions/modmetadataaction.pm	(revision 32079)
@@ -205,5 +205,4 @@
 sub set_index_metadata_entry
 {
-    print STDERR "1\n";
     my $self = shift @_;
     my ($collect_dir,$collect,$infodbtype,$docid,$metaname,$metapos,$metavalue,$metamode,$prevmetavalue) = @_;
@@ -216,5 +215,4 @@
     my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory);
 	
-    print STDERR "2\n";
 #	print STDERR "**** infodb file path = $infodb_file_path\n";
 #	print STDERR "***** infodb type = $infodbtype\n";
@@ -225,5 +223,4 @@
     # Set the metadata value
     if (defined $metapos) {
-    print STDERR "3\n";
 	# if metamode=accumulate AND metapos, warn user and then use metapos
 	if (defined $metamode && $metamode eq "accumulate") {
@@ -234,9 +231,8 @@
     }
     elsif (defined $prevmetavalue) {
-    print STDERR "4\n";
-		my $array = $doc_rec->{$metaname};
+	my $array = $doc_rec->{$metaname};
         my $length = @$array;
 
-		my $found = 0;
+	my $found = 0;
         for (my $i = 0; $i < $length; $i++){
             if(defined $doc_rec->{$metaname}->[$i] && $doc_rec->{$metaname}->[$i] eq $prevmetavalue){
@@ -252,10 +248,8 @@
     }
     elsif (defined $metamode && $metamode eq "override") {
-    print STDERR "5\n";
 	$doc_rec->{$metaname} = [ $metavalue ];	
     }
     else { # default for index was to override, but because accumulate is less destructive, 
 	# and because accumulate is the default for archives and import, that's the new default for index too
-    print STDERR "6\n";
 	if(defined $doc_rec->{$metaname}) {
 	    push(@{$doc_rec->{$metaname}}, $metavalue); # accumulate the value for that metaname
@@ -264,5 +258,4 @@
 	}
     }
-    print STDERR "6\n";
  
     my $status = &dbutil::set_infodb_entry($infodbtype, $infodb_file_path,$docid,$doc_rec);
@@ -861,5 +854,5 @@
 
 			    if ($parser->{'parameters'}->{'poscount'} == $parser->{'parameters'}->{'metapos'}) {
-				print STDERR "#### got pos match!!\n";
+				###print STDERR "#### got pos match!!\n";
 				# Get the value and override the current value
 				my $metavalue = $parser->{'parameters'}->{'metavalue'};
@@ -872,5 +865,5 @@
 			elsif (defined $parser->{'parameters'}->{'prevmetavalue'}) { # if no pos defined but prevmeta defined, then wait for prevmeta match
 			    if ($parser->{'parameters'}->{'prevmetavalue'} eq $attrHash->{'_content'}) {
-				print STDERR "### prev meta value matches\n";
+				###print STDERR "### prev meta value matches\n";
 				my $metavalue = $parser->{'parameters'}->{'metavalue'};
 				$attrHash->{'_content'} = $metavalue;
@@ -879,19 +872,9 @@
 			    }
 			}
-			elsif ($parser->{'parameters'}->{'poscount'} == 0) { # explicit catch all - ignored!!!! 
-			    # If no pos or prevmeta defined, then metavalue set for metaname becomes the ONLY instance of that metaname!!!
-			    print STDERR "#### got pos match!!\n";
-			    # Get the value and override the current value
-			    my $metavalue = $parser->{'parameters'}->{'metavalue'};
-			    $attrHash->{'_content'} = $metavalue;
-			    
-			    # Don't want it to wipe out any other pieces of metadata
-			    $parser->{'parameters'}->{'metamode'} = "done";
-
-			    
-			}
-
-			
-			
+			# Note that before commit rev 32076, if neither metapos nor prevmeta defined, then code tried to set pos 0 for that metaname to the new value			
+			# However that is not how the code works now (and couldn't get it to work that way yet after rev 32076).
+			# What it does now, and what Dr Bainbridge approved of is that:
+			# If no pos or prevmeta defined, then on override, the metavalue set for the specificed metaname becomes the ONLY instance of that metaname
+			# So any earlier instances of that metaname is removed and replaced by the single new instance.			
 		}
 	}
@@ -913,8 +896,8 @@
     my $opt_doc_secnum = $parser->{'parameters'}->{'secnum'};
     
-#    print STDERR "@@@ $tagname Processing a closing </Archive> tag [$curr_secnum|$opt_doc_secnum]\n";
+    # print STDERR "@@@ $tagname Processing a closing </Archive> tag [$curr_secnum|$opt_doc_secnum]\n";
     
     if ($metamode ne "done" && $curr_secnum ne $opt_doc_secnum) {
-	print STDERR "@@@ $tagname Finished processing FINAL Section.\n";
+	#print STDERR "@@@ $tagname Finished processing FINAL Section.\n";
 
 	my $metaname = $parser->{'parameters'}->{'metaname'};
@@ -941,5 +924,5 @@
 	
 ###!!!	print STDERR "**** Processing a closing </Description> tag \n";
-#	print STDERR "@@@ $tagname Processing a closing </Description> tag [$curr_secnum|$opt_doc_secnum]\n";
+	# print STDERR "@@@ $tagname Processing a closing </Description> tag [$curr_secnum|$opt_doc_secnum]\n";
 	
 	# Accumulate the metadata
@@ -963,4 +946,6 @@
 	if ($curr_secnum eq $opt_doc_secnum 
 	    && ($metamode eq "accumulate" || $metamode eq "override")) {
+	    # note, metamode would have been set to done if a metadata operation had already succeeded. 
+	    # If we get here, we still have the metadata to append.
 	    if ($metamode eq "override") {
 		print "Got to end of <Description> block. No metadata value to override.  Switching 'metamode' to accumulate\n";
@@ -982,5 +967,4 @@
 	    my $append_metadata = [ "Metadata" => $metadata_attr ];
 	    my $description_content = $attrHash->{'_content'};
-	    
 	    print "Appending metadata to doc.xml\n";
 	    
@@ -1000,5 +984,4 @@
 ##	    print STDERR "**** NOT ACCUMULATE?!? \n";
 	}
-
     # RAW is [$tagname => $attrHash] not $tagname => $attrHash!!
     return [$tagname => $attrHash];
@@ -1139,6 +1122,8 @@
     # Thereafter, we will finally be setting the overriding metavalue for this metaname
     if (!defined $prevmetavalue && !defined $metapos && $metamode eq "override") {
+	print "override mode with no pos or prev value set. Removing all existing values for $metaname, and setting mode to accumulate for the new value.\n";
 	# remove all values of $metaname metadata 
 	$self->remove_from_doc_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_xml_file), $metaname, undef, undef, $docid_secnum, $metamode);
+	$metamode = "accumulate";
     }
     # Edit the doc.xml file with the specified metadata name, value and position.
