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

(-)a/Koha/SimpleMARC.pm (-9 / +40 lines)
Lines 18-38 package Koha::SimpleMARC; Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use constant LAST_TRANSACTION_FIELD => q/005/;    # MARC21/UNIMARC
22
21
our (@ISA, @EXPORT_OK);
23
our (@ISA, @EXPORT_OK);
22
BEGIN {
24
BEGIN {
23
    require Exporter;
25
    require Exporter;
24
    our @ISA = qw(Exporter);
26
    our @ISA = qw(Exporter);
25
27
26
    @EXPORT_OK = qw(
28
    @EXPORT_OK = qw(
27
      read_field
29
        read_field
28
      add_field
30
        add_field
29
      update_field
31
        update_field
30
      copy_field
32
        copy_field
31
      copy_and_replace_field
33
        copy_and_replace_field
32
      move_field
34
        move_field
33
      delete_field
35
        delete_field
34
      field_exists
36
        field_exists
35
      field_equals
37
        field_equals
38
        update_last_transaction_time
36
    );
39
    );
37
}
40
}
38
41
Lines 525-530 sub delete_field { Link Here
525
    }
528
    }
526
}
529
}
527
530
531
=head3 update_last_transaction_time
532
533
  update_last_transaction_time( { record => $record } );
534
535
  Inserts or updates field for last transaction (005)
536
537
=cut
538
539
sub update_last_transaction_time {
540
    my ($params) = @_;
541
    my $record = $params->{record};
542
543
    my @localtime = (localtime)[ 5, 4, 3, 2, 1, 0 ];
544
    $localtime[0] += 1900;    # add century
545
    $localtime[1]++;          # month 1-based
546
547
    my $value = sprintf( "%4d%02d%02d%02d%02d%04.1f", @localtime );
548
    my $field;
549
    if ( $field = $record->field(LAST_TRANSACTION_FIELD) ) {
550
        $field->update($value);
551
    } else {
552
        $record->insert_fields_ordered(
553
            MARC::Field->new( LAST_TRANSACTION_FIELD, $value ),
554
        );
555
    }
556
}
557
528
sub _delete_field {
558
sub _delete_field {
529
    my ( $params ) = @_;
559
    my ( $params ) = @_;
530
    my $record = $params->{record};
560
    my $record = $params->{record};
Lines 663-667 sub _modify_values { Link Here
663
    }
693
    }
664
    return @$values;
694
    return @$values;
665
}
695
}
696
666
1;
697
1;
667
__END__
698
__END__
(-)a/t/SimpleMARC.t (-3 / +18 lines)
Lines 2-12 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
4
5
use Test::More tests => 11;
5
use Test::More tests => 12;
6
6
7
use_ok("MARC::Field");
7
use_ok("MARC::Field");
8
use_ok("MARC::Record");
8
use_ok("MARC::Record");
9
use_ok("Koha::SimpleMARC", qw( field_exists read_field update_field copy_field copy_and_replace_field move_field delete_field field_equals ));
9
use_ok(
10
    "Koha::SimpleMARC",
11
    qw( field_exists read_field update_field copy_field copy_and_replace_field move_field delete_field field_equals update_last_transaction_time )
12
);
10
13
11
sub new_record {
14
sub new_record {
12
    my $record = MARC::Record->new;
15
    my $record = MARC::Record->new;
Lines 1833-1835 subtest 'field_equals' => sub { Link Here
1833
        is_deeply( $match, [1], 'first 008 control field matches "eng"' );
1836
        is_deeply( $match, [1], 'first 008 control field matches "eng"' );
1834
    };
1837
    };
1835
};
1838
};
1836
- 
1839
1840
subtest 'update_last_transaction_time' => sub {
1841
    plan tests => 3;
1842
    my $record = MARC::Record->new;
1843
    update_last_transaction_time( { record => $record } );
1844
    my $value1 = $record->field('005')->data;
1845
    like( $value1, qr/^\d{14}\.0$/, 'Looks like a 005' );
1846
    sleep 1;
1847
    update_last_transaction_time( { record => $record } );
1848
    my $value2 = $record->field('005')->data;
1849
    like( $value2, qr/^\d{14}\.0$/, 'Still looks like a 005' );
1850
    isnt( $value1, $value2, 'Should not be the same a second later' );
1851
};

Return to bug 35993