head	1.12;
access;
symbols
	TIGRIS_1_1_0RC2:1.4.6.8
	TIGRIS_1_1_0RC1:1.4.6.8
	TIGRIS_1_1:1.4.6.8.0.2
	TIGRIS_1_0_8:1.4.6.8
	TIGRIS_1_0_8RC3:1.4.6.8
	TIGRIS_1_0_8RC2:1.4.6.8
	TIGRIS_1_0_8RC1:1.4.6.8
	TIGRIS_1_0_7:1.4.6.8
	TIGRIS_1_0_7RC3:1.4.6.8
	TIGRIS_1_0_7RC2:1.4.6.8
	TIGRIS_1_0_7RC1:1.4.6.6
	TIGRIS_1_0_6:1.4.6.3
	TIGRIS_1_0_6RC5:1.4.6.3
	TIGRIS_1_0_6RC4:1.4.6.3
	TIGRIS_1_0_6RC3:1.4.6.3
	TIGRIS_1_0_6RC2:1.4.6.3
	TIGRIS_1_0_6RC1:1.4.6.3
	TIGRIS_1_0_5:1.4.6.1
	TIGRIS_1_0_5RC6:1.4.6.1
	TIGRIS_1_0_5RC5:1.4.6.1
	TIGRIS_1_0_5RC4:1.4.6.1
	TIGRIS_1_0_5RC3:1.4.6.1
	TIGRIS_1_0_5RC2:1.4.6.1
	TIGRIS_1_0_5RC1:1.4.6.1
	TIGRIS_1_0_4:1.4.6.1
	TIGRIS_1_0_3:1.4
	TIGRIS_1_0_2:1.4
	TIGRIS_1_0_1:1.4
	TIGRIS_1_0:1.4.0.6
	TIGRIS_1_0_0:1.4
	TIGRIS_1_0_0_RC1:1.4.0.2;
locks; strict;
comment	@# @;


1.12
date	2001.06.30.07.13.34;	author edk;	state Exp;
branches;
next	1.11;

1.11
date	2001.06.26.18.43.01;	author edk;	state Exp;
branches;
next	1.10;

1.10
date	2001.06.22.03.32.52;	author ed;	state Exp;
branches;
next	1.9;

1.9
date	2001.06.22.00.44.17;	author ed;	state Exp;
branches;
next	1.8;

1.8
date	2001.06.05.10.56.06;	author edk;	state Exp;
branches;
next	1.7;

1.7
date	2001.06.05.10.49.51;	author edk;	state Exp;
branches;
next	1.6;

1.6
date	2001.06.04.23.15.46;	author edk;	state Exp;
branches;
next	1.5;

1.5
date	2001.05.01.20.16.50;	author edk;	state Exp;
branches;
next	1.4;

1.4
date	2001.03.23.22.12.26;	author edk;	state Exp;
branches
	1.4.6.1;
next	1.3;

1.3
date	2001.03.19.18.27.05;	author edk;	state Exp;
branches;
next	1.2;

1.2
date	2001.03.19.07.27.49;	author edk;	state Exp;
branches;
next	1.1;

1.1
date	2001.03.18.04.59.30;	author edk;	state Exp;
branches;
next	;

1.4.6.1
date	2001.05.01.20.17.07;	author edk;	state Exp;
branches;
next	1.4.6.2;

1.4.6.2
date	2001.06.05.10.48.14;	author edk;	state Exp;
branches;
next	1.4.6.3;

1.4.6.3
date	2001.06.05.10.52.51;	author edk;	state Exp;
branches;
next	1.4.6.4;

1.4.6.4
date	2001.06.22.00.41.44;	author ed;	state Exp;
branches;
next	1.4.6.5;

1.4.6.5
date	2001.06.22.03.31.54;	author ed;	state Exp;
branches;
next	1.4.6.6;

1.4.6.6
date	2001.06.22.03.33.40;	author ed;	state Exp;
branches;
next	1.4.6.7;

1.4.6.7
date	2001.06.26.18.41.38;	author edk;	state Exp;
branches;
next	1.4.6.8;

1.4.6.8
date	2001.06.30.07.12.52;	author edk;	state Exp;
branches;
next	;


desc
@@


