Changeset 27157 for main/trunk
- Timestamp:
- 2013-04-04T18:26:18+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm
r27156 r27157 8 8 # Copyright (C) 2009 New Zealand Digital Library Project 9 9 # 10 # This program is free software; you can redistr ibute it and/or modify10 # This program is free software; you can redistr te it and/or modify 11 11 # it under the terms of the GNU General Public License as published by 12 12 # the Free Software Foundation; either version 2 of the License, or … … 54 54 'optional-args' => [ "metapos" ] }, 55 55 56 "get- metadata" => {56 "get-index-metadata" => { 57 57 'compulsory-args' => [ "d", "metaname" ], 58 58 'optional-args' => [ "metapos" ] }, 59 60 "get-metadata" => { # alias for get-index-metadata 61 'compulsory-args' => [ "d", "metaname" ], 62 'optional-args' => [ "metapos" ] }, 59 63 60 64 "get-live-metadata" => { … … 67 71 'optional-args' => [ ] }, 68 72 69 "set-metadata" => { 73 "set-metadata" => { # generic set-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 74 'compulsory-args' => [ "metaname", "metavalue" ], 75 'optional-args' => [ "where", "metapos", "metamode", "prevmetavalue", "d", "f" ] }, 76 77 "set-index-metadata" => { 70 78 'compulsory-args' => [ "d", "metaname", "metavalue" ], 71 79 'optional-args' => [ "metapos" ] }, … … 105 113 'optional-args' => [ ] }, 106 114 107 "remove- metadata" => {115 "remove-index-metadata" => { 108 116 'compulsory-args' => [ "d", "metaname" ], 109 117 'optional-args' => [ "metapos", "metavalue" ] }, 118 119 "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 120 'compulsory-args' => [ "d", "metaname" ], 121 'optional-args' => [ "where", "metapos", "metavalue" ] }, 110 122 111 123 #INSERT METHODS … … 202 214 } 203 215 204 216 # just calls the index version 205 217 sub get_metadata 218 { 219 my $self = shift @_; 220 $self->get_index_metadata(@_); 221 } 222 223 sub get_index_metadata 206 224 { 207 225 my $self = shift @_; … … 493 511 } 494 512 495 sub set_live_metadata513 sub _set_live_metadata 496 514 { 497 515 my $self = shift @_; 498 516 499 my $username = $self->{'username'};500 517 my $collect = $self->{'collect'}; 501 518 my $gsdl_cgi = $self->{'gsdl_cgi'}; 502 my $gsdlhome = $self->{'gsdlhome'};519 #my $gsdlhome = $self->{'gsdlhome'}; 503 520 my $infodbtype = $self->{'infodbtype'}; 504 505 if ($baseaction::authentication_enabled) {506 # Ensure the user is allowed to edit this collection507 &authenticate_user($gsdl_cgi, $username, $collect);508 }509 521 510 522 # Obtain the collect dir 511 512 523 my $site = $self->{'site'}; 524 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 513 525 ##my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 514 526 515 # Make sure the collection isn't locked by someone else516 $self->lock_collection($username, $collect);517 527 518 528 # look up additional args … … 552 562 $gsdl_cgi->generate_ok_message("set-live-metadata successful: Key[$metaname]=$metavalue"); 553 563 } 554 564 565 #return $status; # in case calling functions have any further use for this 566 } 567 568 sub set_live_metadata 569 { 570 my $self = shift @_; 571 572 my $username = $self->{'username'}; 573 my $collect = $self->{'collect'}; 574 my $gsdl_cgi = $self->{'gsdl_cgi'}; 575 576 if ($baseaction::authentication_enabled) { 577 # Ensure the user is allowed to edit this collection 578 &authenticate_user($gsdl_cgi, $username, $collect); 579 } 580 581 # Make sure the collection isn't locked by someone else 582 $self->lock_collection($username, $collect); 583 584 $self->_set_live_metadata(@_); 585 555 586 # Release the lock once it is done 556 587 $self->unlock_collection($username, $collect); … … 589 620 } 590 621 591 sub set_metadata622 sub _set_import_metadata 592 623 { 593 624 my $self = shift @_; 594 625 595 my $username = $self->{'username'};596 626 my $collect = $self->{'collect'}; 597 627 my $gsdl_cgi = $self->{'gsdl_cgi'}; 598 my $gsdlhome = $self->{'gsdlhome'}; 599 600 if ($baseaction::authentication_enabled) { 601 # Ensure the user is allowed to edit this collection 602 &authenticate_user($gsdl_cgi, $username, $collect); 603 } 604 605 my $site = $self->{'site'}; 606 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 607 608 $gsdl_cgi->checked_chdir($collect_dir); 609 610 # Obtain the collect dir 628 my $infodbtype = $self->{'infodbtype'}; 629 # my $gsdlhome = $self->{'gsdlhome'}; 630 631 # Obtain the collect and archive dir 632 my $site = $self->{'site'}; 633 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 611 634 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 612 613 # Make sure the collection isn't locked by someone else 614 $self->lock_collection($username, $collect); 635 my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives"); 636 637 # look up additional args 638 # want either d= or f= 639 my $docid = $self->{'d'}; 640 my $import_file = $self->{'f'}; 641 if ((!defined $docid) && (!defined $import_file)) { 642 $gsdl_cgi->generate_error("No docid (d=...) or import file (f=) specified."); 643 } 644 645 # Get the parameters and set default mode to "accumulate" 646 my $metaname = $self->{'metaname'}; 647 my $metavalue = $self->{'metavalue'}; 648 ## $metavalue =~ s/&lt;(.*?)&gt;/<$1>/g; 649 $metavalue =~ s/<(.*?)>/<$1>/g; 650 651 my $metamode = $self->{'metamode'}; 652 if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) { 653 # make "accumulate" the default (less destructive, as won't actually 654 # delete any existing values) 655 $metamode = "accumulate"; 656 } 657 658 # Obtain where the metadata.xml is from the archiveinfo-doc.gdb file 659 # If the doc oid is not specified, we assume the metadata.xml is next to the specified "f" 660 my $metadata_xml_file; 661 my $import_filename = undef; 662 if (defined $docid) { 663 my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir); 664 my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid); 665 666 # This now stores the full pathname 667 $import_filename = $doc_rec->{'src-file'}->[0]; 668 } 669 else { 670 $import_filename = &util::filename_cat($collect_dir,$collect,$import_file); 671 } 672 673 # figure out correct metadata.xml file [?] 674 # Assuming the metadata.xml file is next to the source file 675 # Note: This will not work if it is using the inherited metadata from the parent folder 676 my ($import_tailname, $import_dirname) = File::Basename::fileparse($import_filename); 677 my $metadata_xml_filename = &util::filename_cat($import_dirname,"metadata.xml"); 678 679 # Edit the metadata.xml 680 # Modified by Jeffrey from DL Consulting 681 # Handle the case where there is one metadata.xml file for multiple FileSets 682 # The XML filter needs to know whether it is in the right FileSet 683 # TODO: This doesn't fix the problem where the metadata.xml is not next to the src file. 684 # TODO: This doesn't handle the common metadata (where FileName doesn't point to a single file) 685 $self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename, 686 $metaname, $metavalue, $metamode, $import_tailname); 687 688 689 my $mess = "set-import-metadata successful: Key[$docid] -> $metadata_xml_filename\n"; 690 $mess .= " $metaname"; 691 $mess .= " = $metavalue"; 692 $mess .= " ($metamode)\n"; 693 694 $gsdl_cgi->generate_ok_message($mess); 695 696 #return $status; # in case calling functions have any further use for this 697 } 698 699 # the version of set_index_meta that doesn't do authentication 700 sub _set_archives_metadata 701 { 702 my $self = shift @_; 703 704 my $collect = $self->{'collect'}; 705 my $gsdl_cgi = $self->{'gsdl_cgi'}; 706 my $infodbtype = $self->{'infodbtype'}; 707 708 # Obtain the collect and archive dir 709 my $site = $self->{'site'}; 710 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 711 my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives"); 712 713 # look up additional args 714 my $docid = $self->{'d'}; 715 my $metaname = $self->{'metaname'}; 716 my $metavalue = $self->{'metavalue'}; 717 my $prevmetavalue = $self->{'prevmetavalue'}; 718 719 my $metapos = $self->{'metapos'}; 720 $metapos = 0 if (!defined $metapos); 721 722 my $metamode = $self->{'metamode'}; 723 if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) { 724 # make "accumulate" the default (less destructive, as won't actually 725 # delete any existing values) 726 $metamode = "accumulate"; 727 } 728 729 my $status = $self->set_archives_metadata_entry($gsdl_cgi,$archive_dir, $collect_dir,$collect, $infodbtype,$docid, 730 $metaname,$metapos,$metavalue,$metamode,$prevmetavalue); 731 732 if ($status == 0) { 733 my $mess = "set-archives-metadata successful: Key[$docid]\n"; 734 $mess .= " $metaname"; 735 $mess .= "->[$metapos]" if (defined $metapos); 736 $mess .= " = $metavalue"; 737 $mess .= " ($metamode)\n"; 738 739 $gsdl_cgi->generate_ok_message($mess); 740 } 741 else { 742 my $mess .= "Failed to set archives metadata key: $docid\n"; 743 $mess .= "Exit status: $status\n"; 744 if(defined $self->{'error_msg'}) { 745 $mess .= "Error Message: $self->{'error_msg'}\n"; 746 } else { 747 $mess .= "System Error Message: $!\n"; 748 } 749 $mess .= "-" x 20 . "\n"; 750 751 $gsdl_cgi->generate_error($mess); 752 } 753 754 #return $status; # in case calling functions have any further use for this 755 } 756 757 758 # the version of set_index_meta that doesn't do authentication 759 sub _set_index_metadata 760 { 761 my $self = shift @_; 762 763 my $collect = $self->{'collect'}; 764 my $gsdl_cgi = $self->{'gsdl_cgi'}; 765 766 my $site = $self->{'site'}; 767 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 615 768 616 769 # look up additional args … … 634 787 } 635 788 else { 636 my $mess = "set- metadata successful: Key[$docid]\n";789 my $mess = "set-index-metadata successful: Key[$docid]\n"; 637 790 $mess .= " $metaname"; 638 791 $mess .= "->[$metapos]" if (defined $metapos); 639 $mess .= " = $metavalue ";792 $mess .= " = $metavalue\n"; 640 793 641 794 $gsdl_cgi->generate_ok_message($mess); 642 795 } 796 797 #return $status; # in case calling functions have any further use for this 798 } 799 800 sub set_index_metadata 801 { 802 my $self = shift @_; 803 804 my $username = $self->{'username'}; 805 my $collect = $self->{'collect'}; 806 my $gsdl_cgi = $self->{'gsdl_cgi'}; 807 #my $gsdlhome = $self->{'gsdlhome'}; 808 809 if ($baseaction::authentication_enabled) { 810 # Ensure the user is allowed to edit this collection 811 &authenticate_user($gsdl_cgi, $username, $collect); 812 } 813 814 my $site = $self->{'site'}; 815 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 816 817 $gsdl_cgi->checked_chdir($collect_dir); 818 819 # Obtain the collect dir 820 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 821 822 # Make sure the collection isn't locked by someone else 823 $self->lock_collection($username, $collect); 824 825 $self->_set_index_metadata(@_); 643 826 644 827 # Release the lock once it is done … … 646 829 } 647 830 831 # call this to set the metadata for a combination of dirs archives, import or index, or live 832 # if none specified, defaults to index which was the original behaviour of set_metadata. 833 sub set_metadata 834 { 835 my $self = shift @_; 836 837 # Testing that not defining a variable, setting it to "" or to " " all return false 838 # >perl -e 'my $whichdirs=""; if($whichdirs) {print "$whichdirs\n"};' 839 840 my $where = $self->{'where'}; 841 if(!$where) { 842 $self->set_index_metadata(@_); # call the full version of set_index_meta for the default behaviour 843 return; 844 } 845 846 # authenticate and lock collection once, even if processing multiple dirs 847 my $username = $self->{'username'}; 848 my $collect = $self->{'collect'}; 849 my $gsdl_cgi = $self->{'gsdl_cgi'}; 850 851 if ($baseaction::authentication_enabled) { 852 # Ensure the user is allowed to edit this collection 853 #&authenticate_user($gsdl_cgi, $username, $collect); 854 $self->authenticate_user($username, $collect); 855 } 856 857 if($where =~ m/index/) { 858 my $site = $self->{'site'}; 859 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 860 $gsdl_cgi->checked_chdir($collect_dir); 861 } 862 863 # Make sure the collection isn't locked by someone else 864 $self->lock_collection($username, $collect); 865 866 867 # now at last can set the metadata. $where can specify multiple 868 # $where is of the form: import|archives|index, or a subset thereof 869 870 #my @whichdirs = split('\|', $where); 871 872 # just check whether $where contains import/archives/index/live in turn, and 873 # for each case, process it accordingly 874 if($where =~ m/import/) { 875 $self->_set_import_metadata(@_); 876 } 877 878 if($where =~ m/archives/) { 879 880 # look up docID arg which is optional to set_metadata because it's optional 881 # to set_import, but which is compulsory to set_archives_metadata 882 my $docid = $self->{'d'}; 883 if ((!defined $docid) || ($docid =~ m/^\s*$/)) { 884 $gsdl_cgi->generate_error("No docid (d=...) specified."); 885 } 886 else { # we have a docid, so can set archives meta 887 $self->_set_archives_metadata(@_); 888 } 889 } 890 891 if($where =~ m/index/) { 892 893 # look up docID arg which is optional to set_metadata because it's optional 894 # to set_import, but which is compulsory to set_archives_metadata 895 my $docid = $self->{'d'}; 896 if ((!defined $docid) || ($docid =~ m/^\s*$/)) { 897 $gsdl_cgi->generate_error("No docid (d=...) specified."); 898 } 899 else { # we have a docid, so can set index meta 900 $self->_set_index_metadata(@_); 901 } 902 } 903 904 if($where =~ m/live/) { 905 $self->_set_live_metadata(@_); # docid param, d, is compulsory, but is checked for in subroutine 906 } 907 908 # Release the lock once it is done 909 $self->unlock_collection($username, $collect); 910 } 648 911 649 912 sub set_metadata_array … … 1070 1333 my $collect = $self->{'collect'}; 1071 1334 my $gsdl_cgi = $self->{'gsdl_cgi'}; 1072 my $gsdlhome = $self->{'gsdlhome'};1073 my $infodbtype = $self->{'infodbtype'};1074 1335 1075 1336 if ($baseaction::authentication_enabled) { … … 1078 1339 } 1079 1340 1080 my $site = $self->{'site'};1081 1082 # Obtain the collect and archive dir1083 my $collect_dir = $gsdl_cgi->get_collection_dir($site);1084 1085 my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives");1086 1087 1341 # Make sure the collection isn't locked by someone else 1088 1342 $self->lock_collection($username, $collect); 1089 1343 1090 # look up additional args 1091 my $docid = $self->{'d'}; 1092 my $metaname = $self->{'metaname'}; 1093 my $metavalue = $self->{'metavalue'}; 1094 my $prevmetavalue = $self->{'prevmetavalue'}; 1095 1096 my $metapos = $self->{'metapos'}; 1097 $metapos = 0 if (!defined $metapos); 1098 1099 my $metamode = $self->{'metamode'}; 1100 if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) { 1101 # make "accumulate" the default (less destructive, as won't actually 1102 # delete any existing values) 1103 $metamode = "accumulate"; 1104 } 1105 1106 my $status = $self->set_archives_metadata_entry($gsdl_cgi,$archive_dir, $collect_dir,$collect, $infodbtype,$docid, 1107 $metaname,$metapos,$metavalue,$metamode,$prevmetavalue); 1108 1344 $self->_set_archives_metadata(@_); 1345 1109 1346 # Release the lock once it is done 1110 1347 $self->unlock_collection($username, $collect); 1111 1112 if ($status == 0) {1113 my $mess = "set-archives-metadata successful: Key[$docid]\n";1114 $mess .= " $metaname";1115 $mess .= "->[$metapos]" if (defined $metapos);1116 $mess .= " = $metavalue";1117 $mess .= " ($metamode)\n";1118 1119 $gsdl_cgi->generate_ok_message($mess);1120 }1121 else {1122 my $mess .= "Failed to set archives metadata key: $docid\n";1123 $mess .= "Exit status: $status\n";1124 if(defined $self->{'error_msg'}) {1125 $mess .= "Error Message: $self->{'error_msg'}\n";1126 } else {1127 $mess .= "System Error Message: $!\n";1128 }1129 $mess .= "-" x 20 . "\n";1130 1131 $gsdl_cgi->generate_error($mess);1132 }1133 1348 } 1134 1349 … … 1219 1434 } 1220 1435 1221 sub remove_archives_metadata1436 sub _remove_archives_metadata 1222 1437 { 1223 1438 my $self = shift @_; 1224 1439 1225 my $username = $self->{'username'};1226 1440 my $collect = $self->{'collect'}; 1227 1441 my $gsdl_cgi = $self->{'gsdl_cgi'}; 1228 my $gsdlhome = $self->{'gsdlhome'};1442 # my $gsdlhome = $self->{'gsdlhome'}; 1229 1443 my $infodbtype = $self->{'infodbtype'}; 1230 1231 if ($baseaction::authentication_enabled)1232 {1233 # Ensure the user is allowed to edit this collection1234 &authenticate_user($gsdl_cgi, $username, $collect);1235 }1236 1444 1237 1445 my $site = $self->{'site'}; … … 1242 1450 my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives"); 1243 1451 1244 # Make sure the collection isn't locked by someone else1245 $self->lock_collection($username, $collect);1246 1247 1452 # look up additional args 1248 1453 my ($docid, $docid_secnum) = ($self->{'d'} =~ m/^(.*?)(\..*)?$/); … … 1260 1465 my $status = $self->remove_from_doc_xml($gsdl_cgi, &util::filename_cat($archive_dir, $doc_filename), $metaname, $metapos, undef, $docid_secnum); 1261 1466 1262 # Release the lock once it is done1263 $self->unlock_collection($username, $collect);1264 1265 1467 if ($status == 0) 1266 1468 { … … 1280 1482 $gsdl_cgi->generate_error($mess); 1281 1483 } 1484 1485 #return $status; # in case calling functions have a use for this 1486 } 1487 1488 sub remove_archives_metadata 1489 { 1490 my $self = shift @_; 1491 1492 my $username = $self->{'username'}; 1493 my $collect = $self->{'collect'}; 1494 my $gsdl_cgi = $self->{'gsdl_cgi'}; 1495 1496 if ($baseaction::authentication_enabled) 1497 { 1498 # Ensure the user is allowed to edit this collection 1499 &authenticate_user($gsdl_cgi, $username, $collect); 1500 } 1501 1502 # Make sure the collection isn't locked by someone else 1503 $self->lock_collection($username, $collect); 1504 1505 $self->_remove_archives_metadata(@_); 1506 1507 # Release the lock once it is done 1508 $self->unlock_collection($username, $collect); 1282 1509 } 1283 1510 … … 1594 1821 my $collect = $self->{'collect'}; 1595 1822 my $gsdl_cgi = $self->{'gsdl_cgi'}; 1596 my $gsdlhome = $self->{'gsdlhome'};1597 my $infodbtype = $self->{'infodbtype'};1598 1823 1599 1824 if ($baseaction::authentication_enabled) { … … 1602 1827 } 1603 1828 1604 1605 # Obtain the collect and archive dir1606 my $site = $self->{'site'};1607 my $collect_dir = $gsdl_cgi->get_collection_dir($site);1608 1609 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect");1610 my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives");1611 1612 1829 # Make sure the collection isn't locked by someone else 1613 1830 $self->lock_collection($username, $collect); 1614 1615 # look up additional args 1616 # want either d= or f= 1617 my $docid = $self->{'d'}; 1618 my $import_file = $self->{'f'}; 1619 if ((!defined $docid) && (!defined $import_file)) { 1620 $gsdl_cgi->generate_error("No docid (d=...) or import file (f=) specified."); 1621 } 1622 1623 # Get the parameters and set default mode to "accumulate" 1624 my $metaname = $self->{'metaname'}; 1625 my $metavalue = $self->{'metavalue'}; 1626 ## $metavalue =~ s/&lt;(.*?)&gt;/<$1>/g; 1627 $metavalue =~ s/<(.*?)>/<$1>/g; 1628 1629 my $metamode = $self->{'metamode'}; 1630 if ((!defined $metamode) || ($metamode =~ m/^\s*$/)) { 1631 # make "accumulate" the default (less destructive, as won't actually 1632 # delete any existing values) 1633 $metamode = "accumulate"; 1634 } 1635 1636 # Obtain where the metadata.xml is from the archiveinfo-doc.gdb file 1637 # If the doc oid is not specified, we assume the metadata.xml is next to the specified "f" 1638 my $metadata_xml_file; 1639 my $import_filename = undef; 1640 if (defined $docid) { 1641 my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir); 1642 my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid); 1643 1644 # This now stores the full pathname 1645 $import_filename = $doc_rec->{'src-file'}->[0]; 1646 } 1647 else { 1648 $import_filename = &util::filename_cat($collect_dir,$collect,$import_file); 1649 } 1650 1651 # figure out correct metadata.xml file [?] 1652 # Assuming the metadata.xml file is next to the source file 1653 # Note: This will not work if it is using the inherited metadata from the parent folder 1654 my ($import_tailname, $import_dirname) = File::Basename::fileparse($import_filename); 1655 my $metadata_xml_filename = &util::filename_cat($import_dirname,"metadata.xml"); 1656 1657 # Edit the metadata.xml 1658 # Modified by Jeffrey from DL Consulting 1659 # Handle the case where there is one metadata.xml file for multiple FileSets 1660 # The XML filter needs to know whether it is in the right FileSet 1661 # TODO: This doesn't fix the problem where the metadata.xml is not next to the src file. 1662 # TODO: This doesn't handle the common metadata (where FileName doesn't point to a single file) 1663 $self->edit_metadata_xml($gsdl_cgi, $metadata_xml_filename, 1664 $metaname, $metavalue, $metamode, $import_tailname); 1831 1832 $self->_set_import_metadata(@_); 1665 1833 1666 1834 # Release the lock once it is done 1667 1835 $self->unlock_collection($username, $collect); 1668 1669 my $mess = "set-import-metadata successful: Key[$docid] -> $metadata_xml_filename\n";1670 $mess .= " $metaname";1671 $mess .= " = $metavalue";1672 $mess .= " ($metamode)\n";1673 1674 $gsdl_cgi->generate_ok_message($mess);1675 1836 1676 1837 } … … 1754 1915 } 1755 1916 1756 sub remove_import_metadata1917 sub _remove_import_metadata 1757 1918 { 1758 1919 my $self = shift @_; 1759 1760 my $username = $self->{'username'}; 1920 1761 1921 my $collect = $self->{'collect'}; 1762 1922 my $gsdl_cgi = $self->{'gsdl_cgi'}; 1763 1764 if ($baseaction::authentication_enabled) {1765 # Ensure the user is allowed to edit this collection1766 &authenticate_user($gsdl_cgi, $username, $collect);1767 }1768 1769 1923 my $gsdlhome = $self->{'gsdlhome'}; 1770 1924 my $infodbtype = $self->{'infodbtype'}; … … 1777 1931 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 1778 1932 my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives"); 1779 1780 # Make sure the collection isn't locked by someone else 1781 $self->lock_collection($username, $collect); 1782 1933 1783 1934 # look up additional args 1784 1935 my $docid = $self->{'d'}; … … 1818 1969 $self->remove_from_metadata_xml($gsdl_cgi, $metadata_xml_filename, $metaname, $metavalue, $import_tailname); 1819 1970 1820 # Release the lock once it is done1821 $self->unlock_collection($username, $collect);1822 1823 1971 my $mess = "remove-import-metadata successful: Key[$docid] -> $metadata_xml_filename\n"; 1824 1972 $mess .= " $metaname"; … … 1826 1974 1827 1975 $gsdl_cgi->generate_ok_message($mess); 1976 1977 #return $status; # in case calling functions have a use for this 1978 } 1979 1980 sub remove_import_metadata 1981 { 1982 my $self = shift @_; 1983 1984 my $username = $self->{'username'}; 1985 my $collect = $self->{'collect'}; 1986 my $gsdl_cgi = $self->{'gsdl_cgi'}; 1987 1988 if ($baseaction::authentication_enabled) { 1989 # Ensure the user is allowed to edit this collection 1990 &authenticate_user($gsdl_cgi, $username, $collect); 1991 } 1992 1993 # Make sure the collection isn't locked by someone else 1994 $self->lock_collection($username, $collect); 1995 1996 $self->_remove_import_metadata(@_); 1997 1998 # Release the lock once it is done 1999 $self->unlock_collection($username, $collect); 2000 1828 2001 } 1829 2002 … … 1890 2063 } 1891 2064 1892 sub remove_live_metadata2065 sub _remove_live_metadata 1893 2066 { 1894 2067 my $self = shift @_; 1895 2068 1896 my $username = $self->{'username'};1897 2069 my $collect = $self->{'collect'}; 1898 2070 my $gsdl_cgi = $self->{'gsdl_cgi'}; 1899 my $gsdlhome = $self->{'gsdlhome'};2071 # my $gsdlhome = $self->{'gsdlhome'}; 1900 2072 my $infodbtype = $self->{'infodbtype'}; 1901 1902 if ($baseaction::authentication_enabled) {1903 # Ensure the user is allowed to edit this collection1904 &authenticate_user($gsdl_cgi, $username, $collect);1905 }1906 2073 1907 2074 # Obtain the collect dir 1908 2075 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 1909 my $site = $self->{'site'}; 1910 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 1911 1912 # Make sure the collection isn't locked by someone else 1913 $self->lock_collection($username, $collect); 1914 2076 my $site = $self->{'site'}; 2077 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 2078 2079 1915 2080 # look up additional args 1916 2081 my $docid = $self->{'d'}; … … 1948 2113 } 1949 2114 1950 # Release the lock once it is done 1951 $self->unlock_collection($username, $collect); 1952 } 1953 1954 1955 sub remove_metadata 2115 } 2116 2117 sub remove_live_metadata 1956 2118 { 1957 2119 my $self = shift @_; … … 1961 2123 my $gsdl_cgi = $self->{'gsdl_cgi'}; 1962 2124 my $gsdlhome = $self->{'gsdlhome'}; 1963 my $infodbtype = $self->{'infodbtype'};1964 2125 1965 2126 if ($baseaction::authentication_enabled) { … … 1968 2129 } 1969 2130 1970 # Obtain the collect dir1971 my $site = $self->{'site'};1972 my $collect_dir = $gsdl_cgi->get_collection_dir($site);1973 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect");1974 1975 2131 # Make sure the collection isn't locked by someone else 1976 2132 $self->lock_collection($username, $collect); 1977 2133 1978 # look up additional args 2134 $self->_remove_live_metadata(@_); 2135 2136 $self->unlock_collection($username, $collect); 2137 } 2138 2139 sub remove_metadata 2140 { 2141 my $self = shift @_; 2142 2143 my $where = $self->{'where'}; 2144 if(!$where) { 2145 $self->remove_index_metadata(@_); # call the full version of set_index_meta for the default behaviour 2146 return; 2147 } 2148 2149 my $username = $self->{'username'}; 2150 my $collect = $self->{'collect'}; 2151 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2152 2153 if ($baseaction::authentication_enabled) { 2154 # Ensure the user is allowed to edit this collection 2155 &authenticate_user($gsdl_cgi, $username, $collect); 2156 } 2157 2158 # Make sure the collection isn't locked by someone else 2159 $self->lock_collection($username, $collect); 2160 2161 # check which directories need to be processed, specified in $where as 2162 # any combination of import|archives|index|live 2163 if($where =~ m/import/) { 2164 $self->_remove_import_metadata(@_); 2165 } 2166 if($where =~ m/archives/) { 2167 $self->_remove_archives_metadata(@_); 2168 } 2169 if($where =~ m/index/) { 2170 $self->_remove_index_metadata(@_); 2171 } 2172 2173 # Release the lock once it is done 2174 $self->unlock_collection($username, $collect); 2175 } 2176 2177 # the internal version, without authentication 2178 sub _remove_index_metadata 2179 { 2180 my $self = shift @_; 2181 2182 my $collect = $self->{'collect'}; 2183 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2184 # my $gsdlhome = $self->{'gsdlhome'}; 2185 my $infodbtype = $self->{'infodbtype'}; 2186 2187 # Obtain the collect dir 2188 my $site = $self->{'site'}; 2189 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 2190 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 2191 2192 # look up additional args 1979 2193 my $docid = $self->{'d'}; 1980 2194 if ((!defined $docid) || ($docid =~ m/^\s*$/)) { … … 2062 2276 $gsdl_cgi->generate_ok_message($mess); 2063 2277 } 2278 2279 #return $status; # in case calling functions have a use for this 2280 } 2281 2282 sub remove_index_metadata 2283 { 2284 my $self = shift @_; 2285 2286 my $username = $self->{'username'}; 2287 my $collect = $self->{'collect'}; 2288 my $gsdl_cgi = $self->{'gsdl_cgi'}; 2289 # my $gsdlhome = $self->{'gsdlhome'}; 2290 2291 if ($baseaction::authentication_enabled) { 2292 # Ensure the user is allowed to edit this collection 2293 &authenticate_user($gsdl_cgi, $username, $collect); 2294 } 2295 2296 # Obtain the collect dir 2297 my $site = $self->{'site'}; 2298 my $collect_dir = $gsdl_cgi->get_collection_dir($site); 2299 ## my $collect_dir = &util::filename_cat($gsdlhome, "collect"); 2300 2301 # Make sure the collection isn't locked by someone else 2302 $self->lock_collection($username, $collect); 2303 2304 $self->_remove_index_metadata(@_); 2064 2305 2065 2306 # Release the lock once it is done
Note:
See TracChangeset
for help on using the changeset viewer.