--- loncom/publisher/lonpublisher.pm 2005/01/12 16:18:54 1.182
+++ loncom/publisher/lonpublisher.pm 2005/04/04 23:55:17 1.191
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.182 2005/01/12 16:18:54 www Exp $
+# $Id: lonpublisher.pm,v 1.191 2005/04/04 23:55:17 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -139,6 +139,7 @@ my $cuname;
my $cudom;
my $registered_cleanup;
+my $modified_urls;
=pod
@@ -547,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;
@@ -559,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;
@@ -673,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";
@@ -841,6 +846,35 @@ sub store_metadata {
}
+# ========================================== Parse file for errors and warnings
+
+sub checkonthis {
+ my ($r,$source)=@_;
+ my $uri=&Apache::lonnet::hreflocation($source);
+ $uri=~s/\/$//;
+ my $result=&Apache::lonnet::ssi_body($uri,
+ ('grade_target'=>'web',
+ 'return_only_error_and_warning_counts' => 1));
+ my ($errorcount,$warningcount)=split(':',$result);
+ if (($errorcount) || ($warningcount)) {
+ $r->print('
'.$uri.': ');
+ if ($errorcount) {
+ $r->print(''.
+ $errorcount.' '.
+ &mt('error(s)').' ');
+ }
+ if ($warningcount) {
+ $r->print(''.
+ $warningcount.' '.
+ &mt('warning(s)').'');
+ }
+ } else {
+ #$r->print(''.&mt('ok').'');
+ }
+ $r->rflush();
+ return ($warningcount,$errorcount);
+}
+
# ============================================== Parse file itself for metadata
#
# parses a file with target meta, sets global %metadatafields %metadatakeys
@@ -1006,6 +1040,7 @@ sub publish {
$scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix);
$prefix=~s|^\.\./||;
}
+
# ----------------------------------------------------------- Parse file itself
# read %metadatafields from file itself
@@ -1254,7 +1289,7 @@ END
}
my $copyright_help =
Apache::loncommon::help_open_topic('Publishing_Copyright');
- $intr_scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge;
+ $intr_scrout =~ s/Distribution:/'Distribution: ' . $copyright_help/ge;
$intr_scrout.=&text_with_browse_field('Custom Distribution File','customdistributionfile',$metadatafields{'customdistributionfile'},'rights').$copyright_help;
$intr_scrout.=&selectbox('Source Distribution','sourceavail',
$defaultsourceoption,
@@ -1545,10 +1580,8 @@ sub phasetwo {
$r->rflush;
# ------------------------------------------------------------- Trigger updates
- print $logfile("\nRegistering for notifications: $target $source\n");
- push(@{$ENV{'internal.publication.targetsource'}},[$target,$source]);
+ push(@{$modified_urls},[$target,$source]);
unless ($registered_cleanup) {
- &Apache::lonnet::logthis('Cleanup handler registered');
$r->register_cleanup(\¬ify);
$registered_cleanup=1;
}
@@ -1580,8 +1613,7 @@ sub phasetwo {
# =============================================================== Notifications
sub notify {
# --------------------------------------------------- Send update notifications
- &Apache::lonnet::logthis('Cleanup Phase Publication Handler');
- foreach my $targetsource (@{$ENV{'internal.publication.targetsource'}}){
+ foreach my $targetsource (@{$modified_urls}){
my ($target,$source)=@{$targetsource};
my $logfile=Apache::File->new('>>'.$source.'.log');
print $logfile "\nCleanup phase: Notifications\n";
@@ -1695,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;
}
@@ -1824,8 +1856,9 @@ sub handler {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['filename']);
-# ------------------------------------------------- Flag for registered cleanup
+# -------------------------------------- Flag and buffer for registered cleanup
$registered_cleanup=0;
+ @{$modified_urls}=();
# -------------------------------------------------------------- Check filename
my $fn=&Apache::lonnet::unescape($ENV{'form.filename'});
@@ -1979,8 +2012,20 @@ ENDDIFF
# ------------------ Publishing from $thisfn to $thistarget with $thisembstyle.
unless ($ENV{'form.phase'} eq 'two') {
- my ($outstring,$error)=&publish($thisfn,$thistarget,$thisembstyle);
- $r->print('