diff --git a/apps/files_versions/ajax/getVersions.php b/apps/files_versions/ajax/getVersions.php index 8476e5e8a5..600e69cf79 100644 --- a/apps/files_versions/ajax/getVersions.php +++ b/apps/files_versions/ajax/getVersions.php @@ -4,10 +4,9 @@ OCP\JSON::checkAppEnabled('files_versions'); $userDirectory = "/".OCP\USER::getUser()."/files"; $source = $_GET['source']; -if( OCA_Versions\Storage::isversioned( $source ) ) { +$count = 5; //show the newest revisions +if( ($versions = OCA_Versions\Storage::getVersions( $source, $count)) ) { - $count=5; //show the newest revisions - $versions = OCA_Versions\Storage::getVersions( $source, $count); $versionsFormatted = array(); foreach ( $versions AS $version ) { diff --git a/apps/files_versions/ajax/rollbackVersion.php b/apps/files_versions/ajax/rollbackVersion.php index f1b02eb4b9..f2c211d9c1 100644 --- a/apps/files_versions/ajax/rollbackVersion.php +++ b/apps/files_versions/ajax/rollbackVersion.php @@ -8,10 +8,9 @@ $userDirectory = "/".OCP\USER::getUser()."/files"; $file = $_GET['file']; $revision=(int)$_GET['revision']; -if( OCA_Versions\Storage::isversioned( $file ) ) { - if(OCA_Versions\Storage::rollback( $file, $revision )) { - OCP\JSON::success(array("data" => array( "revision" => $revision, "file" => $file ))); - }else{ - OCP\JSON::error(array("data" => array( "message" => "Could not revert:" . $file ))); - } +if(OCA_Versions\Storage::rollback( $file, $revision )) { + OCP\JSON::success(array("data" => array( "revision" => $revision, "file" => $file ))); +}else{ + OCP\JSON::error(array("data" => array( "message" => "Could not revert:" . $file ))); } + diff --git a/apps/files_versions/history.php b/apps/files_versions/history.php index d4c278ebd8..6e27f43d57 100644 --- a/apps/files_versions/history.php +++ b/apps/files_versions/history.php @@ -52,10 +52,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 + if( ($versions = OCA_Versions\Storage::getVersions( $path, $count)) ) { $tmpl->assign( 'versions', array_reverse( $versions ) ); diff --git a/apps/files_versions/lib/hooks.php b/apps/files_versions/lib/hooks.php index 736d9cd868..5fb9dc3c3c 100644 --- a/apps/files_versions/lib/hooks.php +++ b/apps/files_versions/lib/hooks.php @@ -58,18 +58,16 @@ class Hooks { * of the stored versions along the actual file */ public static function rename_hook($params) { - $versions_fileview = \OCP\Files::getStorage('files_versions'); - $rel_oldpath = $params['oldpath']; - $abs_oldpath = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$rel_oldpath.'.v'; - $abs_newpath = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$params['newpath'].'.v'; - if(Storage::isversioned($rel_oldpath)) { - $info=pathinfo($abs_newpath); - if(!file_exists($info['dirname'])) mkdir($info['dirname'], 0750, true); - $versions = Storage::getVersions($rel_oldpath); - foreach ($versions as $v) { - rename($abs_oldpath.$v['version'], $abs_newpath.$v['version']); - } + if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { + + $versions = new Storage( new \OC_FilesystemView('') ); + + $oldpath = $params['oldpath']; + $newpath = $params['newpath']; + + if($oldpath<>'' && $newpath<>'') $versions->rename( $oldpath, $newpath ); + } } - + } diff --git a/apps/files_versions/lib/versions.php b/apps/files_versions/lib/versions.php index 7b5f4755b2..23aa1319ff 100644 --- a/apps/files_versions/lib/versions.php +++ b/apps/files_versions/lib/versions.php @@ -19,7 +19,8 @@ class Storage { const DEFAULTENABLED=true; const DEFAULTMAXSIZE=50; // unit: percentage; 50% of available disk space/quota - private static $max_versions_per_interval = array(1 => array('intervalEndsAfter' => 10, //first 10sec, one version every 2sec + private static $max_versions_per_interval = array( + 1 => array('intervalEndsAfter' => 10, //first 10sec, one version every 2sec 'step' => 2), 2 => array('intervalEndsAfter' => 60, //next minute, one version every 10sec 'step' => 10), @@ -106,8 +107,7 @@ class Storage { $versions_fileview = new \OC_FilesystemView('/'.$uid .'/files_versions'); $abs_path = \OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath('').$filename.'.v'; - if(Storage::isversioned($filename)) { - $versions = self::getVersions($filename); + if( ($versions = self::getVersions($filename)) ) { if ( ($versionsSize = \OCP\Config::getAppValue('files_versions', 'size')) === null ) { $versionsSize = self::calculateSize($uid); } @@ -119,6 +119,30 @@ class Storage { } } + /** + * Delete versions of a file + */ + public static function rename($oldpath, $newpath) { + error_log("oldpath: $oldpath"); + error_log("newpath: $newpath"); + list($uid, $oldpath) = self::getUidAndFilename($oldpath); + list($uidn, $newpath) = self::getUidAndFilename($newpath); + $versions_view = new \OC_FilesystemView('/'.$uid .'/files_versions'); + $files_view = new \OC_FilesystemView('/'.$uid .'/files'); + + if ( $files_view->is_dir($oldpath) && $versions_view->is_dir($oldpath) ) { + $versions_view->rename($oldpath, $newpath); + } else if ( ($versions = Storage::getVersions($oldpath)) ) { + $info=pathinfo($abs_newpath); + if(!file_exists($info['dirname'])) mkdir($info['dirname'], 0750, true); + $versions = Storage::getVersions($oldpath); + foreach ($versions as $v) { + error_log("rename(".$oldpath.'.v'.$v['version'].", ". $newpath.'.v'.$v['version'].")"); + $versions_view->rename($oldpath.'.v'.$v['version'], $newpath.'.v'.$v['version']); + } + } + } + /** * rollback to an old version of a file. */ @@ -129,9 +153,10 @@ class Storage { $users_view = new \OC_FilesystemView('/'.$uid); //first create a new version - if ( !$users_view->file_exists('files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename))) { - $version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename); + $version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename); + if ( !$users_view->file_exists($version)) { $users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename)); + $versionCreated = true; } // rollback @@ -140,39 +165,14 @@ class Storage { Storage::expire($filename); return true; - }else{ - if (isset($version) ) { - $users_view->unlink($version); - return false; - } + }else if ( $versionCreated ) { + $users_view->unlink($version); } } + return false; } - /** - * check if old versions of a file exist. - */ - public static function isversioned($filename) { - if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') { - list($uid, $filename) = self::getUidAndFilename($filename); - $versions_fileview = new \OC_FilesystemView('/'.$uid.'/files_versions'); - - $versionsName=\OCP\Config::getSystemValue('datadirectory').$versions_fileview->getAbsolutePath($filename); - - // check for old versions - $matches=glob($versionsName.'.v*'); - if(count($matches)>0) { - return true; - }else{ - return false; - } - }else{ - return(false); - } - } - - /** * @brief get a list of all available versions of a file in descending chronological order @@ -391,7 +391,7 @@ class Storage { for ($i=1; $i<$numOfVersions; $i++) { if ( $nextInterval == -1 || $versions[$i]['version'] >= $nextInterval ) { if ( $versions[$i]['version'] > $nextVersion ) { - //distance between two version to small, delete version + //distance between two version too small, delete version $versions_fileview->unlink($versions[$i]['path'].'.v'.$versions[$i]['version']); $availableSpace += $versions[$i]['size']; $versionsSize -= $versions[$i]['size'];