diff options
author | Sam Tuke <samtuke@owncloud.com> | 2012-05-16 14:56:37 +0100 |
---|---|---|
committer | Sam Tuke <samtuke@owncloud.com> | 2012-05-16 14:59:00 +0100 |
commit | 0a46ae4f6dd1f4294f4e90c6049b24bd594226a7 (patch) | |
tree | 483f9733a07c78842c8b7d5dc6982eb21e80706a | |
parent | a00c5ac78ccbd581ba043d173d3f85aaf21b03dd (diff) | |
download | nextcloud-server-0a46ae4f6dd1f4294f4e90c6049b24bd594226a7.tar.gz nextcloud-server-0a46ae4f6dd1f4294f4e90c6049b24bd594226a7.zip |
added recognition of which version is 'current' - which is currently live and in use on history page
-rwxr-xr-x | apps/files_versions/history.php | 4 | ||||
-rwxr-xr-x | apps/files_versions/templates/history.php | 6 | ||||
-rwxr-xr-x | apps/files_versions/versions.php | 69 |
3 files changed, 59 insertions, 20 deletions
diff --git a/apps/files_versions/history.php b/apps/files_versions/history.php index 4306e416400..7c03ef0e5e1 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 6ef996049f5..891a3720e41 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 ' <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 />'; } diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php index 082dfbf7fd0..75a0e1a213c 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() ); + } } |