Skip to content

Commit 4a5b659

Browse files
committed
feat: add iterative log building helper (#48)
1 parent 5d495b8 commit 4a5b659

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

src/Migration/Logging/LoggingService.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ public function addLogEntry(SwagMigrationLogEntry $logEntry): void
7171
];
7272
}
7373

74+
/**
75+
* @param array<array-key, mixed> $keys
76+
* @param callable(array-key $key, mixed|null $value): SwagMigrationLogEntry $callback
77+
*/
78+
public function addLogForEach(array $keys, callable $callback): void
79+
{
80+
foreach ($keys as $key => $value) {
81+
if (\array_is_list($keys)) {
82+
$this->addLogEntry($callback($value, null));
83+
} else {
84+
$this->addLogEntry($callback($key, $value));
85+
}
86+
}
87+
}
88+
7489
private function writePerEntry(Context $context): void
7590
{
7691
foreach ($this->logging as $log) {

src/Migration/Logging/LoggingServiceInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ interface LoggingServiceInterface
1616
{
1717
public function addLogEntry(SwagMigrationLogEntry $logEntry): void;
1818

19+
/**
20+
* @param array<array-key, mixed> $keys
21+
* @param callable(array-key $key, mixed|null $value): SwagMigrationLogEntry $callback
22+
*/
23+
public function addLogForEach(array $keys, callable $callback): void;
24+
1925
public function saveLogging(Context $context): void;
2026
}

src/Migration/Service/MediaFileProcessorService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private function addMessageToBus(string $runUuid, Context $context, DataSet $dat
131131

132132
private function logDataSetNotFoundException(
133133
MigrationContextInterface $migrationContext,
134-
\Throwable $exception
134+
\Throwable $exception,
135135
): void {
136136
$this->loggingService->addLogEntry(
137137
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)

src/Profile/Shopware/Converter/NewsletterRecipientConverter.php

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

88
namespace SwagMigrationAssistant\Profile\Shopware\Converter;
99

10+
use Shopware\Core\Content\Newsletter\Aggregate\NewsletterRecipient\NewsletterRecipientDefinition;
1011
use Shopware\Core\Framework\Context;
1112
use Shopware\Core\Framework\Log\Package;
1213
use Shopware\Core\Framework\Uuid\Uuid;
@@ -63,13 +64,17 @@ public function convert(
6364
$fields = $this->checkForEmptyRequiredDataFields($data, $this->requiredDataFieldKeys);
6465

6566
if (!empty($fields)) {
66-
$this->loggingService->addLogEntry( // TODO: add optional fields
67-
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
67+
$this->loggingService->addLogForEach(
68+
$fields,
69+
fn (string $key) => SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
70+
->withEntityName(NewsletterRecipientDefinition::ENTITY_NAME)
71+
->withFieldName($key)
6872
->build(EmptyNecessaryFieldRunLog::class)
6973
);
7074

7175
return new ConvertStruct(null, $data);
7276
}
77+
7378
$oldData = $data;
7479
$this->generateChecksum($data);
7580
$this->context = $context;

0 commit comments

Comments
 (0)