Skip to content
Merged
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
12 changes: 5 additions & 7 deletions src/Migration/Logging/Log/Builder/SwagMigrationLogBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ public function withExceptionTrace(array $exceptionTrace): self
*/
public function build(string $logClass): AbstractSwagMigrationLogEntry
{
$log = new $logClass(
if (!class_exists($logClass) || !is_subclass_of($logClass, AbstractSwagMigrationLogEntry::class)) {
throw MigrationException::failedToCreateMigrationLog($logClass);
}

return new $logClass(
$this->runId,
$this->profileName,
$this->gatewayName,
Expand All @@ -141,11 +145,5 @@ public function build(string $logClass): AbstractSwagMigrationLogEntry
$this->exceptionMessage,
$this->exceptionTrace,
);

if ($log instanceof AbstractSwagMigrationLogEntry) {
return $log;
}

throw MigrationException::failedToCreateMigrationLog($logClass);
}
}
23 changes: 15 additions & 8 deletions src/Migration/Media/Processor/HttpDownloadServiceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

use Doctrine\DBAL\Connection;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Promise;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Promise\Utils;
use Psr\Http\Message\ResponseInterface;
use Shopware\Core\Content\Media\File\FileSaver;
use Shopware\Core\Content\Media\File\MediaFile;
use Shopware\Core\Content\Media\MediaDefinition;
use Shopware\Core\Content\Media\MediaException;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
Expand Down Expand Up @@ -77,10 +77,11 @@ public function process(MigrationContextInterface $migrationContext, Context $co
if ($client === null) {
$exception = new \Exception('Http download client can not be constructed.');

$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(ExceptionRunLog::class)
);
$this->loggingService->saveLogging($context);
Expand Down Expand Up @@ -122,8 +123,9 @@ function (MediaProcessWorkloadStruct $work) use ($uuid) {
$failureUuids[] = $uuid;
$work->setState(MediaProcessWorkloadStruct::ERROR_STATE);

$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(CannotGetFileRunLog::class)
);
}
Expand All @@ -141,8 +143,9 @@ function (MediaProcessWorkloadStruct $work) use ($uuid) {
$failureUuids[] = $uuid;
$work->setState(MediaProcessWorkloadStruct::ERROR_STATE);

$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(TemporaryFileErrorLog::class)
);

Expand Down Expand Up @@ -181,10 +184,11 @@ function (MediaProcessWorkloadStruct $work) use ($uuid) {
} catch (\Exception $e) {
$failureUuids[] = $uuid;
$work->setState(MediaProcessWorkloadStruct::ERROR_STATE);
$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($e->getMessage())
->withExceptionTrace($e->getTrace())
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(ExceptionRunLog::class)
);
} finally {
Expand Down Expand Up @@ -279,10 +283,11 @@ private function doNormalDownloadRequest(MigrationContextInterface $migrationCon
$workload->setState(MediaProcessWorkloadStruct::FINISH_STATE);
} catch (\Throwable $exception) {
// this should never happen because of Promises, but just in case something is wrong with request construction
$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(ExceptionRunLog::class)
);

Expand All @@ -302,10 +307,11 @@ private function persistFileToMedia(string $filePath, string $uuid, string $name
if ($fileSize === false || $fileSize === 0 || $mimeType === false) {
$exception = new \Exception('Downloaded file is empty or could not determine mime type.');

$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(ExceptionRunLog::class)
);

Expand Down Expand Up @@ -337,10 +343,11 @@ private function persistFileToMedia(string $filePath, string $uuid, string $name
} elseif (\in_array($mediaException->getErrorCode(), [MediaException::MEDIA_ILLEGAL_FILE_NAME, MediaException::MEDIA_EMPTY_FILE_NAME], true)) {
$this->fileSaver->persistFileToMedia($mediaFile, Uuid::randomHex(), $uuid, $context);
} else {
$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($mediaException->getMessage())
->withExceptionTrace($mediaException->getTrace())
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(ExceptionRunLog::class)
);
}
Expand Down
11 changes: 8 additions & 3 deletions src/Migration/MessageQueue/Handler/ProcessMediaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace SwagMigrationAssistant\Migration\MessageQueue\Handler;

use Shopware\Core\Content\Media\MediaDefinition;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
Expand Down Expand Up @@ -84,18 +85,22 @@ public function __invoke(ProcessMediaMessage $message): void
$processor = $this->mediaFileProcessorRegistry->getProcessor($migrationContext);
$workload = $processor->process($migrationContext, $context, $workload);
$this->processFailures($context, $migrationContext, $processor, $workload);
} catch (NoConnectionFoundException) {
$this->loggingService->addLogEntry( // TODO: add optional fields
} catch (NoConnectionFoundException $exception) {
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(ProcessorNotFoundLog::class)
);

$this->loggingService->saveLogging($context);
} catch (\Exception $e) {
$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($e->getMessage())
->withExceptionTrace($e->getTrace())
->withEntityName(MediaDefinition::ENTITY_NAME)
->build(ExceptionRunLog::class)
);

