--- loncom/publisher/lonpublisher.pm 2003/12/29 21:17:00 1.158 +++ loncom/publisher/lonpublisher.pm 2004/01/27 22:54:59 1.163 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Publication Handler # -# $Id: lonpublisher.pm,v 1.158 2003/12/29 21:17:00 www Exp $ +# $Id: lonpublisher.pm,v 1.163 2004/01/27 22:54:59 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -127,6 +127,7 @@ use Apache::lonmysql; use Apache::lonlocal; use Apache::loncfile; use Apache::lonmeta; +use Apache::lonmsg; use vars qw(%metadatafields %metadatakeys); my %addid; @@ -203,7 +204,11 @@ sub metaeval { if ($newentry !~m|^/res|) { $newentry=$prefix.$newentry; } } # actually store - $metadatafields{$unikey}=$newentry; + if ( $entry eq 'rule' && exists($metadatafields{$unikey})) { + $metadatafields{$unikey}.=','.$newentry; + } else { + $metadatafields{$unikey}=$newentry; + } } } } @@ -1029,6 +1034,7 @@ sub publish { # ------------------------------------------ See if anything new in file itself $allmeta=&parseformeta($source,$style); + } @@ -1434,7 +1440,10 @@ sub phasetwo { $r->print($error); print $logfile "\n".$error; } - +# --------------------------------------------- Delete author resource messages + my $delresult=&Apache::lonmsg::del_url_author_res_msg($target); + $r->print('

'.&mt('Removing error messages:').' '.$delresult.'

'); + print $logfile "\nRemoving error messages: $delresult"; # ----------------------------------------------------------- Copy old versions if (-e $target) { @@ -1693,6 +1702,63 @@ sub publishdirectory { } closedir(DIR); } + +######################################### +# publish a default.meta file + +sub defaultmetapublish { + my ($r,$fn,$cuname,$cudom)=@_; + $fn=~s/^\/\~$cuname\//\/home\/$cuname\/public_html\//; + unless (-e $fn) { + return HTTP_NOT_FOUND; + } + my $target=$fn; + $target=~s/^\/home\/$cuname\/public_html\//$Apache::lonnet::perlvar{'lonDocRoot'}\/res\/$cudom\/$cuname\//; + + + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + + $r->print('LON-CAPA Publishing'); + $r->print(&Apache::loncommon::bodytag('Catalog Information Publication')); + +# ---------------------------------------------------------------- Write Source + my $copyfile=$target; + + my @parts=split(/\//,$copyfile); + my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]"; + + my $count; + for ($count=5;$count<$#parts;$count++) { + $path.="/$parts[$count]"; + if ((-e $path)!=1) { + $r->print('

'.&mt('Created directory').' '.$parts[$count].'

'); + mkdir($path,0777); + } + } + + if (copy($fn,$copyfile)) { + $r->print('

'.&mt('Copied source file').'

'); + } else { + return "". + &mt('Failed to copy source').", $!, ".&mt('FAIL').""; + } + +# --------------------------------------------------- Send update notifications + + my @subscribed=&get_subscribed_hosts($target); + foreach my $subhost (@subscribed) { + $r->print('

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


');$r->rflush; + } +# ------------------------------------------------------------------- Link back + my $link=$fn; + $link=~s/^\/home\/$cuname\/public_html\//\/priv\/$cuname\//; + $r->print("".&mt('Back to Catalog Information').''); + $r->print(''); + return OK; +} ######################################### =pod @@ -1751,6 +1817,14 @@ sub handler { my $fn=&Apache::lonnet::unescape($ENV{'form.filename'}); + ($cuname,$cudom)= + &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); + +# special publication: default.meta file + if ($fn=~/\/default.meta$/) { + return &defaultmetapublish($r,$fn,$cuname,$cudom); + } + $fn=~s/\.meta$//; unless ($fn) { $r->log_reason($cuname.' at '.$cudom. @@ -1758,8 +1832,6 @@ sub handler { return HTTP_NOT_FOUND; } - ($cuname,$cudom)= - &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); unless (($cuname) && ($cudom)) { $r->log_reason($cuname.' at '.$cudom. ' trying to publish file '.$ENV{'form.filename'}. @@ -1768,12 +1840,14 @@ sub handler { return HTTP_NOT_ACCEPTABLE; } - unless (&Apache::lonnet::homeserver($cuname,$cudom) - eq $r->dir_config('lonHostID')) { + my $home=&Apache::lonnet::homeserver($cuname,$cudom); + my $allowed=0; + my @ids=&Apache::lonnet::current_machine_ids(); + foreach my $id (@ids) { if ($id eq $home) { $allowed = 1; } } + unless ($allowed) { $r->log_reason($cuname.' at '.$cudom. ' trying to publish file '.$ENV{'form.filename'}. - ' ('.$fn.') - not homeserver ('. - &Apache::lonnet::homeserver($cuname,$cudom).')', + ' ('.$fn.') - not homeserver ('.$home.')', $r->filename); return HTTP_NOT_ACCEPTABLE; }