[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm /publisher londiff.pm lonpubdir.pm lonpublisher.pm lonretrieve.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 13 Sep 2006 21:43:28 -0000


This is a MIME encoded message

--albertel1158183808
Content-Type: text/plain

albertel		Wed Sep 13 17:43:28 2006 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
    /loncom/publisher	londiff.pm lonpubdir.pm lonpublisher.pm 
                     	lonretrieve.pm 
  Log:
  - BUG#5014, when modifying .meta files need to advertise that fact in the
       directoy browser
      - additionaly when doing full dir repbulishes, republish if the .meta file has changed
  - also add support for retrieving a previoulsy published .meta file
  - add support for getting diffs between previous .meta file revisions
  
  
  
--albertel1158183808
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20060913174328.txt"

Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.454 loncom/interface/loncommon.pm:1.455
--- loncom/interface/loncommon.pm:1.454	Wed Sep 13 15:42:06 2006
+++ loncom/interface/loncommon.pm	Wed Sep 13 17:43:25 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.454 2006/09/13 19:42:06 banghart Exp $
+# $Id: loncommon.pm,v 1.455 2006/09/13 21:43:25 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3499,7 +3499,8 @@
 table#LC_browser tr.LC_browser_file_obsolete {
   background: #AAAAAA;
 }
-table#LC_browser tr.LC_browser_file_modified {
+table#LC_browser tr.LC_browser_file_modified,
+table#LC_browser tr.LC_browser_file_metamodified {
   background: #FFFF77;
 }
 table#LC_browser tr.LC_browser_folder {
Index: loncom/publisher/londiff.pm
diff -u loncom/publisher/londiff.pm:1.19 loncom/publisher/londiff.pm:1.20
--- loncom/publisher/londiff.pm:1.19	Wed May 17 09:41:45 2006
+++ loncom/publisher/londiff.pm	Wed Sep 13 17:43:26 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to show differences between file versions
 #
-# $Id: londiff.pm,v 1.19 2006/05/17 13:41:45 www Exp $
+# $Id: londiff.pm,v 1.20 2006/09/13 21:43:26 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,9 +35,10 @@
 use File::Compare;
 use Algorithm::Diff qw(diff);
 use Apache::Constants qw(:common :http :methods);
-use Apache::loncacc;
+use Apache::loncacc();
 use Apache::lonnet;
 use Apache::loncommon();
+use Apache::lonretrieve();
 use Apache::lonlocal;
 
 
@@ -75,7 +76,6 @@
 sub handler {
 
   my $r=shift;
-
 # Get query string for limited number of parameters
 
    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
@@ -122,7 +122,8 @@
       }
 
 
