--- loncom/publisher/lonpublisher.pm 2024/06/01 22:25:23 1.304 +++ loncom/publisher/lonpublisher.pm 2025/01/04 21:23:33 1.307 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Publication Handler # -# $Id: lonpublisher.pm,v 1.304 2024/06/01 22:25:23 raeburn Exp $ +# $Id: lonpublisher.pm,v 1.307 2025/01/04 21:23:33 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -428,7 +428,7 @@ sub common_access { } my %lt = &Apache::lonlocal::texthash( 'default' => 'System wide - can be used for any courses system wide', - 'domain' => 'Domain only - use limited to courses in the domai', + 'domain' => 'Domain only - use limited to courses in the domain', 'custom' => 'Customized right of use ...', 'public' => 'Public - no authentication or authorization required for use', 'closed' => 'Closed - XML source is closed to everyone', @@ -2197,36 +2197,39 @@ sub notify_in_cleanup { # =============================================================== Notifications sub notify { # --------------------------------------------------- Send update notifications - foreach my $targetsource (@{$modified_urls}){ - my ($target,$source)=@{$targetsource}; - my $logfile=Apache::File->new('>>'.$source.'.log'); - print $logfile "\nCleanup phase: Notifications\n"; - my @subscribed=&get_subscribed_hosts($target); - foreach my $subhost (@subscribed) { - print $logfile "\nNotifying host ".$subhost.':'; - my $reply=&Apache::lonnet::critical('update:'.$target,$subhost); - print $logfile $reply; - } + if (ref($modified_urls) eq 'ARRAY') { + foreach my $targetsource (@{$modified_urls}){ + my ($target,$source)=@{$targetsource}; + my $logfile=Apache::File->new('>>'.$source.'.log'); + print $logfile "\nCleanup phase: Notifications\n"; + my @subscribed=&get_subscribed_hosts($target); + foreach my $subhost (@subscribed) { + print $logfile "\nNotifying host ".$subhost.':'; + my $reply=&Apache::lonnet::critical('update:'.$target,$subhost); + print $logfile $reply; + } # ---------------------------------------- Send update notifications, meta only - my @subscribedmeta=&get_subscribed_hosts("$target.meta"); - foreach my $subhost (@subscribedmeta) { - print $logfile "\nNotifying host for metadata only ".$subhost.':'; - my $reply=&Apache::lonnet::critical('update:'.$target.'.meta', - $subhost); - print $logfile $reply; - } + my @subscribedmeta=&get_subscribed_hosts("$target.meta"); + foreach my $subhost (@subscribedmeta) { + print $logfile "\nNotifying host for metadata only ".$subhost.':'; + my $reply=&Apache::lonnet::critical('update:'.$target.'.meta', + $subhost); + print $logfile $reply; + } # --------------------------------------------------- Notify subscribed courses - my %courses=&coursedependencies($target); - my $now=time; - foreach my $course (keys(%courses)) { - print $logfile "\nNotifying course ".$course.':'; - my ($cdom,$cname)=split(/\_/,$course); - my $reply=&Apache::lonnet::cput - ('versionupdate',{$target => $now},$cdom,$cname); - print $logfile $reply; - } - print $logfile "\n============ Done ============\n"; - $logfile->close(); + my %courses=&coursedependencies($target); + my $now=time; + foreach my $course (keys(%courses)) { + print $logfile "\nNotifying course ".$course.':'; + my ($cdom,$cname)=split(/\_/,$course); + my $reply=&Apache::lonnet::cput + ('versionupdate',{$target => $now},$cdom,$cname); + print $logfile $reply; + } + print $logfile "\n============ Done ============\n"; + $logfile->close(); + } + $modified_urls = []; } if ($lock) { &Apache::lonnet::remove_lock($lock); } return OK; @@ -2251,6 +2254,18 @@ sub batchpublish { $srcfile=~/\.(\w+)$/; my $thistype=$1; +# +# If lonpublisher::batchpublish() is called directly from another package +# instead of via a call to lonpublisher::handler(), need to set the package +# scalars: $cuname and $cudom, and will unset when done. +# + my $clearvars; + if (($cuname eq '') && ($cudom eq '')) { + ($cuname,$cudom) = &Apache::lonnet::constructaccess($srcfile); + unless (($cuname eq '') && ($cudom eq '')) { + $clearvars = 1; + } + } my $thisembstyle=&Apache::loncommon::fileembstyle($thistype); @@ -2265,7 +2280,7 @@ sub batchpublish { # phase one takes # my ($source,$target,$style,$batch)=@_; my ($outstring,$error)=&publish($srcfile,$targetfile,$thisembstyle,1,$nokeyref); - + if ($usebuffer) { $output .= '
'.$outstring.'
'; } else { @@ -2283,6 +2298,10 @@ sub batchpublish { } } %env=%oldenv; + if ($clearvars) { + undef($cuname); + undef($cudom); + } if ($usebuffer) { return $output; } else {