[LON-CAPA-cvs] cvs: loncom /automation Autocreate.pl
raeburn
raeburn@source.lon-capa.org
Mon, 07 Mar 2011 02:10:40 -0000
raeburn Mon Mar 7 02:10:40 2011 EDT
Modified files:
/loncom/automation Autocreate.pl
Log:
- Bug 6287.
- New routines to set/unset %env for designated DC in whose name course creation
is processed eliminate duplicate code.
Index: loncom/automation/Autocreate.pl
diff -u loncom/automation/Autocreate.pl:1.18 loncom/automation/Autocreate.pl:1.19
--- loncom/automation/Autocreate.pl:1.18 Sun Mar 6 21:44:14 2011
+++ loncom/automation/Autocreate.pl Mon Mar 7 02:10:40 2011
@@ -2,7 +2,7 @@
#
# Automated Course Creation script
#
-# $Id: Autocreate.pl,v 1.18 2011/03/06 21:44:14 raeburn Exp $
+# $Id: Autocreate.pl,v 1.19 2011/03/07 02:10:40 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -110,15 +110,14 @@
close($fh);
exit;
}
- $env{'user.name'} = $dcname;
- $env{'user.domain'} = $dcdom;
- $env{'request.role.domain'} = $defdom;
+ &set_dc_env($dcname,$dcdom,$defdom);
my @permissions = ('mau','ccc','cin','cta','cep','ccr','cst');
my %permissionflags = ();
&set_permissions(\%permissionflags,\@permissions);
my $output = &process_xml($fh,$defdom,$dcname,$dcdom);
- print $output;
&unset_permissions(\%permissionflags);
+ &unset_dc_env();
+ print $output;
}
} else {
my @permissions = ('mau','ccc','cin','cta','cep','ccr','cst');
@@ -149,7 +148,9 @@
}
}
if ($settings->{'req'}) {
+ &set_dc_env($dcname,$dcdom);
my $output = &Apache::loncoursequeueadmin::process_official_reqs('auto',$dom,$dcname,$dcdom);
+ &unset_dc_env();
if ($output) {
print $fh $output;
}
@@ -164,10 +165,7 @@
sub process_xml {
my ($fh,$dom,$dcname,$dcdom) = @_;
- $env{'user.name'} = $dcname;
- $env{'user.domain'} = $dcdom;
- $env{'request.role.domain'} = $dom;
-
+ &set_dc_env($dcname.$dcdom,$dom);
# Initialize language handler
&Apache::lonlocal::get_language_handle();
@@ -211,9 +209,7 @@
$output .= $newcourse.':';
}
$output =~ s/:$//;
- delete($env{'user.name'});
- delete($env{'user.domain'});
- delete($env{'request.role.domain'});
+ &unset_dc_env();
return $output;
}
@@ -243,3 +239,24 @@
delete($env{"allowed.$allowtype"});
}
}
+
+sub set_dc_env {
+ my ($dcname,$dcdom,$defdom) = @_;
+ $env{'user.name'} = $dcname;
+ $env{'user.domain'} = $dcdom;
+ $env{'user.home'} = &Apache::lonnet::homeserver($dcname,$dcdom);
+ if ($defdom ne '') {
+ $env{'request.role.domain'} = $defdom;
+ }
+ return;
+}
+
+sub unset_dc_env {
+ delete($env{'user.name'});
+ delete($env{'user.domain'});
+ delete($env{'user.home'});
+ if ($env{'request.role.domain'}) {
+ delete($env{'request.role.domain'});
+ }
+ return;
+}