Changeset 23400


Ignore:
Timestamp:
12/07/10 16:58:21 (11 years ago)
Author:
max
Message:

Tested using this action under windows using Sqlite as the database. Code needed a variety of updates to support this.

File:
1 edited

Legend:

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

    r22331 r23400  
    5858
    5959    "set-archives-metadata" => { 'compulsory-args' => [ "d", "metaname", "metavalue" ],
    60                      'optional-args'   => [ "metapos" ]
    61 
     60                     'optional-args'   => [ "metapos", "metamode" ]
     61                      # metamode can be "accumulate", "override",
    6262                },
    6363
     
    9999    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    100100    my $gsdlhome  = $self->{'gsdlhome'};
    101 
     101    my $infodbtype = $self->{'infodbtype'};
     102   
    102103    # Note: Not sure why get_live_metadata doesn't need the authentication check
    103104
     
    123124    $collect_tail =~ s/^.*[\/|\\]//;
    124125    my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text");
    125     my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", "live-$collect_tail", $index_text_directory);
     126    my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, "live-$collect_tail", $index_text_directory);
    126127   
    127128    # Obtain the content of the key
     
    176177    my $metaname  = $self->{'metaname'};
    177178    my $metapos   = $self->{'metapos'};
     179    my $infodbtype = $self->{'infodbtype'};
    178180
    179181    # To people who know $collect_tail please add some comments
     
    182184    $collect_tail =~ s/^.*[\/\\]//;
    183185    my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text");
    184     my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", $collect_tail, $index_text_directory);
     186    my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory);
    185187
    186188    # Read the docid entry
    187     my $doc_rec_string = &dbutil::read_infodb_entry("gdbm", $infodb_file_path, $docid);
    188     my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string);
    189 
     189    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $infodb_file_path, $docid);
     190 
    190191    # Basically loop through and unescape_html the values
    191192    foreach my $k (keys %$doc_rec) {
     
    216217    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    217218    my $gsdlhome  = $self->{'gsdlhome'};
    218 
     219    my $infodbtype = $self->{'infodbtype'};
     220 
    219221    # don't user authenticate for now
    220222    if ($baseaction::authentication_enabled) {
     
    235237    }
    236238    my $metavalue = $self->{'metavalue'};
     239 
    237240
    238241    # Generate the dbkey   
     
    245248    $collect_tail =~ s/^.*[\/\\]//;
    246249    my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text");
    247     my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", "live-$collect_tail", $index_text_directory);
     250    my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, "live-$collect_tail", $index_text_directory);
    248251
    249252    # Set the new value
     
    279282    my $gsdlhome  = $self->{'gsdlhome'};
    280283
     284   
     285   
    281286    # don't user authenticate for now
    282287    if ($baseaction::authentication_enabled) {
     
    296301    my $metapos   = $self->{'metapos'};
    297302    my $metavalue = $self->{'metavalue'};
    298 
     303    my $infodbtype = $self->{'infodbtype'};
     304   
    299305    # To people who know $collect_tail please add some comments
    300306    # Obtain path to the database
     
    302308    $collect_tail =~ s/^.*[\/\\]//;
    303309    my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text");
    304     my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", $collect_tail, $index_text_directory);
    305 
     310    my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory);
     311   
    306312    # Read the docid entry
    307     my $doc_rec_string = &dbutil::read_infodb_entry("gdbm", $infodb_file_path, $docid);
    308     my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string);
    309     foreach my $k (keys %$doc_rec) {
    310     my @escaped_v = ();
    311     foreach my $v (@{$doc_rec->{$k}}) {
    312         if ($k eq "contains") {
    313         # protect quotes in ".2;".3 etc
    314         $v =~ s/\"/\\\"/g;
    315         push(@escaped_v, $v);
    316         }
    317         else {
    318         my $ev = &ghtml::unescape_html($v);
    319         $ev =~ s/\"/\\\"/g;
    320         push(@escaped_v, $ev);
    321         }
    322     }
    323     $doc_rec->{$k} = \@escaped_v;
    324     }
    325     ## print STDERR "**** metavalue = $metavalue\n";
    326 
    327     # Protect the quotes
    328     $metavalue =~ s/\"/\\\"/g;
    329 
     313    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $infodb_file_path, $docid);
     314   
    330315    # Set the metadata value
    331316    if (defined $metapos) {
    332     $doc_rec->{$metaname}->[$metapos] = $metavalue;
     317        $doc_rec->{$metaname}->[$metapos] = $metavalue;
    333318    }
    334319    else {
    335     $doc_rec->{$metaname} = [ $metavalue ];
    336     }
    337     ## print STDERR "**** metavalue = $metavalue\n";
    338 
    339     # Generate the record string
    340     my $serialized_doc_rec = &dbutil::convert_infodb_hash_to_string($doc_rec);
    341     ## print STDERR "**** ser dr\n$serialized_doc_rec\n\n\n";
    342 
    343     # Store it into GDBM
    344     my $cmd = "gdbmset \"$infodb_file_path\" \"$docid\" \"$serialized_doc_rec\"";
    345     my $status = system($cmd);
     320        $doc_rec->{$metaname} = [ $metavalue ];
     321    }
     322 
     323    my $status = &dbutil::set_infodb_entry($infodbtype, $infodb_file_path,$docid,$doc_rec);
    346324    if ($status != 0) {
    347325        # Catch error if gdbmget failed
    348     my $mess = "Failed to set metadata key: $docid\n";
    349    
    350     $mess .= "PATH: $ENV{'PATH'}\n";
    351     $mess .= "cmd = $cmd\n";
    352     $mess .= "Exit status: $status\n";
    353     $mess .= "System Error Message: $!\n";
    354 
    355     $gsdl_cgi->generate_error($mess);
     326        my $mess = "Failed to set metadata key: $docid\n";
     327   
     328        $mess .= "PATH: $ENV{'PATH'}\n";
     329        $mess .= "Exit status: $status\n";
     330        $mess .= "System Error Message: $!\n";
     331
     332        $gsdl_cgi->generate_error($mess);
    356333    }
    357334    else {
    358     my $mess = "set-document-metadata successful: Key[$docid]\n";
    359     $mess .= "  $metaname";
    360     $mess .= "->[$metapos]" if (defined $metapos);
    361     $mess .= " = $metavalue";
    362 
    363     $gsdl_cgi->generate_ok_message($mess);
     335        my $mess = "set-document-metadata successful: Key[$docid]\n";
     336        $mess .= "  $metaname";
     337        $mess .= "->[$metapos]" if (defined $metapos);
     338        $mess .= " = $metavalue";
     339
     340        $gsdl_cgi->generate_ok_message($mess);
    364341    }
    365342   
     
    460437{
    461438    my $self = shift @_;
    462     my ($gsdl_cgi, $doc_xml_filename, $metaname, $metavalue, $metapos) = @_;
     439    my ($gsdl_cgi, $doc_xml_filename, $metaname, $metavalue, $metapos, $metamode) = @_;
    463440
    464441    # use XML::Rules to add it in (read in and out again)
     
    472449    my $options = { 'metaname'  => $metaname,
    473450            'metapos'   => $metapos,
    474             'metavalue' => $metavalue };
     451            'metavalue' => $metavalue,
     452            'metamode'  => $metamode };
     453           
    475454    $self->edit_xml_file($gsdl_cgi,$doc_xml_filename,\@rules,$options);
    476455}
     
    485464    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    486465    my $gsdlhome  = $self->{'gsdlhome'};
    487 
     466    my $infodbtype = $self->{'infodbtype'};
     467   
    488468    # don't user authenticate for now
    489469    if ($baseaction::authentication_enabled) {
     
    503483    my $metaname   = $self->{'metaname'};
    504484    my $metavalue  = $self->{'metavalue'};
     485   
    505486    my $metapos    = $self->{'metapos'};
    506487    $metapos = 0 if (!defined $metapos);
     488
     489    my $metamode   = $self->{'metamode'};
     490    if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) {
     491    # make "accumulate" the default (less destructive, as won't actually
     492    # delete any existing values)
     493    $metamode = "accumulate";
     494    }
    507495   
    508496    # Obtain the doc.xml path for the specified docID
    509     my $arcinfo_doc_filename = &dbutil::get_infodb_file_path("gdbm", "archiveinf-doc", $archive_dir);
    510     my $doc_rec_string = &dbutil::read_infodb_entry("gdbm", $arcinfo_doc_filename, $docid);
    511     my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string);   
     497    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
     498    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
    512499    my $doc_xml_file = $doc_rec->{'doc-file'}->[0];
    513500   
     
    521508    # Running import.pl -groupsize will cause this to have multiple sections in one doc.xml
    522509    $self->edit_doc_xml($gsdl_cgi,$doc_xml_filename,
    523             $metaname,$metavalue,$metapos);
    524 
     510            $metaname,$metavalue,$metapos,$metamode);
     511
     512    my $mess = "set-archives-metadata successful: Key[$docid]\n";
     513    $mess .= "  $metaname";
     514    $mess .= "->[$metapos]" if (defined $metapos);
     515    $mess .= " = $metavalue";
     516    $mess .= " ($metamode)\n";
     517   
     518    $gsdl_cgi->generate_ok_message($mess);
     519       
    525520    # Release the lock once it is done
    526521    $self->unlock_collection($username, $collect);
     522   
    527523}
    528524
     
    682678    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    683679    my $gsdlhome  = $self->{'gsdlhome'};
    684 
     680    my $infodbtype = $self->{'infodbtype'};
     681   
    685682    # don't user authenticate for now
    686683    if ($baseaction::authentication_enabled) {
     
    719716    my $import_filename = undef;
    720717    if (defined $docid) {
    721     my $arcinfo_doc_filename = &dbutil::get_infodb_file_path("gdbm", "archiveinf-doc", $archive_dir);
    722     my $doc_rec_string = &dbutil::read_infodb_entry("gdbm", $arcinfo_doc_filename, $docid);
    723     my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string);
     718    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
     719    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
    724720
    725721    # This now stores the full pathname
     
    759755    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    760756    my $gsdlhome  = $self->{'gsdlhome'};
    761 
     757    my $infodbtype = $self->{'infodbtype'};
     758   
    762759    if ($baseaction::authentication_enabled) {
    763760    # Ensure the user is allowed to edit this collection
     
    786783    $collect_tail =~ s/^.*[\/\\]//;
    787784    my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text");
    788     my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", "live-$collect_tail", $index_text_directory);
     785    my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, "live-$collect_tail", $index_text_directory);
    789786
    790787    # Remove the key
     
    817814    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    818815    my $gsdlhome  = $self->{'gsdlhome'};
    819 
     816    my $infodbtype = $self->{'infodbtype'};
     817   
    820818    # don't user authenticate for now
    821819    if ($baseaction::authentication_enabled) {
     
    843841    $collect_tail =~ s/^.*[\/\\]//;
    844842    my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text");
    845     my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", $collect_tail, $index_text_directory);
     843    my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory);
    846844
    847845    # Read the docid entry
    848     my $doc_rec_string = &dbutil::read_infodb_entry("gdbm", $infodb_file_path, $docid);
    849     my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string);
     846    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $infodb_file_path, $docid);
    850847
    851848    # Basically loop through and unescape_html the values
     
    923920    my $gsdl_cgi  = $self->{'gsdl_cgi'};
    924921    my $gsdlhome  = $self->{'gsdlhome'};
    925 
     922    my $infodbtype = $self->{'infodbtype'};
     923   
    926924    # If the import metadata and gdbm database have been updated, we need to insert some notification to warn user that the the text they see at the moment is not indexed and require a rebuild.
    927925    my $rebuild_pending_macro = "_rebuildpendingmessage_";
     
    963961    # If the doc oid is not specified, we assume the metadata.xml is next to the specified "f"
    964962    my $metadata_xml_file;
    965     my $arcinfo_doc_filename = &dbutil::get_infodb_file_path("gdbm", "archiveinf-doc", $archive_dir);
    966     my $archive_doc_rec_string = &dbutil::read_infodb_entry("gdbm", $arcinfo_doc_filename, $docid);
    967     my $archive_doc_rec = &dbutil::convert_infodb_string_to_hash($archive_doc_rec_string);
     963    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
     964    my $archive_doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
    968965   
    969966    # This now stores the full pathname
     
    10141011    $collect_tail =~ s/^.*[\/\\]//;
    10151012    my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text");
    1016     my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", $collect_tail, $index_text_directory);
     1013    my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory);
    10171014
    10181015    # Read the docid entry
    1019     my $doc_rec_string = &dbutil::read_infodb_entry("gdbm", $infodb_file_path, $docid);
    1020     my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string);
     1016    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $infodb_file_path, $docid);
     1017   
    10211018    foreach my $k (keys %$doc_rec) {
    10221019    my @escaped_v = ();
Note: See TracChangeset for help on using the changeset viewer.