Skip to content

Commit cbba14f

Browse files
fix: solve the abstraction problem and date format
1 parent 3042548 commit cbba14f

31 files changed

+52
-197
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/ChildEntityFormatters/SummitAttendeeBadgePrintAuditLogFormatter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Audit\ConcreteFormatters\ChildEntityFormatters;
44

55
use models\summit\SummitAttendeeBadgePrint;
6+
use App\Audit\Utils\DateFormatter;
67

78
/**
89
* Copyright 2023 OpenStack Foundation
@@ -29,7 +30,7 @@ class SummitAttendeeBadgePrintAuditLogFormatter implements IChildEntityAuditLogF
2930
public function format($subject, string $child_entity_action_type, ?string $additional_info = ""): ?string {
3031
if ($child_entity_action_type == IChildEntityAuditLogFormatter::CHILD_ENTITY_DELETION &&
3132
$subject instanceof SummitAttendeeBadgePrint) {
32-
$print_date = $subject->getPrintDate()->format('Y-m-d H:i:s');
33+
$print_date = DateFormatter::format($subject->getPrintDate());
3334
$view_type_name = 'N/A';
3435
$view_type = $subject->getViewType();
3536
if (!is_null($view_type)) {

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/PresentationActionTypeAuditLogFormatter.php

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

2323
class PresentationActionTypeAuditLogFormatter 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 PresentationActionType) {

app/Audit/ConcreteFormatters/PresentationFormatters/PresentationLinkAuditLogFormatter.php

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

2323
class PresentationLinkAuditLogFormatter 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 PresentationLink) {

app/Audit/ConcreteFormatters/PresentationFormatters/PresentationMediaUploadAuditLogFormatter.php

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

2323
class PresentationMediaUploadAuditLogFormatter 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 PresentationMediaUpload) {

app/Audit/ConcreteFormatters/PresentationFormatters/PresentationSlideAuditLogFormatter.php

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

2323
class PresentationSlideAuditLogFormatter 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 PresentationSlide) {

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/PresentationSpeakerSummitAssistanceConfirmationAuditLogFormatter.php

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

2323
class PresentationSpeakerSummitAssistanceConfirmationAuditLogFormatter 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) {

0 commit comments

Comments
 (0)