summaryrefslogtreecommitdiffstats
path: root/apps/files_versions
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-06-04 23:02:05 +0200
committerBart Visscher <bartv@thisnet.nl>2012-06-04 23:02:05 +0200
commit4a5973662c78eb5769e7b06d7d559572f57e663f (patch)
tree774e2f775b3789f5f40bd2459ddec05df1b73c31 /apps/files_versions
parent786325a4bb976d92de54c472c2c3bd8a73cbef22 (diff)
parent3fee3a4633e5d4d65f7eabf2d387e209efedbc70 (diff)
downloadnextcloud-server-4a5973662c78eb5769e7b06d7d559572f57e663f.tar.gz
nextcloud-server-4a5973662c78eb5769e7b06d7d559572f57e663f.zip
Merge branch 'unstable'
Conflicts: apps/files_external/tests/config.php apps/files_versions/ajax/getVersions.php apps/files_versions/appinfo/app.php apps/files_versions/history.php apps/files_versions/js/versions.js apps/files_versions/templates/history.php apps/files_versions/versions.php lib/base.php
Diffstat (limited to 'apps/files_versions')
-rw-r--r--apps/files_versions/ajax/getVersions.php9
-rw-r--r--apps/files_versions/history.php2
-rw-r--r--apps/files_versions/js/versions.js2
-rw-r--r--apps/files_versions/templates/history.php6
-rw-r--r--apps/files_versions/versions.php185
5 files changed, 159 insertions, 45 deletions
diff --git a/apps/files_versions/ajax/getVersions.php b/apps/files_versions/ajax/getVersions.php
index 1d107c1bda0..bee60543339 100644
--- a/apps/files_versions/ajax/getVersions.php
+++ b/apps/files_versions/ajax/getVersions.php
@@ -10,7 +10,14 @@ $source = strip_tags( $source );
if( OCA_Versions\Storage::isversioned( $source ) ) {
$count=5; //show the newest revisions
- $versions = OCA_Versions\Storage::getversions( $source, $count);
+ $versions = OCA_Versions\Storage::getVersions( $source, $count);
+ $versionsFormatted = array();
+
+ foreach ( $versions AS $version ) {
+
+ $versionsFormatted[] = OCP\Util::formatDate( $version );
+
+ }
$versionsSorted = array_reverse( $versions );
diff --git a/apps/files_versions/history.php b/apps/files_versions/history.php
index 11c07ef86ce..cb4726e8d0e 100644
--- a/apps/files_versions/history.php
+++ b/apps/files_versions/history.php
@@ -54,7 +54,7 @@ if ( isset( $_GET['path'] ) ) {
if( OCA_Versions\Storage::isversioned( $path ) ) {
$count = 999; //show the newest revisions
- $versions = OCA_Versions\Storage::getversions( $path, $count );
+ $versions = OCA_Versions\Storage::getVersions( $path, $count);
$tmpl->assign( 'versions', array_reverse( $versions ) );
diff --git a/apps/files_versions/js/versions.js b/apps/files_versions/js/versions.js
index 5e46b2a0eed..82d569fa0f6 100644
--- a/apps/files_versions/js/versions.js
+++ b/apps/files_versions/js/versions.js
@@ -33,7 +33,7 @@ $(document).ready(function(){
});
function createVersionsDropdown(filename, files) {
-
+
var historyUrl = OC.linkTo('files_versions', 'history.php') + '?path='+encodeURIComponent( $( '#dir' ).val() ).replace( /%2F/g, '/' )+'/'+encodeURIComponent( filename );
var html = '<div id="dropdown" class="drop" data-file="'+files+'">';
diff --git a/apps/files_versions/templates/history.php b/apps/files_versions/templates/history.php
index 58fea75a0d0..13e104152b7 100644
--- 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="'.OCP\Util::linkTo('files_versions', 'history.php').'?path='.urlencode( $_['path'] ).'&revert='. $v .'" class="button">Revert</a><br /><br />';
+ echo OCP\Util::formatDate( $v['version'] );
+ echo ' <a href="'.OCP\Util::linkTo('files_versions', 'history.php').'?path='.urlencode( $_['path'] ).'&revert='. $v['version'] .'" class="button">Revert</a><br /><br />';
+ 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 f39b5a7f4eb..bc579014659 100644
--- a/apps/files_versions/versions.php
+++ b/apps/files_versions/versions.php
@@ -27,7 +27,6 @@ class Storage {
//
// todo:
// - port to oc_filesystem to enable network transparency
- // - check if it works well together with encryption
// - implement expire all function. And find a place to call it ;-)
// - add transparent compression. first test if it´s worth it.
@@ -35,7 +34,7 @@ class Storage {
const DEFAULTFOLDER='versions';
const DEFAULTBLACKLIST='avi mp3 mpg mp4 ctmp';
const DEFAULTMAXFILESIZE=1048576; // 10MB
- const DEFAULTMININTERVAL=120; // 2 min
+ const DEFAULTMININTERVAL=1; // 2 min
const DEFAULTMAXVERSIONS=50;
/**
@@ -76,7 +75,7 @@ class Storage {
} else {
$uid = \OCP\User::getUser();
}
- $versionsfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
+ $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
$filesfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/files';
Storage::init();
@@ -103,7 +102,7 @@ class Storage {
// check mininterval if the file is being modified by the owner (all shared files should be versioned despite mininterval)
if ($uid == \OCP\User::getUser()) {
- $matches=glob($versionsfoldername.'/'.$filename.'.v*');
+ $matches=glob($versionsFolderName.'/'.$filename.'.v*');
sort($matches);
$parts=explode('.v',end($matches));
if((end($parts)+Storage::DEFAULTMININTERVAL)>time()){
@@ -114,12 +113,12 @@ class Storage {
// create all parent folders
$info=pathinfo($filename);
- if(!file_exists($versionsfoldername.'/'.$info['dirname'])) mkdir($versionsfoldername.'/'.$info['dirname'],0700,true);
+ if(!file_exists($versionsFolderName.'/'.$info['dirname'])) mkdir($versionsFolderName.'/'.$info['dirname'],0700,true);
// store a new version of a file
- copy($filesfoldername.'/'.$filename,$versionsfoldername.'/'.$filename.'.v'.time());
+ copy($filesfoldername.'/'.$filename,$versionsFolderName.'/'.$filename.'.v'.time());
- // expire old revisions
+ // expire old revisions if necessary
Storage::expire($filename);
}
}
@@ -138,12 +137,12 @@ class Storage {
} else {
$uid = \OCP\User::getUser();
}
- $versionsfoldername=\OCP\Config::getSystemValue('datadirectory').'/'.$uid .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
+ $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').'/'.$uid .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
$filesfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/files';
// rollback
- if ( @copy($versionsfoldername.'/'.$filename.'.v'.$revision,$filesfoldername.'/'.$filename) ) {
+ if ( @copy($versionsFolderName.'/'.$filename.'.v'.$revision,$filesfoldername.'/'.$filename) ) {
return true;
@@ -169,10 +168,10 @@ class Storage {
} else {
$uid = \OCP\User::getUser();
}
- $versionsfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
+ $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
// check for old versions
- $matches=glob($versionsfoldername.'/'.$filename.'.v*');
+ $matches=glob($versionsFolderName.'/'.$filename.'.v*');
if(count($matches)>1){
return true;
}else{
@@ -186,10 +185,15 @@ class Storage {
/**
- * get a list of old versions of a file.
+ * @brief get a list of all available versions of a file in descending chronological order
+ * @param $filename file to find versions of, relative to the user files dir
+ * @param $count number of versions to return
+ * @returns array
*/
- public static function getversions($filename,$count=0) {
- if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+ public static function getVersions( $filename, $count = 0 ) {
+
+ if( \OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' ) {
+
if (\OCP\App::isEnabled('files_sharing') && $source = \OC_Share::getSource('/'.\OCP\User::getUser().'/files'.$filename)) {
$pos = strpos($source, '/files', 1);
$uid = substr($source, 1, $pos - 1);
@@ -197,29 +201,65 @@ class Storage {
} else {
$uid = \OCP\User::getUser();
}
- $versionsfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/'.\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));
+ $versionsFolderName = \OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/'.\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').\OC_Filesystem::getRoot().'/'.$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() );
+
}
- }
+
+ }
@@ -228,6 +268,7 @@ class Storage {
*/
public static function expire($filename) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
+
if (\OCP\App::isEnabled('files_sharing') && $source = \OC_Share::getSource('/'.\OCP\User::getUser().'/files'.$filename)) {
$pos = strpos($source, '/files', 1);
$uid = substr($source, 1, $pos - 1);
@@ -235,28 +276,92 @@ class Storage {
} else {
$uid = \OCP\User::getUser();
}
- $versionsfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
+ $versionsFolderName=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/'.\OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
// check for old versions
- $matches=glob($versionsfoldername.'/'.$filename.'.v*');
- if(count($matches)>\OCP\Config::getSystemValue('files_versionmaxversions', Storage::DEFAULTMAXVERSIONS)){
- $numbertodelete=count($matches-\OCP\Config::getSystemValue('files_versionmaxversions', Storage::DEFAULTMAXVERSIONS));
+ $matches = glob( $versionsFolderName.'/'.$filename.'.v*' );
+
+ if( count( $matches ) > \OCP\Config::getSystemValue( 'files_versionmaxversions', Storage::DEFAULTMAXVERSIONS ) ) {
+
+ $numberToDelete = count( $matches-\OCP\Config::getSystemValue( 'files_versionmaxversions', Storage::DEFAULTMAXVERSIONS ) );
// delete old versions of a file
- $deleteitems=array_slice($matches,0,$numbertodelete);
- foreach($deleteitems as $de){
- unlink($versionsfoldername.'/'.$filename.'.v'.$de);
+ $deleteItems = array_slice( $matches, 0, $numberToDelete );
+
+ foreach( $deleteItems as $de ) {
+
+ unlink( $versionsFolderName.'/'.$filename.'.v'.$de );
+
}
}
}
}
/**
- * expire all old versions.
+ * @brief erase all old versions of all user files
+ * @return
*/
- public static function expireall($filename) {
- // todo this should go through all the versions directories and delete all the not needed files and not needed directories.
- // useful to be included in a cleanup cronjob.
+ public static function expireAll() {
+
+ function deleteAll($directory, $empty = false) {
+
+ if(substr($directory,-1) == "/") {
+ $directory = substr($directory,0,-1);
+ }
+
+ if(!file_exists($directory) || !is_dir($directory)) {
+
+ return false;
+
+ } elseif(!is_readable($directory)) {
+
+ return false;
+
+ } else {
+
+ $directoryHandle = opendir($directory);
+
+ while ($contents = readdir($directoryHandle)) {
+
+ if( $contents != '.' && $contents != '..') {
+
+ $path = $directory . "/" . $contents;
+
+ if( is_dir($path) ) {
+
+ deleteAll($path);
+
+ } else {
+
+ unlink($path);
+
+ }
+ }
+
+ }
+
+ closedir( $directoryHandle );
+
+ if( $empty == false ) {
+
+ if(!rmdir($directory)) {
+
+ return false;
+
+ }
+
+ }
+
+ return true;
+ }
+
+ }
+
+ // FIXME: make this path dynamic
+ $dir = '/home/samtuke/owncloud/git/oc5/data/admin/versions';
+
+ ( deleteAll( $dir, 1 ) ? return true : return false );
+
}