nextcloud/apps/files_versions/lib/hooks.php

74 lines
1.7 KiB
PHP
Raw Normal View History

<?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.
*/
2012-09-07 16:10:43 +04:00
namespace OCA\Files_Versions;
class Hooks {
/**
* listen to write event.
*/
public static function write_hook( $params ) {
2012-09-07 16:10:43 +04:00
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
2012-09-07 16:10:43 +04:00
2012-10-10 15:18:36 +04:00
$versions = new Storage( new \OC\Files\View('') );
2012-09-07 16:10:43 +04:00
2012-10-10 15:18:36 +04:00
$path = $params[\OC\Files\Filesystem::signal_param_path];
2012-09-07 16:10:43 +04:00
if($path<>'') $versions->store( $path );
2012-09-07 16:10:43 +04:00
}
}
2012-09-07 16:10:43 +04:00
/**
* @brief Erase versions of deleted file
* @param array
*
* This function is connected to the delete signal of OC_Filesystem
* cleanup the versions directory if the actual file gets deleted
*/
public static function remove_hook($params) {
2013-01-28 23:04:10 +04:00
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
$versions = new Storage( new \OC_FilesystemView('') );
$path = $params[\OC\Files\Filesystem::signal_param_path];
if($path<>'') $versions->delete( $path );
}
2012-09-07 16:10:43 +04:00
}
/**
* @brief rename/move versions of renamed/moved files
* @param array with oldpath and newpath
*
* This function is connected to the rename signal of OC_Filesystem and adjust the name and location
* of the stored versions along the actual file
*/
public static function rename_hook($params) {
2013-01-28 23:04:10 +04:00
if(\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
$versions = new Storage( new \OC_FilesystemView('') );
$oldpath = $params['oldpath'];
2013-01-28 23:04:10 +04:00
$newpath = $params['newpath'];
if($oldpath<>'' && $newpath<>'') $versions->rename( $oldpath, $newpath );
2012-09-07 16:10:43 +04:00
}
}
}