Changeset 37215
- Timestamp:
- 2023-01-30T14:10:43+13:00 (8 months ago)
- Location:
- main/trunk/greenstone2/perllib/cgiactions
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cgiactions/metadataaction.pm
r37214 r37215 59 59 60 60 if(!defined $ENV{'GSDL3HOME'} || (defined $ENV{'GS3_AUTHENTICATED'} && $ENV{'GS3_AUTHENTICATED'} eq "true")) { 61 require modmetadataaction;61 require modmetadataaction; 62 62 } 63 63 else { 64 $modmeta_action_table = {};64 $modmeta_action_table = {}; 65 65 } 66 66 } … … 88 88 'optional-args' => [ "dv", "metapos" ] }, 89 89 90 "get-archives-assocfile s" => {90 "get-archives-assocfile" => { 91 91 'compulsory-args' => [ "d", "assocname" ], 92 92 'optional-args' => [ "dv" ] }, … … 123 123 my $class = shift (@_); 124 124 my ($gsdl_cgi,$iis6_mode) = @_; 125 125 126 126 # Treat metavalue specially. To transmit this through a GET request 127 127 # the Javascript side has url-encoded it, so here we need to decode … … 149 149 150 150 my $self = new baseaction($action_table,$gsdl_cgi,$iis6_mode); 151 151 152 152 return bless $self, $class; 153 153 } … … 973 973 } 974 974 975 sub get_archives_assocfile s975 sub get_archives_assocfile 976 976 { 977 977 my $self = shift @_; … … 1001 1001 my $dv = $self->{'dv'}; 1002 1002 if (defined $dv && ($dv ne "")) { 1003 # Need to insert '_fldv_history/nminus-<n>' into doc_file name1003 # Need to insert '_fldv_history/nminus-<n>' into doc_file 1004 1004 1005 1005 my ($doc_tailname, $doc_dirname) = File::Basename::fileparse($doc_file); … … 1013 1013 # get the job done, but is not very efficient 1014 1014 # => candidate for refactoring 1015 1016 my $json_result_str .= "[";1017 1015 1018 1016 … … 1042 1040 1043 1041 if (defined $dv && ($dv ne "")) { 1044 # Need to insert '_fldv_history/nminus-<n>' into doc_filename1042 # Need to insert '_fldv_history/nminus-<n>' into found_file 1045 1043 1046 1044 $found_file = &util::filename_cat($doc_dirname,$FLDV_HISTORY_DIR,$dv,$found_file); -
main/trunk/greenstone2/perllib/cgiactions/modmetadataaction.pm
r37207 r37215 69 69 # Should there not be a "set-archives-text" also ???!!!!?? 70 70 ###### !!!!! 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 }, 71 77 72 78 "set-import-metadata" => { … … 1323 1329 } 1324 1330 1331 1332 1333 # the version of set_archives_meta that doesn't do authentication 1334 sub _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 1413 sub 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 1325 1437 sub _remove_archives_metadata 1326 1438 {
Note:
See TracChangeset
for help on using the changeset viewer.