--- loncom/lonnet/perl/lonnet.pm 2010/06/03 17:04:41 1.1069 +++ loncom/lonnet/perl/lonnet.pm 2010/07/06 18:36:56 1.1072 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1069 2010/06/03 17:04:41 www Exp $ +# $Id: lonnet.pm,v 1.1072 2010/07/06 18:36:56 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -710,7 +710,7 @@ sub compare_server_load { my $userloadans = &reply('userload',$try_server); if ($loadans !~ /\d/ && $userloadans !~ /\d/) { - next; #didn't get a number from the server + return; #didn't get a number from the server } my $load; @@ -3035,7 +3035,7 @@ sub courseiddump { my ($domfilter,$descfilter,$sincefilter,$instcodefilter,$ownerfilter, $coursefilter,$hostidflag,$hostidref,$typefilter,$regexp_ok, $selfenrollonly,$catfilter,$showhidden,$caller,$cloner,$cc_clone, - $cloneonly,$createdbefore,$createdafter,$creationcontext)=@_; + $cloneonly,$createdbefore,$createdafter,$creationcontext,$domcloner)=@_; my $as_hash = 1; my %returnhash; if (!$domfilter) { $domfilter=''; } @@ -3057,7 +3057,8 @@ sub courseiddump { $showhidden.':'.$caller.':'.&escape($cloner).':'. &escape($cc_clone).':'.$cloneonly.':'. &escape($createdbefore).':'.&escape($createdafter).':'. - &escape($creationcontext),$tryserver); + &escape($creationcontext).':'.$domcloner, + $tryserver); my @pairs=split(/\&/,$rep); foreach my $item (@pairs) { my ($key,$value)=split(/\=/,$item,2); @@ -8131,6 +8132,7 @@ sub add_prefix_and_part { # ---------------------------------------------------------------- Get metadata my %metaentry; +my %importedpartids; sub metadata { my ($uri,$what,$liburi,$prefix,$depthcount)=@_; $uri=&declutter($uri); @@ -8158,7 +8160,8 @@ sub metadata { } { # Imported parts would go here - my @newpartorder=(); + my %importedids=(); + my @origfileimportpartids=(); my $importedparts=0; # # Is this a recursive call for a library? @@ -8264,24 +8267,24 @@ sub metadata { # We need to get the original file and the imported file to get the part order correct # Good news: we do not need to worry about nested libraries, since parts cannot be nested # Load and inspect original file - my $origfilelocation=$perlvar{'lonDocRoot'}.&clutter($uri); - my $origfile=&getfile($origfilelocation); - my @origfileimportpartids=($origfile=~/<(part|import)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); + if ($#origfileimportpartids<0) { + undef(%importedpartids); + my $origfilelocation=$perlvar{'lonDocRoot'}.&clutter($uri); + my $origfile=&getfile($origfilelocation); + @origfileimportpartids=($origfile=~/<(part|import)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); + } + # Load and inspect imported file my $impfile=&getfile($location); my @impfilepartids=($impfile=~/]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs); - -#&logthis("Found imported parts".join(',',@impfilepartids)); -#&logthis("Found original parts and imports".join(',',@origfileimportpartids)); if ($#impfilepartids>=0) { # This problem had parts -#&logthis("Importing parted problem"); + $importedpartids{$token->[2]->{'id'}}=join(',',@impfilepartids); } else { # Importing by turning a single problem into a problem part # It gets the import-tags ID as part-ID -#&logthis("Importing unparted problem"); $unikey=&add_prefix_and_part($prefix,$token->[2]->{'id'}); - push(@newpartorder,$token->[2]->{'id'}); + $importedpartids{$token->[2]->{'id'}}=$token->[2]->{'id'}; } } else { # Normal import @@ -8291,8 +8294,6 @@ sub metadata { } } -#&logthis("About to use unikey $unikey"); - if ($depthcount<20) { my $metadata = &metadata($uri,'keys', $location,$unikey, @@ -8302,7 +8303,6 @@ sub metadata { $metathesekeys{$meta}=1; } -#&logthis("Metadata $metadata"); } } else { # @@ -8385,6 +8385,22 @@ sub metadata { grep { ! $seen{$_} ++ } (split(',',$metaentry{':packages'})); $metaentry{':packages'} = join(',',@uniq_packages); + if ($importedparts) { +# We had imported parts and need to rebuild partorder + $metaentry{':partorder'}=''; + $metathesekeys{'partorder'}=1; + for (my $index=0;$index<$#origfileimportpartids;$index+=2) { + if ($origfileimportpartids[$index] eq 'part') { +# original part, part of the problem + $metaentry{':partorder'}.=','.$origfileimportpartids[$index+1]; + } else { +# we have imported parts at this position + $metaentry{':partorder'}.=','.$importedpartids{$origfileimportpartids[$index+1]}; + } + } + $metaentry{':partorder'}=~s/^\,//; + } + $metaentry{':keys'} = join(',',keys(%metathesekeys)); &metadata_generate_part0(\%metathesekeys,\%metaentry,$uri); $metaentry{':allpossiblekeys'}=join(',',keys %metathesekeys);