Ignore:
Timestamp:
2016-12-12T17:45:45+13:00 (7 years ago)
Author:
ak19
Message:

Adding a datestamp field to the new oai-inf.db. Now the timestamp and datestamp fields of oai-inf parallel the oailastmodified (timestamp) and oailastmodifieddate fields of the regular index db.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/oaiinfo.pm

    r31208 r31216  
    44use constant INFO_STATUS_INDEX  => 0;
    55use constant INFO_TIMESTAMP_INDEX => 1;
     6use constant INFO_DATESTAMP_INDEX => 2;
    67
    78use strict;
     
    1011use dbutil;
    1112
    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-Status
     13# 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
    1718
    1819# Deletion status can be:
    1920#  E = Doc with OID exists (has not been deleted from collection). Timestamp indicates last time of build
    2021#  D = Doc with OID has been deleted. Timestamp indicates time of deletion
    21 #  PD = Provisionally Deleted. Timestamp momentarily unaltered.
     22#  PD = Provisionally Deleted. The associated timestamps are momentarily unaltered.
    2223
    2324# oaidb is "always incremental": always reflects the I/B/R/D status of archive info db,
     
    3031 
    3132    my $self = {
    32     'info'=>{} # map of {OID, array[deletion-status,timestamp]} pairs
     33    'info'=>{} # map of {OID, array[deletion-status,timestamp,datestamp]} pairs
    3334    };
    3435   
     
    343344    print STDERR " status: " . $self->{'info'}->{$OID}->[INFO_STATUS_INDEX];
    344345    print STDERR " time: " . $self->{'info'}->{$OID}->[INFO_TIMESTAMP_INDEX];
     346    print STDERR " date: " . $self->{'info'}->{$OID}->[INFO_DATESTAMP_INDEX];
    345347    print STDERR "\n";
    346348    }
     
    401403    # the following method will set to current time if no timestamp provided,
    402404    # 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());
    404406
    405407}
     
    413415    # return localtime; # same as localtime(time); # http://perldoc.perl.org/functions/localtime.html
    414416   
     417}
     418
     419sub 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;
    415429}
    416430
     
    452466    my ($deletion_status) = ($vals=~/^<status>(.*)$/m);
    453467    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);
    456471    }
    457472}
     
    509524    foreach my $oid ( keys $self->{'info'} ) {
    510525    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";
    512529    &dbutil::write_infodb_rawentry($infodbtype,$infodb_handle,$oid,$val);
    513530    }
     
    535552    my $self = shift (@_);
    536553    my ($OID, $del_status, $timestamp) = @_;
     554
    537555    if(!defined $timestamp) { # get current date timestamp
    538556    $timestamp = $self->get_current_time();
    539557    }
    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
     564sub 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], ...]
    546573sub get_OID_list
    547574{
     
    554581
    555582    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          ]);
    557586    }
    558587
Note: See TracChangeset for help on using the changeset viewer.