]> source.dussan.org Git - nextcloud-server.git/commitdiff
added recognition of which version is 'current' - which is currently live and in...
authorSam Tuke <samtuke@owncloud.com>
Wed, 16 May 2012 13:56:37 +0000 (14:56 +0100)
committerSam Tuke <samtuke@owncloud.com>
Wed, 16 May 2012 14:00:36 +0000 (15:00 +0100)
apps/files_versions/history.php
apps/files_versions/templates/history.php
apps/files_versions/versions.php

index 4306e41640004b15186238bc7c91adb5bf92602e..7c03ef0e5e17ebcb2027599badcd7f573f7923fc 100755 (executable)
@@ -54,8 +54,8 @@ if ( isset( $_GET['path'] ) ) {
        // show the history only if there is something to show
         if( OCA_Versions\Storage::isversioned( $path ) ) {
        
-               $count=999; //show the newest revisions
-               $versions=OCA_Versions\Storage::getversions( $path, $count);
+               $count = 999; //show the newest revisions
+               $versions = OCA_Versions\Storage::getversions( $path, $count);
 
                $tmpl->assign( 'versions', array_reverse( $versions ) );
                
index 6ef996049f5e6694b913bfe451ca04c73ff48d53..891a3720e41381745144b63f3ff28d47b265b992 100755 (executable)
@@ -22,8 +22,10 @@ if( isset( $_['message'] ) ) {
        foreach ( $_['versions'] as $v ) {
        
                echo ' ';
-               echo OCP\Util::formatDate( $v );
-               echo ' <a href="history.php?path='.urlencode( $_['path'] ).'&revert='. $v .'" class="button">Revert</a><br /><br />';
+               echo OCP\Util::formatDate( $v['version'] );
+               echo ' <a href="history.php?path='.urlencode( $_['path'] ).'&revert='. $v['version'] .'" class="button">Revert</a>';
+               if ( $v['cur'] ) { echo '  (<b>Current</b>)'; }
+               echo '<br /><br />';
                
        }
 
index 082dfbf7fd07b4dbc5dd25a37395444bca1b24b2..75a0e1a213c17b67161c8c57bf0bae865a750283 100755 (executable)
@@ -35,7 +35,7 @@ class Storage {
        const DEFAULTFOLDER='versions'; 
        const DEFAULTBLACKLIST='avi mp3 mpg mp4'; 
        const DEFAULTMAXFILESIZE=1048576; // 10MB 
-       const DEFAULTMININTERVAL=120; // 2 min
+       const DEFAULTMININTERVAL=1; // 2 min
        const DEFAULTMAXVERSIONS=50; 
 
        /**
@@ -168,28 +168,65 @@ class Storage {
          * get a list of old versions of a file.
          */
         public static function getversions($filename,$count=0) {
-                if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
-                       $versionsfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
-                       $versions=array();         
-                     // fetch for old versions
-                       $matches=glob($versionsfoldername.$filename.'.v*');
-                       sort($matches);
-                       foreach($matches as $ma) {
-                               $parts=explode('.v',$ma);
-                               $versions[]=(end($parts));
+        
+                if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) {
+                
+                       $versionsfoldername = \OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
+                       $versions = array();         
+                       
+                       // fetch for old versions
+                       $matches = glob( $versionsfoldername.$filename.'.v*' );
+                       
+                       sort( $matches );
+                       
+                       $i = 0;
+                       
+                       foreach( $matches as $ma ) {
+                               
+                               $i++;
+                               $versions[$i]['cur'] = 0;
+                               $parts = explode( '.v',$ma );
+                               $versions[$i]['version'] = ( end( $parts ) );
+                               
+                               // if file with modified date exists, flag it in array as currently enabled version
+                               $curFile['fileName'] = basename( $parts[0] );
+                               $curFile['filePath'] = \OCP\Config::getSystemValue('datadirectory').'/'. \OCP\USER::getUser() .'/files/'.$curFile['fileName'];
+                               
+                               ( \md5_file( $ma ) == \md5_file( $curFile['filePath'] ) ? $versions[$i]['fileMatch'] = 1 : $versions[$i]['fileMatch'] = 0 );
+                               
                        }
                        
+                       $versions = array_reverse( $versions );
+                       
+                       foreach( $versions as $key => $value ) {
+                               
+                               // flag the first matched file in array (which will have latest modification date) as current version
+                               if ( $versions[$key]['fileMatch'] ) {
+                               
+                                       $versions[$key]['cur'] = 1;
+                                       break;
+                                       
+                               }
+                       
+                       }
+                       
+                       $versions = array_reverse( $versions );
+                       
                        // only show the newest commits
-                       if($count<>0 and (count($versions)>$count)) {
-                               $versions=array_slice($versions,count($versions)-$count);
+                       if( $count != 0 and ( count( $versions )>$count ) ) {
+                       
+                               $versions = array_slice( $versions, count( $versions ) - $count );
+                               
                        }
        
-                       return($versions);
+                       return( $versions );
 
 
-                }else{
-                        return(array());
+                } else {
+                
+                       // if versioning isn't enabled then return an empty array
+                        return( array() );
+                        
                 }
         }