head	1.16;
access;
symbols
	TIGRIS_1_1_0RC2:1.10.6.1
	TIGRIS_1_1_0RC1:1.10.6.1
	TIGRIS_1_1:1.10.6.1.0.2
	TIGRIS_1_0_8:1.10.6.1
	TIGRIS_1_0_8RC3:1.10.6.1
	TIGRIS_1_0_8RC2:1.10.6.1
	TIGRIS_1_0_8RC1:1.10.6.1
	TIGRIS_1_0_7:1.10.6.1
	TIGRIS_1_0_7RC3:1.10.6.1
	TIGRIS_1_0_7RC2:1.10.6.1
	TIGRIS_1_0_7RC1:1.10.6.1
	TIGRIS_1_0_6:1.10.6.1
	TIGRIS_1_0_6RC5:1.10.6.1
	TIGRIS_1_0_6RC4:1.10.6.1
	TIGRIS_1_0_6RC3:1.10.6.1
	TIGRIS_1_0_6RC2:1.10.6.1
	TIGRIS_1_0_6RC1:1.10.6.1
	TIGRIS_1_0_5:1.10.6.1
	TIGRIS_1_0_5RC6:1.10.6.1
	TIGRIS_1_0_5RC5:1.10.6.1
	TIGRIS_1_0_5RC4:1.10.6.1
	TIGRIS_1_0_5RC3:1.10.6.1
	TIGRIS_1_0_5RC2:1.10.6.1
	TIGRIS_1_0_5RC1:1.10.6.1
	TIGRIS_1_0_4:1.10
	TIGRIS_1_0_3:1.10
	TIGRIS_1_0_2:1.10
	TIGRIS_1_0_1:1.10
	TIGRIS_1_0:1.10.0.6
	TIGRIS_1_0_0:1.10
	TIGRIS_1_0_0_RC1:1.10.0.2;
locks; strict;
comment	@# @;


1.16
date	2001.08.22.16.47.56;	author edk;	state Exp;
branches;
next	1.15;

1.15
date	2001.06.19.07.08.56;	author edk;	state Exp;
branches;
next	1.14;

1.14
date	2001.06.14.10.52.50;	author edk;	state Exp;
branches;
next	1.13;

1.13
date	2001.05.14.09.23.41;	author edk;	state Exp;
branches;
next	1.12;

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

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

1.10
date	2001.03.27.10.55.28;	author edk;	state Exp;
branches
	1.10.6.1;
next	1.9;

1.9
date	2001.03.19.19.31.41;	author edk;	state Exp;
branches;
next	1.8;

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

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

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

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

1.4
date	2001.03.08.04.04.43;	author edk;	state Exp;
branches;
next	1.3;

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

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

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

1.10.6.1
date	2001.05.14.13.13.06;	author edk;	state Exp;
branches
	1.10.6.1.2.1;
next	1.10.6.2;

1.10.6.2
date	2001.08.22.16.47.04;	author edk;	state Exp;
branches;
next	;

1.10.6.1.2.1
date	2001.08.22.16.55.39;	author edk;	state Exp;
branches;
next	;


desc
@@


1.16
log
@fix bug in impplementation of --clean_extra_items
@
text
@#!/usr/bin/perl

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

$main::eyebrowse_dir = "$ENV{SANDBOX}/data/eyebrowse";
main();

sub main
{
    checkEnvironment();

    my $options = getOptions();
    $main::dbh = getDatabaseConnection();
    my ($select, $ret);
    my $operation = $options->{operation};
    if ($operation eq 'create' or $operation eq 'update') {
        saveOperation($options, $main::dbh, $operation);
    } elsif ($operation eq 'reset_archive') {
        resetArchiveOperation($options, $main::dbh);
    } elsif ($operation eq 'check') {
        checkOperation($options, $main::dbh);
    } elsif ($operation eq 'delete') {
        deleteOperation($options, $main::dbh);
    } elsif ($operation eq 'debug') {
        debugOperation($options, $main::dbh, 'DEBUG',
                qw/existing missing all extra/);
    } else {
        showUsage("You must specify a valid operation.");
    }
    exit;
}

sub debugOperation
{
    my ($options, $dbh, $message, @@status) = @@_;
    # currently, $anzu_command_info is a command, and eyebrowse_control_info
    # is a list of arrays, one for each mailing list to be created.
    my $anzu_command_info = getAnzuInfo($options, $dbh);
    my $eyebrowse_control_info = getEbInfo($options, $dbh, $anzu_command_info);
    handleDebug($anzu_command_info, $eyebrowse_control_info, $options,
            $message, @@status);
}


sub checkOperation
{
    my ($options, $dbh) = @@_;
    
    debugOperation($options, $dbh, 'ERROR', qw/missing extra/);
    handleCheckStaleFiles();
}

# this is ugly.  it's really a hack here ... but one which looks like it's
# necessary.
sub resetArchiveOperation
{
    my ($options, $dbh) = @@_;
    my $anzu_command_info = getAnzuInfo($options, $dbh);
    if ($options->{type} eq 'anzu')
    {
        handleAnzuResetArchive($options, $anzu_command_info, qw/all/);
    }
    else
    {
        warn "unknown type for resetArchive : " + $options->{type};
    }
}

sub saveOperation
{
    my ($options, $dbh, $operation) = @@_;

    my $anzu_command_info = getAnzuInfo($options, $dbh);
    my $eyebrowse_control_info = undef;
    # either we'll save the missing items, or we'll save all items
    my $save_key = 'missing';

    if ($options->{wipe_existing_data} || $operation eq 'update')
    {
        $save_key = 'all';
    }
    if ($options->{type} eq 'eyebrowse')
    {
        $eyebrowse_control_info = getEbInfo($options, $dbh, $anzu_command_info);
        if ($options->{wipe_existing_data})
        {
            handleEyebrowseDelete($options,$eyebrowse_control_info,'existing');
        }
        handleEyebrowseCreate($options, $anzu_command_info,
                $eyebrowse_control_info, $save_key);
    }
    elsif ($options->{type} eq 'anzu')
    {
        if ($options->{wipe_existing_data})
        {
            handleAnzuDelete($options, $anzu_command_info, 'existing');
        }
        handleAnzuSave($options, $anzu_command_info, $save_key, $operation);
    }
    else
    {
        warn "unknown type for save : " + $options->{type};
    }
    handleCleanExtraData($options, $anzu_command_info, $eyebrowse_control_info);
}

sub deleteOperation
{
    my ($options, $dbh) = @@_;

    my $anzu_command_info = getAnzuInfo($options, $dbh);
    if ($options->{type} eq 'eyebrowse')
    {
        my $eyebrowse_control_info =
            getEbInfo($options, $dbh, $anzu_command_info);
        handleEyebrowseDelete($options, $eyebrowse_control_info,
                qw/existing extra/);
    }
    elsif ($options->{type} eq 'anzu')
    {
        handleAnzuDelete($options, $anzu_command_info, qw/all extra/);
    }
    else
    {
        warn "unknown type for delete : " + $options->{type};
    }
}

#################################
### handle any required actions
#################################

