[LON-CAPA-cvs] cvs: loncom /interface londocs.pm /lonnet/perl lonnet.pm
raeburn
raeburn at source.lon-capa.org
Sat Aug 26 22:36:58 EDT 2017
raeburn Sun Aug 27 02:36:58 2017 EDT
Modified files:
/loncom/interface londocs.pm
/loncom/lonnet/perl lonnet.pm
Log:
- "Verify Content" in Course Editor includes option to check files
replicated from elsewhere are outdated because "update" transaction has
yet to propagate.
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.636 loncom/interface/londocs.pm:1.637
--- loncom/interface/londocs.pm:1.636 Sun Aug 27 02:23:02 2017
+++ loncom/interface/londocs.pm Sun Aug 27 02:36:49 2017
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.636 2017/08/27 02:23:02 raeburn Exp $
+# $Id: londocs.pm,v 1.637 2017/08/27 02:36:49 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -4588,7 +4588,7 @@
sub checkonthis {
- my ($r,$url,$level,$title)=@_;
+ my ($r,$url,$level,$title,$checkstale)=@_;
$url=&unescape($url);
$alreadyseen{$url}=1;
$r->rflush();
@@ -4603,10 +4603,22 @@
$r->print('<a href="'.$url.'" target="cat">'.
($title?$title:$url).'</a> ');
if ($url=~/^\/res\//) {
+ my $updated;
+ if (($checkstale) && ($url !~ m{^/res/lib/templates/}) &&
+ ($url !~ /\.\d+\.\w+$/)) {
+ $updated = &Apache::lonnet::remove_stale_resfile($url);
+ }
my $result=&Apache::lonnet::repcopy(
&Apache::lonnet::filelocation('',$url));
if ($result eq 'ok') {
$r->print('<span class="LC_success">'.&mt('ok').'</span>');
+ if ($updated) {
+ $r->print('<br />');
+ for (my $i=0;$i<=$level*5;$i++) {
+ $r->print(' ');
+ }
+ $r->print('- '.&mt('Outdated copy removed'));
+ }
$r->rflush();
&Apache::lonnet::countacc($url);
$url=~/\.(\w+)$/;
@@ -4640,7 +4652,7 @@
&Apache::lonnet::metadata($url,'dependencies');
foreach my $dep (split(/\,/,$dependencies)) {
if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
- &checkonthis($r,$dep,$level+1);
+ &checkonthis($r,$dep,$level+1,'',$checkstale);
}
}
} elsif ($result eq 'unavailable') {
@@ -4654,6 +4666,9 @@
} else {
$r->print('<span class="LC_error">'.&mt('access denied').'</span>');
}
+ if (($updated) && ($result ne 'ok')) {
+ $r->print('<br />'.&mt('Outdated copy removed'));
+ }
}
}
}
@@ -4706,9 +4721,29 @@
$r->print(&endContentScreen());
}
+sub contentverifyform {
+ my ($r) = @_;
+ my $crstype = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
+ $r->print(&startContentScreen('tools'));
+ $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
+ $r->print('<form method="post" action="/adm/coursedocs"><p>'.
+ &mt('Include a check if files copied from elsewhere are up to date (will increase verification time)?').
+ ' <span class="LC_nobreak">'.
+ '<label><input type="radio" name="checkstale" value="0" checked="checked" />'.
+ &mt('No').'</label>'.(' 'x2).
+ '<label><input type="radio" name="checkstale" value="1" />'.
+ &mt('Yes').'</label></span></p><p>'.
+ '<input type="submit" value="'.&mt('Verify content').' "/>'.
+ '<input type="hidden" value="1" name="tools" />'.
+ '<input type="hidden" value="1" name="verify" /></p></form>');
+ $r->print(&endContentScreen());
+ return;
+}
sub verifycontent {
- my ($r) = @_;
+ my ($r,$checkstale) = @_;
my $crstype = &Apache::loncommon::course_type();
$r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
@@ -4729,7 +4764,7 @@
}
}
if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
- &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
+ &checkonthis($r,$hash{$key},0,$hash{'title_'.$1},$checkstale);
}
}
&untiehash();
@@ -4737,7 +4772,6 @@
$r->print(&endContentScreen());
}
-
sub devalidateversioncache {
my $src=shift;
&Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
@@ -5208,7 +5242,17 @@
if ($allowed && $env{'form.verify'}) {
&init_breadcrumbs('verify','Verify Content','Docs_Verify_Content');
- &verifycontent($r);
+ if (!$canedit) {
+ &verifycontent($r);
+ } elsif (($env{'form.checkstale'} ne '') && ($env{'form.checkstale'} =~ /^\d$/)) {
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1&verify=1&checkstale=$env{'form.checkstale'}",
+ text=>'Results',
+ faq=>273,
+ bug=>'Instructor Interface'});
+ &verifycontent($r,$env{'form.checkstale'});
+ } else {
+ &contentverifyform($r);
+ }
} elsif ($allowed && $env{'form.listsymbs'}) {
&init_breadcrumbs('listsymbs','List Content IDs');
&list_symbs($r);
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1351 loncom/lonnet/perl/lonnet.pm:1.1352
--- loncom/lonnet/perl/lonnet.pm:1.1351 Wed Aug 23 22:46:38 2017
+++ loncom/lonnet/perl/lonnet.pm Sun Aug 27 02:36:58 2017
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1351 2017/08/23 22:46:38 raeburn Exp $
+# $Id: lonnet.pm,v 1.1352 2017/08/27 02:36:58 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -3171,6 +3171,45 @@
}
}
+sub remove_stale_resfile {
+ my ($url) = @_;
+ my $stale;
+ if ($url=~m{^/res/($match_domain)/($match_username)/}) {
+ my $audom = $1;
+ my $auname = $2;
+ unless (($url =~ /\.\d+\.\w+$/) || ($url !~ m{^/res/lib/templates/})) {
+ my $homeserver = &homeserver($auname,$audom);
+ unless (($homeserver eq 'no_host') ||
+ (grep { $_ eq $homeserver } ¤t_machine_ids())) {
+ my $fname = &filelocation('',$url);
+ if (-e $fname) {
+ my $protocol = $protocol{$homeserver};
+ $protocol = 'http' if ($protocol ne 'https');
+ my $hostname = &hostname($homeserver);
+ if ($hostname) {
+ my $uri = &declutter($url);
+ my $request=new HTTP::Request('HEAD',$protocol.'://'.$hostname.'/raw/'.$uri);
+ my $response = &LONCAPA::LWPReq::makerequest($homeserver,$request,'',\%perlvar,5,0,1);
+ if ($response->is_success()) {
+ my $remmodtime = &HTTP::Date::str2time( $response->header('Last-modified') );
+ my $locmodtime = (stat($fname))[9];
+ if ($locmodtime < $remmodtime) {
+ unlink($fname);
+ if ($uri!~/\.meta$/) {
+ unlink($fname.'.meta');
+ }
+ &reply("unsub:$fname",$homeserver);
+ $stale = 1;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return $stale;
+}
+
# -------------------------------- Allow a /uploaded/ URI to be vouched for
sub allowuploaded {
More information about the LON-CAPA-cvs
mailing list