[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface loncreatecourse.pm

raeburn raeburn at source.lon-capa.org
Fri Jul 26 13:27:44 EDT 2019


raeburn		Fri Jul 26 17:27:44 2019 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	loncreatecourse.pm 
  Log:
  -  or 2.11
    Backport 1.170, 1.171, 1.172
  Cckport 1.170, 1.171, 1.172VS: ----------------------------------------------------------------------
  
  
Index: loncom/interface/loncreatecourse.pm
diff -u loncom/interface/loncreatecourse.pm:1.158.2.4 loncom/interface/loncreatecourse.pm:1.158.2.5
--- loncom/interface/loncreatecourse.pm:1.158.2.4	Tue Sep 11 19:39:58 2018
+++ loncom/interface/loncreatecourse.pm	Fri Jul 26 17:27:44 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Create a course
 #
-# $Id: loncreatecourse.pm,v 1.158.2.4 2018/09/11 19:39:58 raeburn Exp $
+# $Id: loncreatecourse.pm,v 1.158.2.5 2019/07/26 17:27:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -84,6 +84,10 @@
 use LONCAPA::batchcreatecourse;
 use LONCAPA qw(:DEFAULT :match);
 
+my $registered_flush;
+my $registered_instcats;
+my $modified_dom;
+
 # ===================================================== Phase one: fill-in form
 
 sub print_course_creation_page {
@@ -731,8 +735,10 @@
                       '<p>'.&mt('Course identifier to share with students: [_1]',$code).'</p>'
                      );
         }
-        # 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);
+        }
+        &register_cleanups($r,$crsudom,$env{'form.crscode'});
 	$r->print('<p>'.&mt('Roles will be active at next login').'.</p>');
     }
     $r->print('<p><a href="/adm/createcourse?phase='.lc($crstype).'one">'.
@@ -852,12 +858,12 @@
     my $uname = $env{'user.name'};
     my $udom = $env{'user.domain'};
     my $dir = &LONCAPA::tempdir().'addcourse';
-    my ($result,$logmsg);
+    my ($result,$logmsg,$keysmsg,$codesref,$instcodesref);
     if (($defdom =~ /^$match_domain$/) && ($uname =~ /^$match_username$/) && ($udom =~/^$match_domain$/)) {
         my $batchfilepath=&Apache::lonnet::userfileupload('coursecreatorxml',undef,
                                                           'batchupload',undef,undef,
                                                           undef,undef,$defdom);
-        if ($batchfilepath =~ m{^(\Q$dir/$defdom/web/$uname\_$udom\E)/pending/([^/]+)$}) {
+        if ($batchfilepath =~ m{^(\Q$dir/$defdom/web/$uname\E_\Q$udom\E)/pending/([^/]+)$}) {
             my ($batchdir,$filename) = ($1,$2);
             if (-e "$batchfilepath") {
                 if (open(FILE,"<",$batchfilepath)) {
@@ -866,9 +872,10 @@
                     if ((defined($filename)) && (defined($batchdir))) {
                         my @requests = ($filename);
                         my %courseids = ();
-                        ($result,$logmsg) = &LONCAPA::batchcreatecourse::create_courses(
-                                                    \@requests,\%courseids,'web',$defdom,
-                                                    $uname,$udom);
+                       ($result,$logmsg,$keysmsg,$codesref,$instcodesref) =
+                            &LONCAPA::batchcreatecourse::create_courses(
+                                       \@requests,\%courseids,'web',$defdom,
+                                       $uname,$udom);
                         if (keys(%courseids) > 0) {
                             if (!-e "$batchdir/processed") {
                                 mkdir("$batchdir/processed", 0755);
@@ -882,6 +889,13 @@
                             if (-e "$batchdir/processed/$filename") {
                                 unlink("$batchdir/pending/$filename");
                             }
+                            my $updatecats;
+                            if ((ref($instcodesref) eq 'HASH') && (keys(%{$instcodesref}) > 0)) {
+                                &Apache::lonnet::devalidate_cache_new('instcats',$defdom);
+                                $updatecats = 1;
+                            }
+                            &register_cleanups($r,$defdom,$updatecats);
+
                         }
                     }
                 } else {
@@ -1289,6 +1303,44 @@
     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;
@@ -1299,6 +1351,10 @@
        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;




More information about the LON-CAPA-cvs mailing list