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:
parent
ca2b1f7863
commit
a775deaf22
|
@ -28,7 +28,9 @@
|
||||||
OCP\JSON::checkLoggedIn();
|
OCP\JSON::checkLoggedIn();
|
||||||
OCP\App::checkAppEnabled('files_versions');
|
OCP\App::checkAppEnabled('files_versions');
|
||||||
|
|
||||||
if( OCA_Versions\Storage::expireAll() ){
|
$versions = new OCA_Versions\Storage( new OC_FilesystemView('') );
|
||||||
|
|
||||||
|
if( $versions->expireAll() ){
|
||||||
|
|
||||||
OCP\JSON::success();
|
OCP\JSON::success();
|
||||||
die();
|
die();
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
OCP\JSON::checkAppEnabled('files_versions');
|
OCP\JSON::checkAppEnabled('files_versions');
|
||||||
|
|
||||||
require_once('apps/files_versions/versions.php');
|
|
||||||
|
|
||||||
$userDirectory = "/".OCP\USER::getUser()."/files";
|
$userDirectory = "/".OCP\USER::getUser()."/files";
|
||||||
$source = $_GET['source'];
|
$source = $_GET['source'];
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
<?php
|
<?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::registerAdmin('files_versions', 'settings');
|
||||||
OCP\App::registerPersonal('files_versions','settings-personal');
|
OCP\App::registerPersonal('files_versions','settings-personal');
|
||||||
|
@ -8,7 +10,7 @@ OCP\App::registerPersonal('files_versions','settings-personal');
|
||||||
OCP\Util::addscript('files_versions', 'versions');
|
OCP\Util::addscript('files_versions', 'versions');
|
||||||
|
|
||||||
// Listen to write signals
|
// 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
|
// Listen to delete and rename signals
|
||||||
OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA_Versions\Storage", "removeVersions");
|
OCP\Util::connectHook('OC_Filesystem', 'delete', "OCA_Versions\Storage", "removeVersions");
|
||||||
OCP\Util::connectHook('OC_Filesystem', 'rename', "OCA_Versions\Storage", "renameVersions");
|
OCP\Util::connectHook('OC_Filesystem', 'rename', "OCA_Versions\Storage", "renameVersions");
|
|
@ -30,11 +30,12 @@ if ( isset( $_GET['path'] ) ) {
|
||||||
$path = $_GET['path'];
|
$path = $_GET['path'];
|
||||||
$path = strip_tags( $path );
|
$path = strip_tags( $path );
|
||||||
$tmpl->assign( 'path', $path );
|
$tmpl->assign( 'path', $path );
|
||||||
|
$versions = new OCA_Versions\Storage( new OC_FilesystemView('') );
|
||||||
|
|
||||||
// roll back to old version if button clicked
|
// roll back to old version if button clicked
|
||||||
if( isset( $_GET['revert'] ) ) {
|
if( isset( $_GET['revert'] ) ) {
|
||||||
|
|
||||||
if( \OCA_Versions\Storage::rollback( $path, $_GET['revert'] ) ) {
|
if( $versions->rollback( $path, $_GET['revert'] ) ) {
|
||||||
|
|
||||||
$tmpl->assign( 'outcome_stat', 'success' );
|
$tmpl->assign( 'outcome_stat', 'success' );
|
||||||
|
|
||||||
|
|
|
@ -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 );
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
|
@ -26,8 +26,7 @@ class Storage {
|
||||||
// - files_versionmaxversions
|
// - files_versionmaxversions
|
||||||
//
|
//
|
||||||
// todo:
|
// todo:
|
||||||
// - port to oc_filesystem to enable network transparency
|
// - finish porting to OC_FilesystemView to enable network transparency
|
||||||
// - implement expire all function. And find a place to call it ;-)
|
|
||||||
// - add transparent compression. first test if it´s worth it.
|
// - add transparent compression. first test if it´s worth it.
|
||||||
|
|
||||||
const DEFAULTENABLED=true;
|
const DEFAULTENABLED=true;
|
||||||
|
@ -37,6 +36,14 @@ class Storage {
|
||||||
const DEFAULTMININTERVAL=1; // 2 min
|
const DEFAULTMININTERVAL=1; // 2 min
|
||||||
const DEFAULTMAXVERSIONS=50;
|
const DEFAULTMAXVERSIONS=50;
|
||||||
|
|
||||||
|
private $view;
|
||||||
|
|
||||||
|
function __construct( $view ) {
|
||||||
|
|
||||||
|
$this->view = $view;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init the versioning and create the versions folder.
|
* init the versioning and create the versions folder.
|
||||||
*/
|
*/
|
||||||
|
@ -57,7 +64,7 @@ class Storage {
|
||||||
public static function write_hook($params) {
|
public static function write_hook($params) {
|
||||||
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
|
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
|
||||||
$path = $params[\OC_Filesystem::signal_param_path];
|
$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.
|
* 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\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
|
||||||
if (\OCP\App::isEnabled('files_sharing') && $source = \OC_Share::getSource('/'.\OCP\User::getUser().'/files'.$filename)) {
|
if (\OCP\App::isEnabled('files_sharing') && $source = \OC_Share::getSource('/'.\OCP\User::getUser().'/files'.$filename)) {
|
||||||
$pos = strpos($source, '/files', 1);
|
$pos = strpos($source, '/files', 1);
|
||||||
|
@ -119,7 +126,7 @@ class Storage {
|
||||||
copy($filesfoldername.'/'.$filename,$versionsFolderName.'/'.$filename.'.v'.time());
|
copy($filesfoldername.'/'.$filename,$versionsFolderName.'/'.$filename.'.v'.time());
|
||||||
|
|
||||||
// expire old revisions if necessary
|
// 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.
|
* 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\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
|
||||||
if (\OCP\App::isEnabled('files_sharing') && $source = \OC_Share::getSource('/'.\OCP\User::getUser().'/files'.$filename)) {
|
if (\OCP\App::isEnabled('files_sharing') && $source = \OC_Share::getSource('/'.\OCP\User::getUser().'/files'.$filename)) {
|
||||||
|
@ -142,7 +149,7 @@ class Storage {
|
||||||
$filesfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/files';
|
$filesfoldername=\OCP\Config::getSystemValue('datadirectory').'/'. $uid .'/files';
|
||||||
|
|
||||||
// rollback
|
// rollback
|
||||||
if ( @copy($versionsFolderName.'/'.$filename.'.v'.$revision,$filesfoldername.'/'.$filename) ) {
|
if ( copy( $versionsFolderName.'/'.$filename.'.v'.$revision, $filesfoldername.'/'.$filename ) ) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -264,7 +271,7 @@ class Storage {
|
||||||
/**
|
/**
|
||||||
* @brief Erase a file's versions which exceed the set quota
|
* @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\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
|
||||||
|
|
||||||
if (\OCP\App::isEnabled('files_sharing') && $source = \OC_Share::getSource('/'.\OCP\User::getUser().'/files'.$filename)) {
|
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 ) {
|
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
|
* @brief Erase all old versions of all user files
|
||||||
* @return true/false
|
* @return true/false
|
||||||
*/
|
*/
|
||||||
public static function expireAll() {
|
public function expireAll() {
|
||||||
|
|
||||||
$view = new \OC_FilesystemView('');
|
|
||||||
|
|
||||||
$dir = \OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
|
$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)) {
|
if(Storage::isversioned($rel_path)) {
|
||||||
$versions = Storage::getVersions($rel_path);
|
$versions = Storage::getVersions($rel_path);
|
||||||
foreach ($versions as $v){
|
foreach ($versions as $v){
|
||||||
unlink($abs_path . $v['version']);
|
$this->view->unlink( $abs_path . $v['version'] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue