--- loncom/publisher/lonpublisher.pm 2008/08/14 13:39:02 1.245
+++ loncom/publisher/lonpublisher.pm 2024/12/27 04:01:41 1.306
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.245 2008/08/14 13:39:02 onken Exp $
+# $Id: lonpublisher.pm,v 1.306 2024/12/27 04:01:41 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -66,10 +66,10 @@ invocation by F:
=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.
+Authors can only write-access the C 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
@@ -102,8 +102,6 @@ to publication space.
Many of the undocumented subroutines implement various magical
parsing shortcuts.
-=over 4
-
=cut
######################################################################
@@ -121,7 +119,6 @@ use HTML::LCParser;
use HTML::Entities;
use Encode::Encoder;
use Apache::lonxml;
-use Apache::loncacc;
use DBI;
use Apache::lonnet;
use Apache::loncommon();
@@ -131,13 +128,9 @@ use Apache::lonlocal;
use Apache::loncfile;
use LONCAPA::lonmetadata;
use Apache::lonmsg;
-use vars qw(%metadatafields %metadatakeys);
+use vars qw(%metadatafields %metadatakeys %addid $readit);
use LONCAPA qw(:DEFAULT :match);
-
-my %addid;
-my %nokey;
-
my $docroot;
my $cuname;
@@ -150,6 +143,8 @@ my $lock;
=pod
+=over 4
+
=item B
Evaluates a string that contains metadata. This subroutine
@@ -201,12 +196,12 @@ sub metaeval {
if (defined($token->[2]->{'name'})) {
$unikey.="\0".$token->[2]->{'name'};
}
- foreach (@{$token->[3]}) {
- $metadatafields{$unikey.'.'.$_}=$token->[2]->{$_};
+ foreach my $item (@{$token->[3]}) {
+ $metadatafields{$unikey.'.'.$item}=$token->[2]->{$item};
if ($metadatakeys{$unikey}) {
- $metadatakeys{$unikey}.=','.$_;
+ $metadatakeys{$unikey}.=','.$item;
} else {
- $metadatakeys{$unikey}=$_;
+ $metadatakeys{$unikey}=$item;
}
}
my $newentry=$parser->get_text('/'.$entry);
@@ -266,8 +261,9 @@ sub metaread {
my ($logfile,$fn,$prefix)=@_;
unless (-e $fn) {
print($logfile 'No file '.$fn."\n");
- return ' '.&mt('No file').':'.
- &Apache::loncfile::display($fn).'';
+ return '
';
}
#########################################
@@ -292,8 +289,8 @@ sub coursedependencies {
my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
$aauthor,$regexp);
my %courses=();
- foreach (keys %evaldata) {
- if ($_=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
+ foreach my $item (keys(%evaldata)) {
+ if ($item=~/^([a-zA-Z0-9]+_[a-zA-Z0-9]+)___.+___course$/) {
$courses{$1}=1;
}
}
@@ -317,8 +314,12 @@ string which presents the form field (fo
=item B
+=item B
+
=item B
+=item B
+
=item B
=back
@@ -328,7 +329,7 @@ string which presents the form field (fo
#########################################
#########################################
sub textfield {
- my ($title,$name,$value,$noline)=@_;
+ my ($title,$name,$value,$noline,$readonly)=@_;
$value=~s/^\s+//gs;
$value=~s/\s+$//gs;
$value=~s/\s+/ /gs;
@@ -340,22 +341,31 @@ sub textfield {
}
sub text_with_browse_field {
- my ($title,$name,$value,$restriction,$noline)=@_;
+ my ($title,$name,$value,$restriction,$noline,$readonly)=@_;
$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)
- .''
- .' '
+ my $disabled;
+ if ($readonly) {
+ $disabled = ' disabled="disabled"';
+ }
+ my $output =
+ "\n".&Apache::lonhtmlcommon::row_title($title)
+ .'';
+ unless ($readonly) {
+ $output .=
+ ' '
.''
.&mt('Select')
.' '
.''
.&mt('Search')
- .''
- .&Apache::lonhtmlcommon::row_closure($noline);
+ .'';
+ }
+ $output .= &Apache::lonhtmlcommon::row_closure($noline);
+ return $output;
}
sub hiddenfield {
@@ -366,12 +376,12 @@ sub hiddenfield {
sub checkbox {
my ($name,$text)=@_;
- return "\n
'.&mt('Warning!').
- '
'.
- &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.').'
';
+ $scrout.='
'.&mt('Warning!').' '
+ .&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.')
+ .'
';
}
# ------------------------------------------------------- Now have all metadata
@@ -1183,7 +1368,7 @@ sub publish {
$textonly=~s/[^a-z^ü^ä^ö^ß\s]//g; #dont delete german "Umlaute"
foreach ($textonly=~m/[^\s]+/g) { #match all but whitespaces
- unless ($nokey{$_}) {
+ unless ($nokeyref->{$_}) {
$keywords{$_}=1;
}
}
@@ -1210,19 +1395,19 @@ sub publish {
my $intr_scrout.=' '
.'');
+ ''.
+ ''.
+ ''.
+ ''
+ );
+ $r->print(&Apache::lonhtmlcommon::row_closure(1)
+ .&Apache::lonhtmlcommon::end_pick_box()
+ .' '
+ );
$lock=0;
} else {
+ $r->print(&Apache::lonhtmlcommon::row_closure(1)
+ .&Apache::lonhtmlcommon::end_pick_box()
+ );
+ my %commonaccess;
+ map { $commonaccess{$_} = 1; } &Apache::loncommon::get_env_multiple('form.commonaccess');
unless ($lock) { $lock=&Apache::lonnet::set_lock(&mt('Publishing [_1]',$fn)); }
+ if ($lock) {
+ ¬ify_in_cleanup($r);
+ }
# actually publish things
opendir(DIR,$fn);
my @files=sort(readdir(DIR));
@@ -1873,17 +2369,18 @@ sub publishdirectory {
$cuid,$cgid,$crdev,$csize,
$catime,$cmtime,$cctime,
$cblksize,$cblocks)=stat($fn.'/'.$filename);
-
+
my $extension='';
if ($filename=~/\.(\w+)$/) { $extension=$1; }
if ($cmode&$dirptr) {
if (($filename!~/^\./) && ($env{'form.pubrec'})) {
- &publishdirectory($r,$fn.'/'.$filename,$thisdisfn.'/'.$filename);
+ &publishdirectory($r,$fn.'/'.$filename,$thisdisfn.'/'.$filename,$nokeyref,$crsauthor);
}
} elsif ((&Apache::loncommon::fileembstyle($extension) ne 'hdn') &&
($filename!~/^[\#\.]/) && ($filename!~/\~$/)) {
-# find out publication status and/or exiting metadata
+# find out publication status and/or existing metadata
my $publishthis=0;
+ my $skipthis;
if (-e $resdir.'/'.$filename) {
my ($rdev,$rino,$rmode,$rnlink,
$ruid,$rgid,$rrdev,$rsize,
@@ -1891,22 +2388,72 @@ sub publishdirectory {
$rblksize,$rblocks)=stat($resdir.'/'.$filename);
if (($rmtime<$cmtime) || ($env{'form.forcerepub'})) {
# previously published, modified now
- $publishthis=1;
- }
- my $meta_cmtime = (stat($fn.'/'.$filename.'.meta'))[9];
- my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
- if ( $meta_rmtime<$meta_cmtime ) {
- $publishthis=1;
+ if ($env{'form.excludemod'}) {
+ $skipthis='mod';
+ } else {
+ $publishthis=1;
+ }
}
+ unless ($skipthis) {
+ my $meta_cmtime = (stat($fn.'/'.$filename.'.meta'))[9];
+ my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
+ if ( $meta_rmtime<$meta_cmtime ) {
+ if ($env{'form.excludemodmeta'}) {
+ $skipthis='modmeta';
+ $publishthis=0;
+ } else {
+ $publishthis=1;
+ }
+ } else {
+ unless (&Apache::loncommon::fileembstyle($extension) eq 'prv') {
+ if ($commonaccess{'dist'}) {
+ my ($currdist,$currdistfile,$currsourceavail);
+ my $currdist = &Apache::lonnet::metadata($thisdisresdir.'/'.$filename,'copyright');
+ if ($currdist eq 'custom') {
+ $currdistfile = &Apache::lonnet::metadata($thisdisresdir.'/'.$filename,'customdistributionfile');
+ }
+ if ($env{'form.commondistselect'} eq 'custom') {
+ if ($env{'form.commoncustomrights'} =~ m{^/res/.+\.rights$}) {
+ if ($currdist eq 'custom') {
+ unless ($env{'form.commoncustomrights'} eq $currdistfile) {
+ $publishthis=1;
+ }
+ } else {
+ $publishthis=1;
+ }
+ }
+ } elsif ($env{'form.commondistselect'} =~ /^default|domain|public$/) {
+ unless ($currdist eq $env{'form.commondistselect'}) {
+ $publishthis=1;
+ }
+ }
+ }
+ }
+ }
+ }
} else {
# never published
- $publishthis=1;
+ if ($env{'form.excludeunpub'}) {
+ $skipthis='unpub';
+ } else {
+ $publishthis=1;
+ }
}
if ($publishthis) {
- &batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename);
+ &batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename,$nokeyref);
} else {
- $r->print(' '.&mt('Skipping').' '.$filename.' ');
+ my $reason;
+ if ($skipthis) {
+ $reason = $reasons{$skipthis};
+ } else {
+ $reason = &mt('No changes needed to published resource or metadata');
+ }
+ $r->print(' '.&mt('Skipping').' '.$filename);
+ if ($reason) {
+ $r->print(' ('.$reason.')');
+ }
+ $r->print(' ');
}
$r->rflush();
}
@@ -1920,18 +2467,17 @@ sub publishdirectory {
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\//;
+ $target=~s/^\Q$Apache::lonnet::perlvar{'lonDocRoot'}\E\/priv\//\Q$Apache::lonnet::perlvar{'lonDocRoot'}\E\/res\//;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
- $r->print(&Apache::loncommon::start_page('Catalog Information Publication'));
+ $r->print(&Apache::loncommon::start_page('Metadata Publication'));
# ---------------------------------------------------------------- Write Source
my $copyfile=$target;
@@ -1943,8 +2489,12 @@ sub defaultmetapublish {
for ($count=5;$count<$#parts;$count++) {
$path.="/$parts[$count]";
if ((-e $path)!=1) {
- $r->print('