1
|
|
|
<?php |
2
|
|
|
namespace AE\History\Domain\Repository; |
3
|
|
|
|
4
|
|
|
use Neos\Flow\Annotations as Flow; |
5
|
|
|
use Neos\Flow\Persistence\QueryResultInterface; |
6
|
|
|
use Neos\Neos\EventLog\Domain\Model\NodeEvent; |
7
|
|
|
use Neos\Neos\EventLog\Domain\Repository\EventRepository; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* The repository for events |
11
|
|
|
* |
12
|
|
|
* @Flow\Scope("singleton") |
13
|
|
|
*/ |
14
|
|
|
class NodeEventRepository extends EventRepository |
15
|
|
|
{ |
16
|
|
|
const ENTITY_CLASSNAME = NodeEvent::class; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Find all events which are "top-level" and in a given workspace (or are not NodeEvents) |
20
|
|
|
* |
21
|
|
|
* @param int $offset |
22
|
|
|
* @param int $limit |
23
|
|
|
* @param string $workspaceName |
24
|
|
|
* @param string|null $siteIdentifier |
25
|
|
|
* @param string|null $nodeIdentifier |
26
|
|
|
* @param string|null $accountIdentifier |
27
|
|
|
* |
28
|
|
|
* @return QueryResultInterface |
29
|
|
|
*/ |
30
|
|
|
public function findRelevantEventsByWorkspace( |
31
|
|
|
$offset, |
32
|
|
|
$limit, |
33
|
|
|
$workspaceName, |
34
|
|
|
string $siteIdentifier = null, |
35
|
|
|
string $nodeIdentifier = null, |
36
|
|
|
string $accountIdentifier = null |
37
|
|
|
) : QueryResultInterface { |
38
|
|
|
$query = $this->prepareRelevantEventsQuery(); |
39
|
|
|
$queryBuilder = $query->getQueryBuilder(); |
40
|
|
|
$queryBuilder |
41
|
|
|
->andWhere('e.workspaceName = :workspaceName AND e.eventType = :eventType') |
42
|
|
|
->setParameter('workspaceName', $workspaceName) |
43
|
|
|
->setParameter('eventType', 'Node.Published') |
44
|
|
|
; |
45
|
|
|
if ($siteIdentifier !== null) { |
46
|
|
|
$siteCondition = '%' . trim(json_encode(['site' => $siteIdentifier], JSON_PRETTY_PRINT), "{}\n\t ") . '%'; |
47
|
|
|
$queryBuilder |
48
|
|
|
->andWhere('NEOSCR_TOSTRING(e.data) LIKE :site') |
49
|
|
|
->setParameter('site', $siteCondition) |
50
|
|
|
; |
51
|
|
|
} |
52
|
|
|
if ($nodeIdentifier !== null) { |
53
|
|
|
$queryBuilder |
54
|
|
|
->andWhere('e.nodeIdentifier = :nodeIdentifier') |
55
|
|
|
->setParameter('nodeIdentifier', $nodeIdentifier) |
56
|
|
|
; |
57
|
|
|
} |
58
|
|
|
if ($accountIdentifier !== null) { |
59
|
|
|
$queryBuilder |
60
|
|
|
->andWhere('e.accountIdentifier = :accountIdentifier') |
61
|
|
|
->setParameter('accountIdentifier', $accountIdentifier) |
62
|
|
|
; |
63
|
|
|
} |
64
|
|
|
$queryBuilder->setFirstResult($offset); |
65
|
|
|
$queryBuilder->setMaxResults($limit); |
66
|
|
|
|
67
|
|
|
return $query->execute(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Find all account identifiers that modified a specific site |
72
|
|
|
* |
73
|
|
|
* @param string $workspaceName |
74
|
|
|
* @param string|null $siteIdentifier |
75
|
|
|
* @param string|null $nodeIdentifier |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
|
|
public function findAccountIdentifiers( |
80
|
|
|
string $workspaceName, |
81
|
|
|
string $siteIdentifier = null, |
82
|
|
|
string $nodeIdentifier = null |
83
|
|
|
) : array { |
84
|
|
|
$query = $this->prepareRelevantEventsQuery(); |
85
|
|
|
$queryBuilder = $query->getQueryBuilder(); |
86
|
|
|
$queryBuilder |
87
|
|
|
->andWhere('e.workspaceName = :workspaceName AND e.eventType = :eventType') |
88
|
|
|
->setParameter('workspaceName', $workspaceName) |
89
|
|
|
->setParameter('eventType', 'Node.Published') |
90
|
|
|
; |
91
|
|
|
if ($siteIdentifier !== null) { |
92
|
|
|
$siteCondition = '%' . trim(json_encode(['site' => $siteIdentifier], JSON_PRETTY_PRINT), "{}\n\t ") . '%'; |
93
|
|
|
$queryBuilder |
94
|
|
|
->andWhere('NEOSCR_TOSTRING(e.data) LIKE :site') |
95
|
|
|
->setParameter('site', $siteCondition) |
96
|
|
|
; |
97
|
|
|
} |
98
|
|
|
if ($nodeIdentifier !== null) { |
99
|
|
|
$queryBuilder |
100
|
|
|
->andWhere('e.nodeIdentifier = :nodeIdentifier') |
101
|
|
|
->setParameter('nodeIdentifier', $nodeIdentifier) |
102
|
|
|
; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$queryBuilder->groupBy('e.accountIdentifier'); |
106
|
|
|
$queryBuilder->orderBy(null); |
107
|
|
|
|
108
|
|
|
$dql = str_replace('SELECT e', 'SELECT e.accountIdentifier', rtrim($queryBuilder->getDql(), ' ORDER BY ')); |
109
|
|
|
|
110
|
|
|
$dqlQuery = $this->createDqlQuery($dql); |
111
|
|
|
$dqlQuery->setParameters($query->getParameters()); |
112
|
|
|
|
113
|
|
|
return array_map(function($result) { |
114
|
|
|
return $result['accountIdentifier']; |
115
|
|
|
}, $dqlQuery->execute()); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|