Changeset 37215 for main


Ignore:
Timestamp:
2023-01-30T14:10:43+13:00 (15 months ago)
Author:
davidb
Message:

Introduction of new set-archives-assocfile action (data needs to be POSTed); some tidy up on get-arhives-assocfile

Location:
main/trunk/greenstone2/perllib/cgiactions
Files:
2 edited

Legend:

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

    r37214 r37215  
    5959
    6060    if(!defined $ENV{'GSDL3HOME'} || (defined $ENV{'GS3_AUTHENTICATED'} && $ENV{'GS3_AUTHENTICATED'} eq "true")) {
    61     require modmetadataaction;
     61        require modmetadataaction;
    6262    }
    6363    else {
    64     $modmeta_action_table = {};
     64        $modmeta_action_table = {};
    6565    }
    6666}
     
    8888        'optional-args'   => [ "dv", "metapos" ] },
    8989
    90     "get-archives-assocfiles" => {
     90    "get-archives-assocfile" => {
    9191        'compulsory-args' => [ "d", "assocname" ],
    9292        'optional-args'   => [ "dv" ] },
     
    123123    my $class = shift (@_);
    124124    my ($gsdl_cgi,$iis6_mode) = @_;
    125 
     125   
    126126    # Treat metavalue specially.  To transmit this through a GET request
    127127    # the Javascript side has url-encoded it, so here we need to decode
     
    149149
    150150    my $self = new baseaction($action_table,$gsdl_cgi,$iis6_mode);
    151 
     151   
    152152    return bless $self, $class;
    153153}
     
    973973}
    974974
    975 sub get_archives_assocfiles
     975sub get_archives_assocfile
    976976{
    977977    my $self = shift @_;
     
    10011001    my $dv = $self->{'dv'};
    10021002    if (defined $dv && ($dv ne "")) {
    1003         # Need to insert '_fldv_history/nminus-<n>' into doc_filename
     1003        # Need to insert '_fldv_history/nminus-<n>' into doc_file
    10041004       
    10051005        my ($doc_tailname, $doc_dirname) = File::Basename::fileparse($doc_file);
     
    10131013    # get the job done, but is not very efficient
    10141014    # => candidate for refactoring
    1015    
    1016     my $json_result_str .= "[";
    10171015   
    10181016
     
    10421040
    10431041        if (defined $dv && ($dv ne "")) {
    1044         # Need to insert '_fldv_history/nminus-<n>' into doc_filename
     1042        # Need to insert '_fldv_history/nminus-<n>' into found_file
    10451043
    10461044        $found_file = &util::filename_cat($doc_dirname,$FLDV_HISTORY_DIR,$dv,$found_file);
  • main/trunk/greenstone2/perllib/cgiactions/modmetadataaction.pm

    r37207 r37215  
    6969    # Should there not be a "set-archives-text" also ???!!!!??
    7070    ###### !!!!!
     71
     72    "set-archives-assocfile" => {
     73        'compulsory-args' => [ "d", "assocname", 'fileupload' ],
     74        'optional-args'   => [ "dv" ] ,
     75        'help-string'     => [ "Because this action uploads a file, this action needs to be POSTed. The 'fileupload' parameter/field is the uploaded file content; 'assocname' specifies the filename within the archives's document's area that it will be saved as" ]
     76    },
    7177       
    7278    "set-import-metadata" => {
     
    13231329}
    13241330
     1331
     1332
     1333# the version of set_archives_meta that doesn't do authentication
     1334sub _set_archives_assocfile
     1335{
     1336    my $self = shift @_;
     1337
     1338    my $collect   = $self->{'collect'};
     1339    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     1340    my $infodbtype = $self->{'infodbtype'};
     1341
     1342    # Obtain the collect and archive dir   
     1343    my $site = $self->{'site'};
     1344    my $collect_dir = $gsdl_cgi->get_collection_dir($site);
     1345    my $archive_dir = &util::filename_cat($collect_dir,$collect,"archives");
     1346
     1347    # look up additional args
     1348    my $docid  = $self->{'d'};
     1349
     1350    my $assocname = $self->{'assocname'};
     1351
     1352    my $arcinfo_doc_filename = &dbutil::get_infodb_file_path($infodbtype, "archiveinf-doc", $archive_dir);
     1353    my $doc_rec = &dbutil::read_infodb_entry($infodbtype, $arcinfo_doc_filename, $docid);
     1354   
     1355    my $doc_file = $doc_rec->{'doc-file'}->[0];
     1356   
     1357    # check if request if for file-level doc-version history 'nminus-<n>' version
     1358    my $dv = $self->{'dv'};
     1359   
     1360    my ($unused_tailname, $doc_dirname) = File::Basename::fileparse($doc_file);
     1361
     1362    my $output_file = $assocname;
     1363   
     1364    if (defined $dv && ($dv ne "")) {
     1365    # Need to insert '_fldv_history/nminus-<n>' into output_file
     1366   
     1367    $output_file = &util::filename_cat($doc_dirname,$FLDV_HISTORY_DIR,$dv,$output_file);
     1368    }
     1369    else {
     1370    $output_file = &util::filename_cat($doc_dirname,$output_file);
     1371    }
     1372   
     1373    my $output_filename = &util::filename_cat($archive_dir, $output_file);
     1374   
     1375    my $FIN = $self->{'fileupload'};
     1376    if (open(FOUT,">$output_filename")) {
     1377
     1378    binmode(FOUT, ":raw");
     1379
     1380    while (1) {
     1381        my $buffer = "";
     1382        my $bytes_read = read($FIN, $buffer, 1024);
     1383
     1384        if (defined $bytes_read) {
     1385        if ($bytes_read>0) {
     1386            print FOUT $buffer;
     1387        }
     1388        last if $bytes_read < 1024;
     1389        }
     1390        else {
     1391        my $mess = "set-archives-assocfile: Failed to open uploaded file for reading: $!\n";
     1392        print STDERR "Error - $mess";
     1393        $gsdl_cgi->generate_error($mess);
     1394        last;
     1395        }
     1396    }
     1397
     1398    close($FIN);   
     1399    close(FOUT);   
     1400
     1401    my $mess = "set-archives-assocfile successful save uploaded content into 'archives' as: $output_file\n";
     1402    $gsdl_cgi->generate_ok_message($mess);
     1403
     1404    }
     1405    else {
     1406    my $mess = "Failed to save file: $output_filename";
     1407    print STDERR "Error - $mess:\n$!\n";
     1408    $gsdl_cgi->generate_error($mess);
     1409    }       
     1410}
     1411
     1412
     1413sub set_archives_assocfile
     1414{
     1415    my $self = shift @_;
     1416
     1417    my $username  = $self->{'username'};
     1418    my $collect   = $self->{'collect'};
     1419    my $gsdl_cgi  = $self->{'gsdl_cgi'};
     1420
     1421    if ($baseaction::authentication_enabled) {
     1422    # Ensure the user is allowed to edit this collection
     1423    $self->authenticate_user($username, $collect);
     1424    }
     1425
     1426
     1427    # Make sure the collection isn't locked by someone else
     1428    $self->lock_collection($username, $collect);
     1429
     1430    $self->_set_archives_assocfile(@_);
     1431
     1432    # Release the lock once it is done
     1433    $self->unlock_collection($username, $collect);
     1434}
     1435
     1436
    13251437sub _remove_archives_metadata
    13261438{
Note: See TracChangeset for help on using the changeset viewer.