EPrints Technical Mailing List Archive

Message: #03324


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] Re: Datestamp of documents?


Am 22.07.2014 14:21, schrieb Sebastien Francois:
Hiya,

Try to get the File objects (if you're on 3.3+) and get the mtime field
value (i think that's its lastmod)?


Hi seb,

thank you :-), I tried that in EPrints 3.3.10 and %files turns out empty in the following code. Beside of that, did I overlook some $doc->files method counterpart to get the associated file objects instead of just the sizes? Without that, it's hard to retrieve the files:

sub is_archive_needed {
    my ($eprint, @documents) = @_;

    return 0 if @documents < 2;
    return 1 if $eprint->value("datestamp") =~ m{ \A [ 0:-] \z }xms;

    my $ds = $eprint->{session}->dataset("file");

    my %files = map { $_->value("filename") => $_ } $ds->search(
        filters => [{
            meta_fields => [qw(objectid)],
            value => join(" ", map { $_->value("docid") } @documents),
            match => "IN",
        }, { meta_fields => [ 'datasetid' ], value => "document" }],
    )->slice;

    my $latestDate_doc_commit
        = maxstr '0000-00-00 00:00:00',
                 map { $files{ $_->get_main }->value("mtime") }
                     @documents
        ;

    return $eprint->value("lastmod") lt $latestDate_doc_commit;
}

Called is_needed_archive with the eprint and the list of 10 public documents.


Regards
Florian


Alternatively, "stat" the file on-disk?

Seb.

On 22/07/14 13:15, Florian Heß wrote:
Hi,

the code in cfg.d/eprint_fields_automatic.pl is executed on commit of an
eprint. We are obliged to create an archive file of documents of a
multi-doc eprint. I assume that the tarball would be rewritten every
once in a while (e.g. regeneration of thumbnails), which would take a
long time for large files. Hence I want to tar them only when either of
the two following conditions are true:

     * the eprint is put in the live area for the first time
     * documents have been changed (i.e. fresh upload)

My function is_archive_needed(), provided in a custom module I `use` in
eprint_fields_automatic.pl reads like:

use List::Util qw(
sub is_archive_needed {
       my ($eprint, @documents) = @_;

       return 0 if @documents < 2;
       return 1 if $eprint->value("datestamp") =~ m{ \A [ 0:-] \z }xms;

       my $latestDate_doc_commit
           = maxstr map { $_->value("lastmod") } @documents;

       return $eprint->value("lastmod") < $latestDate_doc_commit;
}

My problem is that there is no lastmod date for document records, there
is one for the associated eprint only. So is there any other way to test
the second condition or am I to define a custom lastmod field for that
dataset?



Kind regards
Florian


*** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech
*** Archive: http://www.eprints.org/tech.php/
*** EPrints community wiki: http://wiki.eprints.org/
*** EPrints developers Forum: http://forum.eprints.org/



--
UB Heidelberg (Altstadt)
Plöck 107-109, 69117 HD
Abt. Informationstechnik
http://www.ub.uni-heidelberg.de/