Moved hooks and versions.php into new lib directory

Part-ported filesystem operations to OC_FilesystemView
Refactored Storage class to depend on an OC_FsV object and have fewer static classes
This commit is contained in:
Sam Tuke 2012-07-03 17:42:51 +01:00
parent ca2b1f7863
commit a775deaf22
6 changed files with 381 additions and 338 deletions

View File

@ -28,7 +28,9 @@
OCP\JSON::checkLoggedIn();
OCP\App::checkAppEnabled('files_versions');
if( OCA_Versions\Storage::expireAll() ){
$versions = new OCA_Versions\Storage( new OC_FilesystemView('') );
if( $versions->expireAll() ){
OCP\JSON::success();
die();

View File

@ -1,8 +1,6 @@
<?php
OCP\JSON::checkAppEnabled('files_versions');
require_once('apps/files_versions/versions.php');
$userDirectory = "/".OCP\USER::getUser()."/files";
$source = $_GET['source'];

View File

@ -1,6 +1,8 @@
<?php
require_once('files_versions/versions.php');
//require_once('files_versions/versions.php');
OC::$CLASSPATH['OCA_Versions\Storage'] = 'apps/files_versions/lib/versions.php';
OC::$CLASSPATH['OCA_Versions\Hooks'] = 'apps/files_versions/lib/hooks.php';
OCP\App::registerAdmin('files_versions', 'settings');
OCP\App::registerPersonal('files_versions','settings-personal');
@ -8,7 +10,7 @@ OCP\App::registerPersonal('files_versions','settings-personal');
OCP\Util::addscript('files_versions', 'versions');
// Listen to write signals
OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Storage", "write_hook");
OCP\Util::connectHook('OC_Filesystem', 'post_write', "OCA_Versions\Hooks", "write_hook");
// Listen to delete and rename signals
OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA_Versions\Storage", "removeVersions");
OCP\Util::connectHook('OC_Filesystem', 'rename', "OCA_Versions\Storage", "renameVersions");

View File

@ -30,11 +30,12 @@ if ( isset( $_GET['path'] ) ) {
$path = $_GET['path'];
$path = strip_tags( $path );
$tmpl->assign( 'path', $path );
$versions = new OCA_Versions\Storage( new OC_FilesystemView('') );
// roll back to old version if button clicked
if( isset( $_GET['revert'] ) ) {
if( \OCA_Versions\Storage::rollback( $path, $_GET['revert'] ) ) {
if( $versions->rollback( $path, $_GET['revert'] ) ) {
$tmpl->assign( 'outcome_stat', 'success' );

View File

@ -0,0 +1,35 @@
<?php
/**
* Copyright (c) 2012 Sam Tuke <samtuke@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
/**
* This class contains all hooks.
*/
namespace OCA_Versions;
class Hooks {
/**
* listen to write event.
*/
public static function write_hook( $params ) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
$versions = new Storage( new \OC_FilesystemView('') );
$path = $params[\OC_Filesystem::signal_param_path];
if($path<>'') $versions->store( $path );
}
}
}
?>

View File

@ -26,8 +26,7 @@ class Storage {
// - files_versionmaxversions
//
// todo:
// - port to oc_filesystem to enable network transparency
// - implement expire all function. And find a place to call it ;-)
// - finish porting to OC_FilesystemView to enable network transparency
// - add transparent compression. first test if it´s worth it.
const DEFAULTENABLED=true;
@ -37,6 +36,14 @@ class Storage {
const DEFAULTMININTERVAL=1; // 2 min
const DEFAULTMAXVERSIONS=50;
private $view;
function __construct( $view ) {
$this->view = $view;
}
/**
* init the versioning and create the versions folder.
*/
@ -57,7 +64,7 @@ class Storage {
public static function write_hook($params) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
$path = $params[\OC_Filesystem::signal_param_path];
if($path<>'') Storage::store($path);
if($path<>'') $this->store($path);
}
}
@ -66,7 +73,7 @@ class Storage {
/**
* store a new version of a file.
*/
public static function store($filename) {
public function store($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);
@ -119,7 +126,7 @@ class Storage {
copy($filesfoldername.'/'.$filename,$versionsFolderName.'/'.$filename.'.v'.time());
// expire old revisions if necessary
Storage::expire($filename);
$this->expire($filename);
}
}
@ -127,7 +134,7 @@ class Storage {
/**
* rollback to an old version of a file.
*/
public static function rollback($filename,$revision) {
public function rollback( $filename, $revision ) {
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
if (\OCP\App::isEnabled('files_sharing') && $source = \OC_Share::getSource('/'.\OCP\User::getUser().'/files'.$filename)) {
@ -142,11 +149,11 @@ class Storage {
$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;
}else{
} else {
return false;
@ -264,7 +271,7 @@ class Storage {
/**
* @brief Erase a file's versions which exceed the set quota
*/
public static function expire($filename) {
public 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)) {
@ -288,7 +295,7 @@ class Storage {
foreach( $deleteItems as $de ) {
unlink( $versionsFolderName.'/'.$filename.'.v'.$de );
$this->view->unlink( $versionsFolderName.'/'.$filename.'.v'.$de );
}
}
@ -299,13 +306,11 @@ class Storage {
* @brief Erase all old versions of all user files
* @return true/false
*/
public static function expireAll() {
$view = new \OC_FilesystemView('');
public function expireAll() {
$dir = \OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
return $view->deleteAll( $dir, true );
return $this->view->deleteAll( $dir, true );
}
@ -322,7 +327,7 @@ class Storage {
if(Storage::isversioned($rel_path)) {
$versions = Storage::getVersions($rel_path);
foreach ($versions as $v){
unlink($abs_path . $v['version']);
$this->view->unlink( $abs_path . $v['version'] );
}
}
}