Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 16.0.1
# 16.1.0

- Fixed log entries to have the file path and line number in the exception message
- Remove support for Magento 1.9
- Reduced log file size by removing exception trace args

# 16.0.0
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 16.0.1
# 16.1.0

- Log-Einträge wurden korrigiert, sodass der Dateipfad und die Zeilennummer nun in der Ausnahmemeldung enthalten sind.
- Die Unterstützung für Magento 1.9 wurde entfernt.
- Größe der Protokolldatei reduziert, indem Exception-Trace Argumente entfernt wurden

# 16.0.0
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swag/migration-assistant",
"description": "Migration plugin for shopware/platform",
"version": "16.0.0",
"version": "16.1.0",
"type": "shopware-platform-plugin",
"license": "MIT",
"authors": [
Expand Down
11 changes: 11 additions & 0 deletions src/Exception/MigrationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class MigrationException extends HttpException

public const LOCAL_DATABASE_CONNECTION_ERROR = 'SWAG_MIGRATION__LOCAL_DATABASE_CONNECTION_ERROR';

final public const MAIN_VARIANT_RELATION_MISSING_ID_AND_ORDER_NUMBER = 'SWAG_MIGRATION__MAIN_VARIANT_RELATION_MISSING_ID_AND_ORDER_NUMBER';

public static function associationEntityRequiredMissing(string $entity, string $missingEntity): self
{
return new self(
Expand Down Expand Up @@ -556,4 +558,13 @@ public static function connectionValidationFailed(string $code, string $message)
$message,
);
}

public static function mainVariantRelationMissingIdAndOrderNumber(): self
{
return new self(
Response::HTTP_INTERNAL_SERVER_ERROR,
self::MAIN_VARIANT_RELATION_MISSING_ID_AND_ORDER_NUMBER,
'MainVariantRelation requires ID and order number.',
);
}
}
7 changes: 6 additions & 1 deletion src/Migration/Converter/ConverterRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function getConverter(MigrationContextInterface $migrationContext): Conve
}
}

throw MigrationException::converterNotFound($migrationContext->getProfile()->getName());
$dataSet = $migrationContext->getDataSet();
if ($dataSet === null) {
throw MigrationException::migrationContextPropertyMissing('DataSet');
}

throw MigrationException::converterNotFound($dataSet::getEntity());
}
}
41 changes: 39 additions & 2 deletions src/Migration/Logging/Log/Builder/MigrationLogBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function __construct(
protected ?array $convertedData = null,
protected ?string $exceptionMessage = null,
protected ?array $exceptionTrace = null,
protected ?\Throwable $exception = null,
) {
}

Expand Down Expand Up @@ -100,6 +101,13 @@ public function withConvertedData(array $convertedData): self
return $this;
}

public function withException(\Throwable $exception): self
{
$this->exception = $exception;

return $this;
}

public function withExceptionMessage(string $exceptionMessage): self
{
$this->exceptionMessage = $exceptionMessage;
Expand Down Expand Up @@ -145,8 +153,8 @@ public function build(string $logClass): AbstractMigrationLogEntry
$this->fieldSourcePath,
$this->sourceData,
$this->convertedData,
$this->exceptionMessage,
$this->exceptionTrace,
$this->getExceptionMessage(),
$this->getExceptionTrace(),
);
}

Expand All @@ -162,4 +170,33 @@ private function getRevisedId(?string $id): ?string

return null;
}

private function getExceptionMessage(): ?string
{
if ($this->exceptionMessage !== null) {
return $this->exceptionMessage;
}

if ($this->exception !== null) {
return $this->exception->getMessage() . ' in ' . $this->exception->getFile() . ':' . $this->exception->getLine();
}

return null;
}