- if (&Apache::loncommon::fileembstyle(($efn=~/\.(\w+)$/)) eq 'ssi') {
+ if (&Apache::loncommon::fileembstyle(($efn=~/\.(\w+)$/)) eq 'ssi'
+     || $efn =~ /\.meta$/) {
      $r->print('<p><font color="red">');
      if ($env{'form.versionone'} eq 'priv') {
 	 my $fn='/home/'.$cuname.'/public_html/'.$efn;
@@ -132,7 +133,11 @@
 	 my $fn=
 	     '/home/httpd/html/res/'.$cudom.'/'.$cuname.'/';
 	 if ($env{'form.versionone'}) {
-	     my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
+	     my ($main,$suffix,$is_meta)=
+		 &Apache::lonretrieve::get_file_info($efn);
+
+	     $fn.=($efn =~m|(.*/)[^/]+|)[0];
+	     # add on to $fn the path information in $efn
 	     $fn.=$main.'.'.$env{'form.versionone'}.'.'.$suffix;
 	     $r->print('<b>'.&mt('Version').' '.$env{'form.versionone'}.'</b>');
 	 } else {
@@ -158,7 +163,10 @@
 	 my $fn=
 	     '/home/httpd/html/res/'.$cudom.'/'.$cuname.'/';
 	 if ($env{'form.versiontwo'}) {
-	     my ($main,$suffix)=($efn=~/^(.+)\.(\w+)$/);
+	     my ($main,$suffix,$is_meta)=
+		 &Apache::lonretrieve::get_file_info($efn);
+	     # add on to $fn the path information in $efn
+	     $fn.=($efn =~m|(.*/)[^/]+|)[0];
 	     $fn.=$main.'.'.$env{'form.versiontwo'}.'.'.$suffix;
 	     $r->print('<b>'.&mt('Version').' '.$env{'form.versiontwo'}.'</b>');
 	 } else {
Index: loncom/publisher/lonpubdir.pm
diff -u loncom/publisher/lonpubdir.pm:1.94 loncom/publisher/lonpubdir.pm:1.95
--- loncom/publisher/lonpubdir.pm:1.94	Mon Jun 26 18:47:27 2006
+++ loncom/publisher/lonpubdir.pm	Wed Sep 13 17:43:26 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Construction Space Directory Lister
 #
-# $Id: lonpubdir.pm,v 1.94 2006/06/26 22:47:27 albertel Exp $
+# $Id: lonpubdir.pm,v 1.95 2006/09/13 21:43:26 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -571,6 +571,7 @@
     my $css_class='LC_browser_file';
     my $title='&nbsp;';
     my $publish_button=&mt('Publish');
+    my $cstr_dir = '/home/'.$uname.'/public_html/'.$thisdisfn.'/';
 #    my $action_buttons=
 #        '<br /><a target="_parent" href="/adm/cfile?action=delete&filename=/~'.
 #	$uname.'/'.$thisdisfn.'/'.$filename.'">'.
@@ -585,44 +586,67 @@
            $same=1;
         } else {
            if (&Apache::londiff::are_different_files($resdir.'/'.$filename,
-	                                      '/home/'.$uname.'/public_html/'.$thisdisfn.'/'.$filename)) {
+						     $cstr_dir.'/'.$filename)) {
               $same=0;
            } else {
               $same=1;
            }
         }
+	my $meta_cmtime = (stat($cstr_dir.'/'.$filename.'.meta'))[9];
+	my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
+	my $meta_same = 1;
+	if ($meta_rmtime < $meta_cmtime
+	    && &Apache::londiff::are_different_files($resdir.'/'.$filename.'.meta',
+						     $cstr_dir.'/'.$filename.'.meta')) {
+	    $meta_same = 0;
+	}
 	$publish_button=&mt('Re-publish');
+	my $rights_status =
+	    &mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
+	    &mt(&getSourceRightString($targetdir.'/'.$filename));
+	$title = '<a href="/res/'.$targetdir.'/'.$filename.
+	    '.meta" target="cat">'.
+	    &getTitleString($targetdir.'/'.$filename).'</a>';
+	&Apache::lonnet::logthis("same $same meta $meta_same");
 	if ($same) {
-            $pubstatus = 'published';
-	    $status=&mt('Published').'<br />'.
-		&mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
-		&mt(&getSourceRightString($targetdir.'/'.$filename));
 	    if (&Apache::lonnet::metadata($targetdir.'/'.$filename,'obsolete')) {
                 $pubstatus = 'obsolete';
 		$status=&mt('Obsolete');
-            }
+            } else {
+		if (!$meta_same) {
+		    $pubstatus = 'metamodified';
+		} else {
+		    $pubstatus = 'published';
+		}
+		$status=&mt('Published').
+		    '<br />'. $rights_status;
+	    }
 #	    } else {
 #		$action_buttons='';
 #	    }
-	    $title='<a href="/res/'.$targetdir.'/'.$filename.
-		'.meta" target="cat">'.
-		&getTitleString($targetdir.'/'.$filename).'</a>';
 	} else {
             $pubstatus = 'modified';
-	    $status=&mt('Modified').'<br />'.
-		&mt(&getCopyRightString($targetdir.'/'.$filename)).' '.
-		&mt(&getSourceRightString($targetdir.'/'.$filename));
+	    $status=&mt('Modified').
+		'<br />'. $rights_status;
 #	    $action_buttons='';
-	    $title='<a href="/res/'.$targetdir.'/'.$filename.'.meta" target="cat">'.
-		&getTitleString($targetdir.'/'.$filename).'</a>';
 	    if (&Apache::loncommon::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
 		$status.='<br /><a href="/adm/diff?filename=/~'.$uname.
 		    $thisdisfn.'/'.$filename.
 		    '&amp;versiontwo=priv" target="cat">'.&mt('Diffs').'</a>';
 	    }
-	}
+	} 
+
 	$title.="\n".'<br /><a href="/~'.$uname.$thisdisfn.'/'.$filename.'.meta">'. 
 	    ($$bombs{$targetdir.'/'.$filename}?'<img src="/adm/lonMisc/bomb.gif" border="0" alt="bomb" />':'Edit Metadata').'</a>';
+
+	if (!$meta_same) {
+	    $title = &mt('Metadata Modified').'<br />'.$title.
+		'<br /><a href="/adm/diff?filename=/~'.$uname.
+		$thisdisfn.'/'.$filename.'.meta'.
+		'&amp;versiontwo=priv" target="cat">'.&mt('Metadata Diffs').'</a>';
+	    $title.="\n".'<br /><a href="/adm/retrieve?filename=/~'.$uname.
+		$thisdisfn.'/'.$filename.'.meta" target="_parent">'.&mt('Retrieve Metadata').'</a>';
+	}
 	$status.="\n".'<br /><a href="/adm/retrieve?filename=/~'.$uname.
 	    $thisdisfn.'/'.$filename.'" target="_parent">'.&mt('Retrieve').'</a>';
     }
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.211 loncom/publisher/lonpublisher.pm:1.212
--- loncom/publisher/lonpublisher.pm:1.211	Fri Aug  4 18:16:42 2006
+++ loncom/publisher/lonpublisher.pm	Wed Sep 13 17:43:26 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Publication Handler
 #
