wwwision/node-event-log

事件源内容存储库中节点的日志

0.3.0 2023-02-17 11:11 UTC

This package is auto-updated.

Last update: 2024-09-17 14:45:46 UTC


README

事件源内容存储库中节点的日志

安装

通过 Composer 安装

composer require wwwision/node-event-log

之后,请确保执行 doctrine 迁移

./flow doctrine:migrate

EventLogProjector 已注册为 "ContentRepository" 事件存储的事件监听器,并且每当发布新事件时都会更新。

要使用已发布的事件初始化投影器,可以使用 projection:replay 命令

./flow projection:replay eventlog

用法

过滤

事件日志可以根据多个属性进行过滤,包括

  • 受影响的 节点(递归或不递归)
  • 内容流(或 工作空间名称
  • 发起用户
  • 维度空间点

示例

$recursively = true;
$filter = EventLogFilter::create()
    ->forNode(NodeAggregateIdentifier::fromString('some-node-id'), $recursively)
    ->inContentStream(ContentStreamIdentifier::fromString('some-content-stream-id'))
    ->forInitiatingUser(UserIdentifier::fromString('some-user-id'))
    ->skipInheritedEvents();

渲染前 5 种事件类型

$result = $this->eventLog->filter(EventLogFilter::create());
echo 'Total number of results: ' . $result->count() . PHP_EOL;
/** @var NodeEvent $event */
foreach ($result->first(5)->toNodeArray() as $event) {
    echo $event->eventType() . PHP_EOL;
}

输出(取决于实际事件)

Total number of results: 123
Neos.EventSourcedContentRepository:RootNodeAggregateWithNodeWasCreated
Neos.EventSourcedContentRepository:NodeAggregateWithNodeWasCreated
Neos.EventSourcedContentRepository:NodeAggregateWithNodeWasCreated
Neos.EventSourcedContentRepository:NodeAggregateWithNodeWasCreated
Neos.EventSourcedContentRepository:NodePropertiesWereSet

按降序分页显示结果

$result = $this->eventLog->filter(EventLogFilter::create())->reversed();
$after = null;
do {
    $page = $result->first(3, $after);
    foreach ($page as $edge) {
        /** @var NodeEvent $event */
        $event = $edge->node();
        echo $event->id() . PHP_EOL;
    }
    echo '----' . PHP_EOL;
    $after = $page->pageInfo()->endCursor();
} while ($page->pageInfo()->hasNextPage());

输出(取决于实际事件)

8
7
6
----
5
4
3
----
2
1
----

自定义事件渲染器

$result = $this->eventLog->filter(EventLogFilter::create())
    ->withNodeConverter(fn(array $event) => $event['id']);
echo implode(',', $result->first(10)->toNodeArray());

输出

1,2,3,4,5,6,7,8,9,10

命令行界面

此包包含一个 nodeeventlog:show 命令,允许在命令行中过滤和渲染事件日志

./flow help nodeeventlog:show

Output activities with the specified filters applied

COMMAND:
  wwwision.nodeeventlog:nodeeventlog:show

USAGE:
  ./flow nodeeventlog:show [<options>]

OPTIONS:
  --node               id of the node to fetch activities for
                       (NodeAggregateIdentifier)
  --content-stream     id of the content stream to filter for
                       (ContentStreamIdentifier)
  --workspace          name of the workspace to filter for (WorkspaceName)
  --user               id of the initiating user to filter for (UserIdentifier)
  --dimension          JSON string representing the dimensions space point to
                       filter for (DimensionSpacePoint)
  --recursively        If set activities for all child nodes will be fetched as
                       well (recursively) – this is only evaluated if
                       "--node" is specified, too
  --skip-inherited-events If set only explicit events are considered. Otherwise
                       "inherited" events, e.g. for disabled/removed/moved
                       nodes are included in the result
  --reverse            If set the order of the event log is reversed to show
                       the events in the order they occured
  --first              How many events to display at once (default: 10)
  --after              Only fetch events after the specified cursor (only
                       applicable in conjunction with --first)
  --last               How many events to display at once (default: 10)
  --before             Only fetch events before the specified cursor (only
                       applicable in conjunction with --first)

归属

本包的开发得到了 "Swiss Army Knife Cloud Solutions B.V." 的慷慨支持