View | Details | Raw Unified | Return to bug 35659
Collapse All | Expand All

(-)a/Koha/OAI/Client/Harvester.pm (-10 / +8 lines)
Lines 30-38 Koha::OAI::Client::Harvester contains OAI-PMH harvester main functions Link Here
30
use utf8;
30
use utf8;
31
use open qw( :std :utf8 );
31
use open qw( :std :utf8 );
32
32
33
use C4::Biblio qw( AddBiblio GetFrameworkCode ModBiblio DelBiblio );
33
use C4::Biblio          qw( AddBiblio GetFrameworkCode ModBiblio DelBiblio );
34
use C4::AuthoritiesMarc qw (AddAuthority GuessAuthTypeCode ModAuthority DelAuthority );
34
use C4::AuthoritiesMarc qw (AddAuthority GuessAuthTypeCode ModAuthority DelAuthority );
35
use C4::Log qw( cronlogaction );
35
use C4::Log             qw( cronlogaction );
36
use HTTP::OAI;
36
use HTTP::OAI;
37
use HTTP::OAI::Metadata::OAI_DC;
37
use HTTP::OAI::Metadata::OAI_DC;
38
use Koha::DateUtils qw( dt_from_string );
38
use Koha::DateUtils qw( dt_from_string );
Lines 47-53 use MARC::Record; Link Here
47
use Modern::Perl;
47
use Modern::Perl;
48
use DateTime;
48
use DateTime;
49
use DateTime::Format::Strptime;
49
use DateTime::Format::Strptime;
50
use Try::Tiny qw( catch try );
50
use Try::Tiny  qw( catch try );
51
use Date::Calc qw(
51
use Date::Calc qw(
52
    Add_Delta_Days
52
    Add_Delta_Days
53
    Today
53
    Today
Lines 88-94 sub new { Link Here
88
    $verbose = $args->{'verbose'};
88
    $verbose = $args->{'verbose'};
89
    $days    = $args->{'days'};
89
    $days    = $args->{'days'};
90
    $force   = $args->{'force'};
90
    $force   = $args->{'force'};
91
    return $self;
91
    return bless $args, $self;
92
}
92
}
93
93
94
=head2 init
94
=head2 init
Lines 143-149 sub init { Link Here
143
    if ($days) {
143
    if ($days) {
144
144
145
        # Change this to yyyy-mm-dd
145
        # Change this to yyyy-mm-dd
146
        my $dt_today = dt_from_string();
147
        my ( $nowyear, $nowmonth, $nowday ) = Today();
146
        my ( $nowyear, $nowmonth, $nowday ) = Today();
148
        my @date     = Add_Delta_Days( $nowyear, $nowmonth, $nowday, -$days );
147
        my @date     = Add_Delta_Days( $nowyear, $nowmonth, $nowday, -$days );
149
        my $dt_start = DateTime->new( year => $date[0], month => $date[1], day => $date[2] );
148
        my $dt_start = DateTime->new( year => $date[0], month => $date[1], day => $date[2] );
Lines 296-305 sub processRecord { Link Here
296
                $status = 'deleted';
295
                $status = 'deleted';
297
            }
296
            }
298
        } else {
297
        } else {
299
            my $existing_dt = $strp->parse_datetime( $imported_record->datestamp );
298
            my $existing_dt = dt_from_string( $imported_record->datestamp, 'iso' );
300
            my $incoming_dt = $strp->parse_datetime( $oai_record->datestamp );
299
            my $incoming_dt = $oai_record->datestamp ? dt_from_string( $oai_record->datestamp, 'iso' ) : dt_from_string;
301
300
            if ( $force || $incoming_dt > $existing_dt ) {
302
            if ( $force || !$incoming_dt || !$existing_dt || $incoming_dt > $existing_dt ) {
303
                if ( $server->recordtype eq "biblio" ) {
301
                if ( $server->recordtype eq "biblio" ) {
304
                    my $biblionumber = $imported_record->biblionumber;
302
                    my $biblionumber = $imported_record->biblionumber;
305
                    my $result       = ModBiblio( $marcrecord, $biblionumber, GetFrameworkCode($biblionumber) );
303
                    my $result       = ModBiblio( $marcrecord, $biblionumber, GetFrameworkCode($biblionumber) );
Lines 311-317 sub processRecord { Link Here
311
                }
309
                }
312
                $imported_record->update(
310
                $imported_record->update(
313
                    {
311
                    {
314
                        datestamp => $imported_record->datestamp,
312
                        datestamp => $incoming_dt,
315
                    }
313
                    }
316
                );
314
                );
317
                $status = 'updated';
315
                $status = 'updated';
(-)a/misc/cronjobs/harvest_oai.pl (-1 / +1 lines)
Lines 25-31 use Getopt::Long qw( GetOptions ); Link Here
25
use Koha::Script -cron;
25
use Koha::Script -cron;
26
use Koha::OAI::Client::Harvester;
26
use Koha::OAI::Client::Harvester;
27
use Koha::OaiServers;
27
use Koha::OaiServers;
28
use C4::Log qw( cronlogaction );
28
use C4::Log   qw( cronlogaction );
29
use Try::Tiny qw( catch try );
29
use Try::Tiny qw( catch try );
30
30
31
my $command_line_options = join( " ", @ARGV );
31
my $command_line_options = join( " ", @ARGV );
(-)a/t/db_dependent/Koha/OAIHarvester.t (-3 / +23 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 5;
21
use Test::More tests => 9;
22
use Test::Exception;
22
use Test::Exception;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
Lines 53-65 my $record = Link Here
53
    '<metadata xmlns="http://www.openarchives.org/OAI/2.0/"><oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"><dc:title>Pièces diverses </dc:title><dc:identifier>ARCH/0320 [cote]</dc:identifier><dc:relation>FR-920509801 [RCR établissement]</dc:relation><dc:relation>Central obrera boliviana [Fonds ou collection]</dc:relation><dc:format>1 carton</dc:format><dc:date>1971/2000</dc:date><dc:type>Archives et manuscrits</dc:type></oai_dc:dc></metadata>';
53
    '<metadata xmlns="http://www.openarchives.org/OAI/2.0/"><oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd"><dc:title>Pièces diverses </dc:title><dc:identifier>ARCH/0320 [cote]</dc:identifier><dc:relation>FR-920509801 [RCR établissement]</dc:relation><dc:relation>Central obrera boliviana [Fonds ou collection]</dc:relation><dc:format>1 carton</dc:format><dc:date>1971/2000</dc:date><dc:type>Archives et manuscrits</dc:type></oai_dc:dc></metadata>';
54
54
55
my $r = HTTP::OAI::Record->new();
55
my $r = HTTP::OAI::Record->new();
56
$r->header->datestamp('2017-05-10T09:18:13Z');
57
$r->metadata( HTTP::OAI::Metadata->new( dom => $record ) );
56
$r->metadata( HTTP::OAI::Metadata->new( dom => $record ) );
58
57
59
my $status = $harvester->processRecord($r);
58
my $status = $harvester->processRecord($r);
60
is( $status, 'skipped', 'Record with no identifier is skipped' );
59
is( $status, 'skipped', 'Record with no identifier is skipped' );
61
60
62
$r->header->identifier('oai:myarchive.org:oid-233');
61
$r->header->identifier('oai:myarchive.org:oid-233');
62
$status = $harvester->processRecord($r);
63
is( $status, 'added', 'Record with no date is added' );
64
65
$status = $harvester->processRecord($r);
66
is( $status, 'updated', 'Record with no date is updated' );
67
68
$status = $harvester->processRecord($r);
69
is( $status, 'updated', 'Record with no date is updated even without force' );
70
71
$r->header->identifier('oai:myarchive.org:oid-234');
72
$r->header->datestamp('2017-05-10T09:18:13Z');
63
73
64
$status = $harvester->processRecord($r);
74
$status = $harvester->processRecord($r);
65
is( $status, 'added', 'Record is added' );
75
is( $status, 'added', 'Record is added' );
Lines 75-78 $r->header->datestamp('2018-05-10T09:18:13Z'); Link Here
75
$status = $harvester->processRecord($r);
85
$status = $harvester->processRecord($r);
76
is( $status, 'updated', 'When force is not used, record is updated if newer' );
86
is( $status, 'updated', 'When force is not used, record is updated if newer' );
77
87
88
my $imported_record = Koha::Import::Oaipmh::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } );
89
my $added_datestamp = $imported_record->datestamp;
90
$r->header->datestamp(undef);
91
$status          = $harvester->processRecord($r);
92
$imported_record = Koha::Import::Oaipmh::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } );
93
my $updated_datestamp = $imported_record->datestamp;
94
isnt(
95
    $added_datestamp, $updated_datestamp,
96
    'local datestamp is updated even if there is no datestamp in incoming record'
97
);
98
78
$schema->storage->txn_rollback;
99
$schema->storage->txn_rollback;
79
- 

Return to bug 35659