2015-05-12 20:08:04 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2015 Vincent Petry <pvince81@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test;
|
|
|
|
|
|
|
|
use OC\Files\Filesystem;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper class to register hooks on
|
|
|
|
*/
|
|
|
|
class HookHelper {
|
|
|
|
public static $hookCalls;
|
|
|
|
|
|
|
|
public static function setUpHooks() {
|
|
|
|
self::clear();
|
|
|
|
\OCP\Util::connectHook(
|
|
|
|
Filesystem::CLASSNAME,
|
|
|
|
Filesystem::signal_create,
|
|
|
|
'\Test\HookHelper',
|
|
|
|
'createCallback'
|
|
|
|
);
|
|
|
|
\OCP\Util::connectHook(
|
|
|
|
Filesystem::CLASSNAME,
|
|
|
|
Filesystem::signal_update,
|
|
|
|
'\Test\HookHelper',
|
|
|
|
'updateCallback'
|
|
|
|
);
|
|
|
|
\OCP\Util::connectHook(
|
|
|
|
Filesystem::CLASSNAME,
|
|
|
|
Filesystem::signal_write,
|
|
|
|
'\Test\HookHelper',
|
|
|
|
'writeCallback'
|
|
|
|
);
|
|
|
|
|
|
|
|
\OCP\Util::connectHook(
|
|
|
|
Filesystem::CLASSNAME,
|
|
|
|
Filesystem::signal_post_create,
|
|
|
|
'\Test\HookHelper',
|
|
|
|
'postCreateCallback'
|
|
|
|
);
|
|
|
|
\OCP\Util::connectHook(
|
|
|
|
Filesystem::CLASSNAME,
|
|
|
|
Filesystem::signal_post_update,
|
|
|
|
'\Test\HookHelper',
|
|
|
|
'postUpdateCallback'
|
|
|
|
);
|
|
|
|
\OCP\Util::connectHook(
|
|
|
|
Filesystem::CLASSNAME,
|
|
|
|
Filesystem::signal_post_write,
|
|
|
|
'\Test\HookHelper',
|
|
|
|
'postWriteCallback'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function clear() {
|
|
|
|
self::$hookCalls = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function createCallback($params) {
|
2020-03-26 11:30:18 +03:00
|
|
|
self::$hookCalls[] = [
|
2015-05-12 20:08:04 +03:00
|
|
|
'signal' => Filesystem::signal_create,
|
|
|
|
'params' => $params
|
2020-03-26 11:30:18 +03:00
|
|
|
];
|
2015-05-12 20:08:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function updateCallback($params) {
|
2020-03-26 11:30:18 +03:00
|
|
|
self::$hookCalls[] = [
|
2015-05-12 20:08:04 +03:00
|
|
|
'signal' => Filesystem::signal_update,
|
|
|
|
'params' => $params
|
2020-03-26 11:30:18 +03:00
|
|
|
];
|
2015-05-12 20:08:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function writeCallback($params) {
|
2020-03-26 11:30:18 +03:00
|
|
|
self::$hookCalls[] = [
|
2015-05-12 20:08:04 +03:00
|
|
|
'signal' => Filesystem::signal_write,
|
|
|
|
'params' => $params
|
2020-03-26 11:30:18 +03:00
|
|
|
];
|
2015-05-12 20:08:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function postCreateCallback($params) {
|
2020-03-26 11:30:18 +03:00
|
|
|
self::$hookCalls[] = [
|
2015-05-12 20:08:04 +03:00
|
|
|
'signal' => Filesystem::signal_post_create,
|
|
|
|
'params' => $params
|
2020-03-26 11:30:18 +03:00
|
|
|
];
|
2015-05-12 20:08:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function postUpdateCallback($params) {
|
2020-03-26 11:30:18 +03:00
|
|
|
self::$hookCalls[] = [
|
2015-05-12 20:08:04 +03:00
|
|
|
'signal' => Filesystem::signal_post_update,
|
|
|
|
'params' => $params
|
2020-03-26 11:30:18 +03:00
|
|
|
];
|
2015-05-12 20:08:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function postWriteCallback($params) {
|
2020-03-26 11:30:18 +03:00
|
|
|
self::$hookCalls[] = [
|
2015-05-12 20:08:04 +03:00
|
|
|
'signal' => Filesystem::signal_post_write,
|
|
|
|
'params' => $params
|
2020-03-26 11:30:18 +03:00
|
|
|
];
|
2015-05-12 20:08:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-04-06 13:14:52 +03:00
|
|
|
* Callback that sets the run parameter to false
|
2015-05-12 20:08:04 +03:00
|
|
|
*/
|
|
|
|
public static function cancellingCallback($params) {
|
|
|
|
$params[Filesystem::signal_param_run] = false;
|
|
|
|
}
|
|
|
|
}
|