1.12
log
@add in code to handle renaming bugs mailing lists to issues
@
text
@#!/usr/bin/perl

use Getopt::Long;
use DBI;  
use strict;
END { $main::dbh->disconnect if $main::dbh }


# make sure env.sh has been sourced
checkEnvironment();

my $options = getOptions();
my $tigrisq_home = "$ENV{SANDBOX}/data/helm/qmail-old";
my $tigrisq_home_new = "$ENV{SANDBOX}/data/helm/qmail";

if (! -d "$tigrisq_home" ) {
    print "The old ~tigrisq ($tigrisq_home) isn't present : \n",
          "move_tigrisq needs that data to do the migration.  Please put \n",
          "the data there, then run move_tigrisq again.\n";
    exit;
}
# stop mail delivery
system("chmod", "+t", "$tigrisq_home_new");

# start the anzu server, if needed
startAnzuServer();

# first we create the domain -- note that this won't work if there
# are multiple domains, so it's fair to assume that's not the case.
my @@anzu_command = ();
push @@anzu_command, "delete_domain",$ENV{DOMAIN}, "\n";
push @@anzu_command, "add_domain",$ENV{DOMAIN}, "\n";

# next, we get the list of projects
$main::dbh = getDatabaseConnection();

my $domain_data_dir = "$ENV{SANDBOX}/data/anzu/domains/$ENV{DOMAIN}";

my $anzu_admin = "$ENV{SANDBOX}/helm/scripts/anzu_admin";

# first, get information on what projects, domains, and lists, etc are
# defined in the helm database, compared with eyebrowse and anzu.

my $select = getHelmProjects($main::dbh);
while (my $projectRecord = $select->fetchrow_hashref) {
    my $project   = $projectRecord->{project};
    my $domain    = $projectRecord->{DOMAIN};
    my $projectID = $projectRecord->{projectID};
    my $info      = $projectID;
    if ($domain ne "$ENV{DOMAIN}") {
        die "DOMAIN ($ENV{DOMAIN}) doesn't match a domain in the db ($domain)";
    }
    next if ($project=~ m/\*/);
    # does this project exist in anzu?
    push @@anzu_command, "add_project", $ENV{DOMAIN}, $project, "\n";
}
runAnzuCommand(@@anzu_command) if scalar(@@anzu_command);

# reset all the archives -- this creates the directories for the archives.
# index2mbox.pl should probably do that, but it doesn't ...
system($anzu_admin, '--type=anzu','--op=reset_archive');

# ok -- the domain and the projects exist ; it's time to do the mailing lists

$select = getHelmLists($main::dbh);
while (my $mlRecord = $select->fetchrow_hashref) {
    my $list     = $mlRecord->{LIST_NAME};
    my $type     = $mlRecord->{TYPE};
    my $domain   = $mlRecord->{DOMAIN_NAME};
    my $project  = $mlRecord->{PROJECT_NAME};
    my $listID   = $mlRecord->{MAILINGLIST_ID};
    my $desc     = $mlRecord->{DESCRIPTION};
    my $info     = [$type, $desc];

    my $old_directory = "$tigrisq_home/$project-$list";
    # some classic sites have www- in "top level" list names, others don't.
    if (!-d "$old_directory" && lc($project) eq 'www') {
        $old_directory = "$tigrisq_home/$list";
    }
    if (!-d "$old_directory" && -d lc($old_directory)) {
        $old_directory = lc ($old_directory);
    }
    if (!-d "$old_directory") {
        warn "ERROR $project-$list dir ($old_directory) missing in tigrisq; skipping\n";
        next;
    }
    $project = lc($project);
    $list = lc($list);
    # bugs lists get renamed issues:
    if ($list eq 'bugs') {
        $list = 'issues';
    }
    my $list_file    =
        "$ENV{SANDBOX}/data/eyebrowse/$domain/$project/$list/0mbox";

    if ($options->{debug}) {
        print STDERR "  moving list $project-$list ($domain)\n";
    }
    # move the list in its old location to the new one
    system("mv", "$old_directory",
            "$domain_data_dir/projects/$project/addresses/$list");
    # create list options, so anzu believes this list is set up already
    system("cp", "$domain_data_dir/list_types/discuss",
            "$domain_data_dir/projects/$project/list_options/$list");
    # get the ezmlm archives into an mbox for eb :
    system("$ENV{SANDBOX}/eyebrowse/src/scripts/index2mbox.pl", "--directory",
            "$domain_data_dir/projects/$project/addresses/$list",
            "--output", $list_file);
}