sub handleCleanExtraData
{
    my ($options, $anzu_command_info, $eyebrowse_control_info) = @@_;
    if ($options->{clean_extra_items})
    {
        if ($options->{type} eq 'eyebrowse')
        {
            handleEyebrowseDelete($options, $eyebrowse_control_info, 'extra');
        }
        elsif ($options->{type} eq 'anzu')
        {
            handleAnzuDelete($options, $anzu_command_info, 'extra');
        }
        else
        {
            warn "unknown type for handleCleanExtraData: " + $options->{type};
        }
    }
    else
    {
        handleDebug($anzu_command_info, $eyebrowse_control_info, $options,
                'ERROR', 'extra');
    }
}

sub handleDebug {
    my ($anzu_command_info, $eyebrowse_control_info, $options, $message,
            @@status) = @@_;

    my $aci = $anzu_command_info;

    foreach my $status (@@status) {
        if ($aci) {
            foreach my $domain (keys %{$aci->{$status}{domains}}) {
                print "$message: $status domain : $domain\n";
            }
            foreach my $domain (keys %{$aci->{$status}{projects}}) {
                foreach my $project (
                        keys %{$aci->{$status}{projects}{$domain}}) {
                    print "$message: $status project : $project in $domain\n";
                }
            }
            foreach my $domain (keys %{$aci->{$status}{lists}}) {
                foreach my $project (keys %{$aci->{$status}{lists}{$domain}}) {
                    foreach my $list (keys %{$aci->{$status}{lists}{$domain}{$project}}) {
                        print "$message: $status list: ",
                                getListAddress($domain, $project, $list), "\n";
                    }
                }
            }
        }
        if ($eyebrowse_control_info) {
            foreach my $list (keys %{$eyebrowse_control_info->{$status}}) {
                print "$message: $status eyebrowse list: $list\n";
            }
        }
    }
}

   
sub handleAnzuResetArchive
{
    my ($options, $anzu_command_info, @@status) = @@_;
    my $aci=$anzu_command_info;
    my @@anzu_command = ();
    foreach my $status (@@status) {
        foreach my $domain (keys %{$aci->{$status}{lists}}) {
            foreach my $project(keys %{$aci->{$status}{lists}{$domain}}) {
                foreach my $list (keys %{$aci->{$status}{lists}{$domain}{$project}}) {
                    print "RESET ARCHIVE : $list\@@$project.$domain\n"
                        if ($options->{debug});
                    push @@anzu_command,
                        [ 'ml', $domain, $project, 'reset_archive', $list ];
                }
            }
        }
    }
    runAnzuCommand(@@anzu_command) if scalar(@@anzu_command);
}

sub handleAnzuDelete
{
    my ($options, $anzu_command_info, @@status) = @@_;
    my $aci = $anzu_command_info;
    my @@anzu_command = ();
    foreach my $status (@@status) {
        foreach my $domain (keys %{$aci->{$status}{domains}}) {
            push @@anzu_command, [ 'delete_domain', $domain ];
        }
        foreach my $domain (keys %{$aci->{$status}{projects}}) {
            next if $aci->{$status}{domains}{$domain};
            foreach my $project (keys %{$aci->{$status}{projects}{$domain}}) {
                push @@anzu_command, [ 'delete_project', $domain, $project ];
            }
        }
        foreach my $domain (keys %{$aci->{$status}{lists}}) {
            next if $aci->{$status}{domains}{$domain};
            foreach my $project(keys %{$aci->{$status}{lists}{$domain}}) {
                next if $aci->{$status}{projects}{$domain}{$project};
                foreach my $list (keys %{$aci->{$status}{lists}{$domain}{$project}}) {
                    push @@anzu_command, 
                        [ 'ml', $domain, $project, 'delete', $list ] ;
                }
            }
        }
    }
    runAnzuCommand(@@anzu_command) if scalar(@@anzu_command);
}

sub handleAnzuSave
{
    my ($options, $anzu_command_info, $save_key, $operation) = @@_;

    handleEyebrowseDirCreate();
    handleEyebrowseDirChown();

    my @@anzu_command = ();

    my $aci = $anzu_command_info;

    foreach my $domain (keys %{$aci->{$save_key}{domains}})
    {
        if ($operation eq 'create' or
                !$aci->{existing}{domains}{$domain}) {
            push @@anzu_command, [ 'add_domain', $domain ];
        }
    }
    foreach my $domain (keys %{$aci->{$save_key}{projects}})
    {
        foreach my $project (keys %{$aci->{$save_key}{projects}{$domain}})
        {
            if ($operation eq 'create' or
                    !$aci->{existing}{projects}{$domain}{$project}) {
                push @@anzu_command, [ 'add_project', $domain, $project ];
            }
            my $projectID = $aci->{$save_key}{projects}{$domain}{$project};
            # TODO : this shouldn't be handled as a special case.
            my $subselect = getProjectOwners($main::dbh, $projectID);
            my $ownerAddress = '';
            while (my $ownerRecord = $subselect->fetchrow_hashref) {
                my $ownerLoginID = $ownerRecord->{LOGIN_NAME};
                $ownerAddress .= "\n" if $ownerAddress;
                $ownerAddress .= "$ENV{MAIL_PREFIX}$ownerLoginID\@@$domain";
            }
            push(@@anzu_command,  ['alias', $domain, $project, 'set',
                    'owner', $ownerAddress ]);
        }
    }
    foreach my $domain (keys %{$aci->{$save_key}{lists}})
    {
        foreach my $project (keys %{$aci->{$save_key}{lists}{$domain}})
        {
            foreach my $list (keys
                    %{$aci->{$save_key}{lists}{$domain}{$project}})
            {
                my ($type, $desc, $isPrivate) =
                    @@{$aci->{$save_key}{lists}{$domain}{$project}{$list}};
                my $archiver_address = "$ENV{MAIL_PREFIX}archive=mail-".
                    "$project=$list=$domain\@@$ENV{MAIL_ARCHIVE_HOST}";
                # TODO : set description during creation
                my $op;
                if ($aci->{existing}{lists}{$domain}{$project}{$list} && 
                        !$options->{wipe_existing_data})
                {
                    # for update, save the options which are maintained 
                    # separately from the list type in the helm UI:
                    # 'trailer, 'description', 'owner', 'prefix'
                    push(@@anzu_command, [ 'ml', $domain, $project, 'update',
                            $list, $type, 'trailer', 'description',
                            'owner', 'prefix' ]);
                }
                else
                {
                    push(@@anzu_command, [ 'ml', $domain, $project, 'create',
                            $list, $type ]);
                }
                push(@@anzu_command, [ 'ml', $domain, $project, 'subscribe',
                        $list, '', $archiver_address ]);
                if ($isPrivate)
                {
                    push (@@anzu_command, [ 'ml', $domain, $project,
                            'update_boolean', $list, 'sub_moderation', 'true']);
                }
            }
        }
    }
    foreach my $domain (keys %{$aci->{users}})
    {
        foreach my $user (keys %{$aci->{users}{$domain}})
        {
            push @@anzu_command, [ 'alias', $domain, 'www', 'set', $user,
                $aci->{users}{$domain}{$user} ];
        }
    }

    runAnzuCommand(@@anzu_command);
}

