[LON-CAPA-cvs] cvs: loncom /automation Autocreate.pl

raeburn raeburn@source.lon-capa.org
Tue, 30 Mar 2010 15:24:52 -0000


raeburn		Tue Mar 30 15:24:52 2010 EDT

  Modified files:              
    /loncom/automation	Autocreate.pl 
  Log:
  &process_official_reqs() moved to interface/loncoursequeueadmin.pm to facilitate reuse.
  
  
Index: loncom/automation/Autocreate.pl
diff -u loncom/automation/Autocreate.pl:1.12 loncom/automation/Autocreate.pl:1.13
--- loncom/automation/Autocreate.pl:1.12	Mon Feb 22 03:44:21 2010
+++ loncom/automation/Autocreate.pl	Tue Mar 30 15:24:52 2010
@@ -2,7 +2,7 @@
 #
 # Automated Course Creation script
 #
-# $Id: Autocreate.pl,v 1.12 2010/02/22 03:44:21 raeburn Exp $
+# $Id: Autocreate.pl,v 1.13 2010/03/30 15:24:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -114,12 +114,6 @@
             print $output;
         }
     } else {
-        my $reqsnamespace = 'courserequestqueue';
-        my @courseroles = ('cc','in','ta','ep','ad','st');
-        my %longroles;
-        foreach my $role (@courseroles) {
-            $longroles{$role}=&Apache::lonnet::plaintext($role);
-        }
         my @permissions = ('mau','ccc','cin','cta','cep','ccr','cst');
         my %permissionflags = ();
         &set_permissions(\%permissionflags,\@permissions);
@@ -148,8 +142,10 @@
                     }
                 }
                 if ($settings->{'req'}) {
-                    my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
-                    &process_official_reqs($fh,$dom,$reqsnamespace,\%longroles,\%domdefs);
+                    my $output = &Apache::process_official_reqs('auto',$dom);
+                    if ($output) {
+                        print $fh $output;
+                    }
                 }
             }
         }
@@ -214,115 +210,6 @@
     return $output;
 }
 
-sub process_official_reqs {
-    my ($fh,$dom,$reqsnamespace,$longroles,$domdefs) = @_;
-    my %newcids;
-    my %requesthash = 
-        &Apache::lonnet::dump_dom($reqsnamespace,$dom,undef,'_pending');
-    foreach my $key (keys(%requesthash)) {
-        my ($cnum,$status) = split('_',$key);
-        next if (&Apache::lonnet::homeserver($cnum,$dom) ne 'no_host');
-        if (ref($requesthash{$key}) eq 'HASH') {
-            my $ownername = $requesthash{$key}{'ownername'};
-            my $ownerdom = $requesthash{$key}{'ownerdom'};
-            next if (&Apache::lonnet::homeserver($ownername,$ownerdom) eq 'no_host');
-            my $inststatus;
-            my %userenv =
-                &Apache::lonnet::get('environment',['inststatus'],
-                                     $ownerdom,$ownername);
-            my ($tmp) = keys(%userenv);
-            if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
-                $inststatus = $userenv{'inststatus'};
-            } else {
-                undef(%userenv);
-            }
-            my $reqkey = $dom.'_'.$cnum;
-            my %history = &Apache::lonnet::restore($reqkey,'courserequests',
-                                                   $ownerdom,$ownername);
-            if (ref($history{'details'}) eq 'HASH') {
-                my $instcode = $history{'details'}{'instcode'};
-                my $crstype = $history{'details'}{'crstype'};
-                my $reqtime = $history{'details'}{'reqtime'};
-                my $cdescr = $history{'details'}{'cdescr'};
-                my @currsec;
-                my $sections = $history{'details'}{'sections'};
-                if (ref($sections) eq 'HASH') {
-                    foreach my $i (sort(keys(%{$sections}))) {
-                        if (ref($sections->{$i}) eq 'HASH') {
-                            my $sec = $sections->{$i}{'inst'};
-                            if (!grep(/^\Q$sec\E$/,@currsec)) {
-                                push(@currsec,$sec);
-                            }
-                        }
-                    }
-                }
-                my $instseclist = join(',',@currsec);
-                my ($validationchk,$disposition,$reqstatus,$message,
-                    $validation,$validationerror);
-                $validationchk =
-                    &Apache::lonnet::auto_courserequest_validation($dom,
-                        $ownername.':'.$ownerdom,$crstype,$inststatus,
-                        $instcode,$instseclist);
-                if ($validationchk =~ /:/) {
-                    ($validation,$message) = split(':',$validationchk);
-                } else {
-                    $validation = $validationchk;
-                }
-                if ($validation =~ /^error(.*)$/) {
-                    $disposition = 'approval';
-                    $validationerror = $1;
-                } else {
-                    $disposition = $validation;
-                }
-                $reqstatus = $disposition;
-                if ($disposition eq 'process') {
-                    my ($logmsg,$newusermsg,$addresult,$enrollcount,$response,$keysmsg);
-                    my $result = &Apache::loncoursequeueadmin::course_creation($dom,$cnum,'domain',$history{'details'},\$logmsg,\$newusermsg,\$addresult,\$enrollcount,\$response,\$keysmsg,$domdefs,$longroles);
-                    if ($result eq 'created') {
-                        $disposition = 'created';
-                        $reqstatus = 'created';
-                        push(@{$newcids{$instcode}},$dom.'_'.$cnum);
-                    }
-                } elsif ($disposition eq 'rejected') {
-                    print $fh &mt('Queued course request for [_1] submitted by [_2] with status [_3] rejected when validating',$instcode,$ownername.':'.$ownerdom,$inststatus);
-                } elsif ($disposition eq 'approval') {
-                    print $fh &mt('Queued course request for [_1] submitted by [_2] with status [_3] switched to "approval by DC" because of validation error: [_4].',$instcode,$ownername.':'.$ownerdom,$inststatus,$validationerror);
-
-                    my $requestid = $cnum.'_'.$disposition;
-                    my $request = {
-                            $requestid => {
-                                            timestamp   => $reqtime,
-                                            crstype     => $crstype,
-                                            ownername   => $ownername,
-                                            ownerdom    => $ownerdom,
-                                            description => $cdescr,
-                                          },
-                          };
-                    my $putresult = &Apache::lonnet::newput_dom('courserequestqueue',$request,$dom);
-                    unless ($putresult eq 'ok') {
-                        print $fh &mt("An error occurred saving the modified course request for [_1] submitted by [_2] in the domain's courserequestqueue.db.",$instcode,$ownername.':'.$ownerdom);   
-                    }
-                }
-                unless ($disposition eq 'pending') {
-                    my ($statusresult,$output) = 
-                        &Apache::loncoursequeueadmin::update_coursereq_status(\%requesthash,
-                            $dom,$cnum,$reqstatus,'domain');
-                    unless (&Apache::lonnet::del_dom($reqsnamespace,[$cnum.'_pending'],$dom) eq 'ok') {
-                        print $fh &mt('An error occurred when removing the request for [_1] submitted by [_2] from the pending queue.',$instcode,$ownername.':'.$ownerdom);
-                    }
-                }
-            }
-        }
-    }
-    foreach my $key (sort(keys(%newcids))) {
-        if (ref($newcids{$key}) eq 'ARRAY') {
-            print $fh "created course from queued request: $key - ".join(', ',@{$newcids{$key}})."\n";
-            my $newcourse = &LONCAPA::escape($key.':'.$newcids{$key});
-        }
-    }
-    return;
-}
-
 sub check_activedc {
     my ($dcdom,$dcname,$defdom) = @_;
     my %dumphash=