2012-07-03 20:42:51 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Bart Visscher <bartv@thisnet.nl>
|
|
|
|
* @author Björn Schießle <schiessle@owncloud.com>
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Robin McCorkell <robin@mccorkell.me.uk>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Sam Tuke <mail@samtuke.com>
|
2015-10-05 21:54:56 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
2016-01-12 17:02:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2012-07-03 20:42:51 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class contains all hooks.
|
|
|
|
*/
|
|
|
|
|
2012-09-19 22:59:57 +04:00
|
|
|
namespace OCA\Files_Versions;
|
2012-07-03 20:42:51 +04:00
|
|
|
|
|
|
|
class Hooks {
|
|
|
|
|
2014-07-24 18:49:38 +04:00
|
|
|
public static function connectHooks() {
|
|
|
|
// Listen to write signals
|
2014-10-28 17:57:08 +03:00
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'write', 'OCA\Files_Versions\Hooks', 'write_hook');
|
2014-07-24 18:49:38 +04:00
|
|
|
// Listen to delete and rename signals
|
2014-10-28 17:57:08 +03:00
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'post_delete', 'OCA\Files_Versions\Hooks', 'remove_hook');
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'delete', 'OCA\Files_Versions\Hooks', 'pre_remove_hook');
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'post_rename', 'OCA\Files_Versions\Hooks', 'rename_hook');
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'post_copy', 'OCA\Files_Versions\Hooks', 'copy_hook');
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'rename', 'OCA\Files_Versions\Hooks', 'pre_renameOrCopy_hook');
|
|
|
|
\OCP\Util::connectHook('OC_Filesystem', 'copy', 'OCA\Files_Versions\Hooks', 'pre_renameOrCopy_hook');
|
2015-09-01 20:29:55 +03:00
|
|
|
|
|
|
|
$eventDispatcher = \OC::$server->getEventDispatcher();
|
|
|
|
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', ['OCA\Files_Versions\Hooks', 'onLoadFilesAppScripts']);
|
2014-07-24 18:49:38 +04:00
|
|
|
}
|
|
|
|
|
2012-07-03 20:42:51 +04:00
|
|
|
/**
|
|
|
|
* listen to write event.
|
|
|
|
*/
|
|
|
|
public static function write_hook( $params ) {
|
2012-09-07 16:10:43 +04:00
|
|
|
|
2013-07-30 14:19:01 +04:00
|
|
|
if (\OCP\App::isEnabled('files_versions')) {
|
2012-10-10 15:18:36 +04:00
|
|
|
$path = $params[\OC\Files\Filesystem::signal_param_path];
|
2013-02-10 17:17:18 +04:00
|
|
|
if($path<>'') {
|
|
|
|
Storage::store($path);
|
|
|
|
}
|
2012-07-03 20:42:51 +04:00
|
|
|
}
|
|
|
|
}
|
2012-07-09 18:07:26 +04:00
|
|
|
|
2012-09-07 16:10:43 +04:00
|
|
|
|
|
|
|
/**
|
2014-05-19 19:50:53 +04:00
|
|
|
* Erase versions of deleted file
|
2014-05-15 16:19:32 +04:00
|
|
|
* @param array $params
|
2012-09-07 16:10:43 +04:00
|
|
|
*
|
|
|
|
* This function is connected to the delete signal of OC_Filesystem
|
|
|
|
* cleanup the versions directory if the actual file gets deleted
|
|
|
|
*/
|
2012-07-09 18:51:16 +04:00
|
|
|
public static function remove_hook($params) {
|
2013-07-30 14:19:01 +04:00
|
|
|
|
|
|
|
if (\OCP\App::isEnabled('files_versions')) {
|
2013-01-28 23:04:10 +04:00
|
|
|
$path = $params[\OC\Files\Filesystem::signal_param_path];
|
2013-02-10 17:17:18 +04:00
|
|
|
if($path<>'') {
|
|
|
|
Storage::delete($path);
|
|
|
|
}
|
2013-01-28 23:04:10 +04:00
|
|
|
}
|
2012-09-07 16:10:43 +04:00
|
|
|
}
|
|
|
|
|
2013-11-28 16:17:19 +04:00
|
|
|
/**
|
2014-05-19 19:50:53 +04:00
|
|
|
* mark file as "deleted" so that we can clean up the versions if the file is gone
|
2013-11-28 16:17:19 +04:00
|
|
|
* @param array $params
|
|
|
|
*/
|
|
|
|
public static function pre_remove_hook($params) {
|
|
|
|
$path = $params[\OC\Files\Filesystem::signal_param_path];
|
|
|
|
if($path<>'') {
|
|
|
|
Storage::markDeletedFile($path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-07 16:10:43 +04:00
|
|
|
/**
|
2014-05-19 19:50:53 +04:00
|
|
|
* rename/move versions of renamed/moved files
|
2014-05-15 16:19:32 +04:00
|
|
|
* @param array $params array with oldpath and newpath
|
2012-09-07 16:10:43 +04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
2012-07-09 18:51:16 +04:00
|
|
|
public static function rename_hook($params) {
|
2013-11-28 16:17:19 +04:00
|
|
|
|
2013-07-30 14:19:01 +04:00
|
|
|
if (\OCP\App::isEnabled('files_versions')) {
|
2013-01-11 17:23:28 +04:00
|
|
|
$oldpath = $params['oldpath'];
|
2013-01-28 23:04:10 +04:00
|
|
|
$newpath = $params['newpath'];
|
2013-02-10 17:17:18 +04:00
|
|
|
if($oldpath<>'' && $newpath<>'') {
|
2014-07-24 17:30:00 +04:00
|
|
|
Storage::renameOrCopy($oldpath, $newpath, 'rename');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* copy versions of copied files
|
|
|
|
* @param array $params array with oldpath and newpath
|
|
|
|
*
|
|
|
|
* This function is connected to the copy signal of OC_Filesystem and copies the
|
|
|
|
* the stored versions to the new location
|
|
|
|
*/
|
|
|
|
public static function copy_hook($params) {
|
|
|
|
|
|
|
|
if (\OCP\App::isEnabled('files_versions')) {
|
|
|
|
$oldpath = $params['oldpath'];
|
|
|
|
$newpath = $params['newpath'];
|
|
|
|
if($oldpath<>'' && $newpath<>'') {
|
|
|
|
Storage::renameOrCopy($oldpath, $newpath, 'copy');
|
2013-02-10 17:17:18 +04:00
|
|
|
}
|
2012-09-07 16:10:43 +04:00
|
|
|
}
|
2012-07-05 13:35:08 +04:00
|
|
|
}
|
2013-02-22 20:21:57 +04:00
|
|
|
|
2014-10-28 17:57:08 +03:00
|
|
|
/**
|
|
|
|
* Remember owner and the owner path of the source file.
|
|
|
|
* If the file already exists, then it was a upload of a existing file
|
|
|
|
* over the web interface and we call Storage::store() directly
|
|
|
|
*
|
|
|
|
* @param array $params array with oldpath and newpath
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function pre_renameOrCopy_hook($params) {
|
|
|
|
if (\OCP\App::isEnabled('files_versions')) {
|
|
|
|
|
2014-10-31 18:42:54 +03:00
|
|
|
// if we rename a movable mount point, then the versions don't have
|
|
|
|
// to be renamed
|
|
|
|
$absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files' . $params['oldpath']);
|
|
|
|
$manager = \OC\Files\Filesystem::getMountManager();
|
|
|
|
$mount = $manager->find($absOldPath);
|
|
|
|
$internalPath = $mount->getInternalPath($absOldPath);
|
|
|
|
if ($internalPath === '' and $mount instanceof \OC\Files\Mount\MoveableMount) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-28 17:57:08 +03:00
|
|
|
$view = new \OC\Files\View(\OCP\User::getUser() . '/files');
|
|
|
|
if ($view->file_exists($params['newpath'])) {
|
|
|
|
Storage::store($params['newpath']);
|
|
|
|
} else {
|
|
|
|
Storage::setSourcePathAndUser($params['oldpath']);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-01 20:29:55 +03:00
|
|
|
/**
|
|
|
|
* Load additional scripts when the files app is visible
|
|
|
|
*/
|
|
|
|
public static function onLoadFilesAppScripts() {
|
|
|
|
\OCP\Util::addScript('files_versions', 'versionmodel');
|
|
|
|
\OCP\Util::addScript('files_versions', 'versioncollection');
|
|
|
|
\OCP\Util::addScript('files_versions', 'versionstabview');
|
|
|
|
\OCP\Util::addScript('files_versions', 'filesplugin');
|
|
|
|
}
|
2012-07-03 20:42:51 +04:00
|
|
|
}
|