1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* balloon |
7
|
|
|
* |
8
|
|
|
* @copyright Copryright (c) 2012-2018 gyselroth GmbH (https://gyselroth.com) |
9
|
|
|
* @license GPL-3.0 https://opensource.org/licenses/GPL-3.0 |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Balloon\App\Elasticsearch; |
13
|
|
|
|
14
|
|
|
use Balloon\Filesystem\Node\Collection; |
15
|
|
|
use Balloon\Filesystem\Node\File; |
16
|
|
|
use Balloon\Filesystem\Node\NodeInterface; |
17
|
|
|
use Balloon\Hook\AbstractHook; |
18
|
|
|
use TaskScheduler\Async; |
19
|
|
|
|
20
|
|
|
class Hook extends AbstractHook |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Async. |
24
|
|
|
* |
25
|
|
|
* @var Async |
26
|
|
|
*/ |
27
|
|
|
protected $async; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Constructor. |
31
|
|
|
* |
32
|
|
|
* @param Async $async |
33
|
|
|
*/ |
34
|
|
|
public function __construct(Async $async) |
35
|
|
|
{ |
36
|
|
|
$this->async = $async; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function postCreateCollection(Collection $parent, Collection $node, bool $clone): void |
43
|
|
|
{ |
44
|
|
|
$this->async->addJob(Job::class, [ |
45
|
|
|
'id' => $node->getId(), |
46
|
|
|
'action' => Job::ACTION_CREATE, |
47
|
|
|
]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
|
|
public function postCreateFile(Collection $parent, File $node, bool $clone): void |
54
|
|
|
{ |
55
|
|
|
$this->async->addJob(Job::class, [ |
56
|
|
|
'id' => $node->getId(), |
57
|
|
|
'action' => Job::ACTION_CREATE, |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function postDeleteCollection(Collection $node, bool $force, ?string $recursion, bool $recursion_first): void |
65
|
|
|
{ |
66
|
|
|
if (false === $force) { |
67
|
|
|
return; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$this->async->addJob(Job::class, [ |
71
|
|
|
'id' => $node->getId(), |
72
|
|
|
'action' => Job::ACTION_DELETE_COLLECTION, |
73
|
|
|
]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritdoc} |
78
|
|
|
*/ |
79
|
|
|
public function postDeleteFile(File $node, bool $force, ?string $recursion, bool $recursion_first): void |
80
|
|
|
{ |
81
|
|
|
if (false === $force) { |
82
|
|
|
return; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
$this->async->addJob(Job::class, [ |
86
|
|
|
'id' => $node->getId(), |
87
|
|
|
'action' => Job::ACTION_DELETE_FILE, |
88
|
|
|
'hash' => $node->getHash(), |
89
|
|
|
]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritdoc} |
94
|
|
|
*/ |
95
|
|
|
public function postSaveNodeAttributes(NodeInterface $node, array $attributes, array $remove, ?string $recursion, bool $recursion_first): void |
96
|
|
|
{ |
97
|
|
|
if ($node instanceof Collection) { |
98
|
|
|
$raw = $node->getRawAttributes(); |
99
|
|
|
if ($node->isShared() && !isset($raw['acl'])) { |
100
|
|
|
$this->async->addJob(Job::class, [ |
101
|
|
|
'id' => $node->getId(), |
102
|
|
|
'action' => Job::ACTION_ADD_SHARE, |
103
|
|
|
]); |
104
|
|
|
} elseif (!$node->isShared() && isset($raw['acl']) && $raw['acl'] !== []) { |
105
|
|
|
$this->async->addJob(Job::class, [ |
106
|
|
|
'id' => $node->getId(), |
107
|
|
|
'action' => Job::ACTION_DELETE_SHARE, |
108
|
|
|
]); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$this->async->addJob(Job::class, [ |
113
|
|
|
'id' => $node->getId(), |
114
|
|
|
'action' => Job::ACTION_UPDATE, |
115
|
|
|
'hash' => ($node instanceof File) ? $node->getRawAttributes()['hash'] : null, |
116
|
|
|
]); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|