[Koha-cvs] koha/misc scrub_orphaned_biblios.pl [dev_week]

Kyle Hall kyle.m.hall at gmail.com
Fri Mar 30 19:26:26 CEST 2007


CVSROOT:	/sources/koha
Module name:	koha
Branch:		dev_week
Changes by:	Kyle Hall <kylemhall>	07/03/30 17:26:25

Added files:
	misc           : scrub_orphaned_biblios.pl 

Log message:
	

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/misc/scrub_orphaned_biblios.pl?cvsroot=koha&only_with_tag=dev_week&rev=1.1.2.1

Patches:
Index: scrub_orphaned_biblios.pl
===================================================================
RCS file: scrub_orphaned_biblios.pl
diff -N scrub_orphaned_biblios.pl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ scrub_orphaned_biblios.pl	30 Mar 2007 17:26:25 -0000	1.1.2.1
@@ -0,0 +1,144 @@
+#!/usr/bin/perl
+
+# script to delete biblios with no attached items.
+# (C) 2007 Kyle Hall
+
+use Getopt::Long;
+use Pod::Usage;
+
+use C4::Context;
+use C4::Biblio;
+use C4::Search;
+use MARC::Record;
+use MARC::File::XML ( BinaryEncoding => 'utf8' );
+
+my $dbh = C4::Context->dbh();
+
+## get command line options
+my ( $ignore_types, $verbose, $debug ) = get_options();
+my @ignore_item_types = split( / /, $ignore_types );
+
+if ($verbose) {
+    if ( my $size = @ignore_item_types ) {
+        print "Ignoring $size Item Types\n";
+        print "Ignoring Item Types of ";
+        foreach my $type (@ignore_item_types) {
+            print $type . " ";
+        }
+        print "\n";
+    }
+}
+
+print "\nBeginning Scrub of Orphaned Biblios\n" if $verbose;
+
+# moving data from marc_subfield_value to biblio
+$sth =
+  $dbh->prepare( 'SELECT biblio.biblionumber, biblioitems.itemtype '
+      . 'FROM ( '
+      . 'biblio '
+      . 'RIGHT JOIN biblioitems ON biblio.biblionumber = biblioitems.biblionumber '
+      . ') '
+      . 'LEFT JOIN items ON biblio.biblionumber = items.biblionumber '
+      . 'WHERE items.biblionumber IS NULL ' );
+$sth->execute;
+
+while ( my ( $biblionumber, $itemtype ) = $sth->fetchrow ) {
+    print "Working on biblionumber $biblionumber\n" if $verbose;
+
+    my $error;
+    if (@ignore_item_types) {
+        my $ignore = 0;
+        
+        foreach my $type (@ignore_item_types) {
+            print "Comparing itemtype '$itemtype' to ignore type '$type'\n" if $verbose;
+            
+            if ( $type eq $itemtype ) {
+                $ignore = 1;
+                print "Match Found!\n" if $verbose;
+            }
+            
+        }
+        
+        if ( !$ignore ) {
+        
+            if ( !$debug ) {
+                $error = DelBiblio( $dbh, $biblionumber );
+            } else {
+                $error = "Attempt to delete biblionumber $biblionumber of itemtype '$itemtype' succeeded.\n"
+                       . "...NOT, you are in debug mode!\n";
+            }
+            
+        } else {
+            $error = "Ignoring biblionumber $biblionumber, itemtype '$itemtype' in list of itemtypes to ignore.\n";
+        }
+        
+    } else {
+    
+        if ( !$debug ) {
+            $error = DelBiblio( $dbh, $biblionumber );
+        } else {
+            $error = "Attempt to delete biblionumber $biblionumber of itemtype '$itemtype' succeeded.\n"
+                   . "...NOT, you are in debug mode!\n";
+        }
+        
+    }
+
+    if ($error) {
+        print "Attempt to delete biblionumber $biblionumber failed,\n  message: $error\n";
+    } else {
+        print "Attempt to delete biblionumber $biblionumber of itemtype '$itemtype' succeeded.\n";
+    }
+    
+}
+print "Scrub Complete.\n";
+
+sub get_options {
+    my $ignore_types = '';
+    my $verbose      = '';
+    my $debug        = '';
+    my $help         = '';
+
+    GetOptions(
+        "i|ignoretypes=s" => \$ignore_types,
+        "v|verbose!"      => \$verbose,
+        "d|debug!"        => \$debug,
+        'h|?|help'        => \$help
+    );
+
+    pod2usage( -exitval => 0 ) if $help;
+
+    return ( $ignore_types, $verbose, $debug );
+}
+__END__
+                                                                     
+=head1 NAME
+                                                                                                      
+scrub_orphaned_biblios.pl - Searches Koha for Biblios with no Items attached and deletes them.
+                                                                                                      
+=head1 SYNOPSIS
+                                                                                                      
+scrub_orphaned_biblios.pl -i ignoretypes [-v] [-d] [-h]
+                                                                                                      
+=head1 OPTIONS
+                                                                                                      
+=over 8
+                                                                                                      
+=item B<-i, --ignoretypes>
+
+A string containing a list of itemtypes separated by spaces to ignore when scrubbing. Example: -i "MAG WEB STUF"
+
+=item B<-v, --verbose>
+
+Details of the process will be printed to stdout
+
+=item B<-d, --debug>
+
+Run in debug mode, program will perform all operations except the actual deletion of biblios.
+
+=item B<-h, -?, --help>
+
+Prints this help message and exits.
+
+=back
+
+=cut  





More information about the Koha-cvs mailing list