[LON-CAPA-cvs] cvs: loncom /imspackages imsprocessor.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sat, 23 Aug 2008 17:47:47 -0000


This is a MIME encoded message

--raeburn1219513667
Content-Type: text/plain

raeburn		Sat Aug 23 13:47:47 2008 EDT

  Modified files:              
    /loncom/imspackages	imsprocessor.pm 
  Log:
  Some changes for import of content from WebCT Campus Edition 4:
  - Naming of sequence files now uses the title of the item identifier (with the IMS identifier key appended for uniqueness).
  - for content files in my_files, file path used in src attribute in resource tag in a map is part which proceeds my_files in entry in hrefs array.      
  - .html files are only generated if there are links to include
  General change:
  - localization of content type titles   
  
  
--raeburn1219513667
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080823134747.txt"

Index: loncom/imspackages/imsprocessor.pm
diff -u loncom/imspackages/imsprocessor.pm:1.41 loncom/imspackages/imsprocessor.pm:1.42
--- loncom/imspackages/imsprocessor.pm:1.41	Sun Sep 30 09:20:08 2007
+++ loncom/imspackages/imsprocessor.pm	Sat Aug 23 13:47:44 2008
@@ -25,6 +25,7 @@
 
 use Apache::lonnet;
 use Apache::loncleanup;
+use Apache::lonlocal;
 use LWP::UserAgent;
 use HTTP::Request::Common;
 use LONCAPA::Configuration;
@@ -75,7 +76,7 @@
                 survey => 'webctsurvey',
                 doc => 'webcontent'
                 );