-# $Id: lonpublisher.pm,v 1.211 2006/08/04 22:16:42 albertel Exp $
+# $Id: lonpublisher.pm,v 1.212 2006/09/13 21:43:26 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1820,10 +1820,17 @@
 # previously published, modified now
 			$publishthis=1;
 		    }
+		    my $meta_cmtime = (stat($fn.'/'.$filename.'.meta'))[9];
+		    my $meta_rmtime = (stat($resdir.'/'.$filename.'.meta'))[9];
+		    if ( $meta_rmtime<$meta_cmtime ) {
+			&Apache::lonnet::logthis("meta change!");
+			$publishthis=1;
+		    }
 		} else {
 # never published
 		    $publishthis=1;
 		}
+		
 		if ($publishthis) {
 		    &batchpublish($r,$fn.'/'.$filename,$resdir.'/'.$filename);
 		} else {
Index: loncom/publisher/lonretrieve.pm
diff -u loncom/publisher/lonretrieve.pm:1.30 loncom/publisher/lonretrieve.pm:1.31
--- loncom/publisher/lonretrieve.pm:1.30	Thu Apr  6 18:15:19 2006
+++ loncom/publisher/lonretrieve.pm	Wed Sep 13 17:43:26 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to retrieve an old version of a file
 #
-# $Id: lonretrieve.pm,v 1.30 2006/04/06 22:15:19 albertel Exp $
+# $Id: lonretrieve.pm,v 1.31 2006/09/13 21:43:26 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -51,19 +51,24 @@
     my $resdir=$resfn;
     $resdir=~s/\/[^\/]+$/\//;
 
-    $fn=~/\/([^\/]+)\.(\w+)$/;
-    my $main=$1;
-    my $suffix=$2;
-
+    my ($main,$suffix,$is_meta) = &get_file_info($fn);
+    
     if (-e $resfn) {  
     $r->print('<form action=/adm/retrieve method=post>'.
 	      '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.
               '<input type=hidden name=phase value=two>'.
               '<table border=2><tr><th>'.&mt('Select').'</th><th>'.
 	      &mt('Version').'</th>'.
-              '<th>'.&mt('Published on ...').'</th>'.
-              '<th>'.&mt('Metadata').'</th></tr>');
-
+              '<th>'.&mt('Published on ...').'</th>');
+    if (!$is_meta) {
+	$r->print('<th>'.&mt('Metadata').'</th>');
+    }
+    if ($is_meta
+	|| &Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
+	$r->print('<th>'.&mt('Diffs').'</th>');
+    }
+    $r->print('</tr>');
+    
     opendir(DIR,$resdir);
     my @files = grep(/^\Q$main\E\.(\d+)\.\Q$suffix\E$/,readdir(DIR));
     @files = sort {
@@ -79,33 +84,42 @@
            my $rmtime=&Apache::lonnet::metadata($resdir.'/'.$filename,'lastrevisiondate');
            $r->print('<tr><td><input type=radio name=version value="'.
                      $version.'"></td><td>'.&mt('Previously published version').' '.$version.'</td><td>'.
-                     localtime($rmtime).'</td><td>'.
-                     '<a href="'.$urldir.$filename.'.meta" target=cat>'.
-                     &mt('Metadata Version').' '.$version.'</a>');
-           if (&Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
+                     localtime($rmtime).'</td>');
+		     
+	   if (!$is_meta) {
+	       $r->print('<td><a href="'.$urldir.$filename.'.meta" target=cat>'.
+			 &mt('Metadata Version').' '.$version.'</a></td>');
+	   }
+           if ($is_meta
+	       || &Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
                $r->print(
-                    '&nbsp;&nbsp;<a target=cat href="/adm/diff?filename=/~'.
+                    '<td><a target=cat href="/adm/diff?filename=/~'.
                         $uname.$fn.
                         '&versiontwo=priv&versionone='.$version.
-                        '">'.&mt('Diffs with Version').' '.$version.'</a>');
+			 '">'.&mt('Diffs with Version').' '.$version.
+			 '</a></td>');
            }
-           $r->print('</a></td></tr>');
+           $r->print('</tr>');
         }
     }
     closedir(DIR);
     my $rmtime=&Apache::lonnet::metadata($resfn,'lastrevisiondate');
     $r->print('<tr><td><input type=radio name=version value="new"></td>'.
               '<th>'.&mt('Currently published version').'</th><td>'.localtime($rmtime).
-           '</td><td><a href="'.$urldir.$main.'.'.$suffix.'.meta" target=cat>'.
-              &mt('Metadata current version').'</a>');           
-           if (&Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
+           '</td>');
+    if (!$is_meta) {
+	$r->print('<td><a href="'.$urldir.$main.'.'.$suffix.'.meta" target=cat>'.
+		  &mt('Metadata current version').'</a></td>');           
+    }
+           if ($is_meta 
+	       || &Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
                $r->print(
-                    '&nbsp;&nbsp;<a target=cat href="/adm/diff?filename=/~'.
+                    '<td><a target=cat href="/adm/diff?filename=/~'.
                         $uname.$fn.
                         '&versiontwo=priv'.
-                        '">'.&mt('Diffs with current Version').'</a>');
+                        '">'.&mt('Diffs with current Version').'</a></td>');
            }
