added recognition of which version is 'current' - which is currently live and in use on history page

This commit is contained in:
Sam Tuke 2012-05-16 14:56:37 +01:00
parent a00c5ac78c
commit 0a46ae4f6d
3 changed files with 59 additions and 20 deletions

View File

@ -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 ) );

View File

@ -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 />';
}

View File

@ -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() );
}
}