--- loncom/publisher/lonpublisher.pm 2023/03/28 23:17:16 1.301 +++ 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.301 2023/03/28 23:17:16 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', @@ -1825,7 +1825,21 @@ sub phasetwo { $env{'user.domain'}; $metadatafields{'authorspace'}=$cuname.':'.$cudom; $metadatafields{'domain'}=$cudom; - + + my $crsauthor; + if ($env{'request.course.id'}) { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + if ($distarget =~ m{^/res/$cdom/$cnum}) { + $crsauthor = 1; + my $default_rights = "/res/$cdom/$cnum/default.rights"; + unless ($distarget eq $default_rights) { + $metadatafields{'copyright'} = 'custom'; + $metadatafields{'customdistributionfile'} = $default_rights; + } + } + } + my $allkeywords=$env{'form.addkey'}; if (exists($env{'form.keywords'})) { if (ref($env{'form.keywords'})) { @@ -1907,14 +1921,6 @@ sub phasetwo { $metadatafields{'url'} = $distarget; $metadatafields{'version'} = 'current'; - my $crsauthor; - if ($env{'request.course.id'}) { - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - if ($distarget =~ m{^/res/$cdom/$cnum}) { - $crsauthor = 1; - } - } unless ($crsauthor) { my ($error,$success) = &store_metadata(%metadatafields); if ($success) { @@ -2123,11 +2129,7 @@ sub phasetwo { # ------------------------------------------------------------- Trigger updates push(@{$modified_urls},[$target,$source]); - unless ($registered_cleanup) { - my $handlers = $r->get_handlers('PerlCleanupHandler'); - $r->set_handlers('PerlCleanupHandler' => [\¬ify,@{$handlers}]); - $registered_cleanup=1; - } + ¬ify_in_cleanup($r); # ---------------------------------------------------------- Clear local caches my $thisdistarget=$target; @@ -2183,39 +2185,51 @@ sub phasetwo { } } +sub notify_in_cleanup { + my ($r) = @_; + unless ($registered_cleanup) { + my $handlers = $r->get_handlers('PerlCleanupHandler'); + $r->set_handlers('PerlCleanupHandler' => [\¬ify,@{$handlers}]); + $registered_cleanup=1; + } +} + # =============================================================== 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; @@ -2240,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); @@ -2254,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 { @@ -2272,6 +2298,10 @@ sub batchpublish { } } %env=%oldenv; + if ($clearvars) { + undef($cuname); + undef($cudom); + } if ($usebuffer) { return $output; } else { @@ -2282,7 +2312,7 @@ sub batchpublish { ######################################### sub publishdirectory { - my ($r,$fn,$thisdisfn,$nokeyref)=@_; + my ($r,$fn,$thisdisfn,$nokeyref,$crsauthor)=@_; $fn=~s/\/+/\//g; $thisdisfn=~s/\/+/\//g; my $thisdisresdir=$thisdisfn; @@ -2323,10 +2353,12 @@ sub publishdirectory { &checkbox('excludemodmeta','exclude files with modified metadata'). ''. '
'.&mt('Actions').''. - &checkbox('obsolete','make file(s) obsolete').'
'. - &common_access('dist',&mt('apply common copyright/distribution'), - ['default','domain','public','custom']).'
'. - &common_access('source',&mt('apply common source availability'), + &checkbox('obsolete','make file(s) obsolete').'
'); + unless ($crsauthor) { + $r->print(&common_access('dist',&mt('apply common copyright/distribution'), + ['default','domain','public','custom']).'
'); + } + $r->print(&common_access('source',&mt('apply common source availability'), ['closed','open']). '
' ); @@ -2342,6 +2374,9 @@ sub publishdirectory { my %commonaccess; map { $commonaccess{$_} = 1; } &Apache::loncommon::get_env_multiple('form.commonaccess'); unless ($lock) { $lock=&Apache::lonnet::set_lock(&mt('Publishing [_1]',$fn)); } + if ($lock) { + ¬ify_in_cleanup($r); + } # actually publish things opendir(DIR,$fn); my @files=sort(readdir(DIR)); @@ -2350,12 +2385,12 @@ sub publishdirectory { $cuid,$cgid,$crdev,$csize, $catime,$cmtime,$cctime, $cblksize,$cblocks)=stat($fn.'/'.$filename); - + my $extension=''; if ($filename=~/\.(\w+)$/) { $extension=$1; } if ($cmode&$dirptr) { if (($filename!~/^\./) && ($env{'form.pubrec'})) { - &publishdirectory($r,$fn.'/'.$filename,$thisdisfn.'/'.$filename,$nokeyref); + &publishdirectory($r,$fn.'/'.$filename,$thisdisfn.'/'.$filename,$nokeyref,$crsauthor); } } elsif ((&Apache::loncommon::fileembstyle($extension) ne 'hdn') && ($filename!~/^[\#\.]/) && ($filename!~/\~$/)) { @@ -2598,12 +2633,23 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - + # Breadcrumbs &Apache::lonhtmlcommon::clear_breadcrumbs(); + my $crumbtext = 'Authoring Space'; + my $crumbhref = &Apache::loncommon::authorspace($fn); + my $crsauthor; + if ($env{'request.course.id'}) { + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + if ($crumbhref eq "/priv/$cdom/$cnum/") { + $crumbtext = 'Course Authoring Space'; + $crsauthor = 1; + } + } &Apache::lonhtmlcommon::add_breadcrumb({ - 'text' => 'Authoring Space', - 'href' => &Apache::loncommon::authorspace($fn), + 'text' => $crumbtext, + 'href' => $crumbhref, }); &Apache::lonhtmlcommon::add_breadcrumb({ 'text' => 'Resource Publication', @@ -2673,7 +2719,7 @@ END if ($fn=~/\/$/) { # -------------------------------------------------------- This is a directory - &publishdirectory($r,$docroot.$fn,$thisdisfn,$nokeyref); + &publishdirectory($r,$docroot.$fn,$thisdisfn,$nokeyref,$crsauthor); $r->print( '

'. &Apache::lonhtmlcommon::actionbox([