#!/usr/bin/perl -w
# migrate_3.2.8_to_3.2.9 
# change all assistent to assistant
# (c) 2005 by Christian Kuelker, 
# License: GPLv2

use strict;

# +=======================================================================+
# || fix assistent -> assistant problem                                  ||
# +=======================================================================+

# list all roles
print "* get all cipux roles\n";
my @r= `cipux_task_list_roles`;
my %r =();
foreach(@r){
    chomp;
    $r{$_}=1;
    print "  - $_\n";
}


# if the naughty assistent is defined change it ...
if(defined($r{assistent})){
    print "* bad role assistent is defined ...\n";
    
    # list all user
    my @u= `cipux_task_list_users`;
    my %u =();
    
    # set all course roles from 'asstent' to 'assistant'
    foreach(@u){
	chomp;
	print "  - examine user $_ ...\n";
	$u{$_}=1;
	my $r = `cipux_get_value -c $_ -e cipuxRole`;
	chomp($r);
	if($r eq 'assistent'){
	    print "  -  got assistent $_ as role, changing  it ...\n";
	    `cipux_set_value -c $_ -e cipuxRole -v assistant`;
	}
    }
    
    # set all cipux CAT variables from 'assistent' to 'assistant'
    my @c = `cipux_get_value -x CAT -e cipuxVariable|grep assistent`;
    
    print "  - examine all config variables ...\n";
    foreach(@c){
	chomp;
	print "config [$_]\n";
	s/assistent/assistant/g;
	`cipux_set_value -a -x CAT -e cipuxVariable -v '$_'`;
	print "  - changed CAT variable $_\n";
    }
    
    # rename user assistent to assistant
    if( defined( $r{assistent} ) ){
	print "* rename assistent to assistant\n";     
	system("cipux_change -u assistent -e assistant");
	system("cipux_change -c assistent -e assistant");
    }	
 	print "* role should be fixed now\n";	
}else{		
  	print "* every thing seems ok ...\n";
}	

