Diff for /loncom/debugging_tools/move_construction_spaces.pl between versions 1.5 and 1.8

version 1.5, 2011/10/27 14:01:21 version 1.8, 2012/06/08 13:04:08
Line 38  use LONCAPA qw(:DEFAULT :match); Line 38  use LONCAPA qw(:DEFAULT :match);
 use Apache::lonlocal;  use Apache::lonlocal;
 use File::Copy;  use File::Copy;
 use GDBM_File;  use GDBM_File;
   use DBI;
   
 my ($lonusersdir,$londocroot,$londaemons);  my ($lonusersdir,$londocroot,$londaemons,$lonsqlaccess);
   
 BEGIN {  BEGIN {
     my $perlvar=&LONCAPA::Configuration::read_conf();      my $perlvar=&LONCAPA::Configuration::read_conf();
Line 47  BEGIN { Line 48  BEGIN {
         $lonusersdir = $perlvar->{'lonUsersDir'};          $lonusersdir = $perlvar->{'lonUsersDir'};
         $londocroot = $perlvar->{'lonDocRoot'};          $londocroot = $perlvar->{'lonDocRoot'};
         $londaemons = $perlvar->{'lonDaemons'};          $londaemons = $perlvar->{'lonDaemons'};
           $lonsqlaccess = $perlvar->{'lonSqlAccess'};
     }      }
     undef($perlvar);      undef($perlvar);
 }  }
