Merge pull request #2802 from solgenomics/topic/cross_progenies
[sgn.git] / bin / delete_images.pl
blob2029bfeb47de9e97cae3feb8c783dacfc2a12dae
2 =head1 NAME
4 delete_images.pl - a script to hard delete images from a CXGN database.
6 =head1 DESCRIPTION
8 perl delete_images.pl -h <dbhost> -d <dbname> -i <image_dir> file_with_image_ids
10 =head1 NOTES
12 Be careful with this script! Ids have to match the given database etc etc
14 =head1 AUTHOR
16 Lukas Mueller <lam87@cornell.edu>
18 =cut
20 use strict;
22 use File::Slurp qw | slurp |;
23 use Getopt::Std;
25 use CXGN::Image;
26 use CXGN::DB::InsertDBH;
28 our ($opt_h, $opt_d, $opt_i, $opt_t);
30 getopts('h:d:i:t');
32 my $dbh = CXGN::DB::InsertDBH->new( {
33 dbhost => $opt_h,
34 dbname => $opt_d,
35 });
39 my $image_id_file = shift;
41 my @image_ids = slurp($image_id_file);
43 if ($opt_t) {
44 print STDERR "Note: -t. Test mode. Will rollback after operations are done.\n";
47 my $deleted_image_count = 0;
49 eval {
51 foreach my $id (@image_ids) {
52 my $image = CXGN::Image->new(dbh=>$dbh, image_id=>$id, image_dir=> $opt_i);
54 print STDERR "Deleting image with id $id... (".$image->get_description().") ";
56 $image->hard_delete($opt_t);
57 print STDERR "Done.\n";
60 $deleted_image_count++;
63 if ($opt_t) {
64 print STDERR " -t option (test mode): rolling back...";
65 $dbh->rollback();
66 print STDERR "Done.\n";
67 exit();
69 if ($@) {
70 print STDERR "An unfortunate error occurred... ($@)";
71 $dbh->rollback();
73 else {
74 print STDERR "Committing...\n";
75 $dbh->commit();
78 print STDERR "Deleted $deleted_image_count images. Done.\n";