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


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

1.2
date	2001.07.09.23.39.35;	author ms;	state Exp;
branches;
next	1.1;

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


desc
@@


1.3
log
@Implemented the inverse of the current functionality so that the script looks for orphaned CVS repositories and Issuezilla databases.
@
text
@#!/usr/bin/perl

# This script verifies that every project in the Helm database has 
# a corresponding Issuezilla database and a CVS respository.

BEGIN { push(@@INC, "$ENV{SANDBOX}/scripts/") }
use HelmDB;
use strict;

my $cvsDataPath = "$ENV{SANDBOX}/helm/data/cvs/repository/";

main();

sub main()
{
  my $dbh = HelmDB::connect($ENV{DATABASE_NAME}, $ENV{DATABASE_ADMIN_USER},
			    $ENV{DATABASE_ADMIN_PASSWORD});
  
  my $sysdbh = HelmDB::connect("mysql", $ENV{DATABASE_ADMIN_USER},
			       $ENV{DATABASE_ADMIN_PASSWORD});  

  my $projectQuery = 
    "select PROJECT_ID, NAME from HELM_PROJECT where TYPE NOT IN 
     ('host', 'domain')";  
  my @@projects = HelmDB::runQuery($dbh, $projectQuery);
  my $numProjects = scalar(@@projects);
  my $plural = "s";
  if ($numProjects == 1)
  {
    my $plural = "";
  }
  print "Checking resources for $numProjects project$plural\n";

  if ($ENV{IZ_MULTIPLE_PROJECT_DATABASES} eq "false")
  {
    verifyDatabaseExitance($sysdbh, "issues")
  }

  foreach my $project (@@projects)
  { 
    my $id = $project->[0];
    my $name = $project->[1];
    verifyResources($sysdbh, $id, $name)
  }  

  print "Looking for orphaned CVS repositories\n";
  opendir(IN, $cvsDataPath) || warn "Unable to open: $!\n";
  my @@repositories = readdir(IN);
  foreach my $repository (@@repositories)
  {
    if (!($repository =~ /(^\.{1,2}$|^CVS$|^CVSROOT$)/))
    {
      if (!projectExists($dbh, "NAME", $repository))
      {
	print "Found orphaned CVS repository: $repository\n";
      }  
    }
  }

  print "Looking for orphaned Issuezilla databases\n";
  foreach my $databaseName (getIssuezillaDatabases($sysdbh))
  {    
    my $projectID = $databaseName;
    $projectID =~ s/.*_(.*)/$1/;
    if (!projectExists($dbh, "PROJECT_ID", $projectID))
    {
      print "Found orphaned Issuezilla database: $databaseName\n";
    } 
  }
  print "All done.\n";

  $dbh->disconnect();
  $sysdbh->disconnect();
}

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

sub verifyResources($$$)
{
  my ($dbh, $id, $name) = @@_;
  
  if ($ENV{IZ_MULTIPLE_PROJECT_DATABASES} eq "true")
    {
    verifyDatabaseExistence($dbh, $id);  
  }
  verifyCVSPath($name);
}

sub projectExists($$$)
{
  my ($dbh, $field, $value) = @@_;
  my $projectQuery = "select PROJECT_ID from HELM_PROJECT where $field='$value'";
  my @@projects = HelmDB::runQuery($dbh, $projectQuery);
  return (scalar(@@projects) >= 1);
}

sub issuezillaDatabasePrefix()
{
  my $prefix = "issues_";
  if ($ENV{STANDARD_PORTS} eq "false")
  {
    $prefix .= "$<_";
  }
  return $prefix;
}

sub verifyDatabaseExistence($$)
{
  my ($dbh, $name) = @@_;

  if ($name ne "issues")
  {
    $name = issuezillaDatabasePrefix() . $name
  }

  my $query = "select Db from db where Db='$name'";
  my @@dbs = HelmDB::runQuery($dbh, $query);
  if (scalar(@@dbs) <= 0)
  {
    print "Could not find Issuezilla database $name.\n";
  }
}

sub getIssuezillaDatabases($)
{
  my ($dbh) = @@_;
  my $prefix = issuezillaDatabasePrefix();
  my $query = "show databases";
  print "Running $query\n";
  my @@databases = HelmDB::runQuery($dbh, $query);
  my @@izDatabases = ();
  for my $database (@@databases)
  {
    my $databaseName = $database->[0];
    if ($databaseName =~ /^$prefix/)
    {
      push(@@izDatabases, $databaseName);
    }
  }
  return @@izDatabases;
}

sub verifyCVSPath($)
{
  my ($name) = @@_;
  my $path = "$cvsDataPath/$name";
  if (!-e $path)
  {
    print "Could not find CVS repository for $name project.\n";
  }
}

@


1.2
log
@the watchful eye
@
text
@d10 2
a13 1

d24 1
a24 2
     ('host', 'domain')";
  
d34 5
d45 25
d81 5
a85 1
  verifyDatabaseExistence($dbh, $id);  
d89 18
d111 1
a111 1
  if ($ENV{IZ_MULTIPLE_PROJECT_DATABASES} eq "false")
d113 1
a113 12
    $name = "issues";
  }
  else
  {
    if ($ENV{STANDARD_PORTS})
    {
      $name = "issues_$<_$name";
    }
    else
    {
      $name = "issues_$name";
    }
d124 19
d146 2
a147 2
  my $cvsDataPath = "$ENV{SANDBOX}/helm/data/cvs/respository/$name";
  if (!-e ($cvsDataPath . $name))
d152 1
@


1.1
log
@New script to verify that projects have Issuezilla databases and CVS repositories.
@
text
@d61 1
a61 1
    $name = "issues"
@

