--- loncom/interface/loncreatecourse.pm 2017/08/07 20:22:13 1.166 +++ loncom/interface/loncreatecourse.pm 2019/07/25 20:23:52 1.171 @@ -1,7 +1,7 @@ # The LearningOnline Network # Create a course # -# $Id: loncreatecourse.pm,v 1.166 2017/08/07 20:22:13 raeburn Exp $ +# $Id: loncreatecourse.pm,v 1.171 2019/07/25 20:23:52 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -82,7 +82,11 @@ use Apache::lonlocal; use Apache::lonuserutils; use Apache::lonclonecourse; use LONCAPA::batchcreatecourse; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); + +my $registered_flush; +my $registered_instcats; +my $modified_dom; # ===================================================== Phase one: fill-in form @@ -106,8 +110,8 @@ sub print_course_creation_page { $course_home .= qq{>$server $host_servers{$server}}; } $course_home .= "\n\n"; - my ($trustedref,$untrustedref) = &Apache::lonnet::trusted_domains('enroll',$defdom); - my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain',undef,undef,undef,$trustedref,$untrustedref); + my ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom); + my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain',undef,undef,undef,$trusted,$untrusted); my $cloneform=&Apache::loncommon::select_dom_form ($env{'request.role.domain'},'clonedomain'). &Apache::loncommon::selectcourse_link @@ -764,8 +768,10 @@ sub create_course { '
'.&mt('Course identifier to share with students: [_1]',$code).'
' ); } - # Flush the course logs so reverse user roles immediately updated - $r->register_cleanup(\&Apache::lonnet::flushcourselogs); + if ($env{'form.crscode'} ne '') { + &Apache::lonnet::devalidate_cache_new('instcats',$crsudom); + } + ®ister_cleanups($r,$crsudom,$env{'form.crscode'}); $r->print(''.&mt('Roles will be active at next login').'.
'); } $r->print(''.
@@ -889,42 +895,66 @@ sub upload_batchfile {
sub process_batchfile {
my $r = shift;
- my $start_page =
- &Apache::loncommon::start_page('Create a New Course, Community or Placement Test');
- my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses');
- my $end_page =
- &Apache::loncommon::end_page();
my $defdom=$env{'request.role.domain'};
- my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
- 'batchupload',undef,undef,
- undef,undef,$defdom);
- my ($batchdir,$filename) = ($batchfilepath =~ m-^(.+)/pending/([^/]+)$-);
- my ($result,$logmsg);
- if (-e "$batchfilepath") {
- open(FILE,"<$batchfilepath");
- my @buffer = '.&mt('Could not open attributes file.').' '.&mt('No uploaded attributes file found.').' '.&mt('Invalid path to attributes file.').' '.&mt("Your username, domain, and/or your current role's domain are missing or contain invalid characters.").
+ '
'.&mt('No courses created.').'
'.&mt('No courses created.').'
'.&mt('No courses created.').'
'.&mt('No courses created.').'
'.
- &mt('Creation options menu').''.$end_page);
+ $r->print(&Apache::loncommon::start_page('Create a New Course, Community or Placement Test').
+ &Apache::lonhtmlcommon::breadcrumbs('Creation Outcome','Create_Course',undef,'Create_Courses').
+ $logmsg.$result.'
'.
+ &mt('Creation options menu').''.
+ &Apache::loncommon::end_page());
}
@@ -1317,6 +1347,44 @@ sub get_permission {
return ($allowed,\%permission);
}
+sub register_cleanups {
+ my ($r,$cdom,$updatecats) = @_;
+ # Flush the course logs so reverse user roles immediately updated
+ unless ($registered_flush) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\&Apache::lonnet::flushcourselogs,@{$handlers}]);
+ $registered_flush=1;
+ }
+ # Update cache of self-cataloging courses on institution's server(s).
+ if ($updatecats) {
+ if (&Apache::lonnet::shared_institution($cdom)) {
+ unless ($registered_instcats) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]);
+ $registered_instcats=1;
+ $modified_dom = $cdom;
+ }
+ }
+ }
+ return;
+}
+
+sub devalidate_remote_instcats {
+ if ($modified_dom ne '') {
+ my %servers = &Apache::lonnet::internet_dom_servers($modified_dom);
+ my %thismachine;
+ map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
+ if (keys(%servers)) {
+ foreach my $server (keys(%servers)) {
+ next if ($thismachine{$server});
+ &Apache::lonnet::remote_devalidate_cache($server,['instcats:'.$modified_dom]);
+ }
+ }
+ $modified_dom = '';
+ }
+ return;
+}
+
# ===================================================================== Handler
sub handler {
my $r = shift;
@@ -1327,6 +1395,10 @@ sub handler {
return OK;
}
+ $registered_flush = 0;
+ $registered_instcats = 0;
+ $modified_dom = '';
+
my ($allowed,$permission) = &get_permission($env{'request.role.domain'});
if ($allowed) {
my $show_all_choices = 0;