Changeset 33183
- Timestamp:
- 2019-06-21T16:47:21+12:00 (5 years ago)
- Location:
- main/trunk/greenstone2/perllib/cgiactions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cgiactions/baseaction.pm
r27775 r33183 83 83 my @opt_args = (); 84 84 push(@opt_args,"un") if (!$authentication_enabled); 85 push(@opt_args,@{$action_table->{$a}->{'optional-args'}}) ;85 push(@opt_args,@{$action_table->{$a}->{'optional-args'}}) if $action_table->{$a}->{'optional-args'}; 86 86 87 87 if (scalar(@opt_args)>0) { -
main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm
r32062 r33183 121 121 my $url_encoded_metavalue = $gsdl_cgi->param("metavalue"); 122 122 my $url_decoded_metavalue = &unicode::url_decode($url_encoded_metavalue,1); 123 #$gsdl_cgi->generate_message("@@@ metaaction new - DEBUG before utf82unicode: " . &unicode::debug_unicode_string($url_decoded_metavalue)); 124 123 125 my $unicode_array = &unicode::utf82unicode($url_decoded_metavalue); 124 126 125 127 $url_decoded_metavalue = join("",map(chr($_),@$unicode_array)); 128 129 #$gsdl_cgi->generate_message("@@@ metaaction new - DEBUG after utf82unicode: " . &unicode::debug_unicode_string($url_decoded_metavalue)); 130 126 131 $gsdl_cgi->param("metavalue",$url_decoded_metavalue); 127 132 -
main/trunk/greenstone2/perllib/cgiactions/modmetadataaction.pm
r32849 r33183 120 120 '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 121 121 122 123 #REMOVE MULTIPLE (REMOVE ALL MATCHING METANAME AT DOCID) 124 "erase-import-metadata" => { 125 'compulsory-args' => [ "d", "metaname" ] }, 126 127 "erase-archives-metadata" => { 128 'compulsory-args' => [ "d", "metaname" ] }, 129 130 "erase-index-metadata" => { 131 'compulsory-args' => [ "d", "metaname" ] }, 132 133 "erase-live-metadata" => { 134 'compulsory-args' => [ "d", "metaname" ] }, 135 136 "erase-metadata" => { # generic erase-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 137 'compulsory-args' => [ "d", "metaname" ], 138 'optional-args' => [ "where" ] }, 139 140 122 141 #INSERT METHODS 123 "insert-metadata" => { 142 "insert-metadata" => { 124 143 'compulsory-args' => [ "d", "metaname", "metavalue" ], 125 144 'optional-args' => [ ] } … … 2255 2274 if ($status != 0) { 2256 2275 # Catch error if gdbmdel failed 2257 my $mess = "Failed to setmetadata key: $dbkey\n";2276 my $mess = "Failed to delete metadata key: $dbkey\n"; 2258 2277 2259 2278 $mess .= "PATH: $ENV{'PATH'}\n"; … … 2448 2467 2449 2468 # Release the lock once it is done 2469 $self->unlock_collection($username, $collect); 2470 } 2471 2472 ################################################################################# 2473 # ERASE META METHODS: ERASE ALL VALUES FOR MATCHING METANAME AT SPECIFIED DOCID # 2474 ################################################################################# 2475 2476 sub erase_metadata 2477 { 2478 my $self = shift @_; 2479 2480 my $where = $self->{'where'}; 2481 # when $where is unspecified, following behaviour of sub remove_metadata by defaulting to erasing metadata from index 2482 if(!$where || ($where =~ m/^\s*$/)) { 2483 $self->erase_index_metadata(@_); # call the full version of set_index_meta for the default behaviour 2484 return; 2485 } 2486 2487 my $username = $self->{'username'}; 2488 my $collect = $self->{'collect'}; 2489 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2490 2491 if ($baseaction::authentication_enabled) { 2492 # Ensure the user is allowed to edit this collection 2493 $self->authenticate_user($username, $collect); #&authenticate_user($gsdl_cgi, $username, $collect); 2494 } 2495 2496 # Make sure the collection isn't locked by someone else 2497 $self->lock_collection($username, $collect); 2498 2499 # check which directories need to be processed, specified in $where as 2500 # any combination of import|archives|index|live 2501 if($where =~ m/import/) { 2502 $self->_erase_import_metadata(@_); 2503 } 2504 if($where =~ m/archives/) { 2505 $self->_erase_archives_metadata(@_); 2506 } 2507 if($where =~ m/index/) { 2508 $self->_erase_index_metadata(@_); 2509 } 2510 2511 # Release the lock once it is done 2512 $self->unlock_collection($username, $collect); 2513 } 2514 2515 # the internal version, without authentication 2516 sub _erase_index_metadata 2517 { 2518 my $self = shift @_; 2519 2520 my $collect = $self->{'collect'}; 2521 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2522 # my $gsdlhome = $self->{'gsdlhome'}; 2523 my $infodbtype = $self->{'infodbtype'}; 2524 2525 # Obtain the collect dir 2526 my $site = $self->{'site'}; 2527 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 2528 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 2529 2530 # look up additional args 2531 my $docid = $self->{'d'}; 2532 if ((!defined $docid) || ($docid =~ m/^\s*$/)) { 2533 $gsdl_cgi->generate_error("No docid (d=...) specified."); 2534 } 2535 my $metaname = $self->{'metaname'}; 2536 my $metapos = undef; 2537 my $metavalue = undef; 2538 2539 # To people who know $collect_tail please add some comments 2540 # -> In collection groups, I think collect_tailname is the subcollection name, 2541 # e.g. colgroup-name/col-tail-name 2542 # Obtain the path to the database 2543 my $collect_tail = $collect; 2544 $collect_tail =~ s/^.*[\/|\\]//; 2545 my $index_text_directory = &util::filename_cat($collect_dir,$collect,"index","text"); 2546 my $infodb_file_path = &dbutil::get_infodb_file_path($infodbtype, $collect_tail, $index_text_directory); 2547 2548 # Read the docid entry 2549 my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $infodb_file_path, $docid); 2550 2551 # Check to make sure the key does exist 2552 if (defined ($doc_rec->{$metaname})) { 2553 2554 $doc_rec->{$metaname} = []; 2555 2556 ## Use the dbutil set_entry method instead of assuming the database is gdbm 2557 my $status = &dbutil::set_infodb_entry($infodbtype, $infodb_file_path, $docid, $doc_rec); 2558 2559 if ($status != 0) { 2560 my $mess = "Failed to erase metadata key: $docid\n"; 2561 2562 $mess .= "PATH: $ENV{'PATH'}\n"; 2563 $mess .= "Exit status: $status\n"; 2564 $mess .= "System Error Message: $!\n"; 2565 2566 $gsdl_cgi->generate_error($mess); 2567 } 2568 else { 2569 my $mess = "DB set (with item deleted) successful: Key[$docid]\n"; 2570 $mess .= " $metaname"; 2571 $mess .= "->[$metapos]" if (defined $metapos); 2572 $mess .= " ($metavalue)" if (defined $metavalue); 2573 2574 $gsdl_cgi->generate_ok_message($mess); 2575 } 2576 } 2577 else { # no such metaname. Is it really an error? 2578 $gsdl_cgi->generate_ok_message("Can't erase. No metadata field \"" . $metaname . "\" in the specified document: [" . $docid . "]"); 2579 } 2580 #return $status; # in case calling functions have a use for this 2581 } 2582 2583 sub erase_index_metadata 2584 { 2585 my $self = shift @_; 2586 2587 my $username = $self->{'username'}; 2588 my $collect = $self->{'collect'}; 2589 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2590 # my $gsdlhome = $self->{'gsdlhome'}; 2591 2592 if ($baseaction::authentication_enabled) { 2593 # Ensure the user is allowed to edit this collection 2594 $self->authenticate_user($username, $collect); #&authenticate_user($gsdl_cgi, $username, $collect); 2595 } 2596 2597 # Obtain the collect dir 2598 my $site = $self->{'site'}; 2599 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 2600 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 2601 2602 # Make sure the collection isn't locked by someone else 2603 $self->lock_collection($username, $collect); 2604 2605 $self->_erase_index_metadata(@_); 2606 2607 # Release the lock once it is done 2608 $self->unlock_collection($username, $collect); 2609 } 2610 2611 2612 # Given a metaname, removes ALL metadata with that metaname at the provided docid 2613 sub _erase_archives_metadata 2614 { 2615 my $self = shift @_; 2616 2617 my $collect = $self->{'collect'}; 2618 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2619 # my $gsdlhome = $self->{'gsdlhome'}; 2620 my $infodbtype = $self->{'infodbtype'}; 2621 2622 my $site = $self->{'site'}; 2623 2624 # Obtain the collect and archive dir 2625 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 2626 2627 my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives"); 2628 2629 # look up additional args 2630 my ($docid, $docid_secnum) = ($self->{'d'} =~ m/^(.*?)(\..*)?$/); 2631 2632 my $metaname = $self->{'metaname'}; 2633 2634 # metapos, metavalue and metamode are never provided and therefore all undefined for erase_archives_metadata 2635 my $metapos = undef; 2636 my $metavalue = undef; 2637 my $metamode = "override"; # when override and no metapos or metaval, all values for metaname will be affected 2638 2639 my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir); 2640 my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid); 2641 2642 # This now stores the full pathname 2643 my $doc_filename = $doc_rec->{'doc-file'}->[0]; 2644 2645 my $status = $self->remove_from_doc_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_filename), $metaname, $metapos, $metavalue, $docid_secnum, $metamode); 2646 2647 if ($status == 0) 2648 { 2649 my $mess = "\nerase-archives-metadata successful: \nKey[$docid]\n"; 2650 $mess .= " $metaname"; 2651 $gsdl_cgi->generate_ok_message($mess); 2652 } 2653 else 2654 { 2655 my $mess .= "Failed to erase archives metadata key: $docid\n"; 2656 $mess .= "Exit status: $status\n"; 2657 $mess .= "System Error Message: $!\n"; 2658 $mess .= "-" x 20 . "\n"; 2659 2660 $gsdl_cgi->generate_error($mess); 2661 } 2662 2663 #return $status; # in case calling functions have a use for this 2664 } 2665 2666 # practically identical to remove_archives_metadata 2667 sub erase_archives_metadata 2668 { 2669 my $self = shift @_; 2670 2671 my $username = $self->{'username'}; 2672 my $collect = $self->{'collect'}; 2673 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2674 2675 if ($baseaction::authentication_enabled) 2676 { 2677 # Ensure the user is allowed to edit this collection 2678 $self->authenticate_user($username, $collect); #&authenticate_user($gsdl_cgi, $username, $collect); 2679 } 2680 2681 # Make sure the collection isn't locked by someone else 2682 $self->lock_collection($username, $collect); 2683 2684 $self->_erase_archives_metadata(@_); 2685 2686 # Release the lock once it is done 2687 $self->unlock_collection($username, $collect); 2688 } 2689 2690 sub _erase_import_metadata 2691 { 2692 my $self = shift @_; 2693 2694 my $collect = $self->{'collect'}; 2695 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2696 # my $gsdlhome = $self->{'gsdlhome'}; 2697 my $infodbtype = $self->{'infodbtype'}; 2698 2699 # Obtain the collect dir 2700 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 2701 my $site = $self->{'site'}; 2702 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 2703 2704 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 2705 my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives"); 2706 2707 # look up additional args 2708 my $docid = $self->{'d'}; 2709 if ((!defined $docid) || ($docid =~ m/^\s*$/)) 2710 { 2711 $gsdl_cgi->generate_error("No docid (d=...) specified.\n"); 2712 } 2713 2714 my $metaname = $self->{'metaname'}; 2715 my $metapos = undef; 2716 my $metavalue = undef; 2717 my $metamode = "override"; 2718 2719 # Obtain where the metadata.xml is from the archiveinfo-doc.gdb file 2720 # If the doc oid is not specified, we assume the metadata.xml is next to the specified "f" 2721 my $metadata_xml_file; 2722 my $import_filename = undef; 2723 if (defined $docid) 2724 { 2725 my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir); 2726 my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid); 2727 2728 # This now stores the full pathname 2729 $import_filename = $doc_rec->{'src-file'}->[0]; 2730 $import_filename = &util::placeholders_to_abspath($import_filename); 2731 } 2732 2733 if((!defined $import_filename) || ($import_filename =~ m/^\s*$/)) 2734 { 2735 $gsdl_cgi->generate_error("There is no metadata\n"); 2736 } 2737 2738 # figure out correct metadata.xml file [?] 2739 # Assuming the metadata.xml file is next to the source file 2740 # Note: This will not work if it is using the inherited metadata from the parent folder 2741 my ($import_tailname, $import_dirname) = File::Basename::fileparse($import_filename); 2742 my $metadata_xml_filename = &util::filename_cat($import_dirname,"metadata.xml"); 2743 2744 $self->remove_from_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $metapos, $metavalue, $import_tailname, $metamode); # metamode=override, means all values of metaname are affected 2745 2746 my $mess = "erase-import-metadata successful: Key[$docid] -> $metadata_xml_filename\n"; 2747 $mess .= " $metaname"; 2748 $mess .= " = $metavalue\n"; 2749 2750 $gsdl_cgi->generate_ok_message($mess); 2751 2752 #return $status; # in case calling functions have a use for this 2753 } 2754 2755 sub erase_import_metadata 2756 { 2757 my $self = shift @_; 2758 2759 my $username = $self->{'username'}; 2760 my $collect = $self->{'collect'}; 2761 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2762 2763 if ($baseaction::authentication_enabled) { 2764 # Ensure the user is allowed to edit this collection 2765 $self->authenticate_user($username, $collect); #&authenticate_user($gsdl_cgi, $username, $collect); 2766 } 2767 2768 # Make sure the collection isn't locked by someone else 2769 $self->lock_collection($username, $collect); 2770 2771 $self->_erase_import_metadata(@_); 2772 2773 # Release the lock once it is done 2774 $self->unlock_collection($username, $collect); 2775 2776 } 2777 2778 # removes all meta with matching metaname for the specified docid from the live metadata index 2779 sub _erase_live_metadata 2780 { 2781 my $self = shift @_; 2782 # At present, _remove_live_metadata doesn't take metaval or metapos either and therefore has the desired effect 2783 $self->_remove_live_metadata(@_); 2784 2785 } 2786 2787 sub erase_live_metadata 2788 { 2789 my $self = shift @_; 2790 2791 my $username = $self->{'username'}; 2792 my $collect = $self->{'collect'}; 2793 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2794 my $gsdlhome = $self->{'gsdlhome'}; 2795 2796 if ($baseaction::authentication_enabled) { 2797 # Ensure the user is allowed to edit this collection 2798 $self->authenticate_user($username, $collect); #&authenticate_user($gsdl_cgi, $username, $collect); 2799 } 2800 2801 # Make sure the collection isn't locked by someone else 2802 $self->lock_collection($username, $collect); 2803 2804 $self->_erase_live_metadata(@_); 2805 2450 2806 $self->unlock_collection($username, $collect); 2451 2807 }
Note:
See TracChangeset
for help on using the changeset viewer.