/**
* @return array<mixed>|null
*/
private function getExceptionTrace(): ?array
{
if ($this->exceptionTrace !== null) {
return $this->exceptionTrace;
}

if ($this->exception !== null) {
return $this->exception->getTrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likely needs to be adjusted again to filter out args as well, see
#151

}

return null;
}
}
15 changes: 5 additions & 10 deletions src/Migration/Media/Processor/HttpDownloadServiceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public function process(MigrationContextInterface $migrationContext, Context $co

$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(RunExceptionLog::class)
);
Expand Down Expand Up @@ -188,8 +187,7 @@ function (MediaProcessWorkloadStruct $work) use ($uuid) {
$work->setState(MediaProcessWorkloadStruct::ERROR_STATE);
$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($e->getMessage())
->withExceptionTrace($e->getTrace())
->withException($e)
->withEntityName(MediaDefinition::ENTITY_NAME)
->withEntityId($uuid)
->build(RunExceptionLog::class)
Expand Down Expand Up @@ -287,8 +285,7 @@ private function doNormalDownloadRequest(MigrationContextInterface $migrationCon
// this should never happen because of Promises, but just in case something is wrong with request construction
$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(RunExceptionLog::class)
);
Expand All @@ -311,8 +308,7 @@ private function persistFileToMedia(string $filePath, string $uuid, string $name

$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(RunExceptionLog::class)
);
Expand Down Expand Up @@ -347,8 +343,7 @@ private function persistFileToMedia(string $filePath, string $uuid, string $name
} else {
$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($mediaException->getMessage())
->withExceptionTrace($mediaException->getTrace())
->withException($mediaException)
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(RunExceptionLog::class)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ public function process(
if ($e->getErrorCode() === MigrationException::NO_CONNECTION_FOUND) {
$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($e->getMessage())
->withExceptionTrace($e->getTrace())
->withException($e)
->withEntityName($currentDataSet::getEntity())
->build(FetchProcessorMissingLog::class)
);
Expand All @@ -151,8 +150,7 @@ public function process(
} catch (\Throwable $e) {
$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($e->getMessage())
->withExceptionTrace($e->getTrace())
->withException($e)
->withEntityName($currentDataSet::getEntity())
->build(RunExceptionLog::class)
);
Expand Down
3 changes: 1 addition & 2 deletions src/Migration/Run/RunService.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ public function assignThemeToSalesChannel(string $runUuid, Context $context): vo
$connection->getProfileName(),
$connection->getGatewayName(),
))
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityName(ThemeDefinition::ENTITY_NAME)
->withEntityId($defaultThemeId)
->build(WriteThemeCompilingFailedLog::class)
Expand Down
6 changes: 2 additions & 4 deletions src/Migration/Service/MigrationDataConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public function convert(array $data, MigrationContextInterface $migrationContext
} catch (\Throwable $exception) {
$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityName($dataSet::getEntity())
->build(RunExceptionLog::class)
);
Expand Down Expand Up @@ -128,8 +127,7 @@ private function convertData(
} catch (\Throwable $exception) {
$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityName($dataSet::getEntity())
->withSourceData($item)
->build(RunExceptionLog::class)
Expand Down
3 changes: 1 addition & 2 deletions src/Migration/Service/MigrationDataFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public function fetchData(MigrationContextInterface $migrationContext, Context $
} catch (\Throwable $exception) {
$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityName($dataSet::getEntity())
->build(RunExceptionLog::class)
);
Expand Down
11 changes: 4 additions & 7 deletions src/Migration/Service/MigrationDataWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ public function writeData(MigrationContextInterface $migrationContext, Context $
} catch (MigrationException $writerNotFoundException) {
$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($writerNotFoundException->getMessage())
->withExceptionTrace($writerNotFoundException->getTrace())
->withException($writerNotFoundException)
->withConvertedData([$converted])
->withEntityName($dataSet::getEntity())
->build(RunExceptionLog::class)
Expand Down Expand Up @@ -202,8 +201,7 @@ private function handleWriteException(

$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityName($entityName)
->withConvertedData($entity)
->withEntityId($entity['id'] ?? null)
Expand Down Expand Up @@ -261,12 +259,11 @@ private function writePerEntity(
} catch (\Throwable $exception) {
$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityName($entityName)
->withConvertedData([$entity])
->withEntityId($entity['id'] ?? null)
->build(RunExceptionLog::class)
->build(WriteExceptionLog::class)
);

$updateWrittenData[$dataId]['written'] = false;
Expand Down
6 changes: 2 additions & 4 deletions src/Migration/Subscriber/MessageQueueSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public function onWorkerMessageFailed(WorkerMessageFailedEvent $event): void
$connection?->getProfileName() ?? 'unknown',
$connection?->getGatewayName() ?? 'unknown'
))
->withExceptionMessage($event->getThrowable()->getMessage())
->withExceptionTrace($event->getThrowable()->getTrace())
->withException($event->getThrowable())
->build(RunMessageQueueExceptionLog::class)
);

Expand All @@ -114,8 +113,7 @@ public function onWorkerMessageFailed(WorkerMessageFailedEvent $event): void
$connection?->getProfileName() ?? 'unknown',
$connection?->getGatewayName() ?? 'unknown'
))
->withExceptionMessage($event->getThrowable()->getMessage())
->withExceptionTrace($event->getThrowable()->getTrace())
->withException($event->getThrowable())
->build(RunAbortedLog::class)
);

