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

(-)a/misc/cronjobs/newly_added_records.pl (-1 / +101 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2012 Catalyst IT
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# version.
11
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
# This is script is to create a batch of MARC records that have been added to Koha in a set period
21
# Then email the file to a designated email
22
23
use strict;
24
use warnings;
25
use DateTime;
26
use C4::RecordExporter;
27
28
BEGIN {
29
30
    # find Koha's Perl modules
31
    # test carefully before changing this
32
    use FindBin;
33
    eval { require "$FindBin::Bin/../kohalib.pl" };
34
}
35
36
use Getopt::Long;
37
use Pod::Usage;
38
39
my (
40
    $help,    $days,     $months,     $verbose, $export_items,
41
    @address, $not_loan, @not_itypes, $format,  $filename,
42
);
43
GetOptions(
44
    'help|?'      => \$help,
45
    'days=s'      => \$days,
46
    'months=s'    => \$months,
47
    'v'           => \$verbose,
48
    'items'       => \$export_items,
49
    'address=s'   => \@address,
50
    'not_loan=s'  => \$not_loan,
51
    'not_itype=s' => \@not_itypes,
52
    'format=s'    => \$format,
53
    'filename=s'  => \$filename,
54
);
55
56
if ( $help or ( not $days and not $months ) or not @address or not $format ) {
57
    print <<EOF
58
This script creates an emails a batch of marc records that have been added to
59
Koha in a set period of time
60
    Parameters:
61
    --help|-?       This message
62
    -v              Verbose, output biblionumbers of records that can't be parsed
63
    --items         Export item data also
64
    --days TTT      to define the age of marc records to export
65
    --months TTT    to define the age of marc records to export eg -months 1
66
                    will export any created in the last calendar month
67
    --address TTT   to define the email address to send the file to. Can
68
                    be repeated.
69
    --not_loan TTT  to define the not for loan value to exclude from the
70
                    export (useful for on-order records)
71
    --not_itypes    to define the itemtypes to exclude from the outputted
72
                    records. Can be repeated.
73
    --format        'marc': output the whole record as MARC, 'isbn': just
74
                    output text ISBN values.
75
    --filename      the filename (including extension) of the attachment.
76
                    May include %month% which is replaced with the current
77
                    month.
78
     example :
79
     export PERL5LIB=/path/to/koha;export KOHA_CONF=/etc/koha/koha-conf.xml;./newly_added_records --days 30 --address chrisc\@catalyst.net.nz --format marc
80
     export PERL5LIB=/path/to/koha;export KOHA_CONF=/etc/koha/koha-conf.xml;./newly_added_records --days 30 --not_loan -1 --not_itype BK --not_itype CF --address chrisc\@catalyst.net.nz --format isbn
81
82
EOF
83
      ;
84
    exit;
85
}
86
87
$filename = $filename || 'Koha.' . ( $format eq 'isbn' ? 'csv' : 'mrc' );
88
my $month = lc( DateTime->now()->month_name() );
89
$filename =~ s/%month%/$month/g;
90
91
my $date = DateTime->now();
92
if ($days) {
93
    $date->subtract( days => $days );
94
}
95
elsif ($months) {
96
    $date->set_day(1);
97
    $date->subtract( months => $months );
98
}
99
100
export_and_mail_new( $date, \@address, $verbose, $export_items, $not_loan,
101
    $format, $filename, @not_itypes );

Return to bug 12919