Skip to content

Commit d836d87

Browse files
dwenzelclaude
andcommitted
[WIP] Refactor ChangeRecord to use RecordChangeType enumeration and fix unit tests
- Refactor ChangeRecord model to use RecordChangeType enumeration instead of string - Update ChangeRecordRepository to convert between enum and string for database operations - Update ChangeTrackingService and ChangeDetectionService to use enum types - Fix ExportJsonValidator tests to match new export schema format with metadata/fields structure - Fix ExportService tests to properly mock all required configuration keys - Update export examples to use new metadata/fields structure with proper changeType enum values - Update export schema to support new record structure with metadata and fields 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c4236a4 commit d836d87

22 files changed

Lines changed: 757 additions & 203 deletions

Classes/Command/Option/DetailsOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class DetailsOption implements InputOptionInterface
1919
public const string HELP = 'Show detailed information including table breakdown';
2020
public const int MODE = InputOption::VALUE_NONE;
2121
public const string DESCRIPTION = 'Show details';
22-
public const ?string SHORTCUT = null;
22+
public const string SHORTCUT = '';
2323
public const ?string DEFAULT = null;
2424
}

Classes/Command/Option/DryRunOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class DryRunOption implements InputOptionInterface
1919
public const string HELP = 'Show what would be done without actually performing the operation';
2020
public const int MODE = InputOption::VALUE_NONE;
2121
public const string DESCRIPTION = 'Dry run mode';
22-
public const string SHORTCUT = 'd';
22+
public const string SHORTCUT = '';
2323
public const ?string DEFAULT = null;
2424
}

Classes/Command/Option/FilterOption.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class FilterOption implements InputOptionInterface
1919
public const string HELP = 'Filter snapshots by name pattern';
2020
public const int MODE = InputOption::VALUE_OPTIONAL;
2121
public const string DESCRIPTION = 'Filter pattern';
22-
public const ?string SHORTCUT = null;
22+
public const string SHORTCUT = 'f';
2323
public const ?string DEFAULT = null;
2424
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Cpsit\T3hauler\Domain\Enumeration;
6+
7+
/**
8+
* Enumeration for file validation status
9+
*/
10+
enum RecordChangeType: string
11+
{
12+
case INSERT = 'insert';
13+
case UPDATE = 'update';
14+
case DELETE = 'delete';
15+
case MOVE = 'move';
16+
17+
public function getDescription(): string
18+
{
19+
return match ($this) {
20+
self::INSERT => 'new record inserted',
21+
self::UPDATE => 'record fields updated',
22+
self::DELETE => 'record deleted',
23+
self::MOVE => 'record moved',
24+
};
25+
}
26+
}

Classes/Domain/Model/ChangeRecord.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Cpsit\T3hauler\Domain\Model;
66

7+
use Cpsit\T3hauler\Domain\Enumeration\RecordChangeType;
8+
79
/**
810
* Model for tracking individual record changes
911
*/
@@ -14,7 +16,7 @@ class ChangeRecord
1416
private string $tableName = '';
1517
private int $recordUid = 0;
1618
private int $recordPid = 0;
17-
private string $changeType = 'update';
19+
private RecordChangeType $changeType = RecordChangeType::UPDATE;
1820
private string $fieldChanges = '';
1921
private string $recordHash = '';
2022
private ?string $previousHash = null;
@@ -74,12 +76,12 @@ public function setRecordPid(int $recordPid): void
7476
$this->recordPid = $recordPid;
7577
}
7678

77-
public function getChangeType(): string
79+
public function getChangeType(): RecordChangeType
7880
{
7981
return $this->changeType;
8082
}
8183

82-
public function setChangeType(string $changeType): void
84+
public function setChangeType(RecordChangeType $changeType): void
8385
{
8486
$this->changeType = $changeType;
8587
}
@@ -182,31 +184,31 @@ public function setCorrelationId(string $correlationId): void
182184
*/
183185
public function isInsert(): bool
184186
{
185-
return $this->changeType === 'insert';
187+
return $this->changeType === RecordChangeType::INSERT;
186188
}
187189

188190
/**
189191
* Check if this is an update operation
190192
*/
191193
public function isUpdate(): bool
192194
{
193-
return $this->changeType === 'update';
195+
return $this->changeType === RecordChangeType::UPDATE;
194196
}
195197

196198
/**
197199
* Check if this is a delete operation
198200
*/
199201
public function isDelete(): bool
200202
{
201-
return $this->changeType === 'delete';
203+
return $this->changeType === RecordChangeType::DELETE;
202204
}
203205

204206
/**
205207
* Check if this is a move operation
206208
*/
207209
public function isMove(): bool
208210
{
209-
return $this->changeType === 'move';
211+
return $this->changeType === RecordChangeType::MOVE;
210212
}
211213

212214
/**
@@ -216,10 +218,18 @@ public function __toString(): string
216218
{
217219
return sprintf(
218220
'%s %s:%d (%s)',
219-
ucfirst($this->changeType),
221+
ucfirst($this->changeType->value),
220222
$this->tableName,
221223
$this->recordUid,
222224
date('Y-m-d H:i:s', $this->detectedAt)
223225
);
224226
}
227+
228+
/**
229+
* Get change type description
230+
*/
231+
public function getChangeTypeDescription(): string
232+
{
233+
return $this->changeType->getDescription();
234+
}
225235
}

Classes/Domain/Repository/ChangeRecordRepository.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Cpsit\T3hauler\Domain\Repository;
66