Expand Down
6 changes: 2 additions & 4 deletions src/Migration/Validation/MigrationEntityValidationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,7 @@ private function addValidationExceptionLog(
->withFieldName($fieldName)
->withConvertedData($validationContext->getConvertedData())
->withSourceData($validationContext->getSourceData())
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityId($entityId)
->build($logClass)
);
Expand All @@ -545,8 +544,7 @@ private function addExceptionLog(MigrationValidationContext $validationContext,
->withEntityName($validationContext->getEntityDefinition()->getEntityName())
->withSourceData($validationContext->getSourceData())
->withConvertedData($convertedData)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withException($exception)
->withEntityId($entityId)
->build(MigrationValidationExceptionLog::class)
);
Expand Down
4 changes: 4 additions & 0 deletions src/Migration/Writer/OrderWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function supports(): string
public function writeData(array $data, Context $context): array
{
foreach ($data as &$item) {
if (!isset($item['transactions']) || !\is_array($item['transactions'])) {
continue;
}

foreach ($item['transactions'] as &$transaction) {
$transaction['amount'] = $this->structNormalizer->denormalize($transaction['amount']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
use SwagMigrationAssistant\Exception\MigrationException;
use SwagMigrationAssistant\Migration\Converter\ConvertStruct;
use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities;
use SwagMigrationAssistant\Migration\Logging\Log\Builder\MigrationLogBuilder;
Expand All @@ -35,11 +36,12 @@ public function convert(array $data, Context $context, MigrationContextInterface
$this->connectionId = $connection->getId();

if (!isset($data['id'], $data['ordernumber'])) {
$exception = MigrationException::mainVariantRelationMissingIdAndOrderNumber();

$this->loggingService->log(
MigrationLogBuilder::fromMigrationContext($migrationContext)
->withSourceData($data)
->withExceptionMessage('MainVariantRelation requires ID and order number, to be converted successful')
->withExceptionTrace(\debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 2))
->withException($exception)
->build(ConvertMainVariantRelationFailedLog::class)
);

Expand Down
3 changes: 1 addition & 2 deletions src/Profile/Shopware/Converter/ProductConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,7 @@ private function getEsdFiles(array $esdFiles, string $oldVariantId, array $conve
->withFieldName('path')
->withFieldSourcePath('path')
->withSourceData($esdFile)
->withExceptionMessage($e->getMessage())
->withExceptionTrace($e->getTrace())
->withException($e)
->build(ConvertChildEntityFailedLog::class)
);

Expand Down
Loading
Loading