Bugzilla – Attachment 40505 Details for
Bug 12919
Automate collecting all records added and deleted from the catalogue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12919 - perltidy and consistent sub naming
Bug-12919---perltidy-and-consistent-sub-naming.patch (text/plain), 8.20 KB, created by
Liz Rea
on 2015-06-23 03:43:35 UTC
(
hide
)
Description:
Bug 12919 - perltidy and consistent sub naming
Filename:
MIME Type:
Creator:
Liz Rea
Created:
2015-06-23 03:43:35 UTC
Size:
8.20 KB
patch
obsolete
>From fb60251860223fc8a22e0772b0bd250ad49ba846 Mon Sep 17 00:00:00 2001 >From: Liz Rea <liz@catalyst.net.nz> >Date: Tue, 23 Jun 2015 15:39:49 +1200 >Subject: [PATCH] Bug 12919 - perltidy and consistent sub naming > >--- > C4/RecordExporter.pm | 104 ++++++++++++++++++--------------- > misc/cronjobs/newly_deleted_records.pl | 5 +- > 2 files changed, 60 insertions(+), 49 deletions(-) > >diff --git a/C4/RecordExporter.pm b/C4/RecordExporter.pm >index 3a00ae4..5f3f105 100644 >--- a/C4/RecordExporter.pm >+++ b/C4/RecordExporter.pm >@@ -37,7 +37,7 @@ BEGIN { > require Exporter; > @ISA = qw(Exporter); > @EXPORT = qw(&export_and_mail_new >- export_and_mail_deleted); >+ export_and_mail_deleted); > } > > =head1 NAME >@@ -82,15 +82,15 @@ The attachment is list of all the ISBNs (could be considered a CSV with one colu > =cut > > sub export_and_mail_new { >- my ( $date, $to, $verbose, $export_items, $not_loan, $format, $filename, @not_itypes ) >+ my ( $date, $to, $verbose, $export_items, $not_loan, $format, $filename, >+ @not_itypes ) > = @_; > return unless $to; # bail if we have no email address > my $tmp_filename = >- export_newrecords( $date, $verbose, $export_items, $not_loan, $format, >+ export_new_records( $date, $verbose, $export_items, $not_loan, $format, > @not_itypes ); > my $subject = "Records created since $date"; >- _mail( $tmp_filename, $to, $subject, >- $filename, 'New records' ); >+ _mail( $tmp_filename, $to, $subject, $filename, 'New records' ); > } > > =head2 export_and_mail_deleted >@@ -104,56 +104,59 @@ all biblio who have all their items lost. > =cut > > sub export_and_mail_deleted { >- my ( $date, $to, $verbose, $lost, $format,$filename, @not_itypes ) = @_; >+ my ( $date, $to, $verbose, $lost, $format, $filename, @not_itypes ) = @_; > return unless $to; > my $tmp_filename = >- export_deletedrecords( $date, $verbose, $lost, $format, @not_itypes ); >+ export_deleted_records( $date, $verbose, $lost, $format, @not_itypes ); > my $subject = "Records deleted since $date"; >- _mail( $tmp_filename, $to, $subject, >- $filename, 'Deleted records' ); >+ _mail( $tmp_filename, $to, $subject, $filename, 'Deleted records' ); > } > >-=head2 export_newcords { >+=head2 export_new_records { > >- my $filename = export_newrecords($date,$verbose, $export_items, $not_loan, $format, @not_itypes); >+ my $filename = export_new_records($date,$verbose, $export_items, $not_loan, $format, @not_itypes); > > Given a date, it will export all records created since then to a temp file and return the filename of > the file. If export_items is set it will attach the item data also > > =cut > >-sub export_newrecords { >- my ($date,$verbose, $export_items, $not_loan, $format, @not_itypes) = @_; >+sub export_new_records { >+ my ( $date, $verbose, $export_items, $not_loan, $format, @not_itypes ) = @_; > my $context = C4::Context->new(); > my $dbh = $context->dbh(); > my $sth; >- my $query = q{SELECT biblio.biblionumber FROM items JOIN biblio USING(biblionumber) WHERE biblio.datecreated >= ? }; >- if ( $not_loan || @not_itypes ) { >- if ( $not_loan ) { >- $query .= ' AND items.notforloan != ? '; >- } >- if ( @not_itypes ) { >- $query .= " AND items.itype NOT IN (". join(', ', ('?') x @not_itypes) . ')' ; >- } >- $sth = $dbh->prepare($query); >- if ( $not_loan && @not_itypes ) { >- $sth->execute($date, $not_loan, @not_itypes) >- } >- elsif ( $not_loan ) { >- $sth->execute($date, $not_loan) >- } >- elsif ( @not_itypes ) { >- $sth->execute($date, @not_itypes) >- } >- else { >- die $sth->err_str; # no point trying to do anything else, bail out now >- } >+ my $query = >+q{SELECT biblio.biblionumber FROM items JOIN biblio USING(biblionumber) WHERE biblio.datecreated >= ? }; >+ if ( $not_loan || @not_itypes ) { >+ if ($not_loan) { >+ $query .= ' AND items.notforloan != ? '; >+ } >+ if (@not_itypes) { >+ $query .= " AND items.itype NOT IN (" >+ . join( ', ', ('?') x @not_itypes ) . ')'; >+ } >+ $sth = $dbh->prepare($query); >+ if ( $not_loan && @not_itypes ) { >+ $sth->execute( $date, $not_loan, @not_itypes ); >+ } >+ elsif ($not_loan) { >+ $sth->execute( $date, $not_loan ); >+ } >+ elsif (@not_itypes) { >+ $sth->execute( $date, @not_itypes ); > } > else { >- $sth = $dbh->prepare($query); >- $sth->execute($date) >- || die $sth->err_str; # no point trying to do anything else, bail out now >+ die >+ $sth->err_str; # no point trying to do anything else, bail out now > } >+ } >+ else { >+ $sth = $dbh->prepare($query); >+ $sth->execute($date) >+ || die >+ $sth->err_str; # no point trying to do anything else, bail out now >+ } > > my ( $fh, $filename ) = tempfile(); > binmode( $fh, ":encoding(UTF-8)" ); >@@ -179,23 +182,23 @@ sub export_newrecords { > C4::Biblio::EmbedItemsInMarcBiblio( $record, $biblionumber ) > if $export_items; > >- print $fh record_as_format($format, $record); >+ print $fh record_as_format( $format, $record ); > > } > close $fh; > return $filename; > } > >-=head2 export_deletedcords { >+=head2 export_deleted_records { > >- my $filename = export_deletedrecords ($date,$verbose,$lost); >+ my $filename = export_deleted_records ($date,$verbose,$lost); > > Given a date, it will export all records deleted since then to a temp file and return the filename of > the file. If $lost is set it will also export those with all items marked lost > > =cut > >-sub export_deletedrecords { >+sub export_deleted_records { > my ( $date, $verbose, $export_items, $format, @itypes ) = @_; > my $context = C4::Context->new(); > my $dbh = $context->dbh(); >@@ -250,14 +253,17 @@ will return them all. They will be cleaned a little bit, too. > =cut > > sub record_as_format { >- my ($format, $record) = @_; >+ my ( $format, $record ) = @_; >+ >+ if ( $format eq 'marc' ) { > >- if ($format eq 'marc') { > # Simple enough that there's no point making a sub. > return $record->as_usmarc(); >- } elsif ($format eq 'isbn') { >+ } >+ elsif ( $format eq 'isbn' ) { > return get_isbns($record); >- } else { >+ } >+ else { > croak "Unknown format specified: $format"; > } > } >@@ -274,11 +280,12 @@ up a bit, and return them as a newline-separated string. > sub get_isbns { > my ($record) = @_; > >- my $res = ''; >+ my $res = ''; > my @fields = $record->field('020'); > foreach my $f (@fields) { > my $isbn = $f->subfield('a'); > next if !$isbn; >+ > # We clean this by removing everything that's not a number or a space, > # then take the first series of 9-13 consecutive digits we find > $isbn =~ s/[^0-9 ]//g; >@@ -291,7 +298,7 @@ sub get_isbns { > sub _mail { > my ( $filename, $to, $subject, $attachment_name, $body ) = @_; > my $context = C4::Context->new(); >- my $msg = MIME::Lite->new( >+ my $msg = MIME::Lite->new( > From => $context->preference('KohaAdminEmailAddress'), > To => $to, > Subject => $subject, >@@ -307,7 +314,8 @@ sub _mail { > Filename => $attachment_name, > Disposition => 'attachement' > ); >- $msg->send_by_sendmail(FromSender => $context->preference('KohaAdminEmailAddress')) >+ $msg->send_by_sendmail( >+ FromSender => $context->preference('KohaAdminEmailAddress') ); > } > > 1; >diff --git a/misc/cronjobs/newly_deleted_records.pl b/misc/cronjobs/newly_deleted_records.pl >index 1409f67..5354f28 100755 >--- a/misc/cronjobs/newly_deleted_records.pl >+++ b/misc/cronjobs/newly_deleted_records.pl >@@ -36,7 +36,10 @@ BEGIN { > use Getopt::Long; > use Pod::Usage; > >-my ( $help, $days, $months, $verbose, $lost, @address, @not_itypes, $format, $filename ); >+my ( >+ $help, $days, $months, $verbose, $lost, >+ @address, @not_itypes, $format, $filename >+); > GetOptions( > 'help|?' => \$help, > 'days=s' => \$days, >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12919
:
31589
|
31590
|
31591
|
39260
|
39261
|
39262
|
39263
| 40505