--- loncom/publisher/lonpublisher.pm 2004/09/02 19:34:46 1.178 +++ loncom/publisher/lonpublisher.pm 2005/03/03 21:14:10 1.186 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Publication Handler # -# $Id: lonpublisher.pm,v 1.178 2004/09/02 19:34:46 albertel Exp $ +# $Id: lonpublisher.pm,v 1.186 2005/03/03 21:14:10 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -138,6 +138,9 @@ my $docroot; my $cuname; my $cudom; +my $registered_cleanup; +my $modified_urls; + =pod =item B @@ -329,6 +332,21 @@ sub textfield { ''; } +sub text_with_browse_field { + my ($title,$name,$value,$restriction)=@_; + $value=~s/^\s+//gs; + $value=~s/\s+$//gs; + $value=~s/\s+/ /gs; + $title=&mt($title); + $ENV{'form.'.$name}=$value; + return "\n

$title:". + "


". + ''. + 'Select '. + 'Search'; + +} + sub hiddenfield { my ($name,$value)=@_; $ENV{'form.'.$name}=$value; @@ -530,7 +548,8 @@ sub get_max_ids_indices { my $counter; if ($counter=$addid{$token->[1]}) { if ($counter eq 'id') { - if (defined($token->[2]->{'id'})) { + if (defined($token->[2]->{'id'}) && + $token->[2]->{'id'} !~ /^\s*$/) { $maxid=($token->[2]->{'id'}>$maxid)?$token->[2]->{'id'}:$maxid; if (exists($allids{$token->[2]->{'id'}})) { $duplicateids=1; @@ -542,7 +561,8 @@ sub get_max_ids_indices { $needsfixup=1; } } else { - if (defined($token->[2]->{'index'})) { + if (defined($token->[2]->{'index'}) && + $token->[2]->{'index'} !~ /^\s*$/) { $maxindex=($token->[2]->{'index'}>$maxindex)?$token->[2]->{'index'}:$maxindex; } else { $needsfixup=1; @@ -656,13 +676,15 @@ sub fix_ids_and_indices { if (!$counter) { $counter=$addid{$lctag}; } if ($counter) { if ($counter eq 'id') { - unless (defined($parms{'id'})) { + unless (defined($parms{'id'}) && + $parms{'id'}!~/^\s*$/) { $maxid++; $parms{'id'}=$maxid; print $logfile 'ID: '.$tag.':'.$maxid."\n"; } } elsif ($counter eq 'index') { - unless (defined($parms{'index'})) { + unless (defined($parms{'index'}) && + $parms{'index'}!~/^\s*$/) { $maxindex++; $parms{'index'}=$maxindex; print $logfile 'Index: '.$tag.':'.$maxindex."\n"; @@ -824,6 +846,35 @@ sub store_metadata { } +# ========================================== Parse file for errors and warnings + +sub checkonthis { + my ($r,$source)=@_; + my $oldpath=$ENV{'request.filename'}; + $ENV{'request.filename'}=$source; + &Apache::lonxml::xmlparse($r,'web', + &Apache::lonnet::getfile($source)); + undef($Apache::lonhomework::parsing_a_problem); + $ENV{'request.filename'}=$oldpath; + if (($Apache::lonxml::errorcount) || + ($Apache::lonxml::warningcount)) { + if ($Apache::lonxml::errorcount) { + $r->print(''. + $Apache::lonxml::errorcount.' '. + &mt('error(s)').' '); + } + if ($Apache::lonxml::warningcount) { + $r->print(''. + $Apache::lonxml::warningcount.' '. + &mt('warning(s)').''); + } + } else { + $r->print(''.&mt('ok').''); + } + $r->rflush(); + return ($Apache::lonxml::warningcount,$Apache::lonxml::errorcount); +} + # ============================================== Parse file itself for metadata # # parses a file with target meta, sets global %metadatafields %metadatakeys @@ -989,6 +1040,7 @@ sub publish { $scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix); $prefix=~s|^\.\./||; } + # ----------------------------------------------------------- Parse file itself # read %metadatafields from file itself @@ -1132,7 +1184,7 @@ END my $colcount=0; foreach (sort keys %keywords) { - $keywordout.=''; + $keywordout.=' />'.$_.''; if ($colcount>10) { $keywordout.="\n"; $colcount=0; @@ -1238,15 +1290,12 @@ END my $copyright_help = Apache::loncommon::help_open_topic('Publishing_Copyright'); $intr_scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge; - $intr_scrout.=&textfield('Custom Distribution File','customdistributionfile', - $metadatafields{'customdistributionfile'}). - $copyright_help; + $intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights').$copyright_help; $intr_scrout.=&selectbox('Source Distribution','sourceavail', $defaultsourceoption, \&Apache::loncommon::source_copyrightdescription, (&Apache::loncommon::source_copyrightids)); - $intr_scrout.=&textfield('Source Custom Distribution File','sourcerights', - $metadatafields{'sourcerights'}); + $intr_scrout.=&text_with_browse_field('Source Custom Distribution File','sourcerights',$metadatafields{'sourcerights'},'rights'); my $uctitle=&mt('Obsolete'); $intr_scrout.= "\n

