Skip to content

Commit 9831428

Browse files
fix: solve the abstraction problem and date format
1 parent 2c02e2b commit 9831428

21 files changed

+50
-133
lines changed

app/Audit/AbstractAuditLogFormatter.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace App\Audit;
44

5+
use App\Audit\Utils\DateFormatter;
6+
57
/**
68
* Copyright 2025 OpenStack Foundation
79
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +20,12 @@
1820
abstract class AbstractAuditLogFormatter implements IAuditLogFormatter
1921
{
2022
protected AuditContext $ctx;
23+
protected string $event_type;
24+
25+
public function __construct(string $event_type)
26+
{
27+
$this->event_type = $event_type;
28+
}
2129

2230
final public function setContext(AuditContext $ctx): void
2331
{
@@ -41,6 +49,10 @@ protected function getUserInfo(): string
4149
return sprintf("%s (%s)", $user_name, $user_id);
4250
}
4351

52+
protected function formatAuditDate($date, string $format = 'Y-m-d H:i:s'): string
53+
{
54+
return DateFormatter::format($date, $format);
55+
}
4456

4557
protected function getIgnoredFields(): array
4658
{

app/Audit/ConcreteFormatters/EntityUpdateAuditLogFormatter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ public function format($subject, $change_set): ?string
140140
}
141141

142142
if ($old_value instanceof DateTime || $new_value instanceof DateTime) {
143-
$old_value = $old_value != null ? $old_value->format('Y-m-d H:i:s') : "";
144-
$new_value = $new_value != null ? $new_value->format('Y-m-d H:i:s') : "";
143+
$old_value = $old_value != null ? $this->formatAuditDate($old_value) : "";
144+
$new_value = $new_value != null ? $this->formatAuditDate($new_value) : "";
145145
} else if (is_bool($old_value) || is_bool($new_value)) {
146146
$old_value = $old_value ? 'true' : 'false';
147147
$new_value = $new_value ? 'true' : 'false';

app/Audit/ConcreteFormatters/FeaturedSpeakerAuditLogFormatter.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222

2323
class FeaturedSpeakerAuditLogFormatter extends AbstractAuditLogFormatter
2424
{
25-
private string $event_type;
26-
27-
public function __construct(string $event_type)
28-
{
29-
$this->event_type = $event_type;
30-
}
31-
3225
public function format($subject, array $change_set): ?string
3326
{
3427
if (!$subject instanceof FeaturedSpeaker) {

app/Audit/ConcreteFormatters/PresentationFormatters/PresentationSpeakerAuditLogFormatter.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222

2323
class PresentationSpeakerAuditLogFormatter extends AbstractAuditLogFormatter
2424
{
25-
private string $event_type;
26-
27-
public function __construct(string $event_type)
28-
{
29-
$this->event_type = $event_type;
30-
}
31-
3225
public function format($subject, array $change_set): ?string
3326
{
3427
if (!$subject instanceof PresentationSpeaker) {

app/Audit/ConcreteFormatters/PresentationFormatters/PresentationTrackChairRatingTypeAuditLogFormatter.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222

2323
class PresentationTrackChairRatingTypeAuditLogFormatter extends AbstractAuditLogFormatter
2424
{
25-
private string $event_type;
26-
27-
public function __construct(string $event_type)
28-
{
29-
$this->event_type = $event_type;
30-
}
31-
3225
public function format($subject, array $change_set): ?string
3326
{
3427
if (!$subject instanceof PresentationTrackChairRatingType) {

app/Audit/ConcreteFormatters/PresentationFormatters/PresentationTrackChairScoreTypeAuditLogFormatter.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222

2323
class PresentationTrackChairScoreTypeAuditLogFormatter extends AbstractAuditLogFormatter
2424
{
25-
private string $event_type;
26-
27-
public function __construct(string $event_type)
28-
{
29-
$this->event_type = $event_type;
30-
}
31-
3225
public function format($subject, array $change_set): ?string
3326
{
3427
if (!$subject instanceof PresentationTrackChairScoreType) {

app/Audit/ConcreteFormatters/PresentationFormatters/PresentationUserSubmissionAuditLogFormatter.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99

1010
class PresentationUserSubmissionAuditLogFormatter extends AbstractAuditLogFormatter
1111
{
12-
private string $event_type;
13-
14-
public function __construct(string $event_type)
15-
{
16-
$this->event_type = $event_type;
17-
}
18-
1912
public function format($subject, array $change_set): ?string
2013
{
2114
if (!$subject instanceof Presentation) {

app/Audit/ConcreteFormatters/SelectionPlanAuditLogFormatter.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222

2323
class SelectionPlanAuditLogFormatter extends AbstractAuditLogFormatter
2424
{
25-
private string $event_type;
26-
27-
public function __construct(string $event_type)
28-
{
29-
$this->event_type = $event_type;
30-
}
31-
3225
public function format($subject, array $change_set): ?string
3326
{
3427
if (!$subject instanceof SelectionPlan) {
@@ -46,16 +39,16 @@ public function format($subject, array $change_set): ?string
4639
$submission_dates = $subject->hasSubmissionPeriodDefined()
4740
? sprintf(
4841
"[%s - %s]",
49-
$subject->getSubmissionBeginDate()?->format('Y-m-d H:i:s') ?? 'N/A',
50-
$subject->getSubmissionEndDate()?->format('Y-m-d H:i:s') ?? 'N/A'
42+
$this->formatAuditDate($subject->getSubmissionBeginDate()),
43+
$this->formatAuditDate($subject->getSubmissionEndDate())
5144
)
5245
: 'No dates set';
5346

5447
$selection_dates = $subject->hasSelectionPeriodDefined()
5548
? sprintf(
5649
"[%s - %s]",
57-
$subject->getSelectionBeginDate()?->format('Y-m-d H:i:s') ?? 'N/A',
58-
$subject->getSelectionEndDate()?->format('Y-m-d H:i:s') ?? 'N/A'
50+
$this->formatAuditDate($subject->getSelectionBeginDate()),
51+
$this->formatAuditDate($subject->getSelectionEndDate())
5952
)
6053
: 'No dates set';
6154

app/Audit/ConcreteFormatters/SpeakerAssistanceAuditLogFormatter.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,11 @@
1717

1818
use App\Audit\AbstractAuditLogFormatter;
1919
use App\Audit\Interfaces\IAuditStrategy;
20-
use models\summit\PresentationSpeakerSummitAssistanceConfirmationRequest;
20+
use models\summit\SpeakerAssistanceRequest;
2121
use Illuminate\Support\Facades\Log;
2222

2323
class SpeakerAssistanceAuditLogFormatter extends AbstractAuditLogFormatter
2424
{
25-
private string $event_type;
26-
27-
public function __construct(string $event_type)
28-
{
29-
$this->event_type = $event_type;
30-
}
31-
3225
public function format($subject, array $change_set): ?string
3326
{
3427
if (!$subject instanceof PresentationSpeakerSummitAssistanceConfirmationRequest) {

app/Audit/ConcreteFormatters/SpeakerRegistrationRequestAuditLogFormatter.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222

2323
class SpeakerRegistrationRequestAuditLogFormatter extends AbstractAuditLogFormatter
2424
{
25-
private string $event_type;
26-
27-
public function __construct(string $event_type)
28-
{
29-
$this->event_type = $event_type;
30-
}
31-
3225
public function format($subject, array $change_set): ?string
3326
{
3427
if (!$subject instanceof SpeakerRegistrationRequest) {

0 commit comments

Comments
 (0)