Changeset 23400 for main/trunk/greenstone2/perllib
- Timestamp:
- 2010-12-07T16:58:21+13:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm
r22331 r23400 58 58 59 59 "set-archives-metadata" => { 'compulsory-args' => [ "d", "metaname", "metavalue" ], 60 'optional-args' => [ "metapos" ]61 60 'optional-args' => [ "metapos", "metamode" ] 61 # metamode can be "accumulate", "override", 62 62 }, 63 63 … … 99 99 my $gsdl_cgi = $self->{'gsdl_cgi'}; 100 100 my $gsdlhome = $self->{'gsdlhome'}; 101 101 my $infodbtype = $self->{'infodbtype'}; 102 102 103 # Note: Not sure why get_live_metadata doesn't need the authentication check 103 104 … … 123 124 $collect_tail =~ s/^.*[\/|\\]//; 124 125 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); 126 127 127 128 # Obtain the content of the key … … 176 177 my $metaname = $self->{'metaname'}; 177 178 my $metapos = $self->{'metapos'}; 179 my $infodbtype = $self->{'infodbtype'}; 178 180 179 181 # To people who know $collect_tail please add some comments … … 182 184 $collect_tail =~ s/^.*[\/\\]//; 183 185 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); 185 187 186 188 # 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 190 191 # Basically loop through and unescape_html the values 191 192 foreach my $k (keys %$doc_rec) { … … 216 217 my $gsdl_cgi = $self->{'gsdl_cgi'}; 217 218 my $gsdlhome = $self->{'gsdlhome'}; 218 219 my $infodbtype = $self->{'infodbtype'}; 220 219 221 # don't user authenticate for now 220 222 if ($baseaction::authentication_enabled) { … … 235 237 } 236 238 my $metavalue = $self->{'metavalue'}; 239 237 240 238 241 # Generate the dbkey … … 245 248 $collect_tail =~ s/^.*[\/\\]//; 246 249 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); 248 251 249 252 # Set the new value … … 279 282 my $gsdlhome = $self->{'gsdlhome'}; 280 283 284 285 281 286 # don't user authenticate for now 282 287 if ($baseaction::authentication_enabled) { … … 296 301 my $metapos = $self->{'metapos'}; 297 302 my $metavalue = $self->{'metavalue'}; 298 303 my $infodbtype = $self->{'infodbtype'}; 304 299 305 # To people who know $collect_tail please add some comments 300 306 # Obtain path to the database … … 302 308 $collect_tail =~ s/^.*[\/\\]//; 303 309 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 306 312 # 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 330 315 # Set the metadata value 331 316 if (defined $metapos) { 332 $doc_rec->{$metaname}->[$metapos] = $metavalue;317 $doc_rec->{$metaname}->[$metapos] = $metavalue; 333 318 } 334 319 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); 346 324 if ($status != 0) { 347 325 # 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); 356 333 } 357 334 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); 364 341 } 365 342 … … 460 437 { 461 438 my $self = shift @_; 462 my ($gsdl_cgi, $doc_xml_filename, $metaname, $metavalue, $metapos ) = @_;439 my ($gsdl_cgi, $doc_xml_filename, $metaname, $metavalue, $metapos, $metamode) = @_; 463 440 464 441 # use XML::Rules to add it in (read in and out again) … … 472 449 my $options = { 'metaname' => $metaname, 473 450 'metapos' => $metapos, 474 'metavalue' => $metavalue }; 451 'metavalue' => $metavalue, 452 'metamode' => $metamode }; 453 475 454 $self->edit_xml_file($gsdl_cgi,$doc_xml_filename,\@rules,$options); 476 455 } … … 485 464 my $gsdl_cgi = $self->{'gsdl_cgi'}; 486 465 my $gsdlhome = $self->{'gsdlhome'}; 487 466 my $infodbtype = $self->{'infodbtype'}; 467 488 468 # don't user authenticate for now 489 469 if ($baseaction::authentication_enabled) { … … 503 483 my $metaname = $self->{'metaname'}; 504 484 my $metavalue = $self->{'metavalue'}; 485 505 486 my $metapos = $self->{'metapos'}; 506 487 $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 } 507 495 508 496 # 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); 512 499 my $doc_xml_file = $doc_rec->{'doc-file'}->[0]; 513 500 … … 521 508 # Running import.pl -groupsize will cause this to have multiple sections in one doc.xml 522 509 $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 525 520 # Release the lock once it is done 526 521 $self->unlock_collection($username, $collect); 522 527 523 } 528 524 … … 682 678 my $gsdl_cgi = $self->{'gsdl_cgi'}; 683 679 my $gsdlhome = $self->{'gsdlhome'}; 684 680 my $infodbtype = $self->{'infodbtype'}; 681 685 682 # don't user authenticate for now 686 683 if ($baseaction::authentication_enabled) { … … 719 716 my $import_filename = undef; 720 717 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); 724 720 725 721 # This now stores the full pathname … … 759 755 my $gsdl_cgi = $self->{'gsdl_cgi'}; 760 756 my $gsdlhome = $self->{'gsdlhome'}; 761 757 my $infodbtype = $self->{'infodbtype'}; 758 762 759 if ($baseaction::authentication_enabled) { 763 760 # Ensure the user is allowed to edit this collection … … 786 783 $collect_tail =~ s/^.*[\/\\]//; 787 784 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); 789 786 790 787 # Remove the key … … 817 814 my $gsdl_cgi = $self->{'gsdl_cgi'}; 818 815 my $gsdlhome = $self->{'gsdlhome'}; 819 816 my $infodbtype = $self->{'infodbtype'}; 817 820 818 # don't user authenticate for now 821 819 if ($baseaction::authentication_enabled) { … … 843 841 $collect_tail =~ s/^.*[\/\\]//; 844 842 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); 846 844 847 845 # 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); 850 847 851 848 # Basically loop through and unescape_html the values … … 923 920 my $gsdl_cgi = $self->{'gsdl_cgi'}; 924 921 my $gsdlhome = $self->{'gsdlhome'}; 925 922 my $infodbtype = $self->{'infodbtype'}; 923 926 924 # 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. 927 925 my $rebuild_pending_macro = "_rebuildpendingmessage_"; … … 963 961 # If the doc oid is not specified, we assume the metadata.xml is next to the specified "f" 964 962 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); 968 965 969 966 # This now stores the full pathname … … 1014 1011 $collect_tail =~ s/^.*[\/\\]//; 1015 1012 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); 1017 1014 1018 1015 # 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 1021 1018 foreach my $k (keys %$doc_rec) { 1022 1019 my @escaped_v = ();
Note:
See TracChangeset
for help on using the changeset viewer.