-           $r->print('</td></tr></table><p>'.
+           $r->print('</tr></table><p>'.
            '<font size=+1 color=red>'.
 &mt('Retrieval of an old version will overwrite the file currently in construction space').'</font><p>'.
            '<input type=submit value="'.&mt('Retrieve version').'"></form>');
@@ -126,14 +140,21 @@
         } else {
             $r->print('<h3>'.&mt('Retrieving old version').' '.$version.'</h3>');
         }
+	my ($main,$suffix,$is_meta) = &get_file_info($fn);
+
         my $logfile;
         my $ctarget='/home/'.$uname.'/public_html'.$fn;
         my $vfn=$fn;
         if ($version ne 'new') {
-	    $vfn=~s/\.(\w+)$/\.$version\.$1/;
+	    $vfn=~s/\.(\Q$suffix\E)$/\.$version\.$1/;
         }
+
         my $csource=$r->dir_config('lonDocRoot').'/res/'.$udom.'/'.$uname.$vfn;
-        unless ($logfile=Apache::File->new('>>'.$ctarget.'.log')) {
+
+	my $logname = $ctarget;
+	if ($is_meta) { $logname =~ s/\.meta$//; }
+	$logname = $ctarget.'.log';
+        unless ($logfile=Apache::File->new('>>'.$logname)) {
 	  $r->print(
          '<font color=red>'.&mt('No write permission to user directory, FAIL').'</font>');
         }
@@ -141,7 +162,7 @@
 "\n\n================= Retrieve ".localtime()." ================\n".
 "Version: $version\nSource: $csource\nTarget: $ctarget\n";
         $r->print('<p>'.&mt('Copying file').': ');
-        if (copy($csource,$ctarget)) {
+	if (copy($csource,$ctarget)) {
 	    $r->print('ok<p>');
             print $logfile "Copied sucessfully.\n\n";
         } else {
@@ -158,6 +179,18 @@
     }
 }
 
+sub get_file_info {
+    my ($fn) = @_;
+    my ($main,$suffix) = ($fn=~/\/([^\/]+)\.(\w+)$/);
+    my $is_meta=0;
+    if ($suffix eq 'meta') {
+	$is_meta = 1;
+	($main,$suffix) = ($main=~/(.+)\.(\w+)$/);	    
+	$suffix .= '.meta';
+    }
+    return ($main,$suffix,$is_meta);
+}
+
 # ---------------------------------------------------------------- Main Handler
 sub handler {
 

--albertel1158183808--