|
64 | 64 | (new Audit()) |
65 | 65 | ->group(null) |
66 | 66 | ->register('cache_cleared') |
67 | | - ->listen(ClearingCache::class, 'cache_cleared', fn () => []), |
| 67 | + ->listen(ClearingCache::class, 'cache_cleared', function () { |
| 68 | + return []; |
| 69 | + }), |
68 | 70 |
|
69 | 71 | (new Audit()) |
70 | 72 | ->group(null) |
71 | 73 | ->register('extension.disabled', 'extension.enabled', 'extension.uninstalled') |
72 | | - ->listen(ExtensionEvent\Disabled::class, 'extension.disabled', fn ($e) => ['package' => $e->extension->name]) |
73 | | - ->listen(ExtensionEvent\Enabled::class, 'extension.enabled', fn ($e) => ['package' => $e->extension->name]) |
74 | | - ->listen(ExtensionEvent\Uninstalled::class, 'extension.uninstalled', fn ($e) => ['package' => $e->extension->name]), |
| 74 | + ->listen(ExtensionEvent\Disabled::class, 'extension.disabled', function ($e) { |
| 75 | + return ['package' => $e->extension->name]; |
| 76 | + }) |
| 77 | + ->listen(ExtensionEvent\Enabled::class, 'extension.enabled', function ($e) { |
| 78 | + return ['package' => $e->extension->name]; |
| 79 | + }) |
| 80 | + ->listen(ExtensionEvent\Uninstalled::class, 'extension.uninstalled', function ($e) { |
| 81 | + return ['package' => $e->extension->name]; |
| 82 | + }), |
75 | 83 |
|
76 | 84 | (new Audit()) |
77 | 85 | ->group(null) |
78 | 86 | ->register('discussion.created', 'discussion.deleted', 'discussion.hidden', 'discussion.renamed', 'discussion.restored') |
79 | | - ->listen(DiscussionEvent\Started::class, 'discussion.created', fn ($e) => ['discussion_id' => $e->discussion->id]) |
80 | | - ->listen(DiscussionEvent\Deleted::class, 'discussion.deleted', fn ($e) => ['discussion_id' => $e->discussion->id]) |
81 | | - ->listen(DiscussionEvent\Hidden::class, 'discussion.hidden', fn ($e) => ['discussion_id' => $e->discussion->id]) |
82 | | - ->listen(DiscussionEvent\Restored::class, 'discussion.restored', fn ($e) => ['discussion_id' => $e->discussion->id]) |
83 | | - ->listen(DiscussionEvent\Renamed::class, 'discussion.renamed', fn ($e) => [ |
84 | | - 'discussion_id' => $e->discussion->id, |
85 | | - 'old_title' => $e->oldTitle, |
86 | | - 'new_title' => $e->discussion->title, |
87 | | - ]), |
| 87 | + ->listen(DiscussionEvent\Started::class, 'discussion.created', function ($e) { |
| 88 | + return ['discussion_id' => $e->discussion->id]; |
| 89 | + }) |
| 90 | + ->listen(DiscussionEvent\Deleted::class, 'discussion.deleted', function ($e) { |
| 91 | + return ['discussion_id' => $e->discussion->id]; |
| 92 | + }) |
| 93 | + ->listen(DiscussionEvent\Hidden::class, 'discussion.hidden', function ($e) { |
| 94 | + return ['discussion_id' => $e->discussion->id]; |
| 95 | + }) |
| 96 | + ->listen(DiscussionEvent\Restored::class, 'discussion.restored', function ($e) { |
| 97 | + return ['discussion_id' => $e->discussion->id]; |
| 98 | + }) |
| 99 | + ->listen(DiscussionEvent\Renamed::class, 'discussion.renamed', function ($e) { |
| 100 | + return [ |
| 101 | + 'discussion_id' => $e->discussion->id, |
| 102 | + 'old_title' => $e->oldTitle, |
| 103 | + 'new_title' => $e->discussion->title, |
| 104 | + ]; |
| 105 | + }), |
88 | 106 |
|
89 | 107 | (new Audit()) |
90 | 108 | ->group(null) |
91 | 109 | ->register('post.created', 'post.deleted', 'post.hidden', 'post.restored', 'post.revised') |
92 | | - ->listen(PostEvent\Deleted::class, 'post.deleted', fn ($e) => ['discussion_id' => $e->post->discussion->id, 'post_id' => $e->post->id]) |
93 | | - ->listen(PostEvent\Hidden::class, 'post.hidden', fn ($e) => ['discussion_id' => $e->post->discussion->id, 'post_id' => $e->post->id]) |
94 | | - ->listen(PostEvent\Restored::class, 'post.restored', fn ($e) => ['discussion_id' => $e->post->discussion->id, 'post_id' => $e->post->id]) |
95 | | - ->listen(PostEvent\Revised::class, 'post.revised', fn ($e) => ['discussion_id' => $e->post->discussion->id, 'post_id' => $e->post->id]) |
| 110 | + ->listen(PostEvent\Deleted::class, 'post.deleted', function ($e) { |
| 111 | + return ['discussion_id' => $e->post->discussion->id, 'post_id' => $e->post->id]; |
| 112 | + }) |
| 113 | + ->listen(PostEvent\Hidden::class, 'post.hidden', function ($e) { |
| 114 | + return ['discussion_id' => $e->post->discussion->id, 'post_id' => $e->post->id]; |
| 115 | + }) |
| 116 | + ->listen(PostEvent\Restored::class, 'post.restored', function ($e) { |
| 117 | + return ['discussion_id' => $e->post->discussion->id, 'post_id' => $e->post->id]; |
| 118 | + }) |
| 119 | + ->listen(PostEvent\Revised::class, 'post.revised', function ($e) { |
| 120 | + return ['discussion_id' => $e->post->discussion->id, 'post_id' => $e->post->id]; |
| 121 | + }) |
96 | 122 | // Not logging the first post. There's always going to be one created alongside the discussion. |
97 | | - ->listen(PostEvent\Posted::class, 'post.created', fn ($e) => $e->post->number === 1 ? null : ['discussion_id' => $e->post->discussion->id, 'post_id' => $e->post->id]), |
| 123 | + ->listen(PostEvent\Posted::class, 'post.created', function ($e) { |
| 124 | + return $e->post->number === 1 ? null : ['discussion_id' => $e->post->discussion->id, 'post_id' => $e->post->id]; |
| 125 | + }), |
98 | 126 |
|
99 | 127 | (new Audit()) |
100 | 128 | ->group(null) |
|
109 | 137 | // settings — when the relevant extension is actually active. |
110 | 138 |
|
111 | 139 | (new Extend\Conditional()) |
112 | | - ->whenExtensionEnabled('flarum-approval', fn () => [ |
113 | | - (new Audit()) |
114 | | - ->group('flarum-approval') |
115 | | - ->listen(ApprovalEvent\PostWasApproved::class, 'post.approved', fn ($e) => [ |
116 | | - 'discussion_id' => $e->post->discussion->id, |
117 | | - 'post_id' => $e->post->id, |
118 | | - ]), |
119 | | - ]) |
120 | | - ->whenExtensionEnabled('flarum-flags', fn () => [ |
121 | | - (new Audit()) |
122 | | - ->group('flarum-flags') |
123 | | - ->using(new Integration\FlagsIntegration()), |
124 | | - ]) |
125 | | - ->whenExtensionEnabled('flarum-lock', fn () => [ |
126 | | - (new Audit()) |
127 | | - ->group('flarum-lock') |
128 | | - ->listen(LockEvent\DiscussionWasLocked::class, 'discussion.locked', fn ($e) => ['discussion_id' => $e->discussion->id]) |
129 | | - ->listen(LockEvent\DiscussionWasUnlocked::class, 'discussion.unlocked', fn ($e) => ['discussion_id' => $e->discussion->id]), |
130 | | - ]) |
131 | | - ->whenExtensionEnabled('flarum-nicknames', fn () => [ |
132 | | - (new Audit()) |
133 | | - ->group('flarum-nicknames') |
134 | | - ->using(new Integration\NicknamesIntegration()), |
135 | | - ]) |
136 | | - ->whenExtensionEnabled('flarum-sticky', fn () => [ |
137 | | - (new Audit()) |
138 | | - ->group('flarum-sticky') |
139 | | - ->listen(StickyEvent\DiscussionWasStickied::class, 'discussion.stickied', fn ($e) => ['discussion_id' => $e->discussion->id]) |
140 | | - ->listen(StickyEvent\DiscussionWasUnstickied::class, 'discussion.unstickied', fn ($e) => ['discussion_id' => $e->discussion->id]), |
141 | | - ]) |
142 | | - ->whenExtensionEnabled('flarum-suspend', fn () => [ |
143 | | - (new Audit()) |
144 | | - ->group('flarum-suspend') |
145 | | - ->listen(SuspendEvent\Suspended::class, 'user.suspended', fn ($e) => array_merge( |
146 | | - ['user_id' => $e->user->id], |
147 | | - $e->user->suspended_until ? ['until' => $e->user->suspended_until->toIso8601String()] : [] |
148 | | - )) |
149 | | - ->listen(SuspendEvent\Unsuspended::class, 'user.unsuspended', fn ($e) => ['user_id' => $e->user->id]), |
150 | | - ]) |
151 | | - ->whenExtensionEnabled('flarum-tags', fn () => [ |
152 | | - (new Audit()) |
153 | | - ->group('flarum-tags') |
154 | | - ->listen(TagsEvent\DiscussionWasTagged::class, 'discussion.tagged', fn ($e) => [ |
155 | | - 'discussion_id' => $e->discussion->id, |
156 | | - 'old_tags' => \Illuminate\Support\Arr::pluck($e->oldTags, 'slug'), |
157 | | - // Can't use pre-loaded ->tags because of https://github.com/flarum/core/issues/2514 |
158 | | - 'new_tags' => $e->discussion->tags()->pluck('tags.slug')->all(), |
159 | | - ]) |
160 | | - ->using(new Integration\TagsAdminIntegration()), |
161 | | - ]), |
| 140 | + ->whenExtensionEnabled('flarum-approval', function () { |
| 141 | + return [ |
| 142 | + (new Audit()) |
| 143 | + ->group('flarum-approval') |
| 144 | + ->listen(ApprovalEvent\PostWasApproved::class, 'post.approved', function ($e) { |
| 145 | + return [ |
| 146 | + 'discussion_id' => $e->post->discussion->id, |
| 147 | + 'post_id' => $e->post->id, |
| 148 | + ]; |
| 149 | + }), |
| 150 | + ]; |
| 151 | + }) |
| 152 | + ->whenExtensionEnabled('flarum-flags', function () { |
| 153 | + return [ |
| 154 | + (new Audit()) |
| 155 | + ->group('flarum-flags') |
| 156 | + ->using(new Integration\FlagsIntegration()), |
| 157 | + ]; |
| 158 | + }) |
| 159 | + ->whenExtensionEnabled('flarum-lock', function () { |
| 160 | + return [ |
| 161 | + (new Audit()) |
| 162 | + ->group('flarum-lock') |
| 163 | + ->listen(LockEvent\DiscussionWasLocked::class, 'discussion.locked', function ($e) { |
| 164 | + return ['discussion_id' => $e->discussion->id]; |
| 165 | + }) |
| 166 | + ->listen(LockEvent\DiscussionWasUnlocked::class, 'discussion.unlocked', function ($e) { |
| 167 | + return ['discussion_id' => $e->discussion->id]; |
| 168 | + }), |
| 169 | + ]; |
| 170 | + }) |
| 171 | + ->whenExtensionEnabled('flarum-nicknames', function () { |
| 172 | + return [ |
| 173 | + (new Audit()) |
| 174 | + ->group('flarum-nicknames') |
| 175 | + ->using(new Integration\NicknamesIntegration()), |
| 176 | + ]; |
| 177 | + }) |
| 178 | + ->whenExtensionEnabled('flarum-sticky', function () { |
| 179 | + return [ |
| 180 | + (new Audit()) |
| 181 | + ->group('flarum-sticky') |
| 182 | + ->listen(StickyEvent\DiscussionWasStickied::class, 'discussion.stickied', function ($e) { |
| 183 | + return ['discussion_id' => $e->discussion->id]; |
| 184 | + }) |
| 185 | + ->listen(StickyEvent\DiscussionWasUnstickied::class, 'discussion.unstickied', function ($e) { |
| 186 | + return ['discussion_id' => $e->discussion->id]; |
| 187 | + }), |
| 188 | + ]; |
| 189 | + }) |
| 190 | + ->whenExtensionEnabled('flarum-suspend', function () { |
| 191 | + return [ |
| 192 | + (new Audit()) |
| 193 | + ->group('flarum-suspend') |
| 194 | + ->listen(SuspendEvent\Suspended::class, 'user.suspended', function ($e) { |
| 195 | + return array_merge( |
| 196 | + ['user_id' => $e->user->id], |
| 197 | + $e->user->suspended_until ? ['until' => $e->user->suspended_until->toIso8601String()] : [] |
| 198 | + ); |
| 199 | + }) |
| 200 | + ->listen(SuspendEvent\Unsuspended::class, 'user.unsuspended', function ($e) { |
| 201 | + return ['user_id' => $e->user->id]; |
| 202 | + }), |
| 203 | + ]; |
| 204 | + }) |
| 205 | + ->whenExtensionEnabled('flarum-tags', function () { |
| 206 | + return [ |
| 207 | + (new Audit()) |
| 208 | + ->group('flarum-tags') |
| 209 | + ->listen(TagsEvent\DiscussionWasTagged::class, 'discussion.tagged', function ($e) { |
| 210 | + return [ |
| 211 | + 'discussion_id' => $e->discussion->id, |
| 212 | + 'old_tags' => \Illuminate\Support\Arr::pluck($e->oldTags, 'slug'), |
| 213 | + // Can't use pre-loaded ->tags because of https://github.com/flarum/core/issues/2514 |
| 214 | + 'new_tags' => $e->discussion->tags()->pluck('tags.slug')->all(), |
| 215 | + ]; |
| 216 | + }) |
| 217 | + ->using(new Integration\TagsAdminIntegration()), |
| 218 | + ]; |
| 219 | + }), |
162 | 220 |
|
163 | 221 | // Search. |
164 | 222 |
|
|
0 commit comments