Skip to content

Commit b50abbf

Browse files
authored
feat: fill logs with meaningful data (#49)
1 parent 4a5b659 commit b50abbf

31 files changed

+622
-133
lines changed

src/Profile/Shopware/Converter/CategoryConverter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ public function convert(
8585
$this->connectionName = $connection->getName();
8686

8787
if (!isset($data['_locale'])) {
88-
$this->loggingService->addLogEntry( // TODO: add optional fields
88+
$this->loggingService->addLogEntry(
8989
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
90+
->withEntityName(CategoryDefinition::ENTITY_NAME)
91+
->withFieldSourcePath('_locale')
92+
->withSourceData($data)
9093
->build(EmptyNecessaryFieldRunLog::class)
9194
);
9295

src/Profile/Shopware/Converter/CrossSellingConverter.php

Lines changed: 13 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\Product\Aggregate\ProductCrossSelling\ProductCrossSellingDefinition;
1011
use Shopware\Core\Framework\Context;
1112
use Shopware\Core\Framework\Log\Package;
1213
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
@@ -59,8 +60,13 @@ public function convert(array $data, Context $context, MigrationContextInterface
5960

6061
$sourceProductMapping = $this->getProductMapping($data['articleID']);
6162
if ($sourceProductMapping === null) {
62-
$this->loggingService->addLogEntry( // TODO: add optional fields
63+
$this->loggingService->addLogEntry(
6364
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
65+
->withEntityName(ProductCrossSellingDefinition::ENTITY_NAME)
66+
->withFieldName('id')
67+
->withFieldSourcePath('articleID')
68+
->withSourceData($data)
69+
->withConvertedData($converted)
6470
->build(AssociationRequiredMissingLog::class)
6571
);
6672

@@ -70,8 +76,13 @@ public function convert(array $data, Context $context, MigrationContextInterface
7076

7177
$relatedProductMapping = $this->getProductMapping($data['relatedarticle']);
7278
if ($relatedProductMapping === null) {
73-
$this->loggingService->addLogEntry( // TODO: add optional fields
79+
$this->loggingService->addLogEntry(
7480
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
81+
->withEntityName(ProductCrossSellingDefinition::ENTITY_NAME)
82+
->withFieldName('id')
83+
->withFieldSourcePath('relatedarticle')
84+
->withSourceData($data)
85+
->withConvertedData($converted)
7586
->build(AssociationRequiredMissingLog::class)
7687
);
7788

src/Profile/Shopware/Converter/CustomerConverter.php

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

88
namespace SwagMigrationAssistant\Profile\Shopware\Converter;
99

10+
use Shopware\Core\Checkout\Customer\Aggregate\CustomerAddress\CustomerAddressDefinition;
11+
use Shopware\Core\Checkout\Customer\CustomerDefinition;
1012
use Shopware\Core\Defaults;
1113
use Shopware\Core\Framework\Context;
1214
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
@@ -107,17 +109,25 @@ public function convert(
107109
$fields = $this->checkForEmptyRequiredDataFields($data, $this->requiredDataFieldKeys);
108110

109111
if (!empty($fields)) {
110-
$this->loggingService->addLogEntry( // TODO: add optional fields
111-
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
112+
$this->loggingService->addLogForEach(
113+
$fields,
114+
fn (string $key) => SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
115+
->withEntityName(CustomerDefinition::ENTITY_NAME)
116+
->withFieldSourcePath($key)
117+
->withSourceData($data)
112118
->build(EmptyNecessaryFieldRunLog::class)
113119
);
114120

115121
return new ConvertStruct(null, $oldData);
116122
}
117123

118124
if (!$this->checkEmailValidity($data['email'])) {
119-
$this->loggingService->addLogEntry( // TODO: add optional fields
125+
$this->loggingService->addLogEntry(
120126
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
127+
->withEntityName(CustomerDefinition::ENTITY_NAME)
128+
->withFieldName('email')
129+
->withFieldSourcePath('email')
130+
->withSourceData($data)
121131
->build(InvalidEmailAddressLog::class)
122132
);
123133

@@ -227,8 +237,13 @@ public function convert(
227237
);
228238

229239
if ($mapping === null) {
230-
$this->loggingService->addLogEntry( // TODO: add optional fields
240+
$this->loggingService->addLogEntry(
231241
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
242+
->withEntityName(CustomerDefinition::ENTITY_NAME)
243+
->withFieldName('defaultPaymentMethodId')
244+
->withFieldSourcePath('default_payment_method')
245+
->withSourceData($data)
246+
->withConvertedData($converted)
232247
->build(EmptyNecessaryFieldRunLog::class)
233248
);
234249

@@ -284,11 +299,30 @@ public function convert(
284299
$returnData = null;
285300
}
286301

287-
if (!isset($converted['defaultBillingAddressId'], $converted['defaultShippingAddressId'])) {
302+
if (!isset($converted['defaultBillingAddressId'])) {
288303
$this->mappingService->deleteMapping($converted['id'], $this->connectionId, $this->context);
289304

290-
$this->loggingService->addLogEntry( // TODO: add optional fields
305+
$this->loggingService->addLogEntry(
291306
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
307+
->withEntityName(CustomerDefinition::ENTITY_NAME)
308+
->withFieldName('defaultBillingAddressId')
309+
->withFieldSourcePath('default_billing_address_id')
310+
->withSourceData($data)
311+
->build(EmptyNecessaryFieldRunLog::class)
312+
);
313+
314+
return new ConvertStruct(null, $oldData);
315+
}
316+
317+
if (!isset($converted['defaultShippingAddressId'])) {
318+
$this->mappingService->deleteMapping($converted['id'], $this->connectionId, $this->context);
319+
320+
$this->loggingService->addLogEntry(
321+
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
322+
->withEntityName(CustomerDefinition::ENTITY_NAME)
323+
->withFieldName('defaultShippingAddressId')
324+
->withFieldSourcePath('default_shipping_address_id')
325+
->withSourceData($data)
292326
->build(EmptyNecessaryFieldRunLog::class)
293327
);
294328

@@ -332,8 +366,12 @@ protected function getDefaultPaymentMethod(array $originalData): ?string
332366
);
333367

334368
if ($paymentMethodMapping === null) {
335-
$this->loggingService->addLogEntry( // TODO: add optional fields
369+
$this->loggingService->addLogEntry(
336370
SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
371+
->withEntityName(CustomerDefinition::ENTITY_NAME)
372+
->withFieldName('defaultPaymentMethodId')
373+
->withFieldSourcePath('default_payment_method')
374+
->withSourceData($originalData)
337375
->build(UnknownEntityLog::class)
338376
);
339377

@@ -357,8 +395,12 @@ protected function applyAddresses(array &$originalData, array &$converted, strin
357395

358396
$fields = $this->checkForEmptyRequiredDataFields($address, $this->requiredAddressDataFieldKeys);
359397
if (!empty($fields)) {
360-
$this->loggingService->addLogEntry( // TODO: add optional fields
361-
SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
398+
$this->loggingService->addLogForEach(
399+
$fields,
400+
fn (string $key) => SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
401+
->withEntityName(CustomerAddressDefinition::ENTITY_NAME)
402+
->withFieldSourcePath($key)
403+
->withSourceData($address)
362404
->build(EmptyNecessaryFieldRunLog::class)
363405
);
364406

@@ -539,8 +581,12 @@ protected function getCountryState(array $oldAddressData, string $newCountryId):
539581
$state = ['countryId' => $newCountryId];
540582

541583
if (!isset($oldAddressData['state_id'], $oldAddressData['country']['countryiso'], $oldAddressData['state']['shortcode'])) {
542-
$this->loggingService->addLogEntry( // TODO: add optional fields
584+
$this->loggingService->addLogEntry(
543585
SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
586+
->withEntityName(CustomerAddressDefinition::ENTITY_NAME)
587+
->withFieldName('stateId')
588+
->withFieldSourcePath('state_id')
589+
->withSourceData($oldAddressData)
544590
->build(UnknownEntityLog::class)
545591
);
546592

@@ -572,8 +618,12 @@ protected function getCountryState(array $oldAddressData, string $newCountryId):
572618
$oldAddressData['state']['position'],
573619
$oldAddressData['state']['active']
574620
)) {
575-
$this->loggingService->addLogEntry( // TODO: add optional fields
621+
$this->loggingService->addLogEntry(
576622
SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
623+
->withEntityName(CustomerAddressDefinition::ENTITY_NAME)
624+
->withFieldName('stateId')
625+
->withFieldSourcePath('state.name')
626+
->withSourceData($oldAddressData['state'])
577627
->build(UnknownEntityLog::class)
578628
);
579629

@@ -643,8 +693,16 @@ protected function checkUnsetDefaultShippingAndDefaultBillingAddress(array &$ori
643693
$converted['defaultShippingAddressId'] = $addresses[0]['id'];
644694
unset($originalData['default_billing_address_id'], $originalData['default_shipping_address_id']);
645695

646-
$this->loggingService->addLogEntry( // TODO: add optional fields
647-
SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
696+
$this->loggingService->addLogForEach(
697+
[
698+
'defaultBillingAddressId' => 'default_billing_address_id',
699+
'defaultShippingAddressId' => 'default_shipping_address_id',
700+
],
701+
fn (string $key, string $value) => SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
702+
->withEntityName(CustomerAddressDefinition::ENTITY_NAME)
703+
->withFieldName($key)
704+
->withFieldSourcePath($value)
705+
->withSourceData($originalData)
648706
->build(FieldReassignedRunLog::class)
649707
);
650708
}
@@ -660,8 +718,12 @@ protected function checkUnsetDefaultShippingAddress(array &$originalData, array
660718
$converted['defaultShippingAddressId'] = $converted['defaultBillingAddressId'];
661719
unset($originalData['default_shipping_address_id']);
662720

663-
$this->loggingService->addLogEntry( // TODO: add optional fields
721+
$this->loggingService->addLogEntry(
664722
SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
723+
->withEntityName(CustomerAddressDefinition::ENTITY_NAME)
724+
->withFieldName('defaultShippingAddressId')
725+
->withFieldSourcePath('default_shipping_address_id')
726+
->withSourceData($originalData)
665727
->build(FieldReassignedRunLog::class)
666728
);
667729
}
@@ -677,8 +739,12 @@ protected function checkUnsetDefaultBillingAddress(array &$originalData, array &
677739
$converted['defaultBillingAddressId'] = $converted['defaultShippingAddressId'];
678740
unset($originalData['default_billing_address_id']);
679741

680-
$this->loggingService->addLogEntry( // TODO: add optional fields
742+
$this->loggingService->addLogEntry(
681743
SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
744+
->withEntityName(CustomerAddressDefinition::ENTITY_NAME)
745+
->withFieldName('defaultBillingAddressId')
746+
->withFieldSourcePath('default_billing_address_id')
747+
->withSourceData($originalData)
682748
->build(FieldReassignedRunLog::class)
683749
);
684750
}
@@ -694,8 +760,12 @@ protected function getSalutation(string $salutation): ?string
694760
);
695761

696762
if ($mapping === null) {
697-
$this->loggingService->addLogEntry( // TODO: add optional fields
763+
$this->loggingService->addLogEntry(
698764
SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
765+
->withEntityName(CustomerDefinition::ENTITY_NAME)
766+
->withFieldName('salutationId')
767+
->withFieldSourcePath('salutation')
768+
->withSourceData(['salutation' => $salutation])
699769
->build(UnknownEntityLog::class)
700770
);
701771

src/Profile/Shopware/Converter/LanguageConverter.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Shopware\Core\Framework\Context;
1111
use Shopware\Core\Framework\Log\Package;
12+
use Shopware\Core\System\Language\LanguageDefinition;
1213
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
1314
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
1415
use SwagMigrationAssistant\Migration\Logging\Log\Builder\SwagMigrationLogBuilder;
@@ -50,8 +51,11 @@ public function convert(array $data, Context $context, MigrationContextInterface
5051

5152
$languageUuid = $this->languageLookup->get($data['locale'], $context);
5253
if ($languageUuid !== null) {
53-
$this->loggingService->addLogEntry( // TODO: add optional fields
54+
$this->loggingService->addLogEntry(
5455
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
56+
->withEntityName(LanguageDefinition::ENTITY_NAME)
57+
->withFieldSourcePath('locale')
58+
->withSourceData($data)
5559
->build(EntityAlreadyExistsRunLog::class)
5660
);
5761

src/Profile/Shopware/Converter/MainVariantRelationConverter.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,11 @@ public function convert(array $data, Context $context, MigrationContextInterface
109109
*/
110110
private function addAssociationRequiredLog(MigrationContextInterface $migrationContext, string $field, string $entity, array $data): void
111111
{
112-
$this->loggingService->addLogEntry( // TODO: add optional fields
112+
$this->loggingService->addLogEntry(
113113
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
114114
->withEntityName($entity)
115-
->withFieldName($field)
116115
->withFieldSourcePath($field)
117-
->withSourceData([$data])
116+
->withSourceData($data)
118117
->build(AssociationRequiredMissingLog::class)
119118
);
120119
}

src/Profile/Shopware/Converter/NewsletterRecipientConverter.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ protected function getSalutation(string $salutation, MigrationContextInterface $
161161
);
162162

163163
if ($salutationMapping === null) {
164-
$this->loggingService->addLogEntry( // TODO: add optional fields
164+
$this->loggingService->addLogEntry(
165165
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
166+
->withEntityName(NewsletterRecipientDefinition::ENTITY_NAME)
167+
->withFieldName('salutationId')
168+
->withSourceData(['salutation' => $salutation])
166169
->build(UnknownEntityLog::class)
167170
);
168171

@@ -188,8 +191,12 @@ protected function getSalesChannel(array $data): ?string
188191
}
189192

190193
if (!isset($salesChannelMapping)) {
191-
$this->loggingService->addLogEntry( // TODO: add optional fields
194+
$this->loggingService->addLogEntry(
192195
SwagMigrationLogBuilder::fromMigrationContext($this->migrationContext)
196+
->withEntityName(NewsletterRecipientDefinition::ENTITY_NAME)
197+
->withFieldName('salesChannelId')
198+
->withFieldSourcePath('shopId')
199+
->withSourceData($data)
193200
->build(EmptyNecessaryFieldRunLog::class)
194201
);
195202

@@ -210,8 +217,11 @@ protected function getStatus(MigrationContextInterface $migrationContext): ?stri
210217
);
211218

212219
if ($status === null) {
213-
$this->loggingService->addLogEntry( // TODO: add optional fields
220+
$this->loggingService->addLogEntry(
214221
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
222+
->withEntityName(NewsletterRecipientDefinition::ENTITY_NAME)
223+
->withFieldName('status')
224+
->withSourceData(['status' => NewsletterRecipientStatusReader::SOURCE_ID])
215225
->build(EmptyNecessaryFieldRunLog::class)
216226
);
217227
}

src/Profile/Shopware/Converter/NumberRangeConverter.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Shopware\Core\Framework\Log\Package;
1515
use Shopware\Core\Framework\Uuid\Uuid;
1616
use Shopware\Core\System\NumberRange\NumberRangeCollection;
17+
use Shopware\Core\System\NumberRange\NumberRangeDefinition;
1718
use Shopware\Core\System\NumberRange\NumberRangeEntity;
1819
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
1920
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
@@ -72,8 +73,12 @@ public function convert(array $data, Context $context, MigrationContextInterface
7273
$this->connectionId = $connection->getId();
7374

7475
if (!\array_key_exists($data['name'], self::TYPE_MAPPING)) {
75-
$this->loggingService->addLogEntry( // TODO: add optional fields
76+
$this->loggingService->addLogEntry(
7677
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
78+
->withEntityName(NumberRangeDefinition::ENTITY_NAME)
79+
->withFieldName('typeId')
80+
->withFieldSourcePath('name')
81+
->withSourceData($data)
7782
->build(UnsupportedNumberRangeTypeLog::class)
7883
);
7984

@@ -85,8 +90,12 @@ public function convert(array $data, Context $context, MigrationContextInterface
8590
$converted['typeId'] = $this->getProductNumberRangeTypeUuid($data['name']);
8691

8792
if (empty($converted['typeId'])) {
88-
$this->loggingService->addLogEntry( // TODO: add optional fields
93+
$this->loggingService->addLogEntry(
8994
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
95+
->withEntityName(NumberRangeDefinition::ENTITY_NAME)
96+
->withFieldName('typeId')
97+
->withFieldSourcePath('name')
98+
->withSourceData($data)
9099
->build(EmptyNecessaryFieldRunLog::class)
91100
);
92101

0 commit comments

Comments
 (0)