# we renamed bugs to issues; let's reflect that in the db:
renameHelmBugsLists($main::dbh);

# we could do users, but those'll be handled anyway here.
system("$ENV{SANDBOX}/helm/scripts/anzu_admin", "--op=update");

system("chmod", "-t", "$tigrisq_home_new");

# if we started the anzu server, we should stop it, for consistency:
stopAnzuServer();

#################################
###  preparation (getting information, db connections, etc.)
#################################

sub getOptions
{
    my %options;
    if (!GetOptions(\%options,
                "debug",
                "help")
            or $options{help}) {
        showUsage();
    }

    return \%options;
}

sub getHelmProjects
{
    my ($dbh) = @@_;
    my $select  = $dbh->prepare(
            "SELECT HELM_PROJECT.NAME as project, HELM_DOMAIN.NAME as DOMAIN, ".
                "HELM_PROJECT.PROJECT_ID as projectID ".
            "FROM HELM_PROJECT, HELM_DOMAIN ".
            "WHERE HELM_PROJECT.DOMAIN_ID = HELM_DOMAIN.DOMAIN_ID AND " .
                "HELM_PROJECT.TYPE!='host' AND HELM_PROJECT.TYPE != 'domain'");
    my $ret  = $select->execute();
    warn "error selecting projects" if not $ret;
    return $select;
}

sub getHelmLists
{
    my ($dbh) = @@_;
    my $select = $dbh->prepare(
        "SELECT LIST_NAME, ml.TYPE, Project.NAME as PROJECT_NAME, " .
            "Domain.NAME as DOMAIN_NAME, MAILINGLIST_ID, ml.DESCRIPTION ".
        "FROM HELM_MAILINGLIST ml, HELM_PROJECT Project, HELM_DOMAIN Domain ".
        "WHERE ml.PROJECT_ID = Project.PROJECT_ID AND ".
            "Project.DOMAIN_ID = Domain.DOMAIN_ID");
    my $ret = $select->execute();
    warn "error selecting mailing lists" if not $ret;
    return $select;
}

sub renameHelmBugsLists
{
    my ($dbh) = @@_;
    my $select = $dbh->prepare(
        "UPDATE HELM_MAILINGLIST \n".
	"SET LIST_NAME = 'issues' \n".
	"WHERE LIST_NAME = 'bugs'");
    my $ret = $select->execute();
    warn "error selecting mailing lists" if not $ret;
    return $select;
}
renameHelmBugsLists($main::dbh);


sub getDatabaseConnection
{
    my $db_base = 'mysql';
    my $db_name = "$ENV{DATABASE_NAME}";
    my $db_host = "$ENV{DATABASE_HOST}";
    my $db_port = "$ENV{DATABASE_PORT}";
    my $db_user = "$ENV{DATABASE_USER}";
    my $db_pass = "$ENV{DATABASE_PASSWORD}";
    my $connectstring = "dbi:$db_base:$db_name:host=$db_host:port=$db_port";
    my $dbh = DBI->connect($connectstring, $db_user, $db_pass)
        or die "Can't connect to the table '$connectstring'.\n";
    return $dbh;
}

sub showUsage
{
    my ($message) = @@_;
    print <<EOM;
Usage: move_tigrisq [--debug] [--help]
	help		show this message
	debug		include debugging output

This script is designed to adopt a classic-tigris style ~tigrisq directory
to the anzu directory structure.  You must have sourced env.sh before you
can use it.

It will attempt to guess certain things -- such as if lists in the 'www'
project (aka top level lists) include 'www-' in their names.

EOM

    print "\n\tERROR MESSAGE\n\t$message\n" if ($message);

    exit;
}

sub checkEnvironment
{
    if ($ENV{SANDBOX} eq '') {
        showUsage("SANDBOX not defined in the environment");
    } elsif (! -d $ENV{SANDBOX}) {
        showUsage("SANDBOX does not point to a valid directory");
    }
}

