Show
Ignore:
Timestamp:
07.04.2017 10:33:58 (3 years ago)
Author:
ak19
Message:

Bugfixes I think. Noticed that remove-archives-meta was removing the existing two metavalues for a metaname instead of a specific one despite being given a specific metavalue to remove. This seems to have happened because metapos was not undefined yet did not have a proper value (being the empty string or a string of empty chars), and so metapos was being set to 0. In that case the metavalue at metapos 0 AND the metavalue specified were both being removed. I then noticed the same issue going on with remove-index-meta too, and then noticed that set-index-meta wasn't working the way I expected it to either. All of these had to do with incoming args like metapos and metavalue only being tested for undefinedness rather than being tested for whether they were defined yet consisted of a string of one or more empty spaces.

Files:
1 modified

Legend:

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

    r30058 r31589  
    127127    #REMOVE METHODS 
    128128    "remove-import-metadata" => {  
    129         'compulsory-args' => [ "d", "metaname", "metavalue" ], #TODO: add f argument 
    130         'optional-args'   => [ "metapos" ] }, # only provide metapos arg for SIMPLE collections 
     129        'compulsory-args' => [ "d", "metaname" ], #TODO: add f argument 
     130        'optional-args'   => [ "metapos", "metavalue", "metamode" ] }, # only provide metapos arg for SIMPLE collections. 
     131# Metavalue is now an optional arg for remove_import_metadata() based on what the implementation did, which allowed metavalue to be undefined, and if so, used metapos. 
    131132                      
    132133    "remove-archives-metadata" => {  
    133134        'compulsory-args' => [ "d", "metaname" ], #TODO: add f argument 
    134         'optional-args'   => [ "metapos", "metavalue" ] }, 
     135        'optional-args'   => [ "metapos", "metavalue", "metamode" ] }, 
    135136 
    136137    "remove-live-metadata" => { 
     
    144145    "remove-metadata" => { # generic remove-meta function. The 'where' param can be set to any combination of index|archives|import|live. docid d is still compulsory for setting index, archives and live meta 
    145146        'compulsory-args' => [ "d", "metaname" ], 
    146         'optional-args'   => [ "where", "metapos", "metavalue" ] }, 
     147        'optional-args'   => [ "where", "metapos", "metavalue", "metamode" ] }, # metamode is optional since remove-metadata can call any of remove_import_meta and remove_archives_meta, remove_index_meta, of which the first two accept metamode as an optional param 
    147148 
    148149    #INSERT METHODS 
     
    263264 
    264265    my $where = $self->{'where'}; 
    265     if (!$where) {   
     266    if (!$where || ($where =~ m/^\s*$/)) { # 0, "0", "" and undef are all false. All else is true. 
     267    # What is truth in perl: http://www.berkeleyinternet.com/perl/node11.html 
     268    # and http://www.perlmonks.org/?node_id=33638 
     269 
    266270    $where = "index"; # default behaviour is to get the values from index 
    267271    } 
     
    757761 
    758762    # Obtain the specified metadata value 
    759     $metapos = 0 if (!defined $metapos); 
     763    $metapos = 0 if (!defined $metapos || ($metapos =~ m/^\s*$/)); 
    760764    my $metavalue = $doc_rec->{$metaname}->[$metapos]; 
    761765    $gsdl_cgi->generate_ok_message("$metavalue"); 
     
    782786    my $metaname  = $self->{'metaname'}; 
    783787    my $metapos = $self->{'metapos'}; 
    784     $metapos = 0 if (!defined $metapos); # gets the first value by default since metapos defaults to 0 
     788    $metapos = 0 if (!defined $metapos || ($metapos =~ m/^\s*$/)); # gets the first value by default since metapos defaults to 0 
    785789 
    786790    my $infodbtype = $self->{'infodbtype'}; 
     
    910914    my $metaname = $self->{'metaname'}; 
    911915    my $metapos = $self->{'metapos'}; 
    912     $metapos = 0 if (!defined $metapos); 
     916    $metapos = 0 if (!defined $metapos || ($metapos =~ m/^\s*$/)); 
    913917     
    914918    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir); 
     
    11701174 
    11711175    my $import_file  = $self->{'f'}; 
    1172     if ((!defined $docid) && (!defined $import_file)) { 
    1173     $gsdl_cgi->generate_error("No docid (d=...) or import file (f=) specified."); 
     1176    if ((!defined $docid || $docid =~ m/^\s*$/) && (!defined $import_file || $import_file =~ m/^\s*$/)) { 
     1177    $gsdl_cgi->generate_error("No docid (d=...) or import file (f=) specified."); # at least d or f must be specified 
    11741178    }  
    11751179 
     
    11821186    my $metamode   = $self->{'metamode'}; 
    11831187    if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) { 
    1184     # make "accumulate" the default (less destructive, as won't actually  
     1188    # make "accumulate" the default (less destructive, as it won't actually  
    11851189    # delete any existing values) 
    11861190    $metamode = "accumulate"; 
     
    11901194    my $metapos   = $self->{'metapos'}; # don't force undef to 0. Undef has meaning when metamode=override 
    11911195    my $prevmetavalue = $self->{'prevmetavalue'}; 
     1196    $metapos = undef if(defined $metapos && ($metapos =~ m/^\s*$/)); 
     1197    $prevmetavalue = undef if(defined $prevmetavalue && ($prevmetavalue =~ m/^\s*$/)); 
    11921198 
    11931199    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir); 
     
    12271233                                  # Don't append "|| undef", since if metapos=0 it will then be set to undef 
    12281234 
     1235    $metapos = undef if(defined $metapos && ($metapos =~ m/^\s*$/)); 
     1236    $prevmetavalue = undef if(defined $prevmetavalue && ($prevmetavalue =~ m/^\s*$/)); 
     1237 
    12291238    my $metamode   = $self->{'metamode'}; 
    12301239    if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) { 
    1231     # make "accumulate" the default (less destructive, as won't actually  
     1240    # make "accumulate" the default (less destructive, as it won't actually  
    12321241    # delete any existing values) 
    12331242    $metamode = "accumulate"; 
     
    12841293    my $prevmetavalue = $self->{'prevmetavalue'}; 
    12851294 
     1295    $metapos = undef if(defined $metapos && ($metapos =~ m/^\s*$/)); 
     1296    $prevmetavalue = undef if(defined $prevmetavalue && ($prevmetavalue =~ m/^\s*$/)); 
     1297 
    12861298    print STDERR "SETTING INDEX METADATA ENTRY\n"; 
    1287     my $status = $self->set_index_metadata_entry($collect_dir,$collect,$infodbtype,$docid,$metaname,$metapos,$metavalue,$metamode,$prevmetavalue); 
     1299    my $status = $self->set_index_metadata_entry($collect_dir,$collect,$infodbtype,$docid,$metaname,$metapos,$metavalue,$metamode,$prevmetavalue); 
    12881300    print STDERR "DONE SETTING INDEX METADATA ENTRY\n"; 
    12891301    if ($status != 0) { 
     
    13511363 
    13521364    my $where = $self->{'where'}; 
    1353     if(!$where) {    
     1365    if(!$where || ($where =~ m/^\s*$/)) {    
    13541366    $self->set_index_metadata(@_); # call the full version of set_index_meta for the default behaviour 
    13551367    return; 
     
    14241436 
    14251437    my $where = $self->{'where'}; 
    1426     if(!$where) {    
     1438    if(!$where || ($where =~ m/^\s*$/)) {    
    14271439    $self->set_index_metadata_array(@_); # default behaviour is the full version of set_index_meta_array 
    14281440    return; 
     
    22062218    my $metaname = $self->{'metaname'}; 
    22072219    my $metapos = $self->{'metapos'}; 
    2208  
    2209     my $metavalue = $self->{'metavalue'} || undef; # necessary to force fallback to undef here 
     2220    my $metavalue = $self->{'metavalue'}; 
     2221 
     2222    $metapos = undef if(defined $metapos && ($metapos =~ m/^\s*$/)); 
     2223    $metavalue = undef if(defined $metavalue && ($metavalue =~ m/^\s*$/)); # necessary to force fallback to undef here 
    22102224 
    22112225    # if the user hasn't told us what to delete, not having given a metavalue or metapos, 
     
    22192233    } 
    22202234 
    2221     my $metamode = $self->{'metamode'} || undef; 
     2235    my $metamode = $self->{'metamode'}; 
     2236    $metamode = undef if(defined $metamode && ($metamode =~ m/^\s*$/)); 
    22222237 
    22232238    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir); 
     
    27922807 
    27932808        if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) { 
    2794         # make "accumulate" the default (less destructive, as won't actually  
     2809        # make "accumulate" the default (less destructive, as it won't actually  
    27952810        # delete any existing values) 
    27962811        $metamode = "accumulate"; 
     
    28102825        my $metamode  = $metatable_rec->{'metamode'} || $doc_array_rec->{'metamode'} || $self->{'metamode'}; 
    28112826        if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) { 
    2812             # make "accumulate" the default (less destructive, as won't actually  
     2827            # make "accumulate" the default (less destructive, as it won't actually  
    28132828            # delete any existing values) 
    28142829            $metamode = "accumulate"; 
     
    29502965    my $metapos = $self->{'metapos'}; 
    29512966    my $metavalue = $self->{'metavalue'}; 
    2952     if(defined $metavalue) { 
     2967 
     2968    $metapos = undef if(defined $metapos && ($metapos =~ m/^\s*$/)); 
     2969    $metavalue = undef if(defined $metavalue && ($metavalue =~ m/^\s*$/)); 
     2970 
     2971    if(defined $metavalue) { # metavalue is now a compulsory arg for remove_import_metadata() 
    29532972        $metavalue =~ s/&lt;(.*?)&gt;/<$1>/g; 
    29542973    } elsif (!defined $metapos) { # if given no metavalue or metapos to delete, default to deleting the 1st 
    29552974        $metapos = 0; 
    29562975    } 
    2957     my $metamode = $self->{'metamode'} || undef; 
     2976    my $metamode = $self->{'metamode'}; 
     2977    $metamode = undef if(defined $metamode && ($metamode =~ m/^\s*$/)); 
    29582978 
    29592979    # import works with metadata.xml which can have inherited metadata 
     
    31963216 
    31973217    my $where = $self->{'where'}; 
    3198     if(!$where) { 
     3218    if(!$where || ($where =~ m/^\s*$/)) { 
    31993219    $self->remove_index_metadata(@_); # call the full version of set_index_meta for the default behaviour 
    32003220    return; 
     
    32513271    my $metaname  = $self->{'metaname'}; 
    32523272    my $metapos   = $self->{'metapos'}; 
    3253     my $metavalue = $self->{'metavalue'} || undef; # necessary to force fallback to undef here 
     3273    my $metavalue = $self->{'metavalue'}; 
     3274 
     3275    $metapos = undef if(defined $metapos && ($metapos =~ m/^\s*$/)); 
     3276    $metavalue = undef if(defined $metavalue && ($metavalue =~ m/^\s*$/)); # necessary to force fallback to undef here 
    32543277 
    32553278    # To people who know $collect_tail please add some comments 
     3279    # -> In collection groups, I think collect_tailname is the subcollection name, 
     3280    # e.g. colgroup-name/col-tail-name 
    32563281    # Obtain the path to the database 
    32573282    my $collect_tail = $collect; 
     
    33803405    # Check additional args 
    33813406    my $docid = $self->{'d'}; 
    3382     if (!defined($docid)) { 
     3407    if (!defined($docid) || ($docid =~ m/^\s*$/)) { 
    33833408    $gsdl_cgi->generate_error("No document id is specified: d=..."); 
    33843409    }  
    33853410    my $metaname = $self->{'metaname'}; 
    3386     if (!defined($metaname)) { 
     3411    if (!defined($metaname) || ($metaname =~ m/^\s*$/)) { 
    33873412    $gsdl_cgi->generate_error("No metaname is specified: metadataname=..."); 
    33883413    }  
    33893414    my $metavalue = $self->{'metavalue'}; 
    3390     if (!defined($metavalue) || $metavalue eq "") { 
     3415    if (!defined($metavalue) || ($metavalue =~ m/^\s*$/)) { 
    33913416    $gsdl_cgi->generate_error("No metavalue or empty metavalue is specified: metadataname=..."); 
    33923417    }  
    3393     # make "accumulate" the default (less destructive, as won't actually  
     3418    # make "accumulate" the default (less destructive, as it won't actually  
    33943419    # delete any existing values) 
    33953420    my $metamode = "accumulate";