--- loncom/interface/lonmodifycourse.pm 2019/04/29 22:19:24 1.94 +++ loncom/interface/lonmodifycourse.pm 2019/07/25 20:23:52 1.95 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # handler for DC-only modifiable course settings # -# $Id: lonmodifycourse.pm,v 1.94 2019/04/29 22:19:24 raeburn Exp $ +# $Id: lonmodifycourse.pm,v 1.95 2019/07/25 20:23:52 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -39,6 +39,9 @@ use Apache::lonpickcourse; use lib '/home/httpd/lib/perl'; use LONCAPA qw(:DEFAULT :match); +my $registered_cleanup; +my $modified_dom; + sub get_dc_settable { my ($type,$cdom) = @_; if ($type eq 'Community') { @@ -1484,6 +1487,18 @@ sub modify_course { my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime'); if (($putres eq 'ok') && (($changed{'owner'} || $changed{'code'}))) { &update_coowners($cdom,$cnum,$chome,\%settings,\%newattr); + if ($changed{'code'}) { + &Apache::lonnet::devalidate_cache_new('instcats',$cdom); + # Update cache of self-cataloging courses on institution's server(s). + if (&Apache::lonnet::shared_institution($cdom)) { + unless ($registered_cleanup) { + my $handlers = $r->get_handlers('PerlCleanupHandler'); + $r->set_handlers('PerlCleanupHandler' => [\&devalidate_remote_instcats,@{$handlers}]); + $registered_cleanup=1; + $modified_dom = $cdom; + } + } + } } } } @@ -2539,6 +2554,22 @@ sub get_permission { return ($allowed,\%permission); } +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; +} + sub handler { my $r = shift; if ($r->header_only) { @@ -2547,6 +2578,9 @@ sub handler { return OK; } + $registered_cleanup=0; + $modified_dom = ''; + my $dom = $env{'request.role.domain'}; my $domdesc = &Apache::lonnet::domain($dom,'description'); my ($allowed,$permission) = &get_permission($dom);