$uctitle:". @@ -1255,9 +1304,9 @@ END $intr_scrout.=' checked="1" '; } $intr_scrout.='/ >

'. - &textfield('Suggested Replacement for Obsolete File', - 'obsoletereplacement', - $metadatafields{'obsoletereplacement'}); + &text_with_browse_field('Suggested Replacement for Obsolete File', + 'obsoletereplacement', + $metadatafields{'obsoletereplacement'}); } else { $intr_scrout.=&hiddenfield('copyright','private'); } @@ -1529,41 +1578,12 @@ sub phasetwo { "".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL').""; } $r->rflush; -# --------------------------------------------------- Send update notifications - - my @subscribed=&get_subscribed_hosts($target); - foreach my $subhost (@subscribed) { - $r->print('

'.&mt('Notifying host').' '.$subhost.':');$r->rflush; - print $logfile "\nNotifying host ".$subhost.':'; - my $reply=&Apache::lonnet::critical('update:'.$target,$subhost); - $r->print($reply.'


');$r->rflush; - print $logfile $reply; - } - -# ---------------------------------------- Send update notifications, meta only - my @subscribedmeta=&get_subscribed_hosts("$target.meta"); - foreach my $subhost (@subscribedmeta) { - $r->print('

'. -&mt('Notifying host for metadata only').' '.$subhost.':');$r->rflush; - print $logfile "\nNotifying host for metadata only ".$subhost.':'; - my $reply=&Apache::lonnet::critical('update:'.$target.'.meta', - $subhost); - $r->print($reply.'


');$r->rflush; - print $logfile $reply; - } - -# --------------------------------------------------- Notify subscribed courses - my %courses=&coursedependencies($target); - my $now=time; - foreach (keys %courses) { - $r->print('

'.&mt('Notifying course').' '.$_.':');$r->rflush; - print $logfile "\nNotifying host ".$_.':'; - my ($cdom,$cname)=split(/\_/,$_); - my $reply=&Apache::lonnet::cput - ('versionupdate',{$target => $now},$cdom,$cname); - $r->print($reply.'


');$r->rflush; - print $logfile $reply; +# ------------------------------------------------------------- Trigger updates + push(@{$modified_urls},[$target,$source]); + unless ($registered_cleanup) { + $r->register_cleanup(\¬ify); + $registered_cleanup=1; } # ------------------------------------------------ Provide link to new resource unless ($batch) { @@ -1586,9 +1606,47 @@ sub phasetwo { '">'. &mt('Back to Source Directory').'

'); } + $logfile->close(); return '

'.&mt('Done').'

'; } +# =============================================================== 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; + } +# ---------------------------------------- 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; + } +# --------------------------------------------------- Notify subscribed courses + my %courses=&coursedependencies($target); + my $now=time; + foreach (keys %courses) { + print $logfile "\nNotifying course ".$_.':'; + my ($cdom,$cname)=split(/\_/,$_); + my $reply=&Apache::lonnet::cput + ('versionupdate',{$target => $now},$cdom,$cname); + print $logfile $reply; + } + print $logfile "\n============ Done ============\n"; + $logfile->close(); + } + return OK; +} + ######################################### sub batchpublish { @@ -1669,7 +1727,7 @@ sub publishdirectory { $ruid,$rgid,$rrdev,$rsize, $ratime,$rmtime,$rctime, $rblksize,$rblocks)=stat($resdir.'/'.$filename); - if (($rmtime<$cmtime) || ($ENV{'form.forcerepub'})) { + if (($rmtime<$cmtime) || ($ENV{'form.forcerepub'} eq 'ON')) { # previously published, modified now $publishthis=1; } @@ -1798,6 +1856,9 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['filename']); +# -------------------------------------- Flag and buffer for registered cleanup + $registered_cleanup=0; + @{$modified_urls}=(); # -------------------------------------------------------------- Check filename my $fn=&Apache::lonnet::unescape($ENV{'form.filename'}); @@ -1891,8 +1952,11 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - - $r->print('LON-CAPA Publishing'); + + my $js=&Apache::loncommon::browser_and_searcher_javascript(); + $r->print('LON-CAPA Publishing + '); $r->print(&Apache::loncommon::bodytag('Resource Publication')); @@ -1948,6 +2012,8 @@ ENDDIFF # ------------------ Publishing from $thisfn to $thistarget with $thisembstyle. unless ($ENV{'form.phase'} eq 'two') { +# ---------------------------------------------------------- Parse for problems + &checkonthis($r,$thisfn); my ($outstring,$error)=&publish($thisfn,$thistarget,$thisembstyle); $r->print('
'.$outstring); } else {