--- loncom/publisher/lonpublisher.pm 2003/09/25 20:01:15 1.136
+++ loncom/publisher/lonpublisher.pm 2008/06/30 18:10:24 1.239
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.136 2003/09/25 20:01:15 www Exp $
+# $Id: lonpublisher.pm,v 1.239 2008/06/30 18:10:24 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,24 +25,6 @@
#
# http://www.lon-capa.org/
#
-#
-# (TeX Content Handler
-#
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
-#
-# 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
-# 03/23 Guy Albertelli
-# 03/24,03/29,04/03 Gerd Kortemeyer
-# 05/03,05/05,05/07 Gerd Kortemeyer
-# 06/23,08/07,08/11,8/13,8/17,8/18,8/24,9/26,10/16 Gerd Kortemeyer
-# 12/04,12/05 Guy Albertelli
-# 12/05 Gerd Kortemeyer
-# 12/05 Guy Albertelli
-# 12/06,12/07 Gerd Kortemeyer
-# 12/25 Gerd Kortemeyer
-# YEAR=2002
-# 1/17 Gerd Kortemeyer
-#
###
###############################################################################
@@ -139,11 +121,16 @@ use HTML::LCParser;
use Apache::lonxml;
use Apache::loncacc;
use DBI;
-use Apache::lonnet();
+use Apache::lonnet;
use Apache::loncommon();
use Apache::lonmysql;
use Apache::lonlocal;
+use Apache::loncfile;
+use LONCAPA::lonmetadata;
+use Apache::lonmsg;
use vars qw(%metadatafields %metadatakeys);
+use LONCAPA qw(:DEFAULT :match);
+
my %addid;
my %nokey;
@@ -153,6 +140,11 @@ my $docroot;
my $cuname;
my $cudom;
+my $registered_cleanup;
+my $modified_urls;
+
+my $lock;
+
=pod
=item B $uctitle:".
- " $uctitle:".
- ' '.&mt('New parameters or stored values').
+ $scrout.=' '.&mt('New parameters or saved values').
': '.$chparms.' '.&mt('Obsolete parameters or stored values').': '.
- $chparms.' '.&mt('Obsolete parameters or saved values').': '.
+ $chparms.' '.
+ &mt('If this resource is in active use, student performance data from the previous version may become inaccessible.').'
No file: '.$fn.'';
+ return '
'.&mt('No file').': '.
+ &Apache::loncfile::display($fn).'';
}
print($logfile 'Processing '.$fn."\n");
my $metastring;
{
- my $metafh=Apache::File->new($fn);
- $metastring=join('',<$metafh>);
+ my $metafh=Apache::File->new($fn);
+ $metastring=join('',<$metafh>);
}
- &metaeval($metastring);
- return '
Processed file: '.$fn.'';
+ &metaeval($metastring,$prefix);
+ return '
'.&mt('Processed file').': '.
+ &Apache::loncfile::display($fn).'
';
}
#########################################
@@ -281,9 +283,8 @@ sub metaread {
sub coursedependencies {
my $url=&Apache::lonnet::declutter(shift);
$url=~s/\.meta$//;
- my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
- my $regexp=$url;
- $regexp=~s/(\W)/\\$1/g;
+ my ($adomain,$aauthor)=($url=~ m{^($match_domain)/($match_username)/});
+ my $regexp=quotemeta($url);
$regexp='___'.$regexp.'___course';
my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
$aauthor,$regexp);
@@ -325,25 +326,58 @@ string which presents the form field (fo
#########################################
sub textfield {
my ($title,$name,$value)=@_;
+ $value=~s/^\s+//gs;
+ $value=~s/\s+$//gs;
+ $value=~s/\s+/ /gs;
+ $title=&mt($title);
+ $env{'form.'.$name}=$value;
+ return "\n".&Apache::lonhtmlcommon::row_title($title)
+ .''
+ .&Apache::lonhtmlcommon::row_closure();
+}
+
+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);
- my $uctitle=uc($title);
- return "\n
".
- '';
+ $env{'form.'.$name}=$value;
+ return "\n".&Apache::lonhtmlcommon::row_title($title)
+ .''
+ .'
'
+ .''
+ .&mt('Select')
+ .' '
+ .''
+ .&mt('Search')
+ .''
+ .&Apache::lonhtmlcommon::row_closure();
}
sub hiddenfield {
my ($name,$value)=@_;
+ $env{'form.'.$name}=$value;
return "\n".'';
}
+sub checkbox {
+ my ($name,$text)=@_;
+ return "\n
";
+}
+
sub selectbox {
my ($title,$name,$value,$functionref,@idlist)=@_;
$title=&mt($title);
- my $uctitle=uc($title);
$value=(split(/\s*,\s*/,$value))[-1];
- my $selout="\n
'.&Apache::lonhtmlcommon::row_closure();
+ return $selout;
}
+sub select_level_form {
+ my ($value,$name)=@_;
+ $env{'form.'.$name}=$value;
+ if (!defined($value)) { $env{'form.'.$name}=0; }
+ return &Apache::loncommon::select_level_form($value,$name);
+}
#########################################
#########################################
@@ -375,15 +416,14 @@ sub urlfixup {
if ($url =~ /^mailto:/i) { return $url; }
#internal document links need no fixing
if ($url =~ /^\#/) { return $url; }
- my ($host)=($url=~/(?:http\:\/\/)*([^\/]+)/);
- foreach (values %Apache::lonnet::hostname) {
- if ($_ eq $host) {
- $url=~s/^http\:\/\///;
- $url=~s/^$host//;
- }
+ my ($host)=($url=~m{(?:(?:http|https|ftp)://)*([^/]+)});
+ my @lonids = &Apache::lonnet::machine_ids($host);
+ if (@lonids) {
+ $url=~s{^(?:http|https|ftp)://}{};
+ $url=~s/^\Q$host\E//;
}
- if ($url=~/^http\:\/\//) { return $url; }
- $url=~s/\~$cuname/res\/$cudom\/$cuname/;
+ if ($url=~m{^(?:http|https|ftp)://}) { return $url; }
+ $url=~s{\Q~$cuname\E}{res/$cudom/$cuname};
return $url;
}
@@ -434,11 +474,11 @@ sub set_allow {
}
if (($newurl !~ /^javascript:/i) &&
($newurl !~ /^mailto:/i) &&
- ($newurl !~ /^http:/i) &&
+ ($newurl !~ /^(?:http|https|ftp):/i) &&
($newurl !~ /^\#/)) {
$$allow{&absoluteurl($newurl,$target)}=1;
}
- return $return_url
+ return $return_url;
}
#########################################
@@ -461,10 +501,15 @@ sub get_subscribed_hosts {
$target=~/(.*)\/([^\/]+)$/;
my $srcf=$2;
opendir(DIR,$1);
+ # cycle through listed files, subscriptions used to exist
+ # as "filename.lonid"
while ($filename=readdir(DIR)) {
- if ($filename=~/\Q$srcf\E\.(\w+)$/) {
+ if ($filename=~/\Q$srcf\E\.($match_lonid)$/) {
my $subhost=$1;
- if (($subhost ne 'meta' && $subhost ne 'subscription') &&
+ if (($subhost ne 'meta'
+ && $subhost ne 'subscription'
+ && $subhost ne 'meta.subscription'
+ && $subhost ne 'tmp') &&
($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) {
push(@subscribed,$subhost);
}
@@ -473,19 +518,13 @@ sub get_subscribed_hosts {
closedir(DIR);
my $sh;
if ( $sh=Apache::File->new("$target.subscription") ) {
- &Apache::lonnet::logthis("opened $target.subscription");
while (my $subline=<$sh>) {
- &Apache::lonnet::logthis("Trying $subline");
- if ($subline =~ /(^\w+):/) {
+ if ($subline =~ /^($match_lonid):/) {
if ($1 ne $Apache::lonnet::perlvar{'lonHostID'}) {
push(@subscribed,$1);
}
- } else {
- &Apache::lonnet::logthis("No Match for $subline");
}
}
- } else {
- &Apache::lonnet::logthis("Unable to open $target.subscription");
}
return @subscribed;
}
@@ -515,13 +554,15 @@ sub get_max_ids_indices {
my %duplicatedids;
my $parser=HTML::LCParser->new($content);
+ $parser->xml_mode(1);
my $token;
while ($token=$parser->get_token) {
if ($token->[0] eq 'S') {
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;
@@ -533,7 +574,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;
@@ -575,11 +617,11 @@ sub get_all_text_unbalanced {
} elsif ($token->[0] eq 'E') {
$result.=$token->[2];
}
- if ($result =~ /(.*)\Q$tag\E(.*)/s) {
+ if ($result =~ /\Q$tag\E/s) {
+ ($result,my $redo)=$result =~ /(.*)\Q$tag\E(.*)/is;
#&Apache::lonnet::logthis('Got a winner with leftovers ::'.$2);
#&Apache::lonnet::logthis('Result is :'.$1);
- $result=$1;
- my $redo=$tag.$2;
+ $redo=$tag.$redo;
push (@$pars,HTML::LCParser->new(\$redo));
$$pars[-1]->xml_mode('1');
last;
@@ -619,7 +661,7 @@ sub fix_ids_and_indices {
join(', ',@duplicatedids));
if ($duplicateids) {
print $logfile "Duplicate ID(s) exist, ".join(', ',@duplicatedids)."\n";
- my $outstring='Unable to publish file, it contains duplicated ID(s), ID(s) need to be unique. The duplicated ID(s) are: '.join(', ',@duplicatedids).'';
+ my $outstring=''.&mt('Unable to publish file, it contains duplicated ID(s), ID(s) need to be unique. The duplicated ID(s) are').': '.join(', ',@duplicatedids).'';
return ($outstring,1);
}
if ($needsfixup) {
@@ -628,6 +670,7 @@ sub fix_ids_and_indices {
"Max Index: $maxindex (min 10)\n";
}
my $outstring='';
+ my $responsecounter=1;
my @parser;
$parser[0]=HTML::LCParser->new(\$content);
$parser[-1]->xml_mode(1);
@@ -642,30 +685,41 @@ sub fix_ids_and_indices {
$allow{$token->[2]->{'src'}}=1;
next;
}
+ if ($lctag eq 'base') { next; }
+ if (($lctag eq 'part') || ($lctag eq 'problem')) {
+ $responsecounter=0;
+ }
+ if ($lctag=~/response$/) { $responsecounter++; }
my %parms=%{$token->[2]};
$counter=$addid{$tag};
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";
+ print $logfile 'ID(new) : '.$tag.':'.$maxid."\n";
+ } else {
+ print $logfile 'ID(kept): '.$tag.':'.$parms{'id'}."\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";
}
}
}
- foreach my $type ('src','href','background','bgimg') {
- foreach my $key (keys(%parms)) {
- if ($key =~ /^$type$/i) {
- $parms{$key}=&set_allow(\%allow,$logfile,
- $target,$tag,
- $parms{$key});
+ unless ($parms{'type'} eq 'zombie') {
+ foreach my $type ('src','href','background','bgimg') {
+ foreach my $key (keys(%parms)) {
+ if ($key =~ /^$type$/i) {
+ $parms{$key}=&set_allow(\%allow,$logfile,
+ $target,$tag,
+ $parms{$key});
+ }
}
}
}
@@ -676,6 +730,7 @@ sub fix_ids_and_indices {
($lctag eq 'image')) {
my $next_token=$parser[-1]->get_token();
if ($next_token->[0] eq 'T') {
+ $next_token->[1] =~ s/[\n\r\f]+//g;
$next_token->[1]=&set_allow(\%allow,$logfile,
$target,$tag,
$next_token->[1]);
@@ -684,8 +739,15 @@ sub fix_ids_and_indices {
}
if ($lctag eq 'applet') {
my $codebase='';
- if (defined($parms{'codebase'})) {
- my $oldcodebase=$parms{'codebase'};
+ my $havecodebase=0;
+ foreach my $key (keys(%parms)) {
+ if (lc($key) eq 'codebase') {
+ $codebase=$parms{$key};
+ $havecodebase=1;
+ }
+ }
+ if ($havecodebase) {
+ my $oldcodebase=$codebase;
unless ($oldcodebase=~/\/$/) {
$oldcodebase.='/';
}
@@ -699,14 +761,13 @@ sub fix_ids_and_indices {
}
$allow{&absoluteurl($codebase,$target).'/*'}=1;
} else {
- foreach ('archive','code','object') {
- if (defined($parms{$_})) {
- my $oldurl=$parms{$_};
+ foreach my $key (keys(%parms)) {
+ if ($key =~ /(archive|code|object)/i) {
+ my $oldurl=$parms{$key};
my $newurl=&urlfixup($oldurl,$target);
$newurl=~s/\/[^\/]+$/\/\*/;
- print $logfile 'Allow: applet '.$_.':'.
- $oldurl.' allows '.
- $newurl."\n";
+ print $logfile 'Allow: applet '.lc($key).':'.
+ $oldurl.' allows '.$newurl."\n";
$allow{&absoluteurl($newurl,$target)}=1;
}
}
@@ -724,7 +785,7 @@ sub fix_ids_and_indices {
}
if (!$endtag) { if ($token->[4]=~m:/>$:) { $endtag=' /'; }; }
$outstring.='<'.$tag.$newparmstring.$endtag.'>';
- if ($lctag eq 'm' || $lctag eq 'script'
+ if ($lctag eq 'm' || $lctag eq 'script' || $lctag eq 'answer'
|| $lctag eq 'display' || $lctag eq 'tex') {
$outstring.=&get_all_text_unbalanced('/'.$lctag,\@parser);
}
@@ -733,7 +794,12 @@ sub fix_ids_and_indices {
unless ($token->[1] eq 'allow') {
$outstring.=''.$token->[1].'>';
}
- }
+ }
+ if ((($token->[1] eq 'part') || ($token->[1] eq 'problem'))
+ && (!$responsecounter)) {
+ my $outstring=''.&mt('Found [_1] without responses. This resource cannot be published.',$token->[1]).'';
+ return ($outstring,1);
+ }
} else {
$outstring.=$token->[1];
}
@@ -771,41 +837,90 @@ Returns: (error,status). error is undef
#########################################
#########################################
sub store_metadata {
- my %metadata = %{shift()};
+ my %metadata = @_;
my $error;
# Determine if the table exists
my $status = &Apache::lonmysql::check_table('metadata');
if (! defined($status)) {
- $error='WARNING: Cannot connect to '.
- 'database!';
+ $error='WARNING: Cannot connect to '.
+ 'database!';
&Apache::lonnet::logthis($error);
return ($error,undef);
}
if ($status == 0) {
# It would be nice to actually create the table....
- $error ='WARNING: The metadata table does not '.
- 'exist in the LON-CAPA database.';
+ $error ='WARNING: The metadata table does not '.
+ 'exist in the LON-CAPA database.';
&Apache::lonnet::logthis($error);
return ($error,undef);
}
- # Remove old value from table
- $status = &Apache::lonmysql::remove_from_table
- ('metadata','url',$metadata{'url'});
- if (! defined($status)) {
- $error = 'Error when removing old values from '.
- 'metadata table in LON-CAPA database.';
- &Apache::lonnet::logthis($error);
- return ($error,undef);
+ my $dbh = &Apache::lonmysql::get_dbh();
+ if (($metadata{'obsolete'}) || ($metadata{'copyright'} eq 'priv')) {
+ # remove this entry
+ my $delitem = 'url = '.$dbh->quote($metadata{'url'});
+ $status = &LONCAPA::lonmetadata::delete_metadata($dbh,undef,$delitem);
+
+ } else {
+ $status = &LONCAPA::lonmetadata::update_metadata($dbh,undef,undef,
+ \%metadata);
}
- # Store data in table.
- $status = &Apache::lonmysql::store_row('metadata',\%metadata);
- if (! defined($status)) {
- $error='Error occured storing new values in '.
- 'metadata table in LON-CAPA database';
+ if (defined($status) && $status ne '') {
+ $error='Error occured saving new values in '.
+ 'metadata table in LON-CAPA database';
&Apache::lonnet::logthis($error);
+ &Apache::lonnet::logthis($status);
return ($error,undef);
}
- return (undef,$status);
+ return (undef,'success');
+}
+
+
+# ========================================== 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
+
+sub parseformeta {
+ my ($source,$style)=@_;
+ my $allmeta='';
+ if (($style eq 'ssi') || ($style eq 'prv')) {
+ my $dir=$source;
+ $dir=~s-/[^/]*$--;
+ my $file=$source;
+ $file=(split('/',$file))[-1];
+ $source=&Apache::lonnet::hreflocation($dir,$file);
+ $allmeta=&Apache::lonnet::ssi_body($source,('grade_target' => 'meta'));
+ &metaeval($allmeta);
+ }
+ return $allmeta;
}
#########################################
@@ -839,10 +954,10 @@ sub publish {
my %allow=();
unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
- return ('No write permission to user directory, FAIL',1);
+ return (''.&mt('No write permission to user directory, FAIL').'',1);
}
print $logfile
-"\n\n================= Publish ".localtime()." Phase One ================\n".$ENV{'user.name'}.'@'.$ENV{'user.domain'}."\n";
+"\n\n================= Publish ".localtime()." Phase One ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n";
if (($style eq 'ssi') || ($style eq 'rat') || ($style eq 'prv')) {
# ------------------------------------------------------- This needs processing
@@ -853,7 +968,7 @@ sub publish {
print $logfile "Copied original file to ".$copyfile."\n";
} else {
print $logfile "Unable to write backup ".$copyfile.':'.$!."\n";
- return ("Failed to write backup copy, $!,FAIL",1);
+ return ("".&mt("Failed to write backup copy, [_1], FAIL",$1)."",1);
}
# ------------------------------------------------------------- IDs and indices
@@ -863,31 +978,36 @@ sub publish {
if ($error) { return ($outstring,$error); }
# ------------------------------------------------------------ Construct Allows
- $scrout.='Dependencies
';
+ $scrout.=''.&mt('Dependencies').'
';
my $allowstr='';
- foreach (sort(keys(%allow))) {
- my $thisdep=$_;
+ foreach my $thisdep (sort(keys(%allow))) {
if ($thisdep !~ /[^\s]/) { next; }
+ if ($thisdep =~/\$/) {
+ $scrout.='
'
+ .&mt('The resource depends on another resource with variable filename, i.e., [_1].',''.$thisdep.'').'
'
+ .&mt('You likely need to explicitly allow access to all possible dependencies using the [_1]-tag.','<allow>')
+ .'
';
+ }
unless ($style eq 'rat') {
$allowstr.="\n".'
';
- unless ($thisdep=~/\*/) {
+ if ($thisdep!~/[\*\$]/ && $thisdep!~m|^/adm/|) {
$scrout.='';
}
$scrout.=''.$thisdep.'';
- unless ($thisdep=~/\*/) {
+ if ($thisdep!~/[\*\$]/ && $thisdep!~m|^/adm/|) {
$scrout.='';
if (
&Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
$thisdep.'.meta') eq '-1') {
- $scrout.= ' - Currently not available'.
- '';
+ $scrout.= ' - '.&mt('Currently not available').
+ '';
} else {
my %temphash=(&Apache::lonnet::declutter($target).'___'.
&Apache::lonnet::declutter($thisdep).'___usage'
=> time);
- $thisdep=~/^\/res\/(\w+)\/(\w+)\//;
+ $thisdep=~m{^/res/($match_domain)/($match_username)/};
if ((defined($1)) && (defined($2))) {
&Apache::lonnet::put('nohist_resevaldata',\%temphash,
$1,$2);
@@ -895,20 +1015,17 @@ sub publish {
}
}
}
- $outstring=~s/\n*(\<\/[^\>]+\>)\s*$/$allowstr\n$1\n/s;
+ $outstring=~s/\n*(\<\/[^\>]+\>[^<]*)$/$allowstr\n$1\n/s;
-### FIXME: is this really what we want?
- #Encode any High ASCII characters
- $outstring=&HTML::Entities::encode($outstring,"\200-\377");
# ------------------------------------------------------------- Write modified.
{
my $org;
unless ($org=Apache::File->new('>'.$source)) {
print $logfile "No write permit to $source\n";
- return (''.&mt('No write permission to').
+ return (''.&mt('No write permission to').
' '.$source.
- ', '.&mt('FAIL').'',1);
+ ', '.&mt('FAIL').'',1);
}
print($org $outstring);
}
@@ -918,7 +1035,8 @@ sub publish {
# -------------------------------------------- Initial step done, now metadata.
# --------------------------------------- Storage for metadata keys and fields.
-
+# these are globals
+#
%metadatafields=();
%metadatakeys=();
@@ -926,22 +1044,19 @@ sub publish {
unless ($batch) {
$scrout.=''.&mt('Metadata Information').' ' .
- Apache::loncommon::help_open_topic("Metadata_Description")
+ &Apache::loncommon::help_open_topic("Metadata_Description")
. '
';
}
# ------------------------------------------------ First, check out environment
- unless (-e $source.'.meta') {
- $metadatafields{'author'}=$ENV{'environment.firstname'}.' '.
- $ENV{'environment.middlename'}.' '.
- $ENV{'environment.lastname'}.' '.
- $ENV{'environment.generation'};
+ if ((!(-e $source.'.meta')) || ($env{'form.forceoverride'})) {
+ $metadatafields{'author'}=$env{'environment.firstname'}.' '.
+ $env{'environment.middlename'}.' '.
+ $env{'environment.lastname'}.' '.
+ $env{'environment.generation'};
$metadatafields{'author'}=~s/\s+/ /g;
$metadatafields{'author'}=~s/\s+$//;
- $metadatafields{'owner'}=$cuname.'@'.$cudom;
- $metadatafields{'modifyinguser'}=$ENV{'user.name'}.'@'.
- $ENV{'user.domain'};
- $metadatafields{'authorspace'}=$cuname.'@'.$cudom;
+ $metadatafields{'owner'}=$cuname.':'.$cudom;
# ------------------------------------------------ Check out directory hierachy
@@ -953,11 +1068,18 @@ sub publish {
my $currentpath='/home/'.$cuname.'/';
+ my $prefix='../'x($#urlparts);
foreach (@urlparts) {
$currentpath.=$_.'/';
- $scrout.=&metaread($logfile,$currentpath.'default.meta');
+ $scrout.=&metaread($logfile,$currentpath.'default.meta',$prefix);
+ $prefix=~s|^\.\./||;
}
+# ----------------------------------------------------------- Parse file itself
+# read %metadatafields from file itself
+
+ $allmeta=&parseformeta($source,$style);
+
# ------------------- Clear out parameters and stores (there should not be any)
foreach (keys %metadatafields) {
@@ -977,20 +1099,21 @@ sub publish {
delete $metadatafields{$_};
}
}
-
- }
-
-# -------------------------------------------------- Parse content for metadata
- if (($style eq 'ssi') || ($style eq 'prv')) {
- my $dir=$source;
- $dir=~s-/[^/]*$--;
- my $file=$source;
- $file=(split('/',$file))[-1];
- $source=&Apache::lonnet::hreflocation($dir,$file);
- $allmeta=&Apache::lonnet::ssi_body($source,('grade_target' => 'meta'));
+# ------------------------------------------------------------- Save some stuff
+ my %savemeta=();
+ foreach ('title') {
+ $savemeta{$_}=$metadatafields{$_};
+ }
+# ------------------------------------------ See if anything new in file itself
+
+ $allmeta=&parseformeta($source,$style);
+# ----------------------------------------------------------- Restore the stuff
+ foreach (keys %savemeta) {
+ $metadatafields{$_}=$savemeta{$_};
+ }
+ }
- &metaeval($allmeta);
- }
+
# ---------------- Find and document discrepancies in the parameters and stores
my $chparms='';
@@ -998,14 +1121,16 @@ sub publish {
if (($_=~/^parameter/) || ($_=~/^stores/)) {
unless ($_=~/\.\w+$/) {
unless ($oldparmstores{$_}) {
- print $logfile 'New: '.$_."\n";
- $chparms.=$_.' ';
+ my $disp_key = $_;
+ $disp_key =~ tr/\0/_/;
+ print $logfile ('New: '.$disp_key."\n");
+ $chparms .= $disp_key.' ';
}
}
}
}
if ($chparms) {
- $scrout.=''.&mt('Warning!').
+ '
';
+ }
+ if ($metadatafields{'copyright'} eq 'priv') {
+ $scrout.='
'. + &mt('Copyright/distribution option "Private" is no longer supported. Select another option from below. Consider "Custom Rights" for maximum control over the usage of your resource.').'
'.&mt('Warning: It can take up to 1 hour for rights changes to fully propagate.').'
'); + } + print $logfile - "\n================= Publish ".localtime()." Phase Two ================\n".$ENV{'user.name'}.'@'.$ENV{'user.domain'}."\n"; + "\n================= Publish ".localtime()." Phase Two ================\n".$env{'user.name'}.':'.$env{'user.domain'}."\n"; %metadatafields=(); %metadatakeys=(); + + &metaeval(&unescape($env{'form.allmeta'})); - &metaeval(&Apache::lonnet::unescape($ENV{'form.allmeta'})); - - $metadatafields{'title'}=$ENV{'form.title'}; - $metadatafields{'author'}=$ENV{'form.author'}; - $metadatafields{'subject'}=$ENV{'form.subject'}; - $metadatafields{'notes'}=$ENV{'form.notes'}; - $metadatafields{'abstract'}=$ENV{'form.abstract'}; - $metadatafields{'mime'}=$ENV{'form.mime'}; - $metadatafields{'language'}=$ENV{'form.language'}; - $metadatafields{'creationdate'}=$ENV{'form.creationdate'}; - $metadatafields{'lastrevisiondate'}=$ENV{'form.lastrevisiondate'}; - $metadatafields{'owner'}=$ENV{'form.owner'}; - $metadatafields{'copyright'}=$ENV{'form.copyright'}; + $metadatafields{'title'}=$env{'form.title'}; + $metadatafields{'author'}=$env{'form.author'}; + $metadatafields{'subject'}=$env{'form.subject'}; + $metadatafields{'notes'}=$env{'form.notes'}; + $metadatafields{'abstract'}=$env{'form.abstract'}; + $metadatafields{'mime'}=$env{'form.mime'}; + $metadatafields{'language'}=$env{'form.language'}; + $metadatafields{'creationdate'}=$env{'form.creationdate'}; + $metadatafields{'lastrevisiondate'}=$env{'form.lastrevisiondate'}; + $metadatafields{'owner'}=$env{'form.owner'}; + $metadatafields{'copyright'}=$env{'form.copyright'}; + $metadatafields{'standards'}=$env{'form.standards'}; + $metadatafields{'lowestgradelevel'}=$env{'form.lowestgradelevel'}; + $metadatafields{'highestgradelevel'}=$env{'form.highestgradelevel'}; $metadatafields{'customdistributionfile'}= - $ENV{'form.customdistributionfile'}; - $metadatafields{'dependencies'}=$ENV{'form.dependencies'}; + $env{'form.customdistributionfile'}; + $metadatafields{'sourceavail'}=$env{'form.sourceavail'}; + $metadatafields{'obsolete'}=$env{'form.obsolete'}; + $metadatafields{'obsoletereplacement'}= + $env{'form.obsoletereplacement'}; + $metadatafields{'dependencies'}=$env{'form.dependencies'}; + $metadatafields{'modifyinguser'}=$env{'user.name'}.':'. + $env{'user.domain'}; + $metadatafields{'authorspace'}=$cuname.':'.$cudom; + $metadatafields{'domain'}=$cudom; - my $allkeywords=$ENV{'form.addkey'}; - if (exists($ENV{'form.keywords'})) { - if (ref($ENV{'form.keywords'})) { - $allkeywords .= ','.join(',',@{$ENV{'form.keywords'}}); + my $allkeywords=$env{'form.addkey'}; + if (exists($env{'form.keywords'})) { + if (ref($env{'form.keywords'})) { + $allkeywords .= ','.join(',',@{$env{'form.keywords'}}); } else { - $allkeywords .= ','.$ENV{'form.keywords'}; + $allkeywords .= ','.$env{'form.keywords'}; } } - $allkeywords=~s/\W+/\,/; - $allkeywords=~s/^\,//; + $allkeywords=~s/[\"\']//g; + $allkeywords=~s/\s*[\;\,]\s*/\,/g; + $allkeywords=~s/\s+/ /g; + $allkeywords=~s/^[ \,]//; + $allkeywords=~s/[ \,]$//; $metadatafields{'keywords'}=$allkeywords; +# check if custom distribution file is specified + if ($metadatafields{'copyright'} eq 'custom') { + my $file=$metadatafields{'customdistributionfile'}; + unless ($file=~/\.rights$/) { + $r->print( + ''.&mt('No valid custom distribution rights file specified, FAIL'). + ''); + return 0; + } + } { print $logfile "\nWrite metadata file for ".$source; my $mfh; unless ($mfh=Apache::File->new('>'.$source.'.meta')) { - return - ''.&mt('Could not write metadata, FAIL'). - ''; + $r->print( + ''.&mt('Could not write metadata, FAIL'). + ''); + return 0; } foreach (sort keys %metadatafields) { unless ($_=~/\./) { @@ -1334,7 +1561,7 @@ sub phasetwo { print $mfh ' '.$_.'="'.$value.'"'; } print $mfh '>'. - &HTML::Entities::encode($metadatafields{$unikey}) + &HTML::Entities::encode($metadatafields{$unikey},'<>&"') .''.$tag.'>'; } } @@ -1346,21 +1573,19 @@ sub phasetwo { $metadatafields{'url'} = $distarget; $metadatafields{'version'} = 'current'; - unless ($metadatafields{'copyright'} eq 'priv') { - my ($error,$success) = &store_metadata(\%metadatafields); - if ($success) { - $r->print('Synchronized SQL metadata database
'); - print $logfile "\nSynchronized SQL metadata database"; - } else { - $r->print($error); - print $logfile "\n".$error; - } + + my ($error,$success) = &store_metadata(%metadatafields); + if ($success) { + $r->print(''.&mt('Synchronized SQL metadata database').'
'); + print $logfile "\nSynchronized SQL metadata database"; } else { - $r->print(''. - &mt('Private Publication - did not synchronize database').'
'); - print $logfile "\nPrivate: Did not synchronize data into ". - "SQL metadata database"; + $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) { @@ -1372,7 +1597,9 @@ sub phasetwo { my $srcd=$1; unless ($srcd=~/^\/home\/httpd\/html\/res/) { print $logfile "\nPANIC: Target dir is ".$srcd; - return "Invalid target directory, FAIL"; + $r->print( + "".&mt('Invalid target directory, FAIL').""); + return 0; } opendir(DIR,$srcd); while ($filename=readdir(DIR)) { @@ -1397,8 +1624,9 @@ sub phasetwo { $r->print(''.&mt('Copied old target file').'
'); } else { print $logfile "Unable to write ".$copyfile.':'.$!."\n"; - return "".&mt('Failed to copy old target'). - ", $!, ".&mt('FAIL').""; + $r->print("".&mt('Failed to copy old target'). + ", $!, ".&mt('FAIL').""); + return 0; } # --------------------------------------------------------------- Copy Metadata @@ -1411,15 +1639,16 @@ sub phasetwo { } else { print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n"; if (-e $target.'.meta') { - return - "". -&mt('Failed to write old metadata copy').", $!, ".&mt('FAIL').""; + $r->print( + "". +&mt('Failed to write old metadata copy').", $!, ".&mt('FAIL').""); + return 0; } } } else { - $r->print('Initial version
'); + $r->print(''.&mt('Initial version').'
'); print $logfile "\nInitial version"; } @@ -1444,8 +1673,9 @@ sub phasetwo { $r->print(''.&mt('Copied source file').'
'); } else { print $logfile "\nUnable to write ".$copyfile.':'.$!."\n"; - return "". - &mt('Failed to copy source').", $!, ".&mt('FAIL').""; + $r->print("". + &mt('Failed to copy source').", $!, ".&mt('FAIL').""); + return 0; } # --------------------------------------------------------------- Copy Metadata @@ -1457,53 +1687,31 @@ sub phasetwo { $r->print(''.&mt('Copied metadata').'
'); } else { print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n"; - return - "".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL').""; + $r->print( + "".&mt('Failed to write metadata copy').", $!, ".&mt('FAIL').""); + return 0; } $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.'
'. -&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.'
'.&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.'
'.&mt('Done').'
'); + return 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; + } +# ---------------------------------------- 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(); + } + if ($lock) { &Apache::lonnet::remove_lock($lock); } + return OK; } ######################################### sub batchpublish { my ($r,$srcfile,$targetfile)=@_; - #publication pollutes %ENV with form.* values - my %oldENV=%ENV; + #publication pollutes %env with form.* values + my %oldenv=%env; $srcfile=~s/\/+/\//g; $targetfile=~s/\/+/\//g; my $thisdisfn=$srcfile; @@ -1535,17 +1786,15 @@ sub batchpublish { $thisdistarget=~s/^\Q$docroot\E//; - undef %metadatafields; - undef %metadatakeys; - %metadatafields=(); - %metadatakeys=(); - $srcfile=~/\.(\w+)$/; - my $thistype=$1; + %metadatafields=(); + %metadatakeys=(); + $srcfile=~/\.(\w+)$/; + my $thistype=$1; - my $thisembstyle=&Apache::loncommon::fileembstyle($thistype); + my $thisembstyle=&Apache::loncommon::fileembstyle($thistype); - $r->print(''.$outstring.'
'); # phase two takes # my ($source,$target,$style,$distarget,batch)=@_; -# $ENV{'form.allmeta'},$ENV{'form.title'},$ENV{'form.author'},... +# $env{'form.allmeta'},$env{'form.title'},$env{'form.author'},... if (!$error) { $r->print(''); &phasetwo($r,$srcfile,$targetfile,$thisembstyle,$thisdistarget,1); $r->print('
'); } - %ENV=%oldENV; + %env=%oldenv; return ''; } @@ -1570,53 +1819,129 @@ sub publishdirectory { $fn=~s/\/+/\//g; $thisdisfn=~s/\/+/\//g; my $resdir= - $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cudom.'/'.$cuname.'/'. - $thisdisfn; - $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.'