[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm

raeburn raeburn at source.lon-capa.org
Sat Jul 7 17:58:14 EDT 2012


raeburn		Sat Jul  7 21:58:14 2012 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
  Log:
  - Importing archive file directly into a course.
    - Make two passes over user's choice for disposition of files extracted 
      from archive - first for new files/folders and discards
                   - second for dependencies.
  
  
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1085 loncom/interface/loncommon.pm:1.1086
--- loncom/interface/loncommon.pm:1.1085	Fri Jul  6 22:46:06 2012
+++ loncom/interface/loncommon.pm	Sat Jul  7 21:58:14 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1085 2012/07/06 22:46:06 raeburn Exp $
+# $Id: loncommon.pm,v 1.1086 2012/07/07 21:58:14 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -11207,6 +11207,7 @@
     my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
     if ($numitems) {
         for (my $i=1; $i<=$numitems; $i++) {
+            next if ($env{'form.archive_'.$i} eq 'dependency');
             my $path = $env{'form.archive_content_'.$i};
             if ($path =~ /^\Q$pathtocheck\E/) {
                 if ($env{'form.archive_'.$i} eq 'discard') {
@@ -11298,84 +11299,90 @@
                             }
                         }
                     }
-                } elsif ($env{'form.archive_'.$i} eq 'dependency') {
-                    my ($title) = ($path =~ m{/([^/]+)$});
-                    $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
-                    if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
-                        if (ref($dirorder{$i}) eq 'ARRAY') {
-                            my ($itemidx,$fullpath,$relpath);
+                }
+            } else {
+                $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />'; 
+            }
+        }
+        for (my $i=1; $i<=$numitems; $i++) {
+            next unless ($env{'form.archive_'.$i} eq 'dependency');
+            my $path = $env{'form.archive_content_'.$i};
+            if ($path =~ /^\Q$pathtocheck\E/) {
+                my ($title) = ($path =~ m{/([^/]+)$});
+                $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
+                if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
+                    if (ref($dirorder{$i}) eq 'ARRAY') {
+                        my ($itemidx,$fullpath,$relpath);
+                        if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
+                            my $container = $dirorder{$referrer{$i}}->[-1];
                             for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
-                                if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
-                                    my $container = $dirorder{$referrer{$i}}->[-1];
-                                    for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
-                                        if ($dirorder{$i}->[$j] eq $container) {
-                                            $itemidx = $j;
-                                        }
-                                    }
+                                if ($dirorder{$i}->[$j] eq $container) {
+                                    $itemidx = $j;
                                 }
                             }
-                            if ($itemidx ne '') {
-                                if (grep(/^\Q$referrer{$i}\E$/, at archdirs)) {
-                                    if ($mapinner{$referrer{$i}}) {
-                                        $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
-                                        for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
-                                            if (grep(/^\Q$dirorder{$i}->[$j]\E$/, at archdirs)) {
-                                                unless (defined($newseqid{$dirorder{$i}->[$j]})) {
-                                                    $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
-                                                    $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
-                                                    if (!-e $fullpath) {
-                                                        mkdir($fullpath,0755);
-                                                    }
-                                                }
-                                            } else {
-                                                last;
-                                            }
-                                        }
-                                    }
-                                } elsif ($newdest{$referrer{$i}}) {
-                                    $fullpath = $newdest{$referrer{$i}};
-                                    for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
-                                        if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
-                                            $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
-                                            last;
-                                        } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/, at archdirs)) {
-                                            unless (defined($newseqid{$dirorder{$i}->[$j]})) {
-                                                $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
-                                                $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
-                                                if (!-e $fullpath) {
-                                                    mkdir($fullpath,0755);
-                                                }
+                        }
+                        if ($itemidx eq '') {
+                            $itemidx =  0;
+                        } 
+                        if (grep(/^\Q$referrer{$i}\E$/, at archdirs)) {
+                            if ($mapinner{$referrer{$i}}) {
+                                $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
+                                for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
+                                    if (grep(/^\Q$dirorder{$i}->[$j]\E$/, at archdirs)) {
+                                        unless (defined($newseqid{$dirorder{$i}->[$j]})) {
+                                            $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
+                                            $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
+                                            if (!-e $fullpath) {
+                                                mkdir($fullpath,0755);
                                             }
-                                        } else {
-                                            last;
                                         }
+                                    } else {
+                                        last;
                                     }
                                 }
-                                if ($fullpath ne '') {
-                                    if (-e "$prefix$path") {
-                                        system("mv $prefix$path $fullpath/$title");
-                                    }
-                                    if (-e "$fullpath/$title") {
-                                        my $showpath;
-                                        if ($relpath ne '') {
-                                            $showpath = "$relpath/$title";
-                                        } else {
-                                            $showpath = "/$title";
-                                        } 
-                                        $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
-                                    } 
-                                    unless ($ishome) {
-                                        my $fetch = "$fullpath/$title";
-                                        $fetch =~ s/^\Q$prefix$dir\E//; 
-                                        $prompttofetch{$fetch} = 1;
+                            }
+                        } elsif ($newdest{$referrer{$i}}) {
+                            $fullpath = $newdest{$referrer{$i}};
+                            for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
+                                if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
+                                    $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
+                                    last;
+                                } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/, at archdirs)) {
+                                    unless (defined($newseqid{$dirorder{$i}->[$j]})) {
+                                        $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
+                                        $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
+                                        if (!-e $fullpath) {
+                                            mkdir($fullpath,0755);
+                                        }
                                     }
+                                } else {
+                                    last;
                                 }
                             }
                         }
-                    } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
-                        $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
-                                        $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
+                        if ($fullpath ne '') {
+                            if (-e "$prefix$path") {
+                                system("mv $prefix$path $fullpath/$title");
+                            }
+                            if (-e "$fullpath/$title") {
+                                my $showpath;
+                                if ($relpath ne '') {
+                                    $showpath = "$relpath/$title";
+                                } else {
+                                    $showpath = "/$title";
+                                } 
+                                $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
+                            } 
+                            unless ($ishome) {
+                                my $fetch = "$fullpath/$title";
+                                $fetch =~ s/^\Q$prefix$dir\E//; 
+                                $prompttofetch{$fetch} = 1;
+                            }
+                        }
                     }
+                } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
+                    $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
+                                    $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
                 }
             } else {
                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />'; 


More information about the LON-CAPA-cvs mailing list