[LON-CAPA-cvs] cvs: loncom /misc refresh_courseids_db.pl releaseslist.xml
raeburn
raeburn@source.lon-capa.org
Sat, 24 Jul 2010 00:01:12 -0000
This is a MIME encoded message
--raeburn1279929672
Content-Type: text/plain
raeburn Sat Jul 24 00:01:12 2010 EDT
Added files:
/loncom/misc releaseslist.xml
Modified files:
/loncom/misc refresh_courseids_db.pl
Log:
- Store LON-CAPA version required for a particular course in nohist_courseids.db
(and also as internal.relaserequired in course's environment.db.
- version required is stored in the form N.M (e.g., 2.10).
- Possible constraints currently defined in releaseslist.xml.
- check if question type parameter has been set for any problem parts in the course:
(anonymous survey, survey with credit etc.; practice problem.
- check if course type is Community.
- check if particuar response types are used (i.e., math or custom).
--raeburn1279929672
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20100724000112.txt"
Index: loncom/misc/refresh_courseids_db.pl
diff -u loncom/misc/refresh_courseids_db.pl:1.3 loncom/misc/refresh_courseids_db.pl:1.4
--- loncom/misc/refresh_courseids_db.pl:1.3 Wed Mar 17 18:16:56 2010
+++ loncom/misc/refresh_courseids_db.pl Sat Jul 24 00:01:12 2010
@@ -1,7 +1,7 @@
#!/usr/bin/perl
# The LearningOnline Network
#
-# $Id: refresh_courseids_db.pl,v 1.3 2010/03/17 18:16:56 raeburn Exp $
+# $Id: refresh_courseids_db.pl,v 1.4 2010/07/24 00:01:12 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -54,10 +54,15 @@
use lib '/home/httpd/lib/perl/';
use Apache::lonnet;
use Apache::loncommon;
+use Apache::lonuserstate;
+use Apache::loncoursedata;
+use Apache::lonnavmaps;
use LONCAPA qw(:DEFAULT :match);
exit if ($Apache::lonnet::perlvar{'lonRole'} ne 'library');
+use vars qw( %needsrelease %checkparms %checkresponsetypes %checkcrstypes);
+
# Make sure this process is running from user=www
my $wwwid=getpwnam('www');
if ($wwwid!=$<) {
@@ -73,6 +78,10 @@
print $fh "==== refresh_courseids_db.pl Run ".localtime()."====\n";
my @domains = sort(&Apache::lonnet::current_machine_domains());
+
+&parse_releases_xml();
+$env{'allowed.bre'} = 'F';
+
foreach my $dom (@domains) {
my %courseshash;
my @ids=&Apache::lonnet::current_machine_ids();
@@ -92,6 +101,8 @@
}
}
+delete($env{'allowed.bre'});
+
## Finished!
print $fh "==== refresh_courseids.db completed ".localtime()." ====\n";
close($fh);
@@ -140,7 +151,7 @@
}
my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
my $owner = $courseinfo{'internal.courseowner'};
- my (%roleshash,$gotcc);
+ my (%roleshash,$gotcc,$reqdmajor,$reqdminor);
if ($owner eq '') {
%roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc'],undef,undef,1);
$gotcc = 1;
@@ -201,6 +212,25 @@
}
}
}
+
+ $env{'request.course.id'} = $cdom.'_'.$cnum;
+ $env{'request.role'} = 'cc./'.$cdom.'/'.$cnum;
+ &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+
+ # check all parameters
+ ($reqdmajor,$reqdminor) = ¶meter_constraints($cnum,$cdom);
+
+ # check course type
+ ($reqdmajor,$reqdminor) = &coursetype_constraints($cnum,$cdom,$crstype,
+ $reqdmajor,
+ $reqdminor);
+ # check course contents
+ ($reqdmajor,$reqdminor) = &coursecontent_constraints($cnum,$cdom,
+ $reqdmajor,
+ $reqdminor);
+ delete($env{'request.course.id'});
+ delete($env{'request.role'});
+
unless ($chome eq 'no_host') {
$courseshash->{$chome}{$cid} = {
description => $courseinfo{'description'},
@@ -274,6 +304,12 @@
$courseinfo{'internal.'.$item};
}
}
+ if ($reqdmajor ne '' && $reqdminor ne '') {
+ $courseshash->{$chome}{$cid}{'releaserequired'} = $reqdmajor.'.'.$reqdminor;
+ }
+ if ($courseinfo{'internal.releaserequired'} ne $reqdmajor.'.'.$reqdminor) {
+ $changes{'internal.releaserequired'} = $reqdmajor.'.'.$reqdminor;
+ }
if (keys(%changes)) {
if (&Apache::lonnet::put('environment',\%changes,$cdom,$cnum) eq 'ok') {
print $fh "Course's environment.db for ".$cdom."_".$cnum." successfully updated with following entries: ";
@@ -292,5 +328,128 @@
return;
}
+sub parameter_constraints {
+ my ($cnum,$cdom) = @_;
+ my ($reqdmajor,$reqdminor);
+ my $resourcedata=&read_paramdata($cnum,$cdom);
+ if (ref($resourcedata) eq 'HASH') {
+ foreach my $key (keys(%{$resourcedata})) {
+ foreach my $item (keys(%checkparms)) {
+ if ($key =~ /(\Q$item\E)$/) {
+ if (ref($checkparms{$item}) eq 'ARRAY') {
+ my $value = $resourcedata->{$key};
+ if (grep(/^\Q$value\E$/,@{$checkparms{$item}})) {
+ my ($major,$minor) = split(/\./,$needsrelease{'parameter'}{$item}{$value});
+ ($reqdmajor,$reqdminor) =
+ &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
+ }
+ }
+ }
+ }
+ }
+ }
+ return ($reqdmajor,$reqdminor);
+}
+
+sub coursetype_constraints {
+ my ($cnum,$cdom,$crstype,$reqdmajor,$reqdminor) = @_;
+ if (defined($checkcrstypes{$crstype})) {
+ my ($major,$minor) = split(/\./,$checkcrstypes{$crstype});
+ ($reqdmajor,$reqdminor) =
+ &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
+ }
+ return ($reqdmajor,$reqdminor);
+}
+
+sub coursecontent_constraints {
+ my ($cnum,$cdom,$reqdmajor,$reqdminor) = @_;
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (defined($navmap)) {
+ my %allresponses;
+ foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
+ my %responses = $res->responseTypes();
+ foreach my $key (keys(%responses)) {
+ next unless(exists($checkresponsetypes{$key}));
+ $allresponses{$key} += $responses{$key};
+ }
+ }
+ foreach my $key (keys(%allresponses)) {
+ my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
+ ($reqdmajor,$reqdminor) = &update_reqd_loncaparev($major,$minor,$reqdmajor,$reqdminor);
+ }
+ }
+ return ($reqdmajor,$reqdminor);
+}
+
+sub update_reqd_loncaparev {
+ my ($major,$minor,$reqdmajor,$reqdminor) = @_;
+ if (($major ne '' && $major !~ /\D/) & ($minor ne '' && $minor !~ /\D/)) {
+ if ($reqdmajor eq '' || $reqdminor eq '') {
+ $reqdmajor = $major;
+ $reqdminor = $minor;
+ } elsif (($major > $reqdmajor) ||
+ ($major == $reqdmajor && $minor > $reqdminor)) {
+ $reqdmajor = $major;
+ $reqdminor = $minor;
+ }
+ }
+ return ($reqdmajor,$reqdminor);
+}
+
+sub read_paramdata {
+ my ($cnum,$dom)=@_;
+ my $resourcedata=&Apache::lonnet::get_courseresdata($cnum,$dom);
+ my $classlist=&Apache::loncoursedata::get_classlist();
+ foreach my $student (keys(%{$classlist})) {
+ if ($student =~/^($LONCAPA::match_username)\:($LONCAPA::match_domain)$/) {
+ my ($tuname,$tudom)=($1,$2);
+ my $useropt=&Apache::lonnet::get_userresdata($tuname,$tudom);
+ foreach my $userkey (keys(%{$useropt})) {
+ if ($userkey=~/^$env{'request.course.id'}/) {
+ my $newkey=$userkey;
+ $newkey=~s/^($env{'request.course.id'}\.)/$1\[useropt\:$tuname\:$tudom\]\./;
+ $$resourcedata{$newkey}=$$useropt{$userkey};
+ }
+ }
+ }
+ }
+ return $resourcedata;
+}
+sub parse_releases_xml {
+ my $file = $Apache::lonnet::perlvar{'lonTabDir'}.'/releaseslist.xml';
+ if (-e $file) {
+ my $parser = HTML::LCParser->new($file);
+ while (my $token = $parser->get_token()) {
+ if ($token->[0] eq 'S') {
+ my $item = $token->[1];
+ my $name = $token->[2]{'name'};
+ my $value = $token->[2]{'value'};
+ if ($item ne '' && $name ne '' && $value ne '') {
+ my $release = $parser->get_text();
+ $release =~ s/(^\s*|\s*$ )//gx;
+ $needsrelease{$item}{$name}{$value} = $release;
+ if ($item eq 'parameter') {
+ if (ref($checkparms{$name}) eq 'ARRAY') {
+ unless(grep(/^\Q$name\E$/,@{$checkparms{$name}})) {
+ push(@{$checkparms{$name}},$value);
+ }
+ } else {
+ push(@{$checkparms{$name}},$value);
+ }
+ } elsif ($item eq 'resourcetag') {
+ if ($name eq 'responsetype') {
+ $checkresponsetypes{$value} = $release;
+ }
+ } elsif ($item eq 'course') {
+ if ($name eq 'crstype') {
+ $checkcrstypes{$value} = $release;
+ }
+ }
+ }
+ }
+ }
+ }
+ return;
+}
Index: loncom/misc/releaseslist.xml
+++ loncom/misc/releaseslist.xml
<course name="crstype" value="Community">2.9</course>
<parameter name="type" value="anonsurvey">2.10</parameter>
<parameter name="type" value="anonsurveycred">2.10</parameter>
<parameter name="type" value="surveycred">2.10</parameter>
<parameter name="type" value="practice">2.2</parameter>
<resourcetag name="responsetype" value="custom">2.1</resourcetag>
<resourcetag name="responsetype" value="math">2.2</resourcetag>
--raeburn1279929672--