Ignore:
Timestamp:
2023-11-14T10:35:07+13:00 (7 months ago)
Author:
kjdon
Message:

if we are adding Latitude and Longitude to a section, then we also add corresponding LatShort, LngShort, Coordinate metadata. This is fine for import, but when we are running buildcol, we are reading in the doc.xml and I guess this add_metadata method is being called for each metadata to create teh doc obj in memory. resulting in adding LatShort/LngShort/Coord all over again. Now lets test whether we already have the particular value before adding it again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/doc.pm

    r38159 r38357  
    10631063}
    10641064
     1065# Does this section contain the specified field->value pair?
     1066sub contains_metadata_value {
     1067    my $self = shift (@_);
     1068    my ($section, $field, $value, $ignore_namespace) = @_;
     1069
     1070    $ignore_namespace = 0 unless defined $ignore_namespace;
     1071
     1072    my $section_ptr = $self->_lookup_section($section);
     1073    if (!defined $section_ptr) {
     1074        print STDERR "doc::get_metadata couldn't find section ",
     1075        $section, "\n";
     1076        return 0;
     1077    }
     1078
     1079    # Remove any namespace if we are being told to ignore them
     1080    if($ignore_namespace) {
     1081    $field =~ s/^.*\.//;
     1082    }
     1083
     1084    my @metadata = ();
     1085    foreach my $data (@{$section_ptr->{'metadata'}}) {
     1086
     1087    my $data_name = $data->[0];
     1088
     1089    # Remove any namespace if we are being told to ignore them
     1090    if($ignore_namespace) {
     1091        $data_name =~ s/^.*\.//;
     1092    }   
     1093    # we always remove ex. (but not any subsequent namespace) - ex. maybe there in doc_obj, but we will never ask for it.
     1094    $data_name =~ s/^ex\.([^.]+)$/$1/;
     1095        if ($data_name eq $field && $data->[1] eq $value) {
     1096            return 1;
     1097        }
     1098    }
     1099    # if we get here, we haven't found it.
     1100    return 0;
     1101   
     1102}
     1103
    10651104# $value is optional
    10661105sub delete_metadata {
     
    11751214
    11761215        my $direction;
    1177         # TODO does the following work, with eq latitude? the above code implies can be xxxxx.Latitude. should use metaname??
     1216        # TODO does the following work, with eq xx.Latitude? the above code implies can be xxxxx.Latitude. should use metaname??
    11781217        if($value =~ m/^-/)
    11791218        {
     
    11881227        if(defined $beforeDec && defined $afterDec)
    11891228        {
    1190             my $name = ($field eq "Latitude") ? "LatShort" : "LngShort";
     1229                    my $name = ($field eq "Latitude") ? "LatShort" : "LngShort";
     1230                    # only do the following if we haven't already done it
     1231                    if (!$self->contains_metadata_value($section, $name, $beforeDec . $direction)) {
    11911232            push (@{$section_ptr->{'metadata'}}, [$name, $beforeDec . $direction]);
    11921233           
     
    11981239                }
    11991240            }
    1200 
     1241                    }
    12011242            # what is this???? completely does nothing...
    12021243            #Only add the metadata if it has not already been added
     
    14021443    #push (@{$section_ptr->{'metadata'}}, ["Longitude", $longitude]);
    14031444
     1445        if ($self->contains_metadata_value($section, "Coordinate", "$latitude $longitude")) {
     1446            # it looks like we have already processed these values
     1447            return;
     1448        }
    14041449    push (@{$section_ptr->{'metadata'}}, ["Coordinate", "$latitude $longitude"]); # "$latitude$lat_direction $longitude$lng_direction"
    14051450
Note: See TracChangeset for help on using the changeset viewer.