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

(-)a/misc/cronjobs/newly_deleted_records.pl (-1 / +94 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 ( $help, $days, $months, $verbose, $lost, @address, @not_itypes, $format, $filename );
40
GetOptions(
41
    'help|?'      => \$help,
42
    'days=s'      => \$days,
43
    'months=s'    => \$months,
44
    'v'           => \$verbose,
45
    'lost'        => \$lost,
46
    'address=s'   => \@address,
47
    'not_itype=s' => \@not_itypes,
48
    'format=s'    => \$format,
49
    'filename=s'  => \$filename,
50
);
51
52
if ( $help or ( not $days and not $months ) or not @address or not $format ) {
53
    print <<EOF
54
This script creates an emails a batch of marc records that have been deleted
55
from Koha in a set period of time
56
    Parameters:
57
    --help|-?       This message
58
    -v              Verbose, output biblionumbers of records that can't be
59
                    parsed
60
    --days TTT      to define the age of marc records to export
61
    --months TTT    to define the age of marc records to export eg -months 1
62
                    will export any created in the last calendar month
63
    --address TTT   to define the email address to send the file to. Can
64
                    be repeated.
65
    --lost          if this is set, also export biblio where all items are lost
66
    --not_itype     given an itype code, it will exclude these item types
67
                    from the export. Can be repeated.
68
    --format        'marc': output the whole record as MARC, 'isbn': just
69
                    output text ISBN values.
70
    --filename      the filename (including extension) of the attachment.
71
                    May include %month% which is replaced with the current
72
                    month.
73
     example :
74
     export PERL5LIB=/path/to/koha;export KOHA_CONF=/etc/koha/koha-conf.xml;./newly_deleted_records --days 30 --address chrisc\@catalyst.net.nz --lost --format isbn
75
EOF
76
      ;
77
    exit;
78
}
79
80
$filename = $filename || 'Koha.' . ( $format eq 'isbn' ? 'csv' : 'mrc' );
81
my $month = lc( DateTime->now()->month_name() );
82
$filename =~ s/%month%/$month/g;
83
84
my $date = DateTime->now();
85
if ($days) {
86
    $date->subtract( days => $days );
87
}
88
elsif ($months) {
89
    $date->set_day(1);
90
    $date->subtract( months => $months );
91
}
92
93
export_and_mail_deleted( $date, \@address, $verbose, $lost, $format,
94
    $filename, @not_itypes );

Return to bug 12919