- Timestamp:
- 2010-02-04T13:04:56+13:00 (14 years ago)
- Location:
- main/trunk/greenstone2/perllib/cgiactions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cgiactions/baseaction.pm
r21564 r21715 370 370 371 371 372 # Release the gli.lck otherwise no one else will be able to use the collection again. 373 sub unlock_collection 374 { 375 my $self = shift @_; 376 my ($username, $collection) = @_; 377 my $gsdl_cgi = $self->{'gsdl_cgi'}; 378 379 # Obtain the path to the collection GLI lock file 380 my $lock_file_path = &util::filename_cat($ENV{'GSDLHOME'}, "collect", $collection, "gli.lck"); 381 382 # If the lock file does exist, check if it is ours 383 if (-e $lock_file_path) 384 { 385 my $lock_file_content = ""; 386 open(LOCK_FILE, "<$lock_file_path"); 387 while (<LOCK_FILE>) { 388 $lock_file_content .= $_; 389 } 390 close(LOCK_FILE); 391 392 # Pick out the owner of the lock file 393 $lock_file_content =~ /\<User\>(.*?)\<\/User\>/; 394 my $lock_file_owner = $1; 395 396 # If we are the owner of this lock, we have the right to delete it 397 if ($lock_file_owner eq $username) { 398 unlink($lock_file_path ); 399 } 400 else { 401 $gsdl_cgi->generate_error("Collection is locked by: $lock_file_owner. Cannot be unlocked"); 402 } 403 } 404 } 405 406 372 407 sub send_mail 373 408 { -
main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm
r21569 r21715 43 43 44 44 45 46 45 my $action_table = 47 46 { … … 88 87 89 88 90 91 89 sub get_live_metadata 92 90 { … … 98 96 my $gsdlhome = $self->{'gsdlhome'}; 99 97 98 # Note: Not sure why get_live_metadata doesn't need the authentication check 99 100 # Obtain the collect dir 100 101 my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 101 # $gsdl_cgi->checked_chdir($collect_dir);102 103 102 104 103 # Make sure the collection isn't locked by someone else … … 106 105 107 106 # look up additional args 108 109 107 my $docid = $self->{'d'}; 110 108 if ((!defined $docid) || ($docid =~ m/^\s*$/)) { 111 $gsdl_cgi->generate_error("No docid (d=...) specified."); 112 } 113 109 $gsdl_cgi->generate_error("No docid (d=...) specified."); 110 } 111 112 # Generate the dbkey 114 113 my $metaname = $self->{'metaname'}; 115 116 114 my $dbkey = "$docid.$metaname"; 117 115 116 # To people who know $collect_tail please add some comments 117 # Obtain path to the database 118 118 my $collect_tail = $collect; 119 119 $collect_tail =~ s/^.*[\/|\\]//; 120 121 120 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 122 121 my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", "live-$collect_tail", $index_text_directory); 123 122 123 # Obtain the content of the key 124 124 my $cmd = "gdbmget $infodb_file_path $dbkey"; 125 126 125 if (open(GIN,"$cmd |") == 0) { 126 # Catch error if gdbmget failed 127 127 my $mess = "Failed to get metadata key: $metaname\n"; 128 128 $mess .= "$!\n"; … … 130 130 $gsdl_cgi->generate_error($mess); 131 131 } 132 133 132 else { 133 # Read everything in and concatenate them into $metavalue 134 134 my $metavalue = ""; 135 136 135 my $line; 137 136 while (defined ($line=<GIN>)) { … … 139 138 } 140 139 close(GIN); 141 142 chomp($metavalue); 143 140 chomp($metavalue); # Get rid off the tailing newlines 144 141 $gsdl_cgi->generate_ok_message("$metavalue"); 145 142 } 146 } 147 143 144 # Release the lock once it is done 145 $self->unlock_collection($username, $collect); 146 } 148 147 149 148 … … 157 156 my $gsdlhome = $self->{'gsdlhome'}; 158 157 159 158 # Authenticate user if it is enabled 160 159 if ($baseaction::authentication_enabled) { 161 160 # Ensure the user is allowed to edit this collection … … 163 162 } 164 163 164 # Obtain the collect dir 165 165 my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 166 # $gsdl_cgi->checked_chdir($collect_dir);167 168 166 169 167 # Make sure the collection isn't locked by someone else … … 171 169 172 170 # look up additional args 173 174 171 my $docid = $self->{'d'}; 175 172 my $metaname = $self->{'metaname'}; 176 173 my $metapos = $self->{'metapos'}; 177 174 175 # To people who know $collect_tail please add some comments 176 # Obtain path to the database 178 177 my $collect_tail = $collect; 179 178 $collect_tail =~ s/^.*[\/\\]//; 180 181 179 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 182 180 my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", $collect_tail, $index_text_directory); 181 182 # Read the docid entry 183 183 my $doc_rec_string = &dbutil::read_infodb_entry("gdbm", $infodb_file_path, $docid); 184 184 my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string); 185 186 # Basically loop through and unescape_html the values 185 187 foreach my $k (keys %$doc_rec) { 186 188 my @escaped_v = (); … … 189 191 push(@escaped_v, $ev); 190 192 } 191 192 193 $doc_rec->{$k} = \@escaped_v; 193 194 } 194 195 196 # Obtain the specified metadata value 195 197 $metapos = 0 if (!defined $metapos); 196 197 198 my $metavalue = $doc_rec->{$metaname}->[$metapos]; 198 199 199 $gsdl_cgi->generate_ok_message("$metavalue"); 200 201 } 202 203 200 201 # Release the lock once it is done 202 $self->unlock_collection($username, $collect); 203 } 204 204 205 205 … … 213 213 my $gsdlhome = $self->{'gsdlhome'}; 214 214 215 216 215 # don't user authenticate for now 217 216 if ($baseaction::authentication_enabled) { … … 220 219 } 221 220 221 # Obtain the collect dir 222 222 my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 223 # $gsdl_cgi->checked_chdir($collect_dir);224 225 223 226 224 # Make sure the collection isn't locked by someone else … … 228 226 229 227 # look up additional args 230 231 228 my $docid = $self->{'d'}; 229 if ((!defined $docid) || ($docid =~ m/^\s*$/)) { 230 $gsdl_cgi->generate_error("No docid (d=...) specified."); 231 } 232 my $metavalue = $self->{'metavalue'}; 233 234 # Generate the dbkey 232 235 my $metaname = $self->{'metaname'}; 233 my $metavalue = $self->{'metavalue'};234 235 236 my $dbkey = "$docid.$metaname"; 236 237 238 # To people who know $collect_tail please add some comments 239 # Obtain path to the database 237 240 my $collect_tail = $collect; 238 241 $collect_tail =~ s/^.*[\/\\]//; 239 240 242 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 241 243 my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", "live-$collect_tail", $index_text_directory); 242 244 245 # Set the new value 243 246 my $cmd = "gdbmset \"$infodb_file_path\" \"$dbkey\" \"$metavalue\""; 244 245 247 my $status = system($cmd); 246 247 248 if ($status != 0) { 249 # Catch error if gdbmget failed 248 250 my $mess = "Failed to set metadata key: $dbkey\n"; 249 251 250 252 $mess .= "PATH: $ENV{'PATH'}\n"; 251 253 $mess .= "cmd = $cmd\n"; … … 258 260 $gsdl_cgi->generate_ok_message("set-live-metadata successful: Key[$metaname]=$metavalue"); 259 261 } 260 262 263 # Release the lock once it is done 264 $self->unlock_collection($username, $collect); 261 265 } 262 266 … … 271 275 my $gsdlhome = $self->{'gsdlhome'}; 272 276 273 274 277 # don't user authenticate for now 275 278 if ($baseaction::authentication_enabled) { … … 278 281 } 279 282 283 # Obtain the collect dir 280 284 my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 281 # $gsdl_cgi->checked_chdir($collect_dir);282 283 285 284 286 # Make sure the collection isn't locked by someone else … … 286 288 287 289 # look up additional args 288 289 290 my $docid = $self->{'d'}; 290 291 my $metaname = $self->{'metaname'}; … … 292 293 my $metavalue = $self->{'metavalue'}; 293 294 295 # To people who know $collect_tail please add some comments 296 # Obtain path to the database 294 297 my $collect_tail = $collect; 295 298 $collect_tail =~ s/^.*[\/\\]//; 296 297 299 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 298 300 my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", $collect_tail, $index_text_directory); 301 302 # Read the docid entry 299 303 my $doc_rec_string = &dbutil::read_infodb_entry("gdbm", $infodb_file_path, $docid); 300 304 my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string); … … 313 317 } 314 318 } 315 316 319 $doc_rec->{$k} = \@escaped_v; 317 320 } 318 319 321 ## print STDERR "**** metavalue = $metavalue\n"; 320 322 323 # Protect the quotes 321 324 $metavalue =~ s/\"/\\\"/g; 322 325 326 # Set the metadata value 323 327 if (defined $metapos) { 324 328 $doc_rec->{$metaname}->[$metapos] = $metavalue; … … 327 331 $doc_rec->{$metaname} = [ $metavalue ]; 328 332 } 329 330 333 ## print STDERR "**** metavalue = $metavalue\n"; 331 334 335 # Generate the record string 332 336 my $serialized_doc_rec = &dbutil::convert_infodb_hash_to_string($doc_rec); 333 334 337 ## print STDERR "**** ser dr\n$serialized_doc_rec\n\n\n"; 335 338 339 # Store it into GDBM 336 340 my $cmd = "gdbmset \"$infodb_file_path\" \"$docid\" \"$serialized_doc_rec\""; 337 338 341 my $status = system($cmd); 339 340 342 if ($status != 0) { 343 # Catch error if gdbmget failed 341 344 my $mess = "Failed to set metadata key: $docid\n"; 342 345 … … 356 359 $gsdl_cgi->generate_ok_message($mess); 357 360 } 358 359 } 360 361 362 # Release the lock once it is done 363 $self->unlock_collection($username, $collect); 364 } 361 365 362 366 363 367 sub dxml_metadata 364 368 { 365 366 369 my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_; 367 368 369 370 my $metaname = $parser->{'parameters'}->{'metaname'}; 370 371 my $metamode = $parser->{'parameters'}->{'metamode'}; 371 372 373 # Find the right metadata tag and checks if we are going to override it 374 # Note: This over writes the first metadata block it encountered. If there are multiple Sections in the doc.xml, it might not behave as you would expect 372 375 my $name_attr = $attrHash->{'name'}; 373 374 376 if (($name_attr eq $metaname) && ($metamode eq "override")) { 375 377 # Get the value and override the current value 376 378 my $metavalue = $parser->{'parameters'}->{'metavalue'}; 377 378 379 $attrHash->{'_content'} = $metavalue; 379 380 380 381 # Don't want it to wipe out any other pieces of metadata 381 382 $parser->{'parameters'}->{'metamode'} = "done"; 382 383 383 } 384 384 385 385 # raw extended 386 # Someone please write some comments on why adding ':'.$tagname => $attrHash 386 387 return (':'.$tagname => $attrHash, [$tagname => $attrHash]); 387 388 } … … 390 391 sub dxml_description 391 392 { 392 393 393 my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_; 394 395 394 my $metamode = $parser->{'parameters'}->{'metamode'}; 396 395 397 396 # Accumulate the metadata 397 # NOTE: This appends new metadata element to all description fields. 398 # If there are multiple Sections/SubSections, the new metadata block will get appended to all of them 398 399 if ($metamode eq "accumulate") { 399 400 # tack a new metadata tag on to the end of the <Metadata>+ block 400 401 401 my $metaname = $parser->{'parameters'}->{'metaname'}; 402 402 my $metavalue = $parser->{'parameters'}->{'metavalue'}; 403 403 404 405 404 my $metadata_attr = { '_content' => $metavalue, 406 405 'name' => $metaname, … … 408 407 409 408 my $append_metadata = [ "Metadata" => $metadata_attr ]; 410 411 409 my $description_content = $attrHash->{'_content'}; 412 410 413 411 push(@$description_content," ", $append_metadata ,"\n "); 414 415 412 } 416 413 … … 419 416 } 420 417 418 421 419 sub edit_xml_file 422 420 { 423 421 my $self = shift @_; 424 425 422 my ($gsdl_cgi, $filename, $rules, $options) = @_; 426 423 427 424 # use XML::Rules to add it in (read in and out again) 428 429 425 my $parser = XML::Rules->new(rules => $rules, 430 426 style => 'filter' ); … … 435 431 } 436 432 else { 433 # Read all the text in 437 434 my $line; 438 435 while (defined ($line=<MIN>)) { … … 441 438 close(MIN); 442 439 443 440 # Matched lines will get handled by the call backs 444 441 my $xml_out = ""; 445 442 $parser->filter($xml_in,\$xml_out, $options); … … 450 447 else { 451 448 print MOUT $xml_out; 452 close(MOUT); 453 454 } 455 } 456 } 457 449 close(MOUT); 450 } 451 } 452 } 458 453 459 454 … … 461 456 { 462 457 my $self = shift @_; 463 464 458 my ($gsdl_cgi, $doc_xml_filename, $metaname, $metavalue, $metapos) = @_; 465 459 466 460 # use XML::Rules to add it in (read in and out again) 467 461 # Set the call back functions 468 462 my @rules = 469 463 ( _default => 'raw extended', … … 471 465 'Description' => \&dxml_description ); 472 466 467 # Sets the parameters 473 468 my $options = { 'metaname' => $metaname, 474 469 'metapos' => $metapos, 475 470 'metavalue' => $metavalue }; 476 477 471 $self->edit_xml_file($gsdl_cgi,$doc_xml_filename,\@rules,$options); 478 472 } … … 488 482 my $gsdlhome = $self->{'gsdlhome'}; 489 483 490 491 484 # don't user authenticate for now 492 485 if ($baseaction::authentication_enabled) { … … 495 488 } 496 489 490 # Obtain the collect and archive dir 497 491 my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 498 # $gsdl_cgi->checked_chdir($collect_dir);499 500 492 my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives"); 501 493 … … 504 496 505 497 # look up additional args 506 507 498 my $docid = $self->{'d'}; 508 509 499 my $metaname = $self->{'metaname'}; 510 500 my $metavalue = $self->{'metavalue'}; 511 501 my $metapos = $self->{'metapos'}; 512 513 502 $metapos = 0 if (!defined $metapos); 514 503 504 # Obtain the doc.xml path for the specified docID 515 505 my $arcinfo_doc_filename = &dbutil::get_infodb_file_path("gdbm", "archiveinf-doc", $archive_dir); 516 517 506 my $doc_rec_string = &dbutil::read_infodb_entry("gdbm", $arcinfo_doc_filename, $docid); 518 my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string); 519 507 my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string); 520 508 my $doc_xml_file = $doc_rec->{'doc-file'}->[0]; 521 522 523 my $archives_dir = &util::filename_cat($collect_dir,$collect,"archives"); 524 509 510 # The $doc_xml_file is relative to the archives, and now let's get the full path 511 my $archives_dir = &util::filename_cat($collect_dir,$collect,"archives"); 525 512 my $doc_xml_filename = &util::filename_cat($archives_dir,$doc_xml_file); 526 527 513 514 # Edit the doc.xml file with the specified metadata name, value and position. 515 # TODO: there is a potential problem here as this edit_doc_xml function 516 # is assuming the simple doc.xml situation where there is only one Section and no SubSections. 517 # Running import.pl -groupsize will cause this to have multiple sections in one doc.xml 528 518 $self->edit_doc_xml($gsdl_cgi,$doc_xml_filename, 529 519 $metaname,$metavalue,$metapos); 530 520 531 } 532 533 521 # Release the lock once it is done 522 $self->unlock_collection($username, $collect); 523 } 534 524 535 525 536 526 sub mxml_metadata 537 527 { 538 539 528 my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_; 540 541 542 529 my $metaname = $parser->{'parameters'}->{'metaname'}; 543 530 my $metamode = $parser->{'parameters'}->{'metamode'}; 544 531 532 # Find the right metadata tag and checks if we are going to override it 533 # Note: This over writes the first metadata block it encountered even if it doesn't belong to the source file we specified 545 534 my $name_attr = $attrHash->{'name'}; 546 547 535 if (($name_attr eq $metaname) && ($metamode eq "override")) { 548 536 # Get the value and override the current value 549 537 my $metavalue = $parser->{'parameters'}->{'metavalue'}; 550 551 538 $attrHash->{'_content'} = $metavalue; 552 539 553 540 # Don't want it to wipe out any other pieces of metadata 554 541 $parser->{'parameters'}->{'metamode'} = "done"; 555 556 542 } 557 543 558 544 # raw extended 545 # Someone please write some comments on why adding ':'.$tagname => $attrHash 559 546 return (':'.$tagname => $attrHash, [$tagname => $attrHash]); 560 547 } … … 563 550 sub mxml_description 564 551 { 565 566 552 my ($tagname, $attrHash, $contextArray, $parentDataArray, $parser) = @_; 567 568 553 my $metamode = $parser->{'parameters'}->{'metamode'}; 569 554 570 555 # Accumulate the metadata block to the end of the description block 556 # Note: This adds metadata block to all description blocks, so if there are 557 # multiple FileSets, it will add to all of them 571 558 if ($metamode eq "accumulate") { 572 559 # tack a new metadata tag on to the end of the <Metadata>+ block 573 574 560 my $metaname = $parser->{'parameters'}->{'metaname'}; 575 561 my $metavalue = $parser->{'parameters'}->{'metavalue'}; 576 562 577 578 563 my $metadata_attr = { '_content' => $metavalue, 579 564 'name' => $metaname, … … 581 566 582 567 my $append_metadata = [ "Metadata" => $metadata_attr ]; 583 584 568 my $description_content = $attrHash->{'_content'}; 585 569 586 570 push(@$description_content," ", $append_metadata ,"\n "); 587 588 571 } 589 572 … … 592 575 } 593 576 577 594 578 sub edit_metadata_xml 595 579 { 596 580 my $self = shift @_; 597 598 581 my ($gsdl_cgi, $metadata_xml_filename, $metaname, $metavalue, $metamode) = @_; 599 582 600 # use XML::Rules to add it in (read in and out again) 601 583 # Set the call-back functions for the metadata tags 602 584 my @rules = 603 585 ( _default => 'raw extended', 604 586 'Metadata' => \&mxml_metadata, 605 587 'Description' => \&mxml_description ); 606 607 588 589 # use XML::Rules to add it in (read in and out again) 608 590 my $parser = XML::Rules->new(rules => \@rules, 609 591 style => 'filter' ); 610 611 592 612 593 my $xml_in = ""; … … 615 596 } 616 597 else { 598 # Read them in 617 599 my $line; 618 600 while (defined ($line=<MIN>)) { 619 601 $xml_in .= $line; 620 602 } 621 close(MIN); 603 close(MIN); 622 604 623 605 # Filter with the call-back functions 624 606 my $xml_out = ""; 625 607 $parser->filter($xml_in,\$xml_out, { metaname => $metaname, 626 608 metavalue => $metavalue, 627 628 609 metamode => $metamode } ); 610 629 611 if (!open(MOUT,">$metadata_xml_filename")) { 630 612 $gsdl_cgi->generate_error("Unable to write out to $metadata_xml_filename: $!"); … … 632 614 else { 633 615 print MOUT $xml_out; 634 close(MOUT); 635 616 close(MOUT); 636 617 } 637 618 } … … 642 623 { 643 624 my $self = shift @_; 644 625 645 626 my $username = $self->{'username'}; 646 627 my $collect = $self->{'collect'}; … … 648 629 my $gsdlhome = $self->{'gsdlhome'}; 649 630 650 651 631 # don't user authenticate for now 652 632 if ($baseaction::authentication_enabled) { … … 655 635 } 656 636 637 # Obtain the collect and archive dir 657 638 my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 658 # $gsdl_cgi->checked_chdir($collect_dir);659 660 639 my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives"); 661 662 640 663 641 # Make sure the collection isn't locked by someone else … … 665 643 666 644 # look up additional args 667 668 645 # want either d= or f= 669 646 my $docid = $self->{'d'}; 670 647 my $import_file = $self->{'f'}; 671 672 648 if ((!defined $docid) && (!defined $import_file)) { 673 649 $gsdl_cgi->generate_error("No docid (d=...) or import file (f=) specified."); 674 650 } 675 651 652 # Get the parameters and set default mode to "accumulate" 676 653 my $metaname = $self->{'metaname'}; 677 654 my $metavalue = $self->{'metavalue'}; 678 655 my $metamode = $self->{'metamode'}; 679 680 656 if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) { 681 657 # make "accumulate" the default (less destructive, as won't actually 682 658 # delete any existing values) 683 684 659 $metamode = "accumulate"; 685 660 } 686 661 662 # Obtain where the metadata.xml is from the archiveinfo-doc.gdb file 663 # If the doc oid is not specified, we assume the metadata.xml is next to the specified "f" 687 664 my $metadata_xml_file; 688 689 665 my $import_filename = undef; 690 691 666 if (defined $docid) { 692 667 my $arcinfo_doc_filename = &dbutil::get_infodb_file_path("gdbm", "archiveinf-doc", $archive_dir); … … 698 673 } 699 674 else { 700 $import_filename = &util::filename_cat($collect_dir,$collect,$import_file); 701 } 702 703 # figure out correct metadata.xml file 704 675 $import_filename = &util::filename_cat($collect_dir,$collect,$import_file); 676 } 677 678 679 # figure out correct metadata.xml file [?] 680 # Assuming the metadata.xml file is next to the source file 681 # Note: This will not work if it is using the inherited metadata from the parent folder 705 682 my ($import_tailname, $import_dirname) 706 683 = File::Basename::fileparse($import_filename); 707 708 684 my $metadata_xml_filename = &util::filename_cat($import_dirname,"metadata.xml"); 709 685 686 # Edit the metadata.xml 687 # Note: At moment it doesn't correctly on metadata.xml with multiple FileSets 688 # "accumulate" mode will add new metadata block to all FileSets 689 # "override" mode will over write the first encountered metadata block, even if it doesn't have the right source 710 690 $self->edit_metadata_xml($gsdl_cgi,$metadata_xml_filename, 711 691 $metaname,$metavalue,$metamode); 712 692 713 } 714 715 716 693 # Release the lock once it is done 694 $self->unlock_collection($username, $collect); 695 } 717 696 718 697 … … 726 705 my $gsdlhome = $self->{'gsdlhome'}; 727 706 728 729 707 if ($baseaction::authentication_enabled) { 730 708 # Ensure the user is allowed to edit this collection … … 732 710 } 733 711 712 # Obtain the collect dir 734 713 my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 735 # $gsdl_cgi->checked_chdir($collect_dir);736 737 714 738 715 # Make sure the collection isn't locked by someone else … … 740 717 741 718 # look up additional args 742 743 719 my $docid = $self->{'d'}; 720 if ((!defined $docid) || ($docid =~ m/^\s*$/)) { 721 $gsdl_cgi->generate_error("No docid (d=...) specified."); 722 } 723 724 # Generate the dbkey 744 725 my $metaname = $self->{'metaname'}; 745 746 726 my $dbkey = "$docid.$metaname"; 747 727 728 # To people who know $collect_tail please add some comments 729 # Obtain the live gdbm_db path 748 730 my $collect_tail = $collect; 749 731 $collect_tail =~ s/^.*[\/\\]//; 750 751 732 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 752 733 my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", "live-$collect_tail", $index_text_directory); 753 734 735 # Remove the key 754 736 my $cmd = "gdbmdel \"$infodb_file_path\" \"$dbkey\""; 755 756 737 my $status = system($cmd); 757 758 738 if ($status != 0) { 739 # Catch error if gdbmdel failed 759 740 my $mess = "Failed to set metadata key: $dbkey\n"; 760 741 … … 782 763 my $gsdlhome = $self->{'gsdlhome'}; 783 764 784 785 765 # don't user authenticate for now 786 766 if ($baseaction::authentication_enabled) { … … 789 769 } 790 770 771 # Obtain the collect dir 791 772 my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 792 # $gsdl_cgi->checked_chdir($collect_dir);793 794 773 795 774 # Make sure the collection isn't locked by someone else … … 797 776 798 777 # look up additional args 799 800 778 my $docid = $self->{'d'}; 779 if ((!defined $docid) || ($docid =~ m/^\s*$/)) { 780 $gsdl_cgi->generate_error("No docid (d=...) specified."); 781 } 801 782 my $metaname = $self->{'metaname'}; 802 783 my $metapos = $self->{'metapos'}; 803 784 785 # To people who know $collect_tail please add some comments 786 # Obtain the path to the database 804 787 my $collect_tail = $collect; 805 788 $collect_tail =~ s/^.*[\/\\]//; 806 807 789 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 808 790 my $infodb_file_path = &dbutil::get_infodb_file_path("gdbm", $collect_tail, $index_text_directory); 791 792 # Read the docid entry 809 793 my $doc_rec_string = &dbutil::read_infodb_entry("gdbm", $infodb_file_path, $docid); 810 794 my $doc_rec = &dbutil::convert_infodb_string_to_hash($doc_rec_string); 795 796 # Basically loop through and unescape_html the values 811 797 foreach my $k (keys %$doc_rec) { 812 798 my @escaped_v = (); … … 823 809 } 824 810 } 825 826 811 $doc_rec->{$k} = \@escaped_v; 827 812 } 828 813 814 # Check to make sure the key does exist 815 if (!defined ($doc_rec->{$metaname})) { 816 $gsdl_cgi->generate_error("No metadata field \"" . $metaname . "\" in the specified document: [" . $docid . "]"); 817 } 818 819 # Obtain the specified metadata pos 829 820 $metapos = 0 if (!defined $metapos); 830 821 831 822 # consider check key is defined before deleting? 832 823 # Loop through the metadata array and ignore the specified position 833 824 my $filtered_metadata = []; 834 my $num_metadata_vals = scalar(@{$doc_rec->{$metaname}}); 835 825 my $num_metadata_vals = scalar(@{$doc_rec->{$metaname}}); 836 826 for (my $i=0; $i<$num_metadata_vals; $i++) { 837 827 my $metavalue = shift(@{$doc_rec->{$metaname}}); … … 841 831 } 842 832 } 843 844 833 $doc_rec->{$metaname} = $filtered_metadata; 845 834 835 # Turn the record back to string 846 836 my $serialized_doc_rec = &dbutil::convert_infodb_hash_to_string($doc_rec); 847 837 838 # Store it back to the database 848 839 my $cmd = "gdbmset \"$infodb_file_path\" \"$docid\" \"$serialized_doc_rec\""; 849 850 840 my $status = system($cmd); 851 852 841 if ($status != 0) { 853 842 my $mess = "Failed to set metadata key: $docid\n"; … … 867 856 $gsdl_cgi->generate_ok_message($mess); 868 857 } 869 870 } 871 872 873 874 858 } 875 859 876 860
Note:
See TracChangeset
for help on using the changeset viewer.