Completed
Branch master (3adcdb)
by Raffael
08:09 queued 04:17
created

Hook   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 5
dl 0
loc 99
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A postCreateCollection() 0 7 1
A postCreateFile() 0 7 1
A postDeleteCollection() 0 11 2
A postDeleteFile() 0 12 2
C postSaveNodeAttributes() 0 23 8
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