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

raeburn lon-capa-cvs@mail.lon-capa.org
Fri, 20 Oct 2006 00:34:48 -0000


raeburn		Thu Oct 19 20:34:48 2006 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  When renaming or removing a portfolio file take the same action for the associated metadata file.
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.797 loncom/lonnet/perl/lonnet.pm:1.798
--- loncom/lonnet/perl/lonnet.pm:1.797	Thu Oct 19 17:23:23 2006
+++ loncom/lonnet/perl/lonnet.pm	Thu Oct 19 20:34:45 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.797 2006/10/19 21:23:23 raeburn Exp $
+# $Id: lonnet.pm,v 1.798 2006/10/20 00:34:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1636,7 +1636,14 @@
 sub removeuserfile {
     my ($docuname,$docudom,$fname)=@_;
     my $home=&homeserver($docuname,$docudom);
-    return &reply("removeuserfile:$docudom/$docuname/$fname",$home);
+    my $result = &reply("removeuserfile:$docudom/$docuname/$fname",$home);
+    if ($result eq 'ok') {
+        if (($fname !~ /\.meta$/) && (&is_portfolio_file($fname))) {
+            my $metafile = $fname.'.meta';
+            my $metaresult = &removeuserfile($docuname,$docudom,$metafile); 
+        }
+    }
+    return $result;
 }
 
 sub mkdiruserfile {
@@ -1648,8 +1655,17 @@
 sub renameuserfile {
     my ($docuname,$docudom,$old,$new)=@_;
     my $home=&homeserver($docuname,$docudom);
-    return &reply("renameuserfile:$docudom:$docuname:".&escape("$old").':'.
-		  &escape("$new"),$home);
+    my $result = &reply("renameuserfile:$docudom:$docuname:".
+                        &escape("$old").':'.&escape("$new"),$home);
+    if ($result eq 'ok') {
+        if (($old !~ /\.meta$/) && (&is_portfolio_file($old))) {
+            my $oldmeta = $old.'.meta';
+            my $newmeta = $new.'.meta';
+            my $metaresult = 
+                &renameuserfile($docuname,$docudom,$oldmeta,$newmeta);
+        }
+    }
+    return $result;
 }
 
 # ------------------------------------------------------------------------- Log
@@ -3444,6 +3460,15 @@
     return scalar(&parse_portfolio_url($url));
 }
 
+sub is_portfolio_file {
+    my ($file) = @_;
+    if (($file =~ /^portfolio/) || ($file =~ /^groups\/\w+\/portfolio/)) {
+        return 1;
+    }
+    return;
+}
+
+
 # ---------------------------------------------- Custom access rule evaluation
 
 sub customaccess {