version 1.95, 2002/09/16 13:05:50
|
version 1.104, 2002/10/19 06:34:15
|
Line 139 my $docroot;
|
Line 139 my $docroot;
|
my $cuname; |
my $cuname; |
my $cudom; |
my $cudom; |
|
|
######################################### |
|
######################################### |
|
|
|
=pod |
=pod |
|
|
=item B<metaeval> |
=item B<metaeval> |
Line 265 sub metaread {
|
Line 262 sub metaread {
|
} |
} |
|
|
######################################### |
######################################### |
######################################### |
|
|
|
=pod |
|
|
|
=item B<sqltime> |
|
|
|
Convert 'time' format into a datetime sql format |
|
|
|
Parameters: |
|
|
|
=over 4 |
|
|
|
=item I<$timef> |
|
|
|
Seconds since 00:00:00 UTC, January 1, 1970. |
|
|
|
=back |
|
|
|
Returns: |
|
|
|
=over 4 |
|
|
|
=item Scalar string |
|
|
|
MySQL-compatible datetime string. |
|
|
|
=back |
|
|
|
=cut |
|
|
|
######################################### |
######################################### |
######################################### |
######################################### |
sub sqltime { |
|
my $timef=shift @_; |
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = |
|
localtime($timef); |
|
$mon++; $year+=1900; |
|
return "$year-$mon-$mday $hour:$min:$sec"; |
|
} |
|
|
|
|
|
|
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; |
|
$regexp='___'.$regexp.'___course'; |
|
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$/) { |
|
$courses{$1}=1; |
|
} |
|
} |
|
return %courses; |
|
} |
######################################### |
######################################### |
######################################### |
######################################### |
|
|
|
|
=pod |
=pod |
|
|
=item Form-field-generating subroutines. |
=item Form-field-generating subroutines. |
Line 469 sub get_subscribed_hosts {
|
Line 447 sub get_subscribed_hosts {
|
while ($filename=readdir(DIR)) { |
while ($filename=readdir(DIR)) { |
if ($filename=~/$srcf\.(\w+)$/) { |
if ($filename=~/$srcf\.(\w+)$/) { |
my $subhost=$1; |
my $subhost=$1; |
if ($subhost ne 'meta' && $subhost ne 'subscription') { |
if (($subhost ne 'meta' && $subhost ne 'subscription') && |
|
($subhost ne $Apache::lonnet::perlvar{'lonHostID'})) { |
push(@subscribed,$subhost); |
push(@subscribed,$subhost); |
} |
} |
} |
} |
Line 480 sub get_subscribed_hosts {
|
Line 459 sub get_subscribed_hosts {
|
&Apache::lonnet::logthis("opened $target.subscription"); |
&Apache::lonnet::logthis("opened $target.subscription"); |
while (my $subline=<$sh>) { |
while (my $subline=<$sh>) { |
&Apache::lonnet::logthis("Trying $subline"); |
&Apache::lonnet::logthis("Trying $subline"); |
if ($subline =~ /(^\w+):/) { push(@subscribed,$1); } else { |
if ($subline =~ /(^\w+):/) { |
|
if ($1 ne $Apache::lonnet::perlvar{'lonHostID'}) { |
|
push(@subscribed,$1); |
|
} |
|
} else { |
&Apache::lonnet::logthis("No Match for $subline"); |
&Apache::lonnet::logthis("No Match for $subline"); |
} |
} |
} |
} |
} else { |
} else { |
&Apache::lonnet::logthis("Unable to open $target.subscription"); |
&Apache::lonnet::logthis("Unable to open $target.subscription"); |
} |
} |
&Apache::lonnet::logthis("Got list of ".join(':',@subscribed)); |
|
return @subscribed; |
return @subscribed; |
} |
} |
|
|
Line 805 I<Additional documentation needed.>
|
Line 787 I<Additional documentation needed.>
|
######################################### |
######################################### |
sub publish { |
sub publish { |
|
|
my ($source,$target,$style)=@_; |
my ($source,$target,$style,$batch)=@_; |
my $logfile; |
my $logfile; |
my $scrout=''; |
my $scrout=''; |
my $allmeta=''; |
my $allmeta=''; |
Line 896 sub publish {
|
Line 878 sub publish {
|
|
|
my %oldparmstores=(); |
my %oldparmstores=(); |
|
|
|
unless ($batch) { |
$scrout.='<h3>Metadata Information ' . |
$scrout.='<h3>Metadata Information ' . |
Apache::loncommon::help_open_topic("Metadata_Description") |
Apache::loncommon::help_open_topic("Metadata_Description") |
. '</h3>'; |
. '</h3>'; |
|
} |
|
|
# ------------------------------------------------ First, check out environment |
# ------------------------------------------------ First, check out environment |
unless (-e $source.'.meta') { |
unless (-e $source.'.meta') { |
Line 993 sub publish {
|
Line 976 sub publish {
|
|
|
# ------------------------------------------------------- Now have all metadata |
# ------------------------------------------------------- Now have all metadata |
|
|
|
my %keywords=(); |
|
|
|
if (length($content)<500000) { |
|
my $textonly=$content; |
|
$textonly=~s/\<script[^\<]+\<\/script\>//g; |
|
$textonly=~s/\<m\>[^\<]+\<\/m\>//g; |
|
$textonly=~s/\<[^\>]*\>//g; |
|
$textonly=~tr/A-Z/a-z/; |
|
$textonly=~s/[\$\&][a-z]\w*//g; |
|
$textonly=~s/[^a-z\s]//g; |
|
|
|
foreach ($textonly=~m/(\w+)/g) { |
|
unless ($nokey{$_}) { |
|
$keywords{$_}=1; |
|
} |
|
} |
|
} |
|
|
|
|
|
foreach (split(/\W+/,$metadatafields{'keywords'})) { |
|
$keywords{$_}=1; |
|
} |
|
# --------------------------------------------------- Now we also have keywords |
|
# ============================================================================= |
|
# INTERACTIVE MODE |
|
# |
|
unless ($batch) { |
$scrout.= |
$scrout.= |
'<form name="pubform" action="/adm/publish" method="post">'. |
'<form name="pubform" action="/adm/publish" method="post">'. |
'<p><input type="submit" value="Finalize Publication" /></p>'. |
'<p><input type="submit" value="Finalize Publication" /></p>'. |
Line 1028 function uncheckAll(field)
|
Line 1038 function uncheckAll(field)
|
END |
END |
$keywordout.='<table border=2><tr>'; |
$keywordout.='<table border=2><tr>'; |
my $colcount=0; |
my $colcount=0; |
my %keywords=(); |
|
|
|
if (length($content)<500000) { |
|
my $textonly=$content; |
|
$textonly=~s/\<script[^\<]+\<\/script\>//g; |
|
$textonly=~s/\<m\>[^\<]+\<\/m\>//g; |
|
$textonly=~s/\<[^\>]*\>//g; |
|
$textonly=~tr/A-Z/a-z/; |
|
$textonly=~s/[\$\&][a-z]\w*//g; |
|
$textonly=~s/[^a-z\s]//g; |
|
|
|
foreach ($textonly=~m/(\w+)/g) { |
|
unless ($nokey{$_}) { |
|
$keywords{$_}=1; |
|
} |
|
} |
|
} |
|
|
|
|
|
foreach (split(/\W+/,$metadatafields{'keywords'})) { |
|
$keywords{$_}=1; |
|
} |
|
|
|
foreach (sort keys %keywords) { |
foreach (sort keys %keywords) { |
$keywordout.='<td><input type=checkbox name="keywords" value="'.$_.'"'; |
$keywordout.='<td><input type=checkbox name="keywords" value="'.$_.'"'; |
Line 1093 END
|
Line 1081 END
|
unless ($metadatafields{'creationdate'}) { |
unless ($metadatafields{'creationdate'}) { |
$metadatafields{'creationdate'}=time; |
$metadatafields{'creationdate'}=time; |
} |
} |
$scrout.=&hiddenfield('creationdate',$metadatafields{'creationdate'}); |
$scrout.=&hiddenfield('creationdate', |
|
&Apache::loncommon::unsqltime($metadatafields{'creationdate'})); |
|
|
$scrout.=&hiddenfield('lastrevisiondate',time); |
$scrout.=&hiddenfield('lastrevisiondate',time); |
|
|
Line 1123 END
|
Line 1112 END
|
$scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge; |
$scrout =~ s/DISTRIBUTION:/'DISTRIBUTION: ' . $copyright_help/ge; |
return $scrout. |
return $scrout. |
'<p><input type="submit" value="Finalize Publication" /></p></form>'; |
'<p><input type="submit" value="Finalize Publication" /></p></form>'; |
|
# ============================================================================= |
|
# BATCH MODE |
|
# |
|
} else { |
|
# Transfer metadata directly to environment for stage 2 |
|
foreach (keys %metadatafields) { |
|
$ENV{'form.'.$_}=$metadatafields{$_}; |
|
} |
|
$ENV{'form.addkey'}=''; |
|
$ENV{'form.keywords'}=''; |
|
foreach (keys %keywords) { |
|
if ($metadatafields{'keywords'}) { |
|
if ($metadatafields{'keywords'}=~/$_/) { |
|
$ENV{'form.keywords'}.=$_.','; |
|
} |
|
} elsif (&Apache::loncommon::keyword($_)) { |
|
$ENV{'form.keywords'}.=$_.','; |
|
} |
|
} |
|
$ENV{'form.keywords'}=~s/\,$//; |
|
unless ($ENV{'form.creationdate'}) { $ENV{'form.creationdate'}=time; } |
|
$ENV{'form.lastrevisiondate'}=time; |
|
if ((($style eq 'rat') && ($ENV{'form.copyright'} eq 'public')) || |
|
(!$ENV{'form.copyright'})) { |
|
$ENV{'form.copyright'}='default'; |
|
} |
|
$ENV{'form.allmeta'}=&Apache::lonnet::escape($allmeta); |
|
return $scrout; |
|
} |
} |
} |
|
|
######################################### |
######################################### |
Line 1156 Returns:
|
Line 1174 Returns:
|
=item Scalar string |
=item Scalar string |
|
|
String contains status (errors and warnings) and information associated with |
String contains status (errors and warnings) and information associated with |
the server's attempts at publication. |
the server's attempts at publication. |
|
|
=cut |
=cut |
|
|
|
#'stupid emacs |
######################################### |
######################################### |
######################################### |
######################################### |
sub phasetwo { |
sub phasetwo { |
|
|
my ($source,$target,$style,$distarget)=@_; |
my ($r,$source,$target,$style,$distarget,$batch)=@_; |
|
$source=~s/\/+/\//g; |
|
$target=~s/\/+/\//g; |
|
$distarget=~s/\/+/\//g; |
my $logfile; |
my $logfile; |
my $scrout=''; |
|
unless ($logfile=Apache::File->new('>>'.$source.'.log')) { |
unless ($logfile=Apache::File->new('>>'.$source.'.log')) { |
return |
return |
'<font color=red>No write permission to user directory, FAIL</font>'; |
'<font color=red>No write permission to user directory, FAIL</font>'; |
} |
} |
print $logfile |
print $logfile |
"\n================= Publish ".localtime()." Phase Two ================\n"; |
"\n================= Publish ".localtime()." Phase Two ================\n"; |
|
|
%metadatafields=(); |
%metadatafields=(); |
%metadatakeys=(); |
%metadatakeys=(); |
|
|
&metaeval(&Apache::lonnet::unescape($ENV{'form.allmeta'})); |
&metaeval(&Apache::lonnet::unescape($ENV{'form.allmeta'})); |
|
|
$metadatafields{'title'}=$ENV{'form.title'}; |
$metadatafields{'title'}=$ENV{'form.title'}; |
$metadatafields{'author'}=$ENV{'form.author'}; |
$metadatafields{'author'}=$ENV{'form.author'}; |
$metadatafields{'subject'}=$ENV{'form.subject'}; |
$metadatafields{'subject'}=$ENV{'form.subject'}; |
$metadatafields{'notes'}=$ENV{'form.notes'}; |
$metadatafields{'notes'}=$ENV{'form.notes'}; |
$metadatafields{'abstract'}=$ENV{'form.abstract'}; |
$metadatafields{'abstract'}=$ENV{'form.abstract'}; |
$metadatafields{'mime'}=$ENV{'form.mime'}; |
$metadatafields{'mime'}=$ENV{'form.mime'}; |
$metadatafields{'language'}=$ENV{'form.language'}; |
$metadatafields{'language'}=$ENV{'form.language'}; |
$metadatafields{'creationdate'}= |
$metadatafields{'creationdate'}=$ENV{'form.creationdate'}; |
&sqltime($ENV{'form.creationdate'}); |
$metadatafields{'lastrevisiondate'}=$ENV{'form.lastrevisiondate'}; |
$metadatafields{'lastrevisiondate'}= |
$metadatafields{'owner'}=$ENV{'form.owner'}; |
&sqltime($ENV{'form.lastrevisiondate'}); |
$metadatafields{'copyright'}=$ENV{'form.copyright'}; |
$metadatafields{'owner'}=$ENV{'form.owner'}; |
$metadatafields{'dependencies'}=$ENV{'form.dependencies'}; |
$metadatafields{'copyright'}=$ENV{'form.copyright'}; |
|
$metadatafields{'dependencies'}=$ENV{'form.dependencies'}; |
my $allkeywords=$ENV{'form.addkey'}; |
|
if (exists($ENV{'form.keywords'})) { |
my $allkeywords=$ENV{'form.addkey'}; |
if (ref($ENV{'form.keywords'})) { |
if (exists($ENV{'form.keywords'})) { |
$allkeywords .= ','.join(',',@{$ENV{'form.keywords'}}); |
if (ref($ENV{'form.keywords'})) { |
} else { |
$allkeywords .= ','.join(',',@{$ENV{'form.keywords'}}); |
$allkeywords .= ','.$ENV{'form.keywords'}; |
} else { |
} |
$allkeywords .= ','.$ENV{'form.keywords'}; |
} |
} |
$allkeywords=~s/\W+/\,/; |
} |
$allkeywords=~s/^\,//; |
$allkeywords=~s/\W+/\,/; |
$metadatafields{'keywords'}=$allkeywords; |
$allkeywords=~s/^\,//; |
|
$metadatafields{'keywords'}=$allkeywords; |
{ |
|
print $logfile "\nWrite metadata file for ".$source; |
{ |
my $mfh; |
print $logfile "\nWrite metadata file for ".$source; |
unless ($mfh=Apache::File->new('>'.$source.'.meta')) { |
my $mfh; |
return |
unless ($mfh=Apache::File->new('>'.$source.'.meta')) { |
'<font color=red>Could not write metadata, FAIL</font>'; |
return |
} |
'<font color=red>Could not write metadata, FAIL</font>'; |
foreach (sort keys %metadatafields) { |
} |
unless ($_=~/\./) { |
foreach (sort keys %metadatafields) { |
my $unikey=$_; |
unless ($_=~/\./) { |
$unikey=~/^([A-Za-z]+)/; |
my $unikey=$_; |
my $tag=$1; |
$unikey=~/^([A-Za-z]+)/; |
$tag=~tr/A-Z/a-z/; |
my $tag=$1; |
print $mfh "\n\<$tag"; |
$tag=~tr/A-Z/a-z/; |
foreach (split(/\,/,$metadatakeys{$unikey})) { |
print $mfh "\n\<$tag"; |
my $value=$metadatafields{$unikey.'.'.$_}; |
foreach (split(/\,/,$metadatakeys{$unikey})) { |
$value=~s/\"/\'\'/g; |
my $value=$metadatafields{$unikey.'.'.$_}; |
print $mfh ' '.$_.'="'.$value.'"'; |
$value=~s/\"/\'\'/g; |
} |
print $mfh ' '.$_.'="'.$value.'"'; |
print $mfh '>'. |
} |
&HTML::Entities::encode($metadatafields{$unikey}) |
print $mfh '>'. |
.'</'.$tag.'>'; |
&HTML::Entities::encode($metadatafields{$unikey}) |
} |
.'</'.$tag.'>'; |
} |
} |
$r->print('<p>Wrote Metadata'); |
} |
print $logfile "\nWrote metadata"; |
$scrout.='<p>Wrote Metadata'; |
} |
print $logfile "\nWrote metadata"; |
|
} |
|
|
|
# -------------------------------- Synchronize entry with SQL metadata database |
# -------------------------------- Synchronize entry with SQL metadata database |
my $warning; |
|
$metadatafields{'url'} = $distarget; |
$metadatafields{'url'} = $distarget; |
$metadatafields{'version'} = 'current'; |
$metadatafields{'version'} = 'current'; |
unless ($metadatafields{'copyright'} eq 'priv') { |
unless ($metadatafields{'copyright'} eq 'priv') { |
my ($error,$success) = &store_metadata(\%metadatafields); |
my ($error,$success) = &store_metadata(\%metadatafields); |
if ($success) { |
if ($success) { |
$scrout.='<p>Synchronized SQL metadata database'; |
$r->print('<p>Synchronized SQL metadata database'); |
print $logfile "\nSynchronized SQL metadata database"; |
print $logfile "\nSynchronized SQL metadata database"; |
} else { |
} else { |
$warning.=$error; |
$r->print($error); |
print $logfile "\n".$error; |
print $logfile "\n".$error; |
} |
} |
} else { |
} else { |
$scrout.='<p>Private Publication - did not synchronize database'; |
$r->print('<p>Private Publication - did not synchronize database'); |
print $logfile "\nPrivate: Did not synchronize data into ". |
print $logfile "\nPrivate: Did not synchronize data into ". |
"SQL metadata database"; |
"SQL metadata database"; |
} |
} |
# ----------------------------------------------------------- Copy old versions |
# ----------------------------------------------------------- Copy old versions |
|
|
if (-e $target) { |
if (-e $target) { |
my $filename; |
my $filename; |
my $maxversion=0; |
my $maxversion=0; |
$target=~/(.*)\/([^\/]+)\.(\w+)$/; |
$target=~/(.*)\/([^\/]+)\.(\w+)$/; |
my $srcf=$2; |
my $srcf=$2; |
my $srct=$3; |
my $srct=$3; |
my $srcd=$1; |
my $srcd=$1; |
unless ($srcd=~/^\/home\/httpd\/html\/res/) { |
unless ($srcd=~/^\/home\/httpd\/html\/res/) { |
print $logfile "\nPANIC: Target dir is ".$srcd; |
print $logfile "\nPANIC: Target dir is ".$srcd; |
return "<font color=red>Invalid target directory, FAIL</font>"; |
return "<font color=red>Invalid target directory, FAIL</font>"; |
} |
} |
opendir(DIR,$srcd); |
opendir(DIR,$srcd); |
while ($filename=readdir(DIR)) { |
while ($filename=readdir(DIR)) { |
if ($filename=~/$srcf\.(\d+)\.$srct$/) { |
if (-l $srcd.'/'.$filename) { |
$maxversion=($1>$maxversion)?$1:$maxversion; |
unlink($srcd.'/'.$filename); |
} |
unlink($srcd.'/'.$filename.'.meta'); |
} |
} else { |
closedir(DIR); |
if ($filename=~/$srcf\.(\d+)\.$srct$/) { |
$maxversion++; |
$maxversion=($1>$maxversion)?$1:$maxversion; |
$scrout.='<p>Creating old version '.$maxversion; |
} |
print $logfile "\nCreating old version ".$maxversion; |
} |
|
} |
my $copyfile=$srcd.'/'.$srcf.'.'.$maxversion.'.'.$srct; |
closedir(DIR); |
|
$maxversion++; |
|
$r->print('<p>Creating old version '.$maxversion); |
|
print $logfile "\nCreating old version ".$maxversion; |
|
|
|
my $copyfile=$srcd.'/'.$srcf.'.'.$maxversion.'.'.$srct; |
|
|
if (copy($target,$copyfile)) { |
if (copy($target,$copyfile)) { |
print $logfile "Copied old target to ".$copyfile."\n"; |
print $logfile "Copied old target to ".$copyfile."\n"; |
$scrout.='<p>Copied old target file'; |
$r->print('<p>Copied old target file'); |
} else { |
} else { |
print $logfile "Unable to write ".$copyfile.':'.$!."\n"; |
print $logfile "Unable to write ".$copyfile.':'.$!."\n"; |
return "<font color=red>Failed to copy old target, $!, FAIL</font>"; |
return "<font color=red>Failed to copy old target, $!, FAIL</font>"; |
} |
} |
|
|
# --------------------------------------------------------------- Copy Metadata |
# --------------------------------------------------------------- Copy Metadata |
|
|
$copyfile=$copyfile.'.meta'; |
$copyfile=$copyfile.'.meta'; |
|
|
if (copy($target.'.meta',$copyfile)) { |
if (copy($target.'.meta',$copyfile)) { |
print $logfile "Copied old target metadata to ".$copyfile."\n"; |
print $logfile "Copied old target metadata to ".$copyfile."\n"; |
$scrout.='<p>Copied old metadata'; |
$r->print('<p>Copied old metadata') |
} else { |
} else { |
print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n"; |
print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n"; |
if (-e $target.'.meta') { |
if (-e $target.'.meta') { |
return |
return |
"<font color=red>Failed to write old metadata copy, $!, FAIL</font>"; |
"<font color=red>Failed to write old metadata copy, $!, FAIL</font>"; |
} |
} |
} |
} |
|
|
|
|
} else { |
} else { |
$scrout.='<p>Initial version'; |
$r->print('<p>Initial version'); |
print $logfile "\nInitial version"; |
print $logfile "\nInitial version"; |
} |
} |
|
|
# ---------------------------------------------------------------- Write Source |
# ---------------------------------------------------------------- Write Source |
my $copyfile=$target; |
my $copyfile=$target; |
|
|
my @parts=split(/\//,$copyfile); |
my @parts=split(/\//,$copyfile); |
my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]"; |
my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]"; |
|
|
my $count; |
my $count; |
for ($count=5;$count<$#parts;$count++) { |
for ($count=5;$count<$#parts;$count++) { |
$path.="/$parts[$count]"; |
$path.="/$parts[$count]"; |
if ((-e $path)!=1) { |
if ((-e $path)!=1) { |
print $logfile "\nCreating directory ".$path; |
print $logfile "\nCreating directory ".$path; |
$scrout.='<p>Created directory '.$parts[$count]; |
$r->print('<p>Created directory '.$parts[$count]); |
mkdir($path,0777); |
mkdir($path,0777); |
} |
|
} |
|
|
|
if (copy($source,$copyfile)) { |
|
print $logfile "Copied original source to ".$copyfile."\n"; |
|
$scrout.='<p>Copied source file'; |
|
} else { |
|
print $logfile "Unable to write ".$copyfile.':'.$!."\n"; |
|
return "<font color=red>Failed to copy source, $!, FAIL</font>"; |
|
} |
} |
|
} |
|
|
|
if (copy($source,$copyfile)) { |
|
print $logfile "\nCopied original source to ".$copyfile."\n"; |
|
$r->print('<p>Copied source file'); |
|
} else { |
|
print $logfile "\nUnable to write ".$copyfile.':'.$!."\n"; |
|
return "<font color=red>Failed to copy source, $!, FAIL</font>"; |
|
} |
|
|
# --------------------------------------------------------------- Copy Metadata |
# --------------------------------------------------------------- Copy Metadata |
|
|
$copyfile=$copyfile.'.meta'; |
$copyfile=$copyfile.'.meta'; |
|
|
if (copy($source.'.meta',$copyfile)) { |
if (copy($source.'.meta',$copyfile)) { |
print $logfile "Copied original metadata to ".$copyfile."\n"; |
print $logfile "\nCopied original metadata to ".$copyfile."\n"; |
$scrout.='<p>Copied metadata'; |
$r->print('<p>Copied metadata'); |
} else { |
} else { |
print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n"; |
print $logfile "\nUnable to write metadata ".$copyfile.':'.$!."\n"; |
return |
return |
"<font color=red>Failed to write metadata copy, $!, FAIL</font>"; |
"<font color=red>Failed to write metadata copy, $!, FAIL</font>"; |
} |
} |
|
$r->rflush; |
# --------------------------------------------------- Send update notifications |
# --------------------------------------------------- Send update notifications |
|
|
my @subscribed=&get_subscribed_hosts($target); |
my @subscribed=&get_subscribed_hosts($target); |
foreach my $subhost (@subscribed) { |
foreach my $subhost (@subscribed) { |
$scrout.='<p>Notifying host '.$subhost.':'; |
$r->print('<p>Notifying host '.$subhost.':');$r->rflush; |
print $logfile "\nNotifying host ".$subhost.':'; |
print $logfile "\nNotifying host ".$subhost.':'; |
my $reply=&Apache::lonnet::critical('update:'.$target,$subhost); |
my $reply=&Apache::lonnet::critical('update:'.$target,$subhost); |
$scrout.=$reply; |
$r->print($reply.'<br />');$r->rflush; |
print $logfile $reply; |
print $logfile $reply; |
} |
} |
|
|
# ---------------------------------------- Send update notifications, meta only |
# ---------------------------------------- Send update notifications, meta only |
|
|
my @subscribedmeta=&get_subscribed_hosts("$target.meta"); |
my @subscribedmeta=&get_subscribed_hosts("$target.meta"); |
foreach my $subhost (@subscribedmeta) { |
foreach my $subhost (@subscribedmeta) { |
$scrout.='<p>Notifying host for metadata only '.$subhost.':'; |
$r->print('<p>Notifying host for metadata only '.$subhost.':');$r->rflush; |
print $logfile "\nNotifying host for metadata only ".$subhost.':'; |
print $logfile "\nNotifying host for metadata only ".$subhost.':'; |
my $reply=&Apache::lonnet::critical('update:'.$target.'.meta', |
my $reply=&Apache::lonnet::critical('update:'.$target.'.meta', |
$subhost); |
$subhost); |
$scrout.=$reply; |
$r->print($reply.'<br />');$r->rflush; |
|
print $logfile $reply; |
|
} |
|
|
|
# --------------------------------------------------- Notify subscribed courses |
|
my %courses=&coursedependencies($target); |
|
my $now=time; |
|
foreach (keys %courses) { |
|
$r->print('<p>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.'<br />');$r->rflush; |
print $logfile $reply; |
print $logfile $reply; |
} |
} |
|
|
# ------------------------------------------------ Provide link to new resource |
# ------------------------------------------------ Provide link to new resource |
|
unless ($batch) { |
my $thisdistarget=$target; |
my $thisdistarget=$target; |
$thisdistarget=~s/^$docroot//; |
$thisdistarget=~s/^$docroot//; |
|
|
my $thissrc=$source; |
my $thissrc=$source; |
$thissrc=~s/^\/home\/(\w+)\/public_html/\/priv\/$1/; |
$thissrc=~s/^\/home\/(\w+)\/public_html/\/priv\/$1/; |
|
|
my $thissrcdir=$thissrc; |
my $thissrcdir=$thissrc; |
$thissrcdir=~s/\/[^\/]+$/\//; |
$thissrcdir=~s/\/[^\/]+$/\//; |
|
|
|
|
return $warning.$scrout. |
$r->print( |
'<hr><a href="'.$thisdistarget.'"><font size="+2">'. |
'<hr><a href="'.$thisdistarget.'"><font size="+2">'. |
'View Published Version</font></a>'. |
'View Published Version</font></a>'. |
'<p><a href="'.$thissrc.'"><font size=+2>Back to Source</font></a>'. |
'<p><a href="'.$thissrc.'"><font size=+2>Back to Source</font></a>'. |
'<p><a href="'.$thissrcdir. |
'<p><a href="'.$thissrcdir. |
'"><font size="+2">Back to Source Directory</font></a>'; |
'"><font size="+2">Back to Source Directory</font></a>'); |
|
} |
} |
} |
|
|
######################################### |
######################################### |
|
|
sub batchpublish { |
sub batchpublish { |
my ($r,$srcfile)=@_; |
my ($r,$srcfile,$targetfile)=@_; |
|
$srcfile=~s/\/+/\//g; |
|
$targetfile=~s/\/+/\//g; |
my $thisdisfn=$srcfile; |
my $thisdisfn=$srcfile; |
$thisdisfn=~s/\/home\/korte\/public_html\///; |
$thisdisfn=~s/\/home\/korte\/public_html\///; |
$srcfile=~s/\/+/\//g; |
$srcfile=~s/\/+/\//g; |
|
|
|
my $docroot=$r->dir_config('lonDocRoot'); |
|
my $thisdistarget=$targetfile; |
|
$thisdistarget=~s/^$docroot//; |
|
|
|
|
|
undef %metadatafields; |
|
undef %metadatakeys; |
|
%metadatafields=(); |
|
%metadatakeys=(); |
|
$srcfile=~/\.(\w+)$/; |
|
my $thistype=$1; |
|
|
|
|
|
my $thisembstyle=&Apache::loncommon::fileembstyle($thistype); |
|
|
$r->print('<h2>Publishing <tt>'.$thisdisfn.'</tt></h2>'); |
$r->print('<h2>Publishing <tt>'.$thisdisfn.'</tt></h2>'); |
|
|
|
# phase one takes |
|
# my ($source,$target,$style,$batch)=@_; |
|
$r->print('<p>'.&publish($srcfile,$targetfile,$thisembstyle,1).'</p>'); |
|
# phase two takes |
|
# my ($source,$target,$style,$distarget,batch)=@_; |
|
# $ENV{'form.allmeta'},$ENV{'form.title'},$ENV{'form.author'},... |
|
$r->print('<p>'); |
|
&phasetwo($r,$srcfile,$targetfile,$thisembstyle,$thisdistarget,1); |
|
$r->print('</p>'); |
|
return ''; |
} |
} |
|
|
######################################### |
######################################### |
|
|
sub publishdirectory { |
sub publishdirectory { |
my ($r,$fn,$thisdisfn)=@_; |
my ($r,$fn,$thisdisfn)=@_; |
$r->print('<h1>Directory <tt>'.$thisdisfn.'/</tt></h1>'); |
$fn=~s/\/+/\//g; |
|
$thisdisfn=~s/\/+/\//g; |
|
my $resdir= |
|
$Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cudom.'/'.$cuname.'/'. |
|
$thisdisfn; |
|
$r->print('<h1>Directory <tt>'.$thisdisfn.'</tt></h1>'. |
|
'Target: <tt>'.$resdir.'</tt><br />'); |
|
|
my $dirptr=16384; # Mask indicating a directory in stat.cmode. |
my $dirptr=16384; # Mask indicating a directory in stat.cmode. |
|
|
Line 1422 sub publishdirectory {
|
Line 1493 sub publishdirectory {
|
} |
} |
} elsif ((&Apache::loncommon::fileembstyle($extension) ne 'hdn') && |
} elsif ((&Apache::loncommon::fileembstyle($extension) ne 'hdn') && |
($filename!~/^[\#\.]/) && ($filename!~/\~$/)) { |
($filename!~/^[\#\.]/) && ($filename!~/\~$/)) { |
&batchpublish($r,$fn.'/'.$filename); |
# find out publication status and/or exiting metadata |
|
my $publishthis=0; |
|
if (-e $resdir.'/'.$filename) { |
|
my ($rdev,$rino,$rmode,$rnlink, |
|
$ruid,$rgid,$rrdev,$rsize, |
|
$ratime,$rmtime,$rctime, |
|
$rblksize,$rblocks)=stat($resdir.'/'.$filename); |
|
if ($rmtime<$cmtime) { |
|
# previously published, modified now |
|
$publishthis=1; |
|
} |
|
} else { |
|
# never published |
|
$publishthis=1; |
|
} |
|
if ($publishthis) { |
|
&batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename); |
|
} else { |
|
$r->print('<br />Skipping '.$filename.'<br />'); |
|
} |
$r->rflush(); |
$r->rflush(); |
} |
} |
} |
} |
Line 1570 unless ($ENV{'form.phase'} eq 'two') {
|
Line 1660 unless ($ENV{'form.phase'} eq 'two') {
|
|
|
$r->print('<html><head><title>LON-CAPA Publishing</title></head>'); |
$r->print('<html><head><title>LON-CAPA Publishing</title></head>'); |
$r->print(&Apache::loncommon::bodytag('Resource Publication')); |
$r->print(&Apache::loncommon::bodytag('Resource Publication')); |
|
|
|
|
my $thisfn=$fn; |
my $thisfn=$fn; |
|
|
my $thistarget=$thisfn; |
my $thistarget=$thisfn; |
Line 1606 unless ($ENV{'form.phase'} eq 'two') {
|
Line 1698 unless ($ENV{'form.phase'} eq 'two') {
|
if (&Apache::loncommon::fileembstyle($thistype) eq 'ssi') { |
if (&Apache::loncommon::fileembstyle($thistype) eq 'ssi') { |
$r->print('<br /><a href="/adm/diff?filename=/~'.$cuname.'/'. |
$r->print('<br /><a href="/adm/diff?filename=/~'.$cuname.'/'. |
$thisdisfn. |
$thisdisfn. |
'&versionone=priv" target="cat">Diffs with Current Version</a><p>'); |
'&versiontwo=priv" target="cat">Diffs with Current Version</a><p>'); |
} |
} |
|
|
# ------------------ Publishing from $thisfn to $thistarget with $thisembstyle. |
# ------------------ Publishing from $thisfn to $thistarget with $thisembstyle. |
Line 1615 unless ($ENV{'form.phase'} eq 'two') {
|
Line 1707 unless ($ENV{'form.phase'} eq 'two') {
|
$r->print( |
$r->print( |
'<hr />'.&publish($thisfn,$thistarget,$thisembstyle)); |
'<hr />'.&publish($thisfn,$thistarget,$thisembstyle)); |
} else { |
} else { |
$r->print( |
$r->print('<hr />'); |
'<hr />'.&phasetwo($thisfn,$thistarget, |
&phasetwo($r,$thisfn,$thistarget,$thisembstyle,$thisdistarget); |
$thisembstyle,$thisdistarget)); |
|
} |
} |
|
|
} |
} |