Skip to content

Commit 898af92

Browse files
Revert "chore/refactor to strategy formatters (#468)"
This reverts commit 7e817d7.
1 parent cf5fd28 commit 898af92

17 files changed

Lines changed: 44 additions & 1182 deletions

app/Audit/AbstractAuditLogFormatter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,5 @@ final public function setContext(AuditContext $ctx): void
2424
$this->ctx = $ctx;
2525
}
2626

27-
protected function getUserInfo(): string
28-
{
29-
if (!$this->ctx) {
30-
return 'Unknown (unknown)';
31-
}
32-
33-
$user_name = 'Unknown';
34-
if ($this->ctx->userFirstName || $this->ctx->userLastName) {
35-
$user_name = trim(sprintf("%s %s", $this->ctx->userFirstName ?? '', $this->ctx->userLastName ?? '')) ?: 'Unknown';
36-
} elseif ($this->ctx->userEmail) {
37-
$user_name = $this->ctx->userEmail;
38-
}
39-
40-
$user_id = $this->ctx->userId ?? 'unknown';
41-
return sprintf("%s (%s)", $user_name, $user_id);
42-
}
43-
4427
abstract public function format($subject, array $change_set): ?string;
4528
}

app/Audit/AuditContext.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public function __construct(
2121
public ?string $uiApp = null,
2222
public ?string $uiFlow = null,
2323
public ?string $route = null,
24-
public ?string $rawRoute = null,
2524
public ?string $httpMethod = null,
2625
public ?string $clientIp = null,
2726
public ?string $userAgent = null,

app/Audit/AuditEventListener.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@
1616
use Doctrine\ORM\Event\OnFlushEventArgs;
1717
use Illuminate\Support\Facades\App;
1818
use Illuminate\Support\Facades\Log;
19-
use Illuminate\Support\Facades\Route;
2019

2120
/**
2221
* Class AuditEventListener
2322
* @package App\Audit
2423
*/
2524
class AuditEventListener
2625
{
27-
private const ROUTE_METHOD_SEPARATOR = '|';
2826

2927
public function onFlush(OnFlushEventArgs $eventArgs): void
3028
{
31-
if (app()->environment('testing')) {
29+
if (app()->environment('testing')){
3230
return;
3331
}
3432
$em = $eventArgs->getObjectManager();
@@ -69,7 +67,7 @@ public function onFlush(OnFlushEventArgs $eventArgs): void
6967
/**
7068
* Get the appropriate audit strategy based on environment configuration
7169
*/
72-
private function getAuditStrategy($em): ?IAuditStrategy
70+
private function getAuditStrategy($em)
7371
{
7472
// Check if OTLP audit is enabled
7573
if (config('opentelemetry.enabled', false)) {
@@ -99,11 +97,7 @@ private function buildAuditContext(): AuditContext
9997
//$ui = app()->bound('ui.context') ? app('ui.context') : [];
10098

10199
$req = request();
102-
103-
$route = Route::getRoutes()->match($req);
104-
$method = $route->methods[0] ?? 'UNKNOWN';
105-
$rawRoute = $method . self::ROUTE_METHOD_SEPARATOR . $route->uri;
106-
100+
107101
return new AuditContext(
108102
userId: $member?->getId(),
109103
userEmail: $member?->getEmail(),
@@ -115,7 +109,6 @@ private function buildAuditContext(): AuditContext
115109
httpMethod: $req?->method(),
116110
clientIp: $req?->ip(),
117111
userAgent: $req?->userAgent(),
118-
rawRoute: $rawRoute
119112
);
120113
}
121114
}

app/Audit/AuditLogFormatterFactory.php

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,27 @@ public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatt
4545
if (count($subject) > 0) {
4646
$child_entity = $subject[0];
4747
}
48-
if (is_null($child_entity) && isset($subject->getSnapshot()[0]) && count($subject->getSnapshot()) > 0) {
48+
if (is_null($child_entity) && count($subject->getSnapshot()) > 0) {
4949
$child_entity = $subject->getSnapshot()[0];
5050
}
5151
$child_entity_formatter = $child_entity != null ? ChildEntityFormatterFactory::build($child_entity) : null;
5252
$formatter = new EntityCollectionUpdateAuditLogFormatter($child_entity_formatter);
5353
break;
5454
case IAuditStrategy::EVENT_ENTITY_CREATION:
55-
$formatter = $this->getFormatterByContext($subject, $eventType, $ctx);
56-
if (is_null($formatter)) {
57-
$formatter = $this->getStrategyClass($subject, $eventType);
58-
}
55+
$formatter = $this->getStrategyClass($subject, $eventType);
5956
if(is_null($formatter)) {
6057
$formatter = new EntityCreationAuditLogFormatter();
6158
}
6259
break;
6360
case IAuditStrategy::EVENT_ENTITY_DELETION:
64-
$formatter = $this->getFormatterByContext($subject, $eventType, $ctx);
65-
if (is_null($formatter)) {
66-
$formatter = $this->getStrategyClass($subject, $eventType);
67-
}
61+
$formatter = $this->getStrategyClass($subject, $eventType);
6862
if(is_null($formatter)) {
6963
$child_entity_formatter = ChildEntityFormatterFactory::build($subject);
7064
$formatter = new EntityDeletionAuditLogFormatter($child_entity_formatter);
7165
}
7266
break;
7367
case IAuditStrategy::EVENT_ENTITY_UPDATE:
74-
$formatter = $this->getFormatterByContext($subject, $eventType, $ctx);
75-
if (is_null($formatter)) {
76-
$formatter = $this->getStrategyClass($subject, $eventType);
77-
}
68+
$formatter = $this->getStrategyClass($subject, $eventType);
7869
if(is_null($formatter)) {
7970
$child_entity_formatter = ChildEntityFormatterFactory::build($subject);
8071
$formatter = new EntityUpdateAuditLogFormatter($child_entity_formatter);
@@ -84,39 +75,4 @@ public function make(AuditContext $ctx, $subject, $eventType): ?IAuditLogFormatt
8475
$formatter->setContext($ctx);
8576
return $formatter;
8677
}
87-
88-
private function getFormatterByContext(object $subject, string $event_type, AuditContext $ctx): ?IAuditLogFormatter
89-
{
90-
$class = get_class($subject);
91-
$entity_config = $this->config['entities'][$class] ?? null;
92-
93-
if (!$entity_config || !isset($entity_config['strategies'])) {
94-
return null;
95-
}
96-
97-
foreach ($entity_config['strategies'] as $strategy) {
98-
if (!$this->matchesStrategy($strategy, $ctx)) {
99-
continue;
100-
}
101-
102-
$formatter_class = $strategy['formatter'] ?? null;
103-
return $formatter_class ? new $formatter_class($event_type) : null;
104-
}
105-
106-
return null;
107-
}
108-
109-
private function matchesStrategy(array $strategy, AuditContext $ctx): bool
110-
{
111-
if (isset($strategy['route']) && !$this->routeMatches($strategy['route'], $ctx->rawRoute)) {
112-
return false;
113-
}
114-
115-
return true;
116-
}
117-
118-
private function routeMatches(string $route, string $actual_route): bool
119-
{
120-
return strcmp($actual_route, $route) === 0;
121-
}
12278
}

app/Audit/ConcreteFormatters/FeaturedSpeakerAuditLogFormatter.php

Lines changed: 0 additions & 97 deletions
This file was deleted.

app/Audit/ConcreteFormatters/PresentationFormatters/BasePresentationAuditLogFormatter.php

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)