--- loncom/interface/domainprefs.pm 2011/08/15 05:16:30 1.153
+++ loncom/interface/domainprefs.pm 2011/11/07 18:21:17 1.159
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to set domain-wide configuration settings
#
-# $Id: domainprefs.pm,v 1.153 2011/08/15 05:16:30 raeburn Exp $
+# $Id: domainprefs.pm,v 1.159 2011/11/07 18:21:17 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -171,6 +171,9 @@ use Locale::Language;
use DateTime::TimeZone;
use DateTime::Locale;
+my $registered_cleanup;
+my $modified_urls;
+
sub handler {
my $r=shift;
if ($r->header_only) {
@@ -190,6 +193,10 @@ sub handler {
"/adm/domainprefs:mau:0:0:Cannot modify domain settings";
return HTTP_NOT_ACCEPTABLE;
}
+
+ $registered_cleanup=0;
+ @{$modified_urls}=();
+
&Apache::lonhtmlcommon::clear_breadcrumbs();
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['phase','actions']);
@@ -1051,6 +1058,7 @@ sub print_rolecolors {
sub display_color_options {
my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
$images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
my $css_class = $itemcount%2?' class="LC_odd_row"':'';
my $datatable = '
'.
''.$choices->{'font'}.' | ';
@@ -1128,11 +1136,11 @@ sub display_color_options {
$showfile = $imgfile;
my $imgdir = $1;
my $filename = $2;
- if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
+ if (-e "$londocroot/$imgdir/tn-".$filename) {
$showfile = "/$imgdir/tn-".$filename;
} else {
- my $input = "/home/httpd/html".$imgfile;
- my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
+ my $input = $londocroot.$imgfile;
+ my $output = "$londocroot/$imgdir/tn-".$filename;
if (!-e $output) {
my ($width,$height) = &thumb_dimensions();
my ($fullwidth,$fullheight) = &check_dimensions($input);
@@ -1140,7 +1148,7 @@ sub display_color_options {
if ($fullwidth > $width && $fullheight > $height) {
my $size = $width.'x'.$height;
system("convert -sample $size $input $output");
- $showfile = '/'.$imgdir.'/tn-'.$filename;
+ $showfile = "/$imgdir/tn-".$filename;
}
}
}
@@ -3859,7 +3867,7 @@ sub print_serverstatuses {
sub serverstatus_pages {
return ('userstatus','lonstatus','loncron','server-status','codeversions',
'clusterstatus','metadata_keywords','metadata_harvest',
- 'takeoffline','takeonline','showenv','toggledebug');
+ 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
}
sub coursecategories_javascript {
@@ -4927,7 +4935,7 @@ sub publishlogo {
# See if there is anything left
unless ($fname) { return ('error: no uploaded file'); }
$fname="$subdir/$fname";
- my $filepath='/home/'.$confname.'/public_html';
+ my $filepath=$r->dir_config('lonDocRoot')."/priv/$dom/$confname";
my ($fnamepath,$file,$fetchthumb);
$file=$fname;
if ($fname=~m|/|) {
@@ -5005,8 +5013,15 @@ $env{'user.name'}.':'.$env{'user.domain'
if (copy($source,$copyfile)) {
print $logfile "\nCopied original source to ".$copyfile."\n";
$output = 'ok';
- &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
$logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
+ push(@{$modified_urls},[$copyfile,$source]);
+ my $metaoutput =
+ &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
+ unless ($registered_cleanup) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
+ $registered_cleanup=1;
+ }
} else {
print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
$output = &mt('Failed to copy file to RES space').", $!";
@@ -5024,8 +5039,15 @@ $env{'user.name'}.':'.$env{'user.domain'
my $copyfile=$targetdir.'/tn-'.$file;
if (copy($outfile,$copyfile)) {
print $logfile "\nCopied source to ".$copyfile."\n";
- &write_metadata($dom,$confname,$formname,
- $targetdir,'tn-'.$file,$logfile);
+ my $thumb_metaoutput =
+ &write_metadata($dom,$confname,$formname,
+ $targetdir,'tn-'.$file,$logfile);
+ push(@{$modified_urls},[$copyfile,$outfile]);
+ unless ($registered_cleanup) {
+ my $handlers = $r->get_handlers('PerlCleanupHandler');
+ $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
+ $registered_cleanup=1;
+ }
} else {
print $logfile "\nUnable to write ".$copyfile.
':'.$!."\n";
@@ -5090,30 +5112,79 @@ sub write_metadata {
{
print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
my $mfh;
- unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
+ if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
+ foreach (sort keys %metadatafields) {
+ unless ($_=~/\./) {
+ my $unikey=$_;
+ $unikey=~/^([A-Za-z]+)/;
+ my $tag=$1;
+ $tag=~tr/A-Z/a-z/;
+ print $mfh "\n\<$tag";
+ foreach (split(/\,/,$metadatakeys{$unikey})) {
+ my $value=$metadatafields{$unikey.'.'.$_};
+ $value=~s/\"/\'\'/g;
+ print $mfh ' '.$_.'="'.$value.'"';
+ }
+ print $mfh '>'.
+ &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
+ .''.$tag.'>';
+ }
+ }
+ $output = 'ok';
+ print $logfile "\nWrote metadata";
+ close($mfh);
+ } else {
+ print $logfile "\nFailed to open metadata file";
$output = &mt('Could not write metadata');
}
- foreach (sort keys %metadatafields) {
- unless ($_=~/\./) {
- my $unikey=$_;
- $unikey=~/^([A-Za-z]+)/;
- my $tag=$1;
- $tag=~tr/A-Z/a-z/;
- print $mfh "\n\<$tag";
- foreach (split(/\,/,$metadatakeys{$unikey})) {
- my $value=$metadatafields{$unikey.'.'.$_};
- $value=~s/\"/\'\'/g;
- print $mfh ' '.$_.'="'.$value.'"';
- }
- print $mfh '>'.
- &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
- .''.$tag.'>';
- }
- }
- $output = 'ok';
- print $logfile "\nWrote metadata";
- close($mfh);
}
+ return $output;
+}
+
+sub notifysubscribed {
+ foreach my $targetsource (@{$modified_urls}){
+ next unless (ref($targetsource) eq 'ARRAY');
+ my ($target,$source)=@{$targetsource};
+ if ($source ne '') {
+ if (open(my $logfh,'>>'.$source.'.log')) {
+ print $logfh "\nCleanup phase: Notifications\n";
+ my @subscribed=&subscribed_hosts($target);
+ foreach my $subhost (@subscribed) {
+ print $logfh "\nNotifying host ".$subhost.':';
+ my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
+ print $logfh $reply;
+ }
+ my @subscribedmeta=&subscribed_hosts("$target.meta");
+ foreach my $subhost (@subscribedmeta) {
+ print $logfh "\nNotifying host for metadata only ".$subhost.':';
+ my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
+ $subhost);
+ print $logfh $reply;
+ }
+ print $logfh "\n============ Done ============\n";
+ close(logfh);
+ }
+ }
+ }
+ return OK;
+}
+
+sub subscribed_hosts {
+ my ($target) = @_;
+ my @subscribed;
+ if (open(my $fh,"<$target.subscription")) {
+ while (my $subline=<$fh>) {
+ if ($subline =~ /^($match_lonid):/) {
+ my $host = $1;
+ if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
+ unless (grep(/^\Q$host\E$/,@subscribed)) {
+ push(@subscribed,$host);
+ }
+ }
+ }
+ }
+ }
+ return @subscribed;
}
sub check_switchserver {
@@ -7862,14 +7933,13 @@ sub active_dc_picker {
sub usersession_titles {
return &Apache::lonlocal::texthash(
hosted => 'Hosting of sessions for users from other domains on servers in this domain',
-
remote => 'Hosting of sessions for users in this domain on servers in other domains',
spares => 'Servers offloaded to, when busy',
version => 'LON-CAPA version requirement',
excludedomain => 'Allow all, but exclude specific domains',
includedomain => 'Deny all, but include specific domains',
primary => 'Primary (checked first)',
- default => 'Default',
+ default => 'Default',
);
}