forked from nextcloud/notes
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotesHooks.php
78 lines (69 loc) · 1.73 KB
/
NotesHooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace OCA\Notes;
use OCA\Notes\Service\MetaService;
use OCP\ILogger;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
class NotesHooks {
private $logger;
private $rootFolder;
private $metaService;
public function __construct(
ILogger $logger,
IRootFolder $rootFolder,
MetaService $metaService
) {
$this->logger = $logger;
$this->rootFolder = $rootFolder;
$this->metaService = $metaService;
}
public function register() : void {
$this->listenTo(
$this->rootFolder,
'\OC\Files',
'preWrite',
function (Node $node) {
// $this->logger->warning('preWrite: ' . $node->getPath(), ['app'=>'notes']);
$this->onFileModified($node);
}
);
$this->listenTo(
$this->rootFolder,
'\OC\Files',
'preTouch',
function (Node $node) {
// $this->logger->warning('preTouch: ' . $node->getPath(), ['app'=>'notes']);
$this->onFileModified($node);
}
);
$this->listenTo(
$this->rootFolder,
'\OC\Files',
'preDelete',
function (Node $node) {
// $this->logger->warning('preDelete: ' . $node->getPath(), ['app'=>'notes']);
$this->onFileModified($node);
}
);
$this->listenTo(
$this->rootFolder,
'\OC\Files',
'preRename',
function (Node $source, Node $target) {
// $this->logger->warning('preRename: ' . $source->getPath(), ['app'=>'notes']);
$this->onFileModified($source);
}
);
}
private function listenTo($service, string $scope, string $method, callable $callback) : void {
/* @phan-suppress-next-line PhanUndeclaredMethod */
$service->listen($scope, $method, $callback);
}
private function onFileModified(Node $node) : void {
try {
$this->metaService->deleteByNote($node->getId());
} catch (\Throwable $e) {
}
}
}