-    %{$areaname} = (
+    %{$areaname} = &Apache::lonlocal::texthash (
                 announce => 'Announcements',
                 board => 'Discussion Boards',
                 doc => 'Documents, pages, and folders',
@@ -308,7 +309,6 @@
                         if ($cms eq 'bb5' || $cms eq 'bb6' || 
                             $cms eq 'webctce4' || $cms eq 'webctvista4') {
                             push @{$$hrefs{$identifier}},$attr->{href};
-
                             if ($$resources{$identifier}{type} eq 
                                 'webct.manifest') {
                                 my $manifestfile = $tempdir.'/'.$attr->{href};
@@ -466,10 +466,14 @@
                                 mkdir("$fulldir",0770);
                             }
                         }
+                        my $renameres;
                         if ($cms eq 'angel') {
-                            rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file");
+                            $renameres = rename("$tempdir/_assoc/$key/$file","$destdir/resfiles/$key/$file");
                         } elsif ($cms eq 'bb5' || $cms eq 'bb6') {
-                            rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
+                            $renameres = rename("$tempdir/$key/$file","$destdir/resfiles/$key/$file");
+                        }
+                        if (!$renameres) {
+                            &Apache::lonnet::logthis("IMS import error: $cms - renaming failed for file $file");
                         }
                     } elsif ($cms eq 'webctce4') {
                         if ($file =~ m-/my_files/(.+)$-) {
@@ -486,7 +490,10 @@
                                 }
                             }
                             if (-e "$tempdir/$file") {
-                                rename("$tempdir/$file","$destdir/resfiles/$copyfile");
+                                my $renameres = rename("$tempdir/$file","$destdir/resfiles/$copyfile");
+                                if (!$renameres) {
+                                    &Apache::lonnet::logthis("IMS import error: WebCT4 - renaming failed for file $file");
+                                }
                             }
                         } elsif ($file !~ m-/data/(.+)$-) {
                             &Apache::lonnet::logthis("IMS import error: WebCT4 - file $file is in unexpected location");
@@ -735,7 +742,11 @@
         my $curr_id = 1;
         my $resnum = $$items{$key}{resnum};
         my $type = $$resources{$resnum}{type};
-        my $contentscount = $$items{$key}{'contentscount'}; 
+        my $contentscount = $$items{$key}{'contentscount'};
+        my $seqtitle = $$items{$key}{'title'};
+        $seqtitle =~ s|/+|_|g;
+        $seqtitle =~ s/\s+/_/g;
+        $seqtitle .= '_'.$key;
         if (($cms eq 'angel' && $type eq "FOLDER") || (($cms eq 'bb5' || $cms eq 'bb6') && $$resinfo{$resnum}{'isfolder'} eq "true") && (($type eq "resource/x-bb-document") || ($type eq "resource/x-bb-staffinfo") || ($type eq "resource/x-bb-externallink")) || ($cms eq 'webctce4' &&  $contentscount > 0)) {
             unless (($cms eq 'bb5') && $key eq 'Top') {
                 $seqtext{$key} = "<map>\n";
@@ -773,7 +784,7 @@
                 if (grep/^$res$/,@{$packages}) {
                     $packageflag = 1;
                 }
-                $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem});
+                $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem},$title);
                 unless ($flag{$key}{page} == 1) {
                     if ($$randompicks{$contitem}) {
                         $seqtext{$key} .= qq|
@@ -813,7 +824,7 @@
                             if (grep/^$res$/,@{$packages}) {
                                 $packageflag = 1;
                             }
-                            $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem});
+                            $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem},$title);
                             unless ($flag{$key}{page} == 1) {
                                 $seqtext{$key} .= qq|></resource>
 <link from="$curr_id" to="$next_id" index="$curr_id"></link>\n|;
@@ -845,7 +856,7 @@
                     if (grep/^$res$/,@{$packages}) {
                         $packageflag = 1;
                     }
-                    $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem});
+                    $src = &make_structure($cms,$key,$srcstem,\%flag,\%count,$timestamp,$boardnum,$hrefs,\%pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$$randompicks{$contitem},$title);
 
                     if ($flag{$key}{page}) {
                         if ($count{$key}{seq} + $count{$key}{page} + $count{$key}{board} + $count{$key}{file} +1 == 1) {
@@ -879,10 +890,15 @@
             }
             unless (($cms eq 'bb5') && $key eq 'Top') {
                 $seqtext{$key} .= "</map>\n";
-                open(LOCFILE,">$destdir/sequences/$key.sequence");
+                if ($cms eq 'webctce4' && $key ne 'Top') {
+                    push @{$seqfiles}, "$seqtitle.sequence";
+                    open(LOCFILE,">$destdir/sequences/$seqtitle.sequence");
+                } else {
+                    push @{$seqfiles}, "$key.sequence";
+                    open(LOCFILE,">$destdir/sequences/$key.sequence");
+                }
                 print LOCFILE $seqtext{$key};
                 close(LOCFILE);
-                push @{$seqfiles}, "$key.sequence";
             }
             $count{$key}{page} ++;
             $$total{page} += $count{$key}{page};
@@ -972,10 +988,16 @@
 }
 
 sub make_structure {
-    my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$randompick) = @_;
+    my ($cms,$key,$srcstem,$flag,$count,$timestamp,$boardnum,$hrefs,$pagecontents,$res,$type,$file,$resinfo,$contitem,$uname,$cdom,$contcount,$packageflag,$contitemcount,$randompick,$title) = @_;
     my $src ='';
     if (($cms eq 'angel' && $type eq 'FOLDER') || (($cms eq 'bb5' || $cms eq 'bb6') && (($$resinfo{$res}{'isfolder'} eq 'true') || $key eq 'Top')) || ($cms eq 'webctce4' && $contitemcount > 0)) {
         $src = $srcstem.'/sequences/'.$contitem.'.sequence';
+        if ($cms eq 'webctce4') {
+            $title =~ s|/+|_|g;
+            $title =~ s/\s+/_/g;
+            $title .= '_'.$contitem;
+            $src = $srcstem.'/sequences/'.$title.'.sequence';
+        }
         $$flag{$key}{page} = 0;
         $$flag{$key}{seq} = 1;
         $$count{$key}{seq} ++;
@@ -1038,14 +1060,16 @@
                 if ($file =~ m-/([^/]+)$-) {
                     $filename = $1;
                 }
-                $src =  $srcstem.'/resfiles/'.$res.'/'.$filename;
+                $src =  $srcstem.'/resfiles/'.$filename;
             } else {
                 foreach my $file (@{$$hrefs{$res}}) {
                     my $filename;
-                    if ($file =~ m-/([^/]+)$-) {
+                    if ($file =~ m-/my_files/(.+)$-) {
+                        $filename = $1;
+                    } elsif ($file =~ m-/([^/]+)$-) { 
                         $filename = $1;
                     }
-                    $src = $srcstem.'/resfiles/'.$res.'/'.$filename;
+                    $src = $srcstem.'/resfiles/'.$filename;
                 }
             }
             $$flag{$key}{page} = 0;
@@ -5304,20 +5328,18 @@
 # ---------------------------------------------------------------- WebCT content
 sub webct4_content {
     my ($res,$docroot,$destdir,$settings,$dom,$user,$type,$title,$resrcfiles) = @_;
-    if (!open(FILE,">$destdir/resfiles/$res.html")) {
-        &Apache::lonnet::logthis("IMS import error: Cannot open file - $destdir/resfiles/$res.html - $!");
-    } else {
-        push(@{$resrcfiles}, "$res.html");
-        my $linktag = '';
-        if (defined($$settings{url})) {
-            $linktag = qq|<a href="$$settings{url}"|;
+    if (defined($$settings{url})) {
+        if (!open(FILE,">$destdir/resfiles/$res.html")) {
+            &Apache::lonnet::logthis("IMS import error: Cannot open file - $destdir/resfiles/$res.html - $!");
+        } else {
+            push(@{$resrcfiles}, "$res.html");
+            my $linktag = qq|<a href="$$settings{url}"|;
             if ($title ne '') {
                 $linktag .= qq|>$title</a>|;
             } else {
                 $linktag .= qq|>$$settings{url}|;
             }
-        }
-        print FILE qq|<html>
+            print FILE qq|<html>
 <head>
 <title>$title</title>
 </head>
@@ -5325,7 +5347,8 @@
 $linktag
 </body>
 </html>|;
-        close(FILE);
+            close(FILE);
+        }
     }
 }
 

--raeburn1219513667--