[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm /publisher lonpubdisplay.pm lonpublisher.pm
raeburn
raeburn at source.lon-capa.org
Mon Aug 4 14:42:04 EDT 2025
raeburn Mon Aug 4 18:42:04 2025 EDT
Modified files:
/loncom/publisher lonpublisher.pm lonpubdisplay.pm
/loncom/lonnet/perl lonnet.pm
Log:
- Move two routines in lonpublisher.pm to lonpubdisplay.pm to facilitate
facilitate calling lonpublisher::batchpublish() outside of Apache context.
- Response from lonnet::delenv() is returned by lonnet::remove_lock().
-------------- next part --------------
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.312 loncom/publisher/lonpublisher.pm:1.313
--- loncom/publisher/lonpublisher.pm:1.312 Sun Aug 3 18:18:36 2025
+++ loncom/publisher/lonpublisher.pm Mon Aug 4 18:42:04 2025
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.312 2025/08/03 18:18:36 raeburn Exp $
+# $Id: lonpublisher.pm,v 1.313 2025/08/04 18:42:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2169,6 +2169,73 @@
}
}
+sub coursedependencies {
+ my $url=&Apache::lonnet::declutter(shift);
+ $url=~s/\.meta$//;
+ my ($adomain,$aauthor)=($url=~ m{^($match_domain)/($match_username)/});
+ my $regexp=quotemeta($url);
+ $regexp='___'.$regexp.'___course';
+ my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
+ $aauthor,$regexp);
+ my %courses=();
+ foreach my $item (keys(%evaldata)) {
+ if ($item=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
+ $courses{$1}=1;
+ }
+ }
+ return %courses;
+}
+
+# =============================================================== Notifications
+sub notifications {
+# --------------------------------------------------- Send update notifications
+ if (ref($modified_urls) eq 'ARRAY') {
+ foreach my $targetsource (@{$modified_urls}){
+ my ($target,$source)=@{$targetsource};
+ my ($logfile,$canlog);
+ if (open($logfile,'>>',$source.'.log')) {
+ $canlog = 1;
+ }
+ print $logfile "\nNotifications\n" if ($canlog);
+ my @subscribed=&get_subscribed_hosts($target);
+ foreach my $subhost (@subscribed) {
+ print $logfile "\nNotifying host ".$subhost.':' if ($canlog);
+ my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
+ print $logfile $reply if ($canlog);
+ }
+# ---------------------------------------- Send update notifications, meta only
+ my @subscribedmeta=&get_subscribed_hosts("$target.meta");
+ foreach my $subhost (@subscribedmeta) {
+ print $logfile "\nNotifying host for metadata only ".$subhost.':' if ($canlog);
+ my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
+ $subhost);
+ print $logfile $reply if ($canlog);
+ }
+# --------------------------------------------------- Notify subscribed courses
+ my %courses=&coursedependencies($target);
+ my $now=time;
+ foreach my $course (keys(%courses)) {
+ print $logfile "\nNotifying course ".$course.':' if ($canlog);
+ my ($cdom,$cname)=split(/\_/,$course);
+ my $reply=&Apache::lonnet::cput
+ ('versionupdate',{$target => $now},$cdom,$cname);
+ print $logfile $reply if ($canlog);
+ }
+ if ($canlog) {
+ print $logfile "\n============ Done ============\n";
+ close($logfile);
+ }
+ }
+ $modified_urls = [];
+ }
+ if ($lock) {
+ if (&Apache::lonnet::remove_lock($lock) eq 'ok') {
+ undef($lock);
+ }
+ }
+ return;
+}
+
#########################################
sub batchpublish {
Index: loncom/publisher/lonpubdisplay.pm
diff -u loncom/publisher/lonpubdisplay.pm:1.4 loncom/publisher/lonpubdisplay.pm:1.5
--- loncom/publisher/lonpubdisplay.pm:1.4 Sun Aug 3 16:11:19 2025
+++ loncom/publisher/lonpubdisplay.pm Mon Aug 4 18:42:04 2025
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpubdisplay.pm,v 1.4 2025/08/03 16:11:19 raeburn Exp $
+# $Id: lonpubdisplay.pm,v 1.5 2025/08/04 18:42:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -124,23 +124,6 @@
#########################################
#########################################
-sub coursedependencies {
- my $url=&Apache::lonnet::declutter(shift);
- $url=~s/\.meta$//;
- my ($adomain,$aauthor)=($url=~ m{^($match_domain)/($match_username)/});
- my $regexp=quotemeta($url);
- $regexp='___'.$regexp.'___course';
- my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
- $aauthor,$regexp);
- my %courses=();
- foreach my $item (keys(%evaldata)) {
- if ($item=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
- $courses{$1}=1;
- }
- }
- return %courses;
-}
-
sub notify_in_cleanup {
my ($r) = @_;
unless ($registered_cleanup) {
@@ -154,45 +137,13 @@
sub notify {
# --------------------------------------------------- Send update notifications
if (ref($Apache::lonpublisher::modified_urls) eq 'ARRAY') {
- foreach my $targetsource (@{$Apache::lonpublisher::modified_urls}){
- my ($target,$source)=@{$targetsource};
- my ($logfile,$canlog);
- if (open($logfile,'>>',$source.'.log')) {
- $canlog = 1;
- }
- print $logfile "\nCleanup phase: Notifications\n" if ($canlog);
- my @subscribed=&Apache::lonpublisher::get_subscribed_hosts($target);
- foreach my $subhost (@subscribed) {
- print $logfile "\nNotifying host ".$subhost.':' if ($canlog);
- my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
- print $logfile $reply if ($canlog);
- }
-# ---------------------------------------- Send update notifications, meta only
- my @subscribedmeta=&Apache::lonpublisher::get_subscribed_hosts("$target.meta");
- foreach my $subhost (@subscribedmeta) {
- print $logfile "\nNotifying host for metadata only ".$subhost.':' if ($canlog);
- my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
- $subhost);
- print $logfile $reply if ($canlog);
- }
-# --------------------------------------------------- Notify subscribed courses
- my %courses=&coursedependencies($target);
- my $now=time;
- foreach my $course (keys(%courses)) {
- print $logfile "\nNotifying course ".$course.':' if ($canlog);
- my ($cdom,$cname)=split(/\_/,$course);
- my $reply=&Apache::lonnet::cput
- ('versionupdate',{$target => $now},$cdom,$cname);
- print $logfile $reply if ($canlog);
- }
- if ($canlog) {
- print $logfile "\n============ Done ============\n";
- close($logfile);
- }
+ &Apache::lonpublisher::notifications();
+ }
+ if ($Apache::lonpublisher::lock) {
+ if (&Apache::lonnet::remove_lock($Apache::lonpublisher::lock) eq 'ok') {
+ undef($Apache::lonpublisher::lock);
}
- $Apache::lonpublisher::modified_urls = [];
}
- if ($Apache::lonpublisher::lock) { &Apache::lonnet::remove_lock($Apache::lonpublisher::lock); }
return OK;
}
@@ -261,7 +212,6 @@
$Apache::lonpublisher::cudom = '';
%Apache::lonpublisher::metadatafields = ();
%Apache::lonpublisher::metadatakeys = ();
- @{$Apache::lonpublisher::modified_urls} = ();
}
#########################################
@@ -277,6 +227,7 @@
# Initialize globals in Apache::lonpublisher
&reset_globals();
+ @{$Apache::lonpublisher::modified_urls} = ();
# Get query string for limited number of parameters
@@ -285,7 +236,7 @@
# -------------------------------------- Flag and buffer for registered cleanup
$registered_cleanup=0;
- @{$Apache::lonpublisher::modified_urls}=();
+ @{$Apache::lonpublisher::modified_urls} = ();
# -------------------------------------------------------------- Check filename
my $fn=&unescape($env{'form.filename'});
@@ -319,6 +270,7 @@
$r->log_reason($cuname.' at '.$cudom.
' trying to publish empty filename', $r->filename);
&reset_globals();
+ @{$Apache::lonpublisher::modified_urls} = ();
return HTTP_NOT_FOUND;
}
@@ -328,6 +280,7 @@
$env{'form.filename'}.' ('.$fn.')',
$r->filename);
&reset_globals();
+ @{$Apache::lonpublisher::modified_urls} = ();
return HTTP_NOT_FOUND;
}
@@ -511,7 +464,8 @@
$thisembstyle,$thisdistarget);
$r->print($output);
# ------------------------------------------------------------- Trigger updates
- if (@{$Apache::lonpublisher::modified_urls}) {
+ if ((ref($Apache::lonpublisher::modified_urls) eq 'ARRAY') &&
+ (@{$Apache::lonpublisher::modified_urls})) {
¬ify_in_cleanup($r);
}
}
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1540 loncom/lonnet/perl/lonnet.pm:1.1541
--- loncom/lonnet/perl/lonnet.pm:1.1540 Thu Jul 31 15:47:25 2025
+++ loncom/lonnet/perl/lonnet.pm Mon Aug 4 18:42:04 2025
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1540 2025/07/31 15:47:25 raeburn Exp $
+# $Id: lonnet.pm,v 1.1541 2025/08/04 18:42:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -998,7 +998,7 @@
}
}
&appenv({'session.locks' => $newlocks});
- &delenv('session.lock.'.$id);
+ return &delenv('session.lock.'.$id);
}
sub remove_all_locks {
More information about the LON-CAPA-cvs
mailing list