[LON-CAPA-cvs] cvs: loncom / lonsql /lonnet/perl lonnet.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Wed, 03 Jan 2007 02:00:42 -0000


raeburn		Tue Jan  2 21:00:42 2007 EDT

  Modified files:              
    /loncom	lonsql 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Renaming and deletion of portfolio files now causes removal of records in MySQL portfolio_metadata and portfolio_addedfield tables for old file name.
  
  Arguments passed to lonsql via a querysend to lond changed - $arg1 now colon-separated uname,domain,group; $arg3 -now action (e.g., delete).
  
  
Index: loncom/lonsql
diff -u loncom/lonsql:1.78 loncom/lonsql:1.79
--- loncom/lonsql:1.78	Tue Jan  2 07:51:31 2007
+++ loncom/lonsql	Tue Jan  2 20:59:42 2007
@@ -3,7 +3,7 @@
 # The LearningOnline Network
 # lonsql - LON TCP-MySQL-Server Daemon for handling database requests.
 #
-# $Id: lonsql,v 1.78 2007/01/02 12:51:31 raeburn Exp $
+# $Id: lonsql,v 1.79 2007/01/03 01:59:42 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -659,9 +659,9 @@
         }
     }
     if ($result eq 'ok') {
-        my ($uname,$udom) = split(/:/,&unescape($arg1));
+        my ($uname,$udom,$group) = split(/:/,&unescape($arg1));
         my $file_name = &unescape($arg2);
-        my $group = &unescape($arg3);
+        my $action = $arg3;
         my $is_course = 0;
         if ($group ne '') {
             $is_course = 1;
@@ -677,15 +677,17 @@
             $fullpath = $pathstart.'/portfolio'.$file_name;
             $url = $urlstart.'/portfolio'.$file_name;
         }
-        my %access = &get_access_hash($uname,$udom,$group.$file_name);
         if ($query eq 'portfolio_metadata') {
-            if (-e $fullpath.'.meta') {
+            if ($action eq 'delete') {
+                my %loghash = &LONCAPA::lonmetadata::process_portfolio_metadata($dbh,undef,\%tablenames,$url,$fullpath,$is_course,$udom,$uname,$group,'update');
+            } elsif (-e $fullpath.'.meta') {
                 my %loghash = &LONCAPA::lonmetadata::process_portfolio_metadata($dbh,undef,\%tablenames,$url,$fullpath,$is_course,$udom,$uname,$group,'update');
                 if (keys(%loghash) > 0) {
                     &portfolio_logging(%loghash);
                 }
             }
         } elsif ($query eq 'portfolio_access') {
+            my %access = &get_access_hash($uname,$udom,$group.$file_name);
             my %loghash =
      &LONCAPA::lonmetadata::process_portfolio_access_data($dbh,undef,
          \%tablenames,$url,$fullpath,\%access,'update');
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.820 loncom/lonnet/perl/lonnet.pm:1.821
--- loncom/lonnet/perl/lonnet.pm:1.820	Tue Jan  2 20:50:10 2007
+++ loncom/lonnet/perl/lonnet.pm	Tue Jan  2 21:00:38 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.820 2007/01/03 01:50:10 raeburn Exp $
+# $Id: lonnet.pm,v 1.821 2007/01/03 02:00:38 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1701,6 +1701,17 @@
         if (($fname !~ /\.meta$/) && (&is_portfolio_file($fname))) {
             my $metafile = $fname.'.meta';
             my $metaresult = &removeuserfile($docuname,$docudom,$metafile); 
+            my ($group,$file);
+            if ($fname =~ /^groups\/(\w+)\/portfolio(\/.+)$/) {
+                $group = $1;
+                $file = $2;
+            } elsif ($fname =~ /^portfolio(\/.+)$/) {
+                $file = $1;
+            }
+            my $sqlresult = 
+                &update_portfolio_table($docuname,$docudom,$group.$file,
+                                        'portfolio_metadata',$group,
+                                        'delete');
         }
     }
     return $result;
@@ -1723,6 +1734,17 @@
             my $newmeta = $new.'.meta';
             my $metaresult = 
                 &renameuserfile($docuname,$docudom,$oldmeta,$newmeta);
+            my ($group,$file);
+            if ($old =~ /^groups\/(\w+)\/portfolio(\/.+)$/) {
+                $group = $1;
+                $file = $2;
+            } elsif ($old =~ /^portfolio(\/.+)$/) {
+                $file = $1;
+            }
+            my $sqlresult = 
+                &update_portfolio_table($docuname,$docudom,$group.$file,
+                                        'portfolio_metadata',$group,
+                                        'delete');
         }
     }
     return $result;
@@ -4099,11 +4121,11 @@
 # -------------------------- Update MySQL table for portfolio file
 
 sub update_portfolio_table {
-    my ($uname,$udom,$file_name,$query,$group) = @_;
+    my ($uname,$udom,$file_name,$query,$group,$action) = @_;
     my $homeserver = &homeserver($uname,$udom);
     my $queryid=
-        &reply("querysend:".$query.':'.&escape($uname.':'.$udom).':'.
-              &escape($file_name).':'.&escape($group),$homeserver);
+        &reply("querysend:".$query.':'.&escape($uname.':'.$udom.':'.$group).
+               ':'.&escape($file_name).':'.$action,$homeserver);
     my $reply = &get_query_reply($queryid);
     return $reply;
 }