diff --git a/apps/files_versions/history.php b/apps/files_versions/history.php index 4306e41640..7c03ef0e5e 100755 --- a/apps/files_versions/history.php +++ b/apps/files_versions/history.php @@ -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 ) ); diff --git a/apps/files_versions/templates/history.php b/apps/files_versions/templates/history.php index 6ef996049f..891a3720e4 100755 --- a/apps/files_versions/templates/history.php +++ b/apps/files_versions/templates/history.php @@ -22,8 +22,10 @@ if( isset( $_['message'] ) ) { foreach ( $_['versions'] as $v ) { echo ' '; - echo OCP\Util::formatDate( $v ); - echo ' Revert

'; + echo OCP\Util::formatDate( $v['version'] ); + echo ' Revert'; + if ( $v['cur'] ) { echo ' (Current)'; } + echo '

'; } diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php index 082dfbf7fd..75a0e1a213 100755 --- a/apps/files_versions/versions.php +++ b/apps/files_versions/versions.php @@ -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() ); + } }