Hey there, again
I try to listen to file reads by connecting via the method described in the post title, inspired by how Joas Schilling did it in his files_downloadactivity app:
Application.php
public function __construct(array $urlParams = array()) {
parent::__construct('hyperlog', $urlParams);
$container = $this->getContainer();
$this->registerHooks();
}
private function registerHooks() {
$this->getContainer()->query('SessionHooks')->register();
$this->getContainer()->query('FileHooks')->register();
// read-hook (for logging downloads)
Util::connectHook('OC_Filesystem', 'read', $this, 'listenReadFile');
}
public function listenReadFile($params) {
/** @var Listener $hooks */
$hooks = $this->getContainer()->query(Listener::class);
$hooks->readFile($params['path']);
}
Listener.php
<?php
namespace OCA\HyperLog\Activity;
use OCA\HyperLog\Service\LogService;
use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\IUser;
class Listener {
protected $rootFolder;
protected $request;
protected $user;
protected $logService;
public function __construct(IRootFolder $rootFolder, IRequest $request, IUser $user, LogService $logService) {
$this->rootFolder = $rootFolder;
$this->request = $request;
$this->user = $user;
$this->logService = $logService;
$this->logService->log('Listener instantiated');
}
public function readFile($path) {
$this->logService->log(sprintf('File %s read', $path));
}
}
Nothing is being logged and Listener
doesn't seem to get instantiated. Am I missing something? I thought instantiation would happen automatically.
Any help appreciated.
Best regards,
Constantin