Changeset 31216 for main/trunk/greenstone2/perllib
- Timestamp:
- 2016-12-12T17:45:45+13:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/oaiinfo.pm
r31208 r31216 4 4 use constant INFO_STATUS_INDEX => 0; 5 5 use constant INFO_TIMESTAMP_INDEX => 1; 6 use constant INFO_DATESTAMP_INDEX => 2; 6 7 7 8 use strict; … … 10 11 use dbutil; 11 12 12 # QUESTIONS:13 # Should we use time or localtime(time) for timestamp? Just timestamp.14 # What format should the timestamp be in, or is the basic format used by perl sufficient? Basic.15 16 # File format read in: OID <tab> Date-timestamp <tab> Deletion-Status13 # Store timestamp in 2 formats: internal and external (same as oailastmodified and oailastmodifieddate) 14 # These times indicate the last modified date for that document. In the case of the doc being deleted, 15 # it's the time the doc was deleted. 16 17 # File format read in: OID <tab> (Deletion-)Status <tab> Timestamp <tab> Datestamp 17 18 18 19 # Deletion status can be: 19 20 # E = Doc with OID exists (has not been deleted from collection). Timestamp indicates last time of build 20 21 # D = Doc with OID has been deleted. Timestamp indicates time of deletion 21 # PD = Provisionally Deleted. T imestampmomentarily unaltered.22 # PD = Provisionally Deleted. The associated timestamps are momentarily unaltered. 22 23 23 24 # oaidb is "always incremental": always reflects the I/B/R/D status of archive info db, … … 30 31 31 32 my $self = { 32 'info'=>{} # map of {OID, array[deletion-status,timestamp ]} pairs33 'info'=>{} # map of {OID, array[deletion-status,timestamp,datestamp]} pairs 33 34 }; 34 35 … … 343 344 print STDERR " status: " . $self->{'info'}->{$OID}->[INFO_STATUS_INDEX]; 344 345 print STDERR " time: " . $self->{'info'}->{$OID}->[INFO_TIMESTAMP_INDEX]; 346 print STDERR " date: " . $self->{'info'}->{$OID}->[INFO_DATESTAMP_INDEX]; 345 347 print STDERR "\n"; 346 348 } … … 401 403 # the following method will set to current time if no timestamp provided, 402 404 # But by explicit here, the code is easier to follow 403 $self->set_info($OID, "D", $self->get_current_time()); 405 $self->set_info($OID, "D", $self->get_current_time()); 404 406 405 407 } … … 413 415 # return localtime; # same as localtime(time); # http://perldoc.perl.org/functions/localtime.html 414 416 417 } 418 419 sub get_datestamp { 420 my $self = shift (@_); 421 my ($timestamp) = @_; 422 423 my ($seconds, $minutes, $hours, $day_of_month, $month, $year, 424 $wday, $yday, $isdst) = localtime($timestamp); 425 426 my $datestamp = sprintf("%d%02d%02d",1900+$year,$month+1,$day_of_month); 427 428 return $datestamp; 415 429 } 416 430 … … 452 466 my ($deletion_status) = ($vals=~/^<status>(.*)$/m); 453 467 my ($timestamp) = ($vals=~/^<timestamp>(.*)$/m); 454 455 $self->set_info ($oid, $deletion_status, $timestamp); 468 my ($datestamp) = ($vals=~/^<datestamp>(.*)$/m); 469 470 $self->add_info ($oid, $deletion_status, $timestamp, $datestamp); 456 471 } 457 472 } … … 509 524 foreach my $oid ( keys $self->{'info'} ) { 510 525 my $OID_info = $self->{'info'}->{$oid}; 511 my $val = "<status>".$OID_info->[INFO_STATUS_INDEX]."\n<timestamp>".$OID_info->[INFO_TIMESTAMP_INDEX]."\n"; 526 my $val = "<status>".$OID_info->[INFO_STATUS_INDEX]; 527 $val .= "\n<timestamp>".$OID_info->[INFO_TIMESTAMP_INDEX]; 528 $val .= "\n<datestamp>".$OID_info->[INFO_DATESTAMP_INDEX]."\n"; 512 529 &dbutil::write_infodb_rawentry($infodbtype,$infodb_handle,$oid,$val); 513 530 } … … 535 552 my $self = shift (@_); 536 553 my ($OID, $del_status, $timestamp) = @_; 554 537 555 if(!defined $timestamp) { # get current date timestamp 538 556 $timestamp = $self->get_current_time(); 539 557 } 540 $self->{'info'}->{$OID} = [$del_status, $timestamp]; 541 542 } 543 544 545 # returns a list of the form [[OID, timestamp, deletion_status], ...] 558 my $datestamp = $self->get_datestamp($timestamp); 559 560 $self->{'info'}->{$OID} = [$del_status, $timestamp, $datestamp]; 561 562 } 563 564 sub add_info { # called to load a single record from file into memory, so it should be provided all 4 fields 565 my $self = shift (@_); 566 my ($OID, $del_status, $timestamp, $datestamp) = @_; 567 568 $self->{'info'}->{$OID} = [$del_status, $timestamp, $datestamp]; 569 } 570 571 572 # returns a list of the form [[OID, deletion_status, timestamp, datestamp], ...] 546 573 sub get_OID_list 547 574 { … … 554 581 555 582 push (@list, [$OID, $OID_info->[INFO_STATUS_INDEX], 556 $OID_info->[INFO_TIMESTAMP_INDEX]]); 583 $OID_info->[INFO_TIMESTAMP_INDEX], 584 $OID_info->[INFO_DATESTAMP_INDEX] 585 ]); 557 586 } 558 587
Note:
See TracChangeset
for help on using the changeset viewer.