head	1.5;
access;
symbols;
locks; strict;
comment	@# @;


1.5
date	2001.07.30.18.44.24;	author leonardr;	state dead;
branches;
next	1.4;

1.4
date	2001.07.11.17.38.15;	author leonardr;	state Exp;
branches;
next	1.3;

1.3
date	2001.07.09.20.17.04;	author leonardr;	state Exp;
branches;
next	1.2;

1.2
date	2001.07.09.18.17.08;	author leonardr;	state Exp;
branches;
next	1.1;

1.1
date	2001.07.03.18.12.46;	author leonardr;	state Exp;
branches;
next	;


desc
@@


1.5
log
@Moved stuff from 1.1.0 migration directory to 1.2.0 directory to reflect actual future versioning.
@
text
@#!/usr/bin/perl -w
# -*- Perl -*- script which will delete actions from the database.
#
# $Id: deleteActions.pl,v 1.4 2001/07/11 17:38:15 leonardr Exp $

my @@actions = ("Project - List"
	       ,"Project - Volunteer"
	       ,"ProjectGroup Element - Add"
	       ,"ProjectGroup Element - Delete"
	       ,"ProjectGroup - List"
	       ,"ProjectGroup - Edit"
	       ,"ProjectGroup - View"
	       ,"Project Download - Approve"
	       ,"Project Download - Delete"
	       ,"Project Download - Edit"
	       ,"Project Download - Suggest"
	       ,"Project Download - View"	       
	       ,"Domain - Add"
	       ,"Domain - Delete"
	       ,"Domain - Edit"
	       ,"Domain - List"
	       ,"Domain - View"
	       ,"Domain Branding - Edit"
	       ,"Domain Branding - View"
	       ,"Domain News - Edit"
	       ,"Domain News - View"
	       ,"Domain Page - Edit"
	       ,"DomainProjectCategories - Edit"
	       ,"DomainProjectCategories - View"
	       ,"DomainSpotlight - Edit"
	       ,"DomainSpotlight - View"
	       ,"Project Branding - Edit"
	       ,"Project Branding - View"
	       ,"Project Configuration - Edit"
	       ,"Project Configuration - View"
	       ,"Project Page - Edit"
	       ,"Project Role - Revoke - Self"
	       ,"Project Screenshot - Approve"
	       ,"Project Screenshot - Suggest"
	       ,"Proprietary Page - View"
	       ,"SearchResults - View"
);

use DBI;
use strict;

my $dbh = dbConnection($ENV{DATABASE_NAME}, $ENV{DATABASE_ADMIN_USER},
                         $ENV{DATABASE_ADMIN_PASSWORD});

foreach my $action(@@actions)
{
  my $getActionIDQuery = "select ACTION_ID from HELM_ACTION where NAME='$action'";
  my $something = runSelect($dbh, $getActionIDQuery);
  my $actionID = $something->{ACTION_ID};
  deleteAction($dbh, $actionID);
}

$dbh->disconnect();

sub deleteAction()
  {
    my ($dbh, $actionID) = (@@_);

    if (defined($actionID))
      {
	print "Deleting action $actionID from roles\n";
	my $rarQuery = "delete from HELM_ROLE_ACTION_RESOURCE where ACTION_ID = '$actionID'";
	runStatement($dbh, $rarQuery);

	print "Deleting action $actionID from action table.\n";
	my $actQuery = "delete from HELM_ACTION where ACTION_ID = '$actionID'";
	runStatement($dbh, $actQuery);

      }
  }

####################################################################

# Creates and returns a handle to the database (i.e. connection reference).
#
# ex. my $conn = dbConnection('tigris', 'user', 'passwd');
sub dbConnection($$$)
{
    my ($dbName, $dbUser, $dbPasswd) = @@_;
    return DBI->connect
        ("DBI:mysql:$dbName:$ENV{DATABASE_HOST}:$ENV{DATABASE_PORT}",
         $dbUser, $dbPasswd,
        { RaiseError => 1, AutoCommit => 1 });
}

# Runs a SQL statement.
#
# ex. my $rv = runStatement($dbh, 'delete from bar where baz');
sub runStatement($$)
{
    my ($dbh, $sql) = @@_;
    #print "sql=$sql\n";  # debug
    $sql =~ s/(.*)\;\s*$/$1/s;
    my $sth = $dbh->prepare($sql);
    my $rv = $sth->execute();
    $sth->finish();
    return $rv;
}

# Runs a SQL SELECT statement.
#
# ex. my $rv = runSelect($dbh, 'select foo from bar where baz');
sub runSelect($$)
{
  my ($dbh, $sql) = @@_;
  #print "sql=$sql\n";  # debug
  $sql =~ s/(.*)\;\s*$/$1/s;
  my $sth = $dbh->prepare($sql);

  my $rv = $sth->execute();
  my $hashref=$sth->fetchrow_hashref();
  $sth->finish();
  return $hashref;
}


@


1.4
log
@More action cleanup, and reinstated Domain - View action because it turns out to have been in use after all.
@
text
@d4 1
a4 1
# $Id: deleteActions.pl,v 1.3 2001/07/09 20:17:04 leonardr Exp $
@


1.3
log
@Cleanup: Got rid of never-used actions.
@
text
@d4 1
a4 1
# $Id: deleteActions.pl,v 1.2 2001/07/09 18:17:08 leonardr Exp $
a27 1
	       ,"Domain Page - View"
@


1.2
log
@Getting rid of residual download stuff.
@
text
@d4 1
a4 1
# $Id: deleteActions.pl,v 1.1 2001/07/03 18:12:46 leonardr Exp $
d7 36
a42 11
              ,"Project - Volunteer"
              ,"ProjectGroup Element - Add"
              ,"ProjectGroup Element - Delete"
              ,"ProjectGroup - List"
              ,"ProjectGroup - Edit"
              ,"ProjectGroup - View"
              ,"Project Download - Approve"
              ,"Project Download - Delete"
              ,"Project Download - Edit"
              ,"Project Download - Suggest"
              ,"Project Download - View"
@


1.1
log
@Committing file I'd earlier forgotten
@
text
@d4 1
a4 1
# $Id: deleteActions.pl,v 1.1 2001/03/26 21:41:51 leonardr Exp $
d13 6
a18 1
              ,"ProjectGroup - Delete");
@

