--- loncom/publisher/lonpublisher.pm 2003/09/24 19:40:14 1.126.2.2
+++ loncom/publisher/lonpublisher.pm 2003/11/08 11:20:22 1.145
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.126.2.2 2003/09/24 19:40:14 albertel Exp $
+# $Id: lonpublisher.pm,v 1.145 2003/11/08 11:20:22 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -82,6 +82,26 @@ invocation by F:
ErrorDocument 500 /adm/errorhandler
+=head1 OVERVIEW
+
+Authors can only write-access the C~authorname/> space. They can
+copy resources into the resource area through the publication step,
+and move them back through a recover step. Authors do not have direct
+write-access to their resource space.
+
+During the publication step, several events will be
+triggered. Metadata is gathered, where a wizard manages default
+entries on a hierarchical per-directory base: The wizard imports the
+metadata (including access privileges and royalty information) from
+the most recent published resource in the current directory, and if
+that is not available, from the next directory above, etc. The Network
+keeps all previous versions of a resource and makes them available by
+an explicit version number, which is inserted between the file name
+and extension, for example C, while the most recent
+version does not carry a version number (C). Servers
+subscribing to a changed resource are notified that a new version is
+available.
+
=head1 DESCRIPTION
B takes the proper steps to add resources to the LON-CAPA
@@ -122,6 +142,8 @@ use DBI;
use Apache::lonnet();
use Apache::loncommon();
use Apache::lonmysql;
+use Apache::lonlocal;
+use Apache::loncfile;
use vars qw(%metadatafields %metadatakeys);
my %addid;
@@ -159,46 +181,49 @@ nothing
#########################################
#########################################
+#
+# Modifies global %metadatafields %metadatakeys
+#
+
sub metaeval {
- my $metastring=shift;
+ my ($metastring,$prefix)=@_;
- my $parser=HTML::LCParser->new(\$metastring);
- my $token;
- while ($token=$parser->get_token) {
- if ($token->[0] eq 'S') {
- my $entry=$token->[1];
- my $unikey=$entry;
- if (defined($token->[2]->{'package'})) {
- $unikey.='_package_'.$token->[2]->{'package'};
- }
- if (defined($token->[2]->{'part'})) {
- $unikey.='_'.$token->[2]->{'part'};
- }
- if (defined($token->[2]->{'id'})) {
- $unikey.='_'.$token->[2]->{'id'};
- }
- if (defined($token->[2]->{'name'})) {
- $unikey.='_'.$token->[2]->{'name'};
- }
- foreach (@{$token->[3]}) {
- $metadatafields{$unikey.'.'.$_}=$token->[2]->{$_};
- if ($metadatakeys{$unikey}) {
- $metadatakeys{$unikey}.=','.$_;
- } else {
- $metadatakeys{$unikey}=$_;
- }
- }
- if ($metadatafields{$unikey}) {
- my $newentry=$parser->get_text('/'.$entry);
- unless (($metadatafields{$unikey}=~/\Q$newentry\E/) ||
- ($newentry eq '')) {
- $metadatafields{$unikey}.=', '.$newentry;
- }
- } else {
- $metadatafields{$unikey}=$parser->get_text('/'.$entry);
- }
- }
- }
+ my $parser=HTML::LCParser->new(\$metastring);
+ my $token;
+ while ($token=$parser->get_token) {
+ if ($token->[0] eq 'S') {
+ my $entry=$token->[1];
+ my $unikey=$entry;
+ if (defined($token->[2]->{'package'})) {
+ $unikey.='_package_'.$token->[2]->{'package'};
+ }
+ if (defined($token->[2]->{'part'})) {
+ $unikey.='_'.$token->[2]->{'part'};
+ }
+ if (defined($token->[2]->{'id'})) {
+ $unikey.='_'.$token->[2]->{'id'};
+ }
+ if (defined($token->[2]->{'name'})) {
+ $unikey.='_'.$token->[2]->{'name'};
+ }
+ foreach (@{$token->[3]}) {
+ $metadatafields{$unikey.'.'.$_}=$token->[2]->{$_};
+ if ($metadatakeys{$unikey}) {
+ $metadatakeys{$unikey}.=','.$_;
+ } else {
+ $metadatakeys{$unikey}=$_;
+ }
+ }
+ my $newentry=$parser->get_text('/'.$entry);
+ if ($entry eq 'customdistributionfile') {
+ $newentry=~s/^\s*//;
+ if ($newentry !~m|^/res|) { $newentry=$prefix.$newentry; }
+ }
+ unless ($metadatafields{$unikey}=~/\w/) {
+ $metadatafields{$unikey}=$newentry;
+ }
+ }
+ }
}
#########################################
@@ -239,19 +264,21 @@ XHTML text that indicates successful rea
#########################################
#########################################
sub metaread {
- my ($logfile,$fn)=@_;
+ my ($logfile,$fn,$prefix)=@_;
unless (-e $fn) {
print($logfile 'No file '.$fn."\n");
- return ' No file:'.$fn.'';
+ return ' 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 ' Processed file:'.
+ &Apache::loncfile::display($fn).'';
}
#########################################
@@ -304,6 +331,10 @@ 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);
my $uctitle=uc($title);
return "\n
$uctitle:".
"
".
@@ -317,6 +348,7 @@ sub hiddenfield {
sub selectbox {
my ($title,$name,$value,$functionref,@idlist)=@_;
+ $title=&mt($title);
my $uctitle=uc($title);
$value=(split(/\s*,\s*/,$value))[-1];
my $selout="\n
$uctitle:".
@@ -785,6 +817,26 @@ sub store_metadata {
return (undef,$status);
}
+
+# ============================================== 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;
+}
+
#########################################
#########################################
@@ -874,16 +926,20 @@ sub publish {
}
$outstring=~s/\n*(\<\/[^\>]+\>)\s*$/$allowstr\n$1\n/s;
+### FIXME: is this really what we want?
+# I dont' think so, to will corrupt any UTF-8 resources at least,
+# and any encoding other than ISO-8859-1 will probably break
#Encode any High ASCII characters
- $outstring=&HTML::Entities::encode($outstring,"\200-\377");
+ #$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 ('No write permission to '.$source.
- ', FAIL',1);
+ return (''.&mt('No write permission to').
+ ' '.$source.
+ ', '.&mt('FAIL').'',1);
}
print($org $outstring);
}
@@ -893,14 +949,15 @@ sub publish {
# -------------------------------------------- Initial step done, now metadata.
# --------------------------------------- Storage for metadata keys and fields.
-
+# these are globals
+#
%metadatafields=();
%metadatakeys=();
my %oldparmstores=();
unless ($batch) {
- $scrout.='
';
}
@@ -918,6 +975,10 @@ sub publish {
$ENV{'user.domain'};
$metadatafields{'authorspace'}=$cuname.'@'.$cudom;
+# ----------------------------------------------------------- Parse file itself
+# read %metadatafields from file itself
+
+ $allmeta=&parseformeta($source,$style);
# ------------------------------------------------ Check out directory hierachy
my $thisdisfn=$source;
@@ -928,9 +989,11 @@ 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|^\.\./||;
}
# ------------------- Clear out parameters and stores (there should not be any)
@@ -952,19 +1015,12 @@ sub publish {
delete $metadatafields{$_};
}
}
-
- }
+# ------------------------------------------ See if anything new in file itself
+
+ $allmeta=&parseformeta($source,$style);
+ }
-# -------------------------------------------------- Parse content for metadata
- if (($style eq 'ssi') || ($style eq 'prv')) {
- my $oldenv=$ENV{'request.uri'};
-
- $ENV{'request.uri'}=$target;
- $allmeta=Apache::lonxml::xmlparse(undef,'meta',$content);
- $ENV{'request.uri'}=$oldenv;
-
- &metaeval($allmeta);
- }
+
# ---------------- Find and document discrepancies in the parameters and stores
my $chparms='';
@@ -979,7 +1035,8 @@ sub publish {
}
}
if ($chparms) {
- $scrout.='
New parameters or stored values: '.$chparms.'
';
+ $scrout.='
'.&mt('New parameters or stored values').
+ ': '.$chparms.'
';
}
$chparms='';
@@ -993,8 +1050,10 @@ sub publish {
}
}
if ($chparms) {
- $scrout.='
Obsolete parameters or stored values: '.
- $chparms.'
';
+ $scrout.='
'.&mt('Obsolete parameters or stored values').': '.
+ $chparms.'
'.&mt('Warning!').
+ '
'.
+ &mt('If this resource is in active use, student performance data from the previous version may become inaccessible.').'
';
}
# ------------------------------------------------------- Now have all metadata
@@ -1146,10 +1205,22 @@ END
$scrout.=&textfield('Custom Distribution File','customdistributionfile',
$metadatafields{'customdistributionfile'}).
$copyright_help;
+ my $uctitle=uc(&mt('Obsolete'));
+ $scrout.=
+ "\n
$uctitle:".
+ '
'.
+ &textfield('Suggested Replacement for Obsolete File',
+ 'obsoletereplacement',
+ $metadatafields{'obsoletereplacement'});
} else {
$scrout.=&hiddenfield('copyright','private');
}
- return ($scrout.'',0);
+ return ($scrout.'',0);
# =============================================================================
# BATCH MODE
#
@@ -1227,14 +1298,16 @@ sub phasetwo {
if ($target=~/\_\_\_/) {
$r->print(
- 'Unsupported character combination "___" in filename, FAIL');
+ ''.&mt('Unsupported character combination').
+ ' "___" '.&mt('in filename, FAIL').'');
return 0;
}
$distarget=~s/\/+/\//g;
my $logfile;
unless ($logfile=Apache::File->new('>>'.$source.'.log')) {
$r->print(
- 'No write permission to user directory, FAIL');
+ ''.
+ &mt('No write permission to user directory, FAIL').'');
return 0;
}
print $logfile
@@ -1258,6 +1331,9 @@ sub phasetwo {
$metadatafields{'copyright'}=$ENV{'form.copyright'};
$metadatafields{'customdistributionfile'}=
$ENV{'form.customdistributionfile'};
+ $metadatafields{'obsolete'}=$ENV{'form.obsolete'};
+ $metadatafields{'obsoletereplacement'}=
+ $ENV{'form.obsoletereplacement'};
$metadatafields{'dependencies'}=$ENV{'form.dependencies'};
my $allkeywords=$ENV{'form.addkey'};
@@ -1277,7 +1353,8 @@ sub phasetwo {
my $mfh;
unless ($mfh=Apache::File->new('>'.$source.'.meta')) {
return
- 'Could not write metadata, FAIL';
+ ''.&mt('Could not write metadata, FAIL').
+ '';
}
foreach (sort keys %metadatafields) {
unless ($_=~/\./) {
@@ -1296,7 +1373,7 @@ sub phasetwo {
.''.$tag.'>';
}
}
- $r->print('
Wrote Metadata
');
+ $r->print('
'.&mt('Wrote Metadata').'
');
print $logfile "\nWrote metadata";
}
@@ -1307,14 +1384,15 @@ sub phasetwo {
unless ($metadatafields{'copyright'} eq 'priv') {
my ($error,$success) = &store_metadata(\%metadatafields);
if ($success) {
- $r->print('
Private Publication - did not synchronize database
');
+ $r->print('
'.
+ &mt('Private Publication - did not synchronize database').'
');
print $logfile "\nPrivate: Did not synchronize data into ".
"SQL metadata database";
}
@@ -1351,10 +1429,11 @@ sub phasetwo {
if (copy($target,$copyfile)) {
print $logfile "Copied old target to ".$copyfile."\n";
- $r->print('
Copied old target file
');
+ $r->print('
'.&mt('Copied old target file').'
');
} else {
print $logfile "Unable to write ".$copyfile.':'.$!."\n";
- return "Failed to copy old target, $!, FAIL";
+ return "".&mt('Failed to copy old target').
+ ", $!, ".&mt('FAIL')."";
}
# --------------------------------------------------------------- Copy Metadata
@@ -1363,18 +1442,19 @@ sub phasetwo {
if (copy($target.'.meta',$copyfile)) {
print $logfile "Copied old target metadata to ".$copyfile."\n";
- $r->print('
Copied old metadata
')
+ $r->print('
'.&mt('Copied old metadata').'
')
} else {
print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
if (-e $target.'.meta') {
return
- "Failed to write old metadata copy, $!, FAIL";
+ "".
+&mt('Failed to write old metadata copy').", $!, ".&mt('FAIL')."";
}
}
} else {
- $r->print('
');$r->rflush;
@@ -1430,7 +1511,8 @@ sub phasetwo {
my @subscribedmeta=&get_subscribed_hosts("$target.meta");
foreach my $subhost (@subscribedmeta) {
- $r->print('
Notifying host for metadata only '.$subhost.':');$r->rflush;
+ $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);
@@ -1442,7 +1524,7 @@ sub phasetwo {
my %courses=&coursedependencies($target);
my $now=time;
foreach (keys %courses) {
- $r->print('
'.&mt('Target').':'.
+ $thisdistarget.' ');
- if (($cuname ne $ENV{'user.name'}) || ($cudom ne $ENV{'user.domain'})) {
- $r->print('
Co-Author: '.$cuname.' at '.$cudom.
- '
');
- }
-
- if (&Apache::loncommon::fileembstyle($thistype) eq 'ssi') {
- $r->print(' Diffs with Current Version ');
- }
+ if (($cuname ne $ENV{'user.name'})||($cudom ne $ENV{'user.domain'})) {
+ $r->print('
'.&mt('Co-Author').': '.
+ $cuname.&mt(' at ').$cudom.'