sub getAnzuCommandBase
{
    return ("$ENV{SANDBOX}/site/scripts/anzu/harness");
}

sub runAnzuCommand
{
    unshift @@_, getAnzuCommandBase();
    print STDERR "running anzu Harness; if this hangs, please kill it,\n";
    print STDERR "restart your sandbox, and try again.\n";

    system(@@_);
}

# this will start the anzu server if it's not already running
sub startAnzuServer {
    system("svok", "$ENV{SANDBOX}/site/scripts/anzu/anzu-server");
    $main::start_anzu_server = $? >> 8;
    if ($main::start_anzu_server) {
        print "starting anzu server; will stop it after\n";
        system("$ENV{SANDBOX}/site/scripts/anzu/start_anzu");
        sleep(2);
    }
}

# this will stop the anzu server if it was started by startAnzuServer
sub stopAnzuServer {
    if ($main::start_anzu_server) {
        print "stopping anzu server now\n";
        system("$ENV{SANDBOX}/site/scripts/anzu/stop_anzu");
    }
}
    
@


1.11
log
@looks like this needs to run earlier.  i'm not sure why i was having
problems with it that way on before.
@
text
@d89 4
d111 3
d166 13
@


1.10
log
@this seems to be the right order for operations: call anzu_admin's
update operation before calling the reset_archive operation.
@
text
@d59 4
a108 3

# reset all the archives:
system($anzu_admin, '--type=anzu','--op=reset_archive');
@


1.9
log
@the anzu harness now uses newlines to separate arguments
@
text
@a58 3
# reset all the archives:
system($anzu_admin, '--type=anzu','--op=reset_archive');

d105 4
@


1.8
log
@fix cut and paste error (a line was moved unintentionally)
rename a variable to be clearer
@
text
@d31 2
a32 2
push @@anzu_command, "delete_domain",$ENV{DOMAIN};
push @@anzu_command, "add_domain",$ENV{DOMAIN};
d55 1
a55 1
    push @@anzu_command, "add_project", $ENV{DOMAIN}, $project;
@