Expand Down
10 changes: 7 additions & 3 deletions src/Migration/Run/RunService.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,17 @@ public function assignThemeToSalesChannel(string $runUuid, Context $context): vo
foreach ($salesChannels as $salesChannel) {
try {
$this->themeService->assignTheme($defaultTheme, $salesChannel, $context);
} catch (\Throwable) {
$this->loggingService->addLogEntry( // TODO: add optional fields
} catch (\Throwable $exception) {
$this->loggingService->addLogEntry(
(new SwagMigrationLogBuilder(
$runUuid,
$connection->getProfileName(),
$connection->getGatewayName(),
))->build(ThemeCompilingErrorRunLog::class)
))
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withEntityName(SalesChannelDefinition::ENTITY_NAME)
->build(ThemeCompilingErrorRunLog::class)
);
}
}
Expand Down
18 changes: 11 additions & 7 deletions src/Migration/Service/MediaFileProcessorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function processMediaFiles(MigrationContextInterface $migrationContext, C
if ($currentDataSet === null) {
try {
$currentDataSet = $this->dataSetRegistry->getDataSet($migrationContext, $mediaFile['entity']);
} catch (DataSetNotFoundException) {
$this->logDataSetNotFoundException($migrationContext);
} catch (DataSetNotFoundException $exception) {
$this->logDataSetNotFoundException($migrationContext, $exception);

continue;
}
Expand All @@ -59,8 +59,8 @@ public function processMediaFiles(MigrationContextInterface $migrationContext, C
$messageMediaUuids = [];
$currentCount = 0;
$currentDataSet = $this->dataSetRegistry->getDataSet($migrationContext, $mediaFile['entity']);
} catch (DataSetNotFoundException) {
$this->logDataSetNotFoundException($migrationContext);
} catch (DataSetNotFoundException $exception) {
$this->logDataSetNotFoundException($migrationContext, $exception);

continue;
}
Expand Down Expand Up @@ -129,10 +129,14 @@ private function addMessageToBus(string $runUuid, Context $context, DataSet $dat
$this->messageBus->dispatch($message);
}

private function logDataSetNotFoundException(MigrationContextInterface $migrationContext): void
{
$this->loggingService->addLogEntry( // TODO: add optional fields
private function logDataSetNotFoundException(
MigrationContextInterface $migrationContext,
\Throwable $exception
): void {
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->build(DataSetNotFoundLog::class)
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Migration/Service/MigrationDataConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ public function convert(array $data, MigrationContextInterface $migrationContext
$this->mediaFileService->writeMediaFile($context);
}
} catch (\Throwable $exception) {
$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withEntityName($dataSet::getEntity())
->build(ExceptionRunLog::class)
);

Expand Down Expand Up @@ -104,10 +105,12 @@ private function convertData(
'convertFailure' => $convertFailureFlag,
];
} catch (\Throwable $exception) {
$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withEntityName($dataSet::getEntity())
->withSourceData($item)
->build(ExceptionRunLog::class)
);

Expand Down
3 changes: 2 additions & 1 deletion src/Migration/Service/MigrationDataFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ public function fetchData(MigrationContextInterface $migrationContext, Context $
try {
return $this->gatewayRegistry->getGateway($migrationContext)->read($migrationContext);
} catch (\Throwable $exception) {
$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withEntityName($dataSet::getEntity())
->build(ExceptionRunLog::class)
);
$this->loggingService->saveLogging($context);
Expand Down
14 changes: 11 additions & 3 deletions src/Migration/Service/MigrationDataWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ public function writeData(MigrationContextInterface $migrationContext, Context $
$currentWriter = $this->writerRegistry->getWriter($dataSet::getEntity());
$currentWriter->writeData(\array_values($converted), $this->writeContext);
} catch (WriterNotFoundException $writerNotFoundException) {
$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($writerNotFoundException->getMessage())
->withExceptionTrace($writerNotFoundException->getTrace())
->withConvertedData([$converted])
->withEntityName($dataSet::getEntity())
->build(ExceptionRunLog::class)
);
$this->loggingService->saveLogging($context);
Expand Down Expand Up @@ -181,8 +183,12 @@ private function handleWriteException(
$updateWrittenData[$dataId]['written'] = false;
$updateWrittenData[$dataId]['writeFailure'] = true;

$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withEntityName($entityName)
->withConvertedData($entity)
->build(WriteExceptionRunLog::class)
);

Expand Down Expand Up @@ -234,10 +240,12 @@ private function writePerEntity(
$currentWriter = $this->writerRegistry->getWriter($entityName);
$currentWriter->writeData([$entity], $this->writeContext);
} catch (\Throwable $exception) {
$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
SwagMigrationLogBuilder::fromMigrationContext($migrationContext)
->withExceptionMessage($exception->getMessage())
->withExceptionTrace($exception->getTrace())
->withEntityName($entityName)
->withConvertedData([$entity])
->build(ExceptionRunLog::class)
);

Expand Down
4 changes: 2 additions & 2 deletions src/Migration/Subscriber/MessageQueueSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function onWorkerMessageFailed(WorkerMessageFailedEvent $event): void
* Raise exception counter and log the exception
*/
$progress->raiseExceptionCount();
$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
(new SwagMigrationLogBuilder(
$run->getId(),
$connection?->getProfileName() ?? 'unknown',
Expand All @@ -108,7 +108,7 @@ public function onWorkerMessageFailed(WorkerMessageFailedEvent $event): void
$progress->setIsAborted(true);
$this->updateRun($run->getId(), $progress, $message->getContext());

$this->loggingService->addLogEntry( // TODO: add optional fields
$this->loggingService->addLogEntry(
(new SwagMigrationLogBuilder(
$run->getId(),
$connection?->getProfileName() ?? 'unknown',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Psr\Http\Message\StreamInterface;
use Shopware\Core\Content\Media\File\FileSaver;
use Shopware\Core\Content\Media\File\MediaFile;
use Shopware\Core\Content\Media\MediaDefinition;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\DataAbstractionLayer\Dbal\QueryBuilder;
use Shopware\Core\Framework\Log\Package;
Expand Down Expand Up @@ -203,7 +204,7 @@ public function testProcessWithRequestFailure(): void
'profileName' => '',
'gatewayName' => '',
'userFixable' => false,
'entityName' => null,
'entityName' => MediaDefinition::ENTITY_NAME,
'fieldName' => null,
'fieldSourcePath' => null,
'sourceData' => null,
Expand Down