Line 254  if ($lonusersdir) { Line 256  if ($lonusersdir) {
     my ($dir,$output);      my ($dir,$output);
     if (opendir($dir,$lonusersdir)) {      if (opendir($dir,$lonusersdir)) {
         my @contents = (grep(!/^\.{1,2}$/,readdir($dir)));          my @contents = (grep(!/^\.{1,2}$/,readdir($dir)));
           closedir($dir);
         foreach my $item (@contents) {          foreach my $item (@contents) {
             if (-d "$lonusersdir/$item") {              if (-d "$lonusersdir/$item") {
                 if ($item =~ /^$match_domain$/) {                  if ($item =~ /^$match_domain$/) {
Line 301  if ($lonusersdir) { Line 304  if ($lonusersdir) {
                 }                  }
             }              }
         }          }
         closedir($dir);  
     } else {      } else {
         $output = &mt('Could not open [_1].',"'$lonusersdir'")."\n";          $output = &mt('Could not open [_1].',"'$lonusersdir'")."\n";
         print $output;          print $output;
Line 316  if ($londocroot ne '') { Line 318  if ($londocroot ne '') {
         my ($dir,$domdir);          my ($dir,$domdir);
         if (opendir($dir,"$londocroot/res")) {          if (opendir($dir,"$londocroot/res")) {
             my @contents = (grep(!/^\.{1,2}$/,readdir($dir)));              my @contents = (grep(!/^\.{1,2}$/,readdir($dir)));
               closedir($dir);
             foreach my $dom (@contents) {              foreach my $dom (@contents) {
                 if ((grep(/^\Q$dom\E/,@machinedoms)) && (-d "$londocroot/res/$dom")) {                  if ((grep(/^\Q$dom\E/,@machinedoms)) && (-d "$londocroot/res/$dom")) {
                     if (opendir($domdir,"$londocroot/res/$dom")) {                      if (opendir($domdir,"$londocroot/res/$dom")) {
                         my @unames = (grep(!/^\.{1,2}$/,readdir($domdir)));                          my @unames = (grep(!/^\.{1,2}$/,readdir($domdir)));
                           closedir($domdir);
                         foreach my $uname (@unames) {                          foreach my $uname (@unames) {
                             if ($uname =~ /^$match_username$/) {                              if ($uname =~ /^$match_username$/) {
                                 push(@{$pubusers{$uname}},$dom);                                  push(@{$pubusers{$uname}},$dom);
Line 339  if ($action eq 'undo') { Line 343  if ($action eq 'undo') {
             my ($dir,$domdir);              my ($dir,$domdir);
             if (opendir($dir,"$londocroot/priv")) {              if (opendir($dir,"$londocroot/priv")) {
                 my @contents = (grep(!/^\.{1,2}/,readdir($dir)));                  my @contents = (grep(!/^\.{1,2}/,readdir($dir)));
                   closedir($dir);
                 foreach my $dom (@contents) {                  foreach my $dom (@contents) {
                     next if (!-d "$londocroot/priv/$dom");                      next if (!-d "$londocroot/priv/$dom");
                     if (opendir($domdir,"$londocroot/priv/$dom")) {                      if (opendir($domdir,"$londocroot/priv/$dom")) {
                         my @unames = (grep(!/^\.{1,2}$/,readdir($domdir)));                          my @unames = (grep(!/^\.{1,2}$/,readdir($domdir)));
                           closedir($domdir);
                         foreach my $uname (@unames) {                          foreach my $uname (@unames) {
                             if ($uname =~ /^$match_username$/) {                              if ($uname =~ /^$match_username$/) {
                                 push(@{$privspaces{$uname}},$dom);                                  push(@{$privspaces{$uname}},$dom);
Line 355  if ($action eq 'undo') { Line 361  if ($action eq 'undo') {
     }      }
     foreach my $uname (keys(%privspaces)) {      foreach my $uname (keys(%privspaces)) {
         if (ref($privspaces{$uname}) eq 'ARRAY') {          if (ref($privspaces{$uname}) eq 'ARRAY') {
               my $output;
             if (@{$privspaces{$uname}} > 1) {              if (@{$privspaces{$uname}} > 1) {
                 my $displaydoms = join(', ',@{$privspaces{$uname}});                  my $displaydoms = join(', ',@{$privspaces{$uname}});
                 print &mt('Same username used for authors in multiple domains.')."\n".                  print &mt('Same username used for authors in multiple domains.')."\n".
Line 365  if ($action eq 'undo') { Line 372  if ($action eq 'undo') {
                 my $choice=<STDIN>;                  my $choice=<STDIN>;
                 chomp($choice);                  chomp($choice);
                 if (grep(/^\Q$choice\E$/,@{$privspaces{$uname}})) {                  if (grep(/^\Q$choice\E$/,@{$privspaces{$uname}})) {
                     my $output = &move_priv_to_home($londocroot,$uid,$gid,$uname,$choice);                      $output = &move_priv_to_home($londocroot,$uid,$gid,$uname,$choice);
                     print $output;  
                     print $logfh $output;  
                 } else {                  } else {
                     print &mt('Invalid choice of domain:')." $choice\n";                      print &mt('Invalid choice of domain:')." $choice\n";
                     my $output = &mt('Skipping this user: [_1].',"'$uname'")."\n";                      $output = &mt('Skipping this user: [_1].',"'$uname'")."\n";
                     print $output;                      print $output;
                     print $logfh $output;                      print $logfh $output;
                     next;                      next;
                 }                  }
             } elsif (@{$privspaces{$uname}} == 1) {              } elsif (@{$privspaces{$uname}} == 1) {
                 my $output = &move_priv_to_home($londocroot,$uid,$gid,$uname,$privspaces{$uname}[0]);                  $output = &move_priv_to_home($londocroot,$uid,$gid,$uname,$privspaces{$uname}[0]);
                 print $output;  
                 print $logfh $output;  
             } else {              } else {
                 print &mt('Username [_1] found in [_2] was not within a domain',                  print &mt('Username [_1] found in [_2] was not within a domain',
                           "'$uname'","'$londocroot/priv'")."\n";                            "'$uname'","'$londocroot/priv'")."\n";
                 my $output = &mt('Skipping this user: [_1].',"'$uname'")."\n";                  $output = &mt('Skipping this user: [_1].',"'$uname'")."\n";
                 print $output;  
                 print $logfh $output;  
             }              }
               print $output;
               print $logfh $output;
         }          }
     }      }
       if (-d "$londocroot/priv") {
           my $output;
           if (opendir(my $dir,"$londocroot/priv")) {
               my @doms = grep(!/^\.{1,2}/,readdir($dir));
               closedir($dir);
               foreach my $dom (@doms) {
                   if (opendir(my $domdir,"$londocroot/priv/$dom")) {
                       my @contents =  grep(!/^\.{1,2}/,readdir($domdir));
                       closedir($domdir);
                       if (@contents == 0) {
                           if (rmdir("$londocroot/priv/$dom")) {
                               $output = &mt('Removed empty directory: [_1]',
                                             "'$londocroot/priv/$dom'")."\n";
                           } else {
                               $output = &mt('Failed to remove directory: [_1]',
                                             "'$londocroot/priv/$dom'")."\n";
                           }
                       }
                   }
               }
           }
           my $warning = &mt('WARNING: Access to Construction Spaces in their old locations (i.e., in [_1]) via LON-CAPA with URLs of the form [_2] will not work until the directory at [_3] is moved or deleted.',"'/home/<user>/'","'/priv/<user>/'","'$londocroot/priv/'")."\n";
           if (opendir(my $dir,"$londocroot/priv")) {
               my @contents = (grep(!/^\.{1,2}/,readdir($dir)));
               closedir($dir);
               if (@contents == 0) {
                   if (rmdir("$londocroot/priv")) {
                       $output .= &mt('Removed empty directory: [_1]',
                                      "'$londocroot/priv'")."\n";
                   } else {
                       $output .= &mt('Failed to remove directory: [_1]',
                                      "'$londocroot/priv'")."\n".
                                  $warning."\n";
                   }
               } else {
                   $output .= $warning."\n".
                              &mt('The attempt to remove the directory failed, because it is not empty.')."\n";
               }
           } else {
               $output .= $warning."\n".
                          &mt('The attempt to open the directory to see its contents failed, hence no attempt was made to remove it.')."\n";
           }
           print $output;
           print $logfh $output;
       }
     &stop_logging($logfh);      &stop_logging($logfh);
     print "\n".&mt('Done')."\n";      print "\n".&mt('Done')."\n";
     exit;      exit;
Line 395  if ($action eq 'undo') { Line 443  if ($action eq 'undo') {
   
 my @allskipped;  my @allskipped;
 my %allmoved;  my %allmoved;
   my ($dbh,$dbflag);
   
 # Iterate over directories in /home  # Iterate over directories in /home
 if (opendir(my $dir,"/home")) {  if (opendir(my $dir,"/home")) {
     my @possibles = grep(!/^\.{1,2}$/,readdir($dir));       my @possibles = grep(!/^\.{1,2}$/,readdir($dir));
       closedir($dir);
     foreach my $item (sort(@possibles)) {      foreach my $item (sort(@possibles)) {
         next if ($item eq 'www');          next if ($item eq 'www');
         if ((-d "/home/$item") && ($item ne '')) {          if ((-d "/home/$item") && ($item ne '')) {
 # Is there a public_html-directory?  # Is there a public_html-directory?
             if (-d "/home/$item/public_html") {              if (-d "/home/$item/public_html") {
                 my $author = $item;                  my $author = $item;
                 my ($domain,$skipped,$output);                  my ($domain,$skipped,$output,$stopnow);
                 if (ref($allauthors{$author}) eq 'ARRAY') {                  if (ref($allauthors{$author}) eq 'ARRAY') {
                     ($domain,$skipped) = &choose_domain($action,$author,$allauthors{$author});                      ($domain,$skipped,$stopnow) = 
                           &choose_domain($action,$author,$allauthors{$author});
                       if ($stopnow) {
                           if ($action ne 'dryrun') {
                               my $output = &mt('Stopped by user at author: [_1].',
                                                "'$author'")/"\n";
                               &stop_logging($logfh,$output);
                           }
                           if ($dbflag == 1) {
                               &disconnect_mysql($dbh);
                           }
                           print &mt('Stopped.')."\n";
                           exit;
                       }
                 }                  }
                 if (($domain eq '') && (!$skipped)) {                  if (($domain eq '') && (!$skipped)) {
                     if (ref($pubusers{$author}) eq 'ARRAY') {                      if (ref($pubusers{$author}) eq 'ARRAY') {
                         ($domain,$skipped) = &choose_domain($action,$author,$pubusers{$author});                          ($domain,$skipped,$stopnow) = 
                               &choose_domain($action,$author,$pubusers{$author});
                       }
                       if ($stopnow) {
                           if ($action ne 'dryrun') {
                               my $output = &mt('Stopped by user at author: [_1].',
                                                "'$author'")/"\n";
                               &stop_logging($logfh,$output);
                           }
                           if ($dbflag == 1) {
                               &disconnect_mysql($dbh);
                           }
                           print &mt('Stopped.')."\n";
                           exit;
                     }                      }
                 }                  }
                 if (($domain eq '') && (!$skipped)) {                  if (($domain eq '') && (!$skipped)) {
Line 439  if (opendir(my $dir,"/home")) { Line 515  if (opendir(my $dir,"/home")) {
                         }                          }
                     }                      }
                     if (@foundauthor > 0) {                      if (@foundauthor > 0) {
                         ($domain,$skipped) = &choose_domain($action,$author,\@foundauthor);                          ($domain,$skipped,$stopnow) = 
                                &choose_domain($action,$author,\@foundauthor);
                           if ($stopnow) {
                               if ($action ne 'dryrun') {
                                   my $output = &mt('Stopped by user at author: [_1].',
                                                    "'$author'")/"\n";
                                   &stop_logging($logfh,$output);
                               }
                               if ($dbflag == 1) {
                                   &disconnect_mysql($dbh);
                               }
                               print &mt('Stopped.')."\n";
                               exit;
                           }
                       }
                   }
                   if (($domain eq '') && (!$skipped)) {
                       if (!$dbflag) {
                           ($dbh,$dbflag) = &connect_mysql($lonsqlaccess);
                       }
                       if (defined($dbh)) {
                           my $foundusers = &search_allusers($dbh,$author);
                           if (ref($foundusers) eq 'HASH') {
                               ($domain,$skipped,$stopnow) = 
                                   &choose_domain($action,$author,$foundusers);
                           }
                           if ($stopnow) {
                               if ($action ne 'dryrun') {
                                   my $output = &mt('Stopped by user at author: [_1].',
                                                    "'$author'")/"\n";
                                   &stop_logging($logfh,$output);
                               }
                               if ($dbflag == 1) {
                                   &disconnect_mysql($dbh);
                               }
                               print &mt('Stopped.')."\n";
                               exit;
                           }
                     }                      }
                 }                  }
                 my $source_path="/home/$author/public_html";                  my $source_path="/home/$author/public_html";
Line 460  if (opendir(my $dir,"/home")) { Line 573  if (opendir(my $dir,"/home")) {
                                 if (opendir(my $homedir,"/home/$author")) {                                  if (opendir(my $homedir,"/home/$author")) {
                                     my @contents =                                       my @contents = 
                                         grep(!/^\.{1,2}$/,readdir($homedir));                                          grep(!/^\.{1,2}$/,readdir($homedir));
                                       closedir($homedir);
                                     if (@contents == 0) {                                      if (@contents == 0) {
                                         if (rmdir("/home/$author/")) {                                          if (rmdir("/home/$author/")) {
                                             $output .= &mt('Removed empty directory: [_1]',                                              $output .= &mt('Removed empty directory: [_1]',
Line 496  if (opendir(my $dir,"/home")) { Line 610  if (opendir(my $dir,"/home")) {
                     }                      }
                 } else {                  } else {
                     print '*** '.&mt('WARNING: [_1] has no domain.',"'$author'")."\n".                      print '*** '.&mt('WARNING: [_1] has no domain.',"'$author'")."\n".
                           &mt('Enter [_1]: do nothing, continue.','1')."\n".                            &mt('Enter [_1]: skip this user.','1')."\n".
                           &mt('Enter [_1]: stop.','2')."\n".                            &mt('Enter [_1]: stop.','2')."\n".
                           &mt('or enter domain for user to be placed into')."\n".                            &mt('or enter domain for user to be placed into')."\n".
                           &mt('Your input: ');                            &mt('Your input: ');
Line 520  if (opendir(my $dir,"/home")) { Line 634  if (opendir(my $dir,"/home")) {
                                              "'$author'")/"\n";                                               "'$author'")/"\n";
                             &stop_logging($logfh,$output);                               &stop_logging($logfh,$output); 
                         }                          }
                           if ($dbflag == 1) {
                               &disconnect_mysql($dbh);
                           } 
                         exit;                          exit;
                     } elsif ($choice =~ /^$match_domain$/) {                      } elsif ($choice =~ /^$match_domain$/) {
                         print &mt('You entered:')." $choice\n".                          print &mt('You entered:')." $choice\n".
                               &mt('Is this ok? ~[Y/n~] ');                                &mt('Is this ok? ~[Y/n~] ');
                         if (!&get_user_selection(1)) {                          if (!&get_user_selection(1)) {
                             print &mt('Try again ...')."\n".                              print &mt('Try again ...')."\n".
                                   &mt('Enter [_1]: do nothing, continue.','1')."\n".                                    &mt('Enter [_1]: skip this user.','1')."\n".
                                   &mt('Enter [_1]: stop.','2')."\n".                                    &mt('Enter [_1]: stop.','2')."\n".
                                   &mt('or enter domain for user to be placed into')."\n".                                    &mt('or enter domain for user to be placed into')."\n".
                                   &mt('Your input: ');                                    &mt('Your input: ');
Line 550  if (opendir(my $dir,"/home")) { Line 667  if (opendir(my $dir,"/home")) {
                                                      "'$author'")/"\n";                                                       "'$author'")/"\n";
                                     &stop_logging($logfh,$output);                                      &stop_logging($logfh,$output);
                                 }                                  }
                                   if ($dbflag == 1) {
                                       &disconnect_mysql($dbh);
                                   }
                                 exit;                                  exit;
                             } elsif ($choice !~ /^$match_domain$/) {                              } elsif ($choice !~ /^$match_domain$/) {
                                 print &mt('Invalid domain entered:')." $choice\n";                                  print &mt('Invalid domain entered:')." $choice\n";
Line 579  if (opendir(my $dir,"/home")) { Line 699  if (opendir(my $dir,"/home")) {
                             if (-e $dompath) {                              if (-e $dompath) {
                                 if (move($source_path,$newpath)) {                                  if (move($source_path,$newpath)) {
                                     chown($uid,$gid,$newpath);                                      chown($uid,$gid,$newpath);
                                     chmod($newpath,0750);                                      chmod(0750,$newpath);
                                     $output = &mt('Moved [_1] to [_2].',                                      $output = &mt('Moved [_1] to [_2].',
                                                   "'$source_path'","'$newpath'")."\n";                                                    "'$source_path'","'$newpath'")."\n";
                                 } else {                                  } else {
Line 630  $skipcount = scalar(@allskipped); Line 750  $skipcount = scalar(@allskipped);
 print "\n";  print "\n";
 if ($action ne 'dryrun') {  if ($action ne 'dryrun') {
     my $output = &mt('You skipped: [_1].',$skipcount)."\n".      my $output = &mt('You skipped: [_1].',$skipcount)."\n".
                    join("\n",sort(@allskipped))."\n\n".
                  &mt('Moved ... [_1]',$moveinfo);                   &mt('Moved ... [_1]',$moveinfo);
     print $output;      print $output;
     print $logfh $output;      print $logfh $output;
     &stop_logging($logfh);      &stop_logging($logfh);
 } else {  } else {
     print &mt('You would have skipped: [_1].',$skipcount)."\n".      print &mt('You would have skipped: [_1].',$skipcount)."\n".
             join("\n",sort(@allskipped))."\n\n".
           &mt('You would have moved ... [_1]',$moveinfo);            &mt('You would have moved ... [_1]',$moveinfo);
 }  }
 print "\n\n".&mt('Done.')."\n";  print "\n\n".&mt('Done.')."\n";
   
 sub choose_domain {   sub choose_domain {
     my ($action,$author,$domarrayref) = @_;      my ($action,$author,$domref) = @_;
     my ($domain,$skipped);      my ($domain,$skipped,$stopnow,@domains);
     if (ref($domarrayref) eq 'ARRAY') {      if (ref($domref) eq 'ARRAY') {
          if (@{$domarrayref} > 1) {          @domains = @{$domref};
              print '*** '.&mt('ERROR: [_1] found in multiple domains.',"'$author'")."\n".      } elsif (ref($domref) eq 'HASH') {
                    &mt('Enter a number to choose what action to take.')."\n";          @domains = sort(keys(%{$domref}));
              my $num = 1;      }
              for (my $i=0; $i<@{$domarrayref}; $i++) {      if (@domains > 1) {
                  print &mt('To use: [_1] enter [_2].',$domarrayref->[$i],$num)."\n";          print '*** '.&mt('ERROR: [_1] found in multiple domains.',"'$author'")."\n".
                  $num ++;                 &mt('Enter a number to choose what action to take.')."\n";
              }          my $num = 1;
              print &mt('To skip this user enter: [_1].',$num)."\n".          print &mt('Enter [_1]: skip this user.',$num)."\n";
                    &mt('Your choice:').' ';          for (my $i=0; $i<@domains; $i++) {
              my $choice=<STDIN>;              my $shown = $domains[$i];
              chomp($choice);              if (ref($domref) eq 'HASH') {
              if ($choice =~ /^\d+$/) {                  if ($domref->{$shown} ne '') {
                  if (($choice == $num) || ($choice > $num)) {                      $shown .= ' ('.$domref->{$shown}.') ';
                      $skipped = 1;                         }
                  } elsif (($choice < $num) && ($choice > 0)) {              }
                      $domain = $domarrayref->[$choice-1];              $num ++; 
                  } else {              print &mt('Enter [_1]: use domain - [_2].',$num,$shown)."\n";
                      print &mt('Invalid choice:')." $choice\n";          }
                      $skipped = 1;          $num ++;
                  }          print &mt('Enter [_1]: stop.',$num)."\n";
              } else {          print &mt('Your choice:').' ';
                  print &mt('Invalid choice:')." $choice\n";          my $choice=<STDIN>;
                  $skipped = 1;          chomp($choice);
              }          if ($choice =~ /^\d+$/) {
          } elsif (@{$domarrayref} == 1) {              if ($choice == 1) {
              $domain = $domarrayref->[0];                  $skipped = 1;       
          }              } elsif (($choice < $num) && ($choice > 1)) {
                   $domain = $domains[$choice-2];
               } elsif ($choice == $num) {
                   $stopnow = 1;
               } else {
                   print &mt('Invalid choice:')." $choice\n".
                         &mt('Skipping this user.')."\n";
                   $skipped = 1;
               }
           } else {
               print &mt('Invalid choice:')." $choice\n".
                     &mt('Skipping this user.')."\n";
               $skipped = 1;
           }
       } elsif (@domains == 1) {
           $domain = $domains[0];
     }      }
     return ($domain,$skipped);      return ($domain,$skipped,$stopnow);
 }  }
   
 sub move_priv_to_home {  sub move_priv_to_home {
Line 684  sub move_priv_to_home { Line 821  sub move_priv_to_home {
         my $target_path="/home/$uname/public_html";          my $target_path="/home/$uname/public_html";
         if (!-e "/home/$uname") {          if (!-e "/home/$uname") {
             my (undef,undef,$userid,$groupid) = getpwnam($uname);              my (undef,undef,$userid,$groupid) = getpwnam($uname);
             if (mkdir("/home/$uname",0750)) {              if (mkdir("/home/$uname",0711)) {
                 if ($userid ne '' && $groupid ne '') {                  if ($userid ne '' && $groupid ne '') {
                     chown($userid,$groupid,"/home/$uname");                      chown($userid,$groupid,"/home/$uname");
                 }                  }
Line 698  sub move_priv_to_home { Line 835  sub move_priv_to_home {
             if (!-e $target_path) {              if (!-e $target_path) {
                 move($source_path,$target_path);                  move($source_path,$target_path);
                 chown($uid,$gid,$target_path);                  chown($uid,$gid,$target_path);
                 chmod($target_path,2770);                  chmod(02770,$target_path);
                 $output = &mt('Moved [_1] to [_2].',"'$source_path'","'$target_path'")."\n";                  if (-e $target_path && !-e $source_path) {
                       $output = &mt('Moved [_1] to [_2].',"'$source_path'","'$target_path'")."\n";
                   } else {
                       $output = &mt('Failed to move [_1] to [_2].',"'$source_path'","'$target_path'")."\n";
                   }
             } else {              } else {
                 $output = &mt('Directory [_1] already exists -- not moving [_2].',                  $output = &mt('Directory [_1] already exists -- not moving [_2].',
                               "'$target_path'","'$source_path'")."\n";                                "'$target_path'","'$source_path'")."\n";
Line 753  sub check_for_restore_files { Line 894  sub check_for_restore_files {
     my ($londaemons,$author,$domain) = @_;      my ($londaemons,$author,$domain) = @_;
     if (opendir(my $homedir,"/home/$author")) {      if (opendir(my $homedir,"/home/$author")) {
         my @contents = grep(!/^\.{1,2}$/,readdir($homedir));          my @contents = grep(!/^\.{1,2}$/,readdir($homedir));
           closedir($homedir);
         if (@contents > 0) {          if (@contents > 0) {
             if (grep(/^restore_\d+\.sh$/,@contents)) {              if (grep(/^restore_\d+\.sh$/,@contents)) {
                 if (!-e "$londaemons/logs/moved_construction_spaces") {                   if (!-e "$londaemons/logs/moved_construction_spaces") { 
Line 791  sub check_for_restore_files { Line 933  sub check_for_restore_files {
     return;      return;
 }  }
   
   sub connect_mysql {
       my ($lonsqlaccess) = @_;
       my ($dbh,$dbflag);
       eval { $dbh = DBI->connect("DBI:mysql:loncapa","www",
                                  $lonsqlaccess,
                                  {RaiseError =>0,PrintError=>0}); 
       };
       if ($@) {
           $dbflag = -1;
       } else {
           if (defined($dbh)) {
               $dbflag = 1;
           }
       }
       return ($dbh,$dbflag);
   }
   
   sub disconnect_mysql {
       my ($dbh) = @_;
       if (ref($dbh)) {
           $dbh->disconnect;
       }
       return;
   }
   
   sub search_allusers {
       my ($dbh,$author) = @_;
       my %fullnames;
       if ((ref($dbh)) && ($author ne '')) {
           eval {
               my $statement = "SELECT domain, lastname, firstname FROM allusers WHERE username='$author'";
               my $sth = $dbh->prepare($statement);
               $sth->execute();
               while ( my ($dom,$last,$first) = $sth->fetchrow_array()) {
                   if ($dom ne '') {
                       $fullnames{$dom} = "$first $last";
                   }
               }
               $sth->finish;
           };
       }
       return \%fullnames;
   }

Removed from v.1.5  
changed lines
  Added in v.1.8


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>