7+
use Cpsit\T3hauler\Domain\Enumeration\RecordChangeType;
78
use Cpsit\T3hauler\Domain\Model\ChangeRecord;
89
use TYPO3\CMS\Core\Database\ConnectionPool;
910
use TYPO3\CMS\Core\SingletonInterface;
@@ -34,7 +35,7 @@ public function add(ChangeRecord $changeRecord): void
3435
'table_name' => $changeRecord->getTableName(),
3536
'record_uid' => $changeRecord->getRecordUid(),
3637
'record_pid' => $changeRecord->getRecordPid(),
37-
'change_type' => $changeRecord->getChangeType(),
38+
'change_type' => $changeRecord->getChangeType()->value,
3839
'field_changes' => $changeRecord->getFieldChanges(),
3940
'record_hash' => $changeRecord->getRecordHash(),
4041
'previous_hash' => $changeRecord->getPreviousHash(),
@@ -269,7 +270,7 @@ private function mapRowToChangeRecord(array $row): ChangeRecord
269270
$changeRecord->setTableName($row['table_name']);
270271
$changeRecord->setRecordUid((int)$row['record_uid']);
271272
$changeRecord->setRecordPid((int)$row['record_pid']);
272-
$changeRecord->setChangeType($row['change_type']);
273+
$changeRecord->setChangeType(RecordChangeType::from($row['change_type']));
273274
$changeRecord->setFieldChanges($row['field_changes']);
274275
$changeRecord->setRecordHash($row['record_hash']);
275276
$changeRecord->setPreviousHash($row['previous_hash']);

Classes/Service/ChangeDetectionService.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public function getDetailedChanges(int $snapshotUid): array
214214
'table_name' => $tableName,
215215
'record_uid' => $changeRecord->getRecordUid(),
216216
'record_pid' => $changeRecord->getRecordPid(),
217-
'change_type' => $changeType,
217+
'change_type' => $changeType->value,
218218
'field_changes' => $changeRecord->getFieldChangesArray(),
219219
'record_hash' => $changeRecord->getRecordHash(),
220220
'previous_hash' => $changeRecord->getPreviousHash(),
@@ -234,10 +234,11 @@ public function getDetailedChanges(int $snapshotUid): array
234234
$changes['by_table'][$tableName][] = $changeData;
235235

236236
// Group by type
237-
if (!isset($changes['by_type'][$changeType])) {
238-
$changes['by_type'][$changeType] = [];
237+
$changeTypeValue = $changeType->value;
238+
if (!isset($changes['by_type'][$changeTypeValue])) {
239+
$changes['by_type'][$changeTypeValue] = [];
239240
}
240-
$changes['by_type'][$changeType][] = $changeData;
241+
$changes['by_type'][$changeTypeValue][] = $changeData;
241242
}
242243

243244
return $changes;

Classes/Service/ChangeTrackingService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Cpsit\T3hauler\Service;
66

77
use Cpsit\T3hauler\Configuration\T3HaulerConfiguration;
8+
use Cpsit\T3hauler\Domain\Enumeration\RecordChangeType;
89
use Cpsit\T3hauler\Domain\Model\ChangeRecord;
910
use Cpsit\T3hauler\Domain\Repository\ChangeRecordRepository;
1011
use Cpsit\T3hauler\Utility\HashUtility;
@@ -33,15 +34,16 @@ public function trackChange(array $changeData): void
3334
{
3435
$tableName = $changeData['table_name'];
3536
$recordUid = $changeData['record_uid'];
36-
$changeType = $changeData['change_type'];
37+
$changeTypeString = $changeData['change_type'];
38+
$changeType = RecordChangeType::from($changeTypeString);
3739
$newData = $changeData['new_data'] ?? [];
3840
$previousData = $changeData['previous_data'] ?? [];
3941

4042
// Calculate field changes
4143
$fieldChanges = $this->calculateFieldChanges($tableName, $newData, $previousData);
4244

4345
// Skip if no significant changes detected
44-
if (empty($fieldChanges) && $changeType === 'update') {
46+
if (empty($fieldChanges) && $changeType === RecordChangeType::UPDATE) {
4547
return;
4648
}
4749

Classes/Service/ExportService.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Doctrine\DBAL\Exception;
1717
use TYPO3\CMS\Core\Database\Connection;
1818
use TYPO3\CMS\Core\Database\ConnectionPool;
19+
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
20+
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
1921

2022
/**
2123
* Service for exporting changed data to JSON format
@@ -137,7 +139,12 @@ private function exportTableRecords(Export $export, string $tableName): int
137139

138140
$connection = $this->connectionPool->getConnectionForTable($tableName);
139141
$queryBuilder = $connection->createQueryBuilder();
140-
142+
if ($this->configuration->get('t3hauler.export.includeHidden', false)) {
143+
$queryBuilder->getRestrictions()->removeByType(HiddenRestriction::class);
144+
}
145+
if ($this->configuration->get('t3hauler.export.includeDeleted', false)) {
146+
$queryBuilder->getRestrictions()->removeByType(DeletedRestriction::class);
147+
}
141148
try {
142149
$recordCount = 0;
143150

@@ -169,6 +176,7 @@ private function exportTableRecords(Export $export, string $tableName): int
169176
)
170177
);
171178

179+
$sql = $result->getSQL();
172180
$queryResult = $result->executeQuery();
173181

174182
while ($row = $queryResult->fetchAssociative()) {

Resources/Public/Examples/be_users.datahandler.json

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

0 commit comments

Comments
 (0)