|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Locastic\Loggastic\DataProvider; |
|
4
|
|
|
|
|
5
|
|
|
use Locastic\Loggastic\Bridge\Elasticsearch\Context\ElasticsearchContextFactoryInterface; |
|
6
|
|
|
use Locastic\Loggastic\Bridge\Elasticsearch\ElasticsearchService; |
|
7
|
|
|
use Locastic\Loggastic\Model\Output\ActivityLog; |
|
8
|
|
|
use Locastic\Loggastic\Model\Output\CurrentDataTracker; |
|
9
|
|
|
|
|
10
|
|
|
final class ActivityLogProvider implements ActivityLogProviderInterface |
|
11
|
|
|
{ |
|
12
|
|
|
public function __construct( |
|
13
|
|
|
private readonly ElasticsearchService $elasticsearchService, |
|
14
|
|
|
private readonly ElasticsearchContextFactoryInterface $elasticsearchContextFactory |
|
15
|
|
|
) { } |
|
16
|
|
|
|
|
17
|
|
|
public function getActivityLogsByClass(string $className, array $sort = [], int $limit = 20, int $offset = 0): array |
|
18
|
|
|
{ |
|
19
|
|
|
$elasticContext = $this->elasticsearchContextFactory->create($className); |
|
20
|
|
|
|
|
21
|
|
|
$body = [ |
|
22
|
|
|
'sort' => $sort, |
|
23
|
|
|
]; |
|
24
|
|
|
|
|
25
|
|
|
// todo move class to config |
|
26
|
|
|
return $this->elasticsearchService->getCollection( |
|
27
|
|
|
$elasticContext->getActivityLogIndex(), |
|
28
|
|
|
ActivityLog::class, |
|
29
|
|
|
$body, |
|
30
|
|
|
$limit, |
|
31
|
|
|
$offset |
|
32
|
|
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getCurrentDataTrackerByClassAndId(string $className, $objectId): ?array |
|
36
|
|
|
{ |
|
37
|
|
|
$elasticContext = $this->elasticsearchContextFactory->create($className); |
|
38
|
|
|
|
|
39
|
|
|
$body = [ |
|
40
|
|
|
'query' => ['term' => ['objectId' => $objectId]], |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
// todo move class to config |
|
44
|
|
|
return $this->elasticsearchService->getItemByQuery( |
|
45
|
|
|
$elasticContext->getCurrentDataTrackerIndex(), |
|
46
|
|
|
CurrentDataTracker::class, |
|
47
|
|
|
$body |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getActivityLogsByClassAndId( |
|
52
|
|
|
string $className, |
|
53
|
|
|
mixed $objectId, |
|
54
|
|
|
array $sort = [], |
|
55
|
|
|
int $limit = 20, |
|
56
|
|
|
int $offset = 0 |
|
57
|
|
|
): array { |
|
58
|
|
|
$elasticContext = $this->elasticsearchContextFactory->create($className); |
|
59
|
|
|
|
|
60
|
|
|
$body = [ |
|
61
|
|
|
'sort' => $sort, |
|
62
|
|
|
'query' => [ |
|
63
|
|
|
'term' => ['objectId' => $objectId], |
|
64
|
|
|
], |
|
65
|
|
|
]; |
|
66
|
|
|
|
|
67
|
|
|
// todo move class to config |
|
68
|
|
|
return $this->elasticsearchService->getCollection( |
|
69
|
|
|
$elasticContext->getActivityLogIndex(), |
|
70
|
|
|
ActivityLog::class, |
|
71
|
|
|
$body, |
|
72
|
|
|
$limit, |
|
73
|
|
|
$offset |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getActivityLogsByIndexAndId( |
|
78
|
|
|
string $index, |
|
79
|
|
|
$objectId, |
|
80
|
|
|
array $sort = [], |
|
81
|
|
|
int $limit = 20, |
|
82
|
|
|
int $offset = 0 |
|
83
|
|
|
): array { |
|
84
|
|
|
$body = [ |
|
85
|
|
|
'sort' => $sort, |
|
86
|
|
|
'query' => [ |
|
87
|
|
|
'term' => ['objectId' => $objectId], |
|
88
|
|
|
], |
|
89
|
|
|
]; |
|
90
|
|
|
|
|
91
|
|
|
// todo move class to config |
|
92
|
|
|
return $this->elasticsearchService->getCollection( |
|
93
|
|
|
$index, |
|
94
|
|
|
ActivityLog::class, |
|
95
|
|
|
$body, |
|
96
|
|
|
$limit, |
|
97
|
|
|
$offset |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|