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

(-)a/C4/RecordExporter.pm (-48 / +56 lines)
Lines 37-43 BEGIN { Link Here
37
    require Exporter;
37
    require Exporter;
38
    @ISA    = qw(Exporter);
38
    @ISA    = qw(Exporter);
39
    @EXPORT = qw(&export_and_mail_new
39
    @EXPORT = qw(&export_and_mail_new
40
    export_and_mail_deleted);
40
      export_and_mail_deleted);
41
}
41
}
42
42
43
=head1 NAME
43
=head1 NAME
Lines 82-96 The attachment is list of all the ISBNs (could be considered a CSV with one colu Link Here
82
=cut
82
=cut
83
83
84
sub export_and_mail_new {
84
sub export_and_mail_new {
85
    my ( $date, $to, $verbose, $export_items, $not_loan, $format, $filename, @not_itypes )
85
    my ( $date, $to, $verbose, $export_items, $not_loan, $format, $filename,
86
        @not_itypes )
86
      = @_;
87
      = @_;
87
    return unless $to;    # bail if we have no email address
88
    return unless $to;    # bail if we have no email address
88
    my $tmp_filename =
89
    my $tmp_filename =
89
      export_newrecords( $date, $verbose, $export_items, $not_loan, $format,
90
      export_new_records( $date, $verbose, $export_items, $not_loan, $format,
90
        @not_itypes );
91
        @not_itypes );
91
    my $subject = "Records created since $date";
92
    my $subject = "Records created since $date";
92
    _mail( $tmp_filename, $to, $subject,
93
    _mail( $tmp_filename, $to, $subject, $filename, 'New records' );
93
        $filename, 'New records' );
94
}
94
}
95
95
96
=head2 export_and_mail_deleted
96
=head2 export_and_mail_deleted
Lines 104-159 all biblio who have all their items lost. Link Here
104
=cut
104
=cut
105
105
106
sub export_and_mail_deleted {
106
sub export_and_mail_deleted {
107
    my ( $date, $to, $verbose, $lost, $format,$filename, @not_itypes ) = @_;
107
    my ( $date, $to, $verbose, $lost, $format, $filename, @not_itypes ) = @_;
108
    return unless $to;
108
    return unless $to;
109
    my $tmp_filename =
109
    my $tmp_filename =
110
      export_deletedrecords( $date, $verbose, $lost, $format, @not_itypes );
110
      export_deleted_records( $date, $verbose, $lost, $format, @not_itypes );
111
    my $subject = "Records deleted since $date";
111
    my $subject = "Records deleted since $date";
112
    _mail( $tmp_filename, $to, $subject,
112
    _mail( $tmp_filename, $to, $subject, $filename, 'Deleted records' );
113
        $filename, 'Deleted records' );
114
}
113
}
115
114
116
=head2 export_newcords {
115
=head2 export_new_records {
117
116
118
  my $filename = export_newrecords($date,$verbose, $export_items, $not_loan, $format, @not_itypes);
117
  my $filename = export_new_records($date,$verbose, $export_items, $not_loan, $format, @not_itypes);
119
118
120
Given a date, it will export all records created since then to a temp file and return the filename of
119
Given a date, it will export all records created since then to a temp file and return the filename of
121
the file. If export_items is set it will attach the item data also
120
the file. If export_items is set it will attach the item data also
122
121
123
=cut
122
=cut
124
123
125
sub export_newrecords {
124
sub export_new_records {
126
    my ($date,$verbose, $export_items, $not_loan, $format, @not_itypes)    = @_;
125
    my ( $date, $verbose, $export_items, $not_loan, $format, @not_itypes ) = @_;
127
    my $context = C4::Context->new();
126
    my $context = C4::Context->new();
128
    my $dbh     = $context->dbh();
127
    my $dbh     = $context->dbh();
129
    my $sth;
128
    my $sth;
130
    my $query = q{SELECT biblio.biblionumber FROM items JOIN biblio USING(biblionumber) WHERE biblio.datecreated >= ? };
129
    my $query =
131
        if ( $not_loan || @not_itypes ) {
130
q{SELECT biblio.biblionumber FROM items JOIN biblio USING(biblionumber) WHERE biblio.datecreated >= ? };
132
            if ( $not_loan ) {
131
    if ( $not_loan || @not_itypes ) {
133
                $query .= ' AND items.notforloan != ? ';
132
        if ($not_loan) {
134
            }
133
            $query .= ' AND items.notforloan != ? ';
135
            if ( @not_itypes ) {
134
        }
136
                $query .= " AND items.itype NOT IN (". join(', ', ('?') x @not_itypes) . ')' ;
135
        if (@not_itypes) {
137
            }
136
            $query .= " AND items.itype NOT IN ("
138
            $sth   = $dbh->prepare($query);
137
              . join( ', ', ('?') x @not_itypes ) . ')';
139
            if ( $not_loan && @not_itypes ) {
138
        }
140
                $sth->execute($date, $not_loan, @not_itypes)
139
        $sth = $dbh->prepare($query);
141
            }
140
        if ( $not_loan && @not_itypes ) {
142
            elsif ( $not_loan ) {
141
            $sth->execute( $date, $not_loan, @not_itypes );
143
                $sth->execute($date, $not_loan)
142
        }
144
            }
143
        elsif ($not_loan) {
145
            elsif ( @not_itypes ) {
144
            $sth->execute( $date, $not_loan );
146
               $sth->execute($date, @not_itypes)
145
        }
147
            }
146
        elsif (@not_itypes) {
148
            else {
147
            $sth->execute( $date, @not_itypes );
149
                die $sth->err_str;  # no point trying to do anything else, bail out now
150
            }
151
        }
148
        }
152
        else {
149
        else {
153
            $sth   = $dbh->prepare($query);
150
            die
154
            $sth->execute($date)
151
              $sth->err_str; # no point trying to do anything else, bail out now
155
             || die $sth->err_str;  # no point trying to do anything else, bail out now
156
        }
152
        }
153
    }
154
    else {
155
        $sth = $dbh->prepare($query);
156
        $sth->execute($date)
157
          || die
158
          $sth->err_str;     # no point trying to do anything else, bail out now
159
    }
157
160
158
    my ( $fh, $filename ) = tempfile();
161
    my ( $fh, $filename ) = tempfile();
159
    binmode( $fh, ":encoding(UTF-8)" );
162
    binmode( $fh, ":encoding(UTF-8)" );
Lines 179-201 sub export_newrecords { Link Here
179
        C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber )
182
        C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber )
180
          if $export_items;
183
          if $export_items;
181
184
182
        print $fh record_as_format($format, $record);
185
        print $fh record_as_format( $format, $record );
183
186
184
    }
187
    }
185
    close $fh;
188
    close $fh;
186
    return $filename;
189
    return $filename;
187
}
190
}
188
191
189
=head2 export_deletedcords {
192
=head2 export_deleted_records {
190
193
191
  my $filename = export_deletedrecords ($date,$verbose,$lost);
194
  my $filename = export_deleted_records ($date,$verbose,$lost);
192
195
193
Given a date, it will export all records deleted since then to a temp file and return the filename of
196
Given a date, it will export all records deleted since then to a temp file and return the filename of
194
the file. If $lost is set it will also export those with all items marked lost
197
the file. If $lost is set it will also export those with all items marked lost
195
198
196
=cut
199
=cut
197
200
198
sub export_deletedrecords {
201
sub export_deleted_records {
199
    my ( $date, $verbose, $export_items, $format, @itypes ) = @_;
202
    my ( $date, $verbose, $export_items, $format, @itypes ) = @_;
200
    my $context = C4::Context->new();
203
    my $context = C4::Context->new();
201
    my $dbh     = $context->dbh();
204
    my $dbh     = $context->dbh();
Lines 250-263 will return them all. They will be cleaned a little bit, too. Link Here
250
=cut
253
=cut
251
254
252
sub record_as_format {
255
sub record_as_format {
253
    my ($format, $record) = @_;
256
    my ( $format, $record ) = @_;
257
258
    if ( $format eq 'marc' ) {
254
259
255
    if ($format eq 'marc') {
256
        # Simple enough that there's no point making a sub.
260
        # Simple enough that there's no point making a sub.
257
        return $record->as_usmarc();
261
        return $record->as_usmarc();
258
    } elsif ($format eq 'isbn') {
262
    }
263
    elsif ( $format eq 'isbn' ) {
259
        return get_isbns($record);
264
        return get_isbns($record);
260
    } else {
265
    }
266
    else {
261
        croak "Unknown format specified: $format";
267
        croak "Unknown format specified: $format";
262
    }
268
    }
263
}
269
}
Lines 274-284 up a bit, and return them as a newline-separated string. Link Here
274
sub get_isbns {
280
sub get_isbns {
275
    my ($record) = @_;
281
    my ($record) = @_;
276
282
277
    my $res = '';
283
    my $res    = '';
278
    my @fields = $record->field('020');
284
    my @fields = $record->field('020');
279
    foreach my $f (@fields) {
285
    foreach my $f (@fields) {
280
        my $isbn = $f->subfield('a');
286
        my $isbn = $f->subfield('a');
281
        next if !$isbn;
287
        next if !$isbn;
288
282
        # We clean this by removing everything that's not a number or a space,
289
        # We clean this by removing everything that's not a number or a space,
283
        # then take the first series of 9-13 consecutive digits we find
290
        # then take the first series of 9-13 consecutive digits we find
284
        $isbn =~ s/[^0-9 ]//g;
291
        $isbn =~ s/[^0-9 ]//g;
Lines 291-297 sub get_isbns { Link Here
291
sub _mail {
298
sub _mail {
292
    my ( $filename, $to, $subject, $attachment_name, $body ) = @_;
299
    my ( $filename, $to, $subject, $attachment_name, $body ) = @_;
293
    my $context = C4::Context->new();
300
    my $context = C4::Context->new();
294
    my $msg = MIME::Lite->new(
301
    my $msg     = MIME::Lite->new(
295
        From    => $context->preference('KohaAdminEmailAddress'),
302
        From    => $context->preference('KohaAdminEmailAddress'),
296
        To      => $to,
303
        To      => $to,
297
        Subject => $subject,
304
        Subject => $subject,
Lines 307-313 sub _mail { Link Here
307
        Filename    => $attachment_name,
314
        Filename    => $attachment_name,
308
        Disposition => 'attachement'
315
        Disposition => 'attachement'
309
    );
316
    );
310
    $msg->send_by_sendmail(FromSender => $context->preference('KohaAdminEmailAddress'))
317
    $msg->send_by_sendmail(
318
        FromSender => $context->preference('KohaAdminEmailAddress') );
311
}
319
}
312
320
313
1;
321
1;
(-)a/misc/cronjobs/newly_deleted_records.pl (-2 / +4 lines)
Lines 36-42 BEGIN { Link Here
36
use Getopt::Long;
36
use Getopt::Long;
37
use Pod::Usage;
37
use Pod::Usage;
38
38
39
my ( $help, $days, $months, $verbose, $lost, @address, @not_itypes, $format, $filename );
39
my (
40
    $help,    $days,       $months, $verbose, $lost,
41
    @address, @not_itypes, $format, $filename
42
);
40
GetOptions(
43
GetOptions(
41
    'help|?'      => \$help,
44
    'help|?'      => \$help,
42
    'days=s'      => \$days,
45
    'days=s'      => \$days,
43
- 

Return to bug 12919