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


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


desc
@@


1.1
log
@Action cleanup. Some role actions, and Audit Log - View, had three actions apiece when one would do. We're now down to 76 actions.
@
text
@#!/usr/bin/perl -w

BEGIN
  {
    unshift(@@INC, "$ENV{SANDBOX}/scripts");
  }

use strict;
use HelmDB;

my %changes =
  ("Host Role - Add" => "Role - Add"
   ,"Domain Role - Add" => "Role - Add"
   ,"Project Role - Add" => "Role - Add"
   
   ,"Host Role - Edit" => "Role - Edit"
   ,"Domain Role - Edit" => "Role - Edit"
   ,"Project Role - Edit" => "Role - Edit"
   
   ,"Host Role - Delete" => "Role - Delete"
   ,"Domain Role - Delete" => "Role - Delete"
   ,"Project Role - Delete" => "Role - Delete"
   
   ,"Host Role - Grant" => "Role - Grant"
   ,"Domain Role - Grant" => "Role - Grant"
   ,"Project Role - Grant" => "Role - Grant"
   
   ,"Project Role - Request" => "Role - Request"
   
   ,"Host - Audit Log - View" => "Audit Log - View"
   ,"Domain - Audit Log - View" => "Audit Log - View"
   ,"Project - Audit Log - View" => "Audit Log - View"
);

main();

sub main
  {
    my $dbh = HelmDB::connect();
    for my $oldAction (keys(%changes))
      {
	my $newAction = $changes{$oldAction};
	changeAction($dbh, $oldAction, $newAction);
      }
    $dbh->disconnect() if $dbh;
  }

sub changeAction($$)
  {
    my ($dbh, $oldAction, $newAction) = @@_;
    my $oldActionID = getActionID($dbh, $oldAction);
    my $newActionID = getActionID($dbh, $newAction);
    my $sql = "update HELM_ROLE_ACTION_RESOURCE set ACTION_ID=$newActionID where ACTION_ID=$oldActionID";
    HelmDB::runSQL($dbh, $sql);
  }

sub getActionID
  {
    my ($dbh, $name) = @@_;
    my $getActionIDQuery = "select ACTION_ID from HELM_ACTION where NAME='$name'";
    my @@result = HelmDB::runQuery($dbh, $getActionIDQuery);
    my $r = $result[0][0];
    if (!$r)
      {
	$r = 0;
      }
    return $r;
  }
@