1.7
log
@start anzu server earlier (it's needed earlier)
@
text
@a26 1
system($anzu_admin, '--type=anzu','--op=reset_archive');
d59 3
d221 2
a222 2
    $main::exit_value = $? >> 8;
    if ($main::exit_value) {
d231 1
a231 1
    if ($main::exit_value) {
@


1.6
log
@some tigris classic sites have this fixed (names in the file system
should all be lower case), others don't.
@
text
@d25 4
a58 4

# start the anzu server, if needed
startAnzuServer();
system($anzu_admin, '--type=anzu','--op=reset_archive');
@


1.5
log
@start the anzu server if it wasn't running; and stop it if we started
it
@
text
@d77 3
@


1.4
log
@* exit early if $SANDBOX/data/helm/qmail-old doesn't exist
* special case www- for top level lists in a more complete fashion
  (some classic sites include it, others don't).
* --help option to call showUsage
@
text
@d56 2
d105 3
d213 19
@


1.4.6.1
log
@start the anzu server if it wasn't running; and stop it if we started
it
@
text
@a55 2
# start the anzu server, if needed
startAnzuServer();
a102 3
# if we started the anzu server, we should stop it, for consistency:
stopAnzuServer();

a207 19
# this will start the anzu server if it's not already running
sub startAnzuServer {
    system("svok", "$ENV{SANDBOX}/site/scripts/anzu/anzu-server");
    $main::exit_value = $? >> 8;
    if ($main::exit_value) {
        print "starting anzu server; will stop it after\n";
        system("$ENV{SANDBOX}/site/scripts/anzu/start_anzu");
        sleep(2);
    }
}

# this will stop the anzu server if it was started by startAnzuServer
sub stopAnzuServer {
    if ($main::exit_value) {
        print "stopping anzu server now\n";
        system("$ENV{SANDBOX}/site/scripts/anzu/stop_anzu");
    }
}
    
@


1.4.6.2
log
@handle more odd cases, in terms of lists with some upper case latters
in their names, or the projects' names.
@
text
@a76 3
    if (!-d "$old_directory" && -d lc($old_directory)) {
        $old_directory = lc ($old_directory);
    }
@


1.4.6.3
log
@start the anzu server earlier, when it's needed
@
text
@a24 3
# start the anzu server, if needed
startAnzuServer();

d56 2
a57 1
# reset all the archives
@


1.4.6.4
log
@this was broken since 1.0.5 -- it wasn't separating commands with
newlines.
@
text
@d31 2
a32 2
push @@anzu_command, "delete_domain",$ENV{DOMAIN}, "\n";
push @@anzu_command, "add_domain",$ENV{DOMAIN}, "\n";
d55 1
a55 1
    push @@anzu_command, "add_project", $ENV{DOMAIN}, $project, "\n";
d225 1
a225 1
        sleep(10);
@


1.4.6.5
log
@this seems to be the right order for operations: call anzu_admin's
update operation before calling the reset_archive operation.
@
text
@d59 3
a108 3

# reset all the archives
system($anzu_admin, '--type=anzu','--op=reset_archive');
@


1.4.6.6
log
@minor change to order of operations : finish reseting the archive
before re-enabling mail delivery to tigrisq.
@
text
@d105 1
a108 2

system("chmod", "-t", "$tigrisq_home_new");
@


1.4.6.7
log
@looks like this needs to run earlier.  i'm not sure why i was having
problems with it that way on before.
@
text
@a58 4
# reset all the archives -- this creates the directories for the archives.
# index2mbox.pl should probably do that, but it doesn't ...
system($anzu_admin, '--type=anzu','--op=reset_archive');

d105 3
@


1.4.6.8
log
@add code to rename bugs mailing lists to issues for issuezilla
@
text
@a88 4
    # bugs lists get renamed issues:
    if ($list eq 'bugs') {
        $list = 'issues';
    }
a106 3
# we renamed bugs to issues; let's reflect that in the db:
renameHelmBugsLists($main::dbh);

a158 13

sub renameHelmBugsLists
{
    my ($dbh) = @@_;
    my $select = $dbh->prepare(
        "UPDATE HELM_MAILINGLIST \n".
	"SET LIST_NAME = 'issues' \n".
	"WHERE LIST_NAME = 'bugs'");
    my $ret = $select->execute();
    warn "error selecting mailing lists" if not $ret;
    return $select;
}
renameHelmBugsLists($main::dbh);
@


1.3
log
@* use a new operation added to anzu_admin 'cause using eyebrowse to
  recreate all the lists is prohibitiviely slow.
* handle the special case for www and the difference between how caps
  were handled and how they are handled.

this appears to pass unit tests
@
text
@d15 7
d70 9
a78 3
    my $project_string = ($project eq 'www' ? '' : $project . '-');
    my $old_directory =
        "$tigrisq_home/$project_string$list";
d85 1
a85 5
        print STDERR "  moving list $project_string$list ($domain)\n";
    }
    if (!-d "$old_directory") {
        warn "$project_string$list dir missing in tigrisq; skipping\n";
        next;
d111 2
a112 1
                "debug")
d167 3
a169 1
Usage: move_tigrisq
d174 3
@


1.2
log
@* stop and start mail delivery before/after
* use a different directory to hold the old version of ~tigrisq
@
text
@d20 3
a22 2
runAnzuCommand("delete_domain",$ENV{DOMAIN});
runAnzuCommand("add_domain",$ENV{DOMAIN});
a33 1
my @@anzu_command = ();
d49 1
a49 1
system($anzu_admin, '--type=eyebrowse','--op=create');
d62 6
a70 7
    my $project_string;
    if ($project eq 'www') {
        $project_string = '';
    } 
    else {
        $project_string = $project . '-';
    }
d74 1
a74 1
    if (!-d "$tigrisq_home/$project_string$list") {
d79 1
a79 1
    system("mv", "$tigrisq_home/$project_string$list",
@


1.1
log
@lightly tested script for moving the old-style ~tigrisq to subdirs of
the anzu repository.
@
text
@d13 4
d75 1
a75 1
    if (!-d "$ENV{SANDBOX}/data/helm/qmail/$project_string$list") {
d80 1
a80 1
    system("mv", "$ENV{SANDBOX}/data/helm/qmail/$project_string$list",
d93 1
@

