IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 29, 2009, 11:30:32 AM (17 years ago)
Author:
bills
Message:

Require confirmation from user before deleting a product.
Delete data from database before attempting to remove the files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataStoreServer/scripts/dsprodtool

    r24196 r25664  
    1212use PS::IPP::Metadata::Config;
    1313use File::Copy;
     14
     15use Term::ReadKey;
    1416
    1517use PS::IPP::Config qw($PS_EXIT_SUCCESS
     
    3638my $dsroot;
    3739my $dbname;
     40my $dbpass;
    3841
    3942my $add;
     
    7881} else {
    7982    $product = $del;
     83    if (! -t STDIN) {
     84        die "cannot delete product from script\n";
     85    }
     86    print "*** Delete the Data Store Product $product? ***\n";
     87    print "*** to delete $product answer YES, and give password ***\n";
     88    print "*** WARNING this action is permanant *** \n";
     89    print "Delete? (YES/[n]): ";
     90
     91    my $line = ReadLine(0);
     92    chomp $line;
     93    exit 1 if !$line or ($line ne "YES");
     94
     95    print "password: ";
     96    ReadMode('noecho');
     97    $line = ReadLine(0);
     98    ReadMode('normal');
     99    print "\n";
     100    chomp $line;
     101    $dbpass = $line;
    80102}
    81103
     
    106128    unless defined $dbname;
    107129my $dbuser   = metadataLookupStr($siteConfig, 'DS_DBUSER');
    108 my $dbpass   = metadataLookupStr($siteConfig, 'DS_DBPASSWORD');
     130$dbpass   = metadataLookupStr($siteConfig, 'DS_DBPASSWORD') if !$dbpass;
    109131exit ($PS_EXIT_CONFIG_ERROR) unless defined $dbserver and $dbname and $dbuser and $dbpass;
    110132
    111133my $dsn = "DBI:mysql:host=$dbserver;database=$dbname";
    112 
    113 my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n";
    114 
    115134
    116135my $product_dir = "$dsroot/$product";
     
    118137
    119138if ($del) {
     139    my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n";
    120140    #
    121141    # delete product
     
    129149    }
    130150    my $prod_id = $prod_row->{prod_id};
    131 
    132     # if requested, remove the product directory
    133     if ($remove) {
    134         if (system "rm -r $product_dir") {
    135             die("failed to remove $product_dir");
    136         }
    137     } else  {
    138         # otherwise just zap the index script
    139         unlink("$index_script_name");
    140     }
    141151
    142152
     
    152162    $dbh->do("DELETE from dsProduct where prod_id = $prod_id");
    153163
     164    print "Product $product deleted.\n";
     165
     166    # if requested, remove the product directory
     167    if ($remove) {
     168        print "Removing files from $product.\n";
     169        if (system "rm -r $product_dir") {
     170            die("failed to remove $product_dir");
     171        }
     172    } else  {
     173        # otherwise just zap the index script
     174        unlink("$index_script_name");
     175    }
     176
    154177    exit 0;
    155178
     
    158181    # add a new product
    159182    #
     183    my $dbh = DBI->connect($dsn, $dbuser, $dbpass) or die "Cannot connect to server\n";
     184
    160185    my $stmt = $dbh->prepare("SELECT prod_id FROM dsProduct WHERE prod_name = \'$product\'");
    161186    $stmt->execute();
Note: See TracChangeset for help on using the changeset viewer.