# this calls the eyebrowse wrapper script for each list to delete them all
sub handleEyebrowseDelete
{
    my ($options, $eyebrowse_control_info, $delete_key) = @@_;
    my @@eyebrowse_command_base = getEyebrowseCommandBase();
    $delete_key = 'all' unless $delete_key;

    foreach my $list_address (keys %{$eyebrowse_control_info->{$delete_key}})
    {
        system(@@eyebrowse_command_base, '--command','deletelist',
                '--listname', $list_address);
    }
    system('rm', '-fr',"$main::eyebrowse_dir");
}

# encapsulate logic for creating directory
sub handleEyebrowseDirCreate
{
    mkdir $main::eyebrowse_dir, 0755;
}

# encapsulate logic for chowning directory (well, as much as possible)
sub handleEyebrowseDirChown
{
    my ($options) = @@_;
    if ($> == 0) {
        print STDERR "Setting ownership of the eyebrowse data directory\n";
        system("chown","-R", "tigrisq.tigris", $main::eyebrowse_dir);
    }
}

sub getListAddress
{
    my ($domain, $project, $list) = @@_;
    if ($project eq 'www')
    {
        return "$ENV{MAIL_PREFIX}$list\@@$domain";
    }
    else
    {
        if ($ENV{IS_VHOSTING} eq 'false')
        {
            return "$ENV{MAIL_PREFIX}$project-$list\@@$domain";
        }
        else
        {
            return "$ENV{MAIL_PREFIX}$list\@@$project.$domain";
        }
    }
}

# generally eyebrowse lists should be created by anzu.  it the archive wasn't
# created, then we'll have to take a few extra steps ...
sub handleEyebrowseCreate
{
    my ($options,$anzu_command_info,$eyebrowse_control_info,$create_key) = @@_;
    my @@eyebrowse_command_base = getEyebrowseCommandBase();
    handleEyebrowseDirCreate();

    while (my ($list, $info) = each %{$eyebrowse_control_info->{$create_key}}) {
        warn "there may be a problem.  $list wasn't created in eb by anzu.\n";
        warn "creating it now, but this problem should be investigated.\n";
        my ($listID, $desc, $list_file_dir) = @@$info;
        my $list_file = "$list_file_dir/0mbox";
        print STDERR "adding list $list to eyebrowse database\n";
        system(@@eyebrowse_command_base, '--command', 'addlist', '--listname',
                $list, '--descr', $desc, '--listid', $listID);

        print STDERR "adding list file to eyebrowse database\n";
        system('mkdir', '-p', $list_file_dir);
        system('touch', $list_file);
        system(@@eyebrowse_command_base, '--command', 'addlistfile',
                '--listname', $list, '--listfile', $list_file);

	print STDERR "adding search-index $list_file_dir/index\n";
	mkdir ("$list_file_dir/index", 0755);
        system(@@eyebrowse_command_base, '--command', 'addindex', '--listname',
		$list, '--indexdir', "$list_file_dir/index");
    }
    handleEyebrowseDirChown();
    handleCleanExtraData($options, $anzu_command_info, $eyebrowse_control_info);
}

sub handleCheckStaleFiles
{
    # check for stale lock files
    dataDirectoryCheck("$ENV{SANDBOX}/data/eyebrowse", '.lck', 'eyebrowse');
    # check for evidence that anzu was killed while writing an options file
    # (unlikely race condition)
    dataDirectoryCheck("$ENV{SANDBOX}/data/anzu", '.new', 'anzu');
}

sub dataDirectoryCheck
{
    my ($start_dir, $ext, $component) = @@_;
    opendir(IN, "$start_dir");
    my @@stuff = map "$start_dir/$_", (grep !/^\.{1,2}$/, readdir(IN));
    closedir(IN);
    foreach my $item (@@stuff) {
        if (-f $item) {
            # look for lock files which are older than 4 hours (-M returns
            # last modified time in fracitional days)
            if ($item =~ m/\Q$ext\E$/ && 
                    (-M $item) * 24 * 60 * 60 > 1 * 60 * 60) {
                print "ERROR : stale $ext file in $component data dir: $item\n";
            }
        } elsif (-d $item) {
            dataDirectoryCheck($item, $ext, $component);
        } else {
            print "ERROR : invalid item in $component data dir: $item\n";
        }
    }
}

#################################
### process information according to business logic
#################################

sub getAnzuInfo
{
    my ($options, $dbh) = @@_;

    # first, get information on what projects, domains, and lists, etc are
    # defined in the helm database, compared with eyebrowse and anzu.
    my $anzu_data    = getAnzuDump    ($options, $dbh);
    
    my $control_info = {};

    my $select = getHelmDomains($main::dbh);
    while (my $domainRecord = $select->fetchrow_hashref) {
        my $domain = lc($domainRecord->{DOMAIN});
        next if ($domain =~ m/\*/);
        if ($anzu_data->{$domain}) {
            $control_info->{existing}{domains}{$domain} = 1;
        } else {
            $control_info->{missing}{domains}{$domain} = 1;
        }
        $control_info->{all}{domains}{$domain} = 1;
    }

    $select = getHelmProjects($main::dbh);
    while (my $projectRecord = $select->fetchrow_hashref) {
        my $project   = lc($projectRecord->{project});
        my $domain    = lc($projectRecord->{DOMAIN});
        my $projectID = $projectRecord->{projectID};
        my $info      = $projectID;
        next if ($project=~ m/\*/);
        # does this project exist in anzu?
        if ($anzu_data->{$domain} &&
                $anzu_data->{$domain}{$project}) {
            $control_info->{existing}{projects}{$domain}{$project} = $info;
        } else {
            $control_info->{missing}{projects}{$domain}{$project}=$info;
        }
        $control_info->{all}{projects}{$domain}{$project} = $info;
    }

    $select = getUsers($main::dbh);
    while(my $userRecord = $select->fetchrow_hashref) {
        my $user = lc($userRecord->{LOGIN_NAME});
        my $email = $userRecord->{EMAIL};
        my $domain = lc($userRecord->{DOMAIN});
        next if ($user =~m/\*/); # TODO : better weeding ?
        if ($domain =~ m/\*/) {  # TODO : better handling of wildcards / host ?
            foreach my $domain (keys %{$control_info->{all}{domains}}) {
                $control_info->{users}{$domain}{$user} = $email;
            }
            next;
        }
        $control_info->{users}{$domain}{$user} = $email;
    }

    $select = getHelmLists($main::dbh);
    while (my $mlRecord = $select->fetchrow_hashref) {
        my $list     = lc($mlRecord->{LIST_NAME});
        my $type     = $mlRecord->{TYPE};
        my $domain   = lc($mlRecord->{DOMAIN_NAME});
        my $project  = lc($mlRecord->{PROJECT_NAME});
        my $listID   = $mlRecord->{MAILINGLIST_ID};
        my $isPrivate= $mlRecord->{IS_PRIVATE} eq 'Y';
        my $desc     = $mlRecord->{DESCRIPTION};
        my $info     = [$type, $desc, $isPrivate];
        my $list_file_dir    =
            "$ENV{SANDBOX}/data/eyebrowse/$domain/$project/$list";
        my $list_address     = getListAddress($domain, $project, $list);
        my $eb_info          = [$listID,$desc,$list_file_dir];
        if ($anzu_data->{$domain} &&
                $anzu_data->{$domain}{$project} &&
                $anzu_data->{$domain}{$project}{$list}) {
            $control_info->{existing}{lists}{$domain}{$project}{$list} =
                $info;
        } else {
            $control_info->{missing}{lists}{$domain}{$project}{$list} =
                $info;
        }
        $control_info->{all}{lists}{$domain}{$project}{$list} = $info;
        # store some data for use by eyebrowse later
        $control_info->{eyebrowse}{"$list_address"} = $eb_info;
    }
    # find items in anzu which are not also in helm
    foreach my $domain (keys %$anzu_data) {
        if (!$control_info->{all}{domains}{$domain}) {
            $control_info->{extra}{domains}{$domain} = 1;
        }
        foreach my $project (keys %{$anzu_data->{$domain}}) {
            if (!$control_info->{all}{projects}{$domain}{$project}) {
                $control_info->{extra}{projects}{$domain}{$project} = 1;
            }
            foreach my $list (keys %{$anzu_data->{$domain}{$project}}) {
                if (!$control_info->{all}{lists}{$domain}{$project}{$list}) {
                    $control_info->{extra}{lists}{$domain}{$project}{$list} = 1;
                }
            }
        }
    }

    if ($options->{debug}) {
        print "anzu control_info: \n";
        foreach my $status (qw/existing missing all extra/) {
            my $hash = $control_info->{$status};
            print "Status $status anzu\n  Domains: \n";
            foreach my $domain (keys
                    %{$hash->{domains}}){
                print "    $domain\n";
            }
            print "  Projects: \n";
            foreach my $domain (keys %{$hash->{projects}}) {
                foreach my $project (keys %{$hash->{projects}{$domain}}) {
                    print "    $project $domain\n";
                }
            }
            print "  Lists: \n";
            foreach my $domain (keys %{$hash->{lists}}) {
                foreach my $project (keys %{$hash->{lists}{$domain}}) {
                    foreach my $list (keys
                            %{$hash->{lists}{$domain}{$project}}) {
                        print "    ", getListAddress($domain, $project, $list),
                                "\n";
                    }
                }
            }
        }
    }

    return $control_info;
}

