--- loncom/metadata_database/searchcat.pl 2007/01/02 12:52:22 1.75 +++ loncom/metadata_database/searchcat.pl 2007/07/25 23:17:43 1.77 @@ -2,7 +2,7 @@ # The LearningOnline Network # searchcat.pl "Search Catalog" batch script # -# $Id: searchcat.pl,v 1.75 2007/01/02 12:52:22 raeburn Exp $ +# $Id: searchcat.pl,v 1.77 2007/07/25 23:17:43 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -68,7 +68,7 @@ use strict; use DBI; use lib '/home/httpd/lib/perl/'; use LONCAPA::lonmetadata; - +use LONCAPA; use Getopt::Long; use IO::File; use HTML::TokeParser; @@ -123,6 +123,7 @@ my %oldnames = ( 'portfolio' => 'portfolio_metadata', 'access' => 'portfolio_access', 'addedfields' => 'portfolio_addedfields', + 'allusers' => 'allusers', ); my %newnames; @@ -172,7 +173,7 @@ foreach my $key (keys(%newnames)) { } # -# Create the new metadata and portfolio tables +# Create the new metadata, portfolio and allusers tables foreach my $key (keys(%newnames)) { if ($newnames{$key} ne '') { my $request = @@ -221,15 +222,18 @@ foreach my $dom (@domains) { no_chdir => 1, }, join('/',($Apache::lonnet::perlvar{'lonDocRoot'},'res',$dom,$user)) ); } - # Search for public portfolio files - my %portusers; + # Search for all users and public portfolio files + my (%allusers,%portusers); if ($oneuser) { %portusers = ( $oneuser => '', ); + %allusers = ( + $oneuser => '', + ); } else { my $dir = $Apache::lonnet::perlvar{lonUsersDir}.'/'.$dom; - &descend_tree($dir,0,\%portusers); + &descend_tree($dom,$dir,0,\%portusers,\%allusers); } foreach my $uname (keys(%portusers)) { my $urlstart = '/uploaded/'.$dom.'/'.$uname; @@ -257,6 +261,20 @@ foreach my $dom (@domains) { &portfolio_logging(%portmetalog); } } + # Update allusers + foreach my $uname (keys(%allusers)) { + my %userdata = + &Apache::lonnet::get('environment',['firstname','lastname', + 'middlename','generation','id','permanentemail'],$dom,$uname); + $userdata{'username'} = $uname; + $userdata{'domain'} = $dom; + my %alluserslog = + &LONCAPA::lonmetadata::process_allusers_data($dbh,$simulate, + \%newnames,$uname,$dom,\%userdata); + foreach my $item (keys(%alluserslog)) { + &log(0,$alluserslog{$item}); + } + } } # @@ -317,7 +335,7 @@ sub portfolio_logging { } sub descend_tree { - my ($dir,$depth,$alldomusers) = @_; + my ($dom,$dir,$depth,$allportusers,$alldomusers) = @_; if (-d $dir) { opendir(DIR,$dir); my @contents = grep(!/^\./,readdir(DIR)); @@ -325,10 +343,12 @@ sub descend_tree { $depth ++; foreach my $item (@contents) { if ($depth < 4) { - &descend_tree($dir.'/'.$item,$depth,$alldomusers); + &descend_tree($dom,$dir.'/'.$item,$depth,$allportusers,$alldomusers); } else { if (-e $dir.'/'.$item.'/file_permissions.db') { - + $$allportusers{$item} = ''; + } + if (!&Apache::lonnet::is_course($dom,$item)) { $$alldomusers{$item} = ''; } } @@ -679,7 +699,7 @@ sub write_copyright_count { ## (copied from lond, modification of the return value) sub ishome { my $author=shift; - $author=~s/\/home\/httpd\/html\/res\/([^\/]*)\/([^\/]*).*/$1\/$2/; + $author=~s{/home/httpd/html/res/([^/]*)/([^/]*).*}{$1/$2}; my ($udom,$uname)=split(/\//,$author); my $proname=propath($udom,$uname); if (-e $proname) { @@ -690,20 +710,6 @@ sub ishome { } ## -## &propath($udom,$uname) -## Returns the path to the users LON-CAPA directory -## (copied from lond) -sub propath { - my ($udom,$uname)=@_; - $udom=~s/\W//g; - $uname=~s/\W//g; - my $subdir=$uname.'__'; - $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/; - my $proname="$Apache::lonnet::perlvar{'lonUsersDir'}/$udom/$subdir/$uname"; - return $proname; -} - -## ## &declutter($filename) ## Given a filename, returns a url for the filename. sub declutter { @@ -714,16 +720,3 @@ sub declutter { return $thisfn; } -## -## Escape / Unescape special characters -sub unescape { - my $str=shift; - $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; - return $str; -} - -sub escape { - my $str=shift; - $str =~ s/(\W)/"%".unpack('H2',$1)/eg; - return $str; -}