sub getEbInfo
{
    my ($options, $dbh, $anzu_control) = @@_;
    my $eyebrowse_control_info = {};

    # get eyebrowse info, put it into a hashtable (to avoid linear scan)
    my $eb_lists     = getEbLists     ($options, $dbh);
    my %eb_lists = ();
    foreach my $list (@@$eb_lists)  {
        $eb_lists{$list} = 1;
    }
    # find items in helm which aren't in eyebrowse
    foreach my $domain (keys %{$anzu_control->{all}{lists}}) {
        foreach my $project (keys %{$anzu_control->{all}{lists}{$domain}}) {
            foreach my $list (keys %{$anzu_control->{all}{lists}{$domain}{$project}}) {
                my $list_address = getListAddress($domain, $project, $list);
                my $eb_info = $anzu_control->{eyebrowse}{"$list_address"};
                if (!$eb_lists{$list_address}) {
                    $eyebrowse_control_info->{missing}{$list_address}=$eb_info;
                } else {
                    $eyebrowse_control_info->{existing}{$list_address}=$eb_info;
                }
            }
        }
    }
    # find items in eyebrowse which aren't in helm
    foreach my $list_address (keys %eb_lists) {
        if (!$anzu_control->{eyebrowse}{"$list_address"})
        {
            $eyebrowse_control_info->{extra}{$list_address} = 1;
        }
    }

    if ($options->{debug}) {
        print "eyebrowse control_info:\n";
        foreach my $status (qw/existing missing all extra/) {
            print "Status $status eyebrowse\n  Lists: \n";
            foreach my $list (keys %{$eyebrowse_control_info->{$status}}) {
                print "    $list\n";
            }
        }
    }
    return $eyebrowse_control_info;
}

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

sub getAnzuDump
{
    my ($options, $dbh) = @@_;
    my @@command = (getAnzuCommandBase(), '--silent', 'dump');
    my (@@domains, @@projects, @@lists);
    my $anzu_data = {};
    open(DUMP, "-|") || do {
        close STDERR;
        open (STDERR, ">&STDOUT");
        exec @@command;
    };
    while (<DUMP>) {
        if (m/^domain (\S+)$/) {
            if ($anzu_data->{$1}) {
                die "internal error: already have domain $1\n";
            }
            $anzu_data->{$1} = {};
        } elsif (m/^project (\S+) (\S+)$/) {
            if ($anzu_data->{$1}->{$2}) {
                die "internal error: already have proj $2 in domain $1\n";
            }
            $anzu_data->{$1}->{$2} = {};
        } elsif (m/^list (\S+) (\S+) (\S+)$/) {
            if ($anzu_data->{$1}->{$2}->{$3}) {
                die "internal error: already have list $3 in $2 in $1\n";
            }
            $anzu_data->{$1}->{$2}->{$3} = 1;
        } else {
            die "internal error: invalid response from anzu harness: \n$_\n";
        }
    }
    close (DUMP);


    if ($options->{debug}) {
        print "anzu dump data:\n";
        while (my ($domain, $projects) = each %{$anzu_data}) {
            print "DOMAIN: $domain\n";
            while (my ($project, $lists) = each %$projects) {
                print "PROJECT: $project\n";
                foreach my $list(keys %$lists) {
                    print "MAILING LIST: $list\n";
                }
            }
        }
    }
    return $anzu_data;
}

sub getHelmDomains
{
    my ($dbh) = @@_;
    my $select  = $dbh->prepare(
            "SELECT HELM_PROJECT.NAME as DOMAIN ".
            "FROM HELM_PROJECT WHERE TYPE='domain'");
    my $ret  = $select->execute();
    warn "error selecting domains" if not $ret;
    return $select;
}

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

sub getProjectOwners
{
    my ($dbh, $projectID) = @@_;
    my $select = $dbh->prepare(
            "SELECT u.LOGIN_NAME ".
            "FROM HELM_USER u, HELM_USER_ROLE_PROJECT urp, HELM_ROLE r ".
            "WHERE u.USER_ID = urp.USER_ID and urp.PROJECT_ID = $projectID and ".
                "urp.ROLE_ID = r.ROLE_ID and r.NAME=\"Project Owner\"");
    my $ret    = $select->execute();
    warn "error selecting project owners" if not $ret;
    return $select;
}

sub getUsers
{
    my ($dbh) = @@_;
    my $select = $dbh->prepare(
            "SELECT LOGIN_NAME, EMAIL, HELM_PROJECT.NAME as DOMAIN ".
            "FROM HELM_USER, HELM_PROJECT ".
            "WHERE HELM_USER.DOMAIN_ID = HELM_PROJECT.PROJECT_ID");
    my $ret = $select->execute();
    warn "error selecting users" if not $ret;
    return $select;
}

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


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 getOptions
{
    my %options;
    if (!GetOptions(\%options,
                "type=s",
                "wipe_existing_data",
                "clean_extra_items",
                "help",
                "operation=s",
                "debug")
            or $options{help}) {
        showUsage();
    }

    $options{type} = 'anzu' if ($options{type} ne "eyebrowse");

    showUsage("A valid operation is required.")
        if ($options{operation} ne 'check' &&
                $options{operation} ne 'create' &&
                $options{operation} ne 'update' &&
                $options{operation} ne 'reset_archive' &&
                $options{operation} ne 'delete' &&
                $options{operation} ne 'debug');

    if ($options{operation} eq 'reset_archive' and $options{type} ne 'anzu') {
        showUsage("reset_archive is specific to type anzu"); 
    }

    return \%options;
}

sub showUsage
{
    my ($message) = @@_;
    print <<EOM;
Usage: anzu_admin [--type={type}] [--wipe_existing_data] [--help] [--debug]
           [--clean_extra_items] --operation={operation}
        type                    One of 'eyebrowse' or 'anzu' (default is anzu)
        wipe_existing_data      A flag indicating for wiping existing data
        clean_extra_items       A flag indicating for wiping extra lists, etc
        help                    Show this information
        operation               The operation : 'check', 'create', 'update',
                                'debug', 'delete', 'reset_archive'
        debug                   Verbose debugging output

Note that you must have the env variables from env.sh defined in order to
use this script.  wipe_existing_data is not meaningful for the check
operation.
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 getEbLists
{
    my @@eyebrowse_command_base = getEyebrowseCommandBase();
    open (IN, "-|") or exec @@eyebrowse_command_base, '--command','getlists';
    my @@existing_lists = ();
    while (<IN>) {
        chomp;
        push @@existing_lists, $_;
    }
    close(IN);
    return \@@existing_lists;
}
    
sub getEyebrowseCommandBase
{
    return  ("$ENV{SANDBOX}/site/scripts/eyebrowse/eyebrowse");
}

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

sub runAnzuCommand
{
    print STDERR "running anzu Harness; if this hangs, please kill it,\n";
    print STDERR "restart your sandbox, and try again.\n";
    sleep 2;

# TODO : use STDIN ... first escaping is necessary, since aliases can
# contain newlines (for several different addresses)
#    my @@command = (getAnzuCommandBase(), 'stdin_tab');
#    open(ANZU, "|-") or exec @@command;
#    foreach my $command (@@_) {
#        my @@clean_command = ();
#        foreach my $item (@@$command) {
#            $item =~ s/\t/' ' x 8/eg;
#            push @@clean_command, $item;
#        }
#        print "command: '", join(",", @@clean_command), "'\n";
#        print ANZU ((join "\t", @@clean_command), "\n");
#    }


    # we do this to avoid putting too many commands on one line (exec
    # stops working a little after the args array starts taking more than
    # 120kb)
    my @@command = (getAnzuCommandBase());
    my $i = 0;
    foreach my $command (@@_) {
        push @@command, @@$command, "\n";
        if (++$i > 50) {
            system(@@command);
            @@command = getAnzuCommandBase();
            $i = 0;
        }
    }
    system(@@command) if ($i > 0);
}
@


1.15
log
@HELM_DOMAIN is dead; cease to make reference to it
@
text
@d227 1
a227 1
            foreach my $project (keys %{$aci->{$status}{domains}{$domain}}) {
@


1.14
log
@* make the check operation less verbose
* change from 'extant' to 'existing' for mailing lists which are found
  (for clarity to end users -- extant is not widely in use)
@
text
@d683 2
a684 2
            "SELECT HELM_DOMAIN.NAME as DOMAIN ".
            "FROM HELM_DOMAIN");
d694 9
a702 5
            "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'");
d725 3
a727 3
            "SELECT LOGIN_NAME, EMAIL, HELM_DOMAIN.NAME as DOMAIN ".
            "FROM HELM_USER, HELM_DOMAIN ".
            "WHERE HELM_USER.DOMAIN_ID = HELM_DOMAIN.DOMAIN_ID");
d739 2
a740 1
        "FROM HELM_MAILINGLIST ml, HELM_PROJECT Project, HELM_DOMAIN Domain ".
d742 3
a744 1
            "Project.DOMAIN_ID = Domain.DOMAIN_ID");
@


1.13
log
@avoid putting too many anzu commands on a single line.  unfortunately,
we can't switch to the stdin method of providing commands without some
means of escaping/parsing the data ...
this avoids problems on sites with sufficiently many users.
@
text
@d28 2
a29 1
        debugOperation($options, $main::dbh, qw/extant missing all extra/);
d38 1
a38 1
    my ($options, $dbh, @@status) = @@_;
d43 2
a44 2
    handleDebug($anzu_command_info, $eyebrowse_control_info, 
            qw/extant missing all extra/);
d52 1
a52 1
    debugOperation($options, $dbh, qw/missing extra/);
d90 1
a90 1
            handleEyebrowseDelete($options,$eyebrowse_control_info,'extant');
d99 1
a99 1
            handleAnzuDelete($options, $anzu_command_info, 'extant');
d120 1
a120 1
                qw/extant extra/);
d156 2
a157 1
        handleDebug($anzu_command_info, $eyebrowse_control_info, 'extra');
d162 2
a163 1
    my ($anzu_command_info, $eyebrowse_control_info, @@status) = @@_;
d170 1
a170 1
                print "WARNING: $status domain : $domain\n";
d175 1
a175 1
                    print "WARNING: $status project : $project in $domain\n";
d181 1
a181 1
                        print "WARNING: $status list: ",
d189 1
a189 1
                print "WARNING: $status eyebrowse list: $list\n";
d259 1
a259 1
                !$aci->{extant}{domains}{$domain}) {
d268 1
a268 1
                    !$aci->{extant}{projects}{$domain}{$project}) {
d278 1
a278 1
                $ownerAddress .= "$ownerLoginID\@@$domain";
d297 1
a297 1
                if ($aci->{extant}{lists}{$domain}{$project}{$list} && 
d443 1
a443 1
            print "WARNING : invalid item in $component data dir: $item\n";
d467 1
a467 1
            $control_info->{extant}{domains}{$domain} = 1;
d484 1
a484 1
            $control_info->{extant}{projects}{$domain}{$project} = $info;
d523 1
a523 1
            $control_info->{extant}{lists}{$domain}{$project}{$list} =
d552 1
a552 1
        foreach my $status (qw/extant missing all extra/) {
d601 1
a601 1
                    $eyebrowse_control_info->{extant}{$list_address} =$eb_info;
d616 1
a616 1
        foreach my $status (qw/extant missing all extra/) {
@


1.12
log
@more options which should be saved: owner, prefix, and description
@
text
@d204 2
a205 2
                    push @@anzu_command, 'ml', $domain, $project,
                            'reset_archive', $list, "\n";
d220 1
a220 1
            push @@anzu_command, 'delete_domain', $domain, "\n";
d225 1
a225 1
                push @@anzu_command, 'delete_project', $domain, $project, "\n";
d233 2
a234 2
                    push @@anzu_command, 'ml', $domain, $project, 'delete',
                        $list, "\n";
d257 1
a257 1
            push @@anzu_command, 'add_domain', $domain, "\n";
d266 1
a266 1
                push @@anzu_command, 'add_project', $domain, $project, "\n";
d277 2
a278 2
            push(@@anzu_command, 'alias', $domain, $project, 'set',
                    'owner', $ownerAddress, "\n");
d300 1
a300 1
                    push(@@anzu_command, 'ml', $domain, $project, 'update',
d302 1
a302 1
                            'owner', 'prefix', "\n");
d306 2
a307 2
                    push(@@anzu_command, 'ml', $domain, $project, 'create',
                            $list, $type, "\n");
d309 2
a310 2
                push(@@anzu_command, 'ml', $domain, $project, 'subscribe',
                        $list, '', $archiver_address, "\n");
d313 2
a314 2
                    push (@@anzu_command,'ml',$domain,$project,'update_boolean',
                            $list, 'sub_moderation', 'true', "\n");
d323 2
a324 2
            push @@anzu_command, 'alias', $domain, 'www', 'set', $user,
                $aci->{users}{$domain}{$user}, "\n";
a843 1
    unshift @@_, getAnzuCommandBase();
d848 29
a876 1
    system(@@_);
@


1.11
log
@update for the new interface to the anzu harness class.  the main changes
are that commands are now separated by "\n", and it's possible to save
current options even when reapplying the type via update.
@
text
@d297 3
a299 2
                    # for update, save the trailer option (which we manage
                    # separately from the list type)
d301 2
a302 1
                            $list, $type, 'trailer', "\n");
@


1.10
log
@* handle --wipe + create operation cleanly
* handle IS_PRIVATE flag (setting sub_moderation as need be)
@
text
@d205 1
a205 1
                            'reset_archive', $list;
d220 1
a220 1
            push @@anzu_command, 'delete_domain', $domain;
d225 1
a225 1
                push @@anzu_command, 'delete_project', $domain, $project;
d233 2
a234 1
                    push @@anzu_command,'ml',$domain,$project,'delete',$list;
d257 1
a257 1
            push @@anzu_command, 'add_domain', $domain;
d266 1
a266 1
                push @@anzu_command, 'add_project', $domain, $project;
d278 1
a278 1
                    'owner', $ownerAddress);
d295 11
a305 4
                        !$options->{wipe_existing_data}) {
                    $op = 'update';
                } else {
                    $op = 'create';
a306 1
                push(@@anzu_command, 'ml', $domain, $project, $op, $list, $type);
d308 1
a308 1
                        $list, '', $archiver_address, '');
d311 2
a312 2
                    push (@@anzu_command, 'ml', $domain, $project,
                            'update_boolean', $list, 'sub_moderation', 'true');
d322 1
a322 1
                $aci->{users}{$domain}{$user};
@


1.10.6.1
log
@porting back changes to fix several problems:
* long command line (for sites with lots of users & etc)
* update works without blowing away data managed via the helm UI
Submitted by:	Ed Korthof <edk@@collab.net>
Reviewed by:	Manoj Kasichainula <manoj@@collab.net> (lightly reviewed)
@
text
@d204 2
a205 2
                    push @@anzu_command,
                        [ 'ml', $domain, $project, 'reset_archive', $list ];
d220 1
a220 1
            push @@anzu_command, [ 'delete_domain', $domain ];
d225 1
a225 1
                push @@anzu_command, [ 'delete_project', $domain, $project ];
d233 1
a233 2
                    push @@anzu_command, 
                        [ 'ml', $domain, $project, 'delete', $list ] ;
d256 1
a256 1
            push @@anzu_command, [ 'add_domain', $domain ];
d265 1
a265 1
                push @@anzu_command, [ 'add_project', $domain, $project ];
d276 2
a277 2
            push(@@anzu_command,  ['alias', $domain, $project, 'set',
                    'owner', $ownerAddress ]);
d294 4
a297 13
                        !$options->{wipe_existing_data})
                {
                    # for update, save the options which are maintained 
                    # separately from the list type in the helm UI:
                    # 'trailer, 'description', 'owner', 'prefix'
                    push(@@anzu_command, [ 'ml', $domain, $project, 'update',
                            $list, $type, 'trailer', 'description',
                            'owner', 'prefix' ]);
                }
                else
                {
                    push(@@anzu_command, [ 'ml', $domain, $project, 'create',
                            $list, $type ]);
d299 3
a301 2
                push(@@anzu_command, [ 'ml', $domain, $project, 'subscribe',
                        $list, '', $archiver_address ]);
d304 2
a305 2
                    push (@@anzu_command, [ 'ml', $domain, $project,
                            'update_boolean', $list, 'sub_moderation', 'true']);
d314 2
a315 2
            push @@anzu_command, [ 'alias', $domain, 'www', 'set', $user,
                $aci->{users}{$domain}{$user} ];
d835 1
d840 1
a840 29
# TODO : use STDIN ... first escaping is necessary, since aliases can
# contain newlines (for several different addresses)
#    my @@command = (getAnzuCommandBase(), 'stdin_tab');
#    open(ANZU, "|-") or exec @@command;
#    foreach my $command (@@_) {
#        my @@clean_command = ();
#        foreach my $item (@@$command) {
#            $item =~ s/\t/' ' x 8/eg;
#            push @@clean_command, $item;
#        }
#        print "command: '", join(",", @@clean_command), "'\n";
#        print ANZU ((join "\t", @@clean_command), "\n");
#    }


    # we do this to avoid putting too many commands on one line (exec
    # stops working a little after the args array starts taking more than
    # 120kb)
    my @@command = (getAnzuCommandBase());
    my $i = 0;
    foreach my $command (@@_) {
        push @@command, @@$command, "\n";
        if (++$i > 50) {
            system(@@command);
            @@command = getAnzuCommandBase();
            $i = 0;
        }
    }
    system(@@command) if ($i > 0);
@


1.10.6.1.2.1
log
@fix bug in impplementation of --clean_extra_items
@
text
@d224 1
a224 1
            foreach my $project (keys %{$aci->{$status}{projects}{$domain}}) {
@


1.10.6.2
log
@fix bug in impplementation of --clean_extra_items
@
text
@d224 1
a224 1
            foreach my $project (keys %{$aci->{$status}{projects}{$domain}}) {
@


1.9
log
@reset all archives, and only provide debugging info if its been requested
@
text
@d287 1
a287 1
                my ($type, $desc) =
d293 2
a294 1
                if ($aci->{extant}{lists}{$domain}{$project}{$list}) {
d302 5
d501 1
d503 1
a503 1
        my $info     = [$type, $desc];
d721 1
a721 1
        "SELECT LIST_NAME, ml.TYPE, Project.NAME as PROJECT_NAME, " .
@


1.8
log
@add a way to recreate the archive information for all mailing lists, eg.
when doing data migration.  this is getting clunky (time to reorganize
code again?).
@
text
@d63 1
a63 1
        handleAnzuResetArchive($options, $anzu_command_info, qw/extant/);
d202 2
a203 1
                    print "RESET ARCHIVE : $list\@@$project.$domain\n";
@


1.7
log
@* lowercase stuff from db (so we know whether or not it exists)
* use either create or update for mailing lists depending on which is
  appropriate
@
text
@d21 2
d55 16
d192 19
a217 1
print "status $status\n";
a218 1
print "deleting domain $domain\n";
d237 1
a237 1
    runAnzuCommand(@@anzu_command);
d758 1
d762 4
d780 1
a780 1
                                'debug', 'delete'
@


1.6
log
@use 'set' for owner alias for safety
@
text
@d8 1
a10 1
$main::eyebrowse_dir = "$ENV{SANDBOX}/data/eyebrowse";
d256 7
a262 2
                push(@@anzu_command, 'ml',$domain,$project,$operation,$list,
                        $type);
d410 1
a410 1
        my $domain = $domainRecord->{DOMAIN};
d422 2
a423 2
        my $project   = $projectRecord->{project};
        my $domain    = $projectRecord->{DOMAIN};
d439 1
a439 1
        my $user = $userRecord->{LOGIN_NAME};
d441 1
a441 1
        my $domain = $userRecord->{DOMAIN};
d454 1
a454 1
        my $list     = $mlRecord->{LIST_NAME};
d456 2
a457 2
        my $domain   = $mlRecord->{DOMAIN_NAME};
        my $project  = $mlRecord->{PROJECT_NAME};
@


1.5
log
@support update operation as well (for applying current list types from
db to lists)
@
text
@d240 1
a240 1
            push(@@anzu_command, 'alias', $domain, $project, $operation,
@


1.4
log
@* create user aliases
* handle deletion operation correctly for anzu
* support --clean_extra_items flag
@
text
@d18 4
a21 3
    if ($options->{operation} eq 'create') {
        createOperation($options, $main::dbh);
    } elsif ($options->{operation} eq 'check') {
d23 1
a23 1
    } elsif ($options->{operation} eq 'delete') {
d25 1
a25 1
    } elsif ($options->{operation} eq 'debug') {
d53 1
a53 1
sub createOperation
d55 1
a55 1
    my ($options, $dbh) = @@_;
d59 2
a60 2
    # either we'll create the missing items, or we'll create all items
    my $create_key = 'missing';
d62 1
a62 1
    if ($options->{wipe_existing_data})
d64 1
a64 1
        $create_key = 'all';
d74 1
a74 1
                $eyebrowse_control_info, $create_key);
d82 1
a82 1
        handleAnzuCreate($options, $anzu_command_info, $create_key);
d86 1
a86 1
        warn "unknown type for create : " + $options->{type};
d205 1
a205 1
sub handleAnzuCreate
d207 1
a207 1
    my ($options, $anzu_command_info, $create_key) = @@_;
d216 1
a216 1
    foreach my $domain (keys %{$aci->{$create_key}{domains}})
d218 4
a221 1
        push @@anzu_command, 'add_domain', $domain;
d223 1
a223 1
    foreach my $domain (keys %{$aci->{$create_key}{projects}})
d225 1
a225 1
        foreach my $project (keys %{$aci->{$create_key}{projects}{$domain}})
d227 5
a231 2
            push @@anzu_command, 'add_project', $domain, $project;
            my $projectID = $aci->{$create_key}{projects}{$domain}{$project};
d240 1
a240 1
            push(@@anzu_command, 'alias', $domain, $project, 'create',
d244 1
a244 1
    foreach my $domain (keys %{$aci->{$create_key}{lists}})
d246 1
a246 1
        foreach my $project (keys %{$aci->{$create_key}{lists}{$domain}})
d249 1
a249 1
                    %{$aci->{$create_key}{lists}{$domain}{$project}})
d252 1
a252 3
                    @@{$aci->{$create_key}{lists}{$domain}{$project}{$list}};
                # TODO : set description during creation
                push(@@anzu_command, 'ml',$domain,$project,'create',$list,$type);
d255 3
d717 1
d734 2
a735 2
        operation               The operation : 'check', 'create', 'delete',
                                'debug'
@


1.3
log
@fixes related to eb handling:
* make delete work again
* functionalize the operation of getting a list address, and handle the
  outstanding TODOs regarding vhosting
* describe extra lists accurately (there's no need to parse them)
@
text
@a69 1
            $create_key = 'all';
d79 1
a79 2
            $create_key = 'all';
            handleAnzuDelete($options, $eyebrowse_control_info, 'extant');
d180 1
d182 1
d255 8
d696 1
@


1.2
log
@this seems to work now, though it remains rather ugly.
@
text
@d101 2
a102 1
        handleEyebrowseDelete($options, $eyebrowse_control_info);
d161 2
a162 1
                        print "WARNING: $status list:$list\@@$project.$domain\n";
d290 19
d442 1
a442 2
        # TODO : handle vhosting as well
        my $list_address     = "$ENV{MAIL_PREFIX}$list\@@$project.$domain";
d494 2
a495 1
                        print "    $list\@@$project.$domain\n";
d520 1
a520 2
                # TODO : deal with vhosting
                my $list_address = "$ENV{MAIL_PREFIX}$list\@@$project.$domain";
a531 5
        my ($list, $project, $domain) =
            $list_address =~ m/^$ENV{MAIL_PREFIX}([^@@]+)\@@([^\.]+)\.(.*)$/
            or die "unable to parse list_address $list_address!";

                my $eb_info = $anzu_control->{eyebrowse}{"$list_address"};
d534 1
a534 1
            $eyebrowse_control_info->{extra}{$list} = 1;
@


1.1
log
@script for testing anzu repository, and for making it match what's in
helm, without deleting existing data
@
text
@d10 1
d18 2
a19 2
    if ($options->{operation} eq 'initialize') {
        handleInitialize($options, $main::dbh);
d21 5
a25 1
        handleCheck($options, $main::dbh);
d32 13
a44 1
sub handleCheck
d48 48
a95 2
    # currently, $anzu_command_info is a command, and eyebrowse_command_info
    # is a list of arrays, one for each mailing list to be created.
d97 48
a144 1
    my $eyebrowse_command_info = getEbInfo($options, $dbh, $anzu_command_info);
d146 16
a161 14
    foreach my $status (qw/missing extra/) {
        foreach my $domain (keys %{$anzu_command_info->{$status}{domains}}) {
            print "WARNING: $status domain : $domain\n";
        }
        foreach my $domain (keys %{$anzu_command_info->{$status}{projects}}) {
            foreach my $project (
                    keys %{$anzu_command_info->{$status}{projects}{$domain}}) {
                print "WARNING: $status project : $project in $domain\n";
            }
        }
        foreach my $domain (keys %{$anzu_command_info->{$status}{lists}}) {
            foreach my $project (keys %{$anzu_command_info->{$status}{lists}{$domain}}) {
                foreach my $list (keys %{$anzu_command_info->{$status}{lists}{$domain}{$project}}) {
                    print "WARNING: $status list : $list\@@$project.$domain\n";
d165 4
a168 2
        foreach my $list (keys %{$eyebrowse_command_info->{$status}}) {
            print "WARNING: $status eyebrowse list\n";
d171 1
d173 27
a199 2
    # TODO : check for stale lock files/other signs of sickness
    handleCheckStaleFiles();
d202 1
a202 1
sub handleInitialize
d204 6
a209 1
    my ($options, $dbh) = @@_;
d211 1
a211 4
    # currently, $anzu_command_info is a command, and eyebrowse_command_info
    # is a list of arrays, one for each mailing list to be created.
    my ($anzu_command_info, $eyebrowse_command_info) =
        constructCommandInfo($options, $dbh);
d213 21
a233 2
    if ($options->{type} eq 'all' or $options->{type} eq 'eyebrowse') {
        handleEyebrowseItems($options, $eyebrowse_command_info);
d235 17
a251 2
    if ($options->{type} eq 'all' or $options->{type} eq 'anzu') {
        handleAnzuItems($options, $anzu_command_info);
d253 2
d257 14
a270 3
#################################
### handle any required actions
#################################
d272 2
a273 1
sub handleAnzuItems
d275 2
a276 4
    my ($options, $anzu_command_info) = @@_;
    print STDERR "running anzu Harness; if this hangs, please kill it,\n";
    print STDERR "restart your sandbox, and try again.\n";
    sleep 2;
d278 8
a285 1
#    system(@@$anzu_command);
d288 1
d291 1
a291 1
sub handleEyebrowseItems
d293 1
a293 2
    my ($options, $eyebrowse_control_data) = @@_;
    my $eyebrowse_dir ="$ENV{SANDBOX}/data/eyebrowse";
d295 1
d297 1
a297 5
    mkdir $eyebrowse_dir, 0755;

    # we don't want to wipe existing data here, 'cause anzu should
    # already have done it.  so we only want to create missing lists
    while (my ($list, $info) = each %{$eyebrowse_control_data->{missing}}) {
d305 1
a306 1
    
d317 2
a318 16
    if ($> == 0) {
        print STDERR "Setting ownership of the eyebrowse data directory\n";
        system("chown","-R", "tigrisq.tigris", $eyebrowse_dir);
    }
    my @@extra_lists = keys %{$eyebrowse_control_data->{extra}};
    if (scalar(@@extra_lists)) {
        warn scalar(@@extra_lists) . " extra eb lists\n";
        if (!$options->{'clean-extra-info'}) {
            warn "not fixing\n";
        }
        foreach my $list (@@extra_lists) {
            print STDERR "removing extra list $list\n";
            system(@@eyebrowse_command_base, '--command','deletelist',
                    '--listname', $list);
        }
    }
d364 1
a364 1
    my $control_data = {};
d371 1
a371 1
            $control_data->{extant}{domains}{$domain} = 1;
d373 1
a373 1
            $control_data->{missing}{domains}{$domain} = 1;
d375 1
a375 1
        $control_data->{all}{domains}{$domain} = 1;
d383 1
a383 1
        my $info      = [ $domain, $projectID ];
d388 1
a388 1
            $control_data->{extant}{projects}{$domain}{$project} = $info;
d390 1
a390 1
            $control_data->{missing}{projects}{$domain}{$project}=$info;
d392 1
a392 1
        $control_data->{all}{projects}{$domain}{$project} = $info;
d402 2
a403 2
            foreach my $domain (keys %{$control_data->{all}{domains}}) {
                $control_data->{users}{$domain}{$user} = $email;
d407 1
a407 1
        $control_data->{users}{$domain}{$user} = $email;
d422 1
a422 1
        my $list_address     = "$list\@@$project.$domain";
d427 1
a427 1
            $control_data->{extant}{lists}{$domain}{$project}{$list} =
d430 1
a430 1
            $control_data->{missing}{lists}{$domain}{$project}{$list} =
d433 1
a433 1
        $control_data->{all}{lists}{$domain}{$project}{$list} = $info;
d435 1
a435 1
        $control_data->{eyebrowse}{"$list_address"} = $eb_info;
d439 2
a440 2
        if (!$control_data->{all}{domains}{$domain}) {
            $control_data->{extra}{domains}{$domain} = 1;
d443 2
a444 2
            if (!$control_data->{all}{projects}{$domain}{$project}) {
                $control_data->{extra}{projects}{$domain}{$project} = 1;
d447 2
a448 2
                if (!$control_data->{all}{lists}{$domain}{$project}{$list}) {
                    $control_data->{extra}{lists}{$domain}{$project}{$list} = 1;
d455 1
a455 1
        print "anzu control_data: \n";
d457 1
a457 1
            my $hash = $control_data->{$status};
d481 1
a481 1
    return $control_data;
d487 1
a487 1
    my $eyebrowse_control_data = {};
d490 1
a490 1
    my @@eb_lists     = getEbLists     ($options, $dbh);
d492 1
a492 1
    foreach my $list (@@eb_lists)  {
d500 4
a503 4
                my $listname = "$list\@@$project.$domain";
                if (!$eb_lists{$listname}) {
                    $eyebrowse_control_data->{missing}{$list} = 
                        $anzu_control->{all}{lists}{$domain}{$project}{$list};
d505 1
a505 2
                    $eyebrowse_control_data->{extant}{$list} = 
                        $anzu_control->{all}{lists}{$domain}{$project}{$list};
d511 9
a519 6
    foreach my $listname (keys %eb_lists) {
        my ($list, $project, $domain) = $listname =~ m/^(\w+)\@@([^\.]+)\.(.*)$/
            or die "unable to parse listname $listname!";
        if (!$anzu_control->{all}{lists}{$domain}{$project}{$list}) {
            $eyebrowse_control_data->{extra}{$list} =
                $anzu_control->{all}{lists}{$domain}{$project}{$list};
d524 1
a524 1
        print "eyebrowse control_data:\n";
d527 1
a527 1
            foreach my $list (keys %{$eyebrowse_control_data->{$status}}) {
d532 1
a532 1
    return $eyebrowse_control_data;
a534 26
#        push(@@anzu_command, 'ml',$domain,$project,'create',$list,$type);
#        if ("$ENV{MAIL_PREFIX}" ne '') {
#            push (@@anzu_command, 'ml', $domain, $project, 'update_string',
#                    $list, 'mail_prefix', "$ENV{MAIL_PREFIX}");
#        }
#        my $archiver_address = "$ENV{MAIL_PREFIX}archive=mail-$project=".
#            "$list=$domain\@@$ENV{MAIL_ARCHIVE_HOST}";
#        my $list             = "$ENV{MAIL_PREFIX}$list\@@$project.$domain";
#        my $list_file_dir    =
#            "$ENV{SANDBOX}/data/eyebrowse/$domain/$project/$list";
#
#        push(@@anzu_command, 'ml', $domain, $project, 'subscribe', $list, '',
#                $archiver_address, '');
#
#        push(@@anzu_command, 'add_project', $domain, $project);
#        # TODO : this shouldn't be handled as a special case.
#        my $subselect = getProjectOwners($main::dbh, $projectID);
#        my $ownerAddress = '';
#        while (my $ownerRecord = $subselect->fetchrow_hashref) {
#            my $ownerLoginID = $ownerRecord->{LOGIN_NAME};
#            $ownerAddress .= "\n" if $ownerAddress;
#            $ownerAddress .= "$ownerLoginID\@@$domain";
#        }
#        push(@@anzu_command, 'alias', $domain, $project, 'create',
#                'owner', $ownerAddress);
#
d672 1
a672 1
                "wipe-existing-data",
d680 1
a680 1
    $options{type} || ($options{type} = "all");
d682 1
a682 5
    showUsage("invalid type $options{type}\n") 
        if ($options{type} ne "anzu" and $options{type} ne "eyebrowse"
                and $options{type} ne "all");

    showUsage("A valid operation type is required.")
d684 3
a686 1
                $options{operation} ne 'initialize');
d695 5
a699 4
Usage: anzu_admin [--type={type}] [--wipe-existing-data] [--help] [--debug]
           --operation={operation}
        type                    One of 'all', 'eyebrowse', 'anzu'
        wipe-existing-data      A flag indicating for wiping existing data
d701 2
a702 1
        operation               The type of operation : 'check' or 'initialize'
d706 1
a706 1
use this script.  wipe-existing-data is not meaningful